blob: d5b1474f0f4c7ea564b63ddc49a88ad76d8cd059 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- Solution.h - PBQP Solution -------------------------------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8//
9// PBQP Solution class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
14#define LLVM_CODEGEN_PBQP_SOLUTION_H
15
16#include "llvm/CodeGen/PBQP/Graph.h"
17#include <cassert>
18#include <map>
19
20namespace llvm {
21namespace PBQP {
22
Andrew Scullcdfcccc2018-10-05 20:58:37 +010023 /// Represents a solution to a PBQP problem.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010024 ///
25 /// To get the selection for each node in the problem use the getSelection method.
26 class Solution {
27 private:
28 using SelectionsMap = std::map<GraphBase::NodeId, unsigned>;
29 SelectionsMap selections;
30
31 public:
Andrew Scullcdfcccc2018-10-05 20:58:37 +010032 /// Initialise an empty solution.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010033 Solution() = default;
34
Andrew Scullcdfcccc2018-10-05 20:58:37 +010035 /// Set the selection for a given node.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010036 /// @param nodeId Node id.
37 /// @param selection Selection for nodeId.
38 void setSelection(GraphBase::NodeId nodeId, unsigned selection) {
39 selections[nodeId] = selection;
40 }
41
Andrew Scullcdfcccc2018-10-05 20:58:37 +010042 /// Get a node's selection.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010043 /// @param nodeId Node id.
44 /// @return The selection for nodeId;
45 unsigned getSelection(GraphBase::NodeId nodeId) const {
46 SelectionsMap::const_iterator sItr = selections.find(nodeId);
47 assert(sItr != selections.end() && "No selection for node.");
48 return sItr->second;
49 }
50 };
51
52} // end namespace PBQP
53} // end namespace llvm
54
55#endif // LLVM_CODEGEN_PBQP_SOLUTION_H