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 13/// Attribute property base class. 14class AttrProperty; 15 16/// Can be used as function attribute. 17def FnAttr : AttrProperty; 18 19/// Can be used as parameter attribute. 20def ParamAttr : AttrProperty; 21 22/// Can be used as return attribute. 23def RetAttr : AttrProperty; 24 25 26 27/// Intersection rules. Used for example in sinking/hoisting two 28/// callbases to find a set of attributes that apply to both. 29/// Note, there are some attributes we can (probably) legally drop 30/// but are intentionally excluded as of now. 31/// 32/// When intersecting the attributes both must be present and equal. 33/// Use this for attributes it is not safe to drop at any time. E.g. 34/// `byval(Ty)` on a parameter. 35def IntersectPreserve : AttrProperty; 36 37/// When intersecting take the AND of the two attrs. 38/// Only valid for Enum attrs. 39def IntersectAnd : AttrProperty; 40 41/// When intersecting take the min value of the two attrs. 42/// Only valid for Int attrs. 43def IntersectMin : AttrProperty; 44 45/// When intersecting rely on some specially defined code. 46def IntersectCustom : AttrProperty; 47 48 49 50/// Attribute base class. 51class Attr<string S, AttrProperty I, list<AttrProperty> P> { 52 // String representation of this attribute in the IR. 53 string AttrString = S; 54 list<AttrProperty> Properties = P # [I]; 55} 56 57/// Enum attribute. 58class EnumAttr<string S, AttrProperty I, list<AttrProperty> P> : Attr<S, I, P>; 59 60/// Int attribute. 61class IntAttr<string S, AttrProperty I, list<AttrProperty> P> : Attr<S, I, P>; 62 63/// Type attribute. 64class TypeAttr<string S, AttrProperty I, list<AttrProperty> P> : Attr<S, I, P>; 65 66/// StringBool attribute. 67class StrBoolAttr<string S> : Attr<S, IntersectPreserve, []>; 68 69/// Arbitrary string attribute. 70class ComplexStrAttr<string S, list<AttrProperty> P> : Attr<S, IntersectPreserve, P>; 71 72/// ConstantRange attribute. 73class ConstantRangeAttr<string S, AttrProperty I, list<AttrProperty> P> : Attr<S, I, P>; 74 75/// ConstantRangeList attribute. 76class ConstantRangeListAttr<string S, AttrProperty I, list<AttrProperty> P> : Attr<S, I, P>; 77 78/// Target-independent enum attributes. 79 80/// Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias. 81/// 0 means unaligned (different from align(1)). 82def Alignment : IntAttr<"align", IntersectCustom, [ParamAttr, RetAttr]>; 83 84/// Parameter of a function that tells us the alignment of an allocation, as in 85/// aligned_alloc and aligned ::operator::new. 86def AllocAlign: EnumAttr<"allocalign", IntersectAnd, [ParamAttr]>; 87 88/// Describes behavior of an allocator function in terms of known properties. 89def AllocKind: IntAttr<"allockind", IntersectPreserve, [FnAttr]>; 90 91/// Parameter is the pointer to be manipulated by the allocator function. 92def AllocatedPointer : EnumAttr<"allocptr", IntersectAnd, [ParamAttr]>; 93 94/// The result of the function is guaranteed to point to a number of bytes that 95/// we can determine if we know the value of the function's arguments. 96def AllocSize : IntAttr<"allocsize", IntersectPreserve, [FnAttr]>; 97 98/// inline=always. 99def AlwaysInline : EnumAttr<"alwaysinline", IntersectPreserve, [FnAttr]>; 100 101/// Callee is recognized as a builtin, despite nobuiltin attribute on its 102/// declaration. 103def Builtin : EnumAttr<"builtin", IntersectPreserve, [FnAttr]>; 104 105/// Pass structure by value. 106def ByVal : TypeAttr<"byval", IntersectPreserve, [ParamAttr]>; 107 108/// Mark in-memory ABI type. 109def ByRef : TypeAttr<"byref", IntersectPreserve, [ParamAttr]>; 110 111/// Parameter or return value may not contain uninitialized or poison bits. 112def NoUndef : EnumAttr<"noundef", IntersectAnd, [ParamAttr, RetAttr]>; 113 114/// Marks function as being in a cold path. 115def Cold : EnumAttr<"cold", IntersectAnd, [FnAttr]>; 116 117/// Can only be moved to control-equivalent blocks. 118/// NB: Could be IntersectCustom with "or" handling. 119def Convergent : EnumAttr<"convergent", IntersectPreserve, [FnAttr]>; 120 121/// Marks function as being in a hot path and frequently called. 122def Hot: EnumAttr<"hot", IntersectAnd, [FnAttr]>; 123 124/// Pointer is known to be dereferenceable. 125def Dereferenceable : IntAttr<"dereferenceable", IntersectMin, [ParamAttr, RetAttr]>; 126 127/// Pointer is either null or dereferenceable. 128def DereferenceableOrNull : IntAttr<"dereferenceable_or_null", IntersectMin, 129 [ParamAttr, RetAttr]>; 130 131/// Do not instrument function with sanitizers. 132def DisableSanitizerInstrumentation: EnumAttr<"disable_sanitizer_instrumentation", IntersectPreserve, [FnAttr]>; 133 134/// Provide pointer element type to intrinsic. 135def ElementType : TypeAttr<"elementtype", IntersectPreserve, [ParamAttr]>; 136 137/// Whether to keep return instructions, or replace with a jump to an external 138/// symbol. 139def FnRetThunkExtern : EnumAttr<"fn_ret_thunk_extern", IntersectPreserve, [FnAttr]>; 140 141/// Function has a hybrid patchable thunk. 142def HybridPatchable : EnumAttr<"hybrid_patchable", IntersectPreserve, [FnAttr]>; 143 144/// Pass structure in an alloca. 145def InAlloca : TypeAttr<"inalloca", IntersectPreserve, [ParamAttr]>; 146 147/// Pointer argument memory is initialized. 148def Initializes : ConstantRangeListAttr<"initializes", IntersectPreserve, [ParamAttr]>; 149 150/// Source said inlining was desirable. 151def InlineHint : EnumAttr<"inlinehint", IntersectAnd, [FnAttr]>; 152 153/// Force argument to be passed in register. 154def InReg : EnumAttr<"inreg", IntersectPreserve, [ParamAttr, RetAttr]>; 155 156/// Build jump-instruction tables and replace refs. 157def JumpTable : EnumAttr<"jumptable", IntersectPreserve, [FnAttr]>; 158 159/// Memory effects of the function. 160def Memory : IntAttr<"memory", IntersectCustom, [FnAttr]>; 161 162/// Forbidden floating-point classes. 163def NoFPClass : IntAttr<"nofpclass", IntersectCustom, [ParamAttr, RetAttr]>; 164 165/// Function must be optimized for size first. 166def MinSize : EnumAttr<"minsize", IntersectPreserve, [FnAttr]>; 167 168/// Naked function. 169def Naked : EnumAttr<"naked", IntersectPreserve, [FnAttr]>; 170 171/// Nested function static chain. 172def Nest : EnumAttr<"nest", IntersectPreserve, [ParamAttr]>; 173 174/// Considered to not alias after call. 175def NoAlias : EnumAttr<"noalias", IntersectAnd, [ParamAttr, RetAttr]>; 176 177/// Callee isn't recognized as a builtin. 178def NoBuiltin : EnumAttr<"nobuiltin", IntersectPreserve, [FnAttr]>; 179 180/// Function cannot enter into caller's translation unit. 181def NoCallback : EnumAttr<"nocallback", IntersectAnd, [FnAttr]>; 182 183/// Specify how the pointer may be captured. 184def Captures : IntAttr<"captures", IntersectCustom, [ParamAttr]>; 185 186/// Function is not a source of divergence. 187def NoDivergenceSource : EnumAttr<"nodivergencesource", IntersectAnd, [FnAttr]>; 188 189/// Call cannot be duplicated. 190def NoDuplicate : EnumAttr<"noduplicate", IntersectPreserve, [FnAttr]>; 191 192/// No extension needed before/after call (high bits are undefined). 193def NoExt : EnumAttr<"noext", IntersectPreserve, [ParamAttr, RetAttr]>; 194 195/// Function does not deallocate memory. 196def NoFree : EnumAttr<"nofree", IntersectAnd, [FnAttr, ParamAttr]>; 197 198/// Argument is dead if the call unwinds. 199def DeadOnUnwind : EnumAttr<"dead_on_unwind", IntersectAnd, [ParamAttr]>; 200 201/// Disable implicit floating point insts. 202def NoImplicitFloat : EnumAttr<"noimplicitfloat", IntersectPreserve, [FnAttr]>; 203 204/// inline=never. 205def NoInline : EnumAttr<"noinline", IntersectPreserve, [FnAttr]>; 206 207/// Function is called early and/or often, so lazy binding isn't worthwhile. 208def NonLazyBind : EnumAttr<"nonlazybind", IntersectPreserve, [FnAttr]>; 209 210/// Disable merging for specified functions or call sites. 211def NoMerge : EnumAttr<"nomerge", IntersectPreserve, [FnAttr]>; 212 213/// Pointer is known to be not null. 214def NonNull : EnumAttr<"nonnull", IntersectAnd, [ParamAttr, RetAttr]>; 215 216/// The function does not recurse. 217def NoRecurse : EnumAttr<"norecurse", IntersectAnd, [FnAttr]>; 218 219/// Disable redzone. 220def NoRedZone : EnumAttr<"noredzone", IntersectPreserve, [FnAttr]>; 221 222/// Mark the function as not returning. 223def NoReturn : EnumAttr<"noreturn", IntersectAnd, [FnAttr]>; 224 225/// Function does not synchronize. 226def NoSync : EnumAttr<"nosync", IntersectAnd, [FnAttr]>; 227 228/// Disable Indirect Branch Tracking. 229def NoCfCheck : EnumAttr<"nocf_check", IntersectPreserve, [FnAttr]>; 230 231/// Function should not be instrumented. 232def NoProfile : EnumAttr<"noprofile", IntersectPreserve, [FnAttr]>; 233 234/// This function should not be instrumented but it is ok to inline profiled 235// functions into it. 236def SkipProfile : EnumAttr<"skipprofile", IntersectPreserve, [FnAttr]>; 237 238/// Function doesn't unwind stack. 239def NoUnwind : EnumAttr<"nounwind", IntersectAnd, [FnAttr]>; 240 241/// No SanitizeBounds instrumentation. 242def NoSanitizeBounds : EnumAttr<"nosanitize_bounds", IntersectPreserve, [FnAttr]>; 243 244/// No SanitizeCoverage instrumentation. 245def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", IntersectPreserve, [FnAttr]>; 246 247/// Null pointer in address space zero is valid. 248def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", IntersectPreserve, [FnAttr]>; 249 250/// Select optimizations that give decent debug info. 251def OptimizeForDebugging : EnumAttr<"optdebug", IntersectPreserve, [FnAttr]>; 252 253/// Select optimizations for best fuzzing signal. 254def OptForFuzzing : EnumAttr<"optforfuzzing", IntersectPreserve, [FnAttr]>; 255 256/// opt_size. 257def OptimizeForSize : EnumAttr<"optsize", IntersectPreserve, [FnAttr]>; 258 259/// Function must not be optimized. 260def OptimizeNone : EnumAttr<"optnone", IntersectPreserve, [FnAttr]>; 261 262/// Similar to byval but without a copy. 263def Preallocated : TypeAttr<"preallocated", IntersectPreserve, [FnAttr, ParamAttr]>; 264 265/// Parameter or return value is within the specified range. 266def Range : ConstantRangeAttr<"range", IntersectCustom, [ParamAttr, RetAttr]>; 267 268/// Function does not access memory. 269def ReadNone : EnumAttr<"readnone", IntersectAnd, [ParamAttr]>; 270 271/// Function only reads from memory. 272def ReadOnly : EnumAttr<"readonly", IntersectAnd, [ParamAttr]>; 273 274/// Return value is always equal to this argument. 275def Returned : EnumAttr<"returned", IntersectAnd, [ParamAttr]>; 276 277/// Parameter is required to be a trivial constant. 278def ImmArg : EnumAttr<"immarg", IntersectPreserve, [ParamAttr]>; 279 280/// Function can return twice. 281def ReturnsTwice : EnumAttr<"returns_twice", IntersectPreserve, [FnAttr]>; 282 283/// Safe Stack protection. 284def SafeStack : EnumAttr<"safestack", IntersectPreserve, [FnAttr]>; 285 286/// Shadow Call Stack protection. 287def ShadowCallStack : EnumAttr<"shadowcallstack", IntersectPreserve, [FnAttr]>; 288 289/// Sign extended before/after call. 290def SExt : EnumAttr<"signext", IntersectPreserve, [ParamAttr, RetAttr]>; 291 292/// Alignment of stack for function (3 bits) stored as log2 of alignment with 293/// +1 bias 0 means unaligned (different from alignstack=(1)). 294def StackAlignment : IntAttr<"alignstack", IntersectPreserve, [FnAttr, ParamAttr]>; 295 296/// Function can be speculated. 297def Speculatable : EnumAttr<"speculatable", IntersectAnd, [FnAttr]>; 298 299/// Stack protection. 300def StackProtect : EnumAttr<"ssp", IntersectPreserve, [FnAttr]>; 301 302/// Stack protection required. 303def StackProtectReq : EnumAttr<"sspreq", IntersectPreserve, [FnAttr]>; 304 305/// Strong Stack protection. 306def StackProtectStrong : EnumAttr<"sspstrong", IntersectPreserve, [FnAttr]>; 307 308/// Function was called in a scope requiring strict floating point semantics. 309def StrictFP : EnumAttr<"strictfp", IntersectPreserve, [FnAttr]>; 310 311/// Hidden pointer to structure to return. 312def StructRet : TypeAttr<"sret", IntersectPreserve, [ParamAttr]>; 313 314/// AddressSanitizer is on. 315def SanitizeAddress : EnumAttr<"sanitize_address", IntersectPreserve, [FnAttr]>; 316 317/// ThreadSanitizer is on. 318def SanitizeThread : EnumAttr<"sanitize_thread", IntersectPreserve, [FnAttr]>; 319 320/// TypeSanitizer is on. 321def SanitizeType : EnumAttr<"sanitize_type", IntersectPreserve, [FnAttr]>; 322 323/// MemorySanitizer is on. 324def SanitizeMemory : EnumAttr<"sanitize_memory", IntersectPreserve, [FnAttr]>; 325 326/// HWAddressSanitizer is on. 327def SanitizeHWAddress : EnumAttr<"sanitize_hwaddress", IntersectPreserve, [FnAttr]>; 328 329/// MemTagSanitizer is on. 330def SanitizeMemTag : EnumAttr<"sanitize_memtag", IntersectPreserve, [FnAttr]>; 331 332/// NumericalStabilitySanitizer is on. 333def SanitizeNumericalStability : EnumAttr<"sanitize_numerical_stability", IntersectPreserve, [FnAttr]>; 334 335/// RealtimeSanitizer is on. 336def SanitizeRealtime : EnumAttr<"sanitize_realtime", IntersectPreserve, [FnAttr]>; 337 338/// RealtimeSanitizer should error if a real-time unsafe function is invoked 339/// during a real-time sanitized function (see `sanitize_realtime`). 340def SanitizeRealtimeBlocking : EnumAttr<"sanitize_realtime_blocking", IntersectPreserve, [FnAttr]>; 341 342/// Speculative Load Hardening is enabled. 343/// 344/// Note that this uses the default compatibility (always compatible during 345/// inlining) and a conservative merge strategy where inlining an attributed 346/// body will add the attribute to the caller. This ensures that code carrying 347/// this attribute will always be lowered with hardening enabled. 348def SpeculativeLoadHardening : EnumAttr<"speculative_load_hardening", 349 IntersectPreserve, 350 [FnAttr]>; 351 352/// Argument is swift error. 353def SwiftError : EnumAttr<"swifterror", IntersectPreserve, [ParamAttr]>; 354 355/// Argument is swift self/context. 356def SwiftSelf : EnumAttr<"swiftself", IntersectPreserve, [ParamAttr]>; 357 358/// Argument is swift async context. 359def SwiftAsync : EnumAttr<"swiftasync", IntersectPreserve, [ParamAttr]>; 360 361/// Function must be in a unwind table. 362def UWTable : IntAttr<"uwtable", IntersectPreserve, [FnAttr]>; 363 364/// Minimum/Maximum vscale value for function. 365def VScaleRange : IntAttr<"vscale_range", IntersectPreserve, [FnAttr]>; 366 367/// Function always comes back to callsite. 368def WillReturn : EnumAttr<"willreturn", IntersectAnd, [FnAttr]>; 369 370/// Pointer argument is writable. 371def Writable : EnumAttr<"writable", IntersectAnd, [ParamAttr]>; 372 373/// Function only writes to memory. 374def WriteOnly : EnumAttr<"writeonly", IntersectAnd, [ParamAttr]>; 375 376/// Zero extended before/after call. 377def ZExt : EnumAttr<"zeroext", IntersectPreserve, [ParamAttr, RetAttr]>; 378 379/// Function is required to make Forward Progress. 380def MustProgress : EnumAttr<"mustprogress", IntersectAnd, [FnAttr]>; 381 382/// Function is a presplit coroutine. 383def PresplitCoroutine : EnumAttr<"presplitcoroutine", IntersectPreserve, [FnAttr]>; 384 385/// The coroutine would only be destroyed when it is complete. 386def CoroDestroyOnlyWhenComplete : EnumAttr<"coro_only_destroy_when_complete", IntersectPreserve, [FnAttr]>; 387 388/// The coroutine call meets the elide requirement. Hint the optimization 389/// pipeline to perform elide on the call or invoke instruction. 390def CoroElideSafe : EnumAttr<"coro_elide_safe", IntersectPreserve, [FnAttr]>; 391 392/// Target-independent string attributes. 393def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">; 394def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">; 395def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">; 396def ApproxFuncFPMath : StrBoolAttr<"approx-func-fp-math">; 397def NoSignedZerosFPMath : StrBoolAttr<"no-signed-zeros-fp-math">; 398def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">; 399def NoJumpTables : StrBoolAttr<"no-jump-tables">; 400def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">; 401def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">; 402def UseSampleProfile : StrBoolAttr<"use-sample-profile">; 403 404def DenormalFPMath : ComplexStrAttr<"denormal-fp-math", [FnAttr]>; 405def DenormalFPMathF32 : ComplexStrAttr<"denormal-fp-math-f32", [FnAttr]>; 406 407// Attribute compatiblity rules are generated to check the attribute of the 408// caller and callee and decide whether inlining should be allowed. CompatRule 409// and child classes are used for the rule generation. CompatRule takes only a 410// compare function which could be templated with the attribute type. 411// CompatRuleStrAttr takes the compare function and the string attribute for 412// checking compatibility for inline substitution. 413class CompatRule<string F> { 414 // The function's signature must match "bool(const Function&, const 415 // Function&)", where the first parameter is the reference to the caller and 416 // the second parameter is the reference to the callee. It must return false 417 // if the attributes of the caller and callee are incompatible, and true 418 // otherwise. 419 string CompatFunc = F; 420 string AttrName = ""; 421} 422 423class CompatRuleStrAttr<string F, string Attr> : CompatRule<F> { 424 // The checker function is extended with an third argument as the function 425 // attribute string "bool(const Function&, const Function&, const StringRef&)". 426 string AttrName = Attr; 427} 428 429def : CompatRule<"isEqual<SanitizeAddressAttr>">; 430def : CompatRule<"isEqual<SanitizeThreadAttr>">; 431def : CompatRule<"isEqual<SanitizeTypeAttr>">; 432def : CompatRule<"isEqual<SanitizeMemoryAttr>">; 433def : CompatRule<"isEqual<SanitizeHWAddressAttr>">; 434def : CompatRule<"isEqual<SanitizeMemTagAttr>">; 435def : CompatRule<"isEqual<SanitizeNumericalStabilityAttr>">; 436def : CompatRule<"isEqual<SanitizeRealtimeAttr>">; 437def : CompatRule<"isEqual<SanitizeRealtimeBlockingAttr>">; 438def : CompatRule<"isEqual<SafeStackAttr>">; 439def : CompatRule<"isEqual<ShadowCallStackAttr>">; 440def : CompatRule<"isEqual<UseSampleProfileAttr>">; 441def : CompatRule<"isEqual<NoProfileAttr>">; 442def : CompatRule<"checkDenormMode">; 443def : CompatRule<"checkStrictFP">; 444def : CompatRuleStrAttr<"isEqual", "sign-return-address">; 445def : CompatRuleStrAttr<"isEqual", "sign-return-address-key">; 446def : CompatRuleStrAttr<"isEqual", "branch-protection-pauth-lr">; 447 448class MergeRule<string F> { 449 // The name of the function called to merge the attributes of the caller and 450 // callee. The function's signature must match 451 // "void(Function&, const Function &)", where the first parameter is the 452 // reference to the caller and the second parameter is the reference to the 453 // callee. 454 string MergeFunc = F; 455} 456 457def : MergeRule<"setAND<LessPreciseFPMADAttr>">; 458def : MergeRule<"setAND<NoInfsFPMathAttr>">; 459def : MergeRule<"setAND<NoNansFPMathAttr>">; 460def : MergeRule<"setAND<ApproxFuncFPMathAttr>">; 461def : MergeRule<"setAND<NoSignedZerosFPMathAttr>">; 462def : MergeRule<"setAND<UnsafeFPMathAttr>">; 463def : MergeRule<"setOR<NoImplicitFloatAttr>">; 464def : MergeRule<"setOR<NoJumpTablesAttr>">; 465def : MergeRule<"setOR<ProfileSampleAccurateAttr>">; 466def : MergeRule<"setOR<SpeculativeLoadHardeningAttr>">; 467def : MergeRule<"adjustCallerSSPLevel">; 468def : MergeRule<"adjustCallerStackProbes">; 469def : MergeRule<"adjustCallerStackProbeSize">; 470def : MergeRule<"adjustMinLegalVectorWidth">; 471def : MergeRule<"adjustNullPointerValidAttr">; 472def : MergeRule<"setAND<MustProgressAttr>">; 473