llvm.org GIT mirror llvm / 4e14c83
Add support for callsite in the new C API for attributes Summary: The second consumer of attributes. Reviewers: Wallbraker, whitequark, echristo, rafael, jyknight Subscribers: mehdi_amini Differential Revision: http://reviews.llvm.org/D21266 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272754 91177308-0d34-0410-b5e6-96231b3b80d8 Amaury Sechet 4 years ago
7 changed file(s) with 88 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
312312 CALLSITE_DELEGATE_SETTER(addAttribute(i, Kind, Value));
313313 }
314314
315 void addAttribute(unsigned i, Attribute Attr) {
316 CALLSITE_DELEGATE_SETTER(addAttribute(i, Attr));
317 }
318
315319 void removeAttribute(unsigned i, Attribute::AttrKind Kind) {
316320 CALLSITE_DELEGATE_SETTER(removeAttribute(i, Kind));
317321 }
333337 /// \brief Return true if the call or the callee has the given attribute.
334338 bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const {
335339 CALLSITE_DELEGATE_GETTER(paramHasAttr(i, Kind));
340 }
341
342 Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
343 CALLSITE_DELEGATE_GETTER(getAttribute(i, Kind));
336344 }
337345
338346 /// \brief Return true if the data operand at index \p i directly or
16221622 /// addAttribute - adds the attribute to the list of attributes.
16231623 void addAttribute(unsigned i, StringRef Kind, StringRef Value);
16241624
1625 /// addAttribute - adds the attribute to the list of attributes.
1626 void addAttribute(unsigned i, Attribute Attr);
1627
16251628 /// removeAttribute - removes the attribute from the list of attributes.
16261629 void removeAttribute(unsigned i, Attribute::AttrKind Kind);
16271630
16491652
16501653 /// \brief Determine whether the call or the callee has the given attributes.
16511654 bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const;
1655
1656 /// \brief Get the attribute of a given kind at a position.
1657 Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const;
16521658
16531659 /// \brief Return true if the data operand at index \p i has the attribute \p
16541660 /// A.
35633569 /// addAttribute - adds the attribute to the list of attributes.
35643570 void addAttribute(unsigned i, Attribute::AttrKind Kind);
35653571
3572 /// addAttribute - adds the attribute to the list of attributes.
3573 void addAttribute(unsigned i, Attribute Attr);
3574
35663575 /// removeAttribute - removes the attribute from the list of attributes.
35673576 void removeAttribute(unsigned i, Attribute::AttrKind Kind);
35683577
35903599
35913600 /// \brief Determine whether the call or the callee has the given attributes.
35923601 bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const;
3602
3603 /// \brief Get the attribute of a given kind at a position.
3604 Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const;
35933605
35943606 /// \brief Return true if the data operand at index \p i has the attribute \p
35953607 /// A.
25862586 */
25872587 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr);
25882588
2589
25902589 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index, LLVMAttribute);
25912590 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
25922591 LLVMAttribute);
25932592 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
25942593 unsigned Align);
2594
2595 void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2596 LLVMAttributeRef A);
2597 LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
2598 LLVMAttributeIndex Idx,
2599 unsigned KindID);
2600 void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2601 unsigned KindID);
25952602
25962603 /**
25972604 * Obtain the pointer to the function invoked by this instruction.
22002200 index, B)));
22012201 }
22022202
2203 void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2204 LLVMAttributeRef A) {
2205 CallSite(unwrap(C)).addAttribute(Idx, unwrap(A));
2206 }
2207
2208 LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
2209 LLVMAttributeIndex Idx,
2210 unsigned KindID) {
2211 return wrap(CallSite(unwrap(C))
2212 .getAttribute(Idx, (Attribute::AttrKind)KindID));
2213 }
2214
2215 void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
2216 unsigned KindID) {
2217 CallSite(unwrap(C))
2218 .removeAttribute(Idx, (Attribute::AttrKind)KindID);
2219 }
2220
22032221 LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) {
22042222 return wrap(CallSite(unwrap(Instr)).getCalledValue());
22052223 }
342342 setAttributes(PAL);
343343 }
344344
345 void CallInst::addAttribute(unsigned i, Attribute Attr) {
346 AttributeSet PAL = getAttributes();
347 PAL = PAL.addAttribute(getContext(), i, Attr);
348 setAttributes(PAL);
349 }
350
345351 void CallInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
346352 AttributeSet PAL = getAttributes();
347353 PAL = PAL.removeAttribute(getContext(), i, Kind);
377383 if (const Function *F = getCalledFunction())
378384 return F->getAttributes().hasAttribute(i, Kind);
379385 return false;
386 }
387
388 Attribute CallInst::getAttribute(unsigned i, Attribute::AttrKind Kind) const {
389 return getAttributes().getAttribute(i, Kind);
380390 }
381391
382392 bool CallInst::dataOperandHasImpliedAttr(unsigned i,
701711 setAttributes(PAL);
702712 }
703713
714 void InvokeInst::addAttribute(unsigned i, Attribute Attr) {
715 AttributeSet PAL = getAttributes();
716 PAL = PAL.addAttribute(getContext(), i, Attr);
717 setAttributes(PAL);
718 }
719
704720 void InvokeInst::removeAttribute(unsigned i, Attribute::AttrKind Kind) {
705721 AttributeSet PAL = getAttributes();
706722 PAL = PAL.removeAttribute(getContext(), i, Kind);
713729 PAL = PAL.removeAttributes(getContext(), i,
714730 AttributeSet::get(getContext(), i, B));
715731 setAttributes(PAL);
732 }
733
734 Attribute InvokeInst::getAttribute(unsigned i,
735 Attribute::AttrKind Kind) const {
736 return getAttributes().getAttribute(i, Kind);
716737 }
717738
718739 void InvokeInst::addDereferenceableAttr(unsigned i, uint64_t Bytes) {
2020
2121 define i32 @_D8test01494mainFMZi() personality i32 (i32, i32, i64, i8*, i8*)* @__sd_eh_personality {
2222 body:
23 %0 = invoke i8* @_d_allocmemory(i64 8)
23 %0 = invoke noalias i8* @_d_allocmemory(i64 8)
2424 to label %then unwind label %landingPad
2525
2626 then: ; preds = %body
3232
3333 then1: ; preds = %then
3434 %3 = bitcast i8* %0 to %C6object9Throwable*
35 invoke void @__sd_eh_throw(%C6object9Throwable* %3)
35 invoke void @__sd_eh_throw(%C6object9Throwable* nonnull %3)
3636 to label %then2 unwind label %landingPad
3737
3838 then2: ; preds = %then1
4545 catch %C6object9ClassInfo* @C6object9Exception__ClassInfo
4646 catch %C6object9ClassInfo* @C6object9Throwable__ClassInfo
4747 %5 = extractvalue { i8*, i32 } %4, 1
48 %6 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%C6object9ClassInfo* @C6object5Error__ClassInfo to i8*))
48 %6 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object5Error__ClassInfo to i8*))
4949 %7 = icmp eq i32 %6, %5
5050 br i1 %7, label %catch, label %unwind3
5151
5454 ret i32 %merge
5555
5656 unwind3: ; preds = %landingPad
57 %8 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*))
57 %8 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Exception__ClassInfo to i8*))
5858 %9 = icmp eq i32 %8, %5
5959 br i1 %9, label %catch, label %unwind5
6060
6161 unwind5: ; preds = %unwind3
62 %10 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*))
62 %10 = tail call i32 @llvm.eh.typeid.for(i8* nonnull bitcast (%C6object9ClassInfo* @C6object9Throwable__ClassInfo to i8*))
6363 %11 = icmp eq i32 %10, %5
6464 br i1 %11, label %catch, label %unwind7
6565
374374 return Dst;
375375 }
376376
377 void CloneAttrs(LLVMValueRef Src, LLVMValueRef Dst) {
378 auto Ctx = LLVMGetModuleContext(M);
379 int ArgCount = LLVMGetNumArgOperands(Src);
380 for (int i = LLVMAttributeReturnIndex; i <= ArgCount; i++) {
381 for (unsigned k = 0, e = LLVMGetLastEnumAttributeKind(); k < e; ++k) {
382 if (auto SrcA = LLVMGetCallSiteEnumAttribute(Src, i, k)) {
383 auto Val = LLVMGetEnumAttributeValue(SrcA);
384 auto A = LLVMCreateEnumAttribute(Ctx, k, Val);
385 LLVMAddCallSiteAttribute(Dst, i, A);
386 }
387 }
388 }
389 }
390
377391 LLVMValueRef CloneInstruction(LLVMValueRef Src, LLVMBuilderRef Builder) {
378392 check_value_kind(Src, LLVMInstructionValueKind);
379393 if (!LLVMIsAInstruction(Src))
438452 LLVMBasicBlockRef Unwind = DeclareBB(LLVMGetUnwindDest(Src));
439453 Dst = LLVMBuildInvoke(Builder, Fn, Args.data(), ArgCount,
440454 Then, Unwind, Name);
455 CloneAttrs(Src, Dst);
441456 break;
442457 }
443458 case LLVMUnreachable:
598613 LLVMValueRef Fn = CloneValue(LLVMGetCalledValue(Src));
599614 Dst = LLVMBuildCall(Builder, Fn, Args.data(), ArgCount, Name);
600615 LLVMSetTailCall(Dst, LLVMIsTailCall(Src));
616 CloneAttrs(Src, Dst);
601617 break;
602618 }
603619 case LLVMResume: {