1 /** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LIBLLVMBACKEND_TRANSFORMS_PASSES_INLINEDEVIRT_PASS_H 17 #define LIBLLVMBACKEND_TRANSFORMS_PASSES_INLINEDEVIRT_PASS_H 18 19 #include "llvm_ark_interface.h" 20 #include "transforms/passes/devirt.h" 21 #include "transforms/passes/check_external.h" 22 23 #include <llvm/Transforms/IPO/Inliner.h> 24 25 namespace ark::llvmbackend::passes { 26 27 class InlineDevirt : public llvm::PassInfoMixin<InlineDevirt> { 28 public: 29 explicit InlineDevirt(LLVMArkInterface *arkInterface = nullptr, bool doVirtualInline = true); 30 31 static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); 32 33 static InlineDevirt Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options); 34 35 // NOLINTNEXTLINE(readability-identifier-naming) 36 llvm::PreservedAnalyses run(llvm::LazyCallGraph::SCC &initialSCC, llvm::CGSCCAnalysisManager &analysisManager, 37 llvm::LazyCallGraph &callGraph, llvm::CGSCCUpdateResult &updateResult); 38 39 private: 40 LLVMArkInterface *arkInterface_; 41 bool doVirtualInline_; 42 llvm::FunctionAnalysisManager *functionAnalysisManager_ {nullptr}; 43 llvm::LazyCallGraph::SCC *currentSCC_ {nullptr}; 44 llvm::PassInstrumentation *passInstrumentation_ {nullptr}; 45 llvm::CGSCCAnalysisManager *analysisManager_ {nullptr}; 46 llvm::CGSCCUpdateResult *updateResult_ {nullptr}; 47 llvm::LazyCallGraph *callGraph_ {nullptr}; 48 llvm::PreservedAnalyses preservedAnalyses_; 49 50 public: 51 static constexpr llvm::StringRef ARG_NAME = "inline-devirt"; 52 53 private: 54 bool RunInlining(llvm::InlinerPass &inlinePass, llvm::SmallPtrSetImpl<llvm::Function *> &changedFunctions); 55 bool RunDevirt(ark::llvmbackend::passes::Devirt &devirtPass); 56 void RunCheckExternal(ark::llvmbackend::passes::CheckExternal &externalPass); 57 }; 58 59 } // namespace ark::llvmbackend::passes 60 61 #endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_INLINEDEVIRT_PASS_H 62