blob: 6a247277fdfab67d420f13de7e11aab77fa5c5ef [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- 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 "llvm/CodeGen/PBQP/Graph.h"
18#include <cassert>
19#include <map>
20
21namespace llvm {
22namespace PBQP {
23
24 /// \brief Represents a solution to a PBQP problem.
25 ///
26 /// To get the selection for each node in the problem use the getSelection method.
27 class Solution {
28 private:
29 using SelectionsMap = std::map<GraphBase::NodeId, unsigned>;
30 SelectionsMap selections;
31
32 public:
33 /// \brief Initialise an empty solution.
34 Solution() = default;
35
36 /// \brief Set the selection for a given node.
37 /// @param nodeId Node id.
38 /// @param selection Selection for nodeId.
39 void setSelection(GraphBase::NodeId nodeId, unsigned selection) {
40 selections[nodeId] = selection;
41 }
42
43 /// \brief Get a node's selection.
44 /// @param nodeId Node id.
45 /// @return The selection for nodeId;
46 unsigned getSelection(GraphBase::NodeId nodeId) const {
47 SelectionsMap::const_iterator sItr = selections.find(nodeId);
48 assert(sItr != selections.end() && "No selection for node.");
49 return sItr->second;
50 }
51 };
52
53} // end namespace PBQP
54} // end namespace llvm
55
56#endif // LLVM_CODEGEN_PBQP_SOLUTION_H