[llvm-tblgen] Increase Coverage Index Size (#118329)

This commit is contained in:
Sam Elliott 2024-12-04 09:19:13 +00:00 committed by GitHub
parent 720864907d
commit 73731d6873
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 6 deletions

View File

@ -315,7 +315,7 @@ public:
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
};

View File

@ -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;

View File

@ -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]);

View File

@ -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";