From 5941320c0d89711571b87c486b5c50a7c70a8130 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 19 Apr 2006 18:07:24 +0000 Subject: [PATCH] Allow "let AddedCost = n in" to increase pattern complexity. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27834 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Target.td | 3 +++ lib/Target/TargetSelectionDAG.td | 3 ++- utils/TableGen/DAGISelEmitter.cpp | 21 ++++++++++++++++----- utils/TableGen/DAGISelEmitter.h | 7 +++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/Target/Target.td b/lib/Target/Target.td index 4c846741cae..4d6c80cf97f 100644 --- a/lib/Target/Target.td +++ b/lib/Target/Target.td @@ -144,6 +144,9 @@ class Instruction { // code. list Predicates = []; + // Added cost passed onto matching pattern. + int AddedCost = 0; + // These bits capture information about the high-level semantics of the // instruction. bit isReturn = 0; // Is this instruction a return instruction? diff --git a/lib/Target/TargetSelectionDAG.td b/lib/Target/TargetSelectionDAG.td index 40a4a97d077..38613c41882 100644 --- a/lib/Target/TargetSelectionDAG.td +++ b/lib/Target/TargetSelectionDAG.td @@ -313,7 +313,7 @@ def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>, def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTypeProfile<1, 2, []>, []>; def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT", - SDTypeProfile<1, 3, []>, []>; + SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>]>, []>; // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use // these internally. Don't reference these directly. @@ -473,6 +473,7 @@ class Pattern resultInstrs> { dag PatternToMatch = patternToMatch; list ResultInstrs = resultInstrs; list Predicates = []; // See class Instruction in Target.td. + int AddedCost = 0; // See class Instruction in Target.td. } // Pat - A simple (but common) form of a pattern, which produces a simple result diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 7a6097fa370..8d5186f2111 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -1504,7 +1504,8 @@ void DAGISelEmitter::ParseInstructions() { TreePatternNode *DstPattern = TheInst.getResultPattern(); PatternsToMatch. push_back(PatternToMatch(Instr->getValueAsListInit("Predicates"), - SrcPattern, DstPattern)); + SrcPattern, DstPattern, + Instr->getValueAsInt("AddedCost"))); } } @@ -1580,7 +1581,8 @@ void DAGISelEmitter::ParsePatterns() { PatternsToMatch. push_back(PatternToMatch(Patterns[i]->getValueAsListInit("Predicates"), Pattern->getOnlyTree(), - Temp.getOnlyTree())); + Temp.getOnlyTree(), + Patterns[i]->getValueAsInt("AddedCost"))); } } @@ -1823,7 +1825,8 @@ void DAGISelEmitter::GenerateVariants() { // Otherwise, add it to the list of patterns we have. PatternsToMatch. push_back(PatternToMatch(PatternsToMatch[i].getPredicates(), - Variant, PatternsToMatch[i].getDstPattern())); + Variant, PatternsToMatch[i].getDstPattern(), + PatternsToMatch[i].getAddedCost())); } DEBUG(std::cerr << "\n"); @@ -1933,6 +1936,8 @@ struct PatternSortingPredicate { PatternToMatch *RHS) { unsigned LHSSize = getPatternSize(LHS->getSrcPattern(), ISE); unsigned RHSSize = getPatternSize(RHS->getSrcPattern(), ISE); + LHSSize += LHS->getAddedCost(); + RHSSize += RHS->getAddedCost(); if (LHSSize > RHSSize) return true; // LHS -> bigger -> less cost if (LHSSize < RHSSize) return false; @@ -2003,6 +2008,8 @@ private: // Predicates. ListInit *Predicates; + // Pattern cost. + unsigned Cost; // Instruction selector pattern. TreePatternNode *Pattern; // Matched instruction. @@ -2939,8 +2946,10 @@ void DAGISelEmitter::EmitPatterns(std::vectorprint(OS); OS << "\n"; + unsigned AddedCost = Pattern.getAddedCost(); OS << std::string(Indent, ' ') << "// Pattern complexity = " - << getPatternSize(Pattern.getSrcPattern(), *this) << " cost = " + << getPatternSize(Pattern.getSrcPattern(), *this) + AddedCost + << " cost = " << getResultPatternCost(Pattern.getDstPattern(), *this) << "\n"; } if (!FirstCodeLine.first) { @@ -2960,8 +2969,10 @@ void DAGISelEmitter::EmitPatterns(std::vectorprint(OS); OS << "\n"; + unsigned AddedCost = Pattern.getAddedCost(); OS << std::string(Indent, ' ') << "// Pattern complexity = " - << getPatternSize(Pattern.getSrcPattern(), *this) << " cost = " + << getPatternSize(Pattern.getSrcPattern(), *this) + AddedCost + << " cost = " << getResultPatternCost(Pattern.getDstPattern(), *this) << "\n"; } EmitPatterns(Other, Indent, OS); diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h index 8ed66be800a..c0e984a527f 100644 --- a/utils/TableGen/DAGISelEmitter.h +++ b/utils/TableGen/DAGISelEmitter.h @@ -394,16 +394,19 @@ namespace llvm { /// PatternToMatch - Used by DAGISelEmitter to keep tab of patterns processed /// to produce isel. struct PatternToMatch { - PatternToMatch(ListInit *preds, TreePatternNode *src, TreePatternNode *dst): - Predicates(preds), SrcPattern(src), DstPattern(dst) {}; + PatternToMatch(ListInit *preds, + TreePatternNode *src, TreePatternNode *dst, unsigned cost): + Predicates(preds), SrcPattern(src), DstPattern(dst), AddedCost(cost) {}; ListInit *Predicates; // Top level predicate conditions to match. TreePatternNode *SrcPattern; // Source pattern to match. TreePatternNode *DstPattern; // Resulting pattern. + unsigned AddedCost; // Add to matching pattern complexity. ListInit *getPredicates() const { return Predicates; } TreePatternNode *getSrcPattern() const { return SrcPattern; } TreePatternNode *getDstPattern() const { return DstPattern; } + unsigned getAddedCost() const { return AddedCost; } }; /// DAGISelEmitter - The top-level class which coordinates construction -- 2.34.1