blob: 5d07159591207e5ce0e180c7edd17a0611952230 [file] [log] [blame]
Chris Lattnerc313d0b2006-03-03 02:32:46 +00001//===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner8adcd9f2007-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 Lattnerc313d0b2006-03-03 02:32:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a wrapper class for the 'Intrinsic' TableGen class.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
15#define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
Chris Lattnerc313d0b2006-03-03 02:32:46 +000016
Matt Arsenault303327d2017-12-20 19:36:28 +000017#include "SDNodeProperties.h"
David Blaikie13e77db2018-03-23 23:58:25 +000018#include "llvm/Support/MachineValueType.h"
Chris Lattnerc313d0b2006-03-03 02:32:46 +000019#include <string>
20#include <vector>
21
22namespace llvm {
Justin Bogneracf564c2016-07-08 20:14:27 +000023class Record;
24class RecordKeeper;
25class CodeGenTarget;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000026
Justin Bogneracf564c2016-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 Sands13237ac2008-06-06 12:08:01 +000034
Justin Bogneracf564c2016-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 Sands13237ac2008-06-06 12:08:01 +000046
Justin Bogneracf564c2016-07-08 20:14:27 +000047 /// The records for each return type.
48 std::vector<Record *> RetTypeDefs;
Bill Wendling91821472008-11-13 09:08:33 +000049
Justin Bogneracf564c2016-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 Wendling91821472008-11-13 09:08:33 +000055
Justin Bogneracf564c2016-07-08 20:14:27 +000056 /// The records for each parameter type.
57 std::vector<Record *> ParamTypeDefs;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000058 };
59
Justin Bogneracf564c2016-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 Kaylor57d35bf2016-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 Bogneracf564c2016-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 Kaylor57d35bf2016-11-22 19:16:04 +000076 MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem,
Justin Bogneracf564c2016-07-08 20:14:27 +000077
78 /// The intrinsic may read memory.
Andrew Kaylor57d35bf2016-11-22 19:16:04 +000079 MR_Ref = 8,
Justin Bogneracf564c2016-07-08 20:14:27 +000080
81 /// The intrinsic may write memory.
Andrew Kaylor57d35bf2016-11-22 19:16:04 +000082 MR_Mod = 16,
Justin Bogneracf564c2016-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 Kaylor57d35bf2016-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 Bogneracf564c2016-07-08 20:14:27 +000095 ReadMem = MR_Ref | MR_Anywhere,
Andrew Kaylor57d35bf2016-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 Bogneracf564c2016-07-08 20:14:27 +000099 WriteMem = MR_Mod | MR_Anywhere,
Andrew Kaylor57d35bf2016-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 Bogneracf564c2016-07-08 20:14:27 +0000104 ReadWriteMem = MR_ModRef | MR_Anywhere,
105 };
106 ModRefBehavior ModRef;
107
Matt Arsenault303327d2017-12-20 19:36:28 +0000108 /// SDPatternOperator Properties applied to the intrinsic.
109 unsigned Properties;
110
Justin Bogneracf564c2016-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
127 /// True if the intrinsic is marked as convergent.
128 bool isConvergent;
129
Matt Arsenault868af922017-04-28 21:01:46 +0000130 /// True if the intrinsic has side effects that aren't captured by any
131 /// of the other flags.
132 bool hasSideEffects;
133
Matt Arsenaultb19b57e2017-04-28 20:25:27 +0000134 // True if the intrinsic is marked as speculatable.
135 bool isSpeculatable;
136
Hal Finkel47646c02016-07-11 01:28:42 +0000137 enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone };
Justin Bogneracf564c2016-07-08 20:14:27 +0000138 std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes;
139
Matt Arsenault303327d2017-12-20 19:36:28 +0000140 bool hasProperty(enum SDNP Prop) const {
141 return Properties & (1 << Prop);
142 }
143
Justin Bogneracf564c2016-07-08 20:14:27 +0000144 CodeGenIntrinsic(Record *R);
145};
146
Justin Bogner92a8c612016-07-15 16:31:37 +0000147class CodeGenIntrinsicTable {
148 std::vector<CodeGenIntrinsic> Intrinsics;
149
150public:
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};
Chris Lattnerc313d0b2006-03-03 02:32:46 +0000168}
169
170#endif