• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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_ARK_INLINING_H
17 #define LIBLLVMBACKEND_TRANSFORMS_PASSES_ARK_INLINING_H
18 
19 #include <llvm/Transforms/IPO/Inliner.h>
20 #include <llvm/Target/TargetMachine.h>
21 #include <llvm/IR/PassManager.h>
22 
23 namespace ark::llvmbackend {
24 struct LLVMCompilerOptions;
25 }  // namespace ark::llvmbackend
26 
27 namespace ark::llvmbackend {
28 class LLVMArkInterface;
29 }  // namespace ark::llvmbackend
30 
31 namespace ark::llvmbackend::passes {
32 
33 class IrtocInlineChecker : public llvm::PassInfoMixin<IrtocInlineChecker> {
34 public:
35     static constexpr llvm::StringRef ARG_NAME = "irtoc-inline-check";
36 
37     static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options);
38     void CheckShouldInline(llvm::CallBase *callBase);
39 
40     // NOLINTNEXTLINE(readability-identifier-naming)
41     llvm::PreservedAnalyses run(llvm::LazyCallGraph::SCC &component, llvm::CGSCCAnalysisManager & /*unused*/,
42                                 llvm::LazyCallGraph & /*unused*/, llvm::CGSCCUpdateResult & /*unused*/);
43 };
44 
45 class InlinePrepare : public llvm::PassInfoMixin<InlinePrepare> {
46     llvm::InlineParams inlineParams_;
47 
48 public:
49     static constexpr llvm::StringRef ARG_NAME = "inline-prepare";
50 
InlinePrepare(llvm::InlineParams inlineParams)51     explicit InlinePrepare(llvm::InlineParams inlineParams) : inlineParams_ {inlineParams} {}
52     static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options);
53     static InlinePrepare Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options);
54 
55     // NOLINTNEXTLINE(readability-identifier-naming)
56     llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &moduleAm);
57 };
58 
59 }  // namespace ark::llvmbackend::passes
60 
61 #endif  // LIBLLVMBACKEND_TRANSFORMS_PASSES_ARK_INLINING_H
62