• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_LLVM_COMPILER_H
17 #define LIBLLVMBACKEND_LLVM_COMPILER_H
18 
19 #include "compiler_interface.h"
20 #include "mir_compiler.h"
21 #include "llvm_compiler_options.h"
22 #include "transforms/llvm_optimizer.h"
23 
24 #include <llvm/ADT/Triple.h>
25 #include <llvm/IR/LLVMContext.h>
26 #include <llvm/Support/CommandLine.h>
27 
28 namespace panda::llvmbackend {
29 
30 class LLVMCompiler : public CompilerInterface {
31 public:
32     explicit LLVMCompiler(Arch arch);
33 
GetArch()34     Arch GetArch() const
35     {
36         return arch_;
37     }
38 
39 protected:
40     panda::llvmbackend::LLVMCompilerOptions InitializeLLVMCompilerOptions();
41     void InitializeDefaultLLVMOptions();
42     void InitializeLLVMOptions();
43 
44     template <typename T>
45     static void SetLLVMOption(const char *option, T val);
46 
47     static llvm::Triple GetTripleForArch(Arch arch);
48     static std::string GetCPUForArch(Arch arch);
49 
50     static void InitializeLLVMTarget(Arch arch);
51     static void InitializeLLVMPasses();
52 
GetLLVMContext()53     llvm::LLVMContext *GetLLVMContext()
54     {
55         return &context_;
56     }
57 
58 protected:
59     // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes)
60     std::shared_ptr<llvm::TargetMachine> targetMachine_;
61 
62 private:
63     Arch arch_;
64     llvm::LLVMContext context_;
65 };
66 }  // namespace panda::llvmbackend
67 #endif  // LIBLLVMBACKEND_LLVM_COMPILER_H
68