Index: bindings/go/llvm/ir.go =================================================================== --- bindings/go/llvm/ir.go +++ bindings/go/llvm/ir.go @@ -1076,17 +1076,11 @@ func (v Value) LastParam() (rv Value) { rv.C = C.LLVMGetLastParam(v.C); return } func NextParam(v Value) (rv Value) { rv.C = C.LLVMGetNextParam(v.C); return } func PrevParam(v Value) (rv Value) { rv.C = C.LLVMGetPreviousParam(v.C); return } -func (v Value) AddAttribute(a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMAddAttribute(v.C, C.LLVMAttribute(a)) +func (v Value) AddAttribute(KindID uint) { + C.LLVMAddAttribute(v.C, C.uint(KindID)) } -func (v Value) RemoveAttribute(a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMRemoveAttribute(v.C, C.LLVMAttribute(a)) +func (v Value) RemoveAttribute(KindID uint) { + C.LLVMRemoveAttribute(v.C, C.uint(KindID)) } func (v Value) Attribute() Attribute { return Attribute(C.LLVMGetAttribute(v.C)) } func (v Value) SetParamAlignment(align int) { C.LLVMSetParamAlignment(v.C, C.unsigned(align)) } @@ -1149,17 +1143,11 @@ func (v Value) InstructionCallConv() CallConv { return CallConv(C.LLVMCallConv(C.LLVMGetInstructionCallConv(v.C))) } -func (v Value) AddInstrAttribute(i int, a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMAddInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a)) +func (v Value) AddInstrAttribute(i int, KindID uint) { + C.LLVMAddInstrAttribute(v.C, C.unsigned(i), C.uint(KindID)) } -func (v Value) RemoveInstrAttribute(i int, a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMRemoveInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a)) +func (v Value) RemoveInstrAttribute(i int, KindID uint) { + C.LLVMRemoveInstrAttribute(v.C, C.unsigned(i), C.uint(KindID)) } func (v Value) SetInstrParamAlignment(i int, align int) { C.LLVMSetInstrParamAlignment(v.C, C.unsigned(i), C.unsigned(align)) Index: docs/ReleaseNotes.rst =================================================================== --- docs/ReleaseNotes.rst +++ docs/ReleaseNotes.rst @@ -57,6 +57,9 @@ * The C API enum LLVMAttribute is deprecated in favor of LLVMGetAttrKindID. +* The C API functions LLVMGetAttribute and LLVMGetFunctionAttr + are deprecated in favor of LLVMHasAttribute and LLVMHasFunctionAttr. + * ``TargetFrameLowering::eliminateCallFramePseudoInstr`` now returns an iterator to the next instruction instead of ``void``. Targets that previously did ``MBB.erase(I); return;`` now probably want ``return MBB.erase(I);``. Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -1948,18 +1948,25 @@ /** * Add an attribute to a function. * - * @see llvm::Function::addAttribute() + * @see llvm::Function::addFnAttr() */ -void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); +void LLVMAddFunctionAttr(LLVMValueRef Fn, unsigned KindID); /** - * Add a target-dependent attribute to a function + * Add a target-dependent attribute to a function. + * * @see llvm::AttrBuilder::addAttribute() + * @see llvm::Function::addAttributes() */ void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, const char *V); /** + * Remove an attribute from a function. + */ +void LLVMRemoveFunctionAttr(LLVMValueRef Fn, unsigned KindID); + +/** * Obtain an attribute from a function. * * @see llvm::Function::getAttributes() @@ -1967,9 +1974,24 @@ LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn); /** - * Remove an attribute from a function. + * Check if a function has an attribute. */ -void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA); +LLVMBool LLVMHasFunctionAttr(LLVMValueRef Fn, unsigned KindID); + +/** + * Add a return attribute to a function. + */ +void LLVMAddReturnAttr(LLVMValueRef Fn, unsigned KindID); + +/** + * Remove a return attribute from a function. + */ +void LLVMRemoveReturnAttr(LLVMValueRef Fn, unsigned KindID); + +/** + * Check if a function's return has an attribute. + */ +LLVMBool LLVMHasReturnAttr(LLVMValueRef Fn, unsigned KindID); /** * @defgroup LLVMCCoreValueFunctionParameters Function Parameters @@ -2057,21 +2079,29 @@ * * @see llvm::Argument::addAttr() */ -void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA); +void LLVMAddAttribute(LLVMValueRef Arg, unsigned KindID); /** * Remove an attribute from a function argument. * * @see llvm::Argument::removeAttr() */ -void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA); +void LLVMRemoveAttribute(LLVMValueRef Arg, unsigned KindID); /** * Get an attribute from a function argument. + * This method is DEPRECATED. */ LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg); /** + * Checks if a function argument has a given attribute. + * + * @see llvm::Argument::hasAttribute() + */ +LLVMBool LLVMHasAttribute(LLVMValueRef Arg, unsigned KindID); + +/** * Set the alignment for a function parameter. * * @see llvm::Argument::addAttr() @@ -2520,11 +2550,14 @@ unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr); -void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute); +void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, + unsigned KindID); void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, - LLVMAttribute); + unsigned KindID); void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align); +LLVMBool LLVMHasInstrAttribute(LLVMValueRef Instr, unsigned index, + unsigned KindID); /** * Obtain the pointer to the function invoked by this instruction. Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -1786,10 +1786,10 @@ F->clearGC(); } -void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { +void LLVMAddFunctionAttr(LLVMValueRef Fn, unsigned KindID) { Function *Func = unwrap(Fn); const AttributeSet PAL = Func->getAttributes(); - AttrBuilder B(PA); + AttrBuilder B((LLVMAttribute)KindID); const AttributeSet PALnew = PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex, AttributeSet::get(Func->getContext(), @@ -1809,10 +1809,10 @@ Func->addAttributes(Idx, Set); } -void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) { +void LLVMRemoveFunctionAttr(LLVMValueRef Fn, unsigned KindID) { Function *Func = unwrap(Fn); const AttributeSet PAL = Func->getAttributes(); - AttrBuilder B(PA); + AttrBuilder B((LLVMAttribute)KindID); const AttributeSet PALnew = PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex, AttributeSet::get(Func->getContext(), @@ -1826,6 +1826,38 @@ return (LLVMAttribute)PAL.Raw(AttributeSet::FunctionIndex); } +LLVMBool LLVMHasFunctionAttr(LLVMValueRef Fn, unsigned KindID) { + return LLVMGetFunctionAttr(Fn) | KindID; +} + +void LLVMAddReturnAttr(LLVMValueRef Fn, unsigned KindID) { + Function *Func = unwrap(Fn); + const AttributeSet PAL = Func->getAttributes(); + AttrBuilder B((LLVMAttribute)KindID); + const AttributeSet PALnew = + PAL.addAttributes(Func->getContext(), AttributeSet::ReturnIndex, + AttributeSet::get(Func->getContext(), + AttributeSet::FunctionIndex, B)); + Func->setAttributes(PALnew); +} + +void LLVMRemoveReturnAttr(LLVMValueRef Fn, unsigned KindID) { + Function *Func = unwrap(Fn); + const AttributeSet PAL = Func->getAttributes(); + AttrBuilder B((LLVMAttribute)KindID); + const AttributeSet PALnew = + PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex, + AttributeSet::get(Func->getContext(), + AttributeSet::FunctionIndex, B)); + Func->setAttributes(PALnew); +} + +LLVMBool LLVMHasReturnAttr(LLVMValueRef Fn, unsigned KindID) { + Function *Func = unwrap(Fn); + const AttributeSet PAL = Func->getAttributes(); + return PAL.Raw(AttributeSet::FunctionIndex) | KindID; +} + /*--.. Operations on parameters ............................................--*/ unsigned LLVMCountParams(LLVMValueRef FnRef) { @@ -1884,15 +1916,15 @@ return wrap(&*--I); } -void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) { +void LLVMAddAttribute(LLVMValueRef Arg, unsigned KindID) { Argument *A = unwrap(Arg); - AttrBuilder B(PA); + AttrBuilder B((LLVMAttribute)KindID); A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B)); } -void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) { +void LLVMRemoveAttribute(LLVMValueRef Arg, unsigned KindID) { Argument *A = unwrap(Arg); - AttrBuilder B(PA); + AttrBuilder B((LLVMAttribute)KindID); A->removeAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B)); } @@ -1902,6 +1934,9 @@ Raw(A->getArgNo()+1); } +LLVMBool LLVMHasAttribute(LLVMValueRef Arg, unsigned KindID) { + return LLVMGetAttribute(Arg) | KindID; +} void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) { Argument *A = unwrap(Arg); @@ -2112,9 +2147,9 @@ } void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, - LLVMAttribute PA) { + unsigned KindID) { CallSite Call = CallSite(unwrap(Instr)); - AttrBuilder B(PA); + AttrBuilder B((LLVMAttribute)KindID); Call.setAttributes( Call.getAttributes().addAttributes(Call->getContext(), index, AttributeSet::get(Call->getContext(), @@ -2122,15 +2157,22 @@ } void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, - LLVMAttribute PA) { + unsigned KindID) { CallSite Call = CallSite(unwrap(Instr)); - AttrBuilder B(PA); + AttrBuilder B((LLVMAttribute)KindID); Call.setAttributes(Call.getAttributes() .removeAttributes(Call->getContext(), index, AttributeSet::get(Call->getContext(), index, B))); } +LLVMBool LLVMHasInstrAttribute(LLVMValueRef Instr, unsigned index, + unsigned KindID) { + CallSite Call = CallSite(unwrap(Instr)); + const AttributeSet PAL = Call.getAttributes(); + return PAL.Raw(index) | KindID; +} + void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, unsigned align) { CallSite Call = CallSite(unwrap(Instr));