Skip to content

Commit 88b5445

Browse files
committed
[DecoderEmitter] Eliminate DecodeComplete parameter to decodeToMCInst
Currently, the code generated by decoder emitter always set `DeocdeComplete` to false when returning Fail from `decodeToMCInst`. As a result, we can just use the return `DecodeStatus` from `decodeToMCInst` to decide whether to terminate the decoding and return or continue trying.
1 parent 4be1099 commit 88b5445

File tree

7 files changed

+30
-41
lines changed

7 files changed

+30
-41
lines changed

llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ class LLVM_ABI MCDisassembler {
9898
/// from Success->SoftFail ->Fail can be done with a simple
9999
/// bitwise-AND:
100100
///
101-
/// LEFT & TOP = | Success Unpredictable Fail
102-
/// --------------+-----------------------------------
103-
/// Success | Success Unpredictable Fail
104-
/// Unpredictable | Unpredictable Unpredictable Fail
105-
/// Fail | Fail Fail Fail
101+
/// LEFT & TOP = | Success SoftFail Fail
102+
/// --------------+-----------------------------
103+
/// Success | Success SoftFail Fail
104+
/// SoftFail | SoftFail SoftFail Fail
105+
/// Fail | Fail Fail Fail
106106
///
107107
/// An easy way of encoding this is as 0b11, 0b01, 0b00 for
108108
/// Success, SoftFail, Fail respectively.

llvm/test/TableGen/DecoderEmitter/DecoderEmitterFnTable.td

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ def Inst3 : TestInstruction {
7171
let AsmString = "Inst3";
7272
}
7373

74-
// CHECK-LABEL: DecodeStatus decodeFn_0(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder, bool &DecodeComplete)
75-
// CHECK-LABEL: DecodeStatus decodeFn_1(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder, bool &DecodeComplete)
76-
// CHECK-LABEL: DecodeStatus decodeFn_2(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder, bool &DecodeComplete)
77-
// CHECK-LABEL: DecodeStatus decodeFn_3(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder, bool &DecodeComplete)
78-
// CHECK-LABEL: decodeToMCInst(unsigned Idx, DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder, bool &DecodeComplete)
74+
// CHECK-LABEL: DecodeStatus decodeFn_0(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder)
75+
// CHECK-LABEL: DecodeStatus decodeFn_1(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder)
76+
// CHECK-LABEL: DecodeStatus decodeFn_2(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder)
77+
// CHECK-LABEL: DecodeStatus decodeFn_3(DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder)
78+
// CHECK-LABEL: decodeToMCInst(unsigned Idx, DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const MCDisassembler *Decoder)
7979
// CHECK: static constexpr DecodeFnTy decodeFnTable[]
8080
// CHECK-NEXT: decodeFn_0,
8181
// CHECK-NEXT: decodeFn_1,
8282
// CHECK-NEXT: decodeFn_2,
8383
// CHECK-NEXT: decodeFn_3,
84-
// CHECK: return decodeFnTable[Idx](S, insn, MI, Address, Decoder, DecodeComplete)
84+
// CHECK: return decodeFnTable[Idx](S, insn, MI, Address, Decoder)

llvm/test/TableGen/DecoderEmitter/trydecode-emission.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def InstB : TestInstruction {
4141
// CHECK-NEXT: /* 15 */ OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
4242
// CHECK-NEXT: };
4343

44-
// CHECK: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
44+
// CHECK: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }
4545

4646
// CHECK: unsigned NumToSkip = *Ptr++;
4747
// CHECK-NEXT: NumToSkip |= (*Ptr++) << 8;
@@ -54,7 +54,7 @@ def InstB : TestInstruction {
5454
// CHECK-LARGE-NEXT: /* 16 */ OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
5555
// CHECK-LARGE-NEXT: };
5656

57-
// CHECK-LARGE: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
57+
// CHECK-LARGE: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }
5858

5959
// CHECK-LARGE: unsigned NumToSkip = *Ptr++;
6060
// CHECK-LARGE-NEXT: NumToSkip |= (*Ptr++) << 8;

llvm/test/TableGen/DecoderEmitter/trydecode-emission2.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def InstB : TestInstruction {
3939
// CHECK-NEXT: /* 19 */ OPC_CheckField, 3, 2, 0,
4040
// CHECK-NEXT: /* 23 */ OPC_TryDecode, {{[0-9]+}}, {{[0-9]+}}, 1,
4141

42-
// CHECK: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
43-
// CHECK: if (!Check(S, DecodeInstA(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
42+
// CHECK: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }
43+
// CHECK: if (!Check(S, DecodeInstA(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }
4444

4545
// CHECK-LARGE: /* 0 */ OPC_CheckField, 2, 1, 0,
4646
// CHECK-LARGE-NEXT: /* 4 */ OPC_CheckField, 5, 3, 0,
@@ -51,5 +51,5 @@ def InstB : TestInstruction {
5151
// CHECK-LARGE-NEXT: /* 24 */ OPC_TryDecode, {{[0-9]+}}, {{[0-9]+}}, 1,
5252
// CHECK-LARGE-NEXT: };
5353

54-
// CHECK-LARGE: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
55-
// CHECK-LARGE: if (!Check(S, DecodeInstA(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
54+
// CHECK-LARGE: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }
55+
// CHECK-LARGE: if (!Check(S, DecodeInstA(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }

llvm/test/TableGen/DecoderEmitter/trydecode-emission3.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def InstB : TestInstruction {
4242
// CHECK-NEXT: /* 15 */ OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
4343
// CHECK-NEXT: };
4444

45-
// CHECK: if (!Check(S, DecodeInstBOp(MI, tmp, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
45+
// CHECK: if (!Check(S, DecodeInstBOp(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }
4646

4747
// CHECK-LARGE: /* 0 */ OPC_CheckField, 4, 4, 0,
4848
// CHECK-LARGE-NEXT: /* 4 */ OPC_Scope, 8, 0, 0, // end scope at 16
@@ -51,4 +51,4 @@ def InstB : TestInstruction {
5151
// CHECK-LARGE-NEXT: /* 16 */ OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
5252
// CHECK-LARGE-NEXT: };
5353

54-
// CHECK-LARGE: if (!Check(S, DecodeInstBOp(MI, tmp, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
54+
// CHECK-LARGE: if (!Check(S, DecodeInstBOp(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }

llvm/test/TableGen/DecoderEmitter/trydecode-emission4.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def InstB : TestInstruction {
4040
// CHECK-NEXT: /* 17 */ OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
4141
// CHECK-NEXT: };
4242

43-
// CHECK: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
43+
// CHECK: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }
4444

4545

4646
// CHECK-LARGE: /* 0 */ OPC_CheckField, 250, 3, 4, 0,
@@ -50,4 +50,4 @@ def InstB : TestInstruction {
5050
// CHECK-LARGE-NEXT: /* 18 */ OPC_Decode, {{[0-9]+}}, {{[0-9]+}}, 1, // Opcode: InstA, DecodeIdx: 1
5151
// CHECK-LARGE-NEXT: };
5252

53-
// CHECK-LARGE: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { DecodeComplete = false; return MCDisassembler::Fail; }
53+
// CHECK-LARGE: if (!Check(S, DecodeInstB(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
865865
"InsnType, uint64_t>;\n";
866866
StringRef DecodeParams =
867867
"DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const "
868-
"MCDisassembler *Decoder, bool &DecodeComplete";
868+
"MCDisassembler *Decoder";
869869

870870
// Print the name of the decode function to OS.
871871
auto PrintDecodeFnName = [&OS, BucketBitWidth](unsigned DecodeIdx) {
@@ -904,7 +904,6 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
904904
OS << "// Handling " << Decoders.size() << " cases.\n";
905905
PrintTemplate();
906906
OS << "decodeToMCInst(unsigned Idx, " << DecodeParams << ") {\n";
907-
OS << " DecodeComplete = true;\n";
908907

909908
if (UseFnTableInDecodeToMCInst) {
910909
// Build a table of function pointers
@@ -918,8 +917,7 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
918917
OS << " };\n";
919918
OS << " if (Idx >= " << Decoders.size() << ")\n";
920919
OS << " llvm_unreachable(\"Invalid decoder index!\");\n";
921-
OS << " return decodeFnTable[Idx](S, insn, MI, Address, Decoder, "
922-
"DecodeComplete);\n";
920+
OS << " return decodeFnTable[Idx](S, insn, MI, Address, Decoder);\n";
923921
} else {
924922
OS << " " << TmpTypeDecl;
925923
OS << " TmpType tmp;\n";
@@ -1052,9 +1050,7 @@ static void emitBinaryParser(raw_ostream &OS, indent Indent,
10521050
StringRef Decoder = OpInfo.Decoder;
10531051
if (!Decoder.empty()) {
10541052
OS << Indent << "if (!Check(S, " << Decoder
1055-
<< "(MI, tmp, Address, Decoder))) { "
1056-
<< (OpInfo.HasCompleteDecoder ? "" : "DecodeComplete = false; ")
1057-
<< "return MCDisassembler::Fail; }\n";
1053+
<< "(MI, tmp, Address, Decoder))) { return MCDisassembler::Fail; }\n";
10581054
} else {
10591055
OS << Indent << "MI.addOperand(MCOperand::createImm(tmp));\n";
10601056
}
@@ -1069,9 +1065,7 @@ static std::string getDecoderString(const InstructionEncoding &Encoding) {
10691065
StringRef DecoderMethod = Encoding.getDecoderMethod();
10701066
if (!DecoderMethod.empty()) {
10711067
OS << Indent << "if (!Check(S, " << DecoderMethod
1072-
<< "(MI, insn, Address, Decoder))) { "
1073-
<< (Encoding.hasCompleteDecoder() ? "" : "DecodeComplete = false; ")
1074-
<< "return MCDisassembler::Fail; }\n";
1068+
<< "(MI, insn, Address, Decoder))) { return MCDisassembler::Fail; }\n";
10751069
} else {
10761070
for (const OperandInfo &Op : Encoding.getOperands())
10771071
emitBinaryParser(OS, Indent, Encoding, Op);
@@ -1682,15 +1676,13 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
16821676
unsigned DecodeIdx = decodeULEB128AndIncUnsafe(Ptr);
16831677
16841678
MI.clear();
1685-
MI.setOpcode(Opc);
1686-
bool DecodeComplete;)";
1679+
MI.setOpcode(Opc);)";
16871680
if (IsVarLenInst) {
16881681
OS << "\n unsigned Len = InstrLenTable[Opc];\n"
16891682
<< " makeUp(insn, Len);";
16901683
}
16911684
OS << R"(
1692-
S = decodeToMCInst(DecodeIdx, S, insn, MI, Address, DisAsm, DecodeComplete);
1693-
assert(DecodeComplete);
1685+
S = decodeToMCInst(DecodeIdx, S, insn, MI, Address, DisAsm);
16941686
16951687
LLVM_DEBUG(dbgs() << Loc << ": OPC_Decode: opcode " << Opc
16961688
<< ", using decoder " << DecodeIdx << ": "
@@ -1707,18 +1699,15 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
17071699
// Perform the decode operation.
17081700
MCInst TmpMI;
17091701
TmpMI.setOpcode(Opc);
1710-
bool DecodeComplete;
1711-
S = decodeToMCInst(DecodeIdx, S, insn, TmpMI, Address, DisAsm, DecodeComplete);
1702+
S = decodeToMCInst(DecodeIdx, S, insn, TmpMI, Address, DisAsm);
17121703
LLVM_DEBUG(dbgs() << Loc << ": OPC_TryDecode: opcode " << Opc
17131704
<< ", using decoder " << DecodeIdx << ": ");
17141705
1715-
if (DecodeComplete) {
1716-
// Decoding complete.
1717-
LLVM_DEBUG(dbgs() << (S != MCDisassembler::Fail ? "PASS\n" : "FAIL\n"));
1706+
if (S != MCDisassembler::Fail) {
1707+
LLVM_DEBUG(dbgs() << (S != MCDisassembler::Success ? "Success\n" : "SoftFail\n"));
17181708
MI = TmpMI;
17191709
return S;
17201710
}
1721-
assert(S == MCDisassembler::Fail);
17221711
if (ScopeStack.empty()) {
17231712
LLVM_DEBUG(dbgs() << "FAIL, returning FAIL\n");
17241713
return MCDisassembler::Fail;

0 commit comments

Comments
 (0)