| Chris Lattner | c313d0b | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 1 | //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===// | 
|  | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 | 
| Chris Lattner | c313d0b | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 | // | 
|  | 9 | // This file defines a wrapper class for the 'Intrinsic' TableGen class. | 
|  | 10 | // | 
|  | 11 | //===----------------------------------------------------------------------===// | 
|  | 12 |  | 
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 13 | #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H | 
|  | 14 | #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H | 
| Chris Lattner | c313d0b | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 15 |  | 
| Matt Arsenault | 303327d | 2017-12-20 19:36:28 +0000 | [diff] [blame] | 16 | #include "SDNodeProperties.h" | 
| David Blaikie | 13e77db | 2018-03-23 23:58:25 +0000 | [diff] [blame] | 17 | #include "llvm/Support/MachineValueType.h" | 
| Chris Lattner | c313d0b | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 18 | #include <string> | 
|  | 19 | #include <vector> | 
|  | 20 |  | 
|  | 21 | namespace llvm { | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 22 | class Record; | 
|  | 23 | class RecordKeeper; | 
|  | 24 | class CodeGenTarget; | 
| Chris Lattner | c313d0b | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 25 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 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. | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 33 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 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; | 
| Duncan Sands | 13237ac | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 45 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 46 | /// The records for each return type. | 
|  | 47 | std::vector<Record *> RetTypeDefs; | 
| Bill Wendling | 9182147 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 48 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 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; | 
| Bill Wendling | 9182147 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 54 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 55 | /// The records for each parameter type. | 
|  | 56 | std::vector<Record *> ParamTypeDefs; | 
| Chris Lattner | c313d0b | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 57 | }; | 
|  | 58 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 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 { | 
| Andrew Kaylor | 57d35bf | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 65 | /// The intrinsic may access memory that is otherwise inaccessible via | 
|  | 66 | /// LLVM IR. | 
|  | 67 | MR_InaccessibleMem = 1, | 
|  | 68 |  | 
|  | 69 | /// The intrinsic may access memory through pointer arguments. | 
|  | 70 | /// LLVM IR. | 
|  | 71 | MR_ArgMem = 2, | 
|  | 72 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 73 | /// The intrinsic may access memory anywhere, i.e. it is not restricted | 
|  | 74 | /// to access through pointer arguments. | 
| Andrew Kaylor | 57d35bf | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 75 | MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem, | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 76 |  | 
|  | 77 | /// The intrinsic may read memory. | 
| Andrew Kaylor | 57d35bf | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 78 | MR_Ref = 8, | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 79 |  | 
|  | 80 | /// The intrinsic may write memory. | 
| Andrew Kaylor | 57d35bf | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 81 | MR_Mod = 16, | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 82 |  | 
|  | 83 | /// The intrinsic may both read and write memory. | 
|  | 84 | MR_ModRef = MR_Ref | MR_Mod, | 
|  | 85 | }; | 
|  | 86 |  | 
|  | 87 | /// Memory mod/ref behavior of this intrinsic, corresponding to intrinsic | 
|  | 88 | /// properties (IntrReadMem, IntrArgMemOnly, etc.). | 
|  | 89 | enum ModRefBehavior { | 
|  | 90 | NoMem = 0, | 
| Andrew Kaylor | 57d35bf | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 91 | ReadArgMem = MR_Ref | MR_ArgMem, | 
|  | 92 | ReadInaccessibleMem = MR_Ref | MR_InaccessibleMem, | 
|  | 93 | ReadInaccessibleMemOrArgMem = MR_Ref | MR_ArgMem | MR_InaccessibleMem, | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 94 | ReadMem = MR_Ref | MR_Anywhere, | 
| Andrew Kaylor | 57d35bf | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 95 | WriteArgMem = MR_Mod | MR_ArgMem, | 
|  | 96 | WriteInaccessibleMem = MR_Mod | MR_InaccessibleMem, | 
|  | 97 | WriteInaccessibleMemOrArgMem = MR_Mod | MR_ArgMem | MR_InaccessibleMem, | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 98 | WriteMem = MR_Mod | MR_Anywhere, | 
| Andrew Kaylor | 57d35bf | 2016-11-22 19:16:04 +0000 | [diff] [blame] | 99 | ReadWriteArgMem = MR_ModRef | MR_ArgMem, | 
|  | 100 | ReadWriteInaccessibleMem = MR_ModRef | MR_InaccessibleMem, | 
|  | 101 | ReadWriteInaccessibleMemOrArgMem = MR_ModRef | MR_ArgMem | | 
|  | 102 | MR_InaccessibleMem, | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 103 | ReadWriteMem = MR_ModRef | MR_Anywhere, | 
|  | 104 | }; | 
|  | 105 | ModRefBehavior ModRef; | 
|  | 106 |  | 
| Matt Arsenault | 303327d | 2017-12-20 19:36:28 +0000 | [diff] [blame] | 107 | /// SDPatternOperator Properties applied to the intrinsic. | 
|  | 108 | unsigned Properties; | 
|  | 109 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 110 | /// This is set to true if the intrinsic is overloaded by its argument | 
|  | 111 | /// types. | 
|  | 112 | bool isOverloaded; | 
|  | 113 |  | 
|  | 114 | /// True if the intrinsic is commutative. | 
|  | 115 | bool isCommutative; | 
|  | 116 |  | 
|  | 117 | /// True if the intrinsic can throw. | 
|  | 118 | bool canThrow; | 
|  | 119 |  | 
|  | 120 | /// True if the intrinsic is marked as noduplicate. | 
|  | 121 | bool isNoDuplicate; | 
|  | 122 |  | 
|  | 123 | /// True if the intrinsic is no-return. | 
|  | 124 | bool isNoReturn; | 
|  | 125 |  | 
| Hideto Ueno | 11d3710 | 2019-07-17 15:15:43 +0000 | [diff] [blame] | 126 | /// True if the intrinsic is will-return. | 
|  | 127 | bool isWillReturn; | 
|  | 128 |  | 
| Vedant Kumar | 808e157 | 2018-11-14 19:53:41 +0000 | [diff] [blame] | 129 | /// True if the intrinsic is cold. | 
|  | 130 | bool isCold; | 
|  | 131 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 132 | /// True if the intrinsic is marked as convergent. | 
|  | 133 | bool isConvergent; | 
|  | 134 |  | 
| Matt Arsenault | 868af92 | 2017-04-28 21:01:46 +0000 | [diff] [blame] | 135 | /// True if the intrinsic has side effects that aren't captured by any | 
|  | 136 | /// of the other flags. | 
|  | 137 | bool hasSideEffects; | 
|  | 138 |  | 
| Matt Arsenault | b19b57e | 2017-04-28 20:25:27 +0000 | [diff] [blame] | 139 | // True if the intrinsic is marked as speculatable. | 
|  | 140 | bool isSpeculatable; | 
|  | 141 |  | 
| Matt Arsenault | caf1316 | 2019-03-12 21:02:54 +0000 | [diff] [blame] | 142 | enum ArgAttribute { | 
|  | 143 | NoCapture, | 
| David Bolvansky | bb519c6 | 2019-08-14 08:33:07 +0000 | [diff] [blame] | 144 | NoAlias, | 
| Matt Arsenault | caf1316 | 2019-03-12 21:02:54 +0000 | [diff] [blame] | 145 | Returned, | 
|  | 146 | ReadOnly, | 
|  | 147 | WriteOnly, | 
|  | 148 | ReadNone, | 
|  | 149 | ImmArg | 
|  | 150 | }; | 
|  | 151 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 152 | std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes; | 
|  | 153 |  | 
| Matt Arsenault | 303327d | 2017-12-20 19:36:28 +0000 | [diff] [blame] | 154 | bool hasProperty(enum SDNP Prop) const { | 
|  | 155 | return Properties & (1 << Prop); | 
|  | 156 | } | 
|  | 157 |  | 
| Jessica Paquette | 5c8a29f | 2019-08-20 22:04:10 +0000 | [diff] [blame^] | 158 | /// Returns true if the parameter at \p ParamIdx is a pointer type. Returns | 
|  | 159 | /// false if the parameter is not a pointer, or \p ParamIdx is greater than | 
|  | 160 | /// the size of \p IS.ParamVTs. | 
|  | 161 | /// | 
|  | 162 | /// Note that this requires that \p IS.ParamVTs is available. | 
|  | 163 | bool isParamAPointer(unsigned ParamIdx) const; | 
|  | 164 |  | 
| Justin Bogner | acf564c | 2016-07-08 20:14:27 +0000 | [diff] [blame] | 165 | CodeGenIntrinsic(Record *R); | 
|  | 166 | }; | 
|  | 167 |  | 
| Justin Bogner | 92a8c61 | 2016-07-15 16:31:37 +0000 | [diff] [blame] | 168 | class CodeGenIntrinsicTable { | 
|  | 169 | std::vector<CodeGenIntrinsic> Intrinsics; | 
|  | 170 |  | 
|  | 171 | public: | 
|  | 172 | struct TargetSet { | 
|  | 173 | std::string Name; | 
|  | 174 | size_t Offset; | 
|  | 175 | size_t Count; | 
|  | 176 | }; | 
|  | 177 | std::vector<TargetSet> Targets; | 
|  | 178 |  | 
|  | 179 | explicit CodeGenIntrinsicTable(const RecordKeeper &RC, bool TargetOnly); | 
|  | 180 | CodeGenIntrinsicTable() = default; | 
|  | 181 |  | 
|  | 182 | bool empty() const { return Intrinsics.empty(); } | 
|  | 183 | size_t size() const { return Intrinsics.size(); } | 
|  | 184 | CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; } | 
|  | 185 | const CodeGenIntrinsic &operator[](size_t Pos) const { | 
|  | 186 | return Intrinsics[Pos]; | 
|  | 187 | } | 
|  | 188 | }; | 
| Chris Lattner | c313d0b | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 189 | } | 
|  | 190 |  | 
|  | 191 | #endif |