Skip to content

Commit 62853a2

Browse files
committed
[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: #88972
1 parent 7c26889 commit 62853a2

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: llvm-tblgen -gen-instr-info -I %p/../../include %s | FileCheck %s
2+
3+
include "llvm/Target/Target.td"
4+
5+
def archInstrInfo : InstrInfo {}
6+
7+
def arch : Target {
8+
let InstructionSet = archInstrInfo;
9+
}
10+
11+
def R0 : Register<"r0">;
12+
def P0 : Register<"p0">;
13+
def R32 : RegisterClass<"MyNS", [i32], 0, (add R0)>;
14+
def P1 : RegisterClass<"MyNS", [i1], 0, (add P0)>;
15+
16+
def Reg3Opnd : Operand<OtherVT> {
17+
let MIOperandInfo = (ops R32, R32, P1);
18+
}
19+
20+
// The following checks verify that 'MCInstrDesc' entry for 'InstA' has the
21+
// expected 'NumOperands' and 'NumDefs', i.e. 'InstA' should have 3 defs out of
22+
// 4 operands.
23+
24+
// CHECK: archInstrTable {{.* = \{}}
25+
// CHECK: {{\{}}
26+
// CHECK: {{\{}} [[ID:[0-9]+]], 4, 3, 13, {{.+\}, \/\/}}
27+
// CHECK-SAME: Inst #[[ID]] = InstA
28+
def InstA : Instruction {
29+
let Namespace = "MyNS";
30+
let Size = 13;
31+
// InstA should have 3 defs out of 4 operands.
32+
let OutOperandList = (outs Reg3Opnd:$dst);
33+
let InOperandList = (ins i32imm:$c);
34+
field bits<8> Inst;
35+
field bits<8> SoftFail = 0;
36+
let hasSideEffects = false;
37+
}

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,15 @@ void InstrInfoEmitter::emitRecord(
11811181
// Each logical operand can be multiple MI operands.
11821182
MinOperands =
11831183
Inst.Operands.back().MIOperandNo + Inst.Operands.back().MINumOperands;
1184+
// Even the logical output operand may be multiple MI operands.
1185+
int DefOperands = 0;
1186+
if (Inst.Operands.NumDefs) {
1187+
auto &Opnd = Inst.Operands[Inst.Operands.NumDefs - 1];
1188+
DefOperands = Opnd.MIOperandNo + Opnd.MINumOperands;
1189+
}
11841190

11851191
OS << " { ";
1186-
OS << Num << ",\t" << MinOperands << ",\t" << Inst.Operands.NumDefs << ",\t"
1192+
OS << Num << ",\t" << MinOperands << ",\t" << DefOperands << ",\t"
11871193
<< Inst.TheDef->getValueAsInt("Size") << ",\t"
11881194
<< SchedModels.getSchedClassIdx(Inst) << ",\t";
11891195

0 commit comments

Comments
 (0)