Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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_SRC_COMPILER_LLVM_METHOD_COMPILER_H_ |
| 18 | #define ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_ |
| 19 | |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 20 | #include "backend_types.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 21 | #include "dex_file.h" |
| 22 | #include "dex_instruction.h" |
Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame] | 23 | #include "invoke_type.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 24 | #include "object_utils.h" |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 25 | #include "runtime_support_func.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 26 | |
| 27 | #include <llvm/Support/IRBuilder.h> |
| 28 | |
| 29 | #include <vector> |
| 30 | |
| 31 | #include <stdint.h> |
| 32 | |
| 33 | |
| 34 | namespace art { |
| 35 | class ClassLinker; |
| 36 | class ClassLoader; |
| 37 | class CompiledMethod; |
| 38 | class Compiler; |
| 39 | class DexCache; |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 40 | class Field; |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 41 | class OatCompilationUnit; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | |
| 45 | namespace llvm { |
| 46 | class AllocaInst; |
| 47 | class BasicBlock; |
| 48 | class Function; |
| 49 | class FunctionType; |
| 50 | class LLVMContext; |
| 51 | class Module; |
| 52 | class Type; |
| 53 | } |
| 54 | |
| 55 | |
| 56 | namespace art { |
| 57 | namespace compiler_llvm { |
| 58 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 59 | class CompilationUnit; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 60 | class CompilerLLVM; |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 61 | class DalvikReg; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 62 | class IRBuilder; |
| 63 | |
| 64 | class MethodCompiler { |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 65 | public: |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 66 | MethodCompiler(CompilationUnit* cunit, |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 67 | Compiler* compiler, |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 68 | OatCompilationUnit* oat_compilation_unit); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 69 | |
| 70 | ~MethodCompiler(); |
| 71 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 72 | CompiledMethod* Compile(); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 73 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 74 | |
| 75 | // Code generation helper function |
| 76 | |
| 77 | IRBuilder& GetIRBuilder() const { |
| 78 | return irb_; |
| 79 | } |
| 80 | |
| 81 | |
| 82 | // Register helper function |
| 83 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 84 | llvm::Value* AllocDalvikReg(RegCategory cat, const std::string& name); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 85 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 86 | llvm::Value* GetShadowFrameEntry(uint32_t reg_idx); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 87 | |
| 88 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 89 | private: |
| 90 | void CreateFunction(); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 91 | void EmitPrologue(); |
TDYa127 | 4165a83 | 2012-04-03 17:47:16 -0700 | [diff] [blame] | 92 | void EmitStackOverflowCheck(); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 93 | void EmitPrologueLastBranch(); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 94 | void EmitPrologueAllocShadowFrame(); |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 95 | void EmitPrologueAssignArgRegister(); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 96 | void EmitInstructions(); |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 97 | void EmitInstruction(uint32_t dex_pc, Instruction const* insn); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 98 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 99 | enum CondBranchKind { |
| 100 | kCondBranch_EQ, |
| 101 | kCondBranch_NE, |
| 102 | kCondBranch_LT, |
| 103 | kCondBranch_GE, |
| 104 | kCondBranch_GT, |
| 105 | kCondBranch_LE, |
| 106 | }; |
| 107 | |
| 108 | enum IntArithmKind { |
| 109 | kIntArithm_Add, |
| 110 | kIntArithm_Sub, |
| 111 | kIntArithm_Mul, |
| 112 | kIntArithm_Div, |
| 113 | kIntArithm_Rem, |
| 114 | kIntArithm_And, |
| 115 | kIntArithm_Or, |
| 116 | kIntArithm_Xor, |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | enum IntShiftArithmKind { |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 120 | kIntArithm_Shl, |
| 121 | kIntArithm_Shr, |
| 122 | kIntArithm_UShr, |
| 123 | }; |
| 124 | |
| 125 | enum FPArithmKind { |
| 126 | kFPArithm_Add, |
| 127 | kFPArithm_Sub, |
| 128 | kFPArithm_Mul, |
| 129 | kFPArithm_Div, |
| 130 | kFPArithm_Rem, |
| 131 | }; |
| 132 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 133 | enum InvokeArgFmt { |
| 134 | kArgReg, |
| 135 | kArgRange, |
| 136 | }; |
| 137 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 138 | #define GEN_INSN_ARGS uint32_t dex_pc, Instruction const* insn |
| 139 | |
| 140 | // NOP, PAYLOAD (unreachable) instructions |
| 141 | void EmitInsn_Nop(GEN_INSN_ARGS); |
| 142 | |
| 143 | // MOVE, MOVE_RESULT instructions |
| 144 | void EmitInsn_Move(GEN_INSN_ARGS, JType jty); |
| 145 | void EmitInsn_MoveResult(GEN_INSN_ARGS, JType jty); |
| 146 | |
| 147 | // MOVE_EXCEPTION, THROW instructions |
| 148 | void EmitInsn_MoveException(GEN_INSN_ARGS); |
| 149 | void EmitInsn_ThrowException(GEN_INSN_ARGS); |
Logan Chien | 9e5f5c1 | 2012-04-10 13:51:45 +0800 | [diff] [blame] | 150 | void EmitInsn_ThrowVerificationError(GEN_INSN_ARGS); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 151 | |
| 152 | // RETURN instructions |
| 153 | void EmitInsn_ReturnVoid(GEN_INSN_ARGS); |
| 154 | void EmitInsn_Return(GEN_INSN_ARGS); |
| 155 | |
| 156 | // CONST, CONST_CLASS, CONST_STRING instructions |
| 157 | void EmitInsn_LoadConstant(GEN_INSN_ARGS, JType imm_jty); |
| 158 | void EmitInsn_LoadConstantString(GEN_INSN_ARGS); |
| 159 | void EmitInsn_LoadConstantClass(GEN_INSN_ARGS); |
| 160 | |
| 161 | // MONITOR_ENTER, MONITOR_EXIT instructions |
| 162 | void EmitInsn_MonitorEnter(GEN_INSN_ARGS); |
| 163 | void EmitInsn_MonitorExit(GEN_INSN_ARGS); |
| 164 | |
| 165 | // CHECK_CAST, INSTANCE_OF instructions |
| 166 | void EmitInsn_CheckCast(GEN_INSN_ARGS); |
| 167 | void EmitInsn_InstanceOf(GEN_INSN_ARGS); |
| 168 | |
| 169 | // NEW_INSTANCE instructions |
| 170 | void EmitInsn_NewInstance(GEN_INSN_ARGS); |
| 171 | |
| 172 | // ARRAY_LEN, NEW_ARRAY, FILLED_NEW_ARRAY, FILL_ARRAY_DATA instructions |
| 173 | void EmitInsn_ArrayLength(GEN_INSN_ARGS); |
| 174 | void EmitInsn_NewArray(GEN_INSN_ARGS); |
| 175 | void EmitInsn_FilledNewArray(GEN_INSN_ARGS, bool is_range); |
| 176 | void EmitInsn_FillArrayData(GEN_INSN_ARGS); |
| 177 | |
| 178 | // GOTO, IF_TEST, IF_TESTZ instructions |
| 179 | void EmitInsn_UnconditionalBranch(GEN_INSN_ARGS); |
| 180 | void EmitInsn_BinaryConditionalBranch(GEN_INSN_ARGS, CondBranchKind cond); |
| 181 | void EmitInsn_UnaryConditionalBranch(GEN_INSN_ARGS, CondBranchKind cond); |
| 182 | |
| 183 | // PACKED_SWITCH, SPARSE_SWITCH instrutions |
| 184 | void EmitInsn_PackedSwitch(GEN_INSN_ARGS); |
| 185 | void EmitInsn_SparseSwitch(GEN_INSN_ARGS); |
| 186 | |
| 187 | // CMPX_FLOAT, CMPX_DOUBLE, CMP_LONG instructions |
| 188 | void EmitInsn_FPCompare(GEN_INSN_ARGS, JType fp_jty, bool gt_bias); |
| 189 | void EmitInsn_LongCompare(GEN_INSN_ARGS); |
| 190 | |
| 191 | // AGET, APUT instrutions |
| 192 | void EmitInsn_AGet(GEN_INSN_ARGS, JType elem_jty); |
| 193 | void EmitInsn_APut(GEN_INSN_ARGS, JType elem_jty); |
| 194 | |
| 195 | // IGET, IPUT instructions |
| 196 | void EmitInsn_IGet(GEN_INSN_ARGS, JType field_jty); |
| 197 | void EmitInsn_IPut(GEN_INSN_ARGS, JType field_jty); |
| 198 | |
| 199 | // SGET, SPUT instructions |
| 200 | void EmitInsn_SGet(GEN_INSN_ARGS, JType field_jty); |
| 201 | void EmitInsn_SPut(GEN_INSN_ARGS, JType field_jty); |
| 202 | |
| 203 | // INVOKE instructions |
TDYa127 | 0b686e5 | 2012-04-09 22:43:35 -0700 | [diff] [blame] | 204 | llvm::Value* EmitFixStub(llvm::Value* callee_method_object_addr, |
| 205 | uint32_t method_idx, |
| 206 | bool is_static); |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 207 | llvm::Value* EmitEnsureResolved(llvm::Value* callee, |
| 208 | llvm::Value* caller, |
| 209 | uint32_t dex_method_idx, |
TDYa127 | 0b686e5 | 2012-04-09 22:43:35 -0700 | [diff] [blame] | 210 | bool is_virtual); |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 211 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 212 | void EmitInsn_Invoke(GEN_INSN_ARGS, |
| 213 | InvokeType invoke_type, |
| 214 | InvokeArgFmt arg_fmt); |
| 215 | |
| 216 | llvm::Value* EmitLoadSDCalleeMethodObjectAddr(uint32_t callee_method_idx); |
| 217 | |
| 218 | llvm::Value* EmitLoadVirtualCalleeMethodObjectAddr(int vtable_idx, |
| 219 | llvm::Value* this_addr); |
| 220 | |
| 221 | llvm::Value* EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx, |
| 222 | InvokeType invoke_type, |
| 223 | llvm::Value* this_addr, |
| 224 | uint32_t dex_pc, |
| 225 | bool is_fast_path); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 226 | |
| 227 | // Unary instructions |
| 228 | void EmitInsn_Neg(GEN_INSN_ARGS, JType op_jty); |
| 229 | void EmitInsn_Not(GEN_INSN_ARGS, JType op_jty); |
| 230 | void EmitInsn_SExt(GEN_INSN_ARGS); |
| 231 | void EmitInsn_Trunc(GEN_INSN_ARGS); |
| 232 | void EmitInsn_TruncAndSExt(GEN_INSN_ARGS, unsigned N); |
| 233 | void EmitInsn_TruncAndZExt(GEN_INSN_ARGS, unsigned N); |
| 234 | |
| 235 | void EmitInsn_FNeg(GEN_INSN_ARGS, JType op_jty); |
| 236 | void EmitInsn_IntToFP(GEN_INSN_ARGS, JType src_jty, JType dest_jty); |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 237 | void EmitInsn_FPToInt(GEN_INSN_ARGS, JType src_jty, JType dest_jty, |
| 238 | runtime_support::RuntimeId runtime_func_id); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 239 | void EmitInsn_FExt(GEN_INSN_ARGS); |
| 240 | void EmitInsn_FTrunc(GEN_INSN_ARGS); |
| 241 | |
| 242 | // Integer binary arithmetic instructions |
| 243 | void EmitInsn_IntArithm(GEN_INSN_ARGS, IntArithmKind arithm, |
| 244 | JType op_jty, bool is_2addr); |
| 245 | |
| 246 | void EmitInsn_IntArithmImmediate(GEN_INSN_ARGS, IntArithmKind arithm); |
| 247 | |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 248 | void EmitInsn_IntShiftArithm(GEN_INSN_ARGS, IntShiftArithmKind arithm, |
| 249 | JType op_jty, bool is_2addr); |
| 250 | |
| 251 | void EmitInsn_IntShiftArithmImmediate(GEN_INSN_ARGS, |
| 252 | IntShiftArithmKind arithm); |
| 253 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 254 | void EmitInsn_RSubImmediate(GEN_INSN_ARGS); |
| 255 | |
| 256 | |
| 257 | // Floating-point binary arithmetic instructions |
| 258 | void EmitInsn_FPArithm(GEN_INSN_ARGS, FPArithmKind arithm, |
| 259 | JType op_jty, bool is_2addr); |
| 260 | |
| 261 | #undef GEN_INSN_ARGS |
| 262 | |
TDYa127 | 83bb662 | 2012-04-17 02:20:34 -0700 | [diff] [blame] | 263 | // GC card table helper function |
| 264 | void EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr); |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 265 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 266 | // Shadow frame helper function |
TDYa127 | af54347 | 2012-05-28 21:49:23 -0700 | [diff] [blame^] | 267 | void EmitPushShadowFrame(bool is_inline); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 268 | void EmitPopShadowFrame(); |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 269 | void EmitUpdateDexPC(uint32_t dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 270 | |
| 271 | |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 272 | // Dex cache code generation helper function |
| 273 | llvm::Value* EmitLoadDexCacheAddr(MemberOffset dex_cache_offset); |
| 274 | |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 275 | llvm::Value* EmitLoadDexCacheStaticStorageFieldAddr(uint32_t type_idx); |
| 276 | |
| 277 | llvm::Value* EmitLoadDexCacheResolvedTypeFieldAddr(uint32_t type_idx); |
| 278 | |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 279 | llvm::Value* EmitLoadDexCacheResolvedMethodFieldAddr(uint32_t method_idx); |
| 280 | |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 281 | llvm::Value* EmitLoadDexCacheStringFieldAddr(uint32_t string_idx); |
| 282 | |
| 283 | |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 284 | // Code generation helper function |
| 285 | |
| 286 | llvm::Value* EmitLoadMethodObjectAddr(); |
| 287 | |
| 288 | llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static); |
| 289 | |
TDYa127 | 526643e | 2012-05-26 01:01:48 -0700 | [diff] [blame] | 290 | void EmitGuard_ExceptionLandingPad(uint32_t dex_pc, bool can_skip_unwind); |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 291 | |
| 292 | void EmitBranchExceptionLandingPad(uint32_t dex_pc); |
| 293 | |
TDYa127 | 526643e | 2012-05-26 01:01:48 -0700 | [diff] [blame] | 294 | void EmitGuard_GarbageCollectionSuspend(); |
Logan Chien | 924072f | 2012-01-30 15:07:24 +0800 | [diff] [blame] | 295 | |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 296 | llvm::Value* EmitCompareResultSelection(llvm::Value* cmp_eq, |
| 297 | llvm::Value* cmp_lt); |
| 298 | |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 299 | llvm::Value* EmitConditionResult(llvm::Value* lhs, |
| 300 | llvm::Value* rhs, |
| 301 | CondBranchKind cond); |
| 302 | |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 303 | llvm::Value* EmitIntArithmResultComputation(uint32_t dex_pc, |
| 304 | llvm::Value* lhs, |
| 305 | llvm::Value* rhs, |
| 306 | IntArithmKind arithm, |
| 307 | JType op_jty); |
| 308 | |
TDYa127 | f8641ce | 2012-04-02 06:40:40 -0700 | [diff] [blame] | 309 | llvm::Value* EmitIntDivRemResultComputation(uint32_t dex_pc, |
| 310 | llvm::Value* dividend, |
| 311 | llvm::Value* divisor, |
| 312 | IntArithmKind arithm, |
| 313 | JType op_jty); |
| 314 | |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 315 | llvm::Value* EmitIntShiftArithmResultComputation(uint32_t dex_pc, |
| 316 | llvm::Value* lhs, |
| 317 | llvm::Value* rhs, |
| 318 | IntShiftArithmKind arithm, |
| 319 | JType op_jty); |
| 320 | |
Logan Chien | 76e1c79 | 2011-12-27 18:15:01 +0800 | [diff] [blame] | 321 | llvm::Value* EmitFPArithmResultComputation(uint32_t dex_pc, |
| 322 | llvm::Value* lhs, |
| 323 | llvm::Value* rhs, |
| 324 | FPArithmKind arithm); |
| 325 | |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 326 | llvm::Value* EmitAllocNewArray(uint32_t dex_pc, |
| 327 | int32_t length, |
| 328 | uint32_t type_idx, |
| 329 | bool is_filled_new_array); |
| 330 | |
Logan Chien | 46fbb41 | 2012-02-15 22:29:08 +0800 | [diff] [blame] | 331 | llvm::Value* EmitLoadClassObjectAddr(llvm::Value* this_addr); |
| 332 | |
| 333 | llvm::Value* EmitLoadVTableAddr(llvm::Value* class_object_addr); |
| 334 | |
| 335 | llvm::Value* EmitLoadMethodObjectAddrFromVTable(llvm::Value* vtable_addr, |
| 336 | uint16_t vtable_index); |
| 337 | |
| 338 | llvm::Value* EmitLoadCodeAddr(llvm::Value* method_object_addr, |
| 339 | uint32_t method_idx, |
| 340 | bool is_static); |
| 341 | |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 342 | llvm::Value* EmitLoadArrayLength(llvm::Value* array); |
| 343 | |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 344 | llvm::Value* EmitArrayGEP(llvm::Value* array_addr, |
| 345 | llvm::Value* index_value, |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 346 | JType elem_jty); |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 347 | |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 348 | llvm::Value* EmitLoadConstantClass(uint32_t dex_pc, uint32_t type_idx); |
| 349 | |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 350 | llvm::Value* EmitLoadStaticStorage(uint32_t dex_pc, uint32_t type_idx); |
| 351 | |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 352 | void EmitLoadActualParameters(std::vector<llvm::Value*>& args, |
| 353 | uint32_t callee_method_idx, |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 354 | DecodedInstruction const& di, |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 355 | InvokeArgFmt arg_fmt, |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 356 | bool is_static); |
| 357 | |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 358 | void EmitGuard_DivZeroException(uint32_t dex_pc, |
| 359 | llvm::Value* denominator, |
| 360 | JType op_jty); |
| 361 | |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 362 | void EmitGuard_NullPointerException(uint32_t dex_pc, |
| 363 | llvm::Value* object); |
| 364 | |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 365 | void EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc, |
| 366 | llvm::Value* array, |
| 367 | llvm::Value* index); |
| 368 | |
| 369 | void EmitGuard_ArrayException(uint32_t dex_pc, |
| 370 | llvm::Value* array, |
| 371 | llvm::Value* index); |
| 372 | |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 373 | RegCategory GetInferredRegCategory(uint32_t dex_pc, uint16_t reg); |
| 374 | |
TDYa127 | 1d7e510 | 2012-05-13 09:27:05 -0700 | [diff] [blame] | 375 | InferredRegCategoryMap const* GetInferredRegCategoryMap(); |
| 376 | |
| 377 | bool IsRegCanBeObject(uint16_t reg_idx); |
| 378 | |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 379 | |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 380 | // Basic block helper functions |
| 381 | llvm::BasicBlock* GetBasicBlock(uint32_t dex_pc); |
| 382 | |
| 383 | llvm::BasicBlock* GetNextBasicBlock(uint32_t dex_pc); |
| 384 | |
| 385 | llvm::BasicBlock* CreateBasicBlockWithDexPC(uint32_t dex_pc, |
| 386 | char const* postfix = NULL); |
| 387 | |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 388 | int32_t GetTryItemOffset(uint32_t dex_pc); |
| 389 | |
| 390 | llvm::BasicBlock* GetLandingPadBasicBlock(uint32_t dex_pc); |
| 391 | |
| 392 | llvm::BasicBlock* GetUnwindBasicBlock(); |
| 393 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 394 | |
| 395 | // Register helper function |
| 396 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 397 | llvm::Value* EmitLoadDalvikReg(uint32_t reg_idx, JType jty, JTypeSpace space); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 398 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 399 | llvm::Value* EmitLoadDalvikReg(uint32_t reg_idx, char shorty, JTypeSpace space); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 400 | |
| 401 | void EmitStoreDalvikReg(uint32_t reg_idx, JType jty, |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 402 | JTypeSpace space, llvm::Value* new_value); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 403 | |
| 404 | void EmitStoreDalvikReg(uint32_t reg_idx, char shorty, |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 405 | JTypeSpace space, llvm::Value* new_value); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 406 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 407 | llvm::Value* EmitLoadDalvikRetValReg(JType jty, JTypeSpace space); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 408 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 409 | llvm::Value* EmitLoadDalvikRetValReg(char shorty, JTypeSpace space); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 410 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 411 | void EmitStoreDalvikRetValReg(JType jty, JTypeSpace space, llvm::Value* new_value); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 412 | |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 413 | void EmitStoreDalvikRetValReg(char shorty, JTypeSpace space, llvm::Value* new_value); |
Logan Chien | 50aaf81 | 2012-03-01 21:03:24 +0800 | [diff] [blame] | 414 | |
TDYa127 | cc1b4c3 | 2012-05-15 07:31:37 -0700 | [diff] [blame] | 415 | // TODO: Use high-level IR to do this |
TDYa127 | 29c0cd1 | 2012-05-17 04:51:08 -0700 | [diff] [blame] | 416 | bool EmitInlineJavaIntrinsic(const std::string& callee_method_name, |
| 417 | const std::vector<llvm::Value*>& args, |
| 418 | llvm::BasicBlock* after_invoke); |
| 419 | |
| 420 | bool EmitInlinedStringCharAt(const std::vector<llvm::Value*>& args, |
| 421 | llvm::BasicBlock* after_invoke); |
| 422 | |
| 423 | bool EmitInlinedStringLength(const std::vector<llvm::Value*>& args, |
| 424 | llvm::BasicBlock* after_invoke); |
TDYa127 | cc1b4c3 | 2012-05-15 07:31:37 -0700 | [diff] [blame] | 425 | |
TDYa127 | 526643e | 2012-05-26 01:01:48 -0700 | [diff] [blame] | 426 | bool IsInstructionDirectToReturn(uint32_t dex_pc); |
| 427 | |
TDYa127 | cc1b4c3 | 2012-05-15 07:31:37 -0700 | [diff] [blame] | 428 | struct MethodInfo { |
| 429 | int64_t this_reg_idx; |
| 430 | bool this_will_not_be_null; |
| 431 | bool has_invoke; |
| 432 | bool need_shadow_frame_entry; |
| 433 | bool need_shadow_frame; |
TDYa127 | af54347 | 2012-05-28 21:49:23 -0700 | [diff] [blame^] | 434 | bool lazy_push_shadow_frame; |
TDYa127 | cc1b4c3 | 2012-05-15 07:31:37 -0700 | [diff] [blame] | 435 | }; |
| 436 | MethodInfo method_info_; |
| 437 | |
| 438 | void ComputeMethodInfo(); |
Logan Chien | 50aaf81 | 2012-03-01 21:03:24 +0800 | [diff] [blame] | 439 | |
| 440 | private: |
| 441 | CompilationUnit* cunit_; |
| 442 | Compiler* compiler_; |
| 443 | |
| 444 | ClassLinker* class_linker_; |
| 445 | ClassLoader const* class_loader_; |
| 446 | |
| 447 | DexFile const* dex_file_; |
| 448 | DexCache* dex_cache_; |
| 449 | DexFile::CodeItem const* code_item_; |
| 450 | |
| 451 | OatCompilationUnit* oat_compilation_unit_; |
Logan Chien | 50aaf81 | 2012-03-01 21:03:24 +0800 | [diff] [blame] | 452 | |
| 453 | uint32_t method_idx_; |
| 454 | uint32_t access_flags_; |
| 455 | |
| 456 | llvm::Module* module_; |
| 457 | llvm::LLVMContext* context_; |
| 458 | IRBuilder& irb_; |
| 459 | llvm::Function* func_; |
| 460 | |
| 461 | std::vector<DalvikReg*> regs_; |
TDYa127 | e210214 | 2012-05-26 10:27:38 -0700 | [diff] [blame] | 462 | std::vector<llvm::Value*> shadow_frame_entries_; |
TDYa127 | 1d7e510 | 2012-05-13 09:27:05 -0700 | [diff] [blame] | 463 | std::vector<int32_t> reg_to_shadow_frame_index_; |
Logan Chien | 50aaf81 | 2012-03-01 21:03:24 +0800 | [diff] [blame] | 464 | UniquePtr<DalvikReg> retval_reg_; |
| 465 | |
TDYa127 | b9ff6b1 | 2012-05-17 11:14:29 -0700 | [diff] [blame] | 466 | llvm::BasicBlock* basic_block_alloca_; |
| 467 | llvm::BasicBlock* basic_block_shadow_frame_; |
Logan Chien | 50aaf81 | 2012-03-01 21:03:24 +0800 | [diff] [blame] | 468 | llvm::BasicBlock* basic_block_reg_arg_init_; |
| 469 | std::vector<llvm::BasicBlock*> basic_blocks_; |
| 470 | |
| 471 | std::vector<llvm::BasicBlock*> basic_block_landing_pads_; |
| 472 | llvm::BasicBlock* basic_block_unwind_; |
| 473 | llvm::BasicBlock* basic_block_unreachable_; |
| 474 | |
| 475 | llvm::AllocaInst* shadow_frame_; |
TDYa127 | b9ff6b1 | 2012-05-17 11:14:29 -0700 | [diff] [blame] | 476 | llvm::AllocaInst* jvalue_temp_; |
TDYa127 | 0de52be | 2012-05-27 20:49:31 -0700 | [diff] [blame] | 477 | llvm::Value* old_shadow_frame_; |
Logan Chien | 937105a | 2012-04-02 02:37:37 +0800 | [diff] [blame] | 478 | |
TDYa127 | af54347 | 2012-05-28 21:49:23 -0700 | [diff] [blame^] | 479 | llvm::Value* already_pushed_shadow_frame_; |
| 480 | uint32_t shadow_frame_size_; |
| 481 | |
Logan Chien | 937105a | 2012-04-02 02:37:37 +0800 | [diff] [blame] | 482 | uint16_t elf_func_idx_; |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 483 | }; |
| 484 | |
| 485 | |
| 486 | } // namespace compiler_llvm |
| 487 | } // namespace art |
| 488 | |
| 489 | #endif // ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_ |