10 #ifndef LLVM_CODEGEN_PBQP_HEURISTICBASE_H
11 #define LLVM_CODEGEN_PBQP_HEURISTICBASE_H
51 template <
typename HImpl>
55 typedef std::list<Graph::NodeId> OptimalList;
59 OptimalList optimalList;
62 HImpl& impl() {
return static_cast<HImpl&
>(*this); }
67 optimalList.insert(optimalList.end(), nId);
122 optimalList.push_back(nId);
134 nItr != nEnd; ++nItr) {
135 if (impl().shouldOptimallyReduce(*nItr)) {
138 impl().addToHeuristicReduceList(*nItr);
150 if (optimalList.empty())
154 optimalList.pop_front();
156 switch (s.getSolverDegree(nId)) {
157 case 0: s.applyR0(nId);
break;
158 case 1: s.applyR1(nId);
break;
159 case 2: s.applyR2(nId);
break;
161 "Optimal reductions of degree > 2 nodes is invalid.");
173 bool finished =
false;
239 assert(optimalList.empty() &&
"Nodes left over in optimal reduce list?");
247 #endif // LLVM_CODEGEN_PBQP_HEURISTICBASE_H
bool heuristicReduce()
Heuristically reduce one of the nodes in the heuristic reduce list.
void reduce()
Perform the PBQP reduction process.
NodeItr nodesEnd() const
End iterator for node set.
unsigned getNodeDegree(NodeId nId) const
Get a node's degree.
void postUpdateEdgeCostts(Graph::EdgeId eId)
Handle the change in the costs on the given edge.
HeuristicSolverImpl< HImpl > & getSolver()
Get the solver which is using this heuristic instance.
HeuristicBase(HeuristicSolverImpl< HImpl > &solver)
Construct an instance with a reference to the given solver.
void handleAddEdge(Graph::EdgeId eId)
Handle the addition of a new edge into the PBQP graph.
Abstract base class for heuristic implementations.
void handleRemoveEdge(Graph::EdgeId eId, Graph::NodeId nId)
Handle disconnection of an edge from a node.
#define llvm_unreachable(msg)
bool solverRunSimplify() const
Tell the solver to simplify the graph before the reduction phase.
void cleanup()
Clean up any structures used by HeuristicBase.
Graph & getGraph()
Get the graph representing the problem to be solved.
void addToHeuristicList(Graph::NodeId nId)
Add a node to the heuristic reduce list.
void preUpdateEdgeCosts(Graph::EdgeId eId)
Prepare a change in the costs on the given edge.
void setup()
Initialise the heuristic.
Heuristic PBQP solver implementation.
bool optimalReduce()
Optimally reduce one of the nodes in the optimal reduce list.
NodeItr nodesBegin() const
Begin iterator for node set.
void addToOptimalReduceList(Graph::NodeId nId)
Add the given node to the list of nodes to be optimally reduced.
bool shouldOptimallyReduce(Graph::NodeId nId)
Decide whether a node should be optimally or heuristically reduced.