]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/utils/TableGen/CodeGenIntrinsics.h
Merge llvm trunk r321414 to contrib/llvm.
[FreeBSD/FreeBSD.git] / contrib / llvm / utils / TableGen / CodeGenIntrinsics.h
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 "SDNodeProperties.h"
18 #include "llvm/CodeGen/MachineValueType.h"
19 #include <string>
20 #include <vector>
21
22 namespace llvm {
23 class Record;
24 class RecordKeeper;
25 class CodeGenTarget;
26
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.
34
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;
46
47     /// The records for each return type.
48     std::vector<Record *> RetTypeDefs;
49
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;
55
56     /// The records for each parameter type.
57     std::vector<Record *> ParamTypeDefs;
58   };
59
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 {
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
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,
77
78     /// The intrinsic may read memory.
79     MR_Ref = 8,
80
81     /// The intrinsic may write memory.
82     MR_Mod = 16,
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,
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 |
103                                        MR_InaccessibleMem,
104     ReadWriteMem = MR_ModRef | MR_Anywhere,
105   };
106   ModRefBehavior ModRef;
107
108   /// SDPatternOperator Properties applied to the intrinsic.
109   unsigned Properties;
110
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
127   /// True if the intrinsic is marked as convergent.
128   bool isConvergent;
129
130   /// True if the intrinsic has side effects that aren't captured by any
131   /// of the other flags.
132   bool hasSideEffects;
133
134   // True if the intrinsic is marked as speculatable.
135   bool isSpeculatable;
136
137   enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone };
138   std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes;
139
140   bool hasProperty(enum SDNP Prop) const {
141     return Properties & (1 << Prop);
142   }
143
144   CodeGenIntrinsic(Record *R);
145 };
146
147 class CodeGenIntrinsicTable {
148   std::vector<CodeGenIntrinsic> Intrinsics;
149
150 public:
151   struct TargetSet {
152     std::string Name;
153     size_t Offset;
154     size_t Count;
155   };
156   std::vector<TargetSet> Targets;
157
158   explicit CodeGenIntrinsicTable(const RecordKeeper &RC, bool TargetOnly);
159   CodeGenIntrinsicTable() = default;
160
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];
166   }
167 };
168 }
169
170 #endif