Attributes.td 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. //===- Attributes.td - Defines all LLVM attributes ---------*- tablegen -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines all the LLVM attributes.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. /// Attribute property base class.
  13. class AttrProperty;
  14. /// Can be used as function attribute.
  15. def FnAttr : AttrProperty;
  16. /// Can be used as parameter attribute.
  17. def ParamAttr : AttrProperty;
  18. /// Can be used as return attribute.
  19. def RetAttr : AttrProperty;
  20. /// Attribute base class.
  21. class Attr<string S, list<AttrProperty> P> {
  22. // String representation of this attribute in the IR.
  23. string AttrString = S;
  24. list<AttrProperty> Properties = P;
  25. }
  26. /// Enum attribute.
  27. class EnumAttr<string S, list<AttrProperty> P> : Attr<S, P>;
  28. /// Int attribute.
  29. class IntAttr<string S, list<AttrProperty> P> : Attr<S, P>;
  30. /// Type attribute.
  31. class TypeAttr<string S, list<AttrProperty> P> : Attr<S, P>;
  32. /// StringBool attribute.
  33. class StrBoolAttr<string S> : Attr<S, []>;
  34. /// Target-independent enum attributes.
  35. /// Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias.
  36. /// 0 means unaligned (different from align(1)).
  37. def Alignment : IntAttr<"align", [ParamAttr, RetAttr]>;
  38. /// The result of the function is guaranteed to point to a number of bytes that
  39. /// we can determine if we know the value of the function's arguments.
  40. def AllocSize : IntAttr<"allocsize", [FnAttr]>;
  41. /// inline=always.
  42. def AlwaysInline : EnumAttr<"alwaysinline", [FnAttr]>;
  43. /// Function can access memory only using pointers based on its arguments.
  44. def ArgMemOnly : EnumAttr<"argmemonly", [FnAttr]>;
  45. /// Callee is recognized as a builtin, despite nobuiltin attribute on its
  46. /// declaration.
  47. def Builtin : EnumAttr<"builtin", [FnAttr]>;
  48. /// Pass structure by value.
  49. def ByVal : TypeAttr<"byval", [ParamAttr]>;
  50. /// Mark in-memory ABI type.
  51. def ByRef : TypeAttr<"byref", [ParamAttr]>;
  52. /// Parameter or return value may not contain uninitialized or poison bits.
  53. def NoUndef : EnumAttr<"noundef", [ParamAttr, RetAttr]>;
  54. /// Marks function as being in a cold path.
  55. def Cold : EnumAttr<"cold", [FnAttr]>;
  56. /// Can only be moved to control-equivalent blocks.
  57. def Convergent : EnumAttr<"convergent", [FnAttr]>;
  58. /// Marks function as being in a hot path and frequently called.
  59. def Hot: EnumAttr<"hot", [FnAttr]>;
  60. /// Pointer is known to be dereferenceable.
  61. def Dereferenceable : IntAttr<"dereferenceable", [ParamAttr, RetAttr]>;
  62. /// Pointer is either null or dereferenceable.
  63. def DereferenceableOrNull : IntAttr<"dereferenceable_or_null",
  64. [ParamAttr, RetAttr]>;
  65. /// Do not instrument function with sanitizers.
  66. def DisableSanitizerInstrumentation: EnumAttr<"disable_sanitizer_instrumentation", [FnAttr]>;
  67. /// Provide pointer element type to intrinsic.
  68. def ElementType : TypeAttr<"elementtype", [ParamAttr]>;
  69. /// Function may only access memory that is inaccessible from IR.
  70. def InaccessibleMemOnly : EnumAttr<"inaccessiblememonly", [FnAttr]>;
  71. /// Function may only access memory that is either inaccessible from the IR,
  72. /// or pointed to by its pointer arguments.
  73. def InaccessibleMemOrArgMemOnly : EnumAttr<"inaccessiblemem_or_argmemonly",
  74. [FnAttr]>;
  75. /// Pass structure in an alloca.
  76. def InAlloca : TypeAttr<"inalloca", [ParamAttr]>;
  77. /// Source said inlining was desirable.
  78. def InlineHint : EnumAttr<"inlinehint", [FnAttr]>;
  79. /// Force argument to be passed in register.
  80. def InReg : EnumAttr<"inreg", [ParamAttr, RetAttr]>;
  81. /// Build jump-instruction tables and replace refs.
  82. def JumpTable : EnumAttr<"jumptable", [FnAttr]>;
  83. /// Function must be optimized for size first.
  84. def MinSize : EnumAttr<"minsize", [FnAttr]>;
  85. /// Naked function.
  86. def Naked : EnumAttr<"naked", [FnAttr]>;
  87. /// Nested function static chain.
  88. def Nest : EnumAttr<"nest", [ParamAttr]>;
  89. /// Considered to not alias after call.
  90. def NoAlias : EnumAttr<"noalias", [ParamAttr, RetAttr]>;
  91. /// Callee isn't recognized as a builtin.
  92. def NoBuiltin : EnumAttr<"nobuiltin", [FnAttr]>;
  93. /// Function cannot enter into caller's translation unit.
  94. def NoCallback : EnumAttr<"nocallback", [FnAttr]>;
  95. /// Function creates no aliases of pointer.
  96. def NoCapture : EnumAttr<"nocapture", [ParamAttr]>;
  97. /// Call cannot be duplicated.
  98. def NoDuplicate : EnumAttr<"noduplicate", [FnAttr]>;
  99. /// Function does not deallocate memory.
  100. def NoFree : EnumAttr<"nofree", [FnAttr, ParamAttr]>;
  101. /// Disable implicit floating point insts.
  102. def NoImplicitFloat : EnumAttr<"noimplicitfloat", [FnAttr]>;
  103. /// inline=never.
  104. def NoInline : EnumAttr<"noinline", [FnAttr]>;
  105. /// Function is called early and/or often, so lazy binding isn't worthwhile.
  106. def NonLazyBind : EnumAttr<"nonlazybind", [FnAttr]>;
  107. /// Disable merging for specified functions or call sites.
  108. def NoMerge : EnumAttr<"nomerge", [FnAttr]>;
  109. /// Pointer is known to be not null.
  110. def NonNull : EnumAttr<"nonnull", [ParamAttr, RetAttr]>;
  111. /// The function does not recurse.
  112. def NoRecurse : EnumAttr<"norecurse", [FnAttr]>;
  113. /// Disable redzone.
  114. def NoRedZone : EnumAttr<"noredzone", [FnAttr]>;
  115. /// Mark the function as not returning.
  116. def NoReturn : EnumAttr<"noreturn", [FnAttr]>;
  117. /// Function does not synchronize.
  118. def NoSync : EnumAttr<"nosync", [FnAttr]>;
  119. /// Disable Indirect Branch Tracking.
  120. def NoCfCheck : EnumAttr<"nocf_check", [FnAttr]>;
  121. /// Function should not be instrumented.
  122. def NoProfile : EnumAttr<"noprofile", [FnAttr]>;
  123. /// Function doesn't unwind stack.
  124. def NoUnwind : EnumAttr<"nounwind", [FnAttr]>;
  125. /// No SanitizeCoverage instrumentation.
  126. def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>;
  127. /// Null pointer in address space zero is valid.
  128. def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>;
  129. /// Select optimizations for best fuzzing signal.
  130. def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>;
  131. /// opt_size.
  132. def OptimizeForSize : EnumAttr<"optsize", [FnAttr]>;
  133. /// Function must not be optimized.
  134. def OptimizeNone : EnumAttr<"optnone", [FnAttr]>;
  135. /// Similar to byval but without a copy.
  136. def Preallocated : TypeAttr<"preallocated", [FnAttr, ParamAttr]>;
  137. /// Function does not access memory.
  138. def ReadNone : EnumAttr<"readnone", [FnAttr, ParamAttr]>;
  139. /// Function only reads from memory.
  140. def ReadOnly : EnumAttr<"readonly", [FnAttr, ParamAttr]>;
  141. /// Return value is always equal to this argument.
  142. def Returned : EnumAttr<"returned", [ParamAttr]>;
  143. /// Parameter is required to be a trivial constant.
  144. def ImmArg : EnumAttr<"immarg", [ParamAttr]>;
  145. /// Function can return twice.
  146. def ReturnsTwice : EnumAttr<"returns_twice", [FnAttr]>;
  147. /// Safe Stack protection.
  148. def SafeStack : EnumAttr<"safestack", [FnAttr]>;
  149. /// Shadow Call Stack protection.
  150. def ShadowCallStack : EnumAttr<"shadowcallstack", [FnAttr]>;
  151. /// Sign extended before/after call.
  152. def SExt : EnumAttr<"signext", [ParamAttr, RetAttr]>;
  153. /// Alignment of stack for function (3 bits) stored as log2 of alignment with
  154. /// +1 bias 0 means unaligned (different from alignstack=(1)).
  155. def StackAlignment : IntAttr<"alignstack", [FnAttr, ParamAttr]>;
  156. /// Function can be speculated.
  157. def Speculatable : EnumAttr<"speculatable", [FnAttr]>;
  158. /// Stack protection.
  159. def StackProtect : EnumAttr<"ssp", [FnAttr]>;
  160. /// Stack protection required.
  161. def StackProtectReq : EnumAttr<"sspreq", [FnAttr]>;
  162. /// Strong Stack protection.
  163. def StackProtectStrong : EnumAttr<"sspstrong", [FnAttr]>;
  164. /// Function was called in a scope requiring strict floating point semantics.
  165. def StrictFP : EnumAttr<"strictfp", [FnAttr]>;
  166. /// Hidden pointer to structure to return.
  167. def StructRet : TypeAttr<"sret", [ParamAttr]>;
  168. /// AddressSanitizer is on.
  169. def SanitizeAddress : EnumAttr<"sanitize_address", [FnAttr]>;
  170. /// ThreadSanitizer is on.
  171. def SanitizeThread : EnumAttr<"sanitize_thread", [FnAttr]>;
  172. /// MemorySanitizer is on.
  173. def SanitizeMemory : EnumAttr<"sanitize_memory", [FnAttr]>;
  174. /// HWAddressSanitizer is on.
  175. def SanitizeHWAddress : EnumAttr<"sanitize_hwaddress", [FnAttr]>;
  176. /// MemTagSanitizer is on.
  177. def SanitizeMemTag : EnumAttr<"sanitize_memtag", [FnAttr]>;
  178. /// Speculative Load Hardening is enabled.
  179. ///
  180. /// Note that this uses the default compatibility (always compatible during
  181. /// inlining) and a conservative merge strategy where inlining an attributed
  182. /// body will add the attribute to the caller. This ensures that code carrying
  183. /// this attribute will always be lowered with hardening enabled.
  184. def SpeculativeLoadHardening : EnumAttr<"speculative_load_hardening",
  185. [FnAttr]>;
  186. /// Argument is swift error.
  187. def SwiftError : EnumAttr<"swifterror", [ParamAttr]>;
  188. /// Argument is swift self/context.
  189. def SwiftSelf : EnumAttr<"swiftself", [ParamAttr]>;
  190. /// Argument is swift async context.
  191. def SwiftAsync : EnumAttr<"swiftasync", [ParamAttr]>;
  192. /// Function must be in a unwind table.
  193. def UWTable : EnumAttr<"uwtable", [FnAttr]>;
  194. /// Minimum/Maximum vscale value for function.
  195. def VScaleRange : IntAttr<"vscale_range", [FnAttr]>;
  196. /// Function always comes back to callsite.
  197. def WillReturn : EnumAttr<"willreturn", [FnAttr]>;
  198. /// Function only writes to memory.
  199. def WriteOnly : EnumAttr<"writeonly", [FnAttr, ParamAttr]>;
  200. /// Zero extended before/after call.
  201. def ZExt : EnumAttr<"zeroext", [ParamAttr, RetAttr]>;
  202. /// Function is required to make Forward Progress.
  203. def MustProgress : EnumAttr<"mustprogress", [FnAttr]>;
  204. /// Target-independent string attributes.
  205. def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;
  206. def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">;
  207. def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">;
  208. def NoSignedZerosFPMath : StrBoolAttr<"no-signed-zeros-fp-math">;
  209. def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">;
  210. def NoJumpTables : StrBoolAttr<"no-jump-tables">;
  211. def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">;
  212. def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">;
  213. def UseSampleProfile : StrBoolAttr<"use-sample-profile">;
  214. class CompatRule<string F> {
  215. // The name of the function called to check the attribute of the caller and
  216. // callee and decide whether inlining should be allowed. The function's
  217. // signature must match "bool(const Function&, const Function &)", where the
  218. // first parameter is the reference to the caller and the second parameter is
  219. // the reference to the callee. It must return false if the attributes of the
  220. // caller and callee are incompatible, and true otherwise.
  221. string CompatFunc = F;
  222. }
  223. def : CompatRule<"isEqual<SanitizeAddressAttr>">;
  224. def : CompatRule<"isEqual<SanitizeThreadAttr>">;
  225. def : CompatRule<"isEqual<SanitizeMemoryAttr>">;
  226. def : CompatRule<"isEqual<SanitizeHWAddressAttr>">;
  227. def : CompatRule<"isEqual<SanitizeMemTagAttr>">;
  228. def : CompatRule<"isEqual<SafeStackAttr>">;
  229. def : CompatRule<"isEqual<ShadowCallStackAttr>">;
  230. def : CompatRule<"isEqual<UseSampleProfileAttr>">;
  231. def : CompatRule<"isEqual<NoProfileAttr>">;
  232. class MergeRule<string F> {
  233. // The name of the function called to merge the attributes of the caller and
  234. // callee. The function's signature must match
  235. // "void(Function&, const Function &)", where the first parameter is the
  236. // reference to the caller and the second parameter is the reference to the
  237. // callee.
  238. string MergeFunc = F;
  239. }
  240. def : MergeRule<"setAND<LessPreciseFPMADAttr>">;
  241. def : MergeRule<"setAND<NoInfsFPMathAttr>">;
  242. def : MergeRule<"setAND<NoNansFPMathAttr>">;
  243. def : MergeRule<"setAND<NoSignedZerosFPMathAttr>">;
  244. def : MergeRule<"setAND<UnsafeFPMathAttr>">;
  245. def : MergeRule<"setOR<NoImplicitFloatAttr>">;
  246. def : MergeRule<"setOR<NoJumpTablesAttr>">;
  247. def : MergeRule<"setOR<ProfileSampleAccurateAttr>">;
  248. def : MergeRule<"setOR<SpeculativeLoadHardeningAttr>">;
  249. def : MergeRule<"adjustCallerSSPLevel">;
  250. def : MergeRule<"adjustCallerStackProbes">;
  251. def : MergeRule<"adjustCallerStackProbeSize">;
  252. def : MergeRule<"adjustMinLegalVectorWidth">;
  253. def : MergeRule<"adjustNullPointerValidAttr">;
  254. def : MergeRule<"setAND<MustProgressAttr>">;
  255. // Target dependent attributes
  256. include "llvm/IR/AttributesAMDGPU.td"