@@ -217,12 +217,8 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
217217 Inst.Operands .back ().MIOperandNo + Inst.Operands .back ().MINumOperands ;
218218 OperandMap.grow (NumMIOperands);
219219
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 ;
226222 unsigned OpNo = 0 ;
227223 for (const auto &Opnd : Inst.Operands ) {
228224 int TiedOpIdx = Opnd.getTiedRegister ();
@@ -231,15 +227,25 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
231227 // Set the entry in OperandMap for the tied operand we're skipping.
232228 OperandMap[OpNo] = OperandMap[TiedOpIdx];
233229 ++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+
235237 continue ;
236238 }
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) {
239241 const Record *OpndRec = Opnd.Rec ;
240242 if (Opnd.MINumOperands > 1 )
241243 OpndRec = cast<DefInit>(Opnd.MIOperandInfo ->getArg (SubOp))->getDef ();
242244
245+ if (DAGOpNo >= Dag->getNumArgs ())
246+ PrintFatalError (Rec->getLoc (), " Inst '" + Inst.TheDef ->getName () +
247+ " ' and Dag operand count mismatch" );
248+
243249 if (const auto *DI = dyn_cast<DefInit>(Dag->getArg (DAGOpNo))) {
244250 if (DI->getDef ()->isSubClassOf (" Register" )) {
245251 // Check if the fixed register belongs to the Register class.
@@ -312,34 +318,11 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
312318 Operands[ArgName] = {DAGOpNo, OpNo};
313319 }
314320 }
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 ;
321321
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" );
343326}
344327
345328// Check that all names in the source DAG appear in the destionation DAG.
@@ -454,7 +437,6 @@ void CompressInstEmitter::evaluateCompressPat(const Record *Rec) {
454437 // Checking we are transforming from compressed to uncompressed instructions.
455438 const Record *SourceOperator = SourceDag->getOperatorAsDef (Rec->getLoc ());
456439 CodeGenInstruction SourceInst (SourceOperator);
457- verifyDagOpCount (SourceInst, SourceDag, true );
458440
459441 // Validate output Dag operands.
460442 const DagInit *DestDag = Rec->getValueAsDag (" Output" );
@@ -463,7 +445,6 @@ void CompressInstEmitter::evaluateCompressPat(const Record *Rec) {
463445
464446 const Record *DestOperator = DestDag->getOperatorAsDef (Rec->getLoc ());
465447 CodeGenInstruction DestInst (DestOperator);
466- verifyDagOpCount (DestInst, DestDag, false );
467448
468449 if (SourceOperator->getValueAsInt (" Size" ) <=
469450 DestOperator->getValueAsInt (" Size" ))
0 commit comments