[TableGen] Fix a misuse of getValueAsBitsInit
authorSheng <ox59616e@gmail.com>
Tue, 22 Mar 2022 05:47:18 +0000 (05:47 +0000)
committerSheng <ox59616e@gmail.com>
Tue, 22 Mar 2022 06:04:36 +0000 (06:04 +0000)
`getValueAsBitsInit` will assert when the "SoftFail" isn't presented.

But given the 'if' statement below, we should've allowed this situation.

This patch fix this.

llvm/utils/TableGen/FixedLenDecoderEmitter.cpp

index d945da1..86591cb 100644 (file)
@@ -427,9 +427,9 @@ protected:
     // disassembler should return SoftFail instead of Success.
     //
     // This is used for marking UNPREDICTABLE instructions in the ARM world.
-    BitsInit *SFBits =
-        AllInstructions[Opcode].EncodingDef->getValueAsBitsInit("SoftFail");
-
+    const RecordVal *RV =
+        AllInstructions[Opcode].EncodingDef->getValue("SoftFail");
+    const BitsInit *SFBits = RV ? dyn_cast<BitsInit>(RV->getValue()) : nullptr;
     for (unsigned i = 0; i < BitWidth; ++i) {
       if (SFBits && bitFromBits(*SFBits, i) == BIT_TRUE)
         Insn.push_back(BIT_UNSET);
@@ -1309,8 +1309,9 @@ void FilterChooser::emitPredicateTableEntry(DecoderTableInfo &TableInfo,
 
 void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
                                            unsigned Opc) const {
-  BitsInit *SFBits =
-      AllInstructions[Opc].EncodingDef->getValueAsBitsInit("SoftFail");
+  const RecordVal *RV = AllInstructions[Opc].EncodingDef->getValue("SoftFail");
+  BitsInit *SFBits = RV ? dyn_cast<BitsInit>(RV->getValue()) : nullptr;
+
   if (!SFBits) return;
   BitsInit *InstBits =
       AllInstructions[Opc].EncodingDef->getValueAsBitsInit("Inst");