• 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 #include "mark_inline_module.h"
17 #include "llvm_ark_interface.h"
18 #include "llvm_compiler_options.h"
19 
20 #include <llvm/IR/Module.h>
21 #include <llvm/Support/Debug.h>
22 
23 #define DEBUG_TYPE "mark-inline-module"
24 
25 using llvm::GlobalObject;
26 
27 namespace ark::llvmbackend::passes {
28 
ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions * options)29 bool MarkInlineModule::ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options)
30 {
31     return options->doIrtocInline;
32 }
33 
34 /// Mark all functions and global variables from inline module with FUNCTION_MD_INLINE_MODULE metadata
run(llvm::Module & module,llvm::ModuleAnalysisManager &)35 llvm::PreservedAnalyses MarkInlineModule::run(llvm::Module &module, llvm::ModuleAnalysisManager & /*AM*/)
36 {
37     llvm::for_each(module.global_objects(), MarkInlineModule::Mark);
38     return module.global_objects().empty() ? llvm::PreservedAnalyses::all() : llvm::PreservedAnalyses::none();
39 }
40 
Mark(GlobalObject & object)41 void MarkInlineModule::Mark(GlobalObject &object)
42 {
43     LLVM_DEBUG(llvm::dbgs() << "Marked '" << object.getName() << "'\n");
44     object.addMetadata(LLVMArkInterface::FUNCTION_MD_INLINE_MODULE, *llvm::MDNode::get(object.getContext(), {}));
45 }
46 
47 }  // namespace ark::llvmbackend::passes
48