1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_DEX_FRONTEND_H_
18#define ART_COMPILER_DEX_FRONTEND_H_
19
20#include "dex_file.h"
21#include "invoke_type.h"
22
23namespace llvm {
24  class Module;
25  class LLVMContext;
26}
27
28namespace art {
29namespace llvm {
30  class IntrinsicHelper;
31  class IRBuilder;
32}
33
34/*
35 * Assembly is an iterative process, and usually terminates within
36 * two or three passes.  This should be high enough to handle bizarre
37 * cases, but detect an infinite loop bug.
38 */
39#define MAX_ASSEMBLER_RETRIES 50
40
41// Suppress optimization if corresponding bit set.
42enum opt_control_vector {
43  kLoadStoreElimination = 0,
44  kLoadHoisting,
45  kSuppressLoads,
46  kNullCheckElimination,
47  kClassInitCheckElimination,
48  kGlobalValueNumbering,
49  kPromoteRegs,
50  kTrackLiveTemps,
51  kSafeOptimizations,
52  kBBOpt,
53  kMatch,
54  kPromoteCompilerTemps,
55  kBranchFusing,
56  kSuppressExceptionEdges,
57  kSuppressMethodInlining,
58};
59
60// Force code generation paths for testing.
61enum debugControlVector {
62  kDebugVerbose,
63  kDebugDumpCFG,
64  kDebugSlowFieldPath,
65  kDebugSlowInvokePath,
66  kDebugSlowStringPath,
67  kDebugSlowTypePath,
68  kDebugSlowestFieldPath,
69  kDebugSlowestStringPath,
70  kDebugExerciseResolveMethod,
71  kDebugVerifyDataflow,
72  kDebugShowMemoryUsage,
73  kDebugShowNops,
74  kDebugCountOpcodes,
75  kDebugDumpCheckStats,
76  kDebugDumpBitcodeFile,
77  kDebugVerifyBitcode,
78  kDebugShowSummaryMemoryUsage,
79  kDebugShowFilterStats,
80  kDebugTimings,
81  kDebugCodegenDump
82};
83
84class LLVMInfo {
85  public:
86    LLVMInfo();
87    ~LLVMInfo();
88
89    ::llvm::LLVMContext* GetLLVMContext() {
90      return llvm_context_.get();
91    }
92
93    ::llvm::Module* GetLLVMModule() {
94      return llvm_module_;
95    }
96
97    art::llvm::IntrinsicHelper* GetIntrinsicHelper() {
98      return intrinsic_helper_.get();
99    }
100
101    art::llvm::IRBuilder* GetIRBuilder() {
102      return ir_builder_.get();
103    }
104
105  private:
106    std::unique_ptr< ::llvm::LLVMContext> llvm_context_;
107    ::llvm::Module* llvm_module_;  // Managed by context_.
108    std::unique_ptr<art::llvm::IntrinsicHelper> intrinsic_helper_;
109    std::unique_ptr<art::llvm::IRBuilder> ir_builder_;
110};
111
112class CompiledMethod;
113class CompilerDriver;
114
115}  // namespace art
116
117extern "C" art::CompiledMethod* ArtCompileMethod(art::CompilerDriver& driver,
118                                                 const art::DexFile::CodeItem* code_item,
119                                                 uint32_t access_flags,
120                                                 art::InvokeType invoke_type,
121                                                 uint16_t class_def_idx,
122                                                 uint32_t method_idx,
123                                                 jobject class_loader,
124                                                 const art::DexFile& dex_file);
125
126
127
128#endif  // ART_COMPILER_DEX_FRONTEND_H_
129