llvm.org GIT mirror llvm / ca66910
Make sure we have a Add/Remove/Has function for various thing that can have attribute. Summary: This also deprecated the get attribute function familly. Reviewers: Wallbraker, whitequark, joker.eph, echristo, rafael, jyknight Subscribers: axw, joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D19181 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272504 91177308-0d34-0410-b5e6-96231b3b80d8 Amaury Sechet 4 years ago
10 changed file(s) with 210 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
5353 * The C API function LLVMGetDataLayout is deprecated
5454 in favor of LLVMGetDataLayoutStr.
5555
56 * The C API enum LLVMAttribute is deprecated in favor of
57 LLVMGetAttributeKindForName.
56 * The C API enum LLVMAttribute and associated API is deprecated in favor of
57 the new LLVMAttributeRef API. The deprecated functions are
58 LLVMAddFunctionAttr, LLVMAddTargetDependentFunctionAttr,
59 LLVMRemoveFunctionAttr, LLVMGetFunctionAttr, LLVMAddAttribute,
60 LLVMRemoveAttribute, LLVMGetAttribute, LLVMAddInstrAttribute and
61 LLVMRemoveInstrAttribute.
5862
5963 * ``TargetFrameLowering::eliminateCallFramePseudoInstr`` now returns an
6064 iterator to the next instruction instead of ``void``. Targets that previously
2020 #include "llvm/ADT/Optional.h"
2121 #include "llvm/Support/Compiler.h"
2222 #include "llvm/Support/PointerLikeTypeTraits.h"
23 #include "llvm-c/Types.h"
2324 #include
2425 #include
2526 #include
168169 void Profile(FoldingSetNodeID &ID) const {
169170 ID.AddPointer(pImpl);
170171 }
172
173 /// \brief Return a raw pointer that uniquely identifies this attribute.
174 void *getRawPointer() const {
175 return pImpl;
176 }
177
178 /// \brief Get an attribute from a raw pointer created by getRawPointer.
179 static Attribute fromRawPointer(void *RawPtr) {
180 return Attribute(reinterpret_cast(RawPtr));
181 }
171182 };
183
184 // Specialized opaque value conversions.
185 inline LLVMAttributeRef wrap(Attribute Attr) {
186 return reinterpret_cast(Attr.getRawPointer());
187 }
188
189 // Specialized opaque value conversions.
190 inline Attribute unwrap(LLVMAttributeRef Attr) {
191 return Attribute::fromRawPointer(Attr);
192 }
172193
173194 //===----------------------------------------------------------------------===//
174195 /// \class
204204
205205 /// @brief Return the attribute for the given attribute kind.
206206 Attribute getFnAttribute(Attribute::AttrKind Kind) const {
207 if (!hasFnAttribute(Kind))
208 return Attribute();
209 return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
207 return getAttribute(AttributeSet::FunctionIndex, Kind);
210208 }
211209 Attribute getFnAttribute(StringRef Kind) const {
212 return AttributeSets.getAttribute(AttributeSet::FunctionIndex, Kind);
210 return getAttribute(AttributeSet::FunctionIndex, Kind);
213211 }
214212
215213 /// \brief Return the stack alignment for the function.
231229 /// @brief adds the attribute to the list of attributes.
232230 void addAttribute(unsigned i, Attribute::AttrKind attr);
233231
232 /// @brief adds the attribute to the list of attributes.
233 void addAttribute(unsigned i, Attribute Attr);
234
234235 /// @brief adds the attributes to the list of attributes.
235236 void addAttributes(unsigned i, AttributeSet attrs);
236237
243244 /// @brief check if an attributes is in the list of attributes.
244245 bool hasAttribute(unsigned i, Attribute::AttrKind attr) const {
245246 return getAttributes().hasAttribute(i, attr);
247 }
248
249 Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
250 return AttributeSets.getAttribute(i, Kind);
251 }
252
253 Attribute getAttribute(unsigned i, StringRef Kind) const {
254 return AttributeSets.getAttribute(i, Kind);
246255 }
247256
248257 /// @brief adds the dereferenceable attribute to the list of attributes.
380380 } LLVMDiagnosticSeverity;
381381
382382 /**
383 * Attribute index are either LLVMAttributeReturnIndex,
384 * LLVMAttributeFunctionIndex or a parameter number from 1 to N.
385 */
386 enum {
387 LLVMAttributeReturnIndex = 0U,
388 // ISO C restricts enumerator values to range of 'int'
389 // (4294967295 is too large)
390 // LLVMAttributeFunctionIndex = ~0U,
391 LLVMAttributeFunctionIndex = -1,
392 };
393
394 typedef unsigned LLVMAttributeIndex;
395
396 /**
383397 * @}
384398 */
385399
476490 unsigned LLVMGetMDKindID(const char *Name, unsigned SLen);
477491
478492 /**
479 * Return an unique id given the name of a target independent attribute,
493 * Return an unique id given the name of a enum attribute,
480494 * or 0 if no attribute by that name exists.
481495 *
482496 * See http://llvm.org/docs/LangRef.html#parameter-attributes
486500 * NB: Attribute names and/or id are subject to change without
487501 * going through the C API deprecation cycle.
488502 */
489 unsigned LLVMGetAttributeKindForName(const char *Name, size_t SLen);
503 unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen);
504 unsigned LLVMGetLastEnumAttributeKind();
505
506 /**
507 * Create an enum attribute.
508 */
509 LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
510 uint64_t Val);
511
512 /**
513 * Get the unique id corresponding to the enum attribute
514 * passed as argument.
515 */
516 unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A);
517
518 /**
519 * Get the enum attribute's value. 0 is returned if none exists.
520 */
521 uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A);
522
523 /**
524 * Create a string attribute.
525 */
526 LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
527 const char *K, unsigned KLength,
528 const char *V, unsigned VLength);
529
530 /**
531 * Get the string attribute's kind.
532 */
533 const char *LLVMGetStringAttributeKind(LLVMAttributeRef A, unsigned *Length);
534
535 /**
536 * Get the string attribute's value.
537 */
538 const char *LLVMGetStringAttributeValue(LLVMAttributeRef A, unsigned *Length);
539
540 /**
541 * Check for the different types of attributes.
542 */
543 LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A);
544 LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A);
490545
491546 /**
492547 * @}
19562011 */
19572012 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA);
19582013
2014 void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2015 LLVMAttributeRef A);
2016 LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
2017 LLVMAttributeIndex Idx,
2018 unsigned KindID);
2019 void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
2020 unsigned KindID);
2021
19592022 /**
19602023 * Add a target-dependent attribute to a function
19612024 * @see llvm::AttrBuilder::addAttribute()
108108 typedef struct LLVMOpaqueUse *LLVMUseRef;
109109
110110 /**
111 * Used to represent an attributes.
112 *
113 * @see llvm::Attribute
114 */
115 typedef struct LLVMOpaqueAttributeRef *LLVMAttributeRef;
116
117 /**
111118 * @see llvm::DiagnosticInfo
112119 */
113120 typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
175175 void operator delete(void *p) { ::operator delete(p); }
176176
177177 static AttributeSetNode *get(LLVMContext &C, ArrayRef Attrs);
178
179 /// \brief Return the number of attributes this AttributeSet contains.
180 unsigned getNumAttributes() const { return NumAttrs; }
178181
179182 bool hasAttribute(Attribute::AttrKind Kind) const {
180183 return AvailableAttrs & ((uint64_t)1) << Kind;
123123 #define GET_ATTR_KIND_FROM_NAME
124124 #include "AttributesCompatFunc.inc"
125125
126 unsigned LLVMGetAttributeKindForName(const char *Name, size_t SLen) {
126 unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen) {
127127 return getAttrKindFromName(StringRef(Name, SLen));
128 }
129
130 unsigned LLVMGetLastEnumAttributeKind() {
131 return Attribute::AttrKind::EndAttrKinds;
132 }
133
134 LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID,
135 uint64_t Val) {
136 return wrap(Attribute::get(*unwrap(C), (Attribute::AttrKind)KindID, Val));
137 }
138
139 unsigned LLVMGetEnumAttributeKind(LLVMAttributeRef A) {
140 return unwrap(A).getKindAsEnum();
141 }
142
143 uint64_t LLVMGetEnumAttributeValue(LLVMAttributeRef A) {
144 auto Attr = unwrap(A);
145 if (Attr.isEnumAttribute())
146 return 0;
147 return Attr.getValueAsInt();
148 }
149
150 LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
151 const char *K, unsigned KLength,
152 const char *V, unsigned VLength) {
153 return wrap(Attribute::get(*unwrap(C), StringRef(K, KLength),
154 StringRef(V, VLength)));
155 }
156
157 const char *LLVMGetStringAttributeKind(LLVMAttributeRef A,
158 unsigned *Length) {
159 auto S = unwrap(A).getKindAsString();
160 *Length = S.size();
161 return S.data();
162 }
163
164 const char *LLVMGetStringAttributeValue(LLVMAttributeRef A,
165 unsigned *Length) {
166 auto S = unwrap(A).getValueAsString();
167 *Length = S.size();
168 return S.data();
169 }
170
171 LLVMBool LLVMIsEnumAttribute(LLVMAttributeRef A) {
172 auto Attr = unwrap(A);
173 return Attr.isEnumAttribute() || Attr.isIntAttribute();
174 }
175
176 LLVMBool LLVMIsStringAttribute(LLVMAttributeRef A) {
177 return unwrap(A).isStringAttribute();
128178 }
129179
130180 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
17881838 Func->setAttributes(PALnew);
17891839 }
17901840
1841 void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
1842 LLVMAttributeRef A) {
1843 unwrap(F)->addAttribute(Idx, unwrap(A));
1844 }
1845
1846 LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
1847 LLVMAttributeIndex Idx,
1848 unsigned KindID) {
1849 return wrap(unwrap(F)->getAttribute(Idx,
1850 (Attribute::AttrKind)KindID));
1851 }
1852
1853 void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
1854 unsigned KindID) {
1855 unwrap(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
1856 }
1857
17911858 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
17921859 const char *V) {
17931860 Function *Func = unwrap(Fn);
18921959 return (LLVMAttribute)A->getParent()->getAttributes().
18931960 Raw(A->getArgNo()+1);
18941961 }
1895
18961962
18971963 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
18981964 Argument *A = unwrap(Arg);
368368 void Function::addAttribute(unsigned i, Attribute::AttrKind attr) {
369369 AttributeSet PAL = getAttributes();
370370 PAL = PAL.addAttribute(getContext(), i, attr);
371 setAttributes(PAL);
372 }
373
374 void Function::addAttribute(unsigned i, Attribute Attr) {
375 AttributeSet PAL = getAttributes();
376 PAL = PAL.addAttribute(getContext(), i, Attr);
371377 setAttributes(PAL);
372378 }
373379
6969
7070 declare void @_D6object6Object6__ctorFMC6object6ObjectZv(%C6object6Object*)
7171
72 declare i8* @_d_allocmemory(i64)
72 declare noalias i8* @_d_allocmemory(i64)
7373
7474 declare i32 @__sd_eh_personality(i32, i32, i64, i8*, i8*)
7575
76 declare void @__sd_eh_throw(%C6object9Throwable*)
76 declare void @__sd_eh_throw(%C6object9Throwable* nonnull) #0
7777
7878 ; Function Attrs: nounwind readnone
79 declare i32 @llvm.eh.typeid.for(i8*) #0
79 declare i32 @llvm.eh.typeid.for(i8*) #1
8080
81 attributes #0 = { nounwind readnone }
81 attributes #0 = { noreturn }
82 attributes #1 = { nounwind readnone }
781781 return;
782782 }
783783
784 auto Ctx = LLVMGetModuleContext(M);
785
784786 Cur = Begin;
785787 Next = nullptr;
786788 while (true) {
787789 const char *Name = LLVMGetValueName(Cur);
788790 if (LLVMGetNamedFunction(M, Name))
789791 report_fatal_error("Function already cloned");
790 LLVMAddFunction(M, Name, LLVMGetElementType(TypeCloner(M).Clone(Cur)));
792 auto Ty = LLVMGetElementType(TypeCloner(M).Clone(Cur));
793 auto F = LLVMAddFunction(M, Name, Ty);
794
795 // Copy attributes
796 for (int i = LLVMAttributeFunctionIndex, c = LLVMCountParams(F);
797 i <= c; ++i) {
798 for (unsigned k = 0, e = LLVMGetLastEnumAttributeKind(); k < e; ++k) {
799 if (auto SrcA = LLVMGetEnumAttributeAtIndex(Cur, i, k)) {
800 auto Val = LLVMGetEnumAttributeValue(SrcA);
801 auto DstA = LLVMCreateEnumAttribute(Ctx, k, Val);
802 LLVMAddAttributeAtIndex(F, i, DstA);
803 }
804 }
805 }
791806
792807 Next = LLVMGetNextFunction(Cur);
793808 if (Next == nullptr) {