]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/include/llvm/CodeGen/PBQP/Solution.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / include / llvm / CodeGen / PBQP / Solution.h
1 //===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // PBQP Solution class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
15 #define LLVM_CODEGEN_PBQP_SOLUTION_H
16
17 #include "Graph.h"
18 #include "Math.h"
19 #include <map>
20
21 namespace PBQP {
22
23   /// \brief Represents a solution to a PBQP problem.
24   ///
25   /// To get the selection for each node in the problem use the getSelection method.
26   class Solution {
27   private:
28
29     typedef std::map<Graph::ConstNodeItr, unsigned,
30                      NodeItrComparator> SelectionsMap;
31     SelectionsMap selections;
32
33     unsigned r0Reductions, r1Reductions, r2Reductions, rNReductions;
34
35   public:
36
37     /// \brief Initialise an empty solution.
38     Solution()
39       : r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}
40
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(); }
44
45     /// \brief Records a reduction via the R0 rule. Should be called from the
46     ///        solver only.
47     void recordR0() { ++r0Reductions; }
48
49     /// \brief Returns the number of R0 reductions applied to solve the problem.
50     unsigned numR0Reductions() const { return r0Reductions; }
51
52     /// \brief Records a reduction via the R1 rule. Should be called from the
53     ///        solver only.
54     void recordR1() { ++r1Reductions; }
55
56     /// \brief Returns the number of R1 reductions applied to solve the problem.
57     unsigned numR1Reductions() const { return r1Reductions; }
58
59     /// \brief Records a reduction via the R2 rule. Should be called from the
60     ///        solver only.
61     void recordR2() { ++r2Reductions; }
62
63     /// \brief Returns the number of R2 reductions applied to solve the problem.
64     unsigned numR2Reductions() const { return r2Reductions; }
65
66     /// \brief Records a reduction via the RN rule. Should be called from the
67     ///        solver only.
68     void recordRN() { ++ rNReductions; }
69
70     /// \brief Returns the number of RN reductions applied to solve the problem.
71     unsigned numRNReductions() const { return rNReductions; }
72
73     /// \brief Set the selection for a given node.
74     /// @param nItr Node iterator.
75     /// @param selection Selection for nItr.
76     void setSelection(Graph::NodeItr nItr, unsigned selection) {
77       selections[nItr] = selection;
78     }
79
80     /// \brief Get a node's selection.
81     /// @param nItr Node iterator.
82     /// @return The selection for nItr;
83     unsigned getSelection(Graph::ConstNodeItr nItr) const {
84       SelectionsMap::const_iterator sItr = selections.find(nItr);
85       assert(sItr != selections.end() && "No selection for node.");
86       return sItr->second;
87     }
88
89   };
90
91 }
92
93 #endif // LLVM_CODEGEN_PBQP_SOLUTION_H