Home | History | Annotate | Download | only in Core
      1 //===- lld/Core/PassManager.h - Manage linker passes ----------------------===//
      2 //
      3 //                             The LLVM Linker
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef LLD_CORE_PASS_MANAGER_H
     11 #define LLD_CORE_PASS_MANAGER_H
     12 
     13 #include "lld/Common/LLVM.h"
     14 #include "lld/Core/Pass.h"
     15 #include "llvm/Support/Error.h"
     16 #include <memory>
     17 #include <vector>
     18 
     19 namespace lld {
     20 class SimpleFile;
     21 class Pass;
     22 
     23 /// \brief Owns and runs a collection of passes.
     24 ///
     25 /// This class is currently just a container for passes and a way to run them.
     26 ///
     27 /// In the future this should handle timing pass runs, running parallel passes,
     28 /// and validate/satisfy pass dependencies.
     29 class PassManager {
     30 public:
     31   void add(std::unique_ptr<Pass> pass) {
     32     _passes.push_back(std::move(pass));
     33   }
     34 
     35   llvm::Error runOnFile(SimpleFile &file) {
     36     for (std::unique_ptr<Pass> &pass : _passes)
     37       if (llvm::Error EC = pass->perform(file))
     38         return EC;
     39     return llvm::Error::success();
     40   }
     41 
     42 private:
     43   /// \brief Passes in the order they should run.
     44   std::vector<std::unique_ptr<Pass>> _passes;
     45 };
     46 } // end namespace lld
     47 
     48 #endif
     49