[llvm] 73731d6 - [llvm-tblgen] Increase Coverage Index Size (#118329)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 4 01:19:17 PST 2024
Author: Sam Elliott
Date: 2024-12-04T09:19:13Z
New Revision: 73731d6873b6fb0757c3065aaf2452eaccd0eebc
URL: https://github.com/llvm/llvm-project/commit/73731d6873b6fb0757c3065aaf2452eaccd0eebc
DIFF: https://github.com/llvm/llvm-project/commit/73731d6873b6fb0757c3065aaf2452eaccd0eebc.diff
LOG: [llvm-tblgen] Increase Coverage Index Size (#118329)
Added:
llvm/test/TableGen/dag-isel-instrument.td
Modified:
llvm/include/llvm/CodeGen/SelectionDAGISel.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index f99ec4651009a0..43ba8f4c44cf9c 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -315,7 +315,7 @@ class SelectionDAGISel {
OPC_MorphNodeTo1GlueOutput,
OPC_MorphNodeTo2GlueOutput,
OPC_CompleteMatch,
- // Contains offset in table for pattern being selected
+ // Contains 32-bit offset in table for pattern being selected
OPC_Coverage
};
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 0d99ae9cdebd50..3000dfda1bea03 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -4045,6 +4045,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
// So it should be safe to assume that this node has been selected
unsigned index = MatcherTable[MatcherIndex++];
index |= (MatcherTable[MatcherIndex++] << 8);
+ index |= (MatcherTable[MatcherIndex++] << 16);
+ index |= (MatcherTable[MatcherIndex++] << 24);
dbgs() << "COVERED: " << getPatternForIndex(index) << "\n";
dbgs() << "INCLUDED: " << getIncludePathForIndex(index) << "\n";
continue;
diff --git a/llvm/test/TableGen/dag-isel-instrument.td b/llvm/test/TableGen/dag-isel-instrument.td
new file mode 100644
index 00000000000000..2862af03cf16da
--- /dev/null
+++ b/llvm/test/TableGen/dag-isel-instrument.td
@@ -0,0 +1,32 @@
+// RUN: llvm-tblgen -gen-dag-isel -instrument-coverage -I %p/../../include %s | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+def TestTargetInstrInfo : InstrInfo;
+
+def TestTarget : Target {
+ let InstructionSet = TestTargetInstrInfo;
+}
+
+def REG : Register<"REG">;
+def GPR : RegisterClass<"TestTarget", [i32], 32, (add REG)>;
+
+// CHECK-LABEL: OPC_CheckOpcode, TARGET_VAL(ISD::UDIVREM)
+// CHECK: OPC_EmitNode2None, TARGET_VAL(::INSTR)
+// CHECK-NEXT: Results = #2 #3
+// CHECK-NEXT: OPC_Coverage, COVERAGE_IDX_VAL(0),
+// CHECK-NEXT: OPC_CompleteMatch, 2, 3, 2
+def INSTR : Instruction {
+ let OutOperandList = (outs GPR:$r1, GPR:$r0);
+ let InOperandList = (ins GPR:$t0, GPR:$t1);
+ let Pattern = [(set i32:$r0, i32:$r1, (udivrem i32:$t0, i32:$t1))];
+}
+
+
+// CHECK: getPatternForIndex(unsigned Index)
+// CHECK: static const char *PATTERN_MATCH_TABLE[]
+// CHECK: return StringRef(PATTERN_MATCH_TABLE[Index]);
+
+// CHECK: getIncludePathForIndex(unsigned Index)
+// CHECK: static const char *INCLUDE_PATH_TABLE[]
+// CHECK: return StringRef(INCLUDE_PATH_TABLE[Index]);
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index 74c399ee423176..f2385bdf1dde41 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -381,8 +381,10 @@ static void EndEmitFunction(raw_ostream &OS) {
void MatcherTableEmitter::EmitPatternMatchTable(raw_ostream &OS) {
- assert(isUInt<16>(VecPatterns.size()) &&
- "Using only 16 bits to encode offset into Pattern Table");
+ if (!isUInt<32>(VecPatterns.size()))
+ report_fatal_error("More patterns defined that can fit into 32-bit Pattern "
+ "Table index encoding");
+
assert(VecPatterns.size() == VecIncludeStrings.size() &&
"The sizes of Pattern and include vectors should be the same");
@@ -947,7 +949,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
std::string include_src = getIncludePath(PatRecord);
unsigned Offset =
getPatternIdxFromTable(src + " -> " + dst, std::move(include_src));
- OS << "TARGET_VAL(" << Offset << "),\n";
+ OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
OS.indent(FullIndexWidth + Indent);
}
}
@@ -1060,7 +1062,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
std::string include_src = getIncludePath(PatRecord);
unsigned Offset =
getPatternIdxFromTable(src + " -> " + dst, std::move(include_src));
- OS << "TARGET_VAL(" << Offset << "),\n";
+ OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
OS.indent(FullIndexWidth + Indent);
}
OS << "OPC_CompleteMatch, " << CM->getNumResults() << ", ";
@@ -1393,8 +1395,11 @@ void llvm::EmitMatcherTable(Matcher *TheMatcher, const CodeGenDAGPatterns &CGP,
// final stream.
OS << "{\n";
OS << " // Some target values are emitted as 2 bytes, TARGET_VAL handles\n";
- OS << " // this.\n";
+ OS << " // this. Coverage indexes are emitted as 4 bytes,\n";
+ OS << " // COVERAGE_IDX_VAL handles this.\n";
OS << " #define TARGET_VAL(X) X & 255, unsigned(X) >> 8\n";
+ OS << " #define COVERAGE_IDX_VAL(X) X & 255, (unsigned(X) >> 8) & 255, ";
+ OS << "(unsigned(X) >> 16) & 255, (unsigned(X) >> 24) & 255\n";
OS << " static const unsigned char MatcherTable[] = {\n";
TotalSize = MatcherEmitter.EmitMatcherList(TheMatcher, 1, 0, OS);
OS << " 0\n }; // Total Array size is " << (TotalSize + 1)
@@ -1402,6 +1407,7 @@ void llvm::EmitMatcherTable(Matcher *TheMatcher, const CodeGenDAGPatterns &CGP,
MatcherEmitter.EmitHistogram(TheMatcher, OS);
+ OS << " #undef COVERAGE_IDX_VAL\n";
OS << " #undef TARGET_VAL\n";
OS << " SelectCodeCommon(N, MatcherTable, sizeof(MatcherTable));\n";
OS << "}\n";
More information about the llvm-commits
mailing list