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