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