diff --git a/include/llvm-c/Core.h b/include/llvm-c/Core.h index b536bf5b2a7..d1251dc74fc 100644 --- a/include/llvm-c/Core.h +++ b/include/llvm-c/Core.h @@ -82,6 +82,20 @@ typedef struct LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef; /** See the llvm::PassManagerBase class. */ typedef struct LLVMOpaquePassManager *LLVMPassManagerRef; +typedef enum { + LLVMZExtParamAttr = 1<<0, + LLVMSExtParamAttr = 1<<1, + LLVMNoReturnParamAttr = 1<<2, + LLVMNoUnwindParamAttr = 1<<3, + LLVMInRegParamAttr = 1<<4, + LLVMNoAliasParamAttr = 1<<5, + LLVMStructRetParamAttr = 1<<6, + LLVMByValParamAttr = 1<<7, + LLVMNestParamAttr = 1<<8, + LLVMReadNoneParamAttr = 1<<9, + LLVMReadOnlyParamAttr = 1<<10 +} LLVMParamAttr; + typedef enum { LLVMVoidTypeKind, /**< type with no size */ LLVMFloatTypeKind, /**< 32 bit floating point type */ @@ -413,6 +427,9 @@ LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn); LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn); LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg); LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg); +void LLVMAddParamAttr(LLVMValueRef Arg, LLVMParamAttr PA); +void LLVMRemoveParamAttr(LLVMValueRef Arg, LLVMParamAttr PA); +void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align); /* Operations on basic blocks */ LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB); @@ -441,6 +458,11 @@ LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst); /* Operations on call sites */ void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC); unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); +void LLVMAddInstrParamAttr(LLVMValueRef Instr, unsigned index, LLVMParamAttr); +void LLVMRemoveInstrParamAttr(LLVMValueRef Instr, unsigned index, + LLVMParamAttr); +void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, + unsigned align); /* Operations on phi nodes */ void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, diff --git a/include/llvm/Argument.h b/include/llvm/Argument.h index 23d1a083482..d203a935bd1 100644 --- a/include/llvm/Argument.h +++ b/include/llvm/Argument.h @@ -15,6 +15,7 @@ #define LLVM_ARGUMENT_H #include "llvm/Value.h" +#include "llvm/ParameterAttributes.h" namespace llvm { @@ -60,7 +61,13 @@ public: /// hasSRetAttr - Return true if this argument has the sret attribute on it in /// its containing function. bool hasStructRetAttr() const; + + /// addAttr - Add a ParamAttr to an argument + void addAttr(ParameterAttributes); + /// removeAttr - Remove a ParamAttr from an argument + void removeAttr(ParameterAttributes); + virtual void print(std::ostream &OS) const; void print(std::ostream *OS) const { if (OS) print(*OS); diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index ad72095fe5d..a07464fefd3 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -20,6 +20,7 @@ #include "llvm/TypeSymbolTable.h" #include "llvm/ModuleProvider.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/CallSite.h" #include #include #include @@ -798,6 +799,19 @@ LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) { return wrap(--I); } +void LLVMAddParamAttr(LLVMValueRef Arg, LLVMParamAttr PA) { + unwrap(Arg)->addAttr(PA); +} + +void LLVMRemoveParamAttr(LLVMValueRef Arg, LLVMParamAttr PA) { + unwrap(Arg)->removeAttr(PA); +} + +void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) { + unwrap(Arg)->addAttr( + ParamAttr::constructAlignmentFromInt(align)); +} + /*--.. Operations on basic blocks ..........................................--*/ LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) { @@ -936,6 +950,28 @@ void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) { assert(0 && "LLVMSetInstructionCallConv applies only to call and invoke!"); } +void LLVMAddInstrParamAttr(LLVMValueRef Instr, unsigned index, + LLVMParamAttr PA) { + CallSite Call = CallSite(unwrap(Instr)); + Call.setParamAttrs( + Call.getParamAttrs().addAttr(index, PA)); +} + +void LLVMRemoveInstrParamAttr(LLVMValueRef Instr, unsigned index, + LLVMParamAttr PA) { + CallSite Call = CallSite(unwrap(Instr)); + Call.setParamAttrs( + Call.getParamAttrs().removeAttr(index, PA)); +} + +void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, + unsigned align) { + CallSite Call = CallSite(unwrap(Instr)); + Call.setParamAttrs( + Call.getParamAttrs().addAttr(index, + ParamAttr::constructAlignmentFromInt(align))); +} + /*--.. Operations on phi nodes .............................................--*/ void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues, diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index de011c07bf6..f14c455bce0 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -110,6 +110,17 @@ bool Argument::hasStructRetAttr() const { return getParent()->paramHasAttr(1, ParamAttr::StructRet); } +/// addAttr - Add a ParamAttr to an argument +void Argument::addAttr(ParameterAttributes attr) { + getParent()->setParamAttrs( + getParent()->getParamAttrs().addAttr(getArgNo() + 1, attr)); +} + +/// removeAttr - Remove a ParamAttr from an argument +void Argument::removeAttr(ParameterAttributes attr) { + getParent()->setParamAttrs( + getParent()->getParamAttrs().removeAttr(getArgNo() + 1, attr)); +}