Attributes.td 9.9 KB

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