Attributes.td revision 360784
1113822Sphk/// Attribute base class.
2113822Sphkclass Attr<string S> {
3113822Sphk  // String representation of this attribute in the IR.
4113822Sphk  string AttrString = S;
5113822Sphk}
6113822Sphk
7113822Sphk/// Enum attribute.
8113822Sphkclass EnumAttr<string S> : Attr<S>;
9113877Sphk
10113822Sphk/// StringBool attribute.
11113822Sphkclass StrBoolAttr<string S> : Attr<S>;
12113822Sphk
13113822Sphk/// Target-independent enum attributes.
14113822Sphk
15113822Sphk/// Alignment of parameter (5 bits) stored as log2 of alignment with +1 bias.
16113822Sphk/// 0 means unaligned (different from align(1)).
17113822Sphkdef Alignment : EnumAttr<"align">;
18113822Sphk
19113822Sphk/// The result of the function is guaranteed to point to a number of bytes that
20113822Sphk/// we can determine if we know the value of the function's arguments.
21113822Sphkdef AllocSize : EnumAttr<"allocsize">;
22113822Sphk
23113877Sphk/// inline=always.
24113877Sphkdef AlwaysInline : EnumAttr<"alwaysinline">;
25113877Sphk
26113877Sphk/// Function can access memory only using pointers based on its arguments.
27113877Sphkdef ArgMemOnly : EnumAttr<"argmemonly">;
28113877Sphk
29113877Sphk/// Callee is recognized as a builtin, despite nobuiltin attribute on its
30113877Sphk/// declaration.
31113877Sphkdef Builtin : EnumAttr<"builtin">;
32113877Sphk
33113877Sphk/// Pass structure by value.
34113877Sphkdef ByVal : EnumAttr<"byval">;
35113877Sphk
36113877Sphk/// Marks function as being in a cold path.
37113877Sphkdef Cold : EnumAttr<"cold">;
38113877Sphk
39113877Sphk/// Can only be moved to control-equivalent blocks.
40113822Sphkdef Convergent : EnumAttr<"convergent">;
41113822Sphk
42113822Sphk/// Pointer is known to be dereferenceable.
43113822Sphkdef Dereferenceable : EnumAttr<"dereferenceable">;
44113822Sphk
45113822Sphk/// Pointer is either null or dereferenceable.
46113822Sphkdef DereferenceableOrNull : EnumAttr<"dereferenceable_or_null">;
47113822Sphk
48113822Sphk/// Function may only access memory that is inaccessible from IR.
49113822Sphkdef InaccessibleMemOnly : EnumAttr<"inaccessiblememonly">;
50113822Sphk
51113822Sphk/// Function may only access memory that is either inaccessible from the IR,
52113822Sphk/// or pointed to by its pointer arguments.
53113822Sphkdef InaccessibleMemOrArgMemOnly : EnumAttr<"inaccessiblemem_or_argmemonly">;
54113822Sphk
55113822Sphk/// Pass structure in an alloca.
56113822Sphkdef InAlloca : EnumAttr<"inalloca">;
57113822Sphk
58113822Sphk/// Source said inlining was desirable.
59113822Sphkdef InlineHint : EnumAttr<"inlinehint">;
60113822Sphk
61113822Sphk/// Force argument to be passed in register.
62113822Sphkdef InReg : EnumAttr<"inreg">;
63113822Sphk
64113822Sphk/// Build jump-instruction tables and replace refs.
65113822Sphkdef JumpTable : EnumAttr<"jumptable">;
66113822Sphk
67113822Sphk/// Function must be optimized for size first.
68113822Sphkdef MinSize : EnumAttr<"minsize">;
69113822Sphk
70113822Sphk/// Naked function.
71113822Sphkdef Naked : EnumAttr<"naked">;
72113822Sphk
73113822Sphk/// Nested function static chain.
74113822Sphkdef Nest : EnumAttr<"nest">;
75113822Sphk
76113822Sphk/// Considered to not alias after call.
77113822Sphkdef NoAlias : EnumAttr<"noalias">;
78113822Sphk
79113822Sphk/// Callee isn't recognized as a builtin.
80113822Sphkdef NoBuiltin : EnumAttr<"nobuiltin">;
81113822Sphk
82113822Sphk/// Function creates no aliases of pointer.
83113822Sphkdef NoCapture : EnumAttr<"nocapture">;
84113822Sphk
85113822Sphk/// Call cannot be duplicated.
86113822Sphkdef NoDuplicate : EnumAttr<"noduplicate">;
87113822Sphk
88113822Sphk/// Function does not deallocate memory.
89113822Sphkdef NoFree : EnumAttr<"nofree">;
90113822Sphk
91113822Sphk/// Disable implicit floating point insts.
92113822Sphkdef NoImplicitFloat : EnumAttr<"noimplicitfloat">;
93113822Sphk
94113822Sphk/// inline=never.
95113822Sphkdef NoInline : EnumAttr<"noinline">;
96113822Sphk
97113822Sphk/// Function is called early and/or often, so lazy binding isn't worthwhile.
98113822Sphkdef NonLazyBind : EnumAttr<"nonlazybind">;
99113822Sphk
100113822Sphk/// Pointer is known to be not null.
101113822Sphkdef NonNull : EnumAttr<"nonnull">;
102113822Sphk
103113822Sphk/// The function does not recurse.
104113822Sphkdef NoRecurse : EnumAttr<"norecurse">;
105113822Sphk
106113822Sphk/// Disable redzone.
107113822Sphkdef NoRedZone : EnumAttr<"noredzone">;
108113822Sphk
109113822Sphk/// Mark the function as not returning.
110113822Sphkdef NoReturn : EnumAttr<"noreturn">;
111113822Sphk
112113822Sphk/// Function does not synchronize.
113113822Sphkdef NoSync : EnumAttr<"nosync">;
114113822Sphk
115113822Sphk/// Disable Indirect Branch Tracking.
116113822Sphkdef NoCfCheck : EnumAttr<"nocf_check">;
117113822Sphk
118113822Sphk/// Function doesn't unwind stack.
119113822Sphkdef NoUnwind : EnumAttr<"nounwind">;
120113822Sphk
121113822Sphk/// Select optimizations for best fuzzing signal.
122113897Sphkdef OptForFuzzing : EnumAttr<"optforfuzzing">;
123113897Sphk
124113897Sphk/// opt_size.
125113897Sphkdef OptimizeForSize : EnumAttr<"optsize">;
126113897Sphk
127113897Sphk/// Function must not be optimized.
128113897Sphkdef OptimizeNone : EnumAttr<"optnone">;
129113897Sphk
130113897Sphk/// Function does not access memory.
131113897Sphkdef ReadNone : EnumAttr<"readnone">;
132113897Sphk
133113897Sphk/// Function only reads from memory.
134113897Sphkdef ReadOnly : EnumAttr<"readonly">;
135113897Sphk
136113897Sphk/// Return value is always equal to this argument.
137113897Sphkdef Returned : EnumAttr<"returned">;
138113897Sphk
139113897Sphk/// Parameter is required to be a trivial constant.
140113897Sphkdef ImmArg : EnumAttr<"immarg">;
141113897Sphk
142113897Sphk/// Function can return twice.
143113897Sphkdef ReturnsTwice : EnumAttr<"returns_twice">;
144113897Sphk
145113897Sphk/// Safe Stack protection.
146113897Sphkdef SafeStack : EnumAttr<"safestack">;
147113897Sphk
148113822Sphk/// Shadow Call Stack protection.
149113822Sphkdef ShadowCallStack : EnumAttr<"shadowcallstack">;
150113822Sphk
151113822Sphk/// Sign extended before/after call.
152113822Sphkdef SExt : EnumAttr<"signext">;
153113822Sphk
154113822Sphk/// Alignment of stack for function (3 bits)  stored as log2 of alignment with
155113822Sphk/// +1 bias 0 means unaligned (different from alignstack=(1)).
156113822Sphkdef StackAlignment : EnumAttr<"alignstack">;
157113822Sphk
158/// Function can be speculated.
159def Speculatable : EnumAttr<"speculatable">;
160
161/// Stack protection.
162def StackProtect : EnumAttr<"ssp">;
163
164/// Stack protection required.
165def StackProtectReq : EnumAttr<"sspreq">;
166
167/// Strong Stack protection.
168def StackProtectStrong : EnumAttr<"sspstrong">;
169
170/// Function was called in a scope requiring strict floating point semantics.
171def StrictFP : EnumAttr<"strictfp">;
172
173/// Hidden pointer to structure to return.
174def StructRet : EnumAttr<"sret">;
175
176/// AddressSanitizer is on.
177def SanitizeAddress : EnumAttr<"sanitize_address">;
178
179/// ThreadSanitizer is on.
180def SanitizeThread : EnumAttr<"sanitize_thread">;
181
182/// MemorySanitizer is on.
183def SanitizeMemory : EnumAttr<"sanitize_memory">;
184
185/// HWAddressSanitizer is on.
186def SanitizeHWAddress : EnumAttr<"sanitize_hwaddress">;
187
188/// MemTagSanitizer is on.
189def SanitizeMemTag : EnumAttr<"sanitize_memtag">;
190
191/// Speculative Load Hardening is enabled.
192///
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.
197def SpeculativeLoadHardening : EnumAttr<"speculative_load_hardening">;
198
199/// Argument is swift error.
200def SwiftError : EnumAttr<"swifterror">;
201
202/// Argument is swift self/context.
203def SwiftSelf : EnumAttr<"swiftself">;
204
205/// Function must be in a unwind table.
206def UWTable : EnumAttr<"uwtable">;
207
208/// Function always comes back to callsite.
209def WillReturn : EnumAttr<"willreturn">;
210
211/// Function only writes to memory.
212def WriteOnly : EnumAttr<"writeonly">;
213
214/// Zero extended before/after call.
215def ZExt : EnumAttr<"zeroext">;
216
217/// Target-independent string attributes.
218def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;
219def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">;
220def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">;
221def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">;
222def NoJumpTables : StrBoolAttr<"no-jump-tables">;
223def NoInlineLineTables : StrBoolAttr<"no-inline-line-tables">;
224def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">;
225
226class CompatRule<string F> {
227  // The name of the function called to check the attribute of the caller and
228  // callee and decide whether inlining should be allowed. The function's
229  // signature must match "bool(const Function&, const Function &)", where the
230  // first parameter is the reference to the caller and the second parameter is
231  // the reference to the callee. It must return false if the attributes of the
232  // caller and callee are incompatible, and true otherwise.
233  string CompatFunc = F;
234}
235
236def : CompatRule<"isEqual<SanitizeAddressAttr>">;
237def : CompatRule<"isEqual<SanitizeThreadAttr>">;
238def : CompatRule<"isEqual<SanitizeMemoryAttr>">;
239def : CompatRule<"isEqual<SanitizeHWAddressAttr>">;
240def : CompatRule<"isEqual<SanitizeMemTagAttr>">;
241def : CompatRule<"isEqual<SafeStackAttr>">;
242def : CompatRule<"isEqual<ShadowCallStackAttr>">;
243
244class MergeRule<string F> {
245  // The name of the function called to merge the attributes of the caller and
246  // callee. The function's signature must match
247  // "void(Function&, const Function &)", where the first parameter is the
248  // reference to the caller and the second parameter is the reference to the
249  // callee.
250  string MergeFunc = F;
251}
252
253def : MergeRule<"setAND<LessPreciseFPMADAttr>">;
254def : MergeRule<"setAND<NoInfsFPMathAttr>">;
255def : MergeRule<"setAND<NoNansFPMathAttr>">;
256def : MergeRule<"setAND<UnsafeFPMathAttr>">;
257def : MergeRule<"setOR<NoImplicitFloatAttr>">;
258def : MergeRule<"setOR<NoJumpTablesAttr>">;
259def : MergeRule<"setOR<ProfileSampleAccurateAttr>">;
260def : MergeRule<"setOR<SpeculativeLoadHardeningAttr>">;
261def : MergeRule<"adjustCallerSSPLevel">;
262def : MergeRule<"adjustCallerStackProbes">;
263def : MergeRule<"adjustCallerStackProbeSize">;
264def : MergeRule<"adjustMinLegalVectorWidth">;
265def : MergeRule<"adjustNullPointerValidAttr">;
266