[llvm] r340837 - [TableGen] CodeGenDAGPatterns::GenerateVariants - basic caching of matching predicates
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 28 08:42:08 PDT 2018
Author: rksimon
Date: Tue Aug 28 08:42:08 2018
New Revision: 340837
URL: http://llvm.org/viewvc/llvm-project?rev=340837&view=rev
Log:
[TableGen] CodeGenDAGPatterns::GenerateVariants - basic caching of matching predicates
CodeGenDAGPatterns::GenerateVariants is a costly function in many tblgen commands (33.87% of the total runtime of x86 -gen-dag-isel), and due to the O(N^2) nature of the function, there are a high number of repeated comparisons of the pattern's vector<Predicate>.
This initial patch at least avoids repeating these comparisons for every Variant in a pattern. I began investigating caching all the matches before entering the loop but hit issues with how best to store the data and how to update the cache as patterns were added.
Saves around 15secs in debug builds of x86 -gen-dag-isel.
Differential Revision: https://reviews.llvm.org/D51035
Modified:
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=340837&r1=340836&r2=340837&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Tue Aug 28 08:42:08 2018
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "CodeGenDAGPatterns.h"
+#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
@@ -4477,6 +4478,16 @@ void CodeGenDAGPatterns::GenerateVariant
LLVM_DEBUG(errs() << "FOUND VARIANTS OF: ";
PatternsToMatch[i].getSrcPattern()->dump(); errs() << "\n");
+ // Cache matching predicates.
+ // TODO: Is it performant to pull this out of the loop entirely?
+ BitVector MatchedPredicates(PatternsToMatch.size(), false);
+ for (unsigned p = 0, e = PatternsToMatch.size(); p != e; ++p)
+ MatchedPredicates[p] = (i == p) || (PatternsToMatch[i].getPredicates() ==
+ PatternsToMatch[p].getPredicates());
+
+ unsigned NumMatches = MatchedPredicates.count();
+ (void)NumMatches;
+
for (unsigned v = 0, e = Variants.size(); v != e; ++v) {
TreePatternNodePtr Variant = Variants[v];
@@ -4487,8 +4498,7 @@ void CodeGenDAGPatterns::GenerateVariant
bool AlreadyExists = false;
for (unsigned p = 0, e = PatternsToMatch.size(); p != e; ++p) {
// Skip if the top level predicates do not match.
- if ((i != p) && (PatternsToMatch[i].getPredicates() !=
- PatternsToMatch[p].getPredicates()))
+ if (!MatchedPredicates[p])
continue;
// Check to see if this variant already exists.
if (Variant->isIsomorphicTo(PatternsToMatch[p].getSrcPattern(),
@@ -4507,6 +4517,8 @@ void CodeGenDAGPatterns::GenerateVariant
Variant, PatternsToMatch[i].getDstPatternShared(),
PatternsToMatch[i].getDstRegs(),
PatternsToMatch[i].getAddedComplexity(), Record::getNewUID()));
+ MatchedPredicates.resize(PatternsToMatch.size());
+ MatchedPredicates[PatternsToMatch.size() - 1] = true;
}
LLVM_DEBUG(errs() << "\n");
More information about the llvm-commits
mailing list