Index: test/TableGen/GlobalISelEmitter.td =================================================================== --- test/TableGen/GlobalISelEmitter.td +++ test/TableGen/GlobalISelEmitter.td @@ -27,11 +27,11 @@ //===- Test a simple pattern with regclass operands. ----------------------===// // CHECK: if ((I.getOpcode() == TargetOpcode::G_ADD) && -// CHECK-NEXT: (((MRI.getType(I.getOperand(0).getReg()) == (LLT::scalar(32))) && +// CHECK-NEXT: ((/* Operand 0 */ (MRI.getType(I.getOperand(0).getReg()) == (LLT::scalar(32))) && // CHECK-NEXT: ((&RBI.getRegBankFromRegClass(MyTarget::GPR32RegClass) == RBI.getRegBank(I.getOperand(0).getReg(), MRI, TRI))))) && -// CHECK-NEXT: (((MRI.getType(I.getOperand(1).getReg()) == (LLT::scalar(32))) && +// CHECK-NEXT: ((/* Operand 1 */ (MRI.getType(I.getOperand(1).getReg()) == (LLT::scalar(32))) && // CHECK-NEXT: ((&RBI.getRegBankFromRegClass(MyTarget::GPR32RegClass) == RBI.getRegBank(I.getOperand(1).getReg(), MRI, TRI))))) && -// CHECK-NEXT: (((MRI.getType(I.getOperand(2).getReg()) == (LLT::scalar(32))) && +// CHECK-NEXT: ((/* Operand 2 */ (MRI.getType(I.getOperand(2).getReg()) == (LLT::scalar(32))) && // CHECK-NEXT: ((&RBI.getRegBankFromRegClass(MyTarget::GPR32RegClass) == RBI.getRegBank(I.getOperand(2).getReg(), MRI, TRI)))))) { // CHECK-NEXT: // (add:i32 GPR32:i32:$src1, GPR32:i32:$src2) => (ADD:i32 GPR32:i32:$src1, GPR32:i32:$src2) @@ -46,7 +46,7 @@ //===- Test a pattern with an MBB operand. --------------------------------===// // CHECK: if ((I.getOpcode() == TargetOpcode::G_BR) && -// CHECK-NEXT: (((I.getOperand(0).isMBB())))) { +// CHECK-NEXT: ((/* Operand 0 */ (I.getOperand(0).isMBB())))) { // CHECK-NEXT: // (br (bb:Other):$target) => (BR (bb:Other):$target) // CHECK-NEXT: I.setDesc(TII.get(MyTarget::BR)); Index: utils/TableGen/GlobalISelEmitter.cpp =================================================================== --- utils/TableGen/GlobalISelEmitter.cpp +++ utils/TableGen/GlobalISelEmitter.cpp @@ -131,10 +131,9 @@ public: virtual ~OperandPredicateMatcher() {} - /// Emit a C++ expression that checks the predicate for the OpIdx operand of - /// the instruction given in InsnVarName. - virtual void emitCxxPredicateExpr(raw_ostream &OS, StringRef InsnVarName, - unsigned OpIdx) const = 0; + /// Emit a C++ expression that checks the predicate for the given operand. + virtual void emitCxxPredicateExpr(raw_ostream &OS, + StringRef OperandExpr) const = 0; }; /// Generates code to check that an operand is a particular LLT. @@ -145,10 +144,9 @@ public: LLTOperandMatcher(std::string Ty) : Ty(Ty) {} - void emitCxxPredicateExpr(raw_ostream &OS, StringRef InsnVarName, - unsigned OpIdx) const override { - OS << "MRI.getType(" << InsnVarName << ".getOperand(" << OpIdx - << ").getReg()) == (" << Ty << ")"; + void emitCxxPredicateExpr(raw_ostream &OS, + StringRef OperandExpr) const override { + OS << "MRI.getType(" << OperandExpr << ".getReg()) == (" << Ty << ")"; } }; @@ -160,20 +158,20 @@ public: RegisterBankOperandMatcher(const CodeGenRegisterClass &RC) : RC(RC) {} - void emitCxxPredicateExpr(raw_ostream &OS, StringRef InsnVarName, - unsigned OpIdx) const override { + void emitCxxPredicateExpr(raw_ostream &OS, + StringRef OperandExpr) const override { OS << "(&RBI.getRegBankFromRegClass(" << RC.getQualifiedName() - << "RegClass) == RBI.getRegBank(" << InsnVarName << ".getOperand(" - << OpIdx << ").getReg(), MRI, TRI))"; + << "RegClass) == RBI.getRegBank(" << OperandExpr + << ".getReg(), MRI, TRI))"; } }; /// Generates code to check that an operand is a basic block. class MBBOperandMatcher : public OperandPredicateMatcher { public: - void emitCxxPredicateExpr(raw_ostream &OS, StringRef InsnVarName, - unsigned OpIdx) const override { - OS << InsnVarName << ".getOperand(" << OpIdx << ").isMBB()"; + void emitCxxPredicateExpr(raw_ostream &OS, + StringRef OperandExpr) const override { + OS << OperandExpr << ".isMBB()"; } }; @@ -185,12 +183,15 @@ public: OperandMatcher(unsigned OpIdx) : OpIdx(OpIdx) {} + std::string getOperandExpr(StringRef InsnVarName) const { + return (InsnVarName + ".getOperand(" + std::to_string(OpIdx) + ")").str(); + } /// Emit a C++ expression that tests whether the instruction named in /// InsnVarName matches all the predicate and all the operands. void emitCxxPredicateExpr(raw_ostream &OS, StringRef InsnVarName) const { - OS << "("; - emitCxxPredicateListExpr(OS, InsnVarName, OpIdx); + OS << "(/* Operand " << OpIdx << " */ "; + emitCxxPredicateListExpr(OS, getOperandExpr(InsnVarName)); OS << ")"; } };