Skip to content

Commit 36111f2

Browse files
committed
[TableGen] Fix printing second PC-relative operand
If an instruction has several operands and a PC-relative one is not the first of them, the generator may produce the code that does not pass the 'Address' parameter to the printout method. For example, for an Arm instruction 'LE LR, $imm', it reuses the same code as for other instructions where the second operand is not PC-relative: void ARMInstPrinter::printInstruction(...) { ... case 11: // BF16VDOTI_VDOTD, BF16VDOTI_VDOTQ, BF16VDOTS_VDOTD, ... printOperand(MI, 1, STI, O); O << ", "; printOperand(MI, 2, STI, O); break; ... The patch fixes that by considering 'PCRel' when comparing 'AsmWriterOperand' values. Differential Revision: https://reviews.llvm.org/D104698
1 parent dfafd56 commit 36111f2

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: llvm-tblgen -gen-asm-writer -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 Reg : RegisterClass<"Reg", [i32], 0, (add R0)>;
13+
14+
def IntOperand: Operand<i32>;
15+
16+
def PCRelOperand : Operand<i32> {
17+
let OperandType = "OPERAND_PCREL";
18+
}
19+
20+
def foo : Instruction {
21+
let OutOperandList = (outs);
22+
let InOperandList = (ins Reg:$reg, IntOperand:$imm);
23+
let AsmString = "foo $reg, $imm";
24+
}
25+
26+
def bar : Instruction {
27+
let OutOperandList = (outs);
28+
let InOperandList = (ins Reg:$reg, PCRelOperand:$imm);
29+
let AsmString = "bar $reg, $imm";
30+
}
31+
32+
// CHECK: ArchInstPrinter::printInstruction(
33+
// CHECK: // bar, foo
34+
// CHECK-NEXT: printOperand(MI, 0, O);
35+
// CHECK: // foo
36+
// CHECK-NEXT: printOperand(MI, 1, O);
37+
// CHECK: // bar
38+
// CHECK-NEXT: printOperand(MI, Address, 1, O);

llvm/utils/TableGen/AsmWriterInst.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ namespace llvm {
6666
bool operator!=(const AsmWriterOperand &Other) const {
6767
if (OperandType != Other.OperandType || Str != Other.Str) return true;
6868
if (OperandType == isMachineInstrOperand)
69-
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
69+
return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier ||
70+
PCRel != Other.PCRel;
7071
return false;
7172
}
7273
bool operator==(const AsmWriterOperand &Other) const {

0 commit comments

Comments
 (0)