[llvm] 62853a2 - [TableGen][InstrInfoEmitter] Count sub-operands on def operands
Michael Liao via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 17:34:40 PDT 2024
Author: Michael Liao
Date: 2024-04-16T20:34:20-04:00
New Revision: 62853a246ef131c4de73b63a141c85a0b14c75a5
URL: https://github.com/llvm/llvm-project/commit/62853a246ef131c4de73b63a141c85a0b14c75a5
DIFF: https://github.com/llvm/llvm-project/commit/62853a246ef131c4de73b63a141c85a0b14c75a5.diff
LOG: [TableGen][InstrInfoEmitter] Count sub-operands on def operands
- If a def operand includes multiple sub-operands, count them when
generating instr info.
- Found issues in x86 and sparc backends, where memory operands of
store or store-like instructions are wrongly placed in the output
list.
Reviewers: jayfoad, arsenm, Pierre-vh
Reviewed By: arsenm
Pull Request: https://github.com/llvm/llvm-project/pull/88972
Added:
llvm/test/TableGen/def-multiple-operands.td
Modified:
llvm/utils/TableGen/InstrInfoEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/test/TableGen/def-multiple-operands.td b/llvm/test/TableGen/def-multiple-operands.td
new file mode 100644
index 00000000000000..b747c58907505a
--- /dev/null
+++ b/llvm/test/TableGen/def-multiple-operands.td
@@ -0,0 +1,37 @@
+// RUN: llvm-tblgen -gen-instr-info -I %p/../../include %s | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+def archInstrInfo : InstrInfo {}
+
+def arch : Target {
+ let InstructionSet = archInstrInfo;
+}
+
+def R0 : Register<"r0">;
+def P0 : Register<"p0">;
+def R32 : RegisterClass<"MyNS", [i32], 0, (add R0)>;
+def P1 : RegisterClass<"MyNS", [i1], 0, (add P0)>;
+
+def Reg3Opnd : Operand<OtherVT> {
+ let MIOperandInfo = (ops R32, R32, P1);
+}
+
+// The following checks verify that 'MCInstrDesc' entry for 'InstA' has the
+// expected 'NumOperands' and 'NumDefs', i.e. 'InstA' should have 3 defs out of
+// 4 operands.
+
+// CHECK: archInstrTable {{.* = \{}}
+// CHECK: {{\{}}
+// CHECK: {{\{}} [[ID:[0-9]+]], 4, 3, 13, {{.+\}, \/\/}}
+// CHECK-SAME: Inst #[[ID]] = InstA
+def InstA : Instruction {
+ let Namespace = "MyNS";
+ let Size = 13;
+ // InstA should have 3 defs out of 4 operands.
+ let OutOperandList = (outs Reg3Opnd:$dst);
+ let InOperandList = (ins i32imm:$c);
+ field bits<8> Inst;
+ field bits<8> SoftFail = 0;
+ let hasSideEffects = false;
+}
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index 36f8fa14653938..b3a05e081f6375 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -1181,9 +1181,15 @@ void InstrInfoEmitter::emitRecord(
// Each logical operand can be multiple MI operands.
MinOperands =
Inst.Operands.back().MIOperandNo + Inst.Operands.back().MINumOperands;
+ // Even the logical output operand may be multiple MI operands.
+ int DefOperands = 0;
+ if (Inst.Operands.NumDefs) {
+ auto &Opnd = Inst.Operands[Inst.Operands.NumDefs - 1];
+ DefOperands = Opnd.MIOperandNo + Opnd.MINumOperands;
+ }
OS << " { ";
- OS << Num << ",\t" << MinOperands << ",\t" << Inst.Operands.NumDefs << ",\t"
+ OS << Num << ",\t" << MinOperands << ",\t" << DefOperands << ",\t"
<< Inst.TheDef->getValueAsInt("Size") << ",\t"
<< SchedModels.getSchedClassIdx(Inst) << ",\t";
More information about the llvm-commits
mailing list