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 /// Disable implicit floating point insts.
89 def NoImplicitFloat : EnumAttr<"noimplicitfloat">;
92 def NoInline : EnumAttr<"noinline">;
94 /// Function is called early and/or often, so lazy binding isn't worthwhile.
95 def NonLazyBind : EnumAttr<"nonlazybind">;
97 /// Pointer is known to be not null.
98 def NonNull : EnumAttr<"nonnull">;
100 /// The function does not recurse.
101 def NoRecurse : EnumAttr<"norecurse">;
104 def NoRedZone : EnumAttr<"noredzone">;
106 /// Mark the function as not returning.
107 def NoReturn : EnumAttr<"noreturn">;
109 /// Disable Indirect Branch Tracking.
110 def NoCfCheck : EnumAttr<"nocf_check">;
112 /// Function doesn't unwind stack.
113 def NoUnwind : EnumAttr<"nounwind">;
116 def OptimizeForSize : EnumAttr<"optsize">;
118 /// Function must not be optimized.
119 def OptimizeNone : EnumAttr<"optnone">;
121 /// Function does not access memory.
122 def ReadNone : EnumAttr<"readnone">;
124 /// Function only reads from memory.
125 def ReadOnly : EnumAttr<"readonly">;
127 /// Return value is always equal to this argument.
128 def Returned : EnumAttr<"returned">;
130 /// Function can return twice.
131 def ReturnsTwice : EnumAttr<"returns_twice">;
133 /// Safe Stack protection.
134 def SafeStack : EnumAttr<"safestack">;
136 /// Sign extended before/after call.
137 def SExt : EnumAttr<"signext">;
139 /// Alignment of stack for function (3 bits) stored as log2 of alignment with
140 /// +1 bias 0 means unaligned (different from alignstack=(1)).
141 def StackAlignment : EnumAttr<"alignstack">;
143 /// Function can be speculated.
144 def Speculatable : EnumAttr<"speculatable">;
146 /// Stack protection.
147 def StackProtect : EnumAttr<"ssp">;
149 /// Stack protection required.
150 def StackProtectReq : EnumAttr<"sspreq">;
152 /// Strong Stack protection.
153 def StackProtectStrong : EnumAttr<"sspstrong">;
155 /// Function was called in a scope requiring strict floating point semantics.
156 def StrictFP : EnumAttr<"strictfp">;
158 /// Hidden pointer to structure to return.
159 def StructRet : EnumAttr<"sret">;
161 /// AddressSanitizer is on.
162 def SanitizeAddress : EnumAttr<"sanitize_address">;
164 /// ThreadSanitizer is on.
165 def SanitizeThread : EnumAttr<"sanitize_thread">;
167 /// MemorySanitizer is on.
168 def SanitizeMemory : EnumAttr<"sanitize_memory">;
170 /// HWAddressSanitizer is on.
171 def SanitizeHWAddress : EnumAttr<"sanitize_hwaddress">;
173 /// Argument is swift error.
174 def SwiftError : EnumAttr<"swifterror">;
176 /// Argument is swift self/context.
177 def SwiftSelf : EnumAttr<"swiftself">;
179 /// Function must be in a unwind table.
180 def UWTable : EnumAttr<"uwtable">;
182 /// Function only writes to memory.
183 def WriteOnly : EnumAttr<"writeonly">;
185 /// Zero extended before/after call.
186 def ZExt : EnumAttr<"zeroext">;
188 /// Target-independent string attributes.
189 def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;
190 def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">;
191 def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">;
192 def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">;
193 def NoJumpTables : StrBoolAttr<"no-jump-tables">;
194 def ProfileSampleAccurate : StrBoolAttr<"profile-sample-accurate">;
196 class CompatRule<string F> {
197 // The name of the function called to check the attribute of the caller and
198 // callee and decide whether inlining should be allowed. The function's
199 // signature must match "bool(const Function&, const Function &)", where the
200 // first parameter is the reference to the caller and the second parameter is
201 // the reference to the callee. It must return false if the attributes of the
202 // caller and callee are incompatible, and true otherwise.
203 string CompatFunc = F;
206 def : CompatRule<"isEqual<SanitizeAddressAttr>">;
207 def : CompatRule<"isEqual<SanitizeThreadAttr>">;
208 def : CompatRule<"isEqual<SanitizeMemoryAttr>">;
209 def : CompatRule<"isEqual<SanitizeHWAddressAttr>">;
210 def : CompatRule<"isEqual<SafeStackAttr>">;
212 class MergeRule<string F> {
213 // The name of the function called to merge the attributes of the caller and
214 // callee. The function's signature must match
215 // "void(Function&, const Function &)", where the first parameter is the
216 // reference to the caller and the second parameter is the reference to the
218 string MergeFunc = F;
221 def : MergeRule<"setAND<LessPreciseFPMADAttr>">;
222 def : MergeRule<"setAND<NoInfsFPMathAttr>">;
223 def : MergeRule<"setAND<NoNansFPMathAttr>">;
224 def : MergeRule<"setAND<UnsafeFPMathAttr>">;
225 def : MergeRule<"setOR<NoImplicitFloatAttr>">;
226 def : MergeRule<"setOR<NoJumpTablesAttr>">;
227 def : MergeRule<"setOR<ProfileSampleAccurateAttr>">;
228 def : MergeRule<"adjustCallerSSPLevel">;
229 def : MergeRule<"adjustCallerStackProbes">;
230 def : MergeRule<"adjustCallerStackProbeSize">;