Attributes.td 13 KB

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