PBQPRAConstraint.h 1.8 KB

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