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