1 /// Attribute base class.
3 // String representation of this attribute in the IR.
8 class EnumAttr<string S> : Attr<S>;
10 /// StringBool attribute.
11 class StrBoolAttr<string S> : Attr<S>;
13 /// Target-independent enum attributes.
15 /// Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias.
16 /// 0 means unaligned (different from align(1)).
17 def Alignment : EnumAttr<"align">;
19 /// The result of the function is guaranteed to point to a number of bytes that
20 /// we can determine if we know the value of the function's arguments.
21 def AllocSize : EnumAttr<"allocsize">;
24 def AlwaysInline : EnumAttr<"alwaysinline">;
26 /// Function can access memory only using pointers based on its arguments.
27 def ArgMemOnly : EnumAttr<"argmemonly">;
29 /// Callee is recognized as a builtin, despite nobuiltin attribute on its
31 def Builtin : EnumAttr<"builtin">;
33 /// Pass structure by value.
34 def ByVal : EnumAttr<"byval">;
36 /// Marks function as being in a cold path.
37 def Cold : EnumAttr<"cold">;
39 /// Can only be moved to control-equivalent blocks.
40 def Convergent : EnumAttr<"convergent">;
42 /// Pointer is known to be dereferenceable.
43 def Dereferenceable : EnumAttr<"dereferenceable">;
45 /// Pointer is either null or dereferenceable.
46 def DereferenceableOrNull : EnumAttr<"dereferenceable_or_null">;
48 /// Function may only access memory that is inaccessible from IR.
49 def InaccessibleMemOnly : EnumAttr<"inaccessiblememonly">;
51 /// Function may only access memory that is either inaccessible from the IR,
52 /// or pointed to by its pointer arguments.
53 def InaccessibleMemOrArgMemOnly : EnumAttr<"inaccessiblemem_or_argmemonly">;
55 /// Pass structure in an alloca.
56 def InAlloca : EnumAttr<"inalloca">;
58 /// Source said inlining was desirable.
59 def InlineHint : EnumAttr<"inlinehint">;
61 /// Force argument to be passed in register.
62 def InReg : EnumAttr<"inreg">;
64 /// Build jump-instruction tables and replace refs.
65 def JumpTable : EnumAttr<"jumptable">;
67 /// Function must be optimized for size first.
68 def MinSize : EnumAttr<"minsize">;
71 def Naked : EnumAttr<"naked">;
73 /// Nested function static chain.
74 def Nest : EnumAttr<"nest">;
76 /// Considered to not alias after call.
77 def NoAlias : EnumAttr<"noalias">;
79 /// Callee isn't recognized as a builtin.
80 def NoBuiltin : EnumAttr<"nobuiltin">;
82 /// Function creates no aliases of pointer.
83 def NoCapture : EnumAttr<"nocapture">;
85 /// Call cannot be duplicated.
86 def NoDuplicate : EnumAttr<"noduplicate">;
88 /// Function does not deallocate memory.
89 def NoFree : EnumAttr<"nofree">;
91 /// Disable implicit floating point insts.
92 def NoImplicitFloat : EnumAttr<"noimplicitfloat">;
95 def NoInline : EnumAttr<"noinline">;
97 /// Function is called early and/or often, so lazy binding isn't worthwhile.
98 def NonLazyBind : EnumAttr<"nonlazybind">;
100 /// Pointer is known to be not null.
101 def NonNull : EnumAttr<"nonnull">;
103 /// The function does not recurse.
104 def NoRecurse : EnumAttr<"norecurse">;
107 def NoRedZone : EnumAttr<"noredzone">;
109 /// Mark the function as not returning.
110 def NoReturn : EnumAttr<"noreturn">;
112 /// Function does not synchronize.
113 def NoSync : EnumAttr<"nosync">;
115 /// Disable Indirect Branch Tracking.
116 def NoCfCheck : EnumAttr<"nocf_check">;
118 /// Function doesn't unwind stack.
119 def NoUnwind : EnumAttr<"nounwind">;
121 /// Select optimizations for best fuzzing signal.
122 def OptForFuzzing : EnumAttr<"optforfuzzing">;
125 def OptimizeForSize : EnumAttr<"optsize">;
127 /// Function must not be optimized.
128 def OptimizeNone : EnumAttr<"optnone">;
130 /// Function does not access memory.
131 def ReadNone : EnumAttr<"readnone">;
133 /// Function only reads from memory.
134 def ReadOnly : EnumAttr<"readonly">;
136 /// Return value is always equal to this argument.
137 def Returned : EnumAttr<"returned">;
139 /// Parameter is required to be a trivial constant.
140 def ImmArg : EnumAttr<"immarg">;
142 /// Function can return twice.
143 def ReturnsTwice : EnumAttr<"returns_twice">;
145 /// Safe Stack protection.
146 def SafeStack : EnumAttr<"safestack">;
148 /// Shadow Call Stack protection.
149 def ShadowCallStack : EnumAttr<"shadowcallstack">;
151 /// Sign extended before/after call.
152 def SExt : EnumAttr<"signext">;
154 /// Alignment of stack for function (3 bits) stored as log2 of alignment with
155 /// +1 bias 0 means unaligned (different from alignstack=(1)).
156 def StackAlignment : EnumAttr<"alignstack">;
158 /// Function can be speculated.
159 def Speculatable : EnumAttr<"speculatable">;
161 /// Stack protection.
162 def StackProtect : EnumAttr<"ssp">;
164 /// Stack protection required.
165 def StackProtectReq : EnumAttr<"sspreq">;
167 /// Strong Stack protection.
168 def StackProtectStrong : EnumAttr<"sspstrong">;
170 /// Function was called in a scope requiring strict floating point semantics.
171 def StrictFP : EnumAttr<"strictfp">;
173 /// Hidden pointer to structure to return.
174 def StructRet : EnumAttr<"sret">;
176 /// AddressSanitizer is on.
177 def SanitizeAddress : EnumAttr<"sanitize_address">;
179 /// ThreadSanitizer is on.
180 def SanitizeThread : EnumAttr<"sanitize_thread">;
182 /// MemorySanitizer is on.
183 def SanitizeMemory : EnumAttr<"sanitize_memory">;
185 /// HWAddressSanitizer is on.
186 def SanitizeHWAddress : EnumAttr<"sanitize_hwaddress">;
188 /// MemTagSanitizer is on.
189 def SanitizeMemTag : EnumAttr<"sanitize_memtag">;
191 /// Speculative Load Hardening is enabled.
193 /// Note that this uses the default compatibility (always compatible during
194 /// inlining) and a conservative merge strategy where inlining an attributed
195 /// body will add the attribute to the caller. This ensures that code carrying
196 /// this attribute will always be lowered with hardening enabled.
197 def SpeculativeLoadHardening : EnumAttr<"speculative_load_hardening">;
199 /// Argument is swift error.
200 def SwiftError : EnumAttr<"swifterror">;
202 /// Argument is swift self/context.
203 def SwiftSelf : EnumAttr<"swiftself">;
205 /// Function must be in a unwind table.
206 def UWTable : EnumAttr<"uwtable">;
208 /// Function always comes back to callsite.
209 def WillReturn : EnumAttr<"willreturn">;
211 /// Function only writes to memory.
212 def WriteOnly : EnumAttr<"writeonly">;
214 /// Zero extended before/after call.
215 def ZExt : EnumAttr<"zeroext">;
217 /// Target-independent string attributes.
218 def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;
219 def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">;
220 def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">;
221 def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">;
222 def NoJumpTables : StrBoolAttr<"no-jump-tables">;
223 def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">;
225 class CompatRule<string F> {
226 // The name of the function called to check the attribute of the caller and
227 // callee and decide whether inlining should be allowed. The function's
228 // signature must match "bool(const Function&, const Function &)", where the
229 // first parameter is the reference to the caller and the second parameter is
230 // the reference to the callee. It must return false if the attributes of the
231 // caller and callee are incompatible, and true otherwise.
232 string CompatFunc = F;
235 def : CompatRule<"isEqual<SanitizeAddressAttr>">;
236 def : CompatRule<"isEqual<SanitizeThreadAttr>">;
237 def : CompatRule<"isEqual<SanitizeMemoryAttr>">;
238 def : CompatRule<"isEqual<SanitizeHWAddressAttr>">;
239 def : CompatRule<"isEqual<SanitizeMemTagAttr>">;
240 def : CompatRule<"isEqual<SafeStackAttr>">;
241 def : CompatRule<"isEqual<ShadowCallStackAttr>">;
243 class MergeRule<string F> {
244 // The name of the function called to merge the attributes of the caller and
245 // callee. The function's signature must match
246 // "void(Function&, const Function &)", where the first parameter is the
247 // reference to the caller and the second parameter is the reference to the
249 string MergeFunc = F;
252 def : MergeRule<"setAND<LessPreciseFPMADAttr>">;
253 def : MergeRule<"setAND<NoInfsFPMathAttr>">;
254 def : MergeRule<"setAND<NoNansFPMathAttr>">;
255 def : MergeRule<"setAND<UnsafeFPMathAttr>">;
256 def : MergeRule<"setOR<NoImplicitFloatAttr>">;
257 def : MergeRule<"setOR<NoJumpTablesAttr>">;
258 def : MergeRule<"setOR<ProfileSampleAccurateAttr>">;
259 def : MergeRule<"setOR<SpeculativeLoadHardeningAttr>">;
260 def : MergeRule<"adjustCallerSSPLevel">;
261 def : MergeRule<"adjustCallerStackProbes">;
262 def : MergeRule<"adjustCallerStackProbeSize">;
263 def : MergeRule<"adjustMinLegalVectorWidth">;
264 def : MergeRule<"adjustNullPointerValidAttr">;