@@ -381,8 +381,10 @@ static void EndEmitFunction(raw_ostream &OS) {
381381
382382void 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