From: Wang Nan <wangnan0@huawei.com>
To: <ast@plumgrid.com>
Cc: <hekuang@huawei.com>, <pi3orama@163.com>, <linux-kernel@vger.kernel.org>
Subject: [LLVM CLANG PATCH] BPF: add __builtin_bpf_typeid()
Date: Fri, 31 Jul 2015 10:21:57 +0000 [thread overview]
Message-ID: <1438338117-184506-1-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <55BB4B8A.5000207@huawei.com>
This patch introduces a new builtin function __builtin_bpf_typeid()
for BPF. This function emit a 'llvm.eh_typeid_for', and will be
converted to typeid of a global variable.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
---
include/clang/Basic/BuiltinsBPF.def | 16 ++++++++++++++++
include/clang/Basic/TargetBuiltins.h | 9 +++++++++
lib/Basic/Targets.cpp | 14 +++++++++++++-
lib/CodeGen/CGBuiltin.cpp | 16 ++++++++++++++++
lib/CodeGen/CodeGenFunction.h | 1 +
5 files changed, 55 insertions(+), 1 deletion(-)
create mode 100644 include/clang/Basic/BuiltinsBPF.def
diff --git a/include/clang/Basic/BuiltinsBPF.def b/include/clang/Basic/BuiltinsBPF.def
new file mode 100644
index 0000000..9e53ee0
--- /dev/null
+++ b/include/clang/Basic/BuiltinsBPF.def
@@ -0,0 +1,16 @@
+//===--- BuiltinsBPF.def - BPF Builtin function database ----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the BPF-specific builtin function database. Users of
+// this file must define the BUILTIN macro to make use of this information.
+//
+//===----------------------------------------------------------------------===//
+
+BUILTIN(__builtin_bpf_typeid, "Wiv*", "nc")
+
diff --git a/include/clang/Basic/TargetBuiltins.h b/include/clang/Basic/TargetBuiltins.h
index b4740c5..550f921 100644
--- a/include/clang/Basic/TargetBuiltins.h
+++ b/include/clang/Basic/TargetBuiltins.h
@@ -93,6 +93,15 @@ namespace clang {
};
}
+ namespace BPF {
+ enum {
+ LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsBPF.def"
+ LastTSBuiltin
+ };
+ }
+
/// \brief Flags to identify the types for overloaded Neon builtins.
///
/// These must be kept in sync with the flags in utils/TableGen/NeonEmitter.h.
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index f229c99..aa7fffb 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -6111,6 +6111,7 @@ validateAsmConstraint(const char *&Name,
};
class BPFTargetInfo : public TargetInfo {
+ static const Builtin::Info BuiltinInfo[];
public:
BPFTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
@@ -6141,7 +6142,10 @@ public:
}
void getTargetBuiltins(const Builtin::Info *&Records,
- unsigned &NumRecords) const override {}
+ unsigned &NumRecords) const override {
+ Records = BuiltinInfo;
+ NumRecords = clang::BPF::LastTSBuiltin - Builtin::FirstTSBuiltin;
+ }
const char *getClobbers() const override {
return "";
}
@@ -6164,6 +6168,14 @@ public:
}
};
+const Builtin::Info BPFTargetInfo::BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
+#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
+ ALL_LANGUAGES },
+#include "clang/Basic/BuiltinsBPF.def"
+};
+
+
class MipsTargetInfoBase : public TargetInfo {
virtual void setDescriptionString() = 0;
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index 1555d29..a46f638 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -1882,6 +1882,9 @@ Value *CodeGenFunction::EmitTargetBuiltinExpr(unsigned BuiltinID,
case llvm::Triple::nvptx:
case llvm::Triple::nvptx64:
return EmitNVPTXBuiltinExpr(BuiltinID, E);
+ case llvm::Triple::bpfel:
+ case llvm::Triple::bpfeb:
+ return EmitBPFBuiltinExpr(BuiltinID, E);
default:
return nullptr;
}
@@ -7056,3 +7059,16 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
return nullptr;
}
}
+
+Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
+ const CallExpr *E) {
+ switch (BuiltinID) {
+ default:
+ return nullptr;
+ case BPF::BI__builtin_bpf_typeid:
+ assert(E->getArg(0)->getType()->isPointerType());
+ llvm::Value *llvm_eh_typeid_for =
+ CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
+ return Builder.CreateCall(llvm_eh_typeid_for, EmitScalarExpr(E->getArg(0)));
+ }
+}
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index b7d6bbd..863420d 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -2622,6 +2622,7 @@ public:
llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
+ llvm::Value *EmitBPFBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
--
1.8.3.4
next prev parent reply other threads:[~2015-07-31 10:22 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-10 10:03 [RFC PATCH v4 0/3] Make eBPF programs output data to perf event He Kuang
2015-07-10 10:03 ` [RFC PATCH v4 1/3] tracing/events: Fix wrong sample output by storing array length instead of size He Kuang
2015-07-17 14:32 ` Steven Rostedt
2015-07-17 17:24 ` Sara Rostedt
2015-07-17 18:13 ` Steven Rostedt
2015-07-23 19:36 ` Alex Bennée
2015-07-10 10:03 ` [RFC PATCH v4 2/3] tools lib traceevent: Add function to get dynamic arrays length He Kuang
2015-07-10 10:03 ` [RFC PATCH v4 3/3] bpf: Introduce function for outputing data to perf event He Kuang
2015-07-10 22:10 ` Alexei Starovoitov
2015-07-13 4:36 ` He Kuang
2015-07-13 13:52 ` Namhyung Kim
2015-07-13 14:01 ` pi3orama
2015-07-13 14:09 ` Namhyung Kim
2015-07-13 14:29 ` pi3orama
2015-07-14 1:43 ` Alexei Starovoitov
2015-07-14 11:54 ` He Kuang
2015-07-17 4:11 ` Alexei Starovoitov
2015-07-17 4:14 ` Wangnan (F)
2015-07-17 4:27 ` Alexei Starovoitov
2015-07-23 11:54 ` He Kuang
2015-07-23 20:49 ` llvm bpf debug info. " Alexei Starovoitov
2015-07-24 3:20 ` Alexei Starovoitov
2015-07-24 4:16 ` He Kuang
2015-07-25 10:04 ` He Kuang
2015-07-28 2:18 ` Alexei Starovoitov
2015-07-29 9:38 ` He Kuang
2015-07-29 17:13 ` Alexei Starovoitov
2015-07-29 20:00 ` pi3orama
2015-07-29 22:20 ` Alexei Starovoitov
2015-07-31 10:18 ` Wangnan (F)
2015-07-31 10:20 ` [LLVM PATCH] BPF: add FRAMEADDR support Wang Nan
2015-07-31 10:21 ` Wang Nan [this message]
2015-07-31 10:48 ` llvm bpf debug info. Re: [RFC PATCH v4 3/3] bpf: Introduce function for outputing data to perf event pi3orama
2015-08-03 19:44 ` Alexei Starovoitov
2015-08-04 9:01 ` Cc llvmdev: " Wangnan (F)
2015-08-05 1:58 ` Wangnan (F)
2015-08-05 2:05 ` Wangnan (F)
2015-08-05 6:51 ` [LLVMdev] " Wangnan (F)
2015-08-05 7:11 ` Alexei Starovoitov
2015-08-05 8:28 ` Wangnan (F)
2015-08-06 3:22 ` [llvm-dev] " Alexei Starovoitov
2015-08-06 4:35 ` Wangnan (F)
2015-08-06 6:55 ` Alexei Starovoitov
2015-08-12 2:34 ` Wangnan (F)
2015-08-12 4:57 ` [llvm-dev] " Alexei Starovoitov
2015-08-12 5:28 ` Wangnan (F)
2015-08-12 13:15 ` Brenden Blanco
2015-08-13 6:24 ` Wangnan (F)
2015-08-05 8:59 ` [LLVMdev] Cc llvmdev: " He Kuang
2015-08-06 3:41 ` [llvm-dev] " Alexei Starovoitov
2015-08-06 4:31 ` Wangnan (F)
2015-08-06 6:50 ` Alexei Starovoitov
2015-07-13 8:29 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438338117-184506-1-git-send-email-wangnan0@huawei.com \
--to=wangnan0@huawei.com \
--cc=ast@plumgrid.com \
--cc=hekuang@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pi3orama@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®