/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef LIBLLVMBACKEND_MIR_COMPILER_H #define LIBLLVMBACKEND_MIR_COMPILER_H #include #include #include #include #include "object_code/created_object_file.h" namespace panda::llvmbackend { class InsertingPassManager : public llvm::legacy::PassManager { public: void add(llvm::Pass *p) override; void InsertBefore(llvm::AnalysisID before, llvm::Pass *pass) { befores_[before] = pass; } private: std::unordered_map befores_; }; class MIRCompiler { public: using PassInserterFunction = std::function; explicit MIRCompiler( std::shared_ptr targetMachine, PassInserterFunction insertPasses, CreatedObjectFile::ObjectFilePostProcessor objectFilePostProcessor = [](llvm::object::ObjectFile *) {}) : targetMachine_(std::move(targetMachine)), insertPasses_(std::move(insertPasses)), objectFilePostProcessor_(std::move(objectFilePostProcessor)) { } llvm::Expected> CompileModule(llvm::Module &module); std::shared_ptr GetTargetMachine() { return targetMachine_; } private: std::shared_ptr targetMachine_; PassInserterFunction insertPasses_; CreatedObjectFile::ObjectFilePostProcessor objectFilePostProcessor_; }; } // namespace panda::llvmbackend #endif // LIBLLVMBACKEND_MIR_COMPILER_H