Expose parameter attributes via C bindings.

Patch by Anders Johnsen!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50360 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Gordon Henriksen 2008-04-28 17:37:06 +00:00
parent 1f13c686df
commit e2435da8ab
4 changed files with 76 additions and 0 deletions

View File

@ -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,

View File

@ -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);

View File

@ -20,6 +20,7 @@
#include "llvm/TypeSymbolTable.h"
#include "llvm/ModuleProvider.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/CallSite.h"
#include <cassert>
#include <cstdlib>
#include <cstring>
@ -798,6 +799,19 @@ LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
return wrap(--I);
}
void LLVMAddParamAttr(LLVMValueRef Arg, LLVMParamAttr PA) {
unwrap<Argument>(Arg)->addAttr(PA);
}
void LLVMRemoveParamAttr(LLVMValueRef Arg, LLVMParamAttr PA) {
unwrap<Argument>(Arg)->removeAttr(PA);
}
void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
unwrap<Argument>(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<Instruction>(Instr));
Call.setParamAttrs(
Call.getParamAttrs().addAttr(index, PA));
}
void LLVMRemoveInstrParamAttr(LLVMValueRef Instr, unsigned index,
LLVMParamAttr PA) {
CallSite Call = CallSite(unwrap<Instruction>(Instr));
Call.setParamAttrs(
Call.getParamAttrs().removeAttr(index, PA));
}
void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
unsigned align) {
CallSite Call = CallSite(unwrap<Instruction>(Instr));
Call.setParamAttrs(
Call.getParamAttrs().addAttr(index,
ParamAttr::constructAlignmentFromInt(align)));
}
/*--.. Operations on phi nodes .............................................--*/
void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,

View File

@ -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));
}