Skip to content

Conversation

s-barannikov
Copy link
Contributor

We didn't have tests for AdditionalEncoding and none of the in-tree targets use this functionality, so I inadvertently broke it in #154288.

We didn't have tests for AdditionalEncoding and none of the in-tree
targets use this functionality, so I inadvertently broke it in llvm#154288.
@s-barannikov s-barannikov enabled auto-merge (squash) August 23, 2025 02:06
@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2025

@llvm/pr-subscribers-tablegen

Author: Sergei Barannikov (s-barannikov)

Changes

We didn't have tests for AdditionalEncoding and none of the in-tree targets use this functionality, so I inadvertently broke it in #154288.


Full diff: https://github.com/llvm/llvm-project/pull/155057.diff

2 Files Affected:

  • (added) llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td (+67)
  • (modified) llvm/utils/TableGen/DecoderEmitter.cpp (+2)
diff --git a/llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td b/llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td
new file mode 100644
index 0000000000000..192cb3c3f5858
--- /dev/null
+++ b/llvm/test/TableGen/FixedLenDecoderEmitter/additional-encoding.td
@@ -0,0 +1,67 @@
+// RUN: llvm-tblgen -gen-disassembler -I %p/../../../include %s | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+class Enc {
+  int Size = 2;
+  bits<16> Inst;
+}
+
+class EncSHIFT<bits<2> opc> : Enc {
+  bits<6> shamt;
+  let Inst{15...14} = {0, 0};
+  let Inst{13...12} = opc;
+  let Inst{11...6} = shamt;
+}
+
+class EncNOP<bits<2> opc> : Enc {
+  let Inst{15...14} = {0, 0};
+  let Inst{13...12} = opc;
+  let Inst{11...6} = {0, 0, 0, 0, 0, 0};
+}
+
+def ShAmtOp : Operand<i32> {
+  let DecoderMethod = "decodeShAmt";
+  let hasCompleteDecoder = false;
+}
+
+class I<dag out_ops, dag in_ops> : Instruction {
+  let InOperandList = in_ops;
+  let OutOperandList = out_ops;
+}
+
+// CHECK:      /* 0 */  MCD::OPC_ExtractField, 12, 4,                // Inst{15-12} ...
+// CHECK-NEXT: /* 3 */  MCD::OPC_FilterValue, 0, 14, 0,              // Skip to: 21
+// CHECK-NEXT: /* 7 */  MCD::OPC_CheckField, 6, 6, 0, 4, 0,          // Skip to: 17
+// CHECK-NEXT: /* 13 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0,           // Opcode: {{.*}}:NOP
+// CHECK-NEXT: /* 17 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
+// CHECK-NEXT: /* 21 */ MCD::OPC_FilterValue, 1, 14, 0,              // Skip to: 39
+// CHECK-NEXT: /* 25 */ MCD::OPC_CheckField, 6, 6, 0, 4, 0,          // Skip to: 35
+// CHECK-NEXT: /* 31 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0,           // Opcode: {{.*}}:NOP
+// CHECK-NEXT: /* 35 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
+// CHECK-NEXT: /* 39 */ MCD::OPC_FilterValue, 2, 14, 0,              // Skip to: 57
+// CHECK-NEXT: /* 43 */ MCD::OPC_CheckField, 6, 6, 0, 4, 0,          // Skip to: 53
+// CHECK-NEXT: /* 49 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0,           // Opcode: {{.*}}:NOP
+// CHECK-NEXT: /* 53 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
+// CHECK-NEXT: /* 57 */ MCD::OPC_FilterValueOrFail, 3,
+// CHECK-NEXT: /* 59 */ MCD::OPC_CheckField, 6, 6, 0, 4, 0,          // Skip to: 69
+// CHECK-NEXT: /* 65 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0,           // Opcode: {{.*}}:NOP
+// CHECK-NEXT: /* 69 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
+// CHECK-NEXT: /* 73 */ MCD::OPC_Fail,
+
+class SHIFT<bits<2> opc> : I<(outs), (ins ShAmtOp:$shamt)>, EncSHIFT<opc>;
+def SHIFT0 : SHIFT<0>;
+def SHIFT1 : SHIFT<1>;
+def SHIFT2 : SHIFT<2>;
+def SHIFT3 : SHIFT<3>;
+
+def NOP : I<(outs), (ins)>, EncNOP<0>;
+def : AdditionalEncoding<NOP>, EncNOP<1>;
+def : AdditionalEncoding<NOP>, EncNOP<2>;
+def : AdditionalEncoding<NOP>, EncNOP<3>;
+
+def II : InstrInfo;
+
+def MyTarget : Target {
+  let InstructionSet = II;
+}
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index ece92c7b76ec0..25f1d824ffcd9 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -2495,7 +2495,9 @@ void DecoderEmitter::parseInstructionEncodings() {
       ++NumEncodingsOmitted;
       continue;
     }
+    unsigned EncodingID = Encodings.size();
     Encodings.emplace_back(EncodingDef, &Target.getInstruction(InstDef));
+    EncodingIDsByHwMode[DefaultMode].push_back(EncodingID);
   }
 
   // Do some statistics.

@s-barannikov s-barannikov merged commit 98262e5 into llvm:main Aug 23, 2025
11 checks passed
@s-barannikov s-barannikov deleted the tablegen/decoder/alt-encoding-fix branch August 23, 2025 02:57
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 23, 2025

LLVM Buildbot has detected a new failure on builder lldb-remote-linux-win running on as-builder-10 while building llvm at step 16 "test-check-lldb-unit".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/197/builds/8315

Here is the relevant piece of the build log for the reference
Step 16 (test-check-lldb-unit) failure: 1200 seconds without output running [b'cmake', b'--build', b'.', b'--target', b'check-lldb-unit'], attempting to kill
...
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests.exe/4/12 (942 of 952)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests.exe/3/12 (943 of 952)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests.exe/5/12 (944 of 952)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests.exe/7/12 (945 of 952)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests.exe/6/12 (946 of 952)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests.exe/8/12 (947 of 952)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests.exe/9/12 (948 of 952)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests.exe/0/1 (949 of 952)
PASS: lldb-unit :: Target/./TargetTests.exe/52/54 (950 of 952)
PASS: lldb-unit :: Process/gdb-remote/./ProcessGdbRemoteTests.exe/8/35 (951 of 952)
command timed out: 1200 seconds without output running [b'cmake', b'--build', b'.', b'--target', b'check-lldb-unit'], attempting to kill
program finished with exit code 1
elapsedTime=1247.331317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants