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