Home | History | Annotate | Download | only in IR
      1 /// Attribute base class.
      2 class Attr<string S> {
      3   // String representation of this attribute in the IR.
      4   string AttrString = S;
      5 }
      6 
      7 /// Enum attribute.
      8 class EnumAttr<string S> : Attr<S>;
      9 
     10 /// StringBool attribute.
     11 class StrBoolAttr<string S> : Attr<S>;
     12 
     13 /// Target-independent enum attributes.
     14 
     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">;
     18 
     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">;
     22 
     23 /// inline=always.
     24 def AlwaysInline : EnumAttr<"alwaysinline">;
     25 
     26 /// Function can access memory only using pointers based on its arguments.
     27 def ArgMemOnly : EnumAttr<"argmemonly">;
     28 
     29 /// Callee is recognized as a builtin, despite nobuiltin attribute on its
     30 /// declaration.
     31 def Builtin : EnumAttr<"builtin">;
     32 
     33 /// Pass structure by value.
     34 def ByVal : EnumAttr<"byval">;
     35 
     36 /// Marks function as being in a cold path.
     37 def Cold : EnumAttr<"cold">;
     38 
     39 /// Can only be moved to control-equivalent blocks.
     40 def Convergent : EnumAttr<"convergent">;
     41 
     42 /// Pointer is known to be dereferenceable.
     43 def Dereferenceable : EnumAttr<"dereferenceable">;
     44 
     45 /// Pointer is either null or dereferenceable.
     46 def DereferenceableOrNull : EnumAttr<"dereferenceable_or_null">;
     47 
     48 /// Function may only access memory that is inaccessible from IR.
     49 def InaccessibleMemOnly : EnumAttr<"inaccessiblememonly">;
     50 
     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">;
     54 
     55 /// Pass structure in an alloca.
     56 def InAlloca : EnumAttr<"inalloca">;
     57 
     58 /// Source said inlining was desirable.
     59 def InlineHint : EnumAttr<"inlinehint">;
     60 
     61 /// Force argument to be passed in register.
     62 def InReg : EnumAttr<"inreg">;
     63 
     64 /// Build jump-instruction tables and replace refs.
     65 def JumpTable : EnumAttr<"jumptable">;
     66 
     67 /// Function must be optimized for size first.
     68 def MinSize : EnumAttr<"minsize">;
     69 
     70 /// Naked function.
     71 def Naked : EnumAttr<"naked">;
     72 
     73 /// Nested function static chain.
     74 def Nest : EnumAttr<"nest">;
     75 
     76 /// Considered to not alias after call.
     77 def NoAlias : EnumAttr<"noalias">;
     78 
     79 /// Callee isn't recognized as a builtin.
     80 def NoBuiltin : EnumAttr<"nobuiltin">;
     81 
     82 /// Function creates no aliases of pointer.
     83 def NoCapture : EnumAttr<"nocapture">;
     84 
     85 /// Call cannot be duplicated.
     86 def NoDuplicate : EnumAttr<"noduplicate">;
     87 
     88 /// Disable implicit floating point insts.
     89 def NoImplicitFloat : EnumAttr<"noimplicitfloat">;
     90 
     91 /// inline=never.
     92 def NoInline : EnumAttr<"noinline">;
     93 
     94 /// Function is called early and/or often, so lazy binding isn't worthwhile.
     95 def NonLazyBind : EnumAttr<"nonlazybind">;
     96 
     97 /// Pointer is known to be not null.
     98 def NonNull : EnumAttr<"nonnull">;
     99 
    100 /// The function does not recurse.
    101 def NoRecurse : EnumAttr<"norecurse">;
    102 
    103 /// Disable redzone.
    104 def NoRedZone : EnumAttr<"noredzone">;
    105 
    106 /// Mark the function as not returning.
    107 def NoReturn : EnumAttr<"noreturn">;
    108 
    109 /// Function doesn't unwind stack.
    110 def NoUnwind : EnumAttr<"nounwind">;
    111 
    112 /// opt_size.
    113 def OptimizeForSize : EnumAttr<"optsize">;
    114 
    115 /// Function must not be optimized.
    116 def OptimizeNone : EnumAttr<"optnone">;
    117 
    118 /// Function does not access memory.
    119 def ReadNone : EnumAttr<"readnone">;
    120 
    121 /// Function only reads from memory.
    122 def ReadOnly : EnumAttr<"readonly">;
    123 
    124 /// Return value is always equal to this argument.
    125 def Returned : EnumAttr<"returned">;
    126 
    127 /// Function can return twice.
    128 def ReturnsTwice : EnumAttr<"returns_twice">;
    129 
    130 /// Safe Stack protection.
    131 def SafeStack : EnumAttr<"safestack">;
    132 
    133 /// Sign extended before/after call.
    134 def SExt : EnumAttr<"signext">;
    135 
    136 /// Alignment of stack for function (3 bits)  stored as log2 of alignment with
    137 /// +1 bias 0 means unaligned (different from alignstack=(1)).
    138 def StackAlignment : EnumAttr<"alignstack">;
    139 
    140 /// Stack protection.
    141 def StackProtect : EnumAttr<"ssp">;
    142 
    143 /// Stack protection required.
    144 def StackProtectReq : EnumAttr<"sspreq">;
    145 
    146 /// Strong Stack protection.
    147 def StackProtectStrong : EnumAttr<"sspstrong">;
    148 
    149 /// Hidden pointer to structure to return.
    150 def StructRet : EnumAttr<"sret">;
    151 
    152 /// AddressSanitizer is on.
    153 def SanitizeAddress : EnumAttr<"sanitize_address">;
    154 
    155 /// ThreadSanitizer is on.
    156 def SanitizeThread : EnumAttr<"sanitize_thread">;
    157 
    158 /// MemorySanitizer is on.
    159 def SanitizeMemory : EnumAttr<"sanitize_memory">;
    160 
    161 /// Argument is swift error.
    162 def SwiftError : EnumAttr<"swifterror">;
    163 
    164 /// Argument is swift self/context.
    165 def SwiftSelf : EnumAttr<"swiftself">;
    166 
    167 /// Function must be in a unwind table.
    168 def UWTable : EnumAttr<"uwtable">;
    169 
    170 /// Function only writes to memory.
    171 def WriteOnly : EnumAttr<"writeonly">;
    172 
    173 /// Zero extended before/after call.
    174 def ZExt : EnumAttr<"zeroext">;
    175 
    176 /// Target-independent string attributes.
    177 def LessPreciseFPMAD : StrBoolAttr<"less-precise-fpmad">;
    178 def NoInfsFPMath : StrBoolAttr<"no-infs-fp-math">;
    179 def NoNansFPMath : StrBoolAttr<"no-nans-fp-math">;
    180 def UnsafeFPMath : StrBoolAttr<"unsafe-fp-math">;
    181 def NoJumpTables : StrBoolAttr<"no-jump-tables">;
    182 
    183 class CompatRule<string F> {
    184   // The name of the function called to check the attribute of the caller and
    185   // callee and decide whether inlining should be allowed. The function's
    186   // signature must match "bool(const Function&, const Function &)", where the
    187   // first parameter is the reference to the caller and the second parameter is
    188   // the reference to the callee. It must return false if the attributes of the
    189   // caller and callee are incompatible, and true otherwise.
    190   string CompatFunc = F;
    191 }
    192 
    193 def : CompatRule<"isEqual<SanitizeAddressAttr>">;
    194 def : CompatRule<"isEqual<SanitizeThreadAttr>">;
    195 def : CompatRule<"isEqual<SanitizeMemoryAttr>">;
    196 def : CompatRule<"isEqual<SafeStackAttr>">;
    197 
    198 class MergeRule<string F> {
    199   // The name of the function called to merge the attributes of the caller and
    200   // callee. The function's signature must match
    201   // "void(Function&, const Function &)", where the first parameter is the
    202   // reference to the caller and the second parameter is the reference to the
    203   // callee.
    204   string MergeFunc = F;
    205 }
    206 
    207 def : MergeRule<"setAND<LessPreciseFPMADAttr>">;
    208 def : MergeRule<"setAND<NoInfsFPMathAttr>">;
    209 def : MergeRule<"setAND<NoNansFPMathAttr>">;
    210 def : MergeRule<"setAND<UnsafeFPMathAttr>">;
    211 def : MergeRule<"setOR<NoImplicitFloatAttr>">;
    212 def : MergeRule<"setOR<NoJumpTablesAttr>">;
    213 def : MergeRule<"adjustCallerSSPLevel">;
    214