PBQPRAConstraint.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/CodeGen/PBQPRAConstraint.h --------------------------*- 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. // This file defines the PBQPBuilder interface, for classes which build PBQP
  15. // instances to represent register allocation problems, and the RegAllocPBQP
  16. // interface.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CODEGEN_PBQPRACONSTRAINT_H
  20. #define LLVM_CODEGEN_PBQPRACONSTRAINT_H
  21. #include <algorithm>
  22. #include <memory>
  23. #include <vector>
  24. namespace llvm {
  25. namespace PBQP {
  26. namespace RegAlloc {
  27. // Forward declare PBQP graph class.
  28. class PBQPRAGraph;
  29. } // end namespace RegAlloc
  30. } // end namespace PBQP
  31. using PBQPRAGraph = PBQP::RegAlloc::PBQPRAGraph;
  32. /// Abstract base for classes implementing PBQP register allocation
  33. /// constraints (e.g. Spill-costs, interference, coalescing).
  34. class PBQPRAConstraint {
  35. public:
  36. virtual ~PBQPRAConstraint() = 0;
  37. virtual void apply(PBQPRAGraph &G) = 0;
  38. private:
  39. virtual void anchor();
  40. };
  41. /// PBQP register allocation constraint composer.
  42. ///
  43. /// Constraints added to this list will be applied, in the order that they are
  44. /// added, to the PBQP graph.
  45. class PBQPRAConstraintList : public PBQPRAConstraint {
  46. public:
  47. void apply(PBQPRAGraph &G) override {
  48. for (auto &C : Constraints)
  49. C->apply(G);
  50. }
  51. void addConstraint(std::unique_ptr<PBQPRAConstraint> C) {
  52. if (C)
  53. Constraints.push_back(std::move(C));
  54. }
  55. private:
  56. std::vector<std::unique_ptr<PBQPRAConstraint>> Constraints;
  57. void anchor() override;
  58. };
  59. } // end namespace llvm
  60. #endif // LLVM_CODEGEN_PBQPRACONSTRAINT_H
  61. #ifdef __GNUC__
  62. #pragma GCC diagnostic pop
  63. #endif