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 | |
15 | #ifndef LLVM_CODEGEN_PBQPRACONSTRAINT_H |
16 | #define LLVM_CODEGEN_PBQPRACONSTRAINT_H |
17 | |
18 | #include "llvm/Support/Compiler.h" |
19 | #include <algorithm> |
20 | #include <memory> |
21 | #include <vector> |
22 | |
23 | namespace llvm { |
24 | |
25 | namespace PBQP { |
26 | namespace RegAlloc { |
27 | |
28 | // Forward declare PBQP graph class. |
29 | class PBQPRAGraph; |
30 | |
31 | } // end namespace RegAlloc |
32 | } // end namespace PBQP |
33 | |
34 | using PBQPRAGraph = PBQP::RegAlloc::PBQPRAGraph; |
35 | |
36 | /// Abstract base for classes implementing PBQP register allocation |
37 | /// constraints (e.g. Spill-costs, interference, coalescing). |
38 | class LLVM_ABI PBQPRAConstraint { |
39 | public: |
40 | virtual ~PBQPRAConstraint() = 0; |
41 | virtual void apply(PBQPRAGraph &G) = 0; |
42 | |
43 | private: |
44 | virtual void anchor(); |
45 | }; |
46 | |
47 | /// PBQP register allocation constraint composer. |
48 | /// |
49 | /// Constraints added to this list will be applied, in the order that they are |
50 | /// added, to the PBQP graph. |
51 | class LLVM_ABI PBQPRAConstraintList : public PBQPRAConstraint { |
52 | public: |
53 | // Explicitly non-copyable. |
54 | PBQPRAConstraintList() = default; |
55 | PBQPRAConstraintList &operator=(const PBQPRAConstraintList &) = delete; |
56 | PBQPRAConstraintList(const PBQPRAConstraintList &) = delete; |
57 | |
58 | void apply(PBQPRAGraph &G) override { |
59 | for (auto &C : Constraints) |
60 | C->apply(G); |
61 | } |
62 | |
63 | void addConstraint(std::unique_ptr<PBQPRAConstraint> C) { |
64 | if (C) |
65 | Constraints.push_back(x: std::move(C)); |
66 | } |
67 | |
68 | private: |
69 | std::vector<std::unique_ptr<PBQPRAConstraint>> Constraints; |
70 | |
71 | void anchor() override; |
72 | }; |
73 | |
74 | } // end namespace llvm |
75 | |
76 | #endif // LLVM_CODEGEN_PBQPRACONSTRAINT_H |
77 | |