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