From 19cf75c72ffd9ab9dd802eba625fc2e91e4e8a90 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 3 Feb 2026 13:45:00 -0800 Subject: [PATCH] Revert "[SelectionDAGISel] Separate the operand numbers in OPC_EmitNode/MorphNodeTo into their own table. (#178722)" This reverts commit caab98284166784459a2fb76df7bca3f1d35e41e. This is failing some build bots. --- llvm/include/llvm/CodeGen/SelectionDAGISel.h | 2 +- .../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 23 +++---- llvm/test/TableGen/CPtrWildcard.td | 8 +-- llvm/test/TableGen/RegClassByHwMode.td | 7 --- .../TableGen/dag-isel-regclass-emit-enum.td | 6 +- llvm/utils/TableGen/DAGISelMatcherEmitter.cpp | 63 ++----------------- 6 files changed, 19 insertions(+), 90 deletions(-) diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h index 38a7d70ef6db..c94dc4241368 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h @@ -470,7 +470,7 @@ public: } void SelectCodeCommon(SDNode *NodeToMatch, const uint8_t *MatcherTable, - unsigned TableSize, const uint8_t *OperandLists); + unsigned TableSize); /// Return true if complex patterns for this target can mutate the /// DAG. diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 7419aac6ba3d..e7cb0a3574b4 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -3350,8 +3350,7 @@ public: void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch, const uint8_t *MatcherTable, - unsigned TableSize, - const uint8_t *OperandLists) { + unsigned TableSize) { // FIXME: Should these even be selected? Handle these cases in the caller? switch (NodeToMatch->getOpcode()) { default: @@ -4308,22 +4307,14 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch, // Get the operand list. unsigned NumOps = MatcherTable[MatcherIndex++]; - SmallVector Ops; - if (NumOps != 0) { - // Get the index into the OperandLists. - uint64_t OperandIndex = MatcherTable[MatcherIndex++]; - if (OperandIndex & 128) - OperandIndex = GetVBR(OperandIndex, MatcherTable, MatcherIndex); + for (unsigned i = 0; i != NumOps; ++i) { + unsigned RecNo = MatcherTable[MatcherIndex++]; + if (RecNo & 128) + RecNo = GetVBR(RecNo, MatcherTable, MatcherIndex); - for (unsigned i = 0; i != NumOps; ++i) { - unsigned RecNo = OperandLists[OperandIndex++]; - if (RecNo & 128) - RecNo = GetVBR(RecNo, OperandLists, OperandIndex); - - assert(RecNo < RecordedNodes.size() && "Invalid EmitNode"); - Ops.push_back(RecordedNodes[RecNo].first); - } + assert(RecNo < RecordedNodes.size() && "Invalid EmitNode"); + Ops.push_back(RecordedNodes[RecNo].first); } // If there are variadic operands to add, handle them now. diff --git a/llvm/test/TableGen/CPtrWildcard.td b/llvm/test/TableGen/CPtrWildcard.td index 6e09fce70d83..a8b73dd28c18 100644 --- a/llvm/test/TableGen/CPtrWildcard.td +++ b/llvm/test/TableGen/CPtrWildcard.td @@ -10,22 +10,18 @@ // CHECK-NEXT:/* 6*/ OPC_Scope /*2 children */, 9, // ->17 // CHECK-NEXT:/* 8*/ OPC_CheckChild1Type, /*MVT::c64*/4|128,2/*260*/, // CHECK-NEXT:/* 11*/ OPC_MorphNodeTo1None, TARGET_VAL(MyTarget::C64_TO_I64), -// CHECK-NEXT: MVT::i64, 1/*#Ops*/, /*OperandList*/0, // Ops = #0 +// CHECK-NEXT: MVT::i64, 1/*#Ops*/, 0, // CHECK-NEXT: // Src: (intrinsic_wo_chain:{ *:[i64] } [[#]]:{ *:[iPTR] }, c64:{ *:[c64] }:$src) - Complexity = 8 // CHECK-NEXT: // Dst: (C64_TO_I64:{ *:[i64] } ?:{ *:[c64] }:$src) // CHECK-NEXT:/* 17*/ /*Scope*/ 9, // ->27 // CHECK-NEXT:/* 18*/ OPC_CheckChild1Type, /*MVT::c128*/5|128,2/*261*/, // CHECK-NEXT:/* 21*/ OPC_MorphNodeTo1None, TARGET_VAL(MyTarget::C128_TO_I64), -// CHECK-NEXT: MVT::i64, 1/*#Ops*/, /*OperandList*/0, // Ops = #0 +// CHECK-NEXT: MVT::i64, 1/*#Ops*/, 0, // CHECK-NEXT: // Src: (intrinsic_wo_chain:{ *:[i64] } [[#]]:{ *:[iPTR] }, c128:{ *:[c128] }:$src) - Complexity = 8 // CHECK-NEXT: // Dst: (C128_TO_I64:{ *:[i64] } ?:{ *:[c128] }:$src) // CHECK-NEXT:/* 27*/ 0, // End of Scope // CHECK-NEXT: }; // Total Array size is 28 bytes -// CHECK: static const uint8_t OperandLists[] = { -// CHECK-NEXT: /* 0 */ 0, -// CHECK-NEXT: } - include "llvm/Target/Target.td" def my_cap_ty : LLVMQualPointerType<200> { diff --git a/llvm/test/TableGen/RegClassByHwMode.td b/llvm/test/TableGen/RegClassByHwMode.td index 83531b9248f9..508b098c9f44 100644 --- a/llvm/test/TableGen/RegClassByHwMode.td +++ b/llvm/test/TableGen/RegClassByHwMode.td @@ -212,7 +212,6 @@ include "Common/RegClassByHwModeCommon.td" // ISEL-SDAG-NEXT: OPC_CheckPredicate1, // Predicate_store // ISEL-SDAG-NEXT: OPC_EmitMergeInputChains1_0, // ISEL-SDAG-NEXT: OPC_MorphNodeTo0, TARGET_VAL(MyTarget::MY_STORE), 0|OPFL_Chain|OPFL_MemRefs, -// ISEL-SDAG-NEXT: 2/*#Ops*/, /*OperandList*/1, // Ops = #1 #2 // ISEL-SDAG: /*SwitchOpcode*/ {{[0-9]+}}, TARGET_VAL(ISD::LOAD), // ISEL-SDAG-NEXT: OPC_RecordMemRef, @@ -224,12 +223,6 @@ include "Common/RegClassByHwModeCommon.td" // ISEL-SDAG-NEXT: OPC_CheckTypeI64, // ISEL-SDAG-NEXT: OPC_EmitMergeInputChains1_0, // ISEL-SDAG-NEXT: OPC_MorphNodeToByHwMode, TARGET_VAL(MyTarget::MY_LOAD), 0|OPFL_Chain|OPFL_MemRefs, -// ISEL-SDAG-NEXT: 1/*#VTs*/, /*{(*:i64),(m1:i64),(m2:i64)}*/0, 1/*#Ops*/, /*OperandList*/0, // Ops = #1 - -// ISEL-SDAG: static const uint8_t OperandLists[] = { -// ISEL-SDAG-NEXT: /* 0 */ 1, -// ISEL-SDAG-NEXT: /* 1 */ 1, 2, -// ISEL-SDAG-NEXT: } diff --git a/llvm/test/TableGen/dag-isel-regclass-emit-enum.td b/llvm/test/TableGen/dag-isel-regclass-emit-enum.td index 5a3b4a47953c..2fb04638fd1e 100644 --- a/llvm/test/TableGen/dag-isel-regclass-emit-enum.td +++ b/llvm/test/TableGen/dag-isel-regclass-emit-enum.td @@ -23,17 +23,17 @@ def GPRAbove127 : RegisterClass<"TestTarget", [i32], 32, // CHECK: OPC_CheckOpcode, TARGET_VAL(ISD::ADD), // CHECK-NEXT: OPC_RecordChild0, // #0 = $src -// CHECK-NEXT: OPC_Scope /*2 children */, 11, // ->17 +// CHECK-NEXT: OPC_Scope /*2 children */, 12, // ->18 // CHECK-NEXT: OPC_CheckChild1Integer, 0, // CHECK-NEXT: OPC_EmitIntegerI32, 0|128,1/*128*/, // #1 = TestNamespace::GPRAbove127RegClassID // CHECK-NEXT: OPC_MorphNodeTo1None, TARGET_VAL(TargetOpcode::COPY_TO_REGCLASS), -// CHECK-NEXT: MVT::i32, 2/*#Ops*/, /*OperandList*/0, // Ops = #1 #0 +// CHECK-NEXT: MVT::i32, 2/*#Ops*/, 1, 0, def : Pat<(i32 (add i32:$src, (i32 0))), (COPY_TO_REGCLASS GPRAbove127, GPR0:$src)>; // CHECK: OPC_CheckChild1Integer, 1, // CHECK-NEXT: OPC_EmitIntegerI32, TestNamespace::GPR127RegClassID, // CHECK-NEXT: OPC_MorphNodeTo1None, TARGET_VAL(TargetOpcode::COPY_TO_REGCLASS), -// CHECK-NEXT: MVT::i32, 2/*#Ops*/, /*OperandList*/0, // Ops = #1 #0 +// CHECK-NEXT: MVT::i32, 2/*#Ops*/, 1, 0, def : Pat<(i32 (add i32:$src, (i32 1))), (COPY_TO_REGCLASS GPR127, GPR0:$src)>; diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp index 1058e7567805..9bb5a8415ba1 100644 --- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp +++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp @@ -11,7 +11,6 @@ //===----------------------------------------------------------------------===// #include "Basic/SDNodeProperties.h" -#include "Basic/SequenceToOffsetTable.h" #include "Common/CodeGenDAGPatterns.h" #include "Common/CodeGenInstruction.h" #include "Common/CodeGenRegisters.h" @@ -74,8 +73,6 @@ class MatcherTableEmitter { std::map ValueTypeMap; - SequenceToOffsetTable> OperandTable; - unsigned getPatternIdxFromTable(std::string &&P, std::string &&include_loc) { const auto [It, Inserted] = VecPatterns.try_emplace(std::move(P), VecPatterns.size()); @@ -88,8 +85,7 @@ class MatcherTableEmitter { public: MatcherTableEmitter(const Matcher *TheMatcher, const CodeGenDAGPatterns &cgp) - : CGP(cgp), OpcodeCounts(Matcher::HighestKind + 1, 0), - OperandTable(std::nullopt) { + : CGP(cgp), OpcodeCounts(Matcher::HighestKind + 1, 0) { // Record the usage of ComplexPattern. MapVector ComplexPatternUsage; // Record the usage of PatternPredicate. @@ -115,26 +111,11 @@ public: ++PatternPredicateUsage[CPPM->getPredicate()]; else if (auto *PM = dyn_cast(N)) ++PredicateUsage[PM->getPredicate().getOrigPatFragRecord()]; - - if (const auto *EN = dyn_cast(N)) { - ArrayRef Ops = EN->getOperandList(); - std::vector OpBytes; - for (unsigned Op : Ops) { - uint8_t Buffer[5]; - unsigned Len = encodeULEB128(Op, Buffer); - for (unsigned i = 0; i < Len; ++i) - OpBytes.push_back(Buffer[i]); - } - OperandTable.add(OpBytes); - } - N = N->getNext(); } }; Statistic(TheMatcher); - OperandTable.layout(); - // Sort ComplexPatterns by usage. std::vector> ComplexPatternList( ComplexPatternUsage.begin(), ComplexPatternUsage.end()); @@ -191,8 +172,6 @@ public: unsigned EmitMatcherList(const Matcher *N, const unsigned Indent, unsigned StartIdx, raw_ostream &OS); - void EmitOperandLists(raw_ostream &OS); - unsigned SizeMatcherList(Matcher *N, raw_ostream &OS); void EmitPredicateFunctions(raw_ostream &OS); @@ -1133,42 +1112,21 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N, } } - unsigned NumOps = EN->getNumOperands(); - OS << ' ' << NumOps; + OS << ' ' << EN->getNumOperands(); if (!OmitComments) OS << "/*#Ops*/"; OS << ','; - unsigned NumOperandBytes = 0; - if (NumOps != 0) { - std::vector OpBytes; - for (unsigned i = 0, e = EN->getNumOperands(); i != e; ++i) { - uint8_t Buffer[5]; - unsigned Len = encodeULEB128(EN->getOperand(i), Buffer); - for (unsigned i = 0; i < Len; ++i) - OpBytes.push_back(Buffer[i]); - } - unsigned Index = OperandTable.get(OpBytes); + for (unsigned i = 0, e = EN->getNumOperands(); i != e; ++i) { OS << ' '; - if (!OmitComments) - OS << "/*OperandList*/"; - NumOperandBytes = EmitVBRValue(Index, OS); + NumOperandBytes += EmitVBRValue(EN->getOperand(i), OS); } if (!OmitComments) { - // Print the operand #'s. - ArrayRef Ops = EN->getOperandList(); - OS << " // Ops ="; - if (Ops.empty()) - OS << " None"; - else - for (unsigned OpNo : Ops) - OS << " #" << OpNo; - // Print the result #'s for EmitNode. if (const EmitNodeMatcher *E = dyn_cast(EN)) { if (unsigned NumResults = EN->getNumVTs()) { - OS << " Results ="; + OS << " // Results ="; unsigned First = E->getFirstResultSlot(); for (unsigned i = 0; i != NumResults; ++i) OS << " #" << First + i; @@ -1251,10 +1209,6 @@ unsigned MatcherTableEmitter::EmitMatcherList(const Matcher *N, return Size; } -void MatcherTableEmitter::EmitOperandLists(raw_ostream &OS) { - OperandTable.emit(OS, [](raw_ostream &OS, uint8_t O) { OS << (unsigned)O; }); -} - void MatcherTableEmitter::EmitNodePredicatesFunction( const std::vector &Preds, StringRef Decl, raw_ostream &OS) { if (Preds.empty()) @@ -1590,14 +1544,9 @@ void llvm::EmitMatcherTable(Matcher *TheMatcher, const CodeGenDAGPatterns &CGP, MatcherEmitter.EmitHistogram(OS); - OS << " static const uint8_t OperandLists[] = {\n"; - MatcherEmitter.EmitOperandLists(OS); - OS << " };\n\n"; - OS << " #undef COVERAGE_IDX_VAL\n"; OS << " #undef TARGET_VAL\n"; - OS << " SelectCodeCommon(N, MatcherTable, sizeof(MatcherTable),\n"; - OS << " OperandLists);\n"; + OS << " SelectCodeCommon(N, MatcherTable, sizeof(MatcherTable));\n"; OS << "}\n"; EndEmitFunction(OS);