|
| 1 | +//===- PassManager.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 | +// Registers and executes the Sandbox IR passes. |
| 10 | +// |
| 11 | +// The pass manager contains an ordered sequence of passes that it runs in |
| 12 | +// order. The passes are owned by the PassRegistry, not by the PassManager. |
| 13 | +// |
| 14 | +// Note that in this design a pass manager is also a pass. So a pass manager |
| 15 | +// runs when it is it's turn to run in its parent pass-manager pass pipeline. |
| 16 | +// |
| 17 | + |
| 18 | +#ifndef LLVM_SANDBOXIR_PASSMANAGER_H |
| 19 | +#define LLVM_SANDBOXIR_PASSMANAGER_H |
| 20 | + |
| 21 | +#include "llvm/ADT/STLExtras.h" |
| 22 | +#include "llvm/SandboxIR/Pass.h" |
| 23 | +#include "llvm/Support/Debug.h" |
| 24 | + |
| 25 | +namespace llvm::sandboxir { |
| 26 | + |
| 27 | +class Value; |
| 28 | + |
| 29 | +/// Base class. |
| 30 | +template <typename ParentPass, typename ContainedPass> |
| 31 | +class PassManager : public ParentPass { |
| 32 | +protected: |
| 33 | + /// The list of passes that this pass manager will run. |
| 34 | + SmallVector<ContainedPass *> Passes; |
| 35 | + |
| 36 | + PassManager(StringRef Name) : ParentPass(Name) {} |
| 37 | + PassManager(const PassManager &) = delete; |
| 38 | + virtual ~PassManager() = default; |
| 39 | + PassManager &operator=(const PassManager &) = delete; |
| 40 | + |
| 41 | +public: |
| 42 | + /// Adds \p Pass to the pass pipeline. |
| 43 | + void addPass(ContainedPass *Pass) { |
| 44 | + // TODO: Check that Pass's class type works with this PassManager type. |
| 45 | + Passes.push_back(Pass); |
| 46 | + } |
| 47 | +#ifndef NDEBUG |
| 48 | + void print(raw_ostream &OS) const override { |
| 49 | + OS << this->getName(); |
| 50 | + OS << "("; |
| 51 | + interleave(Passes, OS, [&OS](auto *Pass) { OS << Pass->getName(); }, ","); |
| 52 | + OS << ")"; |
| 53 | + } |
| 54 | + LLVM_DUMP_METHOD void dump() const override { |
| 55 | + print(dbgs()); |
| 56 | + dbgs() << "\n"; |
| 57 | + } |
| 58 | +#endif |
| 59 | +}; |
| 60 | + |
| 61 | +class FunctionPassManager final |
| 62 | + : public PassManager<FunctionPass, FunctionPass> { |
| 63 | +public: |
| 64 | + FunctionPassManager(StringRef Name) : PassManager(Name) {} |
| 65 | + bool runOnFunction(Function &F) final; |
| 66 | +}; |
| 67 | + |
| 68 | +} // namespace llvm::sandboxir |
| 69 | + |
| 70 | +#endif // LLVM_SANDBOXIR_PASSMANAGER_H |
0 commit comments