diff options
| author | bors <bors@rust-lang.org> | 2014-05-23 19:51:20 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-23 19:51:20 -0700 |
| commit | 9c870b3d1c1dda2f00499ab906142c6976d421bd (patch) | |
| tree | 1bb71d4233c06bf9a01ca981d2292b8a66626e2a /src/rustllvm/RustWrapper.cpp | |
| parent | 12e80f1a14195814080300b9ac36e267f8870430 (diff) | |
| parent | 3cae434f5c56b6f07d50da3d1ed85d5bf30c37d7 (diff) | |
| download | rust-9c870b3d1c1dda2f00499ab906142c6976d421bd.tar.gz rust-9c870b3d1c1dda2f00499ab906142c6976d421bd.zip | |
auto merge of #14306 : luqmana/rust/up-llvm, r=alexcrichton
We can now mark arguments and returns as `nonnull` in LLVM. It's still somewhat limited by the fact that LLVM loses this information after inlining but it might help in certain cases.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 717cd333a79..2157aecf376 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -12,6 +12,12 @@ #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" +#if LLVM_VERSION_MINOR >= 5 +#include "llvm/IR/CallSite.h" +#else +#include "llvm/Support/CallSite.h" +#endif + //===----------------------------------------------------------------------=== // // This file defines alternate interfaces to core functions that are more @@ -83,46 +89,43 @@ extern "C" LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) { return wrap(Type::getMetadataTy(*unwrap(C))); } -extern "C" void LLVMAddFunctionAttrString(LLVMValueRef fn, const char *Name) { - unwrap<Function>(fn)->addFnAttr(Name); +extern "C" void LLVMAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, uint64_t Val) { + CallSite Call = CallSite(unwrap<Instruction>(Instr)); + AttrBuilder B; + B.addRawValue(Val); + Call.setAttributes( + Call.getAttributes().addAttributes(Call->getContext(), index, + AttributeSet::get(Call->getContext(), + index, B))); +} + +extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index, uint64_t Val) { + Function *A = unwrap<Function>(Fn); + AttrBuilder B; + B.addRawValue(Val); + A->addAttributes(index, AttributeSet::get(A->getContext(), index, B)); +} + +extern "C" void LLVMAddFunctionAttrString(LLVMValueRef Fn, unsigned index, const char *Name) { + Function *F = unwrap<Function>(Fn); + AttrBuilder B; + B.addAttribute(Name); + F->addAttributes(index, AttributeSet::get(F->getContext(), index, B)); } -extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, const char *Name) { +extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, unsigned index, const char *Name) { Function *f = unwrap<Function>(fn); LLVMContext &C = f->getContext(); AttrBuilder B; B.addAttribute(Name); - AttributeSet to_remove = AttributeSet::get(C, AttributeSet::FunctionIndex, B); + AttributeSet to_remove = AttributeSet::get(C, index, B); AttributeSet attrs = f->getAttributes(); f->setAttributes(attrs.removeAttributes(f->getContext(), - AttributeSet::FunctionIndex, + index, to_remove)); } -extern "C" void LLVMAddReturnAttribute(LLVMValueRef Fn, LLVMAttribute PA) { - Function *A = unwrap<Function>(Fn); - AttrBuilder B(PA); - A->addAttributes(AttributeSet::ReturnIndex, - AttributeSet::get(A->getContext(), AttributeSet::ReturnIndex, B)); -} - -extern "C" void LLVMRemoveReturnAttribute(LLVMValueRef Fn, LLVMAttribute PA) { - Function *A = unwrap<Function>(Fn); - AttrBuilder B(PA); - A->removeAttributes(AttributeSet::ReturnIndex, - AttributeSet::get(A->getContext(), AttributeSet::ReturnIndex, B)); -} - -#if LLVM_VERSION_MINOR >= 5 -extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) { - Function *A = unwrap<Function>(Fn); - A->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold); -} -#else -extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {} -#endif - extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B, LLVMValueRef source, const char* Name, |
