LLVM API Documentation
00001 //===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // PBQP Solution class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H 00015 #define LLVM_CODEGEN_PBQP_SOLUTION_H 00016 00017 #include "Graph.h" 00018 #include "Math.h" 00019 #include <map> 00020 00021 namespace PBQP { 00022 00023 /// \brief Represents a solution to a PBQP problem. 00024 /// 00025 /// To get the selection for each node in the problem use the getSelection method. 00026 class Solution { 00027 private: 00028 00029 typedef std::map<Graph::ConstNodeItr, unsigned, 00030 NodeItrComparator> SelectionsMap; 00031 SelectionsMap selections; 00032 00033 unsigned r0Reductions, r1Reductions, r2Reductions, rNReductions; 00034 00035 public: 00036 00037 /// \brief Initialise an empty solution. 00038 Solution() 00039 : r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {} 00040 00041 /// \brief Number of nodes for which selections have been made. 00042 /// @return Number of nodes for which selections have been made. 00043 unsigned numNodes() const { return selections.size(); } 00044 00045 /// \brief Records a reduction via the R0 rule. Should be called from the 00046 /// solver only. 00047 void recordR0() { ++r0Reductions; } 00048 00049 /// \brief Returns the number of R0 reductions applied to solve the problem. 00050 unsigned numR0Reductions() const { return r0Reductions; } 00051 00052 /// \brief Records a reduction via the R1 rule. Should be called from the 00053 /// solver only. 00054 void recordR1() { ++r1Reductions; } 00055 00056 /// \brief Returns the number of R1 reductions applied to solve the problem. 00057 unsigned numR1Reductions() const { return r1Reductions; } 00058 00059 /// \brief Records a reduction via the R2 rule. Should be called from the 00060 /// solver only. 00061 void recordR2() { ++r2Reductions; } 00062 00063 /// \brief Returns the number of R2 reductions applied to solve the problem. 00064 unsigned numR2Reductions() const { return r2Reductions; } 00065 00066 /// \brief Records a reduction via the RN rule. Should be called from the 00067 /// solver only. 00068 void recordRN() { ++ rNReductions; } 00069 00070 /// \brief Returns the number of RN reductions applied to solve the problem. 00071 unsigned numRNReductions() const { return rNReductions; } 00072 00073 /// \brief Set the selection for a given node. 00074 /// @param nItr Node iterator. 00075 /// @param selection Selection for nItr. 00076 void setSelection(Graph::NodeItr nItr, unsigned selection) { 00077 selections[nItr] = selection; 00078 } 00079 00080 /// \brief Get a node's selection. 00081 /// @param nItr Node iterator. 00082 /// @return The selection for nItr; 00083 unsigned getSelection(Graph::ConstNodeItr nItr) const { 00084 SelectionsMap::const_iterator sItr = selections.find(nItr); 00085 assert(sItr != selections.end() && "No selection for node."); 00086 return sItr->second; 00087 } 00088 00089 }; 00090 00091 } 00092 00093 #endif // LLVM_CODEGEN_PBQP_SOLUTION_H