Skip to content

Commit ed3597e

Browse files
authored
[TableGen][Decoder] Decode operands with zero width or all bits known (#156358)
There are two classes of operands that DecoderEmitter cannot currently handle: 1. Operands that do not participate in instruction encoding. 2. Operands whose encoding contains only 1s and 0s. Because of this, targets developed various workarounds. Some targets insert missing operands after an instruction has been (incompletely) decoded, other take into account the missing operands when printing the instruction. Some targets do neither of that and fail to correctly disassemble some instructions. This patch makes it possible to decode both classes of operands and allows to remove existing workarounds. For the case of operand with no contribution to instruction encoding, one should now add `bits<0> OpName` field to instruction encoding record. This will make DecoderEmitter generate a call to the decoder function specified by the operand's DecoderMethod. The function has a signature different from the usual one and looks like this: ``` static DecodeStatus DecodeImm42Operand(MCInst &Inst, const MCDisassembler *Decoder) { Inst.addOperand(MCOperand::createImm(42)); return DecodeStatus::Success; } ``` Notably, encoding bits are not passed to it (since there are none). There is nothing special about the second case, the operand bits are passed as usual. The difference is that before this change, the function was not called if all the bits of the operand were known (no '?' in the operand encoding). There are two options controlling the behavior. Passing an option enables the old behavior. They exist to allow smooth transition to the new behavior. They are temporary (yeah, I know) and will be removed once all targets migrate, possibly giving some more time to downstream targets. Subsequent patches in the stack enable the new behavior on some in-tree targets.
1 parent 238c2a9 commit ed3597e

File tree

13 files changed

+115
-34
lines changed

13 files changed

+115
-34
lines changed

llvm/lib/Target/AArch64/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ tablegen(LLVM AArch64GenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM AArch64GenAsmWriter1.inc -gen-asm-writer -asmwriternum=1)
88
tablegen(LLVM AArch64GenCallingConv.inc -gen-callingconv)
99
tablegen(LLVM AArch64GenDAGISel.inc -gen-dag-isel)
10-
tablegen(LLVM AArch64GenDisassemblerTables.inc -gen-disassembler)
10+
tablegen(LLVM AArch64GenDisassemblerTables.inc -gen-disassembler
11+
-ignore-non-decodable-operands
12+
-ignore-fully-defined-operands)
1113
tablegen(LLVM AArch64GenFastISel.inc -gen-fast-isel)
1214
tablegen(LLVM AArch64GenGlobalISel.inc -gen-global-isel)
1315
tablegen(LLVM AArch64GenO0PreLegalizeGICombiner.inc -gen-global-isel-combiner

llvm/lib/Target/AMDGPU/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ tablegen(LLVM AMDGPUGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM AMDGPUGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM AMDGPUGenDAGISel.inc -gen-dag-isel)
99
tablegen(LLVM AMDGPUGenDisassemblerTables.inc -gen-disassembler
10-
--specialize-decoders-per-bitwidth)
10+
--specialize-decoders-per-bitwidth
11+
-ignore-non-decodable-operands
12+
-ignore-fully-defined-operands)
1113
tablegen(LLVM AMDGPUGenInstrInfo.inc -gen-instr-info)
1214
tablegen(LLVM AMDGPUGenMCCodeEmitter.inc -gen-emitter)
1315
tablegen(LLVM AMDGPUGenMCPseudoLowering.inc -gen-pseudo-lowering)

llvm/lib/Target/ARM/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ tablegen(LLVM ARMGenAsmMatcher.inc -gen-asm-matcher)
66
tablegen(LLVM ARMGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM ARMGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM ARMGenDAGISel.inc -gen-dag-isel)
9-
tablegen(LLVM ARMGenDisassemblerTables.inc -gen-disassembler)
9+
tablegen(LLVM ARMGenDisassemblerTables.inc -gen-disassembler
10+
-ignore-non-decodable-operands)
1011
tablegen(LLVM ARMGenFastISel.inc -gen-fast-isel)
1112
tablegen(LLVM ARMGenGlobalISel.inc -gen-global-isel)
1213
tablegen(LLVM ARMGenInstrInfo.inc -gen-instr-info)

llvm/lib/Target/AVR/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ tablegen(LLVM AVRGenAsmMatcher.inc -gen-asm-matcher)
66
tablegen(LLVM AVRGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM AVRGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM AVRGenDAGISel.inc -gen-dag-isel)
9-
tablegen(LLVM AVRGenDisassemblerTables.inc -gen-disassembler)
9+
tablegen(LLVM AVRGenDisassemblerTables.inc -gen-disassembler
10+
-ignore-non-decodable-operands)
1011
tablegen(LLVM AVRGenInstrInfo.inc -gen-instr-info)
1112
tablegen(LLVM AVRGenMCCodeEmitter.inc -gen-emitter)
1213
tablegen(LLVM AVRGenRegisterInfo.inc -gen-register-info)

llvm/lib/Target/BPF/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ tablegen(LLVM BPFGenAsmMatcher.inc -gen-asm-matcher)
66
tablegen(LLVM BPFGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM BPFGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM BPFGenDAGISel.inc -gen-dag-isel)
9-
tablegen(LLVM BPFGenDisassemblerTables.inc -gen-disassembler)
9+
tablegen(LLVM BPFGenDisassemblerTables.inc -gen-disassembler
10+
-ignore-non-decodable-operands)
1011
tablegen(LLVM BPFGenInstrInfo.inc -gen-instr-info)
1112
tablegen(LLVM BPFGenMCCodeEmitter.inc -gen-emitter)
1213
tablegen(LLVM BPFGenRegisterInfo.inc -gen-register-info)

llvm/lib/Target/CSKY/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ tablegen(LLVM CSKYGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM CSKYGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM CSKYGenCompressInstEmitter.inc -gen-compress-inst-emitter)
99
tablegen(LLVM CSKYGenDAGISel.inc -gen-dag-isel)
10-
tablegen(LLVM CSKYGenDisassemblerTables.inc -gen-disassembler)
10+
tablegen(LLVM CSKYGenDisassemblerTables.inc -gen-disassembler
11+
-ignore-non-decodable-operands)
1112
tablegen(LLVM CSKYGenInstrInfo.inc -gen-instr-info)
1213
tablegen(LLVM CSKYGenMCCodeEmitter.inc -gen-emitter)
1314
tablegen(LLVM CSKYGenMCPseudoLowering.inc -gen-pseudo-lowering)

llvm/lib/Target/Hexagon/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ tablegen(LLVM HexagonGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM HexagonGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM HexagonGenDAGISel.inc -gen-dag-isel)
99
tablegen(LLVM HexagonGenDFAPacketizer.inc -gen-dfa-packetizer)
10-
tablegen(LLVM HexagonGenDisassemblerTables.inc -gen-disassembler)
10+
tablegen(LLVM HexagonGenDisassemblerTables.inc -gen-disassembler
11+
-ignore-non-decodable-operands)
1112
tablegen(LLVM HexagonGenInstrInfo.inc -gen-instr-info)
1213
tablegen(LLVM HexagonGenMCCodeEmitter.inc -gen-emitter)
1314
tablegen(LLVM HexagonGenRegisterInfo.inc -gen-register-info)

llvm/lib/Target/Hexagon/HexagonDepInstrFormats.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,6 @@ class Enc_cf1927 : OpcodeHexagon {
30493049
class Enc_d0fe02 : OpcodeHexagon {
30503050
bits <5> Rxx32;
30513051
let Inst{20-16} = Rxx32{4-0};
3052-
bits <0> sgp10;
30533052
}
30543053
class Enc_d15d19 : OpcodeHexagon {
30553054
bits <1> Mu2;

llvm/lib/Target/M68k/Disassembler/M68kDisassembler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ static DecodeStatus DecodeFPCSCRegisterClass(MCInst &Inst, uint64_t RegNo,
107107
}
108108
#define DecodeFPICRegisterClass DecodeFPCSCRegisterClass
109109

110+
static DecodeStatus DecodeCCRCRegisterClass(MCInst &Inst,
111+
const MCDisassembler *Decoder) {
112+
Inst.addOperand(MCOperand::createReg(M68k::CCR));
113+
return DecodeStatus::Success;
114+
}
115+
116+
static DecodeStatus DecodeSRCRegisterClass(MCInst &Inst,
117+
const MCDisassembler *Decoder) {
118+
Inst.addOperand(MCOperand::createReg(M68k::SR));
119+
return DecodeStatus::Success;
120+
}
121+
110122
static DecodeStatus DecodeImm32(MCInst &Inst, uint64_t Imm, uint64_t Address,
111123
const void *Decoder) {
112124
Inst.addOperand(MCOperand::createImm(M68k::swapWord<uint32_t>(Imm)));

llvm/lib/Target/Mips/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ tablegen(LLVM MipsGenAsmMatcher.inc -gen-asm-matcher)
66
tablegen(LLVM MipsGenAsmWriter.inc -gen-asm-writer)
77
tablegen(LLVM MipsGenCallingConv.inc -gen-callingconv)
88
tablegen(LLVM MipsGenDAGISel.inc -gen-dag-isel)
9-
tablegen(LLVM MipsGenDisassemblerTables.inc -gen-disassembler)
9+
tablegen(LLVM MipsGenDisassemblerTables.inc -gen-disassembler
10+
-ignore-non-decodable-operands)
1011
tablegen(LLVM MipsGenFastISel.inc -gen-fast-isel)
1112
tablegen(LLVM MipsGenGlobalISel.inc -gen-global-isel)
1213
tablegen(LLVM MipsGenPostLegalizeGICombiner.inc -gen-global-isel-combiner

0 commit comments

Comments
 (0)