blob: 4d4379fbc2c2178d83eead0d091d71df28527ce1 [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
Andrew Scullcdfcccc2018-10-05 20:58:37 +010024 /// Represents a solution to a PBQP problem.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010025 ///
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:
Andrew Scullcdfcccc2018-10-05 20:58:37 +010033 /// Initialise an empty solution.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010034 Solution() = default;
35
Andrew Scullcdfcccc2018-10-05 20:58:37 +010036 /// Set the selection for a given node.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010037 /// @param nodeId Node id.
38 /// @param selection Selection for nodeId.
39 void setSelection(GraphBase::NodeId nodeId, unsigned selection) {
40 selections[nodeId] = selection;
41 }
42
Andrew Scullcdfcccc2018-10-05 20:58:37 +010043 /// Get a node's selection.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010044 /// @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