1 //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a wrapper class for the 'Intrinsic' TableGen class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
15 #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
17 #include "SDNodeProperties.h"
18 #include "llvm/CodeGen/MachineValueType.h"
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.
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
45 std::vector<MVT::SimpleValueType> RetVTs;
47 /// The records for each return type.
48 std::vector<Record *> RetTypeDefs;
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
54 std::vector<MVT::SimpleValueType> ParamVTs;
56 /// The records for each parameter type.
57 std::vector<Record *> ParamTypeDefs;
60 IntrinsicSignature IS;
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.
66 /// The intrinsic may access memory that is otherwise inaccessible via
68 MR_InaccessibleMem = 1,
70 /// The intrinsic may access memory through pointer arguments.
74 /// The intrinsic may access memory anywhere, i.e. it is not restricted
75 /// to access through pointer arguments.
76 MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem,
78 /// The intrinsic may read memory.
81 /// The intrinsic may write memory.
84 /// The intrinsic may both read and write memory.
85 MR_ModRef = MR_Ref | MR_Mod,
88 /// Memory mod/ref behavior of this intrinsic, corresponding to intrinsic
89 /// properties (IntrReadMem, IntrArgMemOnly, etc.).
92 ReadArgMem = MR_Ref | MR_ArgMem,
93 ReadInaccessibleMem = MR_Ref | MR_InaccessibleMem,
94 ReadInaccessibleMemOrArgMem = MR_Ref | MR_ArgMem | MR_InaccessibleMem,
95 ReadMem = MR_Ref | MR_Anywhere,
96 WriteArgMem = MR_Mod | MR_ArgMem,
97 WriteInaccessibleMem = MR_Mod | MR_InaccessibleMem,
98 WriteInaccessibleMemOrArgMem = MR_Mod | MR_ArgMem | MR_InaccessibleMem,
99 WriteMem = MR_Mod | MR_Anywhere,
100 ReadWriteArgMem = MR_ModRef | MR_ArgMem,
101 ReadWriteInaccessibleMem = MR_ModRef | MR_InaccessibleMem,
102 ReadWriteInaccessibleMemOrArgMem = MR_ModRef | MR_ArgMem |
104 ReadWriteMem = MR_ModRef | MR_Anywhere,
106 ModRefBehavior ModRef;
108 /// SDPatternOperator Properties applied to the intrinsic.
111 /// This is set to true if the intrinsic is overloaded by its argument
115 /// True if the intrinsic is commutative.
118 /// True if the intrinsic can throw.
121 /// True if the intrinsic is marked as noduplicate.
124 /// True if the intrinsic is no-return.
127 /// True if the intrinsic is marked as convergent.
130 /// True if the intrinsic has side effects that aren't captured by any
131 /// of the other flags.
134 // True if the intrinsic is marked as speculatable.
137 enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone };
138 std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes;
140 bool hasProperty(enum SDNP Prop) const {
141 return Properties & (1 << Prop);
144 CodeGenIntrinsic(Record *R);
147 class CodeGenIntrinsicTable {
148 std::vector<CodeGenIntrinsic> Intrinsics;
156 std::vector<TargetSet> Targets;
158 explicit CodeGenIntrinsicTable(const RecordKeeper &RC, bool TargetOnly);
159 CodeGenIntrinsicTable() = default;
161 bool empty() const { return Intrinsics.empty(); }
162 size_t size() const { return Intrinsics.size(); }
163 CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; }
164 const CodeGenIntrinsic &operator[](size_t Pos) const {
165 return Intrinsics[Pos];