/// getResultPatternCost - Compute the number of instructions for this pattern.
/// This is a temporary hack. We should really include the instruction
/// latencies in this calculation.
-static unsigned getResultPatternCost(TreePatternNode *P) {
+static unsigned getResultPatternCost(TreePatternNode *P, DAGISelEmitter &ISE) {
if (P->isLeaf()) return 0;
- unsigned Cost = P->getOperator()->isSubClassOf("Instruction");
+ unsigned Cost = 0;
+ Record *Op = P->getOperator();
+ if (Op->isSubClassOf("Instruction")) {
+ Cost++;
+ CodeGenInstruction &II = ISE.getTargetInfo().getInstruction(Op->getName());
+ if (II.usesCustomDAGSchedInserter)
+ Cost += 10;
+ }
for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
- Cost += getResultPatternCost(P->getChild(i));
+ Cost += getResultPatternCost(P->getChild(i), ISE);
return Cost;
}
if (LHSSize < RHSSize) return false;
// If the patterns have equal complexity, compare generated instruction cost
- return getResultPatternCost(LHS->getDstPattern()) <
- getResultPatternCost(RHS->getDstPattern());
+ return getResultPatternCost(LHS->getDstPattern(), ISE) <
+ getResultPatternCost(RHS->getDstPattern(), ISE);
}
};
OS << "\n";
OS << std::string(Indent, ' ') << "// Pattern complexity = "
<< getPatternSize(Pattern.getSrcPattern(), *this) << " cost = "
- << getResultPatternCost(Pattern.getDstPattern()) << "\n";
+ << getResultPatternCost(Pattern.getDstPattern(), *this) << "\n";
}
if (!FirstCodeLine.first) {
OS << std::string(Indent, ' ') << "{\n";
OS << "\n";
OS << std::string(Indent, ' ') << "// Pattern complexity = "
<< getPatternSize(Pattern.getSrcPattern(), *this) << " cost = "
- << getResultPatternCost(Pattern.getDstPattern()) << "\n";
+ << getResultPatternCost(Pattern.getDstPattern(), *this) << "\n";
}
EmitPatterns(Other, Indent, OS);
return;