Add code size to target instruction use it as the 3rd isel sorting tie-breaker.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29193 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2006-07-19 00:24:41 +00:00
parent 917d2c9dc2
commit e6f32034db
2 changed files with 28 additions and 3 deletions

View File

@ -147,6 +147,9 @@ class Instruction {
// code.
list<Predicate> Predicates = [];
// Code size.
int CodeSize = 0;
// Added complexity passed onto matching pattern.
int AddedComplexity = 0;

View File

@ -1986,6 +1986,21 @@ static unsigned getResultPatternCost(TreePatternNode *P, DAGISelEmitter &ISE) {
return Cost;
}
/// getResultPatternCodeSize - Compute the code size of instructions for this
/// pattern.
static unsigned getResultPatternSize(TreePatternNode *P, DAGISelEmitter &ISE) {
if (P->isLeaf()) return 0;
unsigned Cost = 0;
Record *Op = P->getOperator();
if (Op->isSubClassOf("Instruction")) {
Cost += Op->getValueAsInt("CodeSize");
}
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
Cost += getResultPatternSize(P->getChild(i), ISE);
return Cost;
}
// 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.
@ -2003,8 +2018,13 @@ struct PatternSortingPredicate {
if (LHSSize < RHSSize) return false;
// If the patterns have equal complexity, compare generated instruction cost
return getResultPatternCost(LHS->getDstPattern(), ISE) <
getResultPatternCost(RHS->getDstPattern(), ISE);
unsigned LHSCost = getResultPatternCost(LHS->getDstPattern(), ISE);
unsigned RHSCost = getResultPatternCost(RHS->getDstPattern(), ISE);
if (LHSCost < RHSCost) return true;
if (LHSCost > RHSCost) return false;
return getResultPatternSize(LHS->getDstPattern(), ISE) <
getResultPatternSize(RHS->getDstPattern(), ISE);
}
};
@ -3105,7 +3125,9 @@ void DAGISelEmitter::EmitPatterns(std::vector<std::pair<PatternToMatch*,
OS << std::string(Indent, ' ') << "// Pattern complexity = "
<< getPatternSize(Pattern.getSrcPattern(), *this) + AddedComplexity
<< " cost = "
<< getResultPatternCost(Pattern.getDstPattern(), *this) << "\n";
<< getResultPatternCost(Pattern.getDstPattern(), *this)
<< " size = "
<< getResultPatternSize(Pattern.getDstPattern(), *this) << "\n";
}
if (!FirstCodeLine.first) {
OS << std::string(Indent, ' ') << "{\n";