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