@@ -217,12 +217,8 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
217
217
Inst.Operands .back ().MIOperandNo + Inst.Operands .back ().MINumOperands ;
218
218
OperandMap.grow (NumMIOperands);
219
219
220
- // TiedCount keeps track of the number of operands skipped in Inst
221
- // operands list to get to the corresponding Dag operand. This is
222
- // necessary because the number of operands in Inst might be greater
223
- // than number of operands in the Dag due to how tied operands
224
- // are represented.
225
- unsigned TiedCount = 0 ;
220
+ // Tied operands are not represented in the DAG so we count them separately.
221
+ unsigned DAGOpNo = 0 ;
226
222
unsigned OpNo = 0 ;
227
223
for (const auto &Opnd : Inst.Operands ) {
228
224
int TiedOpIdx = Opnd.getTiedRegister ();
@@ -231,15 +227,25 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
231
227
// Set the entry in OperandMap for the tied operand we're skipping.
232
228
OperandMap[OpNo] = OperandMap[TiedOpIdx];
233
229
++OpNo;
234
- ++TiedCount;
230
+
231
+ // Source instructions can have at most 1 tied operand.
232
+ if (IsSourceInst && (OpNo - DAGOpNo > 1 ))
233
+ PrintFatalError (Rec->getLoc (),
234
+ " Input operands for Inst '" + Inst.TheDef ->getName () +
235
+ " ' and input Dag operand count mismatch" );
236
+
235
237
continue ;
236
238
}
237
- for (unsigned SubOp = 0 ; SubOp != Opnd.MINumOperands ; ++SubOp, ++OpNo) {
238
- unsigned DAGOpNo = OpNo - TiedCount;
239
+ for (unsigned SubOp = 0 ; SubOp != Opnd.MINumOperands ;
240
+ ++SubOp, ++ OpNo, ++DAGOpNo) {
239
241
const Record *OpndRec = Opnd.Rec ;
240
242
if (Opnd.MINumOperands > 1 )
241
243
OpndRec = cast<DefInit>(Opnd.MIOperandInfo ->getArg (SubOp))->getDef ();
242
244
245
+ if (DAGOpNo >= Dag->getNumArgs ())
246
+ PrintFatalError (Rec->getLoc (), " Inst '" + Inst.TheDef ->getName () +
247
+ " ' and Dag operand count mismatch" );
248
+
243
249
if (const auto *DI = dyn_cast<DefInit>(Dag->getArg (DAGOpNo))) {
244
250
if (DI->getDef ()->isSubClassOf (" Register" )) {
245
251
// Check if the fixed register belongs to the Register class.
@@ -312,34 +318,11 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
312
318
Operands[ArgName] = {DAGOpNo, OpNo};
313
319
}
314
320
}
315
- }
316
-
317
- // Verify the Dag operand count is enough to build an instruction.
318
- static bool verifyDagOpCount (const CodeGenInstruction &Inst, const DagInit *Dag,
319
- bool IsSource) {
320
- unsigned NumMIOperands = 0 ;
321
321
322
- unsigned TiedOpCount = 0 ;
323
- for (const auto &Op : Inst.Operands ) {
324
- NumMIOperands += Op.MINumOperands ;
325
- if (Op.getTiedRegister () != -1 )
326
- TiedOpCount++;
327
- }
328
-
329
- // Source instructions are non compressed instructions and have at most one
330
- // tied operand.
331
- if (IsSource && (TiedOpCount > 1 ))
332
- PrintFatalError (Inst.TheDef ->getLoc (),
333
- " Input operands for Inst '" + Inst.TheDef ->getName () +
334
- " ' and input Dag operand count mismatch" );
335
-
336
- // The Instruction might have tied operands so the Dag might have
337
- // a fewer operand count.
338
- if (Dag->getNumArgs () != (NumMIOperands - TiedOpCount))
339
- PrintFatalError (Inst.TheDef ->getLoc (),
340
- " Inst '" + Inst.TheDef ->getName () +
341
- " ' and Dag operand count mismatch" );
342
- return true ;
322
+ // We shouldn't have extra Dag operands.
323
+ if (DAGOpNo != Dag->getNumArgs ())
324
+ PrintFatalError (Rec->getLoc (), " Inst '" + Inst.TheDef ->getName () +
325
+ " ' and Dag operand count mismatch" );
343
326
}
344
327
345
328
// Check that all names in the source DAG appear in the destionation DAG.
@@ -454,7 +437,6 @@ void CompressInstEmitter::evaluateCompressPat(const Record *Rec) {
454
437
// Checking we are transforming from compressed to uncompressed instructions.
455
438
const Record *SourceOperator = SourceDag->getOperatorAsDef (Rec->getLoc ());
456
439
CodeGenInstruction SourceInst (SourceOperator);
457
- verifyDagOpCount (SourceInst, SourceDag, true );
458
440
459
441
// Validate output Dag operands.
460
442
const DagInit *DestDag = Rec->getValueAsDag (" Output" );
@@ -463,7 +445,6 @@ void CompressInstEmitter::evaluateCompressPat(const Record *Rec) {
463
445
464
446
const Record *DestOperator = DestDag->getOperatorAsDef (Rec->getLoc ());
465
447
CodeGenInstruction DestInst (DestOperator);
466
- verifyDagOpCount (DestInst, DestDag, false );
467
448
468
449
if (SourceOperator->getValueAsInt (" Size" ) <=
469
450
DestOperator->getValueAsInt (" Size" ))
0 commit comments