blob: 24374127f536ad3f22d09f4d979d477438809ab2 [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
Patrik Hagglund8d09a6c2014-03-15 09:11:41 +000017#include "llvm/CodeGen/MachineValueType.h"
Chris Lattnerc313d0b2006-03-03 02:32:46 +000018#include <string>
19#include <vector>
20
21namespace llvm {
Justin Bogneracf564c2016-07-08 20:14:27 +000022class Record;
23class RecordKeeper;
24class CodeGenTarget;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000025
Justin Bogneracf564c2016-07-08 20:14:27 +000026struct 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 Sands13237ac2008-06-06 12:08:01 +000033
Justin Bogneracf564c2016-07-08 20:14:27 +000034 /// 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 Sands13237ac2008-06-06 12:08:01 +000045
Justin Bogneracf564c2016-07-08 20:14:27 +000046 /// The records for each return type.
47 std::vector<Record *> RetTypeDefs;
Bill Wendling91821472008-11-13 09:08:33 +000048
Justin Bogneracf564c2016-07-08 20:14:27 +000049 /// 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 Wendling91821472008-11-13 09:08:33 +000054
Justin Bogneracf564c2016-07-08 20:14:27 +000055 /// The records for each parameter type.
56 std::vector<Record *> ParamTypeDefs;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000057 };
58
Justin Bogneracf564c2016-07-08 20:14:27 +000059 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 Kaylor57d35bf2016-11-22 19:16:04 +000065 /// 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 Bogneracf564c2016-07-08 20:14:27 +000073 /// The intrinsic may access memory anywhere, i.e. it is not restricted
74 /// to access through pointer arguments.
Andrew Kaylor57d35bf2016-11-22 19:16:04 +000075 MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem,
Justin Bogneracf564c2016-07-08 20:14:27 +000076
77 /// The intrinsic may read memory.
Andrew Kaylor57d35bf2016-11-22 19:16:04 +000078 MR_Ref = 8,
Justin Bogneracf564c2016-07-08 20:14:27 +000079
80 /// The intrinsic may write memory.
Andrew Kaylor57d35bf2016-11-22 19:16:04 +000081 MR_Mod = 16,
Justin Bogneracf564c2016-07-08 20:14:27 +000082
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 Kaylor57d35bf2016-11-22 19:16:04 +000091 ReadArgMem = MR_Ref | MR_ArgMem,
92 ReadInaccessibleMem = MR_Ref | MR_InaccessibleMem,
93 ReadInaccessibleMemOrArgMem = MR_Ref | MR_ArgMem | MR_InaccessibleMem,
Justin Bogneracf564c2016-07-08 20:14:27 +000094 ReadMem = MR_Ref | MR_Anywhere,
Andrew Kaylor57d35bf2016-11-22 19:16:04 +000095 WriteArgMem = MR_Mod | MR_ArgMem,
96 WriteInaccessibleMem = MR_Mod | MR_InaccessibleMem,
97 WriteInaccessibleMemOrArgMem = MR_Mod | MR_ArgMem | MR_InaccessibleMem,
Justin Bogneracf564c2016-07-08 20:14:27 +000098 WriteMem = MR_Mod | MR_Anywhere,
Andrew Kaylor57d35bf2016-11-22 19:16:04 +000099 ReadWriteArgMem = MR_ModRef | MR_ArgMem,
100 ReadWriteInaccessibleMem = MR_ModRef | MR_InaccessibleMem,
101 ReadWriteInaccessibleMemOrArgMem = MR_ModRef | MR_ArgMem |
102 MR_InaccessibleMem,
Justin Bogneracf564c2016-07-08 20:14:27 +0000103 ReadWriteMem = MR_ModRef | MR_Anywhere,
104 };
105 ModRefBehavior ModRef;
106
107 /// This is set to true if the intrinsic is overloaded by its argument
108 /// types.
109 bool isOverloaded;
110
111 /// True if the intrinsic is commutative.
112 bool isCommutative;
113
114 /// True if the intrinsic can throw.
115 bool canThrow;
116
117 /// True if the intrinsic is marked as noduplicate.
118 bool isNoDuplicate;
119
120 /// True if the intrinsic is no-return.
121 bool isNoReturn;
122
123 /// True if the intrinsic is marked as convergent.
124 bool isConvergent;
125
Matt Arsenault868af922017-04-28 21:01:46 +0000126 /// True if the intrinsic has side effects that aren't captured by any
127 /// of the other flags.
128 bool hasSideEffects;
129
Matt Arsenaultb19b57e2017-04-28 20:25:27 +0000130 // True if the intrinsic is marked as speculatable.
131 bool isSpeculatable;
132
Hal Finkel47646c02016-07-11 01:28:42 +0000133 enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone };
Justin Bogneracf564c2016-07-08 20:14:27 +0000134 std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes;
135
136 CodeGenIntrinsic(Record *R);
137};
138
Justin Bogner92a8c612016-07-15 16:31:37 +0000139class CodeGenIntrinsicTable {
140 std::vector<CodeGenIntrinsic> Intrinsics;
141
142public:
143 struct TargetSet {
144 std::string Name;
145 size_t Offset;
146 size_t Count;
147 };
148 std::vector<TargetSet> Targets;
149
150 explicit CodeGenIntrinsicTable(const RecordKeeper &RC, bool TargetOnly);
151 CodeGenIntrinsicTable() = default;
152
153 bool empty() const { return Intrinsics.empty(); }
154 size_t size() const { return Intrinsics.size(); }
155 CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; }
156 const CodeGenIntrinsic &operator[](size_t Pos) const {
157 return Intrinsics[Pos];
158 }
159};
Chris Lattnerc313d0b2006-03-03 02:32:46 +0000160}
161
162#endif