1 //===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // PBQP Solution class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
15 #define LLVM_CODEGEN_PBQP_SOLUTION_H
24 /// \brief Represents a solution to a PBQP problem.
26 /// To get the selection for each node in the problem use the getSelection method.
30 typedef std::map<GraphBase::NodeId, unsigned> SelectionsMap;
31 SelectionsMap selections;
33 unsigned r0Reductions, r1Reductions, r2Reductions, rNReductions;
37 /// \brief Initialise an empty solution.
39 : r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}
41 /// \brief Number of nodes for which selections have been made.
42 /// @return Number of nodes for which selections have been made.
43 unsigned numNodes() const { return selections.size(); }
45 /// \brief Records a reduction via the R0 rule. Should be called from the
47 void recordR0() { ++r0Reductions; }
49 /// \brief Returns the number of R0 reductions applied to solve the problem.
50 unsigned numR0Reductions() const { return r0Reductions; }
52 /// \brief Records a reduction via the R1 rule. Should be called from the
54 void recordR1() { ++r1Reductions; }
56 /// \brief Returns the number of R1 reductions applied to solve the problem.
57 unsigned numR1Reductions() const { return r1Reductions; }
59 /// \brief Records a reduction via the R2 rule. Should be called from the
61 void recordR2() { ++r2Reductions; }
63 /// \brief Returns the number of R2 reductions applied to solve the problem.
64 unsigned numR2Reductions() const { return r2Reductions; }
66 /// \brief Records a reduction via the RN rule. Should be called from the
68 void recordRN() { ++ rNReductions; }
70 /// \brief Returns the number of RN reductions applied to solve the problem.
71 unsigned numRNReductions() const { return rNReductions; }
73 /// \brief Set the selection for a given node.
74 /// @param nodeId Node id.
75 /// @param selection Selection for nodeId.
76 void setSelection(GraphBase::NodeId nodeId, unsigned selection) {
77 selections[nodeId] = selection;
80 /// \brief Get a node's selection.
81 /// @param nodeId Node id.
82 /// @return The selection for nodeId;
83 unsigned getSelection(GraphBase::NodeId nodeId) const {
84 SelectionsMap::const_iterator sItr = selections.find(nodeId);
85 assert(sItr != selections.end() && "No selection for node.");
94 #endif // LLVM_CODEGEN_PBQP_SOLUTION_H