@@ -45,21 +45,27 @@ static void checkOperandType(const SelectionDAG &DAG, const SDNode *N,
4545
4646namespace {
4747
48- struct ConstraintOp {
48+ // / Similar to SDValue, but also records whether it is a result or an operand
49+ // / of a node so we can provide more precise diagnostics.
50+ class SDNodeValue {
4951 const SDNode *N;
5052 unsigned Idx;
5153 bool IsRes;
5254
55+ public:
56+ SDNodeValue (const SDNode *N, unsigned Idx, bool IsRes)
57+ : N(N), Idx(Idx), IsRes(IsRes) {}
58+
5359 SDValue getValue () const {
5460 return IsRes ? SDValue (const_cast <SDNode *>(N), Idx) : N->getOperand (Idx);
5561 }
5662
5763 EVT getValueType () const { return getValue ().getValueType (); }
58- };
5964
60- raw_ostream &operator <<(raw_ostream &OS, const ConstraintOp &Op) {
61- return OS << (Op.IsRes ? " result" : " operand" ) << " #" << Op.Idx ;
62- }
65+ friend raw_ostream &operator <<(raw_ostream &OS, const SDNodeValue &Op) {
66+ return OS << (Op.IsRes ? " result" : " operand" ) << " #" << Op.Idx ;
67+ }
68+ };
6369
6470} // namespace
6571
@@ -152,10 +158,15 @@ void SDNodeInfo::verifyNode(const SelectionDAG &DAG, const SDNode *N) const {
152158 unsigned VTHwMode =
153159 DAG.getSubtarget ().getHwMode (MCSubtargetInfo::HwMode_ValueType);
154160
155- auto GetConstraintOp = [&](unsigned Idx) {
156- if (Idx < Desc.NumResults )
157- return ConstraintOp{N, Idx, /* IsRes=*/ true };
158- return ConstraintOp{N, HasChain + (Idx - Desc.NumResults ), /* IsRes=*/ false };
161+ // Returns a constrained or constraining value (result or operand) of a node.
162+ // ValIdx is the index of a node's value, as defined by SDTypeConstraint;
163+ // that is, it indexes a node's operands after its results and ignores
164+ // chain/glue values.
165+ auto GetConstraintValue = [&](unsigned ValIdx) {
166+ if (ValIdx < Desc.NumResults )
167+ return SDNodeValue (N, ValIdx, /* IsRes=*/ true );
168+ return SDNodeValue (N, HasChain + (ValIdx - Desc.NumResults ),
169+ /* IsRes=*/ false );
159170 };
160171
161172 auto GetConstraintVT = [&](const SDTypeConstraint &C) {
@@ -171,8 +182,8 @@ void SDNodeInfo::verifyNode(const SelectionDAG &DAG, const SDNode *N) const {
171182 raw_svector_ostream SS (ES);
172183
173184 for (const SDTypeConstraint &C : getConstraints (N->getOpcode ())) {
174- ConstraintOp Op = GetConstraintOp (C.OpNo );
175- EVT OpVT = Op .getValueType ();
185+ SDNodeValue Val = GetConstraintValue (C.ConstrainedValIdx );
186+ EVT VT = Val .getValueType ();
176187
177188 switch (C.Kind ) {
178189 case SDTCisVT: {
@@ -183,11 +194,11 @@ void SDNodeInfo::verifyNode(const SelectionDAG &DAG, const SDNode *N) const {
183194 ExpectedVT =
184195 DAG.getTargetLoweringInfo ().getPointerTy (DAG.getDataLayout ());
185196
186- if (OpVT != ExpectedVT) {
187- SS << Op << " must have type " << ExpectedVT;
197+ if (VT != ExpectedVT) {
198+ SS << Val << " must have type " << ExpectedVT;
188199 if (IsPtr)
189200 SS << " (iPTR)" ;
190- SS << " , but has type " << OpVT ;
201+ SS << " , but has type " << VT ;
191202 reportNodeError (DAG, N, SS.str ());
192203 }
193204 break ;
@@ -213,13 +224,13 @@ void SDNodeInfo::verifyNode(const SelectionDAG &DAG, const SDNode *N) const {
213224 case SDTCVecEltisVT: {
214225 EVT ExpectedVT = GetConstraintVT (C);
215226
216- if (!OpVT .isVector ()) {
217- SS << Op << " must have vector type" ;
227+ if (!VT .isVector ()) {
228+ SS << Val << " must have vector type" ;
218229 reportNodeError (DAG, N, SS.str ());
219230 }
220- if (OpVT .getVectorElementType () != ExpectedVT) {
221- SS << Op << " must have " << ExpectedVT << " element type, but has "
222- << OpVT .getVectorElementType () << " element type" ;
231+ if (VT .getVectorElementType () != ExpectedVT) {
232+ SS << Val << " must have " << ExpectedVT << " element type, but has "
233+ << VT .getVectorElementType () << " element type" ;
223234 reportNodeError (DAG, N, SS.str ());
224235 }
225236 break ;
0 commit comments