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/// Disable implicit floating point insts. 155def NoImplicitFloat : EnumAttr<"noimplicitfloat", [FnAttr]>; 156 157/// inline=never. 158def NoInline : EnumAttr<"noinline", [FnAttr]>; 159 160/// Function is called early and/or often, so lazy binding isn't worthwhile. 161def NonLazyBind : EnumAttr<"nonlazybind", [FnAttr]>; 162 163/// Disable merging for specified functions or call sites. 164def NoMerge : EnumAttr<"nomerge", [FnAttr]>; 165 166/// Pointer is known to be not null. 167def NonNull : EnumAttr<"nonnull", [ParamAttr, RetAttr]>; 168 169/// The function does not recurse. 170def NoRecurse : EnumAttr<"norecurse", [FnAttr]>; 171 172/// Disable redzone. 173def NoRedZone : EnumAttr<"noredzone", [FnAttr]>; 174 175/// Mark the function as not returning. 176def NoReturn : EnumAttr<"noreturn", [FnAttr]>; 177 178/// Function does not synchronize. 179def NoSync : EnumAttr<"nosync", [FnAttr]>; 180 181/// Disable Indirect Branch Tracking. 182def NoCfCheck : EnumAttr<"nocf_check", [FnAttr]>; 183 184/// Function should not be instrumented. 185def NoProfile : EnumAttr<"noprofile", [FnAttr]>; 186 187/// This function should not be instrumented but it is ok to inline profiled 188// functions into it. 189def SkipProfile : EnumAttr<"skipprofile", [FnAttr]>; 190 191/// Function doesn't unwind stack. 192def NoUnwind : EnumAttr<"nounwind", [FnAttr]>; 193 194/// No SanitizeBounds instrumentation. 195def NoSanitizeBounds : EnumAttr<"nosanitize_bounds", [FnAttr]>; 196 197/// No SanitizeCoverage instrumentation. 198def NoSanitizeCoverage : EnumAttr<"nosanitize_coverage", [FnAttr]>; 199 200/// Null pointer in address space zero is valid. 201def NullPointerIsValid : EnumAttr<"null_pointer_is_valid", [FnAttr]>; 202 203/// Select optimizations for best fuzzing signal. 204def OptForFuzzing : EnumAttr<"optforfuzzing", [FnAttr]>; 205 206/// opt_size. 207def OptimizeForSize : EnumAttr<"optsize", [FnAttr]>; 208 209/// Function must not be optimized. 210def OptimizeNone : EnumAttr<"optnone", [FnAttr]>; 211 212/// Similar to byval but without a copy. 213def Preallocated : TypeAttr<"preallocated", [FnAttr, ParamAttr]>; 214 215/// Function does not access memory. 216def ReadNone : EnumAttr<"readnone", [ParamAttr]>; 217 218/// Function only reads from memory. 219def ReadOnly : EnumAttr<"readonly", [ParamAttr]>; 220 221/// Return value is always equal to this argument. 222def Returned : EnumAttr<"returned", [ParamAttr]>; 223 224/// Parameter is required to be a trivial constant. 225def ImmArg : EnumAttr<"immarg", [ParamAttr]>; 226 227/// Function can return twice. 228def ReturnsTwice : EnumAttr<"returns_twice", [FnAttr]>; 229 230/// Safe Stack protection. 231def SafeStack : EnumAttr<"safestack", [FnAttr]>; 232 233/// Shadow Call Stack protection. 234def ShadowCallStack : EnumAttr<"shadowcallstack", [FnAttr]>; 235 236/// Sign extended before/after call. 237def SExt : EnumAttr<"signext", [ParamAttr, RetAttr]>; 238 239/// Alignment of stack for function (3 bits) stored as log2 of alignment with 240/// +1 bias 0 means unaligned (different from alignstack=(1)). 241def StackAlignment : IntAttr<"alignstack", [FnAttr, ParamAttr]>; 242 243/// Function can be speculated. 244def Speculatable : EnumAttr<"speculatable", [FnAttr]>; 245 246/// Stack protection. 247def StackProtect : EnumAttr<"ssp", [FnAttr]>; 248 249/// Stack protection required. 250def StackProtectReq : EnumAttr<"sspreq", [FnAttr]>; 251 252/// Strong Stack protection. 253def StackProtectStrong : EnumAttr<"sspstrong", [FnAttr]>; 254 255/// Function was called in a scope requiring strict floating point semantics. 256def StrictFP : EnumAttr<"strictfp", [FnAttr]>; 257 258/// Hidden pointer to structure to return. 259def StructRet : TypeAttr<"sret", [ParamAttr]>; 260 261/// AddressSanitizer is on. 262def SanitizeAddress : EnumAttr<"sanitize_address", [FnAttr]>; 263 264/// ThreadSanitizer is on. 265def SanitizeThread : EnumAttr<"sanitize_thread", [FnAttr]>; 266 267/// MemorySanitizer is on. 268def SanitizeMemory : EnumAttr<"sanitize_memory", [FnAttr]>; 269 270/// HWAddressSanitizer is on. 271def SanitizeHWAddress : EnumAttr<"sanitize_hwaddress", [FnAttr]>; 272 273/// MemTagSanitizer is on. 274def SanitizeMemTag : EnumAttr<"sanitize_memtag", [FnAttr]>; 275 276/// Speculative Load Hardening is enabled. 277/// 278/// Note that this uses the default compatibility (always compatible during 279/// inlining) and a conservative merge strategy where inlining an attributed 280/// body will add the attribute to the caller. This ensures that code carrying 281/// this attribute will always be lowered with hardening enabled. 282def SpeculativeLoadHardening : EnumAttr<"speculative_load_hardening", 283 [FnAttr]>; 284 285/// Argument is swift error. 286def SwiftError : EnumAttr<"swifterror", [ParamAttr]>; 287 288/// Argument is swift self/context. 289def SwiftSelf : EnumAttr<"swiftself", [ParamAttr]>; 290 291/// Argument is swift async context. 292def SwiftAsync : EnumAttr<"swiftasync", [ParamAttr]>; 293 294/// Function must be in a unwind table. 295def UWTable : IntAttr<"uwtable", [FnAttr]>; 296 297/// Minimum/Maximum vscale value for function. 298def VScaleRange : IntAttr<"vscale_range", [FnAttr]>; 299 300/// Function always comes back to callsite. 301def WillReturn : EnumAttr<"willreturn", [FnAttr]>; 302 303/// Function only writes to memory. 304def WriteOnly : EnumAttr<"writeonly", [ParamAttr]>; 305 306/// Zero extended before/after call. 307def ZExt : EnumAttr<"zeroext", [ParamAttr, RetAttr]>; 308 309/// Function is required to make Forward Progress. 310def MustProgress : EnumAttr<"mustprogress", [FnAttr]>; 311 312/// Function is a presplit coroutine. 313def PresplitCoroutine : EnumAttr<"presplitcoroutine", [FnAttr]>; 314 315/// Target-independent string attributes. 316def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">; 317def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">; 318def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">; 319def ApproxFuncFPMath : StrBoolAttr<"approx-func-fp-math">; 320def NoSignedZerosFPMath : StrBoolAttr<"no-signed-zeros-fp-math">; 321def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">; 322def NoJumpTables : StrBoolAttr<"no-jump-tables">; 323def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">; 324def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">; 325def UseSampleProfile : StrBoolAttr<"use-sample-profile">; 326 327def DenormalFPMath : ComplexStrAttr<"denormal-fp-math", [FnAttr]>; 328def DenormalFPMathF32 : ComplexStrAttr<"denormal-fp-math-f32", [FnAttr]>; 329 330class CompatRule<string F> { 331 // The name of the function called to check the attribute of the caller and 332 // callee and decide whether inlining should be allowed. The function's 333 // signature must match "bool(const Function&, const Function &)", where the 334 // first parameter is the reference to the caller and the second parameter is 335 // the reference to the callee. It must return false if the attributes of the 336 // caller and callee are incompatible, and true otherwise. 337 string CompatFunc = F; 338} 339 340def : CompatRule<"isEqual<SanitizeAddressAttr>">; 341def : CompatRule<"isEqual<SanitizeThreadAttr>">; 342def : CompatRule<"isEqual<SanitizeMemoryAttr>">; 343def : CompatRule<"isEqual<SanitizeHWAddressAttr>">; 344def : CompatRule<"isEqual<SanitizeMemTagAttr>">; 345def : CompatRule<"isEqual<SafeStackAttr>">; 346def : CompatRule<"isEqual<ShadowCallStackAttr>">; 347def : CompatRule<"isEqual<UseSampleProfileAttr>">; 348def : CompatRule<"isEqual<NoProfileAttr>">; 349def : CompatRule<"checkDenormMode">; 350 351 352class MergeRule<string F> { 353 // The name of the function called to merge the attributes of the caller and 354 // callee. The function's signature must match 355 // "void(Function&, const Function &)", where the first parameter is the 356 // reference to the caller and the second parameter is the reference to the 357 // callee. 358 string MergeFunc = F; 359} 360 361def : MergeRule<"setAND<LessPreciseFPMADAttr>">; 362def : MergeRule<"setAND<NoInfsFPMathAttr>">; 363def : MergeRule<"setAND<NoNansFPMathAttr>">; 364def : MergeRule<"setAND<ApproxFuncFPMathAttr>">; 365def : MergeRule<"setAND<NoSignedZerosFPMathAttr>">; 366def : MergeRule<"setAND<UnsafeFPMathAttr>">; 367def : MergeRule<"setOR<NoImplicitFloatAttr>">; 368def : MergeRule<"setOR<NoJumpTablesAttr>">; 369def : MergeRule<"setOR<ProfileSampleAccurateAttr>">; 370def : MergeRule<"setOR<SpeculativeLoadHardeningAttr>">; 371def : MergeRule<"adjustCallerSSPLevel">; 372def : MergeRule<"adjustCallerStackProbes">; 373def : MergeRule<"adjustCallerStackProbeSize">; 374def : MergeRule<"adjustMinLegalVectorWidth">; 375def : MergeRule<"adjustNullPointerValidAttr">; 376def : MergeRule<"setAND<MustProgressAttr>">; 377