1 //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines a wrapper class for the 'Intrinsic' TableGen class. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H 15 #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H 16 17 #include "llvm/CodeGen/MachineValueType.h" 18 #include <string> 19 #include <vector> 20 21 namespace llvm { 22 class Record; 23 class RecordKeeper; 24 class CodeGenTarget; 25 26 struct CodeGenIntrinsic { 27 Record *TheDef; // The actual record defining this intrinsic. 28 std::string Name; // The name of the LLVM function "llvm.bswap.i32" 29 std::string EnumName; // The name of the enum "bswap_i32" 30 std::string GCCBuiltinName; // Name of the corresponding GCC builtin, or "". 31 std::string MSBuiltinName; // Name of the corresponding MS builtin, or "". 32 std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics. 33 34 /// This structure holds the return values and parameter values of an 35 /// intrinsic. If the number of return values is > 1, then the intrinsic 36 /// implicitly returns a first-class aggregate. The numbering of the types 37 /// starts at 0 with the first return value and continues from there through 38 /// the parameter list. This is useful for "matching" types. 39 struct IntrinsicSignature { 40 /// The MVT::SimpleValueType for each return type. Note that this list is 41 /// only populated when in the context of a target .td file. When building 42 /// Intrinsics.td, this isn't available, because we don't know the target 43 /// pointer size. 44 std::vector<MVT::SimpleValueType> RetVTs; 45 46 /// The records for each return type. 47 std::vector<Record *> RetTypeDefs; 48 49 /// The MVT::SimpleValueType for each parameter type. Note that this list is 50 /// only populated when in the context of a target .td file. When building 51 /// Intrinsics.td, this isn't available, because we don't know the target 52 /// pointer size. 53 std::vector<MVT::SimpleValueType> ParamVTs; 54 55 /// The records for each parameter type. 56 std::vector<Record *> ParamTypeDefs; 57 }; 58 59 IntrinsicSignature IS; 60 61 /// Bit flags describing the type (ref/mod) and location of memory 62 /// accesses that may be performed by the intrinsics. Analogous to 63 /// \c FunctionModRefBehaviour. 64 enum ModRefBits { 65 /// The intrinsic may access memory anywhere, i.e. it is not restricted 66 /// to access through pointer arguments. 67 MR_Anywhere = 1, 68 69 /// The intrinsic may read memory. 70 MR_Ref = 2, 71 72 /// The intrinsic may write memory. 73 MR_Mod = 4, 74 75 /// The intrinsic may both read and write memory. 76 MR_ModRef = MR_Ref | MR_Mod, 77 }; 78 79 /// Memory mod/ref behavior of this intrinsic, corresponding to intrinsic 80 /// properties (IntrReadMem, IntrArgMemOnly, etc.). 81 enum ModRefBehavior { 82 NoMem = 0, 83 ReadArgMem = MR_Ref, 84 ReadMem = MR_Ref | MR_Anywhere, 85 WriteArgMem = MR_Mod, 86 WriteMem = MR_Mod | MR_Anywhere, 87 ReadWriteArgMem = MR_ModRef, 88 ReadWriteMem = MR_ModRef | MR_Anywhere, 89 }; 90 ModRefBehavior ModRef; 91 92 /// This is set to true if the intrinsic is overloaded by its argument 93 /// types. 94 bool isOverloaded; 95 96 /// True if the intrinsic is commutative. 97 bool isCommutative; 98 99 /// True if the intrinsic can throw. 100 bool canThrow; 101 102 /// True if the intrinsic is marked as noduplicate. 103 bool isNoDuplicate; 104 105 /// True if the intrinsic is no-return. 106 bool isNoReturn; 107 108 /// True if the intrinsic is marked as convergent. 109 bool isConvergent; 110 111 enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone }; 112 std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes; 113 114 CodeGenIntrinsic(Record *R); 115 }; 116 117 /// Read all of the intrinsics defined in the specified .td file. 118 std::vector<CodeGenIntrinsic> LoadIntrinsics(const RecordKeeper &RC, 119 bool TargetOnly); 120 } 121 122 #endif 123