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