mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Sort the patterns before adding them to the FA so that we get the
least cost matches. This gets us from 195 -> 208 passes on the ppc codegen tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96747 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -141,7 +141,6 @@ struct PatternSortingPredicate {
|
|||||||
|
|
||||||
typedef std::pair<unsigned, std::string> CodeLine;
|
typedef std::pair<unsigned, std::string> CodeLine;
|
||||||
typedef std::vector<CodeLine> CodeList;
|
typedef std::vector<CodeLine> CodeList;
|
||||||
typedef std::vector<std::pair<const PatternToMatch*, CodeList> > PatternList;
|
|
||||||
|
|
||||||
bool operator()(const std::pair<const PatternToMatch*, CodeList> &LHSPair,
|
bool operator()(const std::pair<const PatternToMatch*, CodeList> &LHSPair,
|
||||||
const std::pair<const PatternToMatch*, CodeList> &RHSPair) {
|
const std::pair<const PatternToMatch*, CodeList> &RHSPair) {
|
||||||
@@ -1889,6 +1888,36 @@ void DAGISelEmitter::EmitInstructionSelector(raw_ostream &OS) {
|
|||||||
<< "}\n\n";
|
<< "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// PatternSortingPredicate - return true if we prefer to match LHS before RHS.
|
||||||
|
// In particular, we want to match maximal patterns first and lowest cost within
|
||||||
|
// a particular complexity first.
|
||||||
|
struct PatternSortingPredicate2 {
|
||||||
|
PatternSortingPredicate2(CodeGenDAGPatterns &cgp) : CGP(cgp) {}
|
||||||
|
CodeGenDAGPatterns &CGP;
|
||||||
|
|
||||||
|
bool operator()(const PatternToMatch *LHS,
|
||||||
|
const PatternToMatch *RHS) {
|
||||||
|
unsigned LHSSize = getPatternSize(LHS->getSrcPattern(), CGP);
|
||||||
|
unsigned RHSSize = getPatternSize(RHS->getSrcPattern(), CGP);
|
||||||
|
LHSSize += LHS->getAddedComplexity();
|
||||||
|
RHSSize += RHS->getAddedComplexity();
|
||||||
|
if (LHSSize > RHSSize) return true; // LHS -> bigger -> less cost
|
||||||
|
if (LHSSize < RHSSize) return false;
|
||||||
|
|
||||||
|
// If the patterns have equal complexity, compare generated instruction cost
|
||||||
|
unsigned LHSCost = getResultPatternCost(LHS->getDstPattern(), CGP);
|
||||||
|
unsigned RHSCost = getResultPatternCost(RHS->getDstPattern(), CGP);
|
||||||
|
if (LHSCost < RHSCost) return true;
|
||||||
|
if (LHSCost > RHSCost) return false;
|
||||||
|
|
||||||
|
return getResultPatternSize(LHS->getDstPattern(), CGP) <
|
||||||
|
getResultPatternSize(RHS->getDstPattern(), CGP);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DAGISelEmitter::run(raw_ostream &OS) {
|
void DAGISelEmitter::run(raw_ostream &OS) {
|
||||||
EmitSourceFileHeader("DAG Instruction Selector for the " +
|
EmitSourceFileHeader("DAG Instruction Selector for the " +
|
||||||
CGP.getTargetInfo().getName() + " target", OS);
|
CGP.getTargetInfo().getName() + " target", OS);
|
||||||
@@ -1919,11 +1948,27 @@ void DAGISelEmitter::run(raw_ostream &OS) {
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
MatcherNode *Matcher = 0;
|
MatcherNode *Matcher = 0;
|
||||||
// Walk the patterns backwards, building a matcher for each and adding it to
|
|
||||||
// the matcher for the whole target.
|
// Add all the patterns to a temporary list so we can sort them.
|
||||||
for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(),
|
std::vector<const PatternToMatch*> Patterns;
|
||||||
E = CGP.ptm_end(); I != E;) {
|
for (CodeGenDAGPatterns::ptm_iterator I = CGP.ptm_begin(), E = CGP.ptm_end();
|
||||||
const PatternToMatch &Pattern = *--E;
|
I != E; ++I)
|
||||||
|
Patterns.push_back(&*I);
|
||||||
|
|
||||||
|
// We want to process the matches in order of minimal cost. Sort the patterns
|
||||||
|
// so the least cost one is at the start.
|
||||||
|
// FIXME: Eliminate "PatternSortingPredicate" and rename.
|
||||||
|
std::stable_sort(Patterns.begin(), Patterns.end(),
|
||||||
|
PatternSortingPredicate2(CGP));
|
||||||
|
|
||||||
|
|
||||||
|
// Walk the patterns backwards (since we append to the front of the generated
|
||||||
|
// code), building a matcher for each and adding it to the matcher for the
|
||||||
|
// whole target.
|
||||||
|
while (!Patterns.empty()) {
|
||||||
|
const PatternToMatch &Pattern = *Patterns.back();
|
||||||
|
Patterns.pop_back();
|
||||||
|
|
||||||
MatcherNode *N = ConvertPatternToMatcher(Pattern, CGP);
|
MatcherNode *N = ConvertPatternToMatcher(Pattern, CGP);
|
||||||
|
|
||||||
if (Matcher == 0)
|
if (Matcher == 0)
|
||||||
@@ -1933,8 +1978,8 @@ void DAGISelEmitter::run(raw_ostream &OS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OptimizeMatcher(Matcher);
|
// OptimizeMatcher(Matcher);
|
||||||
EmitMatcherTable(Matcher, OS);
|
|
||||||
//Matcher->dump();
|
//Matcher->dump();
|
||||||
|
EmitMatcherTable(Matcher, OS);
|
||||||
delete Matcher;
|
delete Matcher;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user