[PATCH] D46098: [GlobalISel][InstructionSelect] Making Coverage Info generation optional on per-match table basis

Roman Tereshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 17:26:08 PDT 2018


rtereshin created this revision.
rtereshin added reviewers: dsanders, aemerson.
Herald added subscribers: llvm-commits, kristof.beyls, rovka.

to make sure that Testgen always has access to coverage info even if the match table used by the selector itself is stripped off that information for performance reasons.

Originally part of the larger https://reviews.llvm.org/D43962 ([GlobalISel][utils] Adding the init version of Instruction Select Testgen) patch, extracted as to make it smaller and more targeted.

Partially reviewed by @dsanders within the patch mentioned.

Required by https://reviews.llvm.org/D43962, depends on https://reviews.llvm.org/D46097


Repository:
  rL LLVM

https://reviews.llvm.org/D46098

Files:
  utils/TableGen/GlobalISelEmitter.cpp


Index: utils/TableGen/GlobalISelEmitter.cpp
===================================================================
--- utils/TableGen/GlobalISelEmitter.cpp
+++ utils/TableGen/GlobalISelEmitter.cpp
@@ -424,6 +424,8 @@
   unsigned CurrentSize = 0;
   /// A unique identifier for a MatchTable label.
   unsigned CurrentLabelID = 0;
+  /// Determines if the table should be instrumented for rule coverage tracking.
+  bool IsWithCoverage;
 
 public:
   static MatchTableRecord LineBreak;
@@ -466,9 +468,12 @@
                                 MatchTableRecord::MTRF_CommaFollows);
   }
 
-  static MatchTable buildTable(ArrayRef<Matcher *> Rules);
+  static MatchTable buildTable(ArrayRef<Matcher *> Rules, bool WithCoverage);
 
-  MatchTable(unsigned ID = 0) : ID(ID) {}
+  MatchTable(bool WithCoverage, unsigned ID = 0)
+      : ID(ID), IsWithCoverage(WithCoverage) {}
+
+  bool isWithCoverage() const { return IsWithCoverage; }
 
   void push_back(const MatchTableRecord &Value) {
     if (Value.Flags & MatchTableRecord::MTRF_Label)
@@ -578,8 +583,9 @@
   virtual std::unique_ptr<PredicateMatcher> forgetFirstCondition() = 0;
 };
 
-MatchTable MatchTable::buildTable(ArrayRef<Matcher *> Rules) {
-  MatchTable Table;
+MatchTable MatchTable::buildTable(ArrayRef<Matcher *> Rules,
+                                  bool WithCoverage) {
+  MatchTable Table(WithCoverage);
   for (Matcher *Rule : Rules)
     Rule->emit(Table);
 
@@ -2492,7 +2498,7 @@
   for (const auto &MA : Actions)
     MA->emitActionOpcodes(Table, *this);
 
-  if (GenerateCoverage)
+  if (Table.isWithCoverage())
     Table << MatchTable::Opcode("GIR_Coverage") << MatchTable::IntValue(RuleID)
           << MatchTable::LineBreak;
 
@@ -2698,7 +2704,8 @@
       ArrayRef<Matcher *> Rules,
       std::vector<std::unique_ptr<GroupMatcher>> &StorageGroupMatcher);
 
-  MatchTable buildMatchTable(MutableArrayRef<RuleMatcher> Rules, bool Optimize);
+  MatchTable buildMatchTable(MutableArrayRef<RuleMatcher> Rules, bool Optimize,
+                             bool WithCoverage);
 };
 
 void GlobalISelEmitter::gatherNodeEquivs() {
@@ -3688,19 +3695,19 @@
 
 MatchTable
 GlobalISelEmitter::buildMatchTable(MutableArrayRef<RuleMatcher> Rules,
-                                   bool Optimize) {
+                                   bool Optimize, bool WithCoverage) {
   std::vector<Matcher *> InputRules;
   for (Matcher &Rule : Rules)
     InputRules.push_back(&Rule);
 
   if (!Optimize)
-    return MatchTable::buildTable(InputRules);
+    return MatchTable::buildTable(InputRules, WithCoverage);
 
   std::vector<std::unique_ptr<GroupMatcher>> StorageGroupMatcher;
   std::vector<Matcher *> OptRules =
       optimizeRules(InputRules, StorageGroupMatcher);
 
-  return MatchTable::buildTable(OptRules);
+  return MatchTable::buildTable(OptRules, WithCoverage);
 }
 
 void GlobalISelEmitter::run(raw_ostream &OS) {
@@ -3991,7 +3998,8 @@
      << "  return false;\n"
      << "}\n\n";
 
-  const MatchTable Table = buildMatchTable(Rules, OptimizeMatchTable);
+  const MatchTable Table =
+      buildMatchTable(Rules, OptimizeMatchTable, GenerateCoverage);
   OS << "const int64_t *" << Target.getName()
      << "InstructionSelector::getMatchTable() const {\n";
   Table.emitDeclaration(OS);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46098.144042.patch
Type: text/x-patch
Size: 3257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180426/c0774b61/attachment.bin>


More information about the llvm-commits mailing list