[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Sep 28 10:58:07 PDT 2005
Changes in directory llvm/utils/TableGen:
DAGISelEmitter.cpp updated: 1.45 -> 1.46
---
Log message:
Prefer cheaper patterns to more expensive ones. Print the costs to the generated
file
---
Diffs of the changes: (+50 -39)
DAGISelEmitter.cpp | 89 +++++++++++++++++++++++++++++------------------------
1 files changed, 50 insertions(+), 39 deletions(-)
Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.45 llvm/utils/TableGen/DAGISelEmitter.cpp:1.46
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.45 Wed Sep 28 11:58:06 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp Wed Sep 28 12:57:56 2005
@@ -995,6 +995,52 @@
});
}
+/// getPatternSize - Return the 'size' of this pattern. We want to match large
+/// patterns before small ones. This is used to determine the size of a
+/// pattern.
+static unsigned getPatternSize(TreePatternNode *P) {
+ assert(MVT::isInteger(P->getType()) || MVT::isFloatingPoint(P->getType()) &&
+ "Not a valid pattern node to size!");
+ unsigned Size = 1; // The node itself.
+
+ // Count children in the count if they are also nodes.
+ for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i) {
+ TreePatternNode *Child = P->getChild(i);
+ if (!Child->isLeaf() && Child->getType() != MVT::Other)
+ Size += getPatternSize(Child);
+ }
+
+ return Size;
+}
+
+/// 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) {
+ if (P->isLeaf()) return 0;
+
+ unsigned Cost = P->getOperator()->isSubClassOf("Instruction");
+ for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i)
+ Cost += getResultPatternCost(P->getChild(i));
+ 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.
+struct PatternSortingPredicate {
+ bool operator()(DAGISelEmitter::PatternToMatch *LHS,
+ DAGISelEmitter::PatternToMatch *RHS) {
+ unsigned LHSSize = getPatternSize(LHS->first);
+ unsigned RHSSize = getPatternSize(RHS->first);
+ if (LHSSize > RHSSize) return true; // LHS -> bigger -> less cost
+ if (LHSSize < RHSSize) return false;
+
+ // If the patterns have equal complexity, compare generated instruction cost
+ return getResultPatternCost(LHS->second) <getResultPatternCost(RHS->second);
+ }
+};
+
/// EmitMatchForPattern - Emit a matcher for N, going to the label for PatternNo
/// if the match fails. At this point, we already know that the opcode for N
/// matches, and the SDNode for the result has the RootName specified name.
@@ -1160,16 +1206,16 @@
unsigned PatternNo = PatternCount++;
OS << " { // Pattern #" << PatternNo << ": ";
Pattern.first->print(OS);
+ OS << "\n // Emits: ";
+ Pattern.second->print(OS);
OS << "\n";
+ OS << " // Pattern complexity = " << getPatternSize(Pattern.first)
+ << " cost = " << getResultPatternCost(Pattern.second) << "\n";
// Emit the matcher, capturing named arguments in VariableMap.
std::map<std::string,std::string> VariableMap;
EmitMatchForPattern(Pattern.first, "N", VariableMap, PatternNo, OS);
- OS << " // Emit: ";
- Pattern.second->print(OS);
- OS << "\n";
-
unsigned TmpNo = 0;
unsigned Res = CodeGenPatternResult(Pattern.second, TmpNo, VariableMap, OS);
@@ -1179,41 +1225,6 @@
OS << " }\n P" << PatternNo << "Fail:\n";
}
-/// getPatternSize - Return the 'size' of this pattern. We want to match large
-/// patterns before small ones. This is used to determine the size of a
-/// pattern.
-static unsigned getPatternSize(TreePatternNode *P) {
- assert(MVT::isInteger(P->getType()) || MVT::isFloatingPoint(P->getType()) &&
- "Not a valid pattern node to size!");
- unsigned Size = 1; // The node itself.
-
- // Count children in the count if they are also nodes.
- for (unsigned i = 0, e = P->getNumChildren(); i != e; ++i) {
- TreePatternNode *Child = P->getChild(i);
- if (!Child->isLeaf() && Child->getType() != MVT::Other)
- Size += getPatternSize(Child);
- }
-
- return Size;
-}
-
-// 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 PatternSortingPredicate {
- bool operator()(DAGISelEmitter::PatternToMatch *LHS,
- DAGISelEmitter::PatternToMatch *RHS) {
- unsigned LHSSize = getPatternSize(LHS->first);
- unsigned RHSSize = getPatternSize(RHS->first);
- if (LHSSize > RHSSize) return true; // LHS -> bigger -> less cost
- if (LHSSize < RHSSize) return false;
-
- // If they are equal, compare cost.
- // FIXME: Compute cost!
- return false;
- }
-};
-
namespace {
/// CompareByRecordName - An ordering predicate that implements less-than by
More information about the llvm-commits
mailing list