Solution.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- Solution.h - PBQP Solution -------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // PBQP Solution class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
  18. #define LLVM_CODEGEN_PBQP_SOLUTION_H
  19. #include "llvm/CodeGen/PBQP/Graph.h"
  20. #include <cassert>
  21. #include <map>
  22. namespace llvm {
  23. namespace PBQP {
  24. /// 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. public:
  32. /// Initialise an empty solution.
  33. Solution() = default;
  34. /// Set the selection for a given node.
  35. /// @param nodeId Node id.
  36. /// @param selection Selection for nodeId.
  37. void setSelection(GraphBase::NodeId nodeId, unsigned selection) {
  38. selections[nodeId] = selection;
  39. }
  40. /// Get a node's selection.
  41. /// @param nodeId Node id.
  42. /// @return The selection for nodeId;
  43. unsigned getSelection(GraphBase::NodeId nodeId) const {
  44. SelectionsMap::const_iterator sItr = selections.find(nodeId);
  45. assert(sItr != selections.end() && "No selection for node.");
  46. return sItr->second;
  47. }
  48. };
  49. } // end namespace PBQP
  50. } // end namespace llvm
  51. #endif // LLVM_CODEGEN_PBQP_SOLUTION_H
  52. #ifdef __GNUC__
  53. #pragma GCC diagnostic pop
  54. #endif