blob: 9487a79c143238d20853564d4f562b4eb78bb7b0 [file] [log] [blame]
Chris Lattner9e493cf2006-03-03 02:32:46 +00001//===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner9e493cf2006-03-03 02:32:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a wrapper class for the 'Intrinsic' TableGen class.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer00e08fc2014-08-13 16:26:38 +000014#ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
15#define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
Chris Lattner9e493cf2006-03-03 02:32:46 +000016
Matt Arsenault082879a2017-12-20 19:36:28 +000017#include "SDNodeProperties.h"
David Blaikie9d9a46a2018-03-23 23:58:25 +000018#include "llvm/Support/MachineValueType.h"
Chris Lattner9e493cf2006-03-03 02:32:46 +000019#include <string>
20#include <vector>
21
22namespace llvm {
Justin Bogner56042632016-07-08 20:14:27 +000023class Record;
24class RecordKeeper;
25class CodeGenTarget;
Chris Lattner9e493cf2006-03-03 02:32:46 +000026
Justin Bogner56042632016-07-08 20:14:27 +000027struct 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 Sands83ec4b62008-06-06 12:08:01 +000034
Justin Bogner56042632016-07-08 20:14:27 +000035 /// 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 Sands83ec4b62008-06-06 12:08:01 +000046
Justin Bogner56042632016-07-08 20:14:27 +000047 /// The records for each return type.
48 std::vector<Record *> RetTypeDefs;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +000049
Justin Bogner56042632016-07-08 20:14:27 +000050 /// 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 Wendlingcdcc3e62008-11-13 09:08:33 +000055
Justin Bogner56042632016-07-08 20:14:27 +000056 /// The records for each parameter type.
57 std::vector<Record *> ParamTypeDefs;
Chris Lattner9e493cf2006-03-03 02:32:46 +000058 };
59
Justin Bogner56042632016-07-08 20:14:27 +000060 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 Kaylora5156e52016-11-22 19:16:04 +000066 /// 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 Bogner56042632016-07-08 20:14:27 +000074 /// The intrinsic may access memory anywhere, i.e. it is not restricted
75 /// to access through pointer arguments.
Andrew Kaylora5156e52016-11-22 19:16:04 +000076 MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem,
Justin Bogner56042632016-07-08 20:14:27 +000077
78 /// The intrinsic may read memory.
Andrew Kaylora5156e52016-11-22 19:16:04 +000079 MR_Ref = 8,
Justin Bogner56042632016-07-08 20:14:27 +000080
81 /// The intrinsic may write memory.
Andrew Kaylora5156e52016-11-22 19:16:04 +000082 MR_Mod = 16,
Justin Bogner56042632016-07-08 20:14:27 +000083
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 Kaylora5156e52016-11-22 19:16:04 +000092 ReadArgMem = MR_Ref | MR_ArgMem,
93 ReadInaccessibleMem = MR_Ref | MR_InaccessibleMem,
94 ReadInaccessibleMemOrArgMem = MR_Ref | MR_ArgMem | MR_InaccessibleMem,
Justin Bogner56042632016-07-08 20:14:27 +000095 ReadMem = MR_Ref | MR_Anywhere,
Andrew Kaylora5156e52016-11-22 19:16:04 +000096 WriteArgMem = MR_Mod | MR_ArgMem,
97 WriteInaccessibleMem = MR_Mod | MR_InaccessibleMem,
98 WriteInaccessibleMemOrArgMem = MR_Mod | MR_ArgMem | MR_InaccessibleMem,
Justin Bogner56042632016-07-08 20:14:27 +000099 WriteMem = MR_Mod | MR_Anywhere,
Andrew Kaylora5156e52016-11-22 19:16:04 +0000100 ReadWriteArgMem = MR_ModRef | MR_ArgMem,
101 ReadWriteInaccessibleMem = MR_ModRef | MR_InaccessibleMem,
102 ReadWriteInaccessibleMemOrArgMem = MR_ModRef | MR_ArgMem |
103 MR_InaccessibleMem,
Justin Bogner56042632016-07-08 20:14:27 +0000104 ReadWriteMem = MR_ModRef | MR_Anywhere,
105 };
106 ModRefBehavior ModRef;
107
Matt Arsenault082879a2017-12-20 19:36:28 +0000108 /// SDPatternOperator Properties applied to the intrinsic.
109 unsigned Properties;
110
Justin Bogner56042632016-07-08 20:14:27 +0000111 /// 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 Kumar3d60ff72018-11-14 19:53:41 +0000127 /// True if the intrinsic is cold.
128 bool isCold;
129
Justin Bogner56042632016-07-08 20:14:27 +0000130 /// True if the intrinsic is marked as convergent.
131 bool isConvergent;
132
Matt Arsenault8c9ed242017-04-28 21:01:46 +0000133 /// True if the intrinsic has side effects that aren't captured by any
134 /// of the other flags.
135 bool hasSideEffects;
136
Matt Arsenaultea376da2017-04-28 20:25:27 +0000137 // True if the intrinsic is marked as speculatable.
138 bool isSpeculatable;
139
Hal Finkelb7a19e92016-07-11 01:28:42 +0000140 enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone };
Justin Bogner56042632016-07-08 20:14:27 +0000141 std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes;
142
Matt Arsenault082879a2017-12-20 19:36:28 +0000143 bool hasProperty(enum SDNP Prop) const {
144 return Properties & (1 << Prop);
145 }
146
Justin Bogner56042632016-07-08 20:14:27 +0000147 CodeGenIntrinsic(Record *R);
148};
149
Justin Bognera3d02c72016-07-15 16:31:37 +0000150class CodeGenIntrinsicTable {
151 std::vector<CodeGenIntrinsic> Intrinsics;
152
153public:
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 Lattner9e493cf2006-03-03 02:32:46 +0000171}
172
173#endif