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