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