From c7ef4cc9fcb5e91c0f402e9dc6c85f8357f2cbfc Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Fri, 12 Feb 2010 09:43:37 +0000 Subject: [PATCH] * Updated the cost matrix normalization proceedure to better handle infinite costs. * Enabled R1/R2 application for nodes with infinite spill costs in the Briggs heuristic (made safe by the changes to the normalization proceedure). * Removed a redundant header. llvm-svn: 95973 --- llvm/lib/CodeGen/PBQP/HeuristicSolver.h | 25 ++++++++++++++++++----- llvm/lib/CodeGen/PBQP/Heuristics/Briggs.h | 9 +------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/llvm/lib/CodeGen/PBQP/HeuristicSolver.h b/llvm/lib/CodeGen/PBQP/HeuristicSolver.h index b48f548950d9..c156264fae0f 100644 --- a/llvm/lib/CodeGen/PBQP/HeuristicSolver.h +++ b/llvm/lib/CodeGen/PBQP/HeuristicSolver.h @@ -18,7 +18,6 @@ #include "Graph.h" #include "Solution.h" -#include "llvm/Support/raw_ostream.h" #include #include @@ -494,14 +493,23 @@ namespace PBQP { bool tryNormaliseEdgeMatrix(Graph::EdgeItr &eItr) { + const PBQPNum infinity = std::numeric_limits::infinity(); + Matrix &edgeCosts = g.getEdgeCosts(eItr); Vector &uCosts = g.getNodeCosts(g.getEdgeNode1(eItr)), &vCosts = g.getNodeCosts(g.getEdgeNode2(eItr)); for (unsigned r = 0; r < edgeCosts.getRows(); ++r) { - PBQPNum rowMin = edgeCosts.getRowMin(r); + PBQPNum rowMin = infinity; + + for (unsigned c = 0; c < edgeCosts.getCols(); ++c) { + if (vCosts[c] != infinity && edgeCosts[r][c] < rowMin) + rowMin = edgeCosts[r][c]; + } + uCosts[r] += rowMin; - if (rowMin != std::numeric_limits::infinity()) { + + if (rowMin != infinity) { edgeCosts.subFromRow(r, rowMin); } else { @@ -510,9 +518,16 @@ namespace PBQP { } for (unsigned c = 0; c < edgeCosts.getCols(); ++c) { - PBQPNum colMin = edgeCosts.getColMin(c); + PBQPNum colMin = infinity; + + for (unsigned r = 0; r < edgeCosts.getRows(); ++r) { + if (uCosts[r] != infinity && edgeCosts[r][c] < colMin) + colMin = edgeCosts[r][c]; + } + vCosts[c] += colMin; - if (colMin != std::numeric_limits::infinity()) { + + if (colMin != infinity) { edgeCosts.subFromCol(c, colMin); } else { diff --git a/llvm/lib/CodeGen/PBQP/Heuristics/Briggs.h b/llvm/lib/CodeGen/PBQP/Heuristics/Briggs.h index c09ad74b198a..30d34d9e3e92 100644 --- a/llvm/lib/CodeGen/PBQP/Heuristics/Briggs.h +++ b/llvm/lib/CodeGen/PBQP/Heuristics/Briggs.h @@ -128,14 +128,7 @@ namespace PBQP { /// selected for heuristic reduction instead. bool shouldOptimallyReduce(Graph::NodeItr nItr) { if (getSolver().getSolverDegree(nItr) < 3) { - if (getGraph().getNodeCosts(nItr)[0] != - std::numeric_limits::infinity()) { - return true; - } - // Otherwise we have an infinite spill cost node. - initializeNode(nItr); - NodeData &nd = getHeuristicNodeData(nItr); - return nd.isAllocable; + return true; } // else return false;