Skip to content

Commit 8fe6f1f

Browse files
committed
The customary LLVM way of obtaining intrinsics is with
Intrinsic::getDeclaration and use the definition in include/llvm/Intrinsics.td This also makes the attribute on the intrinsic to be more consistent with the back-end (code-gen), which automatically assumes it's ReadNone (because this is what Intrinsics.td) defines. Using ReadNone rather than ReadOnly may be not strictly correct because the intrinsic depends on the value of the TP. However, this attribute is not really used anywhere in IR optimizations, and in the backend the intrinsic is ReadNone anyhow (the IR setting gets overridden). If we run into any problems with this in the future, we may consider handling the lowering of this intrinsic in TargetLowering::LowerINTRINSIC_W_CHAIN rather than in TargetLowering::LowerINTRINSIC_WO_CHAIN. BUG=None [email protected] Review URL: https://codereview.chromium.org/14643019
1 parent 1ab5bcc commit 8fe6f1f

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

include/llvm/IR/Intrinsics.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,7 @@ def int_nacl_longjmp : Intrinsic<[], [llvm_ptr_ty, llvm_i32_ty],
479479
[IntrNoReturn]>;
480480

481481
// Fast built-in version of NaCl's tls_get() IRT interface.
482-
def int_nacl_read_tp : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>,
483-
GCCBuiltin<"__builtin_nacl_read_tp">;
482+
def int_nacl_read_tp : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
484483

485484
// The following intrinsics provide target-specific implementations of
486485
// the interface in native_client/src/untrusted/nacl/tls_params.h.

lib/Transforms/NaCl/ExpandTls.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/IR/DataLayout.h"
3030
#include "llvm/IR/DerivedTypes.h"
3131
#include "llvm/IR/Instructions.h"
32+
#include "llvm/IR/Intrinsics.h"
3233
#include "llvm/IR/Module.h"
3334
#include "llvm/Support/raw_ostream.h"
3435
#include "llvm/Transforms/NaCl.h"
@@ -233,17 +234,7 @@ static PointerType *buildTlsTemplate(Module &M, std::vector<VarInfo> *TlsVars) {
233234
static void rewriteTlsVars(Module &M, std::vector<VarInfo> *TlsVars,
234235
PointerType *TemplatePtrType) {
235236
// Set up the intrinsic that reads the thread pointer.
236-
Type *i8 = Type::getInt8Ty(M.getContext());
237-
FunctionType *ReadTpType = FunctionType::get(PointerType::get(i8, 0),
238-
/*isVarArg=*/false);
239-
AttrBuilder B;
240-
B.addAttribute(Attribute::ReadOnly);
241-
B.addAttribute(Attribute::NoUnwind);
242-
AttributeSet ReadTpAttrs = AttributeSet::get(
243-
M.getContext(), AttributeSet::FunctionIndex, B);
244-
Constant *ReadTpFunc = M.getOrInsertTargetIntrinsic("llvm.nacl.read.tp",
245-
ReadTpType,
246-
ReadTpAttrs);
237+
Function *ReadTpFunc = Intrinsic::getDeclaration(&M, Intrinsic::nacl_read_tp);
247238

248239
for (std::vector<VarInfo>::iterator VarInfo = TlsVars->begin();
249240
VarInfo != TlsVars->end();

0 commit comments

Comments
 (0)