LLVM: lib/CodeGen/SelectionDAG/SDNodeInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
14
15using namespace llvm;
16
18 const Twine &Msg) {
19 std::string S;
21 SS << "invalid node: " << Msg << '\n';
22 N->printrWithDepth(SS, &DAG, 2);
24}
25
27 unsigned ResIdx, EVT ExpectedVT) {
28 EVT ActualVT = N->getValueType(ResIdx);
29 if (ActualVT != ExpectedVT)
31 DAG, N,
32 "result #" + Twine(ResIdx) + " has invalid type; expected " +
34}
35
37 unsigned OpIdx, EVT ExpectedVT) {
38 EVT ActualVT = N->getOperand(OpIdx).getValueType();
39 if (ActualVT != ExpectedVT)
41 DAG, N,
42 "operand #" + Twine(OpIdx) + " has invalid type; expected " +
44}
45
46namespace {
47
48
49
50class SDNodeValue {
51 const SDNode *N;
52 unsigned Idx;
53 bool IsRes;
54
55public:
56 SDNodeValue(const SDNode *N, unsigned Idx, bool IsRes)
57 : N(N), Idx(Idx), IsRes(IsRes) {}
58
59 SDValue getValue() const {
60 return IsRes ? SDValue(const_cast<SDNode *>(N), Idx) : N->getOperand(Idx);
61 }
62
63 EVT getValueType() const { return getValue().getValueType(); }
64
65 friend raw_ostream &operator<<(raw_ostream &OS, const SDNodeValue &Op) {
66 return OS << (Op.IsRes ? "result" : "operand") << " #" << Op.Idx;
67 }
68};
69
70}
71
79
80 unsigned ActualNumResults = N->getNumValues();
81 unsigned ExpectedNumResults = Desc.NumResults + HasChain + HasOutGlue;
82
83 if (ActualNumResults != ExpectedNumResults)
85 "invalid number of results; expected " +
86 Twine(ExpectedNumResults) + ", got " +
87 Twine(ActualNumResults));
88
89
90 if (HasChain) {
91 unsigned ChainResIdx = Desc.NumResults;
93 }
94
95
96 if (HasOutGlue) {
97 unsigned GlueResIdx = Desc.NumResults + HasChain;
99 }
100
101
102
103
104
105 bool HasOptionalOperands = Desc.NumOperands < 0 || IsVariadic;
106
107 unsigned ActualNumOperands = N->getNumOperands();
108 unsigned ExpectedMinNumOperands =
109 (Desc.NumOperands >= 0 ? Desc.NumOperands : 0) + HasChain + HasInGlue;
110
111
112 if (ActualNumOperands < ExpectedMinNumOperands) {
113 StringRef How = HasOptionalOperands ? "at least " : "";
115 "invalid number of operands; expected " + How +
116 Twine(ExpectedMinNumOperands) + ", got " +
117 Twine(ActualNumOperands));
118 }
119
120
121
122 if (Desc.NumOperands >= 0 && !IsVariadic) {
123
124 unsigned ExpectedMaxNumOperands = ExpectedMinNumOperands + HasOptInGlue;
125 if (ActualNumOperands > ExpectedMaxNumOperands) {
126 StringRef How = HasOptInGlue ? "at most " : "";
128 "invalid number of operands; expected " + How +
129 Twine(ExpectedMaxNumOperands) + ", got " +
130 Twine(ActualNumOperands));
131 }
132 }
133
134
135 if (HasChain)
137
138
139 if (HasInGlue)
141 if (HasOptInGlue && ActualNumOperands >= 1 &&
142 N->getOperand(ActualNumOperands - 1).getValueType() == MVT::Glue)
143 HasInGlue = true;
144
145
146 if (IsVariadic && Desc.NumOperands >= 0) {
147 unsigned VarOpStart = HasChain + Desc.NumOperands;
148 unsigned VarOpEnd = ActualNumOperands - HasInGlue;
149 for (unsigned OpIdx = VarOpStart; OpIdx != VarOpEnd; ++OpIdx) {
150 unsigned OpOpcode = N->getOperand(OpIdx).getOpcode();
153 "variadic operand #" + Twine(OpIdx) +
154 " must be Register or RegisterMask");
155 }
156 }
157
158 unsigned VTHwMode =
160
161
162
163
164
165 auto GetConstraintValue = [&](unsigned ValIdx) {
166 if (ValIdx < Desc.NumResults)
167 return SDNodeValue(N, ValIdx, true);
168 return SDNodeValue(N, HasChain + (ValIdx - Desc.NumResults),
169 false);
170 };
171
173 if (.NumHwModes)
175 for (auto [Mode, VT] : ArrayRef(&VTByHwModeTable[C.VT], C.NumHwModes))
176 if (Mode == VTHwMode)
177 return VT;
179 };
180
183
185 SDNodeValue Val = GetConstraintValue(C.ConstrainedValIdx);
186 EVT VT = Val.getValueType();
187
188 switch (C.Kind) {
190 EVT ExpectedVT = GetConstraintVT(C);
191
192 bool IsPtr = ExpectedVT == MVT::iPTR;
193 if (IsPtr)
194 ExpectedVT =
196
197 if (VT != ExpectedVT) {
198 SS << Val << " must have type " << ExpectedVT;
199 if (IsPtr)
200 SS << " (iPTR)";
201 SS << ", but has type " << VT;
203 }
204 break;
205 }
207 break;
209 break;
211 break;
213 break;
215 break;
217 break;
219 break;
221 break;
223 break;
225 EVT ExpectedVT = GetConstraintVT(C);
226
228 SS << Val << " must have vector type";
230 }
232 SS << Val << " must have " << ExpectedVT << " element type, but has "
235 }
236 break;
237 }
239 break;
241 break;
242 }
243 }
244}
MachineInstr unsigned OpIdx
static void checkOperandType(const SelectionDAG &DAG, const SDNode *N, unsigned OpIdx, EVT ExpectedVT)
Definition SDNodeInfo.cpp:36
static void reportNodeError(const SelectionDAG &DAG, const SDNode *N, const Twine &Msg)
Definition SDNodeInfo.cpp:17
static void checkResultType(const SelectionDAG &DAG, const SDNode *N, unsigned ResIdx, EVT ExpectedVT)
Definition SDNodeInfo.cpp:26
static Type * getValueType(Value *V)
Returns the type of the given value/instruction V.
This file describes how to lower LLVM code to machine code.
virtual unsigned getHwMode(enum HwModeType type=HwMode_Default) const
HwMode ID corresponding to the 'type' parameter is retrieved from the HwMode bit set of the current s...
const SDNodeDesc & getDesc(unsigned Opcode) const
Returns the description of a node with the given opcode.
void verifyNode(const SelectionDAG &DAG, const SDNode *N) const
Definition SDNodeInfo.cpp:72
ArrayRef< SDTypeConstraint > getConstraints(unsigned Opcode) const
Returns operand constraints for a node with the given opcode.
Represents one node in the SelectionDAG.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
const TargetSubtargetInfo & getSubtarget() const
const TargetLowering & getTargetLoweringInfo() const
const DataLayout & getDataLayout() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI std::string getEVTString() const
This function returns value type as a string, e.g. "i32".
bool isVector() const
Return true if this is a vector value type.
EVT getVectorElementType() const
Given a vector type, return the type of each element.