1292915Sdim/// Attribute base class. 2292915Sdimclass Attr<string S> { 3292915Sdim // String representation of this attribute in the IR. 4292915Sdim string AttrString = S; 5292915Sdim} 6292915Sdim 7292915Sdim/// Enum attribute. 8292915Sdimclass EnumAttr<string S> : Attr<S>; 9292915Sdim 10292915Sdim/// StringBool attribute. 11292915Sdimclass StrBoolAttr<string S> : Attr<S>; 12292915Sdim 13292915Sdim/// Target-independent enum attributes. 14292915Sdim 15292915Sdim/// Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias. 16292915Sdim/// 0 means unaligned (different from align(1)). 17292915Sdimdef Alignment : EnumAttr<"align">; 18292915Sdim 19309124Sdim/// The result of the function is guaranteed to point to a number of bytes that 20309124Sdim/// we can determine if we know the value of the function's arguments. 21309124Sdimdef AllocSize : EnumAttr<"allocsize">; 22309124Sdim 23292915Sdim/// inline=always. 24292915Sdimdef AlwaysInline : EnumAttr<"alwaysinline">; 25292915Sdim 26292915Sdim/// Function can access memory only using pointers based on its arguments. 27292915Sdimdef ArgMemOnly : EnumAttr<"argmemonly">; 28292915Sdim 29292915Sdim/// Callee is recognized as a builtin, despite nobuiltin attribute on its 30292915Sdim/// declaration. 31292915Sdimdef Builtin : EnumAttr<"builtin">; 32292915Sdim 33292915Sdim/// Pass structure by value. 34292915Sdimdef ByVal : EnumAttr<"byval">; 35292915Sdim 36292915Sdim/// Marks function as being in a cold path. 37292915Sdimdef Cold : EnumAttr<"cold">; 38292915Sdim 39292915Sdim/// Can only be moved to control-equivalent blocks. 40292915Sdimdef Convergent : EnumAttr<"convergent">; 41292915Sdim 42292915Sdim/// Pointer is known to be dereferenceable. 43292915Sdimdef Dereferenceable : EnumAttr<"dereferenceable">; 44292915Sdim 45292915Sdim/// Pointer is either null or dereferenceable. 46292915Sdimdef DereferenceableOrNull : EnumAttr<"dereferenceable_or_null">; 47292915Sdim 48292915Sdim/// Function may only access memory that is inaccessible from IR. 49292915Sdimdef InaccessibleMemOnly : EnumAttr<"inaccessiblememonly">; 50292915Sdim 51292915Sdim/// Function may only access memory that is either inaccessible from the IR, 52292915Sdim/// or pointed to by its pointer arguments. 53292915Sdimdef InaccessibleMemOrArgMemOnly : EnumAttr<"inaccessiblemem_or_argmemonly">; 54292915Sdim 55292915Sdim/// Pass structure in an alloca. 56292915Sdimdef InAlloca : EnumAttr<"inalloca">; 57292915Sdim 58292915Sdim/// Source said inlining was desirable. 59292915Sdimdef InlineHint : EnumAttr<"inlinehint">; 60292915Sdim 61292915Sdim/// Force argument to be passed in register. 62292915Sdimdef InReg : EnumAttr<"inreg">; 63292915Sdim 64292915Sdim/// Build jump-instruction tables and replace refs. 65292915Sdimdef JumpTable : EnumAttr<"jumptable">; 66292915Sdim 67292915Sdim/// Function must be optimized for size first. 68292915Sdimdef MinSize : EnumAttr<"minsize">; 69292915Sdim 70292915Sdim/// Naked function. 71292915Sdimdef Naked : EnumAttr<"naked">; 72292915Sdim 73292915Sdim/// Nested function static chain. 74292915Sdimdef Nest : EnumAttr<"nest">; 75292915Sdim 76292915Sdim/// Considered to not alias after call. 77292915Sdimdef NoAlias : EnumAttr<"noalias">; 78292915Sdim 79292915Sdim/// Callee isn't recognized as a builtin. 80292915Sdimdef NoBuiltin : EnumAttr<"nobuiltin">; 81292915Sdim 82292915Sdim/// Function creates no aliases of pointer. 83292915Sdimdef NoCapture : EnumAttr<"nocapture">; 84292915Sdim 85292915Sdim/// Call cannot be duplicated. 86292915Sdimdef NoDuplicate : EnumAttr<"noduplicate">; 87292915Sdim 88353358Sdim/// Function does not deallocate memory. 89353358Sdimdef NoFree : EnumAttr<"nofree">; 90353358Sdim 91292915Sdim/// Disable implicit floating point insts. 92292915Sdimdef NoImplicitFloat : EnumAttr<"noimplicitfloat">; 93292915Sdim 94292915Sdim/// inline=never. 95292915Sdimdef NoInline : EnumAttr<"noinline">; 96292915Sdim 97292915Sdim/// Function is called early and/or often, so lazy binding isn't worthwhile. 98292915Sdimdef NonLazyBind : EnumAttr<"nonlazybind">; 99292915Sdim 100292915Sdim/// Pointer is known to be not null. 101292915Sdimdef NonNull : EnumAttr<"nonnull">; 102292915Sdim 103292915Sdim/// The function does not recurse. 104292915Sdimdef NoRecurse : EnumAttr<"norecurse">; 105292915Sdim 106292915Sdim/// Disable redzone. 107292915Sdimdef NoRedZone : EnumAttr<"noredzone">; 108292915Sdim 109292915Sdim/// Mark the function as not returning. 110292915Sdimdef NoReturn : EnumAttr<"noreturn">; 111292915Sdim 112353358Sdim/// Function does not synchronize. 113353358Sdimdef NoSync : EnumAttr<"nosync">; 114353358Sdim 115341825Sdim/// Disable Indirect Branch Tracking. 116341825Sdimdef NoCfCheck : EnumAttr<"nocf_check">; 117341825Sdim 118292915Sdim/// Function doesn't unwind stack. 119292915Sdimdef NoUnwind : EnumAttr<"nounwind">; 120292915Sdim 121341825Sdim/// Select optimizations for best fuzzing signal. 122341825Sdimdef OptForFuzzing : EnumAttr<"optforfuzzing">; 123341825Sdim 124292915Sdim/// opt_size. 125292915Sdimdef OptimizeForSize : EnumAttr<"optsize">; 126292915Sdim 127292915Sdim/// Function must not be optimized. 128292915Sdimdef OptimizeNone : EnumAttr<"optnone">; 129292915Sdim 130292915Sdim/// Function does not access memory. 131292915Sdimdef ReadNone : EnumAttr<"readnone">; 132292915Sdim 133292915Sdim/// Function only reads from memory. 134292915Sdimdef ReadOnly : EnumAttr<"readonly">; 135292915Sdim 136292915Sdim/// Return value is always equal to this argument. 137292915Sdimdef Returned : EnumAttr<"returned">; 138292915Sdim 139353358Sdim/// Parameter is required to be a trivial constant. 140353358Sdimdef ImmArg : EnumAttr<"immarg">; 141353358Sdim 142292915Sdim/// Function can return twice. 143292915Sdimdef ReturnsTwice : EnumAttr<"returns_twice">; 144292915Sdim 145292915Sdim/// Safe Stack protection. 146292915Sdimdef SafeStack : EnumAttr<"safestack">; 147292915Sdim 148341825Sdim/// Shadow Call Stack protection. 149341825Sdimdef ShadowCallStack : EnumAttr<"shadowcallstack">; 150341825Sdim 151292915Sdim/// Sign extended before/after call. 152292915Sdimdef SExt : EnumAttr<"signext">; 153292915Sdim 154292915Sdim/// Alignment of stack for function (3 bits) stored as log2 of alignment with 155292915Sdim/// +1 bias 0 means unaligned (different from alignstack=(1)). 156292915Sdimdef StackAlignment : EnumAttr<"alignstack">; 157292915Sdim 158321369Sdim/// Function can be speculated. 159321369Sdimdef Speculatable : EnumAttr<"speculatable">; 160321369Sdim 161292915Sdim/// Stack protection. 162292915Sdimdef StackProtect : EnumAttr<"ssp">; 163292915Sdim 164292915Sdim/// Stack protection required. 165292915Sdimdef StackProtectReq : EnumAttr<"sspreq">; 166292915Sdim 167292915Sdim/// Strong Stack protection. 168292915Sdimdef StackProtectStrong : EnumAttr<"sspstrong">; 169292915Sdim 170327952Sdim/// Function was called in a scope requiring strict floating point semantics. 171327952Sdimdef StrictFP : EnumAttr<"strictfp">; 172327952Sdim 173292915Sdim/// Hidden pointer to structure to return. 174292915Sdimdef StructRet : EnumAttr<"sret">; 175292915Sdim 176292915Sdim/// AddressSanitizer is on. 177292915Sdimdef SanitizeAddress : EnumAttr<"sanitize_address">; 178292915Sdim 179292915Sdim/// ThreadSanitizer is on. 180292915Sdimdef SanitizeThread : EnumAttr<"sanitize_thread">; 181292915Sdim 182292915Sdim/// MemorySanitizer is on. 183292915Sdimdef SanitizeMemory : EnumAttr<"sanitize_memory">; 184292915Sdim 185327952Sdim/// HWAddressSanitizer is on. 186327952Sdimdef SanitizeHWAddress : EnumAttr<"sanitize_hwaddress">; 187327952Sdim 188353358Sdim/// MemTagSanitizer is on. 189353358Sdimdef SanitizeMemTag : EnumAttr<"sanitize_memtag">; 190353358Sdim 191344779Sdim/// Speculative Load Hardening is enabled. 192344779Sdim/// 193344779Sdim/// Note that this uses the default compatibility (always compatible during 194344779Sdim/// inlining) and a conservative merge strategy where inlining an attributed 195344779Sdim/// body will add the attribute to the caller. This ensures that code carrying 196344779Sdim/// this attribute will always be lowered with hardening enabled. 197344779Sdimdef SpeculativeLoadHardening : EnumAttr<"speculative_load_hardening">; 198344779Sdim 199309124Sdim/// Argument is swift error. 200309124Sdimdef SwiftError : EnumAttr<"swifterror">; 201309124Sdim 202309124Sdim/// Argument is swift self/context. 203309124Sdimdef SwiftSelf : EnumAttr<"swiftself">; 204309124Sdim 205292915Sdim/// Function must be in a unwind table. 206292915Sdimdef UWTable : EnumAttr<"uwtable">; 207292915Sdim 208353358Sdim/// Function always comes back to callsite. 209353358Sdimdef WillReturn : EnumAttr<"willreturn">; 210353358Sdim 211309124Sdim/// Function only writes to memory. 212309124Sdimdef WriteOnly : EnumAttr<"writeonly">; 213309124Sdim 214292915Sdim/// Zero extended before/after call. 215292915Sdimdef ZExt : EnumAttr<"zeroext">; 216292915Sdim 217292915Sdim/// Target-independent string attributes. 218292915Sdimdef LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">; 219292915Sdimdef NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">; 220292915Sdimdef NoNansFPMath : StrBoolAttr<"no-nans-fp-math">; 221292915Sdimdef UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">; 222309124Sdimdef NoJumpTables : StrBoolAttr<"no-jump-tables">; 223360784Sdimdef NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">; 224327952Sdimdef ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">; 225292915Sdim 226292915Sdimclass CompatRule<string F> { 227292915Sdim // The name of the function called to check the attribute of the caller and 228292915Sdim // callee and decide whether inlining should be allowed. The function's 229292915Sdim // signature must match "bool(const Function&, const Function &)", where the 230292915Sdim // first parameter is the reference to the caller and the second parameter is 231292915Sdim // the reference to the callee. It must return false if the attributes of the 232292915Sdim // caller and callee are incompatible, and true otherwise. 233292915Sdim string CompatFunc = F; 234292915Sdim} 235292915Sdim 236292915Sdimdef : CompatRule<"isEqual<SanitizeAddressAttr>">; 237292915Sdimdef : CompatRule<"isEqual<SanitizeThreadAttr>">; 238292915Sdimdef : CompatRule<"isEqual<SanitizeMemoryAttr>">; 239327952Sdimdef : CompatRule<"isEqual<SanitizeHWAddressAttr>">; 240353358Sdimdef : CompatRule<"isEqual<SanitizeMemTagAttr>">; 241309124Sdimdef : CompatRule<"isEqual<SafeStackAttr>">; 242341825Sdimdef : CompatRule<"isEqual<ShadowCallStackAttr>">; 243292915Sdim 244292915Sdimclass MergeRule<string F> { 245292915Sdim // The name of the function called to merge the attributes of the caller and 246292915Sdim // callee. The function's signature must match 247292915Sdim // "void(Function&, const Function &)", where the first parameter is the 248292915Sdim // reference to the caller and the second parameter is the reference to the 249292915Sdim // callee. 250292915Sdim string MergeFunc = F; 251292915Sdim} 252292915Sdim 253294024Sdimdef : MergeRule<"setAND<LessPreciseFPMADAttr>">; 254294024Sdimdef : MergeRule<"setAND<NoInfsFPMathAttr>">; 255294024Sdimdef : MergeRule<"setAND<NoNansFPMathAttr>">; 256294024Sdimdef : MergeRule<"setAND<UnsafeFPMathAttr>">; 257294024Sdimdef : MergeRule<"setOR<NoImplicitFloatAttr>">; 258309124Sdimdef : MergeRule<"setOR<NoJumpTablesAttr>">; 259327952Sdimdef : MergeRule<"setOR<ProfileSampleAccurateAttr>">; 260344779Sdimdef : MergeRule<"setOR<SpeculativeLoadHardeningAttr>">; 261292915Sdimdef : MergeRule<"adjustCallerSSPLevel">; 262321369Sdimdef : MergeRule<"adjustCallerStackProbes">; 263321369Sdimdef : MergeRule<"adjustCallerStackProbeSize">; 264341825Sdimdef : MergeRule<"adjustMinLegalVectorWidth">; 265341825Sdimdef : MergeRule<"adjustNullPointerValidAttr">; 266