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