From 3cae434f5c56b6f07d50da3d1ed85d5bf30c37d7 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Wed, 21 May 2014 15:07:48 -0400 Subject: librustc: Consolidate the attribute handling for tagging function arguments and returns. --- src/rustllvm/RustWrapper.cpp | 71 +++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 40 deletions(-) (limited to 'src/rustllvm/RustWrapper.cpp') diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 3661d152d59..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,58 +89,43 @@ extern "C" LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) { return wrap(Type::getMetadataTy(*unwrap(C))); } -extern "C" void LLVMAddFunctionAttrString(LLVMValueRef fn, const char *Name) { - unwrap(fn)->addFnAttr(Name); +extern "C" void LLVMAddCallSiteAttribute(LLVMValueRef Instr, unsigned index, uint64_t Val) { + CallSite Call = CallSite(unwrap(Instr)); + AttrBuilder B; + B.addRawValue(Val); + Call.setAttributes( + Call.getAttributes().addAttributes(Call->getContext(), index, + AttributeSet::get(Call->getContext(), + index, B))); } -extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, const char *Name) { +extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index, uint64_t Val) { + Function *A = unwrap(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(Fn); + AttrBuilder B; + B.addAttribute(Name); + F->addAttributes(index, AttributeSet::get(F->getContext(), index, B)); +} + +extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, unsigned index, const char *Name) { Function *f = unwrap(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(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(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(Fn); - A->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold); -} - -extern "C" void LLVMAddNonNullAttribute(LLVMValueRef Arg) { - Argument *A = unwrap(Arg); - A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, Attribute::NonNull)); -} - -extern "C" void LLVMAddNonNullReturnAttribute(LLVMValueRef Fn) { - Function *A = unwrap(Fn); - A->addAttribute(AttributeSet::ReturnIndex, Attribute::NonNull); -} -#else -extern "C" void LLVMAddColdAttribute(LLVMValueRef Fn) {} -extern "C" void LLVMAddNonNullAttribute(LLVMValueRef Arg) {} -extern "C" void LLVMAddNonNullReturnAttribute(LLVMValueRef Fn) {} -#endif - extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B, LLVMValueRef source, const char* Name, -- cgit 1.4.1-3-g733a5