Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 1 | //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 3060910 | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a wrapper class for the 'Intrinsic' TableGen class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 00e08fc | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H |
| 15 | #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 16 | |
Matt Arsenault | 082879a | 2017-12-20 19:36:28 +0000 | [diff] [blame] | 17 | #include "SDNodeProperties.h" |
David Blaikie | 9d9a46a | 2018-03-23 23:58:25 +0000 | [diff] [blame] | 18 | #include "llvm/Support/MachineValueType.h" |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
| 22 | namespace llvm { |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 23 | class Record; |
| 24 | class RecordKeeper; |
| 25 | class CodeGenTarget; |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 26 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 27 | struct CodeGenIntrinsic { |
| 28 | Record *TheDef; // The actual record defining this intrinsic. |
| 29 | std::string Name; // The name of the LLVM function "llvm.bswap.i32" |
| 30 | std::string EnumName; // The name of the enum "bswap_i32" |
| 31 | std::string GCCBuiltinName; // Name of the corresponding GCC builtin, or "". |
| 32 | std::string MSBuiltinName; // Name of the corresponding MS builtin, or "". |
| 33 | std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 34 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 35 | /// This structure holds the return values and parameter values of an |
| 36 | /// intrinsic. If the number of return values is > 1, then the intrinsic |
| 37 | /// implicitly returns a first-class aggregate. The numbering of the types |
| 38 | /// starts at 0 with the first return value and continues from there through |
| 39 | /// the parameter list. This is useful for "matching" types. |
| 40 | struct IntrinsicSignature { |
| 41 | /// The MVT::SimpleValueType for each return type. Note that this list is |
| 42 | /// only populated when in the context of a target .td file. When building |
| 43 | /// Intrinsics.td, this isn't available, because we don't know the target |
| 44 | /// pointer size. |
| 45 | std::vector<MVT::SimpleValueType> RetVTs; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 46 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 47 | /// The records for each return type. |
| 48 | std::vector<Record *> RetTypeDefs; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 49 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 50 | /// The MVT::SimpleValueType for each parameter type. Note that this list is |
| 51 | /// only populated when in the context of a target .td file. When building |
| 52 | /// Intrinsics.td, this isn't available, because we don't know the target |
| 53 | /// pointer size. |
| 54 | std::vector<MVT::SimpleValueType> ParamVTs; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 55 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 56 | /// The records for each parameter type. |
| 57 | std::vector<Record *> ParamTypeDefs; |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 60 | IntrinsicSignature IS; |
| 61 | |
| 62 | /// Bit flags describing the type (ref/mod) and location of memory |
| 63 | /// accesses that may be performed by the intrinsics. Analogous to |
| 64 | /// \c FunctionModRefBehaviour. |
| 65 | enum ModRefBits { |
Andrew Kaylor | a5156e5 | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 66 | /// The intrinsic may access memory that is otherwise inaccessible via |
| 67 | /// LLVM IR. |
| 68 | MR_InaccessibleMem = 1, |
| 69 | |
| 70 | /// The intrinsic may access memory through pointer arguments. |
| 71 | /// LLVM IR. |
| 72 | MR_ArgMem = 2, |
| 73 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 74 | /// The intrinsic may access memory anywhere, i.e. it is not restricted |
| 75 | /// to access through pointer arguments. |
Andrew Kaylor | a5156e5 | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 76 | MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem, |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 77 | |
| 78 | /// The intrinsic may read memory. |
Andrew Kaylor | a5156e5 | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 79 | MR_Ref = 8, |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 80 | |
| 81 | /// The intrinsic may write memory. |
Andrew Kaylor | a5156e5 | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 82 | MR_Mod = 16, |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 83 | |
| 84 | /// The intrinsic may both read and write memory. |
| 85 | MR_ModRef = MR_Ref | MR_Mod, |
| 86 | }; |
| 87 | |
| 88 | /// Memory mod/ref behavior of this intrinsic, corresponding to intrinsic |
| 89 | /// properties (IntrReadMem, IntrArgMemOnly, etc.). |
| 90 | enum ModRefBehavior { |
| 91 | NoMem = 0, |
Andrew Kaylor | a5156e5 | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 92 | ReadArgMem = MR_Ref | MR_ArgMem, |
| 93 | ReadInaccessibleMem = MR_Ref | MR_InaccessibleMem, |
| 94 | ReadInaccessibleMemOrArgMem = MR_Ref | MR_ArgMem | MR_InaccessibleMem, |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 95 | ReadMem = MR_Ref | MR_Anywhere, |
Andrew Kaylor | a5156e5 | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 96 | WriteArgMem = MR_Mod | MR_ArgMem, |
| 97 | WriteInaccessibleMem = MR_Mod | MR_InaccessibleMem, |
| 98 | WriteInaccessibleMemOrArgMem = MR_Mod | MR_ArgMem | MR_InaccessibleMem, |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 99 | WriteMem = MR_Mod | MR_Anywhere, |
Andrew Kaylor | a5156e5 | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 100 | ReadWriteArgMem = MR_ModRef | MR_ArgMem, |
| 101 | ReadWriteInaccessibleMem = MR_ModRef | MR_InaccessibleMem, |
| 102 | ReadWriteInaccessibleMemOrArgMem = MR_ModRef | MR_ArgMem | |
| 103 | MR_InaccessibleMem, |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 104 | ReadWriteMem = MR_ModRef | MR_Anywhere, |
| 105 | }; |
| 106 | ModRefBehavior ModRef; |
| 107 | |
Matt Arsenault | 082879a | 2017-12-20 19:36:28 +0000 | [diff] [blame] | 108 | /// SDPatternOperator Properties applied to the intrinsic. |
| 109 | unsigned Properties; |
| 110 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 111 | /// This is set to true if the intrinsic is overloaded by its argument |
| 112 | /// types. |
| 113 | bool isOverloaded; |
| 114 | |
| 115 | /// True if the intrinsic is commutative. |
| 116 | bool isCommutative; |
| 117 | |
| 118 | /// True if the intrinsic can throw. |
| 119 | bool canThrow; |
| 120 | |
| 121 | /// True if the intrinsic is marked as noduplicate. |
| 122 | bool isNoDuplicate; |
| 123 | |
| 124 | /// True if the intrinsic is no-return. |
| 125 | bool isNoReturn; |
| 126 | |
Vedant Kumar | 3d60ff7 | 2018-11-14 19:53:41 +0000 | [diff] [blame] | 127 | /// True if the intrinsic is cold. |
| 128 | bool isCold; |
| 129 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 130 | /// True if the intrinsic is marked as convergent. |
| 131 | bool isConvergent; |
| 132 | |
Matt Arsenault | 8c9ed24 | 2017-04-28 21:01:46 +0000 | [diff] [blame] | 133 | /// True if the intrinsic has side effects that aren't captured by any |
| 134 | /// of the other flags. |
| 135 | bool hasSideEffects; |
| 136 | |
Matt Arsenault | ea376da | 2017-04-28 20:25:27 +0000 | [diff] [blame] | 137 | // True if the intrinsic is marked as speculatable. |
| 138 | bool isSpeculatable; |
| 139 | |
Hal Finkel | b7a19e9 | 2016-07-11 01:28:42 +0000 | [diff] [blame] | 140 | enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone }; |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 141 | std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes; |
| 142 | |
Matt Arsenault | 082879a | 2017-12-20 19:36:28 +0000 | [diff] [blame] | 143 | bool hasProperty(enum SDNP Prop) const { |
| 144 | return Properties & (1 << Prop); |
| 145 | } |
| 146 | |
Justin Bogner | 5604263 | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 147 | CodeGenIntrinsic(Record *R); |
| 148 | }; |
| 149 | |
Justin Bogner | a3d02c7 | 2016-07-15 16:31:37 +0000 | [diff] [blame] | 150 | class CodeGenIntrinsicTable { |
| 151 | std::vector<CodeGenIntrinsic> Intrinsics; |
| 152 | |
| 153 | public: |
| 154 | struct TargetSet { |
| 155 | std::string Name; |
| 156 | size_t Offset; |
| 157 | size_t Count; |
| 158 | }; |
| 159 | std::vector<TargetSet> Targets; |
| 160 | |
| 161 | explicit CodeGenIntrinsicTable(const RecordKeeper &RC, bool TargetOnly); |
| 162 | CodeGenIntrinsicTable() = default; |
| 163 | |
| 164 | bool empty() const { return Intrinsics.empty(); } |
| 165 | size_t size() const { return Intrinsics.size(); } |
| 166 | CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; } |
| 167 | const CodeGenIntrinsic &operator[](size_t Pos) const { |
| 168 | return Intrinsics[Pos]; |
| 169 | } |
| 170 | }; |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | #endif |