Index: bindings/go/llvm/ir.go =================================================================== --- bindings/go/llvm/ir.go +++ bindings/go/llvm/ir.go @@ -115,56 +115,6 @@ } //------------------------------------------------------------------------- -// llvm.Attribute -//------------------------------------------------------------------------- - -const ( - NoneAttribute Attribute = 0 - ZExtAttribute Attribute = C.LLVMZExtAttribute - SExtAttribute Attribute = C.LLVMSExtAttribute - NoReturnAttribute Attribute = C.LLVMNoReturnAttribute - InRegAttribute Attribute = C.LLVMInRegAttribute - StructRetAttribute Attribute = C.LLVMStructRetAttribute - NoUnwindAttribute Attribute = C.LLVMNoUnwindAttribute - NoAliasAttribute Attribute = C.LLVMNoAliasAttribute - ByValAttribute Attribute = C.LLVMByValAttribute - NestAttribute Attribute = C.LLVMNestAttribute - ReadNoneAttribute Attribute = C.LLVMReadNoneAttribute - ReadOnlyAttribute Attribute = C.LLVMReadOnlyAttribute - NoInlineAttribute Attribute = C.LLVMNoInlineAttribute - AlwaysInlineAttribute Attribute = C.LLVMAlwaysInlineAttribute - OptimizeForSizeAttribute Attribute = C.LLVMOptimizeForSizeAttribute - StackProtectAttribute Attribute = C.LLVMStackProtectAttribute - StackProtectReqAttribute Attribute = C.LLVMStackProtectReqAttribute - Alignment Attribute = C.LLVMAlignment - NoCaptureAttribute Attribute = C.LLVMNoCaptureAttribute - NoRedZoneAttribute Attribute = C.LLVMNoRedZoneAttribute - NoImplicitFloatAttribute Attribute = C.LLVMNoImplicitFloatAttribute - NakedAttribute Attribute = C.LLVMNakedAttribute - InlineHintAttribute Attribute = C.LLVMInlineHintAttribute - StackAlignment Attribute = C.LLVMStackAlignment - ReturnsTwiceAttribute Attribute = C.LLVMReturnsTwice - UWTableAttribute Attribute = C.LLVMUWTable - NonLazyBindAttribute Attribute = 1 << 31 - SanitizeAddressAttribute Attribute = 1 << 32 - MinSizeAttribute Attribute = 1 << 33 - NoDuplicateAttribute Attribute = 1 << 34 - StackProtectStrongAttribute Attribute = 1 << 35 - SanitizeThreadAttribute Attribute = 1 << 36 - SanitizeMemoryAttribute Attribute = 1 << 37 - NoBuiltinAttribute Attribute = 1 << 38 - ReturnedAttribute Attribute = 1 << 39 - ColdAttribute Attribute = 1 << 40 - BuiltinAttribute Attribute = 1 << 41 - OptimizeNoneAttribute Attribute = 1 << 42 - InAllocaAttribute Attribute = 1 << 43 - NonNullAttribute Attribute = 1 << 44 - JumpTableAttribute Attribute = 1 << 45 - ConvergentAttribute Attribute = 1 << 46 - SafeStackAttribute Attribute = 1 << 47 -) - -//------------------------------------------------------------------------- // llvm.Opcode //------------------------------------------------------------------------- @@ -1142,17 +1092,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: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -55,51 +55,6 @@ */ typedef enum { - LLVMZExtAttribute = 1<<0, - LLVMSExtAttribute = 1<<1, - LLVMNoReturnAttribute = 1<<2, - LLVMInRegAttribute = 1<<3, - LLVMStructRetAttribute = 1<<4, - LLVMNoUnwindAttribute = 1<<5, - LLVMNoAliasAttribute = 1<<6, - LLVMByValAttribute = 1<<7, - LLVMNestAttribute = 1<<8, - LLVMReadNoneAttribute = 1<<9, - LLVMReadOnlyAttribute = 1<<10, - LLVMNoInlineAttribute = 1<<11, - LLVMAlwaysInlineAttribute = 1<<12, - LLVMOptimizeForSizeAttribute = 1<<13, - LLVMStackProtectAttribute = 1<<14, - LLVMStackProtectReqAttribute = 1<<15, - LLVMAlignment = 31<<16, - LLVMNoCaptureAttribute = 1<<21, - LLVMNoRedZoneAttribute = 1<<22, - LLVMNoImplicitFloatAttribute = 1<<23, - LLVMNakedAttribute = 1<<24, - LLVMInlineHintAttribute = 1<<25, - LLVMStackAlignment = 7<<26, - LLVMReturnsTwice = 1 << 29, - LLVMUWTable = 1 << 30, - LLVMNonLazyBind = 1 << 31 - - /* FIXME: These attributes are currently not included in the C API as - a temporary measure until the API/ABI impact to the C API is understood - and the path forward agreed upon. - LLVMSanitizeAddressAttribute = 1ULL << 32, - LLVMStackProtectStrongAttribute = 1ULL<<35, - LLVMColdAttribute = 1ULL << 40, - LLVMOptimizeNoneAttribute = 1ULL << 42, - LLVMInAllocaAttribute = 1ULL << 43, - LLVMNonNullAttribute = 1ULL << 44, - LLVMJumpTableAttribute = 1ULL << 45, - LLVMConvergentAttribute = 1ULL << 46, - LLVMSafeStackAttribute = 1ULL << 47, - LLVMSwiftSelfAttribute = 1ULL << 48, - LLVMSwiftErrorAttribute = 1ULL << 49, - */ -} LLVMAttribute; - -typedef enum { /* Terminator Instructions */ LLVMRet = 1, LLVMBr = 2, @@ -2472,11 +2427,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: include/llvm/IR/CallSite.h =================================================================== --- include/llvm/IR/CallSite.h +++ include/llvm/IR/CallSite.h @@ -305,6 +305,22 @@ CALLSITE_DELEGATE_SETTER(setAttributes(PAL)); } + void addAttribute(unsigned i, Attribute::AttrKind attr) { + CALLSITE_DELEGATE_SETTER(addAttribute(i, attr)); + } + + void addAttribute(unsigned i, StringRef Kind, StringRef Value) { + CALLSITE_DELEGATE_SETTER(addAttribute(i, Kind, Value)); + } + + void removeAttribute(unsigned i, Attribute::AttrKind attr) { + CALLSITE_DELEGATE_SETTER(removeAttribute(i, attr)); + } + + void removeAttribute(unsigned i, Attribute attr) { + CALLSITE_DELEGATE_SETTER(removeAttribute(i, attr)); + } + /// \brief Return true if this function has the given attribute. bool hasFnAttr(Attribute::AttrKind A) const { CALLSITE_DELEGATE_GETTER(hasFnAttr(A)); Index: include/llvm/IR/Instructions.h =================================================================== --- include/llvm/IR/Instructions.h +++ include/llvm/IR/Instructions.h @@ -1625,6 +1625,9 @@ void addAttribute(unsigned i, StringRef Kind, StringRef Value); /// removeAttribute - removes the attribute from the list of attributes. + void removeAttribute(unsigned i, Attribute::AttrKind attr); + + /// removeAttribute - removes the attribute from the list of attributes. void removeAttribute(unsigned i, Attribute attr); /// \brief adds the dereferenceable attribute to the list of attributes. @@ -3558,6 +3561,9 @@ void addAttribute(unsigned i, Attribute::AttrKind attr); /// removeAttribute - removes the attribute from the list of attributes. + void removeAttribute(unsigned i, Attribute::AttrKind attr); + + /// removeAttribute - removes the attribute from the list of attributes. void removeAttribute(unsigned i, Attribute attr); /// \brief adds the dereferenceable attribute to the list of attributes. Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -2100,23 +2100,21 @@ } void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, - LLVMAttribute PA) { + unsigned KindID) { CallSite Call = CallSite(unwrap(Instr)); - AttrBuilder B(PA); - Call.setAttributes( - Call.getAttributes().addAttributes(Call->getContext(), index, - AttributeSet::get(Call->getContext(), - index, B))); + Call.addAttribute(index, (Attribute::AttrKind)KindID); } void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index, - LLVMAttribute PA) { + unsigned KindID) { CallSite Call = CallSite(unwrap(Instr)); - AttrBuilder B(PA); - Call.setAttributes(Call.getAttributes() - .removeAttributes(Call->getContext(), index, - AttributeSet::get(Call->getContext(), - index, B))); + Call.removeAttribute(index, (Attribute::AttrKind)KindID); +} + +LLVMBool LLVMHasInstrAttribute(LLVMValueRef Instr, unsigned index, + unsigned KindID) { + CallSite Call = CallSite(unwrap(Instr)); + return Call.paramHasAttr(index, (Attribute::AttrKind)KindID); } void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, Index: lib/IR/Instructions.cpp =================================================================== --- lib/IR/Instructions.cpp +++ lib/IR/Instructions.cpp @@ -325,6 +325,12 @@ setAttributes(PAL); } +void CallInst::removeAttribute(unsigned i, Attribute::AttrKind attr) { + AttributeSet PAL = getAttributes(); + PAL = PAL.removeAttribute(getContext(), i, attr); + setAttributes(PAL); +} + void CallInst::removeAttribute(unsigned i, Attribute attr) { AttributeSet PAL = getAttributes(); AttrBuilder B(attr); @@ -645,6 +651,12 @@ setAttributes(PAL); } +void InvokeInst::removeAttribute(unsigned i, Attribute::AttrKind attr) { + AttributeSet PAL = getAttributes(); + PAL = PAL.removeAttribute(getContext(), i, attr); + setAttributes(PAL); +} + void InvokeInst::removeAttribute(unsigned i, Attribute attr) { AttributeSet PAL = getAttributes(); AttrBuilder B(attr); Index: test/Bindings/llvm-c/invoke.ll =================================================================== --- test/Bindings/llvm-c/invoke.ll +++ test/Bindings/llvm-c/invoke.ll @@ -21,7 +21,7 @@ define i32 @_D8test01494mainFMZi() personality i32 (i32, i32, i64, i8*, i8*)* @__sd_eh_personality { body: - %0 = invoke i8* @_d_allocmemory(i64 8) + %0 = invoke noalias i8* @_d_allocmemory(i64 8) to label %then unwind label %landingPad then: ; preds = %body @@ -33,7 +33,7 @@ then1: ; preds = %then %3 = bitcast i8* %0 to %C6object9Throwable* - invoke void @__sd_eh_throw(%C6object9Throwable* %3) + invoke void @__sd_eh_throw(%C6object9Throwable* nonnull %3) to label %then2 unwind label %landingPad then2: ; preds = %then1 @@ -46,7 +46,7 @@ catch %C6object9ClassInfo* @C6object9Exception__ClassInfo catch %C6object9ClassInfo* @C6object9Throwable__ClassInfo %5 = extractvalue { i8*, i32 } %4, 1 - %6 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%C6object9ClassInfo* @C6object5Error__ClassInfo to i8*)) + %6 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object5Error__ClassInfo to i8*)) %7 = icmp eq i32 %6, %5 br i1 %7, label %catch, label %unwind3 @@ -55,12 +55,12 @@ ret i32 %merge unwind3: ; preds = %landingPad - %8 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*)) + %8 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*)) %9 = icmp eq i32 %8, %5 br i1 %9, label %catch, label %unwind5 unwind5: ; preds = %unwind3 - %10 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*)) + %10 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*)) %11 = icmp eq i32 %10, %5 br i1 %11, label %catch, label %unwind7 Index: tools/llvm-c-test/echo.cpp =================================================================== --- tools/llvm-c-test/echo.cpp +++ tools/llvm-c-test/echo.cpp @@ -355,6 +355,17 @@ return Dst; } + void CloneAttrs(LLVMValueRef Src, LLVMValueRef Dst) { + int ArgCount = LLVMGetNumArgOperands(Src); + for (unsigned k = 0, e = LLVMGetEndAttrKind(); k < e; ++k) { + // NB: 0 is the return value attribute. Arguments are 1 - ArgCount. + for (int i = 0; i <= ArgCount; i++) { + if (LLVMHasInstrAttribute(Src, i, k)) + LLVMAddInstrAttribute(Dst, i, k); + } + } + } + LLVMValueRef CloneInstruction(LLVMValueRef Src, LLVMBuilderRef Builder) { const char *Name = LLVMGetValueName(Src); if (!LLVMIsAInstruction(Src)) @@ -417,6 +428,7 @@ LLVMBasicBlockRef Unwind = DeclareBB(LLVMGetUnwindDest(Src)); Dst = LLVMBuildInvoke(Builder, Fn, Args.data(), ArgCount, Then, Unwind, Name); + CloneAttrs(Src, Dst); break; } case LLVMUnreachable: @@ -577,6 +589,7 @@ LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src)); Dst = LLVMBuildCall(Builder, Fn, Args.data(), ArgCount, Name); LLVMSetTailCall(Dst, LLVMIsTailCall(Src)); + CloneAttrs(Src, Dst); break; } case LLVMResume: {