1 //===- CodeGenIntrinsics.h - Intrinsic Class Wrapper -----------*- C++ -*--===// 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 a wrapper class for the 'Intrinsic' TableGen class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H 14 #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H 15 16 #include "SDNodeProperties.h" 17 #include "llvm/ADT/ArrayRef.h" 18 #include "llvm/ADT/SmallVector.h" 19 #include "llvm/Support/ModRef.h" 20 #include <string> 21 #include <tuple> 22 #include <vector> 23 24 namespace llvm { 25 class Record; 26 class RecordKeeper; 27 28 struct CodeGenIntrinsic { 29 Record *TheDef; // The actual record defining this intrinsic. 30 std::string Name; // The name of the LLVM function "llvm.bswap.i32" 31 std::string EnumName; // The name of the enum "bswap_i32" 32 std::string ClangBuiltinName; // Name of the corresponding GCC builtin, or "". 33 std::string MSBuiltinName; // Name of the corresponding MS builtin, or "". 34 std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics. 35 36 /// This structure holds the return values and parameter values of an 37 /// intrinsic. If the number of return values is > 1, then the intrinsic 38 /// implicitly returns a first-class aggregate. The numbering of the types 39 /// starts at 0 with the first return value and continues from there through 40 /// the parameter list. This is useful for "matching" types. 41 struct IntrinsicSignature { 42 /// The MVT::SimpleValueType for each return type. Note that this list is 43 /// only populated when in the context of a target .td file. When building 44 /// Intrinsics.td, this isn't available, because we don't know the target 45 /// pointer size. 46 std::vector<Record *> RetTys; 47 48 /// The MVT::SimpleValueType for each parameter type. Note that this list is 49 /// only populated when in the context of a target .td file. When building 50 /// Intrinsics.td, this isn't available, because we don't know the target 51 /// pointer size. 52 std::vector<Record *> ParamTys; 53 }; 54 55 IntrinsicSignature IS; 56 57 /// Memory effects of the intrinsic. 58 MemoryEffects ME = MemoryEffects::unknown(); 59 60 /// SDPatternOperator Properties applied to the intrinsic. 61 unsigned Properties; 62 63 /// This is set to true if the intrinsic is overloaded by its argument 64 /// types. 65 bool isOverloaded; 66 67 /// True if the intrinsic is commutative. 68 bool isCommutative; 69 70 /// True if the intrinsic can throw. 71 bool canThrow; 72 73 /// True if the intrinsic is marked as noduplicate. 74 bool isNoDuplicate; 75 76 /// True if the intrinsic is marked as nomerge. 77 bool isNoMerge; 78 79 /// True if the intrinsic is no-return. 80 bool isNoReturn; 81 82 /// True if the intrinsic is no-callback. 83 bool isNoCallback; 84 85 /// True if the intrinsic is no-sync. 86 bool isNoSync; 87 88 /// True if the intrinsic is no-free. 89 bool isNoFree; 90 91 /// True if the intrinsic is will-return. 92 bool isWillReturn; 93 94 /// True if the intrinsic is cold. 95 bool isCold; 96 97 /// True if the intrinsic is marked as convergent. 98 bool isConvergent; 99 100 /// True if the intrinsic has side effects that aren't captured by any 101 /// of the other flags. 102 bool hasSideEffects; 103 104 // True if the intrinsic is marked as speculatable. 105 bool isSpeculatable; 106 107 // True if the intrinsic is marked as strictfp. 108 bool isStrictFP; 109 110 enum ArgAttrKind { 111 NoCapture, 112 NoAlias, 113 NoUndef, 114 NonNull, 115 Returned, 116 ReadOnly, 117 WriteOnly, 118 ReadNone, 119 ImmArg, 120 Alignment, 121 Dereferenceable 122 }; 123 124 struct ArgAttribute { 125 ArgAttrKind Kind; 126 uint64_t Value; 127 ArgAttributeCodeGenIntrinsic::ArgAttribute128 ArgAttribute(ArgAttrKind K, uint64_t V) : Kind(K), Value(V) {} 129 130 bool operator<(const ArgAttribute &Other) const { 131 return std::tie(Kind, Value) < std::tie(Other.Kind, Other.Value); 132 } 133 }; 134 135 /// Vector of attributes for each argument. 136 SmallVector<SmallVector<ArgAttribute, 0>> ArgumentAttributes; 137 138 void addArgAttribute(unsigned Idx, ArgAttrKind AK, uint64_t V = 0); 139 hasPropertyCodeGenIntrinsic140 bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); } 141 142 /// Goes through all IntrProperties that have IsDefault 143 /// value set and sets the property. 144 void setDefaultProperties(Record *R, ArrayRef<Record *> DefaultProperties); 145 146 /// Helper function to set property \p Name to true; 147 void setProperty(Record *R); 148 149 /// Returns true if the parameter at \p ParamIdx is a pointer type. Returns 150 /// false if the parameter is not a pointer, or \p ParamIdx is greater than 151 /// the size of \p IS.ParamVTs. 152 /// 153 /// Note that this requires that \p IS.ParamVTs is available. 154 bool isParamAPointer(unsigned ParamIdx) const; 155 156 bool isParamImmArg(unsigned ParamIdx) const; 157 158 CodeGenIntrinsic(Record *R, ArrayRef<Record *> DefaultProperties); 159 }; 160 161 class CodeGenIntrinsicTable { 162 std::vector<CodeGenIntrinsic> Intrinsics; 163 164 public: 165 struct TargetSet { 166 std::string Name; 167 size_t Offset; 168 size_t Count; 169 }; 170 std::vector<TargetSet> Targets; 171 172 explicit CodeGenIntrinsicTable(const RecordKeeper &RC); 173 CodeGenIntrinsicTable() = default; 174 empty()175 bool empty() const { return Intrinsics.empty(); } size()176 size_t size() const { return Intrinsics.size(); } begin()177 auto begin() const { return Intrinsics.begin(); } end()178 auto end() const { return Intrinsics.end(); } 179 CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; } 180 const CodeGenIntrinsic &operator[](size_t Pos) const { 181 return Intrinsics[Pos]; 182 } 183 }; 184 } // namespace llvm 185 186 #endif 187