From e6f32034dbacf1a71e78b69391fb0dc4aeba9902 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 19 Jul 2006 00:24:41 +0000 Subject: [PATCH] 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 --- lib/Target/Target.td | 3 +++ utils/TableGen/DAGISelEmitter.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/Target/Target.td b/lib/Target/Target.td index 3e7665fd2e9..75d3d7b4f82 100644 --- a/lib/Target/Target.td +++ b/lib/Target/Target.td @@ -147,6 +147,9 @@ class Instruction { // code. list Predicates = []; + // Code size. + int CodeSize = 0; + // Added complexity passed onto matching pattern. int AddedComplexity = 0; diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index a28b62eaf34..9f1913798d8 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -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