Skip to content

Commit 73731d6

Browse files
authored
[llvm-tblgen] Increase Coverage Index Size (#118329)
1 parent 7208649 commit 73731d6

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class SelectionDAGISel {
315315
OPC_MorphNodeTo1GlueOutput,
316316
OPC_MorphNodeTo2GlueOutput,
317317
OPC_CompleteMatch,
318-
// Contains offset in table for pattern being selected
318+
// Contains 32-bit offset in table for pattern being selected
319319
OPC_Coverage
320320
};
321321

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4045,6 +4045,8 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
40454045
// So it should be safe to assume that this node has been selected
40464046
unsigned index = MatcherTable[MatcherIndex++];
40474047
index |= (MatcherTable[MatcherIndex++] << 8);
4048+
index |= (MatcherTable[MatcherIndex++] << 16);
4049+
index |= (MatcherTable[MatcherIndex++] << 24);
40484050
dbgs() << "COVERED: " << getPatternForIndex(index) << "\n";
40494051
dbgs() << "INCLUDED: " << getIncludePathForIndex(index) << "\n";
40504052
continue;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: llvm-tblgen -gen-dag-isel -instrument-coverage -I %p/../../include %s | FileCheck %s
2+
3+
include "llvm/Target/Target.td"
4+
5+
def TestTargetInstrInfo : InstrInfo;
6+
7+
def TestTarget : Target {
8+
let InstructionSet = TestTargetInstrInfo;
9+
}
10+
11+
def REG : Register<"REG">;
12+
def GPR : RegisterClass<"TestTarget", [i32], 32, (add REG)>;
13+
14+
// CHECK-LABEL: OPC_CheckOpcode, TARGET_VAL(ISD::UDIVREM)
15+
// CHECK: OPC_EmitNode2None, TARGET_VAL(::INSTR)
16+
// CHECK-NEXT: Results = #2 #3
17+
// CHECK-NEXT: OPC_Coverage, COVERAGE_IDX_VAL(0),
18+
// CHECK-NEXT: OPC_CompleteMatch, 2, 3, 2
19+
def INSTR : Instruction {
20+
let OutOperandList = (outs GPR:$r1, GPR:$r0);
21+
let InOperandList = (ins GPR:$t0, GPR:$t1);
22+
let Pattern = [(set i32:$r0, i32:$r1, (udivrem i32:$t0, i32:$t1))];
23+
}
24+
25+
26+
// CHECK: getPatternForIndex(unsigned Index)
27+
// CHECK: static const char *PATTERN_MATCH_TABLE[]
28+
// CHECK: return StringRef(PATTERN_MATCH_TABLE[Index]);
29+
30+
// CHECK: getIncludePathForIndex(unsigned Index)
31+
// CHECK: static const char *INCLUDE_PATH_TABLE[]
32+
// CHECK: return StringRef(INCLUDE_PATH_TABLE[Index]);

llvm/utils/TableGen/DAGISelMatcherEmitter.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,10 @@ static void EndEmitFunction(raw_ostream &OS) {
381381

382382
void MatcherTableEmitter::EmitPatternMatchTable(raw_ostream &OS) {
383383

384-
assert(isUInt<16>(VecPatterns.size()) &&
385-
"Using only 16 bits to encode offset into Pattern Table");
384+
if (!isUInt<32>(VecPatterns.size()))
385+
report_fatal_error("More patterns defined that can fit into 32-bit Pattern "
386+
"Table index encoding");
387+
386388
assert(VecPatterns.size() == VecIncludeStrings.size() &&
387389
"The sizes of Pattern and include vectors should be the same");
388390

@@ -947,7 +949,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
947949
std::string include_src = getIncludePath(PatRecord);
948950
unsigned Offset =
949951
getPatternIdxFromTable(src + " -> " + dst, std::move(include_src));
950-
OS << "TARGET_VAL(" << Offset << "),\n";
952+
OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
951953
OS.indent(FullIndexWidth + Indent);
952954
}
953955
}
@@ -1060,7 +1062,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
10601062
std::string include_src = getIncludePath(PatRecord);
10611063
unsigned Offset =
10621064
getPatternIdxFromTable(src + " -> " + dst, std::move(include_src));
1063-
OS << "TARGET_VAL(" << Offset << "),\n";
1065+
OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
10641066
OS.indent(FullIndexWidth + Indent);
10651067
}
10661068
OS << "OPC_CompleteMatch, " << CM->getNumResults() << ", ";
@@ -1393,15 +1395,19 @@ void llvm::EmitMatcherTable(Matcher *TheMatcher, const CodeGenDAGPatterns &CGP,
13931395
// final stream.
13941396
OS << "{\n";
13951397
OS << " // Some target values are emitted as 2 bytes, TARGET_VAL handles\n";
1396-
OS << " // this.\n";
1398+
OS << " // this. Coverage indexes are emitted as 4 bytes,\n";
1399+
OS << " // COVERAGE_IDX_VAL handles this.\n";
13971400
OS << " #define TARGET_VAL(X) X & 255, unsigned(X) >> 8\n";
1401+
OS << " #define COVERAGE_IDX_VAL(X) X & 255, (unsigned(X) >> 8) & 255, ";
1402+
OS << "(unsigned(X) >> 16) & 255, (unsigned(X) >> 24) & 255\n";
13981403
OS << " static const unsigned char MatcherTable[] = {\n";
13991404
TotalSize = MatcherEmitter.EmitMatcherList(TheMatcher, 1, 0, OS);
14001405
OS << " 0\n }; // Total Array size is " << (TotalSize + 1)
14011406
<< " bytes\n\n";
14021407

14031408
MatcherEmitter.EmitHistogram(TheMatcher, OS);
14041409

1410+
OS << " #undef COVERAGE_IDX_VAL\n";
14051411
OS << " #undef TARGET_VAL\n";
14061412
OS << " SelectCodeCommon(N, MatcherTable, sizeof(MatcherTable));\n";
14071413
OS << "}\n";

0 commit comments

Comments
 (0)