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