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