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 | #include "method_compiler.h" |
| 18 | |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 19 | #include "backend_types.h" |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 20 | #include "compilation_unit.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 21 | #include "compiler.h" |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 22 | #include "inferred_reg_category_map.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 23 | #include "ir_builder.h" |
| 24 | #include "logging.h" |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 25 | #include "oat_compilation_unit.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 26 | #include "object.h" |
| 27 | #include "object_utils.h" |
Logan Chien | 42e0e15 | 2012-01-13 15:42:36 +0800 | [diff] [blame] | 28 | #include "runtime_support_func.h" |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 29 | #include "runtime_support_llvm.h" |
Logan Chien | 1b0a1b7 | 2012-03-15 06:20:17 +0800 | [diff] [blame] | 30 | #include "shadow_frame.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 31 | #include "stl_util.h" |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 32 | #include "stringprintf.h" |
| 33 | #include "utils_llvm.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 34 | #include "verifier/method_verifier.h" |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 35 | |
| 36 | #include <iomanip> |
| 37 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 38 | #include <llvm/BasicBlock.h> |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 39 | #include <llvm/Function.h> |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 40 | #include <llvm/GlobalVariable.h> |
| 41 | #include <llvm/Intrinsics.h> |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 42 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 43 | namespace art { |
| 44 | namespace compiler_llvm { |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 45 | |
Logan Chien | 42e0e15 | 2012-01-13 15:42:36 +0800 | [diff] [blame] | 46 | using namespace runtime_support; |
| 47 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 48 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 49 | MethodCompiler::MethodCompiler(CompilationUnit* cunit, |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 50 | Compiler* compiler, |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 51 | OatCompilationUnit* oat_compilation_unit) |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 52 | : cunit_(cunit), compiler_(compiler), |
| 53 | class_linker_(oat_compilation_unit->class_linker_), |
| 54 | class_loader_(oat_compilation_unit->class_loader_), |
| 55 | dex_file_(oat_compilation_unit->dex_file_), |
| 56 | dex_cache_(oat_compilation_unit->dex_cache_), |
| 57 | code_item_(oat_compilation_unit->code_item_), |
| 58 | oat_compilation_unit_(oat_compilation_unit), |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 59 | method_idx_(oat_compilation_unit->method_idx_), |
| 60 | access_flags_(oat_compilation_unit->access_flags_), |
| 61 | module_(cunit->GetModule()), |
| 62 | context_(cunit->GetLLVMContext()), |
| 63 | irb_(*cunit->GetIRBuilder()), func_(NULL), retval_reg_(NULL), |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 64 | basic_block_stack_overflow_(NULL), |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 65 | basic_block_reg_alloca_(NULL), basic_block_shadow_frame_alloca_(NULL), |
Logan Chien | ef4a656 | 2012-04-24 18:02:24 +0800 | [diff] [blame] | 66 | basic_block_reg_arg_init_(NULL), |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 67 | basic_blocks_(code_item_->insns_size_in_code_units_), |
| 68 | basic_block_landing_pads_(code_item_->tries_size_, NULL), |
| 69 | basic_block_unwind_(NULL), basic_block_unreachable_(NULL), |
Logan Chien | 937105a | 2012-04-02 02:37:37 +0800 | [diff] [blame] | 70 | shadow_frame_(NULL), elf_func_idx_(cunit_->AcquireUniqueElfFuncIndex()) { |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
| 74 | MethodCompiler::~MethodCompiler() { |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 75 | STLDeleteElements(®s_); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 79 | void MethodCompiler::CreateFunction() { |
| 80 | // LLVM function name |
Logan Chien | 937105a | 2012-04-02 02:37:37 +0800 | [diff] [blame] | 81 | std::string func_name(ElfFuncName(elf_func_idx_)); |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 82 | |
| 83 | // Get function type |
| 84 | llvm::FunctionType* func_type = |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 85 | GetFunctionType(method_idx_, oat_compilation_unit_->IsStatic()); |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 86 | |
| 87 | // Create function |
| 88 | func_ = llvm::Function::Create(func_type, llvm::Function::ExternalLinkage, |
| 89 | func_name, module_); |
| 90 | |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 91 | #if !defined(NDEBUG) |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 92 | // Set argument name |
| 93 | llvm::Function::arg_iterator arg_iter(func_->arg_begin()); |
| 94 | llvm::Function::arg_iterator arg_end(func_->arg_end()); |
| 95 | |
| 96 | DCHECK_NE(arg_iter, arg_end); |
| 97 | arg_iter->setName("method"); |
| 98 | ++arg_iter; |
| 99 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 100 | if (!oat_compilation_unit_->IsStatic()) { |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 101 | DCHECK_NE(arg_iter, arg_end); |
| 102 | arg_iter->setName("this"); |
| 103 | ++arg_iter; |
| 104 | } |
| 105 | |
| 106 | for (unsigned i = 0; arg_iter != arg_end; ++i, ++arg_iter) { |
| 107 | arg_iter->setName(StringPrintf("a%u", i)); |
| 108 | } |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 109 | #endif |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
| 113 | llvm::FunctionType* MethodCompiler::GetFunctionType(uint32_t method_idx, |
| 114 | bool is_static) { |
| 115 | // Get method signature |
| 116 | DexFile::MethodId const& method_id = dex_file_->GetMethodId(method_idx); |
| 117 | |
Logan Chien | 8faf802 | 2012-02-24 12:25:29 +0800 | [diff] [blame] | 118 | uint32_t shorty_size; |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 119 | char const* shorty = dex_file_->GetMethodShorty(method_id, &shorty_size); |
Logan Chien | 8faf802 | 2012-02-24 12:25:29 +0800 | [diff] [blame] | 120 | CHECK_GE(shorty_size, 1u); |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 121 | |
| 122 | // Get return type |
| 123 | llvm::Type* ret_type = irb_.getJType(shorty[0], kAccurate); |
| 124 | |
| 125 | // Get argument type |
| 126 | std::vector<llvm::Type*> args_type; |
| 127 | |
| 128 | args_type.push_back(irb_.getJObjectTy()); // method object pointer |
| 129 | |
| 130 | if (!is_static) { |
| 131 | args_type.push_back(irb_.getJType('L', kAccurate)); // "this" object pointer |
| 132 | } |
| 133 | |
Logan Chien | 8faf802 | 2012-02-24 12:25:29 +0800 | [diff] [blame] | 134 | for (uint32_t i = 1; i < shorty_size; ++i) { |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 135 | args_type.push_back(irb_.getJType(shorty[i], kAccurate)); |
| 136 | } |
| 137 | |
| 138 | return llvm::FunctionType::get(ret_type, args_type, false); |
| 139 | } |
| 140 | |
| 141 | |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 142 | void MethodCompiler::EmitPrologue() { |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 143 | // Create basic blocks for prologue |
TDYa127 | 9948913 | 2012-04-29 01:27:58 -0700 | [diff] [blame] | 144 | #if !defined(NDEBUG) |
| 145 | // Add a BasicBlock named as PrettyMethod for debugging. |
| 146 | llvm::BasicBlock* entry = |
| 147 | llvm::BasicBlock::Create(*context_, PrettyMethod(method_idx_, *dex_file_), func_); |
| 148 | #endif |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 149 | basic_block_reg_alloca_ = |
| 150 | llvm::BasicBlock::Create(*context_, "prologue.alloca", func_); |
| 151 | |
TDYa127 | 97339c4 | 2012-04-29 01:26:35 -0700 | [diff] [blame] | 152 | basic_block_stack_overflow_ = |
| 153 | llvm::BasicBlock::Create(*context_, "prologue.stack_overflow_check", func_); |
| 154 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 155 | basic_block_shadow_frame_alloca_ = |
| 156 | llvm::BasicBlock::Create(*context_, "prologue.shadowframe", func_); |
| 157 | |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 158 | basic_block_reg_arg_init_ = |
| 159 | llvm::BasicBlock::Create(*context_, "prologue.arginit", func_); |
| 160 | |
TDYa127 | 9948913 | 2012-04-29 01:27:58 -0700 | [diff] [blame] | 161 | #if !defined(NDEBUG) |
| 162 | irb_.SetInsertPoint(entry); |
| 163 | irb_.CreateBr(basic_block_reg_alloca_); |
| 164 | #endif |
| 165 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 166 | // Create register array |
| 167 | for (uint16_t r = 0; r < code_item_->registers_size_; ++r) { |
| 168 | regs_.push_back(DalvikReg::CreateLocalVarReg(*this, r)); |
| 169 | } |
| 170 | |
| 171 | retval_reg_.reset(DalvikReg::CreateRetValReg(*this)); |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 172 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 173 | // Create Shadow Frame |
| 174 | EmitPrologueAllocShadowFrame(); |
| 175 | |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 176 | // Store argument to dalvik register |
| 177 | irb_.SetInsertPoint(basic_block_reg_arg_init_); |
| 178 | EmitPrologueAssignArgRegister(); |
| 179 | |
| 180 | // Branch to start address |
| 181 | irb_.CreateBr(GetBasicBlock(0)); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
TDYa127 | 4165a83 | 2012-04-03 17:47:16 -0700 | [diff] [blame] | 185 | void MethodCompiler::EmitStackOverflowCheck() { |
| 186 | irb_.SetInsertPoint(basic_block_stack_overflow_); |
| 187 | |
| 188 | // Call llvm intrinsic function to get frame address. |
| 189 | llvm::Function* frameaddress = |
| 190 | llvm::Intrinsic::getDeclaration(module_, llvm::Intrinsic::frameaddress); |
| 191 | |
| 192 | // The type of llvm::frameaddress is: i8* @llvm.frameaddress(i32) |
| 193 | llvm::Value* frame_address = irb_.CreateCall(frameaddress, irb_.getInt32(0)); |
| 194 | |
| 195 | // Cast i8* to int |
| 196 | frame_address = irb_.CreatePtrToInt(frame_address, irb_.getPtrEquivIntTy()); |
| 197 | |
| 198 | // Get thread.stack_end_ |
| 199 | llvm::Value* thread_object_addr = |
| 200 | irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 201 | |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 202 | llvm::Value* stack_end = |
| 203 | irb_.LoadFromObjectOffset(thread_object_addr, |
| 204 | Thread::StackEndOffset().Int32Value(), |
| 205 | irb_.getPtrEquivIntTy()); |
TDYa127 | 4165a83 | 2012-04-03 17:47:16 -0700 | [diff] [blame] | 206 | |
| 207 | // Check the frame address < thread.stack_end_ ? |
| 208 | llvm::Value* is_stack_overflow = irb_.CreateICmpULT(frame_address, stack_end); |
| 209 | |
| 210 | llvm::BasicBlock* block_exception = |
| 211 | llvm::BasicBlock::Create(*context_, "stack_overflow", func_); |
| 212 | |
| 213 | llvm::BasicBlock* block_continue = |
| 214 | llvm::BasicBlock::Create(*context_, "stack_overflow_cont", func_); |
| 215 | |
| 216 | irb_.CreateCondBr(is_stack_overflow, block_exception, block_continue); |
| 217 | |
| 218 | // If stack overflow, throw exception. |
| 219 | irb_.SetInsertPoint(block_exception); |
| 220 | irb_.CreateCall(irb_.GetRuntime(ThrowStackOverflowException)); |
| 221 | |
| 222 | // Unwind. |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 223 | char ret_shorty = oat_compilation_unit_->GetShorty()[0]; |
TDYa127 | 4165a83 | 2012-04-03 17:47:16 -0700 | [diff] [blame] | 224 | if (ret_shorty == 'V') { |
| 225 | irb_.CreateRetVoid(); |
| 226 | } else { |
| 227 | irb_.CreateRet(irb_.getJZero(ret_shorty)); |
| 228 | } |
| 229 | |
| 230 | basic_block_stack_overflow_ = block_continue; |
| 231 | } |
| 232 | |
| 233 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 234 | void MethodCompiler::EmitPrologueLastBranch() { |
| 235 | irb_.SetInsertPoint(basic_block_reg_alloca_); |
TDYa127 | 97339c4 | 2012-04-29 01:26:35 -0700 | [diff] [blame] | 236 | irb_.CreateBr(basic_block_stack_overflow_); |
| 237 | |
| 238 | EmitStackOverflowCheck(); |
| 239 | |
| 240 | irb_.SetInsertPoint(basic_block_stack_overflow_); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 241 | irb_.CreateBr(basic_block_shadow_frame_alloca_); |
| 242 | |
| 243 | irb_.SetInsertPoint(basic_block_shadow_frame_alloca_); |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 244 | irb_.CreateBr(basic_block_reg_arg_init_); |
| 245 | } |
| 246 | |
| 247 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 248 | void MethodCompiler::EmitPrologueAllocShadowFrame() { |
| 249 | irb_.SetInsertPoint(basic_block_shadow_frame_alloca_); |
| 250 | |
| 251 | // Allocate the shadow frame now! |
| 252 | uint32_t sirt_size = code_item_->registers_size_; |
| 253 | // TODO: registers_size_ is a bad approximation. Compute a |
| 254 | // tighter approximation at Dex verifier while performing data-flow |
| 255 | // analysis. |
| 256 | |
| 257 | llvm::StructType* shadow_frame_type = irb_.getShadowFrameTy(sirt_size); |
| 258 | shadow_frame_ = irb_.CreateAlloca(shadow_frame_type); |
| 259 | |
| 260 | // Zero-initialization of the shadow frame |
| 261 | llvm::ConstantAggregateZero* zero_initializer = |
| 262 | llvm::ConstantAggregateZero::get(shadow_frame_type); |
| 263 | |
| 264 | irb_.CreateStore(zero_initializer, shadow_frame_); |
| 265 | |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 266 | // Get method object |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 267 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 268 | |
| 269 | // Store the method pointer |
| 270 | irb_.StoreToObjectOffset(shadow_frame_, |
| 271 | ShadowFrame::MethodOffset(), |
| 272 | method_object_addr); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 273 | |
| 274 | // Store the number of the pointer slots |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 275 | irb_.StoreToObjectOffset(shadow_frame_, |
| 276 | ShadowFrame::NumberOfReferencesOffset(), |
| 277 | irb_.getJInt(sirt_size)); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 278 | |
| 279 | // Push the shadow frame |
| 280 | llvm::Value* shadow_frame_upcast = |
| 281 | irb_.CreateConstGEP2_32(shadow_frame_, 0, 0); |
| 282 | |
| 283 | irb_.CreateCall(irb_.GetRuntime(PushShadowFrame), shadow_frame_upcast); |
| 284 | } |
| 285 | |
| 286 | |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 287 | void MethodCompiler::EmitPrologueAssignArgRegister() { |
| 288 | uint16_t arg_reg = code_item_->registers_size_ - code_item_->ins_size_; |
| 289 | |
| 290 | llvm::Function::arg_iterator arg_iter(func_->arg_begin()); |
| 291 | llvm::Function::arg_iterator arg_end(func_->arg_end()); |
| 292 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 293 | uint32_t shorty_size = 0; |
| 294 | char const* shorty = oat_compilation_unit_->GetShorty(&shorty_size); |
| 295 | CHECK_GE(shorty_size, 1u); |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 296 | |
| 297 | ++arg_iter; // skip method object |
| 298 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 299 | if (!oat_compilation_unit_->IsStatic()) { |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 300 | EmitStoreDalvikReg(arg_reg, kObject, kAccurate, arg_iter); |
| 301 | ++arg_iter; |
| 302 | ++arg_reg; |
| 303 | } |
| 304 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 305 | for (uint32_t i = 1; i < shorty_size; ++i, ++arg_iter) { |
Logan Chien | d6ececa | 2011-12-27 16:20:15 +0800 | [diff] [blame] | 306 | EmitStoreDalvikReg(arg_reg, shorty[i], kAccurate, arg_iter); |
| 307 | |
| 308 | ++arg_reg; |
| 309 | if (shorty[i] == 'J' || shorty[i] == 'D') { |
| 310 | // Wide types, such as long and double, are using a pair of registers |
| 311 | // to store the value, so we have to increase arg_reg again. |
| 312 | ++arg_reg; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | DCHECK_EQ(arg_end, arg_iter); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 320 | void MethodCompiler::EmitInstructions() { |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 321 | uint32_t dex_pc = 0; |
| 322 | while (dex_pc < code_item_->insns_size_in_code_units_) { |
| 323 | Instruction const* insn = Instruction::At(code_item_->insns_ + dex_pc); |
| 324 | EmitInstruction(dex_pc, insn); |
| 325 | dex_pc += insn->SizeInCodeUnits(); |
| 326 | } |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 330 | void MethodCompiler::EmitInstruction(uint32_t dex_pc, |
| 331 | Instruction const* insn) { |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 332 | |
| 333 | // Set the IRBuilder insertion point |
| 334 | irb_.SetInsertPoint(GetBasicBlock(dex_pc)); |
| 335 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 336 | #define ARGS dex_pc, insn |
| 337 | |
| 338 | // Dispatch the instruction |
| 339 | switch (insn->Opcode()) { |
| 340 | case Instruction::NOP: |
| 341 | EmitInsn_Nop(ARGS); |
| 342 | break; |
| 343 | |
| 344 | case Instruction::MOVE: |
| 345 | case Instruction::MOVE_FROM16: |
| 346 | case Instruction::MOVE_16: |
| 347 | EmitInsn_Move(ARGS, kInt); |
| 348 | break; |
| 349 | |
| 350 | case Instruction::MOVE_WIDE: |
| 351 | case Instruction::MOVE_WIDE_FROM16: |
| 352 | case Instruction::MOVE_WIDE_16: |
| 353 | EmitInsn_Move(ARGS, kLong); |
| 354 | break; |
| 355 | |
| 356 | case Instruction::MOVE_OBJECT: |
| 357 | case Instruction::MOVE_OBJECT_FROM16: |
| 358 | case Instruction::MOVE_OBJECT_16: |
| 359 | EmitInsn_Move(ARGS, kObject); |
| 360 | break; |
| 361 | |
| 362 | case Instruction::MOVE_RESULT: |
| 363 | EmitInsn_MoveResult(ARGS, kInt); |
| 364 | break; |
| 365 | |
| 366 | case Instruction::MOVE_RESULT_WIDE: |
| 367 | EmitInsn_MoveResult(ARGS, kLong); |
| 368 | break; |
| 369 | |
| 370 | case Instruction::MOVE_RESULT_OBJECT: |
| 371 | EmitInsn_MoveResult(ARGS, kObject); |
| 372 | break; |
| 373 | |
| 374 | case Instruction::MOVE_EXCEPTION: |
| 375 | EmitInsn_MoveException(ARGS); |
| 376 | break; |
| 377 | |
| 378 | case Instruction::RETURN_VOID: |
| 379 | EmitInsn_ReturnVoid(ARGS); |
| 380 | break; |
| 381 | |
| 382 | case Instruction::RETURN: |
| 383 | case Instruction::RETURN_WIDE: |
| 384 | case Instruction::RETURN_OBJECT: |
| 385 | EmitInsn_Return(ARGS); |
| 386 | break; |
| 387 | |
| 388 | case Instruction::CONST_4: |
| 389 | case Instruction::CONST_16: |
| 390 | case Instruction::CONST: |
| 391 | case Instruction::CONST_HIGH16: |
| 392 | EmitInsn_LoadConstant(ARGS, kInt); |
| 393 | break; |
| 394 | |
| 395 | case Instruction::CONST_WIDE_16: |
| 396 | case Instruction::CONST_WIDE_32: |
| 397 | case Instruction::CONST_WIDE: |
| 398 | case Instruction::CONST_WIDE_HIGH16: |
| 399 | EmitInsn_LoadConstant(ARGS, kLong); |
| 400 | break; |
| 401 | |
| 402 | case Instruction::CONST_STRING: |
| 403 | case Instruction::CONST_STRING_JUMBO: |
| 404 | EmitInsn_LoadConstantString(ARGS); |
| 405 | break; |
| 406 | |
| 407 | case Instruction::CONST_CLASS: |
| 408 | EmitInsn_LoadConstantClass(ARGS); |
| 409 | break; |
| 410 | |
| 411 | case Instruction::MONITOR_ENTER: |
| 412 | EmitInsn_MonitorEnter(ARGS); |
| 413 | break; |
| 414 | |
| 415 | case Instruction::MONITOR_EXIT: |
| 416 | EmitInsn_MonitorExit(ARGS); |
| 417 | break; |
| 418 | |
| 419 | case Instruction::CHECK_CAST: |
| 420 | EmitInsn_CheckCast(ARGS); |
| 421 | break; |
| 422 | |
| 423 | case Instruction::INSTANCE_OF: |
| 424 | EmitInsn_InstanceOf(ARGS); |
| 425 | break; |
| 426 | |
| 427 | case Instruction::ARRAY_LENGTH: |
| 428 | EmitInsn_ArrayLength(ARGS); |
| 429 | break; |
| 430 | |
| 431 | case Instruction::NEW_INSTANCE: |
| 432 | EmitInsn_NewInstance(ARGS); |
| 433 | break; |
| 434 | |
| 435 | case Instruction::NEW_ARRAY: |
| 436 | EmitInsn_NewArray(ARGS); |
| 437 | break; |
| 438 | |
| 439 | case Instruction::FILLED_NEW_ARRAY: |
| 440 | EmitInsn_FilledNewArray(ARGS, false); |
| 441 | break; |
| 442 | |
| 443 | case Instruction::FILLED_NEW_ARRAY_RANGE: |
| 444 | EmitInsn_FilledNewArray(ARGS, true); |
| 445 | break; |
| 446 | |
| 447 | case Instruction::FILL_ARRAY_DATA: |
| 448 | EmitInsn_FillArrayData(ARGS); |
| 449 | break; |
| 450 | |
| 451 | case Instruction::THROW: |
| 452 | EmitInsn_ThrowException(ARGS); |
| 453 | break; |
| 454 | |
| 455 | case Instruction::GOTO: |
| 456 | case Instruction::GOTO_16: |
| 457 | case Instruction::GOTO_32: |
| 458 | EmitInsn_UnconditionalBranch(ARGS); |
| 459 | break; |
| 460 | |
| 461 | case Instruction::PACKED_SWITCH: |
| 462 | EmitInsn_PackedSwitch(ARGS); |
| 463 | break; |
| 464 | |
| 465 | case Instruction::SPARSE_SWITCH: |
| 466 | EmitInsn_SparseSwitch(ARGS); |
| 467 | break; |
| 468 | |
| 469 | case Instruction::CMPL_FLOAT: |
| 470 | EmitInsn_FPCompare(ARGS, kFloat, false); |
| 471 | break; |
| 472 | |
| 473 | case Instruction::CMPG_FLOAT: |
| 474 | EmitInsn_FPCompare(ARGS, kFloat, true); |
| 475 | break; |
| 476 | |
| 477 | case Instruction::CMPL_DOUBLE: |
| 478 | EmitInsn_FPCompare(ARGS, kDouble, false); |
| 479 | break; |
| 480 | |
| 481 | case Instruction::CMPG_DOUBLE: |
| 482 | EmitInsn_FPCompare(ARGS, kDouble, true); |
| 483 | break; |
| 484 | |
| 485 | case Instruction::CMP_LONG: |
| 486 | EmitInsn_LongCompare(ARGS); |
| 487 | break; |
| 488 | |
| 489 | case Instruction::IF_EQ: |
| 490 | EmitInsn_BinaryConditionalBranch(ARGS, kCondBranch_EQ); |
| 491 | break; |
| 492 | |
| 493 | case Instruction::IF_NE: |
| 494 | EmitInsn_BinaryConditionalBranch(ARGS, kCondBranch_NE); |
| 495 | break; |
| 496 | |
| 497 | case Instruction::IF_LT: |
| 498 | EmitInsn_BinaryConditionalBranch(ARGS, kCondBranch_LT); |
| 499 | break; |
| 500 | |
| 501 | case Instruction::IF_GE: |
| 502 | EmitInsn_BinaryConditionalBranch(ARGS, kCondBranch_GE); |
| 503 | break; |
| 504 | |
| 505 | case Instruction::IF_GT: |
| 506 | EmitInsn_BinaryConditionalBranch(ARGS, kCondBranch_GT); |
| 507 | break; |
| 508 | |
| 509 | case Instruction::IF_LE: |
| 510 | EmitInsn_BinaryConditionalBranch(ARGS, kCondBranch_LE); |
| 511 | break; |
| 512 | |
| 513 | case Instruction::IF_EQZ: |
| 514 | EmitInsn_UnaryConditionalBranch(ARGS, kCondBranch_EQ); |
| 515 | break; |
| 516 | |
| 517 | case Instruction::IF_NEZ: |
| 518 | EmitInsn_UnaryConditionalBranch(ARGS, kCondBranch_NE); |
| 519 | break; |
| 520 | |
| 521 | case Instruction::IF_LTZ: |
| 522 | EmitInsn_UnaryConditionalBranch(ARGS, kCondBranch_LT); |
| 523 | break; |
| 524 | |
| 525 | case Instruction::IF_GEZ: |
| 526 | EmitInsn_UnaryConditionalBranch(ARGS, kCondBranch_GE); |
| 527 | break; |
| 528 | |
| 529 | case Instruction::IF_GTZ: |
| 530 | EmitInsn_UnaryConditionalBranch(ARGS, kCondBranch_GT); |
| 531 | break; |
| 532 | |
| 533 | case Instruction::IF_LEZ: |
| 534 | EmitInsn_UnaryConditionalBranch(ARGS, kCondBranch_LE); |
| 535 | break; |
| 536 | |
| 537 | case Instruction::AGET: |
| 538 | EmitInsn_AGet(ARGS, kInt); |
| 539 | break; |
| 540 | |
| 541 | case Instruction::AGET_WIDE: |
| 542 | EmitInsn_AGet(ARGS, kLong); |
| 543 | break; |
| 544 | |
| 545 | case Instruction::AGET_OBJECT: |
| 546 | EmitInsn_AGet(ARGS, kObject); |
| 547 | break; |
| 548 | |
| 549 | case Instruction::AGET_BOOLEAN: |
| 550 | EmitInsn_AGet(ARGS, kBoolean); |
| 551 | break; |
| 552 | |
| 553 | case Instruction::AGET_BYTE: |
| 554 | EmitInsn_AGet(ARGS, kByte); |
| 555 | break; |
| 556 | |
| 557 | case Instruction::AGET_CHAR: |
| 558 | EmitInsn_AGet(ARGS, kChar); |
| 559 | break; |
| 560 | |
| 561 | case Instruction::AGET_SHORT: |
| 562 | EmitInsn_AGet(ARGS, kShort); |
| 563 | break; |
| 564 | |
| 565 | case Instruction::APUT: |
| 566 | EmitInsn_APut(ARGS, kInt); |
| 567 | break; |
| 568 | |
| 569 | case Instruction::APUT_WIDE: |
| 570 | EmitInsn_APut(ARGS, kLong); |
| 571 | break; |
| 572 | |
| 573 | case Instruction::APUT_OBJECT: |
| 574 | EmitInsn_APut(ARGS, kObject); |
| 575 | break; |
| 576 | |
| 577 | case Instruction::APUT_BOOLEAN: |
| 578 | EmitInsn_APut(ARGS, kBoolean); |
| 579 | break; |
| 580 | |
| 581 | case Instruction::APUT_BYTE: |
| 582 | EmitInsn_APut(ARGS, kByte); |
| 583 | break; |
| 584 | |
| 585 | case Instruction::APUT_CHAR: |
| 586 | EmitInsn_APut(ARGS, kChar); |
| 587 | break; |
| 588 | |
| 589 | case Instruction::APUT_SHORT: |
| 590 | EmitInsn_APut(ARGS, kShort); |
| 591 | break; |
| 592 | |
| 593 | case Instruction::IGET: |
| 594 | EmitInsn_IGet(ARGS, kInt); |
| 595 | break; |
| 596 | |
| 597 | case Instruction::IGET_WIDE: |
| 598 | EmitInsn_IGet(ARGS, kLong); |
| 599 | break; |
| 600 | |
| 601 | case Instruction::IGET_OBJECT: |
| 602 | EmitInsn_IGet(ARGS, kObject); |
| 603 | break; |
| 604 | |
| 605 | case Instruction::IGET_BOOLEAN: |
| 606 | EmitInsn_IGet(ARGS, kBoolean); |
| 607 | break; |
| 608 | |
| 609 | case Instruction::IGET_BYTE: |
| 610 | EmitInsn_IGet(ARGS, kByte); |
| 611 | break; |
| 612 | |
| 613 | case Instruction::IGET_CHAR: |
| 614 | EmitInsn_IGet(ARGS, kChar); |
| 615 | break; |
| 616 | |
| 617 | case Instruction::IGET_SHORT: |
| 618 | EmitInsn_IGet(ARGS, kShort); |
| 619 | break; |
| 620 | |
| 621 | case Instruction::IPUT: |
| 622 | EmitInsn_IPut(ARGS, kInt); |
| 623 | break; |
| 624 | |
| 625 | case Instruction::IPUT_WIDE: |
| 626 | EmitInsn_IPut(ARGS, kLong); |
| 627 | break; |
| 628 | |
| 629 | case Instruction::IPUT_OBJECT: |
| 630 | EmitInsn_IPut(ARGS, kObject); |
| 631 | break; |
| 632 | |
| 633 | case Instruction::IPUT_BOOLEAN: |
| 634 | EmitInsn_IPut(ARGS, kBoolean); |
| 635 | break; |
| 636 | |
| 637 | case Instruction::IPUT_BYTE: |
| 638 | EmitInsn_IPut(ARGS, kByte); |
| 639 | break; |
| 640 | |
| 641 | case Instruction::IPUT_CHAR: |
| 642 | EmitInsn_IPut(ARGS, kChar); |
| 643 | break; |
| 644 | |
| 645 | case Instruction::IPUT_SHORT: |
| 646 | EmitInsn_IPut(ARGS, kShort); |
| 647 | break; |
| 648 | |
| 649 | case Instruction::SGET: |
| 650 | EmitInsn_SGet(ARGS, kInt); |
| 651 | break; |
| 652 | |
| 653 | case Instruction::SGET_WIDE: |
| 654 | EmitInsn_SGet(ARGS, kLong); |
| 655 | break; |
| 656 | |
| 657 | case Instruction::SGET_OBJECT: |
| 658 | EmitInsn_SGet(ARGS, kObject); |
| 659 | break; |
| 660 | |
| 661 | case Instruction::SGET_BOOLEAN: |
| 662 | EmitInsn_SGet(ARGS, kBoolean); |
| 663 | break; |
| 664 | |
| 665 | case Instruction::SGET_BYTE: |
| 666 | EmitInsn_SGet(ARGS, kByte); |
| 667 | break; |
| 668 | |
| 669 | case Instruction::SGET_CHAR: |
| 670 | EmitInsn_SGet(ARGS, kChar); |
| 671 | break; |
| 672 | |
| 673 | case Instruction::SGET_SHORT: |
| 674 | EmitInsn_SGet(ARGS, kShort); |
| 675 | break; |
| 676 | |
| 677 | case Instruction::SPUT: |
| 678 | EmitInsn_SPut(ARGS, kInt); |
| 679 | break; |
| 680 | |
| 681 | case Instruction::SPUT_WIDE: |
| 682 | EmitInsn_SPut(ARGS, kLong); |
| 683 | break; |
| 684 | |
| 685 | case Instruction::SPUT_OBJECT: |
| 686 | EmitInsn_SPut(ARGS, kObject); |
| 687 | break; |
| 688 | |
| 689 | case Instruction::SPUT_BOOLEAN: |
| 690 | EmitInsn_SPut(ARGS, kBoolean); |
| 691 | break; |
| 692 | |
| 693 | case Instruction::SPUT_BYTE: |
| 694 | EmitInsn_SPut(ARGS, kByte); |
| 695 | break; |
| 696 | |
| 697 | case Instruction::SPUT_CHAR: |
| 698 | EmitInsn_SPut(ARGS, kChar); |
| 699 | break; |
| 700 | |
| 701 | case Instruction::SPUT_SHORT: |
| 702 | EmitInsn_SPut(ARGS, kShort); |
| 703 | break; |
| 704 | |
| 705 | |
| 706 | case Instruction::INVOKE_VIRTUAL: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 707 | EmitInsn_Invoke(ARGS, kVirtual, kArgReg); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 708 | break; |
| 709 | |
| 710 | case Instruction::INVOKE_SUPER: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 711 | EmitInsn_Invoke(ARGS, kSuper, kArgReg); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 712 | break; |
| 713 | |
| 714 | case Instruction::INVOKE_DIRECT: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 715 | EmitInsn_Invoke(ARGS, kDirect, kArgReg); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case Instruction::INVOKE_STATIC: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 719 | EmitInsn_Invoke(ARGS, kStatic, kArgReg); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case Instruction::INVOKE_INTERFACE: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 723 | EmitInsn_Invoke(ARGS, kInterface, kArgReg); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case Instruction::INVOKE_VIRTUAL_RANGE: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 727 | EmitInsn_Invoke(ARGS, kVirtual, kArgRange); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case Instruction::INVOKE_SUPER_RANGE: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 731 | EmitInsn_Invoke(ARGS, kSuper, kArgRange); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 732 | break; |
| 733 | |
| 734 | case Instruction::INVOKE_DIRECT_RANGE: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 735 | EmitInsn_Invoke(ARGS, kDirect, kArgRange); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case Instruction::INVOKE_STATIC_RANGE: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 739 | EmitInsn_Invoke(ARGS, kStatic, kArgRange); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 740 | break; |
| 741 | |
| 742 | case Instruction::INVOKE_INTERFACE_RANGE: |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 743 | EmitInsn_Invoke(ARGS, kInterface, kArgRange); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case Instruction::NEG_INT: |
| 747 | EmitInsn_Neg(ARGS, kInt); |
| 748 | break; |
| 749 | |
| 750 | case Instruction::NOT_INT: |
| 751 | EmitInsn_Not(ARGS, kInt); |
| 752 | break; |
| 753 | |
| 754 | case Instruction::NEG_LONG: |
| 755 | EmitInsn_Neg(ARGS, kLong); |
| 756 | break; |
| 757 | |
| 758 | case Instruction::NOT_LONG: |
| 759 | EmitInsn_Not(ARGS, kLong); |
| 760 | break; |
| 761 | |
| 762 | case Instruction::NEG_FLOAT: |
| 763 | EmitInsn_FNeg(ARGS, kFloat); |
| 764 | break; |
| 765 | |
| 766 | case Instruction::NEG_DOUBLE: |
| 767 | EmitInsn_FNeg(ARGS, kDouble); |
| 768 | break; |
| 769 | |
| 770 | case Instruction::INT_TO_LONG: |
| 771 | EmitInsn_SExt(ARGS); |
| 772 | break; |
| 773 | |
| 774 | case Instruction::INT_TO_FLOAT: |
| 775 | EmitInsn_IntToFP(ARGS, kInt, kFloat); |
| 776 | break; |
| 777 | |
| 778 | case Instruction::INT_TO_DOUBLE: |
| 779 | EmitInsn_IntToFP(ARGS, kInt, kDouble); |
| 780 | break; |
| 781 | |
| 782 | case Instruction::LONG_TO_INT: |
| 783 | EmitInsn_Trunc(ARGS); |
| 784 | break; |
| 785 | |
| 786 | case Instruction::LONG_TO_FLOAT: |
| 787 | EmitInsn_IntToFP(ARGS, kLong, kFloat); |
| 788 | break; |
| 789 | |
| 790 | case Instruction::LONG_TO_DOUBLE: |
| 791 | EmitInsn_IntToFP(ARGS, kLong, kDouble); |
| 792 | break; |
| 793 | |
| 794 | case Instruction::FLOAT_TO_INT: |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 795 | EmitInsn_FPToInt(ARGS, kFloat, kInt, F2I); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 796 | break; |
| 797 | |
| 798 | case Instruction::FLOAT_TO_LONG: |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 799 | EmitInsn_FPToInt(ARGS, kFloat, kLong, F2L); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case Instruction::FLOAT_TO_DOUBLE: |
| 803 | EmitInsn_FExt(ARGS); |
| 804 | break; |
| 805 | |
| 806 | case Instruction::DOUBLE_TO_INT: |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 807 | EmitInsn_FPToInt(ARGS, kDouble, kInt, D2I); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 808 | break; |
| 809 | |
| 810 | case Instruction::DOUBLE_TO_LONG: |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 811 | EmitInsn_FPToInt(ARGS, kDouble, kLong, D2L); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 812 | break; |
| 813 | |
| 814 | case Instruction::DOUBLE_TO_FLOAT: |
| 815 | EmitInsn_FTrunc(ARGS); |
| 816 | break; |
| 817 | |
| 818 | case Instruction::INT_TO_BYTE: |
| 819 | EmitInsn_TruncAndSExt(ARGS, 8); |
| 820 | break; |
| 821 | |
| 822 | case Instruction::INT_TO_CHAR: |
| 823 | EmitInsn_TruncAndZExt(ARGS, 16); |
| 824 | break; |
| 825 | |
| 826 | case Instruction::INT_TO_SHORT: |
| 827 | EmitInsn_TruncAndSExt(ARGS, 16); |
| 828 | break; |
| 829 | |
| 830 | case Instruction::ADD_INT: |
| 831 | EmitInsn_IntArithm(ARGS, kIntArithm_Add, kInt, false); |
| 832 | break; |
| 833 | |
| 834 | case Instruction::SUB_INT: |
| 835 | EmitInsn_IntArithm(ARGS, kIntArithm_Sub, kInt, false); |
| 836 | break; |
| 837 | |
| 838 | case Instruction::MUL_INT: |
| 839 | EmitInsn_IntArithm(ARGS, kIntArithm_Mul, kInt, false); |
| 840 | break; |
| 841 | |
| 842 | case Instruction::DIV_INT: |
| 843 | EmitInsn_IntArithm(ARGS, kIntArithm_Div, kInt, false); |
| 844 | break; |
| 845 | |
| 846 | case Instruction::REM_INT: |
| 847 | EmitInsn_IntArithm(ARGS, kIntArithm_Rem, kInt, false); |
| 848 | break; |
| 849 | |
| 850 | case Instruction::AND_INT: |
| 851 | EmitInsn_IntArithm(ARGS, kIntArithm_And, kInt, false); |
| 852 | break; |
| 853 | |
| 854 | case Instruction::OR_INT: |
| 855 | EmitInsn_IntArithm(ARGS, kIntArithm_Or, kInt, false); |
| 856 | break; |
| 857 | |
| 858 | case Instruction::XOR_INT: |
| 859 | EmitInsn_IntArithm(ARGS, kIntArithm_Xor, kInt, false); |
| 860 | break; |
| 861 | |
| 862 | case Instruction::SHL_INT: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 863 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shl, kInt, false); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case Instruction::SHR_INT: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 867 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shr, kInt, false); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case Instruction::USHR_INT: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 871 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_UShr, kInt, false); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case Instruction::ADD_LONG: |
| 875 | EmitInsn_IntArithm(ARGS, kIntArithm_Add, kLong, false); |
| 876 | break; |
| 877 | |
| 878 | case Instruction::SUB_LONG: |
| 879 | EmitInsn_IntArithm(ARGS, kIntArithm_Sub, kLong, false); |
| 880 | break; |
| 881 | |
| 882 | case Instruction::MUL_LONG: |
| 883 | EmitInsn_IntArithm(ARGS, kIntArithm_Mul, kLong, false); |
| 884 | break; |
| 885 | |
| 886 | case Instruction::DIV_LONG: |
| 887 | EmitInsn_IntArithm(ARGS, kIntArithm_Div, kLong, false); |
| 888 | break; |
| 889 | |
| 890 | case Instruction::REM_LONG: |
| 891 | EmitInsn_IntArithm(ARGS, kIntArithm_Rem, kLong, false); |
| 892 | break; |
| 893 | |
| 894 | case Instruction::AND_LONG: |
| 895 | EmitInsn_IntArithm(ARGS, kIntArithm_And, kLong, false); |
| 896 | break; |
| 897 | |
| 898 | case Instruction::OR_LONG: |
| 899 | EmitInsn_IntArithm(ARGS, kIntArithm_Or, kLong, false); |
| 900 | break; |
| 901 | |
| 902 | case Instruction::XOR_LONG: |
| 903 | EmitInsn_IntArithm(ARGS, kIntArithm_Xor, kLong, false); |
| 904 | break; |
| 905 | |
| 906 | case Instruction::SHL_LONG: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 907 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shl, kLong, false); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 908 | break; |
| 909 | |
| 910 | case Instruction::SHR_LONG: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 911 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shr, kLong, false); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case Instruction::USHR_LONG: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 915 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_UShr, kLong, false); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case Instruction::ADD_FLOAT: |
| 919 | EmitInsn_FPArithm(ARGS, kFPArithm_Add, kFloat, false); |
| 920 | break; |
| 921 | |
| 922 | case Instruction::SUB_FLOAT: |
| 923 | EmitInsn_FPArithm(ARGS, kFPArithm_Sub, kFloat, false); |
| 924 | break; |
| 925 | |
| 926 | case Instruction::MUL_FLOAT: |
| 927 | EmitInsn_FPArithm(ARGS, kFPArithm_Mul, kFloat, false); |
| 928 | break; |
| 929 | |
| 930 | case Instruction::DIV_FLOAT: |
| 931 | EmitInsn_FPArithm(ARGS, kFPArithm_Div, kFloat, false); |
| 932 | break; |
| 933 | |
| 934 | case Instruction::REM_FLOAT: |
| 935 | EmitInsn_FPArithm(ARGS, kFPArithm_Rem, kFloat, false); |
| 936 | break; |
| 937 | |
| 938 | case Instruction::ADD_DOUBLE: |
| 939 | EmitInsn_FPArithm(ARGS, kFPArithm_Add, kDouble, false); |
| 940 | break; |
| 941 | |
| 942 | case Instruction::SUB_DOUBLE: |
| 943 | EmitInsn_FPArithm(ARGS, kFPArithm_Sub, kDouble, false); |
| 944 | break; |
| 945 | |
| 946 | case Instruction::MUL_DOUBLE: |
| 947 | EmitInsn_FPArithm(ARGS, kFPArithm_Mul, kDouble, false); |
| 948 | break; |
| 949 | |
| 950 | case Instruction::DIV_DOUBLE: |
| 951 | EmitInsn_FPArithm(ARGS, kFPArithm_Div, kDouble, false); |
| 952 | break; |
| 953 | |
| 954 | case Instruction::REM_DOUBLE: |
| 955 | EmitInsn_FPArithm(ARGS, kFPArithm_Rem, kDouble, false); |
| 956 | break; |
| 957 | |
| 958 | case Instruction::ADD_INT_2ADDR: |
| 959 | EmitInsn_IntArithm(ARGS, kIntArithm_Add, kInt, true); |
| 960 | break; |
| 961 | |
| 962 | case Instruction::SUB_INT_2ADDR: |
| 963 | EmitInsn_IntArithm(ARGS, kIntArithm_Sub, kInt, true); |
| 964 | break; |
| 965 | |
| 966 | case Instruction::MUL_INT_2ADDR: |
| 967 | EmitInsn_IntArithm(ARGS, kIntArithm_Mul, kInt, true); |
| 968 | break; |
| 969 | |
| 970 | case Instruction::DIV_INT_2ADDR: |
| 971 | EmitInsn_IntArithm(ARGS, kIntArithm_Div, kInt, true); |
| 972 | break; |
| 973 | |
| 974 | case Instruction::REM_INT_2ADDR: |
| 975 | EmitInsn_IntArithm(ARGS, kIntArithm_Rem, kInt, true); |
| 976 | break; |
| 977 | |
| 978 | case Instruction::AND_INT_2ADDR: |
| 979 | EmitInsn_IntArithm(ARGS, kIntArithm_And, kInt, true); |
| 980 | break; |
| 981 | |
| 982 | case Instruction::OR_INT_2ADDR: |
| 983 | EmitInsn_IntArithm(ARGS, kIntArithm_Or, kInt, true); |
| 984 | break; |
| 985 | |
| 986 | case Instruction::XOR_INT_2ADDR: |
| 987 | EmitInsn_IntArithm(ARGS, kIntArithm_Xor, kInt, true); |
| 988 | break; |
| 989 | |
| 990 | case Instruction::SHL_INT_2ADDR: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 991 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shl, kInt, true); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 992 | break; |
| 993 | |
| 994 | case Instruction::SHR_INT_2ADDR: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 995 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shr, kInt, true); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 996 | break; |
| 997 | |
| 998 | case Instruction::USHR_INT_2ADDR: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 999 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_UShr, kInt, true); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1000 | break; |
| 1001 | |
| 1002 | case Instruction::ADD_LONG_2ADDR: |
| 1003 | EmitInsn_IntArithm(ARGS, kIntArithm_Add, kLong, true); |
| 1004 | break; |
| 1005 | |
| 1006 | case Instruction::SUB_LONG_2ADDR: |
| 1007 | EmitInsn_IntArithm(ARGS, kIntArithm_Sub, kLong, true); |
| 1008 | break; |
| 1009 | |
| 1010 | case Instruction::MUL_LONG_2ADDR: |
| 1011 | EmitInsn_IntArithm(ARGS, kIntArithm_Mul, kLong, true); |
| 1012 | break; |
| 1013 | |
| 1014 | case Instruction::DIV_LONG_2ADDR: |
| 1015 | EmitInsn_IntArithm(ARGS, kIntArithm_Div, kLong, true); |
| 1016 | break; |
| 1017 | |
| 1018 | case Instruction::REM_LONG_2ADDR: |
| 1019 | EmitInsn_IntArithm(ARGS, kIntArithm_Rem, kLong, true); |
| 1020 | break; |
| 1021 | |
| 1022 | case Instruction::AND_LONG_2ADDR: |
| 1023 | EmitInsn_IntArithm(ARGS, kIntArithm_And, kLong, true); |
| 1024 | break; |
| 1025 | |
| 1026 | case Instruction::OR_LONG_2ADDR: |
| 1027 | EmitInsn_IntArithm(ARGS, kIntArithm_Or, kLong, true); |
| 1028 | break; |
| 1029 | |
| 1030 | case Instruction::XOR_LONG_2ADDR: |
| 1031 | EmitInsn_IntArithm(ARGS, kIntArithm_Xor, kLong, true); |
| 1032 | break; |
| 1033 | |
| 1034 | case Instruction::SHL_LONG_2ADDR: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 1035 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shl, kLong, true); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1036 | break; |
| 1037 | |
| 1038 | case Instruction::SHR_LONG_2ADDR: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 1039 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_Shr, kLong, true); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1040 | break; |
| 1041 | |
| 1042 | case Instruction::USHR_LONG_2ADDR: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 1043 | EmitInsn_IntShiftArithm(ARGS, kIntArithm_UShr, kLong, true); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1044 | break; |
| 1045 | |
| 1046 | case Instruction::ADD_FLOAT_2ADDR: |
| 1047 | EmitInsn_FPArithm(ARGS, kFPArithm_Add, kFloat, true); |
| 1048 | break; |
| 1049 | |
| 1050 | case Instruction::SUB_FLOAT_2ADDR: |
| 1051 | EmitInsn_FPArithm(ARGS, kFPArithm_Sub, kFloat, true); |
| 1052 | break; |
| 1053 | |
| 1054 | case Instruction::MUL_FLOAT_2ADDR: |
| 1055 | EmitInsn_FPArithm(ARGS, kFPArithm_Mul, kFloat, true); |
| 1056 | break; |
| 1057 | |
| 1058 | case Instruction::DIV_FLOAT_2ADDR: |
| 1059 | EmitInsn_FPArithm(ARGS, kFPArithm_Div, kFloat, true); |
| 1060 | break; |
| 1061 | |
| 1062 | case Instruction::REM_FLOAT_2ADDR: |
| 1063 | EmitInsn_FPArithm(ARGS, kFPArithm_Rem, kFloat, true); |
| 1064 | break; |
| 1065 | |
| 1066 | case Instruction::ADD_DOUBLE_2ADDR: |
| 1067 | EmitInsn_FPArithm(ARGS, kFPArithm_Add, kDouble, true); |
| 1068 | break; |
| 1069 | |
| 1070 | case Instruction::SUB_DOUBLE_2ADDR: |
| 1071 | EmitInsn_FPArithm(ARGS, kFPArithm_Sub, kDouble, true); |
| 1072 | break; |
| 1073 | |
| 1074 | case Instruction::MUL_DOUBLE_2ADDR: |
| 1075 | EmitInsn_FPArithm(ARGS, kFPArithm_Mul, kDouble, true); |
| 1076 | break; |
| 1077 | |
| 1078 | case Instruction::DIV_DOUBLE_2ADDR: |
| 1079 | EmitInsn_FPArithm(ARGS, kFPArithm_Div, kDouble, true); |
| 1080 | break; |
| 1081 | |
| 1082 | case Instruction::REM_DOUBLE_2ADDR: |
| 1083 | EmitInsn_FPArithm(ARGS, kFPArithm_Rem, kDouble, true); |
| 1084 | break; |
| 1085 | |
| 1086 | case Instruction::ADD_INT_LIT16: |
| 1087 | case Instruction::ADD_INT_LIT8: |
| 1088 | EmitInsn_IntArithmImmediate(ARGS, kIntArithm_Add); |
| 1089 | break; |
| 1090 | |
| 1091 | case Instruction::RSUB_INT: |
| 1092 | case Instruction::RSUB_INT_LIT8: |
| 1093 | EmitInsn_RSubImmediate(ARGS); |
| 1094 | break; |
| 1095 | |
| 1096 | case Instruction::MUL_INT_LIT16: |
| 1097 | case Instruction::MUL_INT_LIT8: |
| 1098 | EmitInsn_IntArithmImmediate(ARGS, kIntArithm_Mul); |
| 1099 | break; |
| 1100 | |
| 1101 | case Instruction::DIV_INT_LIT16: |
| 1102 | case Instruction::DIV_INT_LIT8: |
| 1103 | EmitInsn_IntArithmImmediate(ARGS, kIntArithm_Div); |
| 1104 | break; |
| 1105 | |
| 1106 | case Instruction::REM_INT_LIT16: |
| 1107 | case Instruction::REM_INT_LIT8: |
| 1108 | EmitInsn_IntArithmImmediate(ARGS, kIntArithm_Rem); |
| 1109 | break; |
| 1110 | |
| 1111 | case Instruction::AND_INT_LIT16: |
| 1112 | case Instruction::AND_INT_LIT8: |
| 1113 | EmitInsn_IntArithmImmediate(ARGS, kIntArithm_And); |
| 1114 | break; |
| 1115 | |
| 1116 | case Instruction::OR_INT_LIT16: |
| 1117 | case Instruction::OR_INT_LIT8: |
| 1118 | EmitInsn_IntArithmImmediate(ARGS, kIntArithm_Or); |
| 1119 | break; |
| 1120 | |
| 1121 | case Instruction::XOR_INT_LIT16: |
| 1122 | case Instruction::XOR_INT_LIT8: |
| 1123 | EmitInsn_IntArithmImmediate(ARGS, kIntArithm_Xor); |
| 1124 | break; |
| 1125 | |
| 1126 | case Instruction::SHL_INT_LIT8: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 1127 | EmitInsn_IntShiftArithmImmediate(ARGS, kIntArithm_Shl); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1128 | break; |
| 1129 | |
| 1130 | case Instruction::SHR_INT_LIT8: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 1131 | EmitInsn_IntShiftArithmImmediate(ARGS, kIntArithm_Shr); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1132 | break; |
| 1133 | |
| 1134 | case Instruction::USHR_INT_LIT8: |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 1135 | EmitInsn_IntShiftArithmImmediate(ARGS, kIntArithm_UShr); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1136 | break; |
| 1137 | |
Logan Chien | 9e5f5c1 | 2012-04-10 13:51:45 +0800 | [diff] [blame] | 1138 | case Instruction::THROW_VERIFICATION_ERROR: |
| 1139 | EmitInsn_ThrowVerificationError(ARGS); |
| 1140 | break; |
| 1141 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1142 | case Instruction::UNUSED_3E: |
| 1143 | case Instruction::UNUSED_3F: |
| 1144 | case Instruction::UNUSED_40: |
| 1145 | case Instruction::UNUSED_41: |
| 1146 | case Instruction::UNUSED_42: |
| 1147 | case Instruction::UNUSED_43: |
| 1148 | case Instruction::UNUSED_73: |
| 1149 | case Instruction::UNUSED_79: |
| 1150 | case Instruction::UNUSED_7A: |
| 1151 | case Instruction::UNUSED_E3: |
| 1152 | case Instruction::UNUSED_E4: |
| 1153 | case Instruction::UNUSED_E5: |
| 1154 | case Instruction::UNUSED_E6: |
| 1155 | case Instruction::UNUSED_E7: |
| 1156 | case Instruction::UNUSED_E8: |
| 1157 | case Instruction::UNUSED_E9: |
| 1158 | case Instruction::UNUSED_EA: |
| 1159 | case Instruction::UNUSED_EB: |
| 1160 | case Instruction::UNUSED_EC: |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1161 | case Instruction::UNUSED_EE: |
| 1162 | case Instruction::UNUSED_EF: |
| 1163 | case Instruction::UNUSED_F0: |
| 1164 | case Instruction::UNUSED_F1: |
| 1165 | case Instruction::UNUSED_F2: |
| 1166 | case Instruction::UNUSED_F3: |
| 1167 | case Instruction::UNUSED_F4: |
| 1168 | case Instruction::UNUSED_F5: |
| 1169 | case Instruction::UNUSED_F6: |
| 1170 | case Instruction::UNUSED_F7: |
| 1171 | case Instruction::UNUSED_F8: |
| 1172 | case Instruction::UNUSED_F9: |
| 1173 | case Instruction::UNUSED_FA: |
| 1174 | case Instruction::UNUSED_FB: |
| 1175 | case Instruction::UNUSED_FC: |
| 1176 | case Instruction::UNUSED_FD: |
| 1177 | case Instruction::UNUSED_FE: |
| 1178 | case Instruction::UNUSED_FF: |
| 1179 | LOG(FATAL) << "Dex file contains UNUSED bytecode: " << insn->Opcode(); |
| 1180 | break; |
| 1181 | } |
| 1182 | |
| 1183 | #undef ARGS |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | void MethodCompiler::EmitInsn_Nop(uint32_t dex_pc, |
| 1188 | Instruction const* insn) { |
Logan Chien | e09a6b7 | 2011-12-27 17:50:21 +0800 | [diff] [blame] | 1189 | |
| 1190 | uint16_t insn_signature = code_item_->insns_[dex_pc]; |
| 1191 | |
| 1192 | if (insn_signature == Instruction::kPackedSwitchSignature || |
| 1193 | insn_signature == Instruction::kSparseSwitchSignature || |
| 1194 | insn_signature == Instruction::kArrayDataSignature) { |
| 1195 | irb_.CreateUnreachable(); |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 1196 | } else { |
Logan Chien | e09a6b7 | 2011-12-27 17:50:21 +0800 | [diff] [blame] | 1197 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1198 | } |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1202 | void MethodCompiler::EmitInsn_Move(uint32_t dex_pc, |
| 1203 | Instruction const* insn, |
| 1204 | JType jty) { |
Logan Chien | 4817313 | 2011-12-27 17:51:13 +0800 | [diff] [blame] | 1205 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1206 | DecodedInstruction dec_insn(insn); |
Logan Chien | 4817313 | 2011-12-27 17:51:13 +0800 | [diff] [blame] | 1207 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1208 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, jty, kReg); |
| 1209 | EmitStoreDalvikReg(dec_insn.vA, jty, kReg, src_value); |
Logan Chien | 4817313 | 2011-12-27 17:51:13 +0800 | [diff] [blame] | 1210 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1211 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1212 | } |
| 1213 | |
| 1214 | |
| 1215 | void MethodCompiler::EmitInsn_MoveResult(uint32_t dex_pc, |
| 1216 | Instruction const* insn, |
| 1217 | JType jty) { |
Logan Chien | 4817313 | 2011-12-27 17:51:13 +0800 | [diff] [blame] | 1218 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1219 | DecodedInstruction dec_insn(insn); |
Logan Chien | 4817313 | 2011-12-27 17:51:13 +0800 | [diff] [blame] | 1220 | |
| 1221 | llvm::Value* src_value = EmitLoadDalvikRetValReg(jty, kReg); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1222 | EmitStoreDalvikReg(dec_insn.vA, jty, kReg, src_value); |
Logan Chien | 4817313 | 2011-12-27 17:51:13 +0800 | [diff] [blame] | 1223 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1224 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | void MethodCompiler::EmitInsn_MoveException(uint32_t dex_pc, |
| 1229 | Instruction const* insn) { |
Logan Chien | 3354cec | 2012-01-13 14:29:03 +0800 | [diff] [blame] | 1230 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1231 | DecodedInstruction dec_insn(insn); |
Logan Chien | 3354cec | 2012-01-13 14:29:03 +0800 | [diff] [blame] | 1232 | |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 1233 | // Get thread |
Logan Chien | 3354cec | 2012-01-13 14:29:03 +0800 | [diff] [blame] | 1234 | llvm::Value* thread_object_addr = |
| 1235 | irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 1236 | |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 1237 | // Get thread-local exception field address |
| 1238 | llvm::Value* exception_object_addr = |
| 1239 | irb_.LoadFromObjectOffset(thread_object_addr, |
| 1240 | Thread::ExceptionOffset().Int32Value(), |
| 1241 | irb_.getJObjectTy()); |
Logan Chien | 3354cec | 2012-01-13 14:29:03 +0800 | [diff] [blame] | 1242 | |
| 1243 | // Set thread-local exception field address to NULL |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 1244 | irb_.StoreToObjectOffset(thread_object_addr, |
| 1245 | Thread::ExceptionOffset().Int32Value(), |
| 1246 | irb_.getJNull()); |
Logan Chien | 3354cec | 2012-01-13 14:29:03 +0800 | [diff] [blame] | 1247 | |
| 1248 | // Keep the exception object in the Dalvik register |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1249 | EmitStoreDalvikReg(dec_insn.vA, kObject, kAccurate, exception_object_addr); |
Logan Chien | 3354cec | 2012-01-13 14:29:03 +0800 | [diff] [blame] | 1250 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1251 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | void MethodCompiler::EmitInsn_ThrowException(uint32_t dex_pc, |
| 1256 | Instruction const* insn) { |
Logan Chien | 6c6f12d | 2012-01-13 19:26:27 +0800 | [diff] [blame] | 1257 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1258 | DecodedInstruction dec_insn(insn); |
Logan Chien | 6c6f12d | 2012-01-13 19:26:27 +0800 | [diff] [blame] | 1259 | |
| 1260 | llvm::Value* exception_addr = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1261 | EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | 6c6f12d | 2012-01-13 19:26:27 +0800 | [diff] [blame] | 1262 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1263 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1264 | |
Logan Chien | 6c6f12d | 2012-01-13 19:26:27 +0800 | [diff] [blame] | 1265 | irb_.CreateCall(irb_.GetRuntime(ThrowException), exception_addr); |
| 1266 | |
| 1267 | EmitBranchExceptionLandingPad(dex_pc); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | |
Logan Chien | 9e5f5c1 | 2012-04-10 13:51:45 +0800 | [diff] [blame] | 1271 | void MethodCompiler::EmitInsn_ThrowVerificationError(uint32_t dex_pc, |
| 1272 | Instruction const* insn) { |
| 1273 | |
| 1274 | DecodedInstruction dec_insn(insn); |
| 1275 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1276 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 9e5f5c1 | 2012-04-10 13:51:45 +0800 | [diff] [blame] | 1277 | |
| 1278 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1279 | llvm::Value* kind_value = irb_.getInt32(dec_insn.vA); |
| 1280 | llvm::Value* ref_value = irb_.getInt32(dec_insn.vB); |
| 1281 | |
| 1282 | irb_.CreateCall3(irb_.GetRuntime(ThrowVerificationError), |
| 1283 | method_object_addr, kind_value, ref_value); |
| 1284 | |
| 1285 | EmitBranchExceptionLandingPad(dex_pc); |
| 1286 | } |
| 1287 | |
| 1288 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1289 | void MethodCompiler::EmitInsn_ReturnVoid(uint32_t dex_pc, |
| 1290 | Instruction const* insn) { |
Logan Chien | 8898a27 | 2011-12-27 17:51:56 +0800 | [diff] [blame] | 1291 | // Garbage collection safe-point |
| 1292 | EmitGuard_GarbageCollectionSuspend(dex_pc); |
| 1293 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1294 | // Pop the shadow frame |
| 1295 | EmitPopShadowFrame(); |
| 1296 | |
Logan Chien | 8898a27 | 2011-12-27 17:51:56 +0800 | [diff] [blame] | 1297 | // Return! |
| 1298 | irb_.CreateRetVoid(); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | |
| 1302 | void MethodCompiler::EmitInsn_Return(uint32_t dex_pc, |
| 1303 | Instruction const* insn) { |
Logan Chien | 8898a27 | 2011-12-27 17:51:56 +0800 | [diff] [blame] | 1304 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1305 | DecodedInstruction dec_insn(insn); |
Logan Chien | 8898a27 | 2011-12-27 17:51:56 +0800 | [diff] [blame] | 1306 | |
| 1307 | // Garbage collection safe-point |
| 1308 | EmitGuard_GarbageCollectionSuspend(dex_pc); |
| 1309 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1310 | // Pop the shadow frame |
| 1311 | EmitPopShadowFrame(); |
| 1312 | // NOTE: It is important to keep this AFTER the GC safe-point. Otherwise, |
| 1313 | // the return value might be collected since the shadow stack is popped. |
| 1314 | |
Logan Chien | 8898a27 | 2011-12-27 17:51:56 +0800 | [diff] [blame] | 1315 | // Return! |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1316 | char ret_shorty = oat_compilation_unit_->GetShorty()[0]; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1317 | llvm::Value* retval = EmitLoadDalvikReg(dec_insn.vA, ret_shorty, kAccurate); |
Logan Chien | 8898a27 | 2011-12-27 17:51:56 +0800 | [diff] [blame] | 1318 | |
| 1319 | irb_.CreateRet(retval); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | |
| 1323 | void MethodCompiler::EmitInsn_LoadConstant(uint32_t dex_pc, |
| 1324 | Instruction const* insn, |
| 1325 | JType imm_jty) { |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1326 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1327 | DecodedInstruction dec_insn(insn); |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1328 | |
| 1329 | DCHECK(imm_jty == kInt || imm_jty == kLong) << imm_jty; |
| 1330 | |
| 1331 | int64_t imm = 0; |
| 1332 | |
| 1333 | switch (insn->Opcode()) { |
| 1334 | // 32-bit Immediate |
| 1335 | case Instruction::CONST_4: |
| 1336 | case Instruction::CONST_16: |
| 1337 | case Instruction::CONST: |
| 1338 | case Instruction::CONST_WIDE_16: |
| 1339 | case Instruction::CONST_WIDE_32: |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1340 | imm = static_cast<int64_t>(static_cast<int32_t>(dec_insn.vB)); |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1341 | break; |
| 1342 | |
| 1343 | case Instruction::CONST_HIGH16: |
| 1344 | imm = static_cast<int64_t>(static_cast<int32_t>( |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1345 | static_cast<uint32_t>(static_cast<uint16_t>(dec_insn.vB)) << 16)); |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1346 | break; |
| 1347 | |
| 1348 | // 64-bit Immediate |
| 1349 | case Instruction::CONST_WIDE: |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1350 | imm = static_cast<int64_t>(dec_insn.vB_wide); |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1351 | break; |
| 1352 | |
| 1353 | case Instruction::CONST_WIDE_HIGH16: |
| 1354 | imm = static_cast<int64_t>( |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1355 | static_cast<uint64_t>(static_cast<uint16_t>(dec_insn.vB)) << 48); |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1356 | break; |
| 1357 | |
| 1358 | // Unknown opcode for load constant (unreachable) |
| 1359 | default: |
| 1360 | LOG(FATAL) << "Unknown opcode for load constant: " << insn->Opcode(); |
| 1361 | break; |
| 1362 | } |
| 1363 | |
| 1364 | // Store the non-object register |
| 1365 | llvm::Type* imm_type = irb_.getJType(imm_jty, kAccurate); |
| 1366 | llvm::Constant* imm_value = llvm::ConstantInt::getSigned(imm_type, imm); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1367 | EmitStoreDalvikReg(dec_insn.vA, imm_jty, kAccurate, imm_value); |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1368 | |
| 1369 | // Store the object register if it is possible to be null. |
| 1370 | if (imm_jty == kInt && imm == 0) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1371 | EmitStoreDalvikReg(dec_insn.vA, kObject, kAccurate, irb_.getJNull()); |
Shih-wei Liao | 798366e | 2012-02-16 09:25:33 -0800 | [diff] [blame] | 1372 | } |
| 1373 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1374 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | void MethodCompiler::EmitInsn_LoadConstantString(uint32_t dex_pc, |
| 1379 | Instruction const* insn) { |
Logan Chien | c3b4ba1 | 2012-01-16 19:52:53 +0800 | [diff] [blame] | 1380 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1381 | DecodedInstruction dec_insn(insn); |
Logan Chien | c3b4ba1 | 2012-01-16 19:52:53 +0800 | [diff] [blame] | 1382 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1383 | uint32_t string_idx = dec_insn.vB; |
Logan Chien | c3b4ba1 | 2012-01-16 19:52:53 +0800 | [diff] [blame] | 1384 | |
| 1385 | llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx); |
| 1386 | |
| 1387 | llvm::Value* string_addr = irb_.CreateLoad(string_field_addr); |
| 1388 | |
| 1389 | if (!compiler_->CanAssumeStringIsPresentInDexCache(dex_cache_, string_idx)) { |
| 1390 | llvm::BasicBlock* block_str_exist = |
| 1391 | CreateBasicBlockWithDexPC(dex_pc, "str_exist"); |
| 1392 | |
| 1393 | llvm::BasicBlock* block_str_resolve = |
| 1394 | CreateBasicBlockWithDexPC(dex_pc, "str_resolve"); |
| 1395 | |
| 1396 | // Test: Is the string resolved and in the dex cache? |
| 1397 | llvm::Value* equal_null = irb_.CreateICmpEQ(string_addr, irb_.getJNull()); |
| 1398 | |
TDYa127 | a849cb6 | 2012-04-01 05:59:34 -0700 | [diff] [blame] | 1399 | irb_.CreateCondBr(equal_null, block_str_resolve, block_str_exist); |
Logan Chien | c3b4ba1 | 2012-01-16 19:52:53 +0800 | [diff] [blame] | 1400 | |
| 1401 | // String is resolved, go to next basic block. |
| 1402 | irb_.SetInsertPoint(block_str_exist); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1403 | EmitStoreDalvikReg(dec_insn.vA, kObject, kAccurate, string_addr); |
Logan Chien | c3b4ba1 | 2012-01-16 19:52:53 +0800 | [diff] [blame] | 1404 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1405 | |
| 1406 | // String is not resolved yet, resolve it now. |
| 1407 | irb_.SetInsertPoint(block_str_resolve); |
| 1408 | |
| 1409 | llvm::Function* runtime_func = irb_.GetRuntime(ResolveString); |
| 1410 | |
| 1411 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1412 | |
| 1413 | llvm::Value* string_idx_value = irb_.getInt32(string_idx); |
| 1414 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1415 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1416 | |
| 1417 | string_addr = irb_.CreateCall2(runtime_func, method_object_addr, |
| 1418 | string_idx_value); |
Logan Chien | c3b4ba1 | 2012-01-16 19:52:53 +0800 | [diff] [blame] | 1419 | |
| 1420 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1421 | } |
| 1422 | |
| 1423 | // Store the string object to the Dalvik register |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1424 | EmitStoreDalvikReg(dec_insn.vA, kObject, kAccurate, string_addr); |
Logan Chien | c3b4ba1 | 2012-01-16 19:52:53 +0800 | [diff] [blame] | 1425 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1426 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1427 | } |
| 1428 | |
| 1429 | |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1430 | llvm::Value* MethodCompiler::EmitLoadConstantClass(uint32_t dex_pc, |
| 1431 | uint32_t type_idx) { |
| 1432 | if (!compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_, |
| 1433 | *dex_file_, type_idx)) { |
| 1434 | llvm::Value* type_idx_value = irb_.getInt32(type_idx); |
| 1435 | |
| 1436 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1437 | |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 1438 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 1439 | |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1440 | llvm::Function* runtime_func = |
| 1441 | irb_.GetRuntime(InitializeTypeAndVerifyAccess); |
| 1442 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1443 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1444 | |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1445 | llvm::Value* type_object_addr = |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 1446 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1447 | |
| 1448 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1449 | |
| 1450 | return type_object_addr; |
| 1451 | |
| 1452 | } else { |
| 1453 | // Try to load the class (type) object from the test cache. |
| 1454 | llvm::Value* type_field_addr = |
| 1455 | EmitLoadDexCacheResolvedTypeFieldAddr(type_idx); |
| 1456 | |
| 1457 | llvm::Value* type_object_addr = irb_.CreateLoad(type_field_addr); |
| 1458 | |
| 1459 | if (compiler_->CanAssumeTypeIsPresentInDexCache(dex_cache_, type_idx)) { |
| 1460 | return type_object_addr; |
| 1461 | } |
| 1462 | |
| 1463 | llvm::BasicBlock* block_original = irb_.GetInsertBlock(); |
| 1464 | |
| 1465 | // Test whether class (type) object is in the dex cache or not |
| 1466 | llvm::Value* equal_null = |
| 1467 | irb_.CreateICmpEQ(type_object_addr, irb_.getJNull()); |
| 1468 | |
| 1469 | llvm::BasicBlock* block_cont = |
| 1470 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 1471 | |
| 1472 | llvm::BasicBlock* block_load_class = |
| 1473 | CreateBasicBlockWithDexPC(dex_pc, "load_class"); |
| 1474 | |
| 1475 | irb_.CreateCondBr(equal_null, block_load_class, block_cont); |
| 1476 | |
| 1477 | // Failback routine to load the class object |
| 1478 | irb_.SetInsertPoint(block_load_class); |
| 1479 | |
| 1480 | llvm::Function* runtime_func = irb_.GetRuntime(InitializeType); |
| 1481 | |
| 1482 | llvm::Constant* type_idx_value = irb_.getInt32(type_idx); |
| 1483 | |
| 1484 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1485 | |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 1486 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 1487 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1488 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1489 | |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1490 | llvm::Value* loaded_type_object_addr = |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 1491 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1492 | |
| 1493 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1494 | |
| 1495 | llvm::BasicBlock* block_after_load_class = irb_.GetInsertBlock(); |
| 1496 | |
| 1497 | irb_.CreateBr(block_cont); |
| 1498 | |
| 1499 | // Now the class object must be loaded |
| 1500 | irb_.SetInsertPoint(block_cont); |
| 1501 | |
| 1502 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 1503 | |
| 1504 | phi->addIncoming(type_object_addr, block_original); |
| 1505 | phi->addIncoming(loaded_type_object_addr, block_after_load_class); |
| 1506 | |
| 1507 | return phi; |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1512 | void MethodCompiler::EmitInsn_LoadConstantClass(uint32_t dex_pc, |
| 1513 | Instruction const* insn) { |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1514 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1515 | DecodedInstruction dec_insn(insn); |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1516 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1517 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, dec_insn.vB); |
| 1518 | EmitStoreDalvikReg(dec_insn.vA, kObject, kAccurate, type_object_addr); |
Logan Chien | 27b3025 | 2012-01-14 03:43:35 +0800 | [diff] [blame] | 1519 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1520 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1521 | } |
| 1522 | |
| 1523 | |
| 1524 | void MethodCompiler::EmitInsn_MonitorEnter(uint32_t dex_pc, |
| 1525 | Instruction const* insn) { |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1526 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1527 | DecodedInstruction dec_insn(insn); |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1528 | |
| 1529 | llvm::Value* object_addr = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1530 | EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1531 | |
| 1532 | // TODO: Slow path always. May not need NullPointerException check. |
| 1533 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 1534 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1535 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1536 | |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 1537 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 1538 | |
| 1539 | irb_.CreateCall2(irb_.GetRuntime(LockObject), object_addr, thread_object_addr); |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1540 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1541 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1542 | } |
| 1543 | |
| 1544 | |
| 1545 | void MethodCompiler::EmitInsn_MonitorExit(uint32_t dex_pc, |
| 1546 | Instruction const* insn) { |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1547 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1548 | DecodedInstruction dec_insn(insn); |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1549 | |
| 1550 | llvm::Value* object_addr = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1551 | EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1552 | |
| 1553 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 1554 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1555 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1556 | |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 1557 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 1558 | |
| 1559 | irb_.CreateCall2(irb_.GetRuntime(UnlockObject), object_addr, thread_object_addr); |
Logan Chien | 9e0dbe4 | 2012-01-13 12:11:37 +0800 | [diff] [blame] | 1560 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1561 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1562 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1563 | } |
| 1564 | |
| 1565 | |
| 1566 | void MethodCompiler::EmitInsn_CheckCast(uint32_t dex_pc, |
| 1567 | Instruction const* insn) { |
Logan Chien | fc88095 | 2012-01-15 23:53:10 +0800 | [diff] [blame] | 1568 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1569 | DecodedInstruction dec_insn(insn); |
Logan Chien | fc88095 | 2012-01-15 23:53:10 +0800 | [diff] [blame] | 1570 | |
| 1571 | llvm::BasicBlock* block_test_class = |
| 1572 | CreateBasicBlockWithDexPC(dex_pc, "test_class"); |
| 1573 | |
| 1574 | llvm::BasicBlock* block_test_sub_class = |
| 1575 | CreateBasicBlockWithDexPC(dex_pc, "test_sub_class"); |
| 1576 | |
| 1577 | llvm::Value* object_addr = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1578 | EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | fc88095 | 2012-01-15 23:53:10 +0800 | [diff] [blame] | 1579 | |
| 1580 | // Test: Is the reference equal to null? Act as no-op when it is null. |
| 1581 | llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull()); |
| 1582 | |
| 1583 | irb_.CreateCondBr(equal_null, |
| 1584 | GetNextBasicBlock(dex_pc), |
| 1585 | block_test_class); |
| 1586 | |
| 1587 | // Test: Is the object instantiated from the given class? |
| 1588 | irb_.SetInsertPoint(block_test_class); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1589 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, dec_insn.vB); |
Logan Chien | fc88095 | 2012-01-15 23:53:10 +0800 | [diff] [blame] | 1590 | DCHECK_EQ(Object::ClassOffset().Int32Value(), 0); |
| 1591 | |
| 1592 | llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy(); |
| 1593 | |
| 1594 | llvm::Value* object_type_field_addr = |
| 1595 | irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo()); |
| 1596 | |
| 1597 | llvm::Value* object_type_object_addr = |
| 1598 | irb_.CreateLoad(object_type_field_addr); |
| 1599 | |
| 1600 | llvm::Value* equal_class = |
| 1601 | irb_.CreateICmpEQ(type_object_addr, object_type_object_addr); |
| 1602 | |
| 1603 | irb_.CreateCondBr(equal_class, |
| 1604 | GetNextBasicBlock(dex_pc), |
| 1605 | block_test_sub_class); |
| 1606 | |
| 1607 | // Test: Is the object instantiated from the subclass of the given class? |
| 1608 | irb_.SetInsertPoint(block_test_sub_class); |
| 1609 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1610 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1611 | |
Logan Chien | fc88095 | 2012-01-15 23:53:10 +0800 | [diff] [blame] | 1612 | irb_.CreateCall2(irb_.GetRuntime(CheckCast), |
| 1613 | type_object_addr, object_type_object_addr); |
| 1614 | |
| 1615 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1616 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1617 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1618 | } |
| 1619 | |
| 1620 | |
| 1621 | void MethodCompiler::EmitInsn_InstanceOf(uint32_t dex_pc, |
| 1622 | Instruction const* insn) { |
Logan Chien | 68725e2 | 2012-01-15 22:25:34 +0800 | [diff] [blame] | 1623 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1624 | DecodedInstruction dec_insn(insn); |
Logan Chien | 68725e2 | 2012-01-15 22:25:34 +0800 | [diff] [blame] | 1625 | |
| 1626 | llvm::Constant* zero = irb_.getJInt(0); |
| 1627 | llvm::Constant* one = irb_.getJInt(1); |
| 1628 | |
| 1629 | llvm::BasicBlock* block_nullp = CreateBasicBlockWithDexPC(dex_pc, "nullp"); |
| 1630 | |
| 1631 | llvm::BasicBlock* block_test_class = |
| 1632 | CreateBasicBlockWithDexPC(dex_pc, "test_class"); |
| 1633 | |
| 1634 | llvm::BasicBlock* block_class_equals = |
| 1635 | CreateBasicBlockWithDexPC(dex_pc, "class_eq"); |
| 1636 | |
| 1637 | llvm::BasicBlock* block_test_sub_class = |
| 1638 | CreateBasicBlockWithDexPC(dex_pc, "test_sub_class"); |
| 1639 | |
| 1640 | llvm::Value* object_addr = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1641 | EmitLoadDalvikReg(dec_insn.vB, kObject, kAccurate); |
Logan Chien | 68725e2 | 2012-01-15 22:25:34 +0800 | [diff] [blame] | 1642 | |
| 1643 | // Overview of the following code : |
| 1644 | // We check for null, if so, then false, otherwise check for class == . If so |
| 1645 | // then true, otherwise do callout slowpath. |
| 1646 | // |
| 1647 | // Test: Is the reference equal to null? Set 0 when it is null. |
| 1648 | llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull()); |
| 1649 | |
| 1650 | irb_.CreateCondBr(equal_null, block_nullp, block_test_class); |
| 1651 | |
| 1652 | irb_.SetInsertPoint(block_nullp); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1653 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, zero); |
Logan Chien | 68725e2 | 2012-01-15 22:25:34 +0800 | [diff] [blame] | 1654 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1655 | |
| 1656 | // Test: Is the object instantiated from the given class? |
| 1657 | irb_.SetInsertPoint(block_test_class); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1658 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, dec_insn.vC); |
Logan Chien | 68725e2 | 2012-01-15 22:25:34 +0800 | [diff] [blame] | 1659 | DCHECK_EQ(Object::ClassOffset().Int32Value(), 0); |
| 1660 | |
| 1661 | llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy(); |
| 1662 | |
| 1663 | llvm::Value* object_type_field_addr = |
| 1664 | irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo()); |
| 1665 | |
| 1666 | llvm::Value* object_type_object_addr = |
| 1667 | irb_.CreateLoad(object_type_field_addr); |
| 1668 | |
| 1669 | llvm::Value* equal_class = |
| 1670 | irb_.CreateICmpEQ(type_object_addr, object_type_object_addr); |
| 1671 | |
| 1672 | irb_.CreateCondBr(equal_class, block_class_equals, block_test_sub_class); |
| 1673 | |
| 1674 | irb_.SetInsertPoint(block_class_equals); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1675 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, one); |
Logan Chien | 68725e2 | 2012-01-15 22:25:34 +0800 | [diff] [blame] | 1676 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1677 | |
| 1678 | // Test: Is the object instantiated from the subclass of the given class? |
| 1679 | irb_.SetInsertPoint(block_test_sub_class); |
| 1680 | |
| 1681 | llvm::Value* result = |
| 1682 | irb_.CreateCall2(irb_.GetRuntime(IsAssignable), |
| 1683 | type_object_addr, object_type_object_addr); |
| 1684 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1685 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result); |
Logan Chien | 68725e2 | 2012-01-15 22:25:34 +0800 | [diff] [blame] | 1686 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1687 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1688 | } |
| 1689 | |
| 1690 | |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 1691 | llvm::Value* MethodCompiler::EmitLoadArrayLength(llvm::Value* array) { |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 1692 | // Load array length |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 1693 | return irb_.LoadFromObjectOffset(array, |
| 1694 | Array::LengthOffset().Int32Value(), |
| 1695 | irb_.getJIntTy()); |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1699 | void MethodCompiler::EmitInsn_ArrayLength(uint32_t dex_pc, |
| 1700 | Instruction const* insn) { |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 1701 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1702 | DecodedInstruction dec_insn(insn); |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 1703 | |
| 1704 | // Get the array object address |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1705 | llvm::Value* array_addr = EmitLoadDalvikReg(dec_insn.vB, kObject, kAccurate); |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 1706 | EmitGuard_NullPointerException(dex_pc, array_addr); |
| 1707 | |
| 1708 | // Get the array length and store it to the register |
| 1709 | llvm::Value* array_len = EmitLoadArrayLength(array_addr); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1710 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, array_len); |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 1711 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1712 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1713 | } |
| 1714 | |
| 1715 | |
| 1716 | void MethodCompiler::EmitInsn_NewInstance(uint32_t dex_pc, |
| 1717 | Instruction const* insn) { |
Logan Chien | 032bdad | 2012-01-16 09:59:23 +0800 | [diff] [blame] | 1718 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1719 | DecodedInstruction dec_insn(insn); |
Logan Chien | 032bdad | 2012-01-16 09:59:23 +0800 | [diff] [blame] | 1720 | |
| 1721 | llvm::Function* runtime_func; |
Logan Chien | 1a032b1 | 2012-04-11 11:43:04 +0800 | [diff] [blame] | 1722 | if (compiler_->CanAccessInstantiableTypeWithoutChecks( |
| 1723 | method_idx_, dex_cache_, *dex_file_, dec_insn.vB)) { |
Logan Chien | 032bdad | 2012-01-16 09:59:23 +0800 | [diff] [blame] | 1724 | runtime_func = irb_.GetRuntime(AllocObject); |
| 1725 | } else { |
| 1726 | runtime_func = irb_.GetRuntime(AllocObjectWithAccessCheck); |
| 1727 | } |
| 1728 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1729 | llvm::Constant* type_index_value = irb_.getInt32(dec_insn.vB); |
Logan Chien | 032bdad | 2012-01-16 09:59:23 +0800 | [diff] [blame] | 1730 | |
| 1731 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1732 | |
TDYa127 | da83d97 | 2012-04-18 00:21:49 -0700 | [diff] [blame] | 1733 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 1734 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1735 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1736 | |
Logan Chien | 032bdad | 2012-01-16 09:59:23 +0800 | [diff] [blame] | 1737 | llvm::Value* object_addr = |
TDYa127 | da83d97 | 2012-04-18 00:21:49 -0700 | [diff] [blame] | 1738 | irb_.CreateCall3(runtime_func, type_index_value, method_object_addr, thread_object_addr); |
Logan Chien | 032bdad | 2012-01-16 09:59:23 +0800 | [diff] [blame] | 1739 | |
| 1740 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1741 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1742 | EmitStoreDalvikReg(dec_insn.vA, kObject, kAccurate, object_addr); |
Logan Chien | 032bdad | 2012-01-16 09:59:23 +0800 | [diff] [blame] | 1743 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1744 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1745 | } |
| 1746 | |
| 1747 | |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1748 | llvm::Value* MethodCompiler::EmitAllocNewArray(uint32_t dex_pc, |
| 1749 | int32_t length, |
| 1750 | uint32_t type_idx, |
| 1751 | bool is_filled_new_array) { |
| 1752 | llvm::Function* runtime_func; |
| 1753 | |
| 1754 | bool skip_access_check = |
| 1755 | compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_, |
| 1756 | *dex_file_, type_idx); |
| 1757 | |
TDYa127 | a849cb6 | 2012-04-01 05:59:34 -0700 | [diff] [blame] | 1758 | llvm::Value* array_length_value; |
| 1759 | |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1760 | if (is_filled_new_array) { |
| 1761 | runtime_func = skip_access_check ? |
| 1762 | irb_.GetRuntime(CheckAndAllocArray) : |
| 1763 | irb_.GetRuntime(CheckAndAllocArrayWithAccessCheck); |
TDYa127 | a849cb6 | 2012-04-01 05:59:34 -0700 | [diff] [blame] | 1764 | array_length_value = irb_.getInt32(length); |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1765 | } else { |
| 1766 | runtime_func = skip_access_check ? |
| 1767 | irb_.GetRuntime(AllocArray) : |
| 1768 | irb_.GetRuntime(AllocArrayWithAccessCheck); |
TDYa127 | a849cb6 | 2012-04-01 05:59:34 -0700 | [diff] [blame] | 1769 | array_length_value = EmitLoadDalvikReg(length, kInt, kAccurate); |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | llvm::Constant* type_index_value = irb_.getInt32(type_idx); |
| 1773 | |
| 1774 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1775 | |
TDYa127 | da83d97 | 2012-04-18 00:21:49 -0700 | [diff] [blame] | 1776 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 1777 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 1778 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 1779 | |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1780 | llvm::Value* object_addr = |
TDYa127 | da83d97 | 2012-04-18 00:21:49 -0700 | [diff] [blame] | 1781 | irb_.CreateCall4(runtime_func, type_index_value, method_object_addr, |
| 1782 | array_length_value, thread_object_addr); |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1783 | |
| 1784 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1785 | |
| 1786 | return object_addr; |
| 1787 | } |
| 1788 | |
| 1789 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1790 | void MethodCompiler::EmitInsn_NewArray(uint32_t dex_pc, |
| 1791 | Instruction const* insn) { |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1792 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1793 | DecodedInstruction dec_insn(insn); |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1794 | |
| 1795 | llvm::Value* object_addr = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1796 | EmitAllocNewArray(dex_pc, dec_insn.vB, dec_insn.vC, false); |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1797 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1798 | EmitStoreDalvikReg(dec_insn.vA, kObject, kAccurate, object_addr); |
Logan Chien | a2cc6a3 | 2012-01-16 10:38:41 +0800 | [diff] [blame] | 1799 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1800 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1801 | } |
| 1802 | |
| 1803 | |
| 1804 | void MethodCompiler::EmitInsn_FilledNewArray(uint32_t dex_pc, |
| 1805 | Instruction const* insn, |
| 1806 | bool is_range) { |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1807 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1808 | DecodedInstruction dec_insn(insn); |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1809 | |
| 1810 | llvm::Value* object_addr = |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1811 | EmitAllocNewArray(dex_pc, dec_insn.vA, dec_insn.vB, true); |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1812 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1813 | if (dec_insn.vA > 0) { |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1814 | // Resolve the element type |
TDYa127 | 183cf26 | 2012-04-11 07:53:21 -0700 | [diff] [blame] | 1815 | Class* klass = dex_cache_->GetResolvedType(dec_insn.vB)->GetComponentType(); |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1816 | // TODO: Avoid the usage of the dex_cache_. Try to figure out a better |
| 1817 | // way to distinguish [I and [L. |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1818 | CHECK_NE(klass, static_cast<Class*>(NULL)); |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1819 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1820 | uint32_t alignment; |
| 1821 | llvm::Constant* elem_size; |
| 1822 | llvm::PointerType* field_type; |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1823 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1824 | // NOTE: Currently filled-new-array only supports 'L', '[', and 'I' |
| 1825 | // as the element, thus we are only checking 2 cases: primitive int and |
| 1826 | // non-primitive type. |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1827 | if (klass->IsPrimitiveInt()) { |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1828 | alignment = sizeof(int32_t); |
| 1829 | elem_size = irb_.getPtrEquivInt(sizeof(int32_t)); |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1830 | field_type = irb_.getJIntTy()->getPointerTo(); |
| 1831 | } else { |
| 1832 | CHECK(!klass->IsPrimitive()); |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1833 | alignment = irb_.getSizeOfPtrEquivInt(); |
| 1834 | elem_size = irb_.getSizeOfPtrEquivIntValue(); |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1835 | field_type = irb_.getJObjectTy()->getPointerTo(); |
| 1836 | } |
| 1837 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1838 | llvm::Value* data_field_offset = |
| 1839 | irb_.getPtrEquivInt(Array::DataOffset(alignment).Int32Value()); |
| 1840 | |
| 1841 | llvm::Value* data_field_addr = |
| 1842 | irb_.CreatePtrDisp(object_addr, data_field_offset, field_type); |
| 1843 | |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1844 | // TODO: Tune this code. Currently we are generating one instruction for |
| 1845 | // one element which may be very space consuming. Maybe changing to use |
| 1846 | // memcpy may help; however, since we can't guarantee that the alloca of |
| 1847 | // dalvik register are continuous, we can't perform such optimization yet. |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1848 | for (uint32_t i = 0; i < dec_insn.vA; ++i) { |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1849 | int reg_index; |
| 1850 | if (is_range) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1851 | reg_index = dec_insn.vC + i; |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1852 | } else { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1853 | reg_index = dec_insn.arg[i]; |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | llvm::Value* reg_value; |
| 1857 | if (klass->IsPrimitiveInt()) { |
| 1858 | reg_value = EmitLoadDalvikReg(reg_index, kInt, kAccurate); |
| 1859 | } else { |
| 1860 | reg_value = EmitLoadDalvikReg(reg_index, kObject, kAccurate); |
| 1861 | } |
| 1862 | |
| 1863 | irb_.CreateStore(reg_value, data_field_addr); |
| 1864 | |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 1865 | data_field_addr = |
| 1866 | irb_.CreatePtrDisp(data_field_addr, elem_size, field_type); |
Logan Chien | a85fb2f | 2012-01-16 12:52:56 +0800 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | EmitStoreDalvikRetValReg(kObject, kAccurate, object_addr); |
| 1871 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1872 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1873 | } |
| 1874 | |
| 1875 | |
| 1876 | void MethodCompiler::EmitInsn_FillArrayData(uint32_t dex_pc, |
| 1877 | Instruction const* insn) { |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1878 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1879 | DecodedInstruction dec_insn(insn); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1880 | |
| 1881 | // Read the payload |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1882 | int32_t payload_offset = static_cast<int32_t>(dex_pc) + |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1883 | static_cast<int32_t>(dec_insn.vB); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1884 | |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1885 | const Instruction::ArrayDataPayload* payload = |
| 1886 | reinterpret_cast<const Instruction::ArrayDataPayload*>( |
| 1887 | code_item_->insns_ + payload_offset); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1888 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1889 | // Load array object |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1890 | llvm::Value* array_addr = EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1891 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1892 | if (payload->element_count == 0) { |
| 1893 | // When the number of the elements in the payload is zero, we don't have |
| 1894 | // to copy any numbers. However, we should check whether the array object |
| 1895 | // address is equal to null or not. |
| 1896 | EmitGuard_NullPointerException(dex_pc, array_addr); |
| 1897 | } else { |
| 1898 | // To save the code size, we are going to call the runtime function to |
| 1899 | // copy the content from DexFile. |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1900 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1901 | // NOTE: We will check for the NullPointerException in the runtime. |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1902 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1903 | llvm::Function* runtime_func = irb_.GetRuntime(FillArrayData); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1904 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1905 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1906 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1907 | EmitUpdateDexPC(dex_pc); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1908 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1909 | irb_.CreateCall4(runtime_func, |
| 1910 | method_object_addr, irb_.getInt32(dex_pc), |
| 1911 | array_addr, irb_.getInt32(payload_offset)); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1912 | |
Logan Chien | 86f5067 | 2012-04-24 13:08:45 +0800 | [diff] [blame] | 1913 | EmitGuard_ExceptionLandingPad(dex_pc); |
Logan Chien | e58b658 | 2012-01-16 17:13:13 +0800 | [diff] [blame] | 1914 | } |
| 1915 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1916 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 1917 | } |
| 1918 | |
| 1919 | |
| 1920 | void MethodCompiler::EmitInsn_UnconditionalBranch(uint32_t dex_pc, |
| 1921 | Instruction const* insn) { |
Logan Chien | a466c16 | 2011-12-27 17:55:46 +0800 | [diff] [blame] | 1922 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1923 | DecodedInstruction dec_insn(insn); |
Logan Chien | a466c16 | 2011-12-27 17:55:46 +0800 | [diff] [blame] | 1924 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1925 | int32_t branch_offset = dec_insn.vA; |
Logan Chien | a466c16 | 2011-12-27 17:55:46 +0800 | [diff] [blame] | 1926 | |
| 1927 | if (branch_offset <= 0) { |
| 1928 | // Garbage collection safe-point on backward branch |
| 1929 | EmitGuard_GarbageCollectionSuspend(dex_pc); |
| 1930 | } |
| 1931 | |
| 1932 | irb_.CreateBr(GetBasicBlock(dex_pc + branch_offset)); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | |
| 1936 | void MethodCompiler::EmitInsn_PackedSwitch(uint32_t dex_pc, |
| 1937 | Instruction const* insn) { |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1938 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1939 | DecodedInstruction dec_insn(insn); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1940 | |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1941 | int32_t payload_offset = static_cast<int32_t>(dex_pc) + |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1942 | static_cast<int32_t>(dec_insn.vB); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1943 | |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1944 | const Instruction::PackedSwitchPayload* payload = |
| 1945 | reinterpret_cast<const Instruction::PackedSwitchPayload*>( |
| 1946 | code_item_->insns_ + payload_offset); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1947 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1948 | llvm::Value* value = EmitLoadDalvikReg(dec_insn.vA, kInt, kAccurate); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1949 | |
| 1950 | llvm::SwitchInst* sw = |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1951 | irb_.CreateSwitch(value, GetNextBasicBlock(dex_pc), payload->case_count); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1952 | |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1953 | for (uint16_t i = 0; i < payload->case_count; ++i) { |
| 1954 | sw->addCase(irb_.getInt32(payload->first_key + i), |
| 1955 | GetBasicBlock(dex_pc + payload->targets[i])); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1956 | } |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | |
| 1960 | void MethodCompiler::EmitInsn_SparseSwitch(uint32_t dex_pc, |
| 1961 | Instruction const* insn) { |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1962 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1963 | DecodedInstruction dec_insn(insn); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1964 | |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1965 | int32_t payload_offset = static_cast<int32_t>(dex_pc) + |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1966 | static_cast<int32_t>(dec_insn.vB); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1967 | |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1968 | const Instruction::SparseSwitchPayload* payload = |
| 1969 | reinterpret_cast<const Instruction::SparseSwitchPayload*>( |
| 1970 | code_item_->insns_ + payload_offset); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1971 | |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1972 | const int32_t* keys = payload->GetKeys(); |
| 1973 | const int32_t* targets = payload->GetTargets(); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1974 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1975 | llvm::Value* value = EmitLoadDalvikReg(dec_insn.vA, kInt, kAccurate); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1976 | |
| 1977 | llvm::SwitchInst* sw = |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1978 | irb_.CreateSwitch(value, GetNextBasicBlock(dex_pc), payload->case_count); |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1979 | |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 1980 | for (size_t i = 0; i < payload->case_count; ++i) { |
Logan Chien | 7a89b6d | 2011-12-27 17:56:56 +0800 | [diff] [blame] | 1981 | sw->addCase(irb_.getInt32(keys[i]), GetBasicBlock(dex_pc + targets[i])); |
| 1982 | } |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | |
| 1986 | void MethodCompiler::EmitInsn_FPCompare(uint32_t dex_pc, |
| 1987 | Instruction const* insn, |
| 1988 | JType fp_jty, |
| 1989 | bool gt_bias) { |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 1990 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1991 | DecodedInstruction dec_insn(insn); |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 1992 | |
| 1993 | DCHECK(fp_jty == kFloat || fp_jty == kDouble) << "JType: " << fp_jty; |
| 1994 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1995 | llvm::Value* src1_value = EmitLoadDalvikReg(dec_insn.vB, fp_jty, kAccurate); |
| 1996 | llvm::Value* src2_value = EmitLoadDalvikReg(dec_insn.vC, fp_jty, kAccurate); |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 1997 | |
| 1998 | llvm::Value* cmp_eq = irb_.CreateFCmpOEQ(src1_value, src2_value); |
| 1999 | llvm::Value* cmp_lt; |
| 2000 | |
| 2001 | if (gt_bias) { |
| 2002 | cmp_lt = irb_.CreateFCmpOLT(src1_value, src2_value); |
| 2003 | } else { |
| 2004 | cmp_lt = irb_.CreateFCmpULT(src1_value, src2_value); |
| 2005 | } |
| 2006 | |
| 2007 | llvm::Value* result = EmitCompareResultSelection(cmp_eq, cmp_lt); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2008 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result); |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 2009 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2010 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2011 | } |
| 2012 | |
| 2013 | |
| 2014 | void MethodCompiler::EmitInsn_LongCompare(uint32_t dex_pc, |
| 2015 | Instruction const* insn) { |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 2016 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2017 | DecodedInstruction dec_insn(insn); |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 2018 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2019 | llvm::Value* src1_value = EmitLoadDalvikReg(dec_insn.vB, kLong, kAccurate); |
| 2020 | llvm::Value* src2_value = EmitLoadDalvikReg(dec_insn.vC, kLong, kAccurate); |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 2021 | |
| 2022 | llvm::Value* cmp_eq = irb_.CreateICmpEQ(src1_value, src2_value); |
| 2023 | llvm::Value* cmp_lt = irb_.CreateICmpSLT(src1_value, src2_value); |
| 2024 | |
| 2025 | llvm::Value* result = EmitCompareResultSelection(cmp_eq, cmp_lt); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2026 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result); |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 2027 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2028 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2029 | } |
| 2030 | |
| 2031 | |
Logan Chien | 2c37e8e | 2011-12-27 17:58:46 +0800 | [diff] [blame] | 2032 | llvm::Value* MethodCompiler::EmitCompareResultSelection(llvm::Value* cmp_eq, |
| 2033 | llvm::Value* cmp_lt) { |
| 2034 | |
| 2035 | llvm::Constant* zero = irb_.getJInt(0); |
| 2036 | llvm::Constant* pos1 = irb_.getJInt(1); |
| 2037 | llvm::Constant* neg1 = irb_.getJInt(-1); |
| 2038 | |
| 2039 | llvm::Value* result_lt = irb_.CreateSelect(cmp_lt, neg1, pos1); |
| 2040 | llvm::Value* result_eq = irb_.CreateSelect(cmp_eq, zero, result_lt); |
| 2041 | |
| 2042 | return result_eq; |
| 2043 | } |
| 2044 | |
| 2045 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2046 | void MethodCompiler::EmitInsn_BinaryConditionalBranch(uint32_t dex_pc, |
| 2047 | Instruction const* insn, |
| 2048 | CondBranchKind cond) { |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2049 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2050 | DecodedInstruction dec_insn(insn); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2051 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2052 | int8_t src1_reg_cat = GetInferredRegCategory(dex_pc, dec_insn.vA); |
| 2053 | int8_t src2_reg_cat = GetInferredRegCategory(dex_pc, dec_insn.vB); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2054 | |
| 2055 | DCHECK_NE(kRegUnknown, src1_reg_cat); |
| 2056 | DCHECK_NE(kRegUnknown, src2_reg_cat); |
| 2057 | DCHECK_NE(kRegCat2, src1_reg_cat); |
| 2058 | DCHECK_NE(kRegCat2, src2_reg_cat); |
| 2059 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2060 | int32_t branch_offset = dec_insn.vC; |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2061 | |
| 2062 | if (branch_offset <= 0) { |
| 2063 | // Garbage collection safe-point on backward branch |
| 2064 | EmitGuard_GarbageCollectionSuspend(dex_pc); |
| 2065 | } |
| 2066 | |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2067 | llvm::Value* src1_value; |
| 2068 | llvm::Value* src2_value; |
| 2069 | |
TDYa127 | 8e9b449 | 2012-04-24 15:50:27 -0700 | [diff] [blame] | 2070 | if (src1_reg_cat == kRegZero && src2_reg_cat == kRegZero) { |
| 2071 | src1_value = irb_.getInt32(0); |
| 2072 | src2_value = irb_.getInt32(0); |
| 2073 | } else if (src1_reg_cat != kRegZero && src2_reg_cat != kRegZero) { |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2074 | CHECK_EQ(src1_reg_cat, src2_reg_cat); |
| 2075 | |
| 2076 | if (src1_reg_cat == kRegCat1nr) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2077 | src1_value = EmitLoadDalvikReg(dec_insn.vA, kInt, kAccurate); |
| 2078 | src2_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2079 | } else { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2080 | src1_value = EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
| 2081 | src2_value = EmitLoadDalvikReg(dec_insn.vB, kObject, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2082 | } |
| 2083 | } else { |
| 2084 | DCHECK(src1_reg_cat == kRegZero || |
| 2085 | src2_reg_cat == kRegZero); |
| 2086 | |
| 2087 | if (src1_reg_cat == kRegZero) { |
| 2088 | if (src2_reg_cat == kRegCat1nr) { |
| 2089 | src1_value = irb_.getJInt(0); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2090 | src2_value = EmitLoadDalvikReg(dec_insn.vA, kInt, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2091 | } else { |
| 2092 | src1_value = irb_.getJNull(); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2093 | src2_value = EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2094 | } |
| 2095 | } else { // src2_reg_cat == kRegZero |
| 2096 | if (src2_reg_cat == kRegCat1nr) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2097 | src1_value = EmitLoadDalvikReg(dec_insn.vA, kInt, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2098 | src2_value = irb_.getJInt(0); |
| 2099 | } else { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2100 | src1_value = EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2101 | src2_value = irb_.getJNull(); |
| 2102 | } |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | llvm::Value* cond_value = |
| 2107 | EmitConditionResult(src1_value, src2_value, cond); |
| 2108 | |
| 2109 | irb_.CreateCondBr(cond_value, |
| 2110 | GetBasicBlock(dex_pc + branch_offset), |
| 2111 | GetNextBasicBlock(dex_pc)); |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | |
| 2115 | void MethodCompiler::EmitInsn_UnaryConditionalBranch(uint32_t dex_pc, |
| 2116 | Instruction const* insn, |
| 2117 | CondBranchKind cond) { |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2118 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2119 | DecodedInstruction dec_insn(insn); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2120 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2121 | int8_t src_reg_cat = GetInferredRegCategory(dex_pc, dec_insn.vA); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2122 | |
| 2123 | DCHECK_NE(kRegUnknown, src_reg_cat); |
| 2124 | DCHECK_NE(kRegCat2, src_reg_cat); |
| 2125 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2126 | int32_t branch_offset = dec_insn.vB; |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2127 | |
| 2128 | if (branch_offset <= 0) { |
| 2129 | // Garbage collection safe-point on backward branch |
| 2130 | EmitGuard_GarbageCollectionSuspend(dex_pc); |
| 2131 | } |
| 2132 | |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2133 | llvm::Value* src1_value; |
| 2134 | llvm::Value* src2_value; |
| 2135 | |
TDYa127 | 8e9b449 | 2012-04-24 15:50:27 -0700 | [diff] [blame] | 2136 | if (src_reg_cat == kRegZero) { |
| 2137 | src1_value = irb_.getInt32(0); |
| 2138 | src2_value = irb_.getInt32(0); |
| 2139 | } else if (src_reg_cat == kRegCat1nr) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2140 | src1_value = EmitLoadDalvikReg(dec_insn.vA, kInt, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2141 | src2_value = irb_.getInt32(0); |
| 2142 | } else { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2143 | src1_value = EmitLoadDalvikReg(dec_insn.vA, kObject, kAccurate); |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2144 | src2_value = irb_.getJNull(); |
| 2145 | } |
| 2146 | |
| 2147 | llvm::Value* cond_value = |
| 2148 | EmitConditionResult(src1_value, src2_value, cond); |
| 2149 | |
| 2150 | irb_.CreateCondBr(cond_value, |
| 2151 | GetBasicBlock(dex_pc + branch_offset), |
| 2152 | GetNextBasicBlock(dex_pc)); |
| 2153 | } |
| 2154 | |
| 2155 | |
| 2156 | RegCategory MethodCompiler::GetInferredRegCategory(uint32_t dex_pc, |
| 2157 | uint16_t reg_idx) { |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 2158 | |
| 2159 | Compiler::MethodReference mref(dex_file_, method_idx_); |
| 2160 | |
| 2161 | InferredRegCategoryMap const* map = |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 2162 | verifier::MethodVerifier::GetInferredRegCategoryMap(mref); |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 2163 | |
Logan Chien | a78e3c8 | 2011-12-27 17:59:35 +0800 | [diff] [blame] | 2164 | CHECK_NE(map, static_cast<InferredRegCategoryMap*>(NULL)); |
| 2165 | |
| 2166 | return map->GetRegCategory(dex_pc, reg_idx); |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | llvm::Value* MethodCompiler::EmitConditionResult(llvm::Value* lhs, |
| 2171 | llvm::Value* rhs, |
| 2172 | CondBranchKind cond) { |
| 2173 | switch (cond) { |
| 2174 | case kCondBranch_EQ: |
| 2175 | return irb_.CreateICmpEQ(lhs, rhs); |
| 2176 | |
| 2177 | case kCondBranch_NE: |
| 2178 | return irb_.CreateICmpNE(lhs, rhs); |
| 2179 | |
| 2180 | case kCondBranch_LT: |
| 2181 | return irb_.CreateICmpSLT(lhs, rhs); |
| 2182 | |
| 2183 | case kCondBranch_GE: |
| 2184 | return irb_.CreateICmpSGE(lhs, rhs); |
| 2185 | |
| 2186 | case kCondBranch_GT: |
| 2187 | return irb_.CreateICmpSGT(lhs, rhs); |
| 2188 | |
| 2189 | case kCondBranch_LE: |
| 2190 | return irb_.CreateICmpSLE(lhs, rhs); |
| 2191 | |
| 2192 | default: // Unreachable |
| 2193 | LOG(FATAL) << "Unknown conditional branch kind: " << cond; |
| 2194 | return NULL; |
| 2195 | } |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2196 | } |
| 2197 | |
TDYa127 | 83bb662 | 2012-04-17 02:20:34 -0700 | [diff] [blame] | 2198 | void MethodCompiler::EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr) { |
| 2199 | // Using runtime support, let the target can override by InlineAssembly. |
| 2200 | llvm::Function* runtime_func = irb_.GetRuntime(MarkGCCard); |
| 2201 | |
| 2202 | irb_.CreateCall2(runtime_func, value, target_addr); |
| 2203 | } |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2204 | |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2205 | void |
| 2206 | MethodCompiler::EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc, |
| 2207 | llvm::Value* array, |
| 2208 | llvm::Value* index) { |
| 2209 | llvm::Value* array_len = EmitLoadArrayLength(array); |
| 2210 | |
| 2211 | llvm::Value* cmp = irb_.CreateICmpUGE(index, array_len); |
| 2212 | |
| 2213 | llvm::BasicBlock* block_exception = |
| 2214 | CreateBasicBlockWithDexPC(dex_pc, "overflow"); |
| 2215 | |
| 2216 | llvm::BasicBlock* block_continue = |
| 2217 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2218 | |
| 2219 | irb_.CreateCondBr(cmp, block_exception, block_continue); |
| 2220 | |
| 2221 | irb_.SetInsertPoint(block_exception); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2222 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2223 | EmitUpdateDexPC(dex_pc); |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2224 | irb_.CreateCall2(irb_.GetRuntime(ThrowIndexOutOfBounds), index, array_len); |
| 2225 | EmitBranchExceptionLandingPad(dex_pc); |
| 2226 | |
| 2227 | irb_.SetInsertPoint(block_continue); |
| 2228 | } |
| 2229 | |
| 2230 | |
| 2231 | void MethodCompiler::EmitGuard_ArrayException(uint32_t dex_pc, |
| 2232 | llvm::Value* array, |
| 2233 | llvm::Value* index) { |
| 2234 | EmitGuard_NullPointerException(dex_pc, array); |
| 2235 | EmitGuard_ArrayIndexOutOfBoundsException(dex_pc, array, index); |
| 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | // Emit Array GetElementPtr |
| 2240 | llvm::Value* MethodCompiler::EmitArrayGEP(llvm::Value* array_addr, |
| 2241 | llvm::Value* index_value, |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 2242 | llvm::Type* elem_type, |
| 2243 | JType elem_jty) { |
| 2244 | |
| 2245 | int data_offset; |
| 2246 | if (elem_jty == kLong || elem_jty == kDouble || |
| 2247 | (elem_jty == kObject && sizeof(uint64_t) == sizeof(Object*))) { |
| 2248 | data_offset = Array::DataOffset(sizeof(int64_t)).Int32Value(); |
| 2249 | } else { |
| 2250 | data_offset = Array::DataOffset(sizeof(int32_t)).Int32Value(); |
| 2251 | } |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2252 | |
| 2253 | llvm::Constant* data_offset_value = |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 2254 | irb_.getPtrEquivInt(data_offset); |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2255 | |
| 2256 | llvm::Value* array_data_addr = |
| 2257 | irb_.CreatePtrDisp(array_addr, data_offset_value, |
| 2258 | elem_type->getPointerTo()); |
| 2259 | |
| 2260 | return irb_.CreateGEP(array_data_addr, index_value); |
| 2261 | } |
| 2262 | |
| 2263 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2264 | void MethodCompiler::EmitInsn_AGet(uint32_t dex_pc, |
| 2265 | Instruction const* insn, |
| 2266 | JType elem_jty) { |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2267 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2268 | DecodedInstruction dec_insn(insn); |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2269 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2270 | llvm::Value* array_addr = EmitLoadDalvikReg(dec_insn.vB, kObject, kAccurate); |
| 2271 | llvm::Value* index_value = EmitLoadDalvikReg(dec_insn.vC, kInt, kAccurate); |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2272 | |
| 2273 | EmitGuard_ArrayException(dex_pc, array_addr, index_value); |
| 2274 | |
| 2275 | llvm::Type* elem_type = irb_.getJType(elem_jty, kArray); |
| 2276 | |
| 2277 | llvm::Value* array_elem_addr = |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 2278 | EmitArrayGEP(array_addr, index_value, elem_type, elem_jty); |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2279 | |
| 2280 | llvm::Value* array_elem_value = irb_.CreateLoad(array_elem_addr); |
| 2281 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2282 | EmitStoreDalvikReg(dec_insn.vA, elem_jty, kArray, array_elem_value); |
Logan Chien | e27fdbb | 2012-01-02 23:27:26 +0800 | [diff] [blame] | 2283 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2284 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2285 | } |
| 2286 | |
| 2287 | |
| 2288 | void MethodCompiler::EmitInsn_APut(uint32_t dex_pc, |
| 2289 | Instruction const* insn, |
| 2290 | JType elem_jty) { |
Logan Chien | 8dabb43 | 2012-01-02 23:29:32 +0800 | [diff] [blame] | 2291 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2292 | DecodedInstruction dec_insn(insn); |
Logan Chien | 8dabb43 | 2012-01-02 23:29:32 +0800 | [diff] [blame] | 2293 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2294 | llvm::Value* array_addr = EmitLoadDalvikReg(dec_insn.vB, kObject, kAccurate); |
| 2295 | llvm::Value* index_value = EmitLoadDalvikReg(dec_insn.vC, kInt, kAccurate); |
Logan Chien | 8dabb43 | 2012-01-02 23:29:32 +0800 | [diff] [blame] | 2296 | |
| 2297 | EmitGuard_ArrayException(dex_pc, array_addr, index_value); |
| 2298 | |
| 2299 | llvm::Type* elem_type = irb_.getJType(elem_jty, kArray); |
| 2300 | |
| 2301 | llvm::Value* array_elem_addr = |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 2302 | EmitArrayGEP(array_addr, index_value, elem_type, elem_jty); |
Logan Chien | 8dabb43 | 2012-01-02 23:29:32 +0800 | [diff] [blame] | 2303 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2304 | llvm::Value* new_value = EmitLoadDalvikReg(dec_insn.vA, elem_jty, kArray); |
Logan Chien | 8dabb43 | 2012-01-02 23:29:32 +0800 | [diff] [blame] | 2305 | |
TDYa127 | 83bb662 | 2012-04-17 02:20:34 -0700 | [diff] [blame] | 2306 | if (elem_jty == kObject) { // If put an object, check the type, and mark GC card table. |
TDYa127 | 1b86d07 | 2012-04-05 17:38:56 -0700 | [diff] [blame] | 2307 | llvm::Function* runtime_func = irb_.GetRuntime(CheckPutArrayElement); |
| 2308 | |
| 2309 | irb_.CreateCall2(runtime_func, new_value, array_addr); |
| 2310 | |
| 2311 | EmitGuard_ExceptionLandingPad(dex_pc); |
TDYa127 | 83bb662 | 2012-04-17 02:20:34 -0700 | [diff] [blame] | 2312 | |
| 2313 | EmitMarkGCCard(new_value, array_addr); |
TDYa127 | 1b86d07 | 2012-04-05 17:38:56 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Logan Chien | 8dabb43 | 2012-01-02 23:29:32 +0800 | [diff] [blame] | 2316 | irb_.CreateStore(new_value, array_elem_addr); |
| 2317 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2318 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2319 | } |
| 2320 | |
| 2321 | |
| 2322 | void MethodCompiler::EmitInsn_IGet(uint32_t dex_pc, |
| 2323 | Instruction const* insn, |
| 2324 | JType field_jty) { |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2325 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2326 | DecodedInstruction dec_insn(insn); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2327 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2328 | uint32_t reg_idx = dec_insn.vB; |
| 2329 | uint32_t field_idx = dec_insn.vC; |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2330 | |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2331 | llvm::Value* object_addr = EmitLoadDalvikReg(reg_idx, kObject, kAccurate); |
| 2332 | |
| 2333 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 2334 | |
| 2335 | llvm::Value* field_value; |
| 2336 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2337 | int field_offset; |
| 2338 | bool is_volatile; |
| 2339 | bool is_fast_path = compiler_->ComputeInstanceFieldInfo( |
| 2340 | field_idx, oat_compilation_unit_, field_offset, is_volatile, false); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2341 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2342 | if (!is_fast_path) { |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2343 | llvm::Function* runtime_func; |
| 2344 | |
| 2345 | if (field_jty == kObject) { |
Logan Chien | 3b2b2e7 | 2012-03-06 16:11:45 +0800 | [diff] [blame] | 2346 | runtime_func = irb_.GetRuntime(GetObjectInstance); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2347 | } else if (field_jty == kLong || field_jty == kDouble) { |
Logan Chien | 3b2b2e7 | 2012-03-06 16:11:45 +0800 | [diff] [blame] | 2348 | runtime_func = irb_.GetRuntime(Get64Instance); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2349 | } else { |
Logan Chien | 3b2b2e7 | 2012-03-06 16:11:45 +0800 | [diff] [blame] | 2350 | runtime_func = irb_.GetRuntime(Get32Instance); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | llvm::ConstantInt* field_idx_value = irb_.getInt32(field_idx); |
| 2354 | |
| 2355 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2356 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2357 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2358 | |
Logan Chien | 3b2b2e7 | 2012-03-06 16:11:45 +0800 | [diff] [blame] | 2359 | field_value = irb_.CreateCall3(runtime_func, field_idx_value, |
| 2360 | method_object_addr, object_addr); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2361 | |
| 2362 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2363 | |
| 2364 | } else { |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2365 | DCHECK_GE(field_offset, 0); |
| 2366 | |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2367 | llvm::PointerType* field_type = |
| 2368 | irb_.getJType(field_jty, kField)->getPointerTo(); |
| 2369 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2370 | llvm::ConstantInt* field_offset_value = irb_.getPtrEquivInt(field_offset); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2371 | |
| 2372 | llvm::Value* field_addr = |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2373 | irb_.CreatePtrDisp(object_addr, field_offset_value, field_type); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2374 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2375 | // TODO: Check is_volatile. We need to generate atomic load instruction |
| 2376 | // when is_volatile is true. |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2377 | field_value = irb_.CreateLoad(field_addr); |
| 2378 | } |
| 2379 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2380 | EmitStoreDalvikReg(dec_insn.vA, field_jty, kField, field_value); |
Logan Chien | 48f1d2a | 2012-01-02 22:49:53 +0800 | [diff] [blame] | 2381 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2382 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2383 | } |
| 2384 | |
| 2385 | |
| 2386 | void MethodCompiler::EmitInsn_IPut(uint32_t dex_pc, |
| 2387 | Instruction const* insn, |
| 2388 | JType field_jty) { |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2389 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2390 | DecodedInstruction dec_insn(insn); |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2391 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2392 | uint32_t reg_idx = dec_insn.vB; |
| 2393 | uint32_t field_idx = dec_insn.vC; |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2394 | |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2395 | llvm::Value* object_addr = EmitLoadDalvikReg(reg_idx, kObject, kAccurate); |
| 2396 | |
| 2397 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 2398 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2399 | llvm::Value* new_value = EmitLoadDalvikReg(dec_insn.vA, field_jty, kField); |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2400 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2401 | int field_offset; |
| 2402 | bool is_volatile; |
| 2403 | bool is_fast_path = compiler_->ComputeInstanceFieldInfo( |
| 2404 | field_idx, oat_compilation_unit_, field_offset, is_volatile, true); |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2405 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2406 | if (!is_fast_path) { |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2407 | llvm::Function* runtime_func; |
| 2408 | |
| 2409 | if (field_jty == kObject) { |
| 2410 | runtime_func = irb_.GetRuntime(SetObjectInstance); |
| 2411 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 2412 | runtime_func = irb_.GetRuntime(Set64Instance); |
| 2413 | } else { |
| 2414 | runtime_func = irb_.GetRuntime(Set32Instance); |
| 2415 | } |
| 2416 | |
| 2417 | llvm::Value* field_idx_value = irb_.getInt32(field_idx); |
| 2418 | |
| 2419 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2420 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2421 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2422 | |
Logan Chien | 3b2b2e7 | 2012-03-06 16:11:45 +0800 | [diff] [blame] | 2423 | irb_.CreateCall4(runtime_func, field_idx_value, |
| 2424 | method_object_addr, object_addr, new_value); |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2425 | |
| 2426 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2427 | |
| 2428 | } else { |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2429 | DCHECK_GE(field_offset, 0); |
| 2430 | |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2431 | llvm::PointerType* field_type = |
| 2432 | irb_.getJType(field_jty, kField)->getPointerTo(); |
| 2433 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2434 | llvm::Value* field_offset_value = irb_.getPtrEquivInt(field_offset); |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2435 | |
| 2436 | llvm::Value* field_addr = |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2437 | irb_.CreatePtrDisp(object_addr, field_offset_value, field_type); |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2438 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2439 | // TODO: Check is_volatile. We need to generate atomic store instruction |
| 2440 | // when is_volatile is true. |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2441 | irb_.CreateStore(new_value, field_addr); |
TDYa127 | 83bb662 | 2012-04-17 02:20:34 -0700 | [diff] [blame] | 2442 | |
| 2443 | if (field_jty == kObject) { // If put an object, mark the GC card table. |
| 2444 | EmitMarkGCCard(new_value, object_addr); |
| 2445 | } |
Logan Chien | dd6aa87 | 2012-01-03 16:06:32 +0800 | [diff] [blame] | 2446 | } |
| 2447 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2448 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2449 | } |
| 2450 | |
| 2451 | |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2452 | llvm::Value* MethodCompiler::EmitLoadStaticStorage(uint32_t dex_pc, |
| 2453 | uint32_t type_idx) { |
| 2454 | llvm::BasicBlock* block_load_static = |
| 2455 | CreateBasicBlockWithDexPC(dex_pc, "load_static"); |
| 2456 | |
| 2457 | llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2458 | |
| 2459 | // Load static storage from dex cache |
| 2460 | llvm::Value* storage_field_addr = |
| 2461 | EmitLoadDexCacheStaticStorageFieldAddr(type_idx); |
| 2462 | |
| 2463 | llvm::Value* storage_object_addr = irb_.CreateLoad(storage_field_addr); |
| 2464 | |
| 2465 | llvm::BasicBlock* block_original = irb_.GetInsertBlock(); |
| 2466 | |
| 2467 | // Test: Is the static storage of this class initialized? |
| 2468 | llvm::Value* equal_null = |
| 2469 | irb_.CreateICmpEQ(storage_object_addr, irb_.getJNull()); |
| 2470 | |
| 2471 | irb_.CreateCondBr(equal_null, block_load_static, block_cont); |
| 2472 | |
| 2473 | // Failback routine to load the class object |
| 2474 | irb_.SetInsertPoint(block_load_static); |
| 2475 | |
| 2476 | llvm::Function* runtime_func = |
| 2477 | irb_.GetRuntime(InitializeStaticStorage); |
| 2478 | |
| 2479 | llvm::Constant* type_idx_value = irb_.getInt32(type_idx); |
| 2480 | |
| 2481 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2482 | |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 2483 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 2484 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2485 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2486 | |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2487 | llvm::Value* loaded_storage_object_addr = |
TDYa127 | 706e9b6 | 2012-04-19 12:24:26 -0700 | [diff] [blame] | 2488 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2489 | |
| 2490 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2491 | |
| 2492 | llvm::BasicBlock* block_after_load_static = irb_.GetInsertBlock(); |
| 2493 | |
| 2494 | irb_.CreateBr(block_cont); |
| 2495 | |
| 2496 | // Now the class object must be loaded |
| 2497 | irb_.SetInsertPoint(block_cont); |
| 2498 | |
| 2499 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 2500 | |
| 2501 | phi->addIncoming(storage_object_addr, block_original); |
| 2502 | phi->addIncoming(loaded_storage_object_addr, block_after_load_static); |
| 2503 | |
| 2504 | return phi; |
| 2505 | } |
| 2506 | |
| 2507 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2508 | void MethodCompiler::EmitInsn_SGet(uint32_t dex_pc, |
| 2509 | Instruction const* insn, |
| 2510 | JType field_jty) { |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2511 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2512 | DecodedInstruction dec_insn(insn); |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2513 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2514 | uint32_t field_idx = dec_insn.vB; |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2515 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2516 | int field_offset; |
| 2517 | int ssb_index; |
| 2518 | bool is_referrers_class; |
| 2519 | bool is_volatile; |
| 2520 | |
| 2521 | bool is_fast_path = compiler_->ComputeStaticFieldInfo( |
| 2522 | field_idx, oat_compilation_unit_, field_offset, ssb_index, |
| 2523 | is_referrers_class, is_volatile, false); |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2524 | |
| 2525 | llvm::Value* static_field_value; |
| 2526 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2527 | if (!is_fast_path) { |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2528 | llvm::Function* runtime_func; |
| 2529 | |
| 2530 | if (field_jty == kObject) { |
| 2531 | runtime_func = irb_.GetRuntime(GetObjectStatic); |
| 2532 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 2533 | runtime_func = irb_.GetRuntime(Get64Static); |
| 2534 | } else { |
| 2535 | runtime_func = irb_.GetRuntime(Get32Static); |
| 2536 | } |
| 2537 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2538 | llvm::Constant* field_idx_value = irb_.getInt32(dec_insn.vB); |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2539 | |
| 2540 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2541 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2542 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2543 | |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2544 | static_field_value = |
| 2545 | irb_.CreateCall2(runtime_func, field_idx_value, method_object_addr); |
| 2546 | |
| 2547 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2548 | |
| 2549 | } else { |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2550 | DCHECK_GE(field_offset, 0); |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2551 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2552 | llvm::Value* static_storage_addr = NULL; |
| 2553 | |
| 2554 | if (is_referrers_class) { |
| 2555 | // Fast path, static storage base is this method's class |
| 2556 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2557 | |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 2558 | static_storage_addr = |
| 2559 | irb_.LoadFromObjectOffset(method_object_addr, |
| 2560 | Method::DeclaringClassOffset().Int32Value(), |
| 2561 | irb_.getJObjectTy()); |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2562 | } else { |
| 2563 | // Medium path, static storage base in a different class which |
| 2564 | // requires checks that the other class is initialized |
| 2565 | DCHECK_GE(ssb_index, 0); |
| 2566 | static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index); |
| 2567 | } |
| 2568 | |
| 2569 | llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset); |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2570 | |
| 2571 | llvm::Value* static_field_addr = |
| 2572 | irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value, |
| 2573 | irb_.getJType(field_jty, kField)->getPointerTo()); |
| 2574 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2575 | // TODO: Check is_volatile. We need to generate atomic load instruction |
| 2576 | // when is_volatile is true. |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2577 | static_field_value = irb_.CreateLoad(static_field_addr); |
| 2578 | } |
| 2579 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2580 | EmitStoreDalvikReg(dec_insn.vA, field_jty, kField, static_field_value); |
Logan Chien | 438c4b6 | 2012-01-17 16:06:00 +0800 | [diff] [blame] | 2581 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2582 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2583 | } |
| 2584 | |
| 2585 | |
| 2586 | void MethodCompiler::EmitInsn_SPut(uint32_t dex_pc, |
| 2587 | Instruction const* insn, |
| 2588 | JType field_jty) { |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2589 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2590 | DecodedInstruction dec_insn(insn); |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2591 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2592 | uint32_t field_idx = dec_insn.vB; |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2593 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2594 | llvm::Value* new_value = EmitLoadDalvikReg(dec_insn.vA, field_jty, kField); |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2595 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2596 | int field_offset; |
| 2597 | int ssb_index; |
| 2598 | bool is_referrers_class; |
| 2599 | bool is_volatile; |
| 2600 | |
| 2601 | bool is_fast_path = compiler_->ComputeStaticFieldInfo( |
| 2602 | field_idx, oat_compilation_unit_, field_offset, ssb_index, |
| 2603 | is_referrers_class, is_volatile, true); |
| 2604 | |
| 2605 | if (!is_fast_path) { |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2606 | llvm::Function* runtime_func; |
| 2607 | |
| 2608 | if (field_jty == kObject) { |
| 2609 | runtime_func = irb_.GetRuntime(SetObjectStatic); |
| 2610 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 2611 | runtime_func = irb_.GetRuntime(Set64Static); |
| 2612 | } else { |
| 2613 | runtime_func = irb_.GetRuntime(Set32Static); |
| 2614 | } |
| 2615 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2616 | llvm::Constant* field_idx_value = irb_.getInt32(dec_insn.vB); |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2617 | |
| 2618 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2619 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2620 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2621 | |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2622 | irb_.CreateCall3(runtime_func, field_idx_value, |
| 2623 | method_object_addr, new_value); |
| 2624 | |
| 2625 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2626 | |
| 2627 | } else { |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2628 | DCHECK_GE(field_offset, 0); |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2629 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2630 | llvm::Value* static_storage_addr = NULL; |
| 2631 | |
| 2632 | if (is_referrers_class) { |
| 2633 | // Fast path, static storage base is this method's class |
| 2634 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2635 | |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 2636 | static_storage_addr = |
| 2637 | irb_.LoadFromObjectOffset(method_object_addr, |
| 2638 | Method::DeclaringClassOffset().Int32Value(), |
| 2639 | irb_.getJObjectTy()); |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2640 | } else { |
| 2641 | // Medium path, static storage base in a different class which |
| 2642 | // requires checks that the other class is initialized |
| 2643 | DCHECK_GE(ssb_index, 0); |
| 2644 | static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index); |
| 2645 | } |
| 2646 | |
| 2647 | llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset); |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2648 | |
| 2649 | llvm::Value* static_field_addr = |
| 2650 | irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value, |
| 2651 | irb_.getJType(field_jty, kField)->getPointerTo()); |
| 2652 | |
Logan Chien | 933abf8 | 2012-04-11 12:24:31 +0800 | [diff] [blame] | 2653 | // TODO: Check is_volatile. We need to generate atomic store instruction |
| 2654 | // when is_volatile is true. |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2655 | irb_.CreateStore(new_value, static_field_addr); |
TDYa127 | 83bb662 | 2012-04-17 02:20:34 -0700 | [diff] [blame] | 2656 | |
| 2657 | if (field_jty == kObject) { // If put an object, mark the GC card table. |
| 2658 | EmitMarkGCCard(new_value, static_storage_addr); |
| 2659 | } |
Logan Chien | 14179c8 | 2012-01-17 17:06:34 +0800 | [diff] [blame] | 2660 | } |
| 2661 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2662 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2663 | } |
| 2664 | |
| 2665 | |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2666 | void MethodCompiler:: |
| 2667 | EmitLoadActualParameters(std::vector<llvm::Value*>& args, |
| 2668 | uint32_t callee_method_idx, |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2669 | DecodedInstruction const& dec_insn, |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2670 | InvokeArgFmt arg_fmt, |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2671 | bool is_static) { |
| 2672 | |
| 2673 | // Get method signature |
| 2674 | DexFile::MethodId const& method_id = |
| 2675 | dex_file_->GetMethodId(callee_method_idx); |
| 2676 | |
Logan Chien | 8faf802 | 2012-02-24 12:25:29 +0800 | [diff] [blame] | 2677 | uint32_t shorty_size; |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2678 | char const* shorty = dex_file_->GetMethodShorty(method_id, &shorty_size); |
Logan Chien | 8faf802 | 2012-02-24 12:25:29 +0800 | [diff] [blame] | 2679 | CHECK_GE(shorty_size, 1u); |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2680 | |
| 2681 | // Load argument values according to the shorty (without "this") |
| 2682 | uint16_t reg_count = 0; |
| 2683 | |
| 2684 | if (!is_static) { |
| 2685 | ++reg_count; // skip the "this" pointer |
| 2686 | } |
| 2687 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2688 | bool is_range = (arg_fmt == kArgRange); |
| 2689 | |
Logan Chien | 8faf802 | 2012-02-24 12:25:29 +0800 | [diff] [blame] | 2690 | for (uint32_t i = 1; i < shorty_size; ++i) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2691 | uint32_t reg_idx = (is_range) ? (dec_insn.vC + reg_count) |
| 2692 | : (dec_insn.arg[reg_count]); |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2693 | |
| 2694 | args.push_back(EmitLoadDalvikReg(reg_idx, shorty[i], kAccurate)); |
| 2695 | |
| 2696 | ++reg_count; |
| 2697 | if (shorty[i] == 'J' || shorty[i] == 'D') { |
| 2698 | // Wide types, such as long and double, are using a pair of registers |
| 2699 | // to store the value, so we have to increase arg_reg again. |
| 2700 | ++reg_count; |
| 2701 | } |
| 2702 | } |
| 2703 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2704 | DCHECK_EQ(reg_count, dec_insn.vA) |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2705 | << "Actual argument mismatch for callee: " |
| 2706 | << PrettyMethod(callee_method_idx, *dex_file_); |
| 2707 | } |
| 2708 | |
TDYa127 | 0b686e5 | 2012-04-09 22:43:35 -0700 | [diff] [blame] | 2709 | llvm::Value* MethodCompiler::EmitFixStub(llvm::Value* callee_method_object_addr, |
| 2710 | uint32_t method_idx, |
| 2711 | bool is_static) { |
| 2712 | // TODO: Remove this after we solve the link and trampoline related problems. |
| 2713 | llvm::Value* code_addr = irb_.CreateCall(irb_.GetRuntime(FixStub), callee_method_object_addr); |
| 2714 | |
| 2715 | llvm::FunctionType* method_type = GetFunctionType(method_idx, is_static); |
| 2716 | |
| 2717 | return irb_.CreatePointerCast(code_addr, method_type->getPointerTo()); |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 2718 | } |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2719 | |
Shih-wei Liao | 399ed3f | 2012-03-08 01:27:04 -0800 | [diff] [blame] | 2720 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2721 | void MethodCompiler::EmitInsn_Invoke(uint32_t dex_pc, |
| 2722 | Instruction const* insn, |
| 2723 | InvokeType invoke_type, |
| 2724 | InvokeArgFmt arg_fmt) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 2725 | DecodedInstruction dec_insn(insn); |
Logan Chien | 46fbb41 | 2012-02-15 22:29:08 +0800 | [diff] [blame] | 2726 | |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 2727 | bool is_static = (invoke_type == kStatic); |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2728 | uint32_t callee_method_idx = dec_insn.vB; |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 2729 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2730 | // Compute invoke related information for compiler decision |
| 2731 | int vtable_idx = -1; |
Logan Chien | 92ad16d | 2012-03-18 05:48:55 +0800 | [diff] [blame] | 2732 | uintptr_t direct_code = 0; // Currently unused |
Logan Chien | fca6437 | 2012-04-23 14:57:01 +0800 | [diff] [blame] | 2733 | uintptr_t direct_method = 0; |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 2734 | bool is_fast_path = compiler_-> |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2735 | ComputeInvokeInfo(callee_method_idx, oat_compilation_unit_, |
Logan Chien | 92ad16d | 2012-03-18 05:48:55 +0800 | [diff] [blame] | 2736 | invoke_type, vtable_idx, direct_code, direct_method); |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 2737 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2738 | // Load *this* actual parameter |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2739 | llvm::Value* this_addr = NULL; |
| 2740 | |
| 2741 | if (!is_static) { |
| 2742 | // Test: Is *this* parameter equal to null? |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2743 | this_addr = (arg_fmt == kArgReg) ? |
| 2744 | EmitLoadDalvikReg(dec_insn.arg[0], kObject, kAccurate): |
| 2745 | EmitLoadDalvikReg(dec_insn.vC + 0, kObject, kAccurate); |
| 2746 | |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2747 | EmitGuard_NullPointerException(dex_pc, this_addr); |
| 2748 | } |
| 2749 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2750 | // Load the method object |
TDYa127 | 4e42a59 | 2012-04-10 20:13:54 -0700 | [diff] [blame] | 2751 | llvm::Value* callee_method_object_addr = NULL; |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2752 | |
| 2753 | if (!is_fast_path) { |
TDYa127 | 4e42a59 | 2012-04-10 20:13:54 -0700 | [diff] [blame] | 2754 | callee_method_object_addr = |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2755 | EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, invoke_type, |
| 2756 | this_addr, dex_pc, is_fast_path); |
| 2757 | } else { |
| 2758 | switch (invoke_type) { |
| 2759 | case kStatic: |
| 2760 | case kDirect: |
Logan Chien | fca6437 | 2012-04-23 14:57:01 +0800 | [diff] [blame] | 2761 | if (direct_method != 0u && |
| 2762 | direct_method != static_cast<uintptr_t>(-1)) { |
| 2763 | callee_method_object_addr = |
TDYa127 | 17826bf | 2012-04-24 01:15:10 -0700 | [diff] [blame] | 2764 | irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_method), |
| 2765 | irb_.getJObjectTy()); |
Logan Chien | fca6437 | 2012-04-23 14:57:01 +0800 | [diff] [blame] | 2766 | } else { |
| 2767 | callee_method_object_addr = |
| 2768 | EmitLoadSDCalleeMethodObjectAddr(callee_method_idx); |
| 2769 | } |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2770 | break; |
| 2771 | |
| 2772 | case kVirtual: |
| 2773 | DCHECK(vtable_idx != -1); |
TDYa127 | 4e42a59 | 2012-04-10 20:13:54 -0700 | [diff] [blame] | 2774 | callee_method_object_addr = |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2775 | EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr); |
| 2776 | break; |
| 2777 | |
| 2778 | case kSuper: |
| 2779 | LOG(FATAL) << "invoke-super should be promoted to invoke-direct in " |
| 2780 | "the fast path."; |
| 2781 | break; |
| 2782 | |
| 2783 | case kInterface: |
TDYa127 | 4e42a59 | 2012-04-10 20:13:54 -0700 | [diff] [blame] | 2784 | callee_method_object_addr = |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2785 | EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, |
| 2786 | invoke_type, this_addr, |
| 2787 | dex_pc, is_fast_path); |
| 2788 | break; |
| 2789 | } |
| 2790 | } |
| 2791 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2792 | llvm::Value* code_addr = |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 2793 | irb_.LoadFromObjectOffset(callee_method_object_addr, |
| 2794 | Method::GetCodeOffset().Int32Value(), |
| 2795 | GetFunctionType(callee_method_idx, is_static)->getPointerTo()); |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 2796 | |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2797 | // Load the actual parameter |
| 2798 | std::vector<llvm::Value*> args; |
| 2799 | |
| 2800 | args.push_back(callee_method_object_addr); // method object for callee |
| 2801 | |
| 2802 | if (!is_static) { |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2803 | DCHECK(this_addr != NULL); |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2804 | args.push_back(this_addr); // "this" object for callee |
| 2805 | } |
| 2806 | |
| 2807 | EmitLoadActualParameters(args, callee_method_idx, dec_insn, |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2808 | arg_fmt, is_static); |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2809 | |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2810 | #if 0 |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2811 | // Invoke callee |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2812 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2813 | llvm::Value* retval = irb_.CreateCall(code_addr, args); |
| 2814 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2815 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2816 | uint32_t callee_access_flags = is_static ? kAccStatic : 0; |
| 2817 | UniquePtr<OatCompilationUnit> callee_oat_compilation_unit( |
| 2818 | oat_compilation_unit_->GetCallee(callee_method_idx, callee_access_flags)); |
| 2819 | |
| 2820 | char ret_shorty = callee_oat_compilation_unit->GetShorty()[0]; |
Shih-wei Liao | 90d5099 | 2012-02-19 03:32:05 -0800 | [diff] [blame] | 2821 | if (ret_shorty != 'V') { |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2822 | EmitStoreDalvikRetValReg(ret_shorty, kAccurate, retval); |
| 2823 | } |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2824 | #else |
| 2825 | uint32_t callee_access_flags = is_static ? kAccStatic : 0; |
| 2826 | UniquePtr<OatCompilationUnit> callee_oat_compilation_unit( |
| 2827 | oat_compilation_unit_->GetCallee(callee_method_idx, callee_access_flags)); |
| 2828 | |
| 2829 | char ret_shorty = callee_oat_compilation_unit->GetShorty()[0]; |
| 2830 | |
| 2831 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2832 | EmitUpdateDexPC(dex_pc); |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2833 | |
| 2834 | |
| 2835 | llvm::BasicBlock* block_normal = CreateBasicBlockWithDexPC(dex_pc, "normal"); |
TDYa127 | ce15472 | 2012-04-21 16:43:29 -0700 | [diff] [blame] | 2836 | llvm::BasicBlock* block_stub = CreateBasicBlockWithDexPC(dex_pc, "stub"); |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2837 | llvm::BasicBlock* block_continue = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2838 | |
| 2839 | llvm::Type* accurate_ret_type = irb_.getJType(ret_shorty, kAccurate); |
| 2840 | llvm::Value* retval_addr = NULL; |
| 2841 | if (ret_shorty != 'V') { |
| 2842 | retval_addr = irb_.CreateAlloca(accurate_ret_type); |
| 2843 | } |
| 2844 | |
| 2845 | |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2846 | llvm::Value* code_addr_int = irb_.CreatePtrToInt(code_addr, irb_.getPtrEquivIntTy()); |
TDYa127 | ce15472 | 2012-04-21 16:43:29 -0700 | [diff] [blame] | 2847 | llvm::Value* max_stub_int = irb_.getPtrEquivInt(special_stub::kMaxSpecialStub); |
| 2848 | llvm::Value* is_stub = irb_.CreateICmpULT(code_addr_int, max_stub_int); |
| 2849 | irb_.CreateCondBr(is_stub, block_stub, block_normal); |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2850 | |
| 2851 | |
| 2852 | irb_.SetInsertPoint(block_normal); |
| 2853 | { |
| 2854 | // Invoke callee |
TDYa127 | ce15472 | 2012-04-21 16:43:29 -0700 | [diff] [blame] | 2855 | llvm::Value* retval = irb_.CreateCall(code_addr, args); |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2856 | if (ret_shorty != 'V') { |
TDYa127 | ce15472 | 2012-04-21 16:43:29 -0700 | [diff] [blame] | 2857 | EmitStoreDalvikRetValReg(ret_shorty, kAccurate, retval); |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2858 | } |
| 2859 | } |
| 2860 | irb_.CreateBr(block_continue); |
| 2861 | |
| 2862 | |
TDYa127 | ce15472 | 2012-04-21 16:43:29 -0700 | [diff] [blame] | 2863 | irb_.SetInsertPoint(block_stub); |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2864 | { |
TDYa127 | ce15472 | 2012-04-21 16:43:29 -0700 | [diff] [blame] | 2865 | { // lazy link |
| 2866 | // TODO: Remove this after we solve the link problem. |
| 2867 | llvm::BasicBlock* block_proxy_stub = CreateBasicBlockWithDexPC(dex_pc, "proxy"); |
| 2868 | llvm::BasicBlock* block_link = CreateBasicBlockWithDexPC(dex_pc, "link"); |
| 2869 | |
| 2870 | irb_.CreateCondBr(irb_.CreateIsNull(code_addr), block_link, block_proxy_stub); |
| 2871 | |
| 2872 | |
| 2873 | irb_.SetInsertPoint(block_link); |
| 2874 | code_addr = EmitFixStub(callee_method_object_addr, callee_method_idx, is_static); |
| 2875 | |
| 2876 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2877 | |
| 2878 | llvm::Value* retval = irb_.CreateCall(code_addr, args); |
| 2879 | if (ret_shorty != 'V') { |
| 2880 | EmitStoreDalvikRetValReg(ret_shorty, kAccurate, retval); |
| 2881 | } |
| 2882 | irb_.CreateBr(block_continue); |
| 2883 | |
| 2884 | |
| 2885 | irb_.SetInsertPoint(block_proxy_stub); |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2886 | } |
TDYa127 | ce15472 | 2012-04-21 16:43:29 -0700 | [diff] [blame] | 2887 | { // proxy stub |
| 2888 | llvm::Value* temp_space_addr; |
| 2889 | if (ret_shorty != 'V') { |
| 2890 | temp_space_addr = irb_.CreateAlloca(irb_.getJValueTy()); |
| 2891 | args.push_back(temp_space_addr); |
| 2892 | } |
| 2893 | // TODO: Remove this after we solve the proxy trampoline calling convention problem. |
| 2894 | irb_.CreateCall(irb_.GetRuntime(ProxyInvokeHandler), args); |
| 2895 | if (ret_shorty != 'V') { |
| 2896 | llvm::Value* result_addr = |
| 2897 | irb_.CreateBitCast(temp_space_addr, accurate_ret_type->getPointerTo()); |
| 2898 | llvm::Value* retval = irb_.CreateLoad(result_addr); |
| 2899 | EmitStoreDalvikRetValReg(ret_shorty, kAccurate, retval); |
| 2900 | } |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2901 | } |
| 2902 | } |
| 2903 | irb_.CreateBr(block_continue); |
| 2904 | |
| 2905 | |
| 2906 | irb_.SetInsertPoint(block_continue); |
| 2907 | |
TDYa127 | 5bb8601 | 2012-04-11 05:57:28 -0700 | [diff] [blame] | 2908 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2909 | #endif |
Logan Chien | 1a121b9 | 2012-02-15 22:23:42 +0800 | [diff] [blame] | 2910 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 2911 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 2912 | } |
| 2913 | |
| 2914 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2915 | llvm::Value* MethodCompiler:: |
| 2916 | EmitLoadSDCalleeMethodObjectAddr(uint32_t callee_method_idx) { |
| 2917 | llvm::Value* callee_method_object_field_addr = |
| 2918 | EmitLoadDexCacheResolvedMethodFieldAddr(callee_method_idx); |
Logan Chien | 7caf37e | 2012-02-03 22:56:04 +0800 | [diff] [blame] | 2919 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2920 | return irb_.CreateLoad(callee_method_object_field_addr); |
| 2921 | } |
Logan Chien | 7caf37e | 2012-02-03 22:56:04 +0800 | [diff] [blame] | 2922 | |
Logan Chien | 7caf37e | 2012-02-03 22:56:04 +0800 | [diff] [blame] | 2923 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2924 | llvm::Value* MethodCompiler:: |
| 2925 | EmitLoadVirtualCalleeMethodObjectAddr(int vtable_idx, |
| 2926 | llvm::Value* this_addr) { |
| 2927 | // Load class object of *this* pointer |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 2928 | llvm::Value* class_object_addr = |
| 2929 | irb_.LoadFromObjectOffset(this_addr, |
| 2930 | Object::ClassOffset().Int32Value(), |
| 2931 | irb_.getJObjectTy()); |
Logan Chien | 7caf37e | 2012-02-03 22:56:04 +0800 | [diff] [blame] | 2932 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2933 | // Load vtable address |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 2934 | llvm::Value* vtable_addr = |
| 2935 | irb_.LoadFromObjectOffset(class_object_addr, |
| 2936 | Class::VTableOffset().Int32Value(), |
| 2937 | irb_.getJObjectTy()); |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2938 | |
| 2939 | // Load callee method object |
| 2940 | llvm::Value* vtable_idx_value = |
| 2941 | irb_.getPtrEquivInt(static_cast<uint64_t>(vtable_idx)); |
| 2942 | |
| 2943 | llvm::Value* method_field_addr = |
| 2944 | EmitArrayGEP(vtable_addr, vtable_idx_value, irb_.getJObjectTy(), kObject); |
| 2945 | |
| 2946 | return irb_.CreateLoad(method_field_addr); |
| 2947 | } |
| 2948 | |
| 2949 | |
| 2950 | llvm::Value* MethodCompiler:: |
| 2951 | EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx, |
| 2952 | InvokeType invoke_type, |
| 2953 | llvm::Value* this_addr, |
| 2954 | uint32_t dex_pc, |
| 2955 | bool is_fast_path) { |
| 2956 | |
| 2957 | llvm::Function* runtime_func = NULL; |
| 2958 | |
| 2959 | switch (invoke_type) { |
| 2960 | case kStatic: |
| 2961 | runtime_func = irb_.GetRuntime(FindStaticMethodWithAccessCheck); |
| 2962 | break; |
| 2963 | |
| 2964 | case kDirect: |
| 2965 | runtime_func = irb_.GetRuntime(FindDirectMethodWithAccessCheck); |
| 2966 | break; |
| 2967 | |
| 2968 | case kVirtual: |
| 2969 | runtime_func = irb_.GetRuntime(FindVirtualMethodWithAccessCheck); |
| 2970 | break; |
| 2971 | |
| 2972 | case kSuper: |
| 2973 | runtime_func = irb_.GetRuntime(FindSuperMethodWithAccessCheck); |
| 2974 | break; |
| 2975 | |
| 2976 | case kInterface: |
| 2977 | if (is_fast_path) { |
| 2978 | runtime_func = irb_.GetRuntime(FindInterfaceMethod); |
| 2979 | } else { |
| 2980 | runtime_func = irb_.GetRuntime(FindInterfaceMethodWithAccessCheck); |
| 2981 | } |
| 2982 | break; |
| 2983 | } |
Logan Chien | 7caf37e | 2012-02-03 22:56:04 +0800 | [diff] [blame] | 2984 | |
| 2985 | llvm::Value* callee_method_idx_value = irb_.getInt32(callee_method_idx); |
| 2986 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 2987 | if (this_addr == NULL) { |
| 2988 | DCHECK_EQ(invoke_type, kStatic); |
| 2989 | this_addr = irb_.getJNull(); |
| 2990 | } |
| 2991 | |
| 2992 | llvm::Value* caller_method_object_addr = EmitLoadMethodObjectAddr(); |
| 2993 | |
TDYa127 | da83d97 | 2012-04-18 00:21:49 -0700 | [diff] [blame] | 2994 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 2995 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 2996 | EmitUpdateDexPC(dex_pc); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 2997 | |
TDYa127 | 0b686e5 | 2012-04-09 22:43:35 -0700 | [diff] [blame] | 2998 | llvm::Value* callee_method_object_addr = |
TDYa127 | da83d97 | 2012-04-18 00:21:49 -0700 | [diff] [blame] | 2999 | irb_.CreateCall4(runtime_func, |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 3000 | callee_method_idx_value, |
| 3001 | this_addr, |
TDYa127 | da83d97 | 2012-04-18 00:21:49 -0700 | [diff] [blame] | 3002 | caller_method_object_addr, |
| 3003 | thread_object_addr); |
Logan Chien | 7caf37e | 2012-02-03 22:56:04 +0800 | [diff] [blame] | 3004 | |
| 3005 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 3006 | |
Logan Chien | 7e7fabc | 2012-04-10 18:59:11 +0800 | [diff] [blame] | 3007 | return callee_method_object_addr; |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | |
| 3011 | void MethodCompiler::EmitInsn_Neg(uint32_t dex_pc, |
| 3012 | Instruction const* insn, |
| 3013 | JType op_jty) { |
Logan Chien | 1b5685f | 2011-12-27 18:01:14 +0800 | [diff] [blame] | 3014 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3015 | DecodedInstruction dec_insn(insn); |
Logan Chien | 1b5685f | 2011-12-27 18:01:14 +0800 | [diff] [blame] | 3016 | |
| 3017 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 3018 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3019 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
Logan Chien | 1b5685f | 2011-12-27 18:01:14 +0800 | [diff] [blame] | 3020 | llvm::Value* result_value = irb_.CreateNeg(src_value); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3021 | EmitStoreDalvikReg(dec_insn.vA, op_jty, kAccurate, result_value); |
Logan Chien | 1b5685f | 2011-12-27 18:01:14 +0800 | [diff] [blame] | 3022 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3023 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3024 | } |
| 3025 | |
| 3026 | |
| 3027 | void MethodCompiler::EmitInsn_Not(uint32_t dex_pc, |
| 3028 | Instruction const* insn, |
| 3029 | JType op_jty) { |
Logan Chien | e53750d | 2011-12-27 18:02:27 +0800 | [diff] [blame] | 3030 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3031 | DecodedInstruction dec_insn(insn); |
Logan Chien | e53750d | 2011-12-27 18:02:27 +0800 | [diff] [blame] | 3032 | |
| 3033 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 3034 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3035 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
Logan Chien | e53750d | 2011-12-27 18:02:27 +0800 | [diff] [blame] | 3036 | llvm::Value* result_value = |
| 3037 | irb_.CreateXor(src_value, static_cast<uint64_t>(-1)); |
| 3038 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3039 | EmitStoreDalvikReg(dec_insn.vA, op_jty, kAccurate, result_value); |
Logan Chien | e53750d | 2011-12-27 18:02:27 +0800 | [diff] [blame] | 3040 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3041 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3042 | } |
| 3043 | |
| 3044 | |
| 3045 | void MethodCompiler::EmitInsn_SExt(uint32_t dex_pc, |
| 3046 | Instruction const* insn) { |
Logan Chien | 61752ad | 2011-12-27 18:03:51 +0800 | [diff] [blame] | 3047 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3048 | DecodedInstruction dec_insn(insn); |
Logan Chien | 61752ad | 2011-12-27 18:03:51 +0800 | [diff] [blame] | 3049 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3050 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
Logan Chien | 61752ad | 2011-12-27 18:03:51 +0800 | [diff] [blame] | 3051 | llvm::Value* result_value = irb_.CreateSExt(src_value, irb_.getJLongTy()); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3052 | EmitStoreDalvikReg(dec_insn.vA, kLong, kAccurate, result_value); |
Logan Chien | 61752ad | 2011-12-27 18:03:51 +0800 | [diff] [blame] | 3053 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3054 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3055 | } |
| 3056 | |
| 3057 | |
| 3058 | void MethodCompiler::EmitInsn_Trunc(uint32_t dex_pc, |
| 3059 | Instruction const* insn) { |
Logan Chien | 17a5766 | 2011-12-27 18:05:14 +0800 | [diff] [blame] | 3060 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3061 | DecodedInstruction dec_insn(insn); |
Logan Chien | 17a5766 | 2011-12-27 18:05:14 +0800 | [diff] [blame] | 3062 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3063 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kLong, kAccurate); |
Logan Chien | 17a5766 | 2011-12-27 18:05:14 +0800 | [diff] [blame] | 3064 | llvm::Value* result_value = irb_.CreateTrunc(src_value, irb_.getJIntTy()); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3065 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result_value); |
Logan Chien | 17a5766 | 2011-12-27 18:05:14 +0800 | [diff] [blame] | 3066 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3067 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3068 | } |
| 3069 | |
| 3070 | |
| 3071 | void MethodCompiler::EmitInsn_TruncAndSExt(uint32_t dex_pc, |
| 3072 | Instruction const* insn, |
| 3073 | unsigned N) { |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3074 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3075 | DecodedInstruction dec_insn(insn); |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3076 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3077 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3078 | |
| 3079 | llvm::Value* trunc_value = |
| 3080 | irb_.CreateTrunc(src_value, llvm::Type::getIntNTy(*context_, N)); |
| 3081 | |
| 3082 | llvm::Value* result_value = irb_.CreateSExt(trunc_value, irb_.getJIntTy()); |
| 3083 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3084 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result_value); |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3085 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3086 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3087 | } |
| 3088 | |
| 3089 | |
| 3090 | void MethodCompiler::EmitInsn_TruncAndZExt(uint32_t dex_pc, |
| 3091 | Instruction const* insn, |
| 3092 | unsigned N) { |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3093 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3094 | DecodedInstruction dec_insn(insn); |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3095 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3096 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3097 | |
| 3098 | llvm::Value* trunc_value = |
| 3099 | irb_.CreateTrunc(src_value, llvm::Type::getIntNTy(*context_, N)); |
| 3100 | |
| 3101 | llvm::Value* result_value = irb_.CreateZExt(trunc_value, irb_.getJIntTy()); |
| 3102 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3103 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result_value); |
Logan Chien | b6744c5 | 2011-12-27 18:06:26 +0800 | [diff] [blame] | 3104 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3105 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3106 | } |
| 3107 | |
| 3108 | |
| 3109 | void MethodCompiler::EmitInsn_FNeg(uint32_t dex_pc, |
| 3110 | Instruction const* insn, |
| 3111 | JType op_jty) { |
Logan Chien | 7a48b09 | 2011-12-27 18:07:45 +0800 | [diff] [blame] | 3112 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3113 | DecodedInstruction dec_insn(insn); |
Logan Chien | 7a48b09 | 2011-12-27 18:07:45 +0800 | [diff] [blame] | 3114 | |
| 3115 | DCHECK(op_jty == kFloat || op_jty == kDouble) << op_jty; |
| 3116 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3117 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
Logan Chien | 7a48b09 | 2011-12-27 18:07:45 +0800 | [diff] [blame] | 3118 | llvm::Value* result_value = irb_.CreateFNeg(src_value); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3119 | EmitStoreDalvikReg(dec_insn.vA, op_jty, kAccurate, result_value); |
Logan Chien | 7a48b09 | 2011-12-27 18:07:45 +0800 | [diff] [blame] | 3120 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3121 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3122 | } |
| 3123 | |
| 3124 | |
| 3125 | void MethodCompiler::EmitInsn_IntToFP(uint32_t dex_pc, |
| 3126 | Instruction const* insn, |
| 3127 | JType src_jty, |
| 3128 | JType dest_jty) { |
Logan Chien | 62dd453 | 2011-12-27 18:09:00 +0800 | [diff] [blame] | 3129 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3130 | DecodedInstruction dec_insn(insn); |
Logan Chien | 62dd453 | 2011-12-27 18:09:00 +0800 | [diff] [blame] | 3131 | |
| 3132 | DCHECK(src_jty == kInt || src_jty == kLong) << src_jty; |
| 3133 | DCHECK(dest_jty == kFloat || dest_jty == kDouble) << dest_jty; |
| 3134 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3135 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, src_jty, kAccurate); |
Logan Chien | 62dd453 | 2011-12-27 18:09:00 +0800 | [diff] [blame] | 3136 | llvm::Type* dest_type = irb_.getJType(dest_jty, kAccurate); |
| 3137 | llvm::Value* dest_value = irb_.CreateSIToFP(src_value, dest_type); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3138 | EmitStoreDalvikReg(dec_insn.vA, dest_jty, kAccurate, dest_value); |
Logan Chien | 62dd453 | 2011-12-27 18:09:00 +0800 | [diff] [blame] | 3139 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3140 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3141 | } |
| 3142 | |
| 3143 | |
| 3144 | void MethodCompiler::EmitInsn_FPToInt(uint32_t dex_pc, |
| 3145 | Instruction const* insn, |
| 3146 | JType src_jty, |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 3147 | JType dest_jty, |
| 3148 | runtime_support::RuntimeId runtime_func_id) { |
Logan Chien | 12dc175 | 2011-12-27 18:10:15 +0800 | [diff] [blame] | 3149 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3150 | DecodedInstruction dec_insn(insn); |
Logan Chien | 12dc175 | 2011-12-27 18:10:15 +0800 | [diff] [blame] | 3151 | |
| 3152 | DCHECK(src_jty == kFloat || src_jty == kDouble) << src_jty; |
| 3153 | DCHECK(dest_jty == kInt || dest_jty == kLong) << dest_jty; |
| 3154 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3155 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, src_jty, kAccurate); |
TDYa127 | a474687 | 2012-04-11 23:48:55 -0700 | [diff] [blame] | 3156 | llvm::Value* dest_value = irb_.CreateCall(irb_.GetRuntime(runtime_func_id), src_value); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3157 | EmitStoreDalvikReg(dec_insn.vA, dest_jty, kAccurate, dest_value); |
Logan Chien | 12dc175 | 2011-12-27 18:10:15 +0800 | [diff] [blame] | 3158 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3159 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3160 | } |
| 3161 | |
| 3162 | |
| 3163 | void MethodCompiler::EmitInsn_FExt(uint32_t dex_pc, |
| 3164 | Instruction const* insn) { |
Logan Chien | c56ded9 | 2011-12-27 18:10:57 +0800 | [diff] [blame] | 3165 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3166 | DecodedInstruction dec_insn(insn); |
Logan Chien | c56ded9 | 2011-12-27 18:10:57 +0800 | [diff] [blame] | 3167 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3168 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kFloat, kAccurate); |
Logan Chien | c56ded9 | 2011-12-27 18:10:57 +0800 | [diff] [blame] | 3169 | llvm::Value* result_value = irb_.CreateFPExt(src_value, irb_.getJDoubleTy()); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3170 | EmitStoreDalvikReg(dec_insn.vA, kDouble, kAccurate, result_value); |
Logan Chien | c56ded9 | 2011-12-27 18:10:57 +0800 | [diff] [blame] | 3171 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3172 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3173 | } |
| 3174 | |
| 3175 | |
| 3176 | void MethodCompiler::EmitInsn_FTrunc(uint32_t dex_pc, |
| 3177 | Instruction const* insn) { |
Logan Chien | 927744f | 2011-12-27 18:11:52 +0800 | [diff] [blame] | 3178 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3179 | DecodedInstruction dec_insn(insn); |
Logan Chien | 927744f | 2011-12-27 18:11:52 +0800 | [diff] [blame] | 3180 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3181 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kDouble, kAccurate); |
Logan Chien | 927744f | 2011-12-27 18:11:52 +0800 | [diff] [blame] | 3182 | llvm::Value* result_value = irb_.CreateFPTrunc(src_value, irb_.getJFloatTy()); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3183 | EmitStoreDalvikReg(dec_insn.vA, kFloat, kAccurate, result_value); |
Logan Chien | 927744f | 2011-12-27 18:11:52 +0800 | [diff] [blame] | 3184 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3185 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3186 | } |
| 3187 | |
| 3188 | |
| 3189 | void MethodCompiler::EmitInsn_IntArithm(uint32_t dex_pc, |
| 3190 | Instruction const* insn, |
| 3191 | IntArithmKind arithm, |
| 3192 | JType op_jty, |
| 3193 | bool is_2addr) { |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3194 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3195 | DecodedInstruction dec_insn(insn); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3196 | |
| 3197 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 3198 | |
| 3199 | llvm::Value* src1_value; |
| 3200 | llvm::Value* src2_value; |
| 3201 | |
| 3202 | if (is_2addr) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3203 | src1_value = EmitLoadDalvikReg(dec_insn.vA, op_jty, kAccurate); |
| 3204 | src2_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3205 | } else { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3206 | src1_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
| 3207 | src2_value = EmitLoadDalvikReg(dec_insn.vC, op_jty, kAccurate); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | llvm::Value* result_value = |
| 3211 | EmitIntArithmResultComputation(dex_pc, src1_value, src2_value, |
| 3212 | arithm, op_jty); |
| 3213 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3214 | EmitStoreDalvikReg(dec_insn.vA, op_jty, kAccurate, result_value); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3215 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3216 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3217 | } |
| 3218 | |
| 3219 | |
| 3220 | void MethodCompiler::EmitInsn_IntArithmImmediate(uint32_t dex_pc, |
| 3221 | Instruction const* insn, |
| 3222 | IntArithmKind arithm) { |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3223 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3224 | DecodedInstruction dec_insn(insn); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3225 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3226 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3227 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3228 | llvm::Value* imm_value = irb_.getInt32(dec_insn.vC); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3229 | |
| 3230 | llvm::Value* result_value = |
| 3231 | EmitIntArithmResultComputation(dex_pc, src_value, imm_value, arithm, kInt); |
| 3232 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3233 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result_value); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3234 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3235 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3236 | } |
| 3237 | |
| 3238 | |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3239 | llvm::Value* |
| 3240 | MethodCompiler::EmitIntArithmResultComputation(uint32_t dex_pc, |
| 3241 | llvm::Value* lhs, |
| 3242 | llvm::Value* rhs, |
| 3243 | IntArithmKind arithm, |
| 3244 | JType op_jty) { |
| 3245 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 3246 | |
| 3247 | switch (arithm) { |
| 3248 | case kIntArithm_Add: |
| 3249 | return irb_.CreateAdd(lhs, rhs); |
| 3250 | |
| 3251 | case kIntArithm_Sub: |
| 3252 | return irb_.CreateSub(lhs, rhs); |
| 3253 | |
| 3254 | case kIntArithm_Mul: |
| 3255 | return irb_.CreateMul(lhs, rhs); |
| 3256 | |
| 3257 | case kIntArithm_Div: |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3258 | case kIntArithm_Rem: |
TDYa127 | f8641ce | 2012-04-02 06:40:40 -0700 | [diff] [blame] | 3259 | return EmitIntDivRemResultComputation(dex_pc, lhs, rhs, arithm, op_jty); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3260 | |
| 3261 | case kIntArithm_And: |
| 3262 | return irb_.CreateAnd(lhs, rhs); |
| 3263 | |
| 3264 | case kIntArithm_Or: |
| 3265 | return irb_.CreateOr(lhs, rhs); |
| 3266 | |
| 3267 | case kIntArithm_Xor: |
| 3268 | return irb_.CreateXor(lhs, rhs); |
| 3269 | |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3270 | default: |
| 3271 | LOG(FATAL) << "Unknown integer arithmetic kind: " << arithm; |
| 3272 | return NULL; |
| 3273 | } |
| 3274 | } |
| 3275 | |
| 3276 | |
TDYa127 | f8641ce | 2012-04-02 06:40:40 -0700 | [diff] [blame] | 3277 | llvm::Value* |
| 3278 | MethodCompiler::EmitIntDivRemResultComputation(uint32_t dex_pc, |
| 3279 | llvm::Value* dividend, |
| 3280 | llvm::Value* divisor, |
| 3281 | IntArithmKind arithm, |
| 3282 | JType op_jty) { |
| 3283 | // Throw exception if the divisor is 0. |
| 3284 | EmitGuard_DivZeroException(dex_pc, divisor, op_jty); |
| 3285 | |
| 3286 | // Check the special case: MININT / -1 = MININT |
| 3287 | // That case will cause overflow, which is undefined behavior in llvm. |
| 3288 | // So we check the divisor is -1 or not, if the divisor is -1, we do |
| 3289 | // the special path to avoid undefined behavior. |
| 3290 | llvm::Type* op_type = irb_.getJType(op_jty, kAccurate); |
| 3291 | llvm::Value* zero = irb_.getJZero(op_jty); |
| 3292 | llvm::Value* neg_one = llvm::ConstantInt::getSigned(op_type, -1); |
| 3293 | llvm::Value* result = irb_.CreateAlloca(op_type); |
| 3294 | |
| 3295 | llvm::BasicBlock* eq_neg_one = CreateBasicBlockWithDexPC(dex_pc, "eq_neg_one"); |
| 3296 | llvm::BasicBlock* ne_neg_one = CreateBasicBlockWithDexPC(dex_pc, "ne_neg_one"); |
| 3297 | llvm::BasicBlock* neg_one_cont = CreateBasicBlockWithDexPC(dex_pc, "neg_one_cont"); |
| 3298 | |
| 3299 | llvm::Value* is_equal_neg_one = EmitConditionResult(divisor, neg_one, kCondBranch_EQ); |
| 3300 | irb_.CreateCondBr(is_equal_neg_one, eq_neg_one, ne_neg_one); |
| 3301 | |
| 3302 | // If divisor == -1 |
| 3303 | irb_.SetInsertPoint(eq_neg_one); |
| 3304 | llvm::Value* eq_result; |
| 3305 | if (arithm == kIntArithm_Div) { |
| 3306 | // We can just change from "dividend div -1" to "neg dividend". |
| 3307 | // The sub don't care the sign/unsigned because of two's complement representation. |
| 3308 | // And the behavior is what we want: |
| 3309 | // -(2^n) (2^n)-1 |
| 3310 | // MININT < k <= MAXINT -> mul k -1 = -k |
| 3311 | // MININT == k -> mul k -1 = k |
| 3312 | // |
| 3313 | // LLVM use sub to represent 'neg' |
| 3314 | eq_result = irb_.CreateSub(zero, dividend); |
| 3315 | } else { |
| 3316 | // Everything modulo -1 will be 0. |
| 3317 | eq_result = zero; |
| 3318 | } |
| 3319 | irb_.CreateStore(eq_result, result); |
| 3320 | irb_.CreateBr(neg_one_cont); |
| 3321 | |
| 3322 | // If divisor != -1, just do the division. |
| 3323 | irb_.SetInsertPoint(ne_neg_one); |
| 3324 | llvm::Value* ne_result; |
| 3325 | if (arithm == kIntArithm_Div) { |
| 3326 | ne_result = irb_.CreateSDiv(dividend, divisor); |
| 3327 | } else { |
| 3328 | ne_result = irb_.CreateSRem(dividend, divisor); |
| 3329 | } |
| 3330 | irb_.CreateStore(ne_result, result); |
| 3331 | irb_.CreateBr(neg_one_cont); |
| 3332 | |
| 3333 | irb_.SetInsertPoint(neg_one_cont); |
| 3334 | return irb_.CreateLoad(result); |
| 3335 | } |
| 3336 | |
| 3337 | |
Logan Chien | 5539ad0 | 2012-04-02 14:36:55 +0800 | [diff] [blame] | 3338 | void MethodCompiler::EmitInsn_IntShiftArithm(uint32_t dex_pc, |
| 3339 | Instruction const* insn, |
| 3340 | IntShiftArithmKind arithm, |
| 3341 | JType op_jty, |
| 3342 | bool is_2addr) { |
| 3343 | |
| 3344 | DecodedInstruction dec_insn(insn); |
| 3345 | |
| 3346 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 3347 | |
| 3348 | llvm::Value* src1_value; |
| 3349 | llvm::Value* src2_value; |
| 3350 | |
| 3351 | // NOTE: The 2nd operand of the shift arithmetic instruction is |
| 3352 | // 32-bit integer regardless of the 1st operand. |
| 3353 | if (is_2addr) { |
| 3354 | src1_value = EmitLoadDalvikReg(dec_insn.vA, op_jty, kAccurate); |
| 3355 | src2_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
| 3356 | } else { |
| 3357 | src1_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
| 3358 | src2_value = EmitLoadDalvikReg(dec_insn.vC, kInt, kAccurate); |
| 3359 | } |
| 3360 | |
| 3361 | llvm::Value* result_value = |
| 3362 | EmitIntShiftArithmResultComputation(dex_pc, src1_value, src2_value, |
| 3363 | arithm, op_jty); |
| 3364 | |
| 3365 | EmitStoreDalvikReg(dec_insn.vA, op_jty, kAccurate, result_value); |
| 3366 | |
| 3367 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3368 | } |
| 3369 | |
| 3370 | |
| 3371 | void MethodCompiler:: |
| 3372 | EmitInsn_IntShiftArithmImmediate(uint32_t dex_pc, |
| 3373 | Instruction const* insn, |
| 3374 | IntShiftArithmKind arithm) { |
| 3375 | |
| 3376 | DecodedInstruction dec_insn(insn); |
| 3377 | |
| 3378 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
| 3379 | |
| 3380 | llvm::Value* imm_value = irb_.getInt32(dec_insn.vC); |
| 3381 | |
| 3382 | llvm::Value* result_value = |
| 3383 | EmitIntShiftArithmResultComputation(dex_pc, src_value, imm_value, |
| 3384 | arithm, kInt); |
| 3385 | |
| 3386 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result_value); |
| 3387 | |
| 3388 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3389 | } |
| 3390 | |
| 3391 | |
| 3392 | llvm::Value* |
| 3393 | MethodCompiler::EmitIntShiftArithmResultComputation(uint32_t dex_pc, |
| 3394 | llvm::Value* lhs, |
| 3395 | llvm::Value* rhs, |
| 3396 | IntShiftArithmKind arithm, |
| 3397 | JType op_jty) { |
| 3398 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 3399 | |
| 3400 | if (op_jty == kInt) { |
| 3401 | rhs = irb_.CreateAnd(rhs, 0x1f); |
| 3402 | } else { |
| 3403 | llvm::Value* masked_rhs = irb_.CreateAnd(rhs, 0x3f); |
| 3404 | rhs = irb_.CreateZExt(masked_rhs, irb_.getJLongTy()); |
| 3405 | } |
| 3406 | |
| 3407 | switch (arithm) { |
| 3408 | case kIntArithm_Shl: |
| 3409 | return irb_.CreateShl(lhs, rhs); |
| 3410 | |
| 3411 | case kIntArithm_Shr: |
| 3412 | return irb_.CreateAShr(lhs, rhs); |
| 3413 | |
| 3414 | case kIntArithm_UShr: |
| 3415 | return irb_.CreateLShr(lhs, rhs); |
| 3416 | |
| 3417 | default: |
| 3418 | LOG(FATAL) << "Unknown integer shift arithmetic kind: " << arithm; |
| 3419 | return NULL; |
| 3420 | } |
| 3421 | } |
| 3422 | |
| 3423 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3424 | void MethodCompiler::EmitInsn_RSubImmediate(uint32_t dex_pc, |
| 3425 | Instruction const* insn) { |
Logan Chien | 65c62d4 | 2011-12-27 18:14:18 +0800 | [diff] [blame] | 3426 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3427 | DecodedInstruction dec_insn(insn); |
Logan Chien | 65c62d4 | 2011-12-27 18:14:18 +0800 | [diff] [blame] | 3428 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3429 | llvm::Value* src_value = EmitLoadDalvikReg(dec_insn.vB, kInt, kAccurate); |
| 3430 | llvm::Value* imm_value = irb_.getInt32(dec_insn.vC); |
Logan Chien | 65c62d4 | 2011-12-27 18:14:18 +0800 | [diff] [blame] | 3431 | llvm::Value* result_value = irb_.CreateSub(imm_value, src_value); |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3432 | EmitStoreDalvikReg(dec_insn.vA, kInt, kAccurate, result_value); |
Logan Chien | 65c62d4 | 2011-12-27 18:14:18 +0800 | [diff] [blame] | 3433 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3434 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3435 | } |
| 3436 | |
| 3437 | |
| 3438 | void MethodCompiler::EmitInsn_FPArithm(uint32_t dex_pc, |
| 3439 | Instruction const* insn, |
| 3440 | FPArithmKind arithm, |
| 3441 | JType op_jty, |
| 3442 | bool is_2addr) { |
Logan Chien | 76e1c79 | 2011-12-27 18:15:01 +0800 | [diff] [blame] | 3443 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3444 | DecodedInstruction dec_insn(insn); |
Logan Chien | 76e1c79 | 2011-12-27 18:15:01 +0800 | [diff] [blame] | 3445 | |
| 3446 | DCHECK(op_jty == kFloat || op_jty == kDouble) << op_jty; |
| 3447 | |
| 3448 | llvm::Value* src1_value; |
| 3449 | llvm::Value* src2_value; |
| 3450 | |
| 3451 | if (is_2addr) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3452 | src1_value = EmitLoadDalvikReg(dec_insn.vA, op_jty, kAccurate); |
| 3453 | src2_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
Logan Chien | 76e1c79 | 2011-12-27 18:15:01 +0800 | [diff] [blame] | 3454 | } else { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3455 | src1_value = EmitLoadDalvikReg(dec_insn.vB, op_jty, kAccurate); |
| 3456 | src2_value = EmitLoadDalvikReg(dec_insn.vC, op_jty, kAccurate); |
Logan Chien | 76e1c79 | 2011-12-27 18:15:01 +0800 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | llvm::Value* result_value = |
| 3460 | EmitFPArithmResultComputation(dex_pc, src1_value, src2_value, arithm); |
| 3461 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 3462 | EmitStoreDalvikReg(dec_insn.vA, op_jty, kAccurate, result_value); |
Logan Chien | 76e1c79 | 2011-12-27 18:15:01 +0800 | [diff] [blame] | 3463 | |
Logan Chien | 70f94b4 | 2011-12-27 17:49:11 +0800 | [diff] [blame] | 3464 | irb_.CreateBr(GetNextBasicBlock(dex_pc)); |
| 3465 | } |
| 3466 | |
| 3467 | |
Logan Chien | 76e1c79 | 2011-12-27 18:15:01 +0800 | [diff] [blame] | 3468 | llvm::Value* |
| 3469 | MethodCompiler::EmitFPArithmResultComputation(uint32_t dex_pc, |
| 3470 | llvm::Value *lhs, |
| 3471 | llvm::Value *rhs, |
| 3472 | FPArithmKind arithm) { |
| 3473 | switch (arithm) { |
| 3474 | case kFPArithm_Add: |
| 3475 | return irb_.CreateFAdd(lhs, rhs); |
| 3476 | |
| 3477 | case kFPArithm_Sub: |
| 3478 | return irb_.CreateFSub(lhs, rhs); |
| 3479 | |
| 3480 | case kFPArithm_Mul: |
| 3481 | return irb_.CreateFMul(lhs, rhs); |
| 3482 | |
| 3483 | case kFPArithm_Div: |
| 3484 | return irb_.CreateFDiv(lhs, rhs); |
| 3485 | |
| 3486 | case kFPArithm_Rem: |
| 3487 | return irb_.CreateFRem(lhs, rhs); |
| 3488 | |
| 3489 | default: |
| 3490 | LOG(FATAL) << "Unknown floating-point arithmetic kind: " << arithm; |
| 3491 | return NULL; |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3496 | void MethodCompiler::EmitGuard_DivZeroException(uint32_t dex_pc, |
| 3497 | llvm::Value* denominator, |
| 3498 | JType op_jty) { |
| 3499 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 3500 | |
| 3501 | llvm::Constant* zero = irb_.getJZero(op_jty); |
| 3502 | |
| 3503 | llvm::Value* equal_zero = irb_.CreateICmpEQ(denominator, zero); |
| 3504 | |
| 3505 | llvm::BasicBlock* block_exception = CreateBasicBlockWithDexPC(dex_pc, "div0"); |
| 3506 | |
| 3507 | llvm::BasicBlock* block_continue = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 3508 | |
| 3509 | irb_.CreateCondBr(equal_zero, block_exception, block_continue); |
| 3510 | |
| 3511 | irb_.SetInsertPoint(block_exception); |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 3512 | EmitUpdateDexPC(dex_pc); |
Logan Chien | c3f7d96 | 2011-12-27 18:13:18 +0800 | [diff] [blame] | 3513 | irb_.CreateCall(irb_.GetRuntime(ThrowDivZeroException)); |
| 3514 | EmitBranchExceptionLandingPad(dex_pc); |
| 3515 | |
| 3516 | irb_.SetInsertPoint(block_continue); |
| 3517 | } |
| 3518 | |
| 3519 | |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 3520 | void MethodCompiler::EmitGuard_NullPointerException(uint32_t dex_pc, |
| 3521 | llvm::Value* object) { |
| 3522 | llvm::Value* equal_null = irb_.CreateICmpEQ(object, irb_.getJNull()); |
| 3523 | |
| 3524 | llvm::BasicBlock* block_exception = |
| 3525 | CreateBasicBlockWithDexPC(dex_pc, "nullp"); |
| 3526 | |
| 3527 | llvm::BasicBlock* block_continue = |
| 3528 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 3529 | |
| 3530 | irb_.CreateCondBr(equal_null, block_exception, block_continue); |
| 3531 | |
| 3532 | irb_.SetInsertPoint(block_exception); |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 3533 | EmitUpdateDexPC(dex_pc); |
TDYa127 | 3f9137d | 2012-04-08 15:59:19 -0700 | [diff] [blame] | 3534 | irb_.CreateCall(irb_.GetRuntime(ThrowNullPointerException), irb_.getInt32(dex_pc)); |
Logan Chien | 61bb614 | 2012-02-03 15:34:53 +0800 | [diff] [blame] | 3535 | EmitBranchExceptionLandingPad(dex_pc); |
| 3536 | |
| 3537 | irb_.SetInsertPoint(block_continue); |
| 3538 | } |
| 3539 | |
| 3540 | |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 3541 | llvm::Value* MethodCompiler::EmitLoadDexCacheAddr(MemberOffset offset) { |
| 3542 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 3543 | |
TDYa127 | ee1f59b | 2012-04-25 00:56:40 -0700 | [diff] [blame] | 3544 | return irb_.LoadFromObjectOffset(method_object_addr, |
| 3545 | offset.Int32Value(), |
| 3546 | irb_.getJObjectTy()); |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 3550 | llvm::Value* MethodCompiler:: |
| 3551 | EmitLoadDexCacheStaticStorageFieldAddr(uint32_t type_idx) { |
| 3552 | llvm::Value* static_storage_dex_cache_addr = |
| 3553 | EmitLoadDexCacheAddr(Method::DexCacheInitializedStaticStorageOffset()); |
| 3554 | |
| 3555 | llvm::Value* type_idx_value = irb_.getPtrEquivInt(type_idx); |
| 3556 | |
| 3557 | return EmitArrayGEP(static_storage_dex_cache_addr, type_idx_value, |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 3558 | irb_.getJObjectTy(), kObject); |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | |
| 3562 | llvm::Value* MethodCompiler:: |
| 3563 | EmitLoadDexCacheResolvedTypeFieldAddr(uint32_t type_idx) { |
| 3564 | llvm::Value* resolved_type_dex_cache_addr = |
| 3565 | EmitLoadDexCacheAddr(Method::DexCacheResolvedTypesOffset()); |
| 3566 | |
| 3567 | llvm::Value* type_idx_value = irb_.getPtrEquivInt(type_idx); |
| 3568 | |
| 3569 | return EmitArrayGEP(resolved_type_dex_cache_addr, type_idx_value, |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 3570 | irb_.getJObjectTy(), kObject); |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | |
| 3574 | llvm::Value* MethodCompiler:: |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 3575 | EmitLoadDexCacheResolvedMethodFieldAddr(uint32_t method_idx) { |
| 3576 | llvm::Value* resolved_method_dex_cache_addr = |
| 3577 | EmitLoadDexCacheAddr(Method::DexCacheResolvedMethodsOffset()); |
| 3578 | |
| 3579 | llvm::Value* method_idx_value = irb_.getPtrEquivInt(method_idx); |
| 3580 | |
| 3581 | return EmitArrayGEP(resolved_method_dex_cache_addr, method_idx_value, |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 3582 | irb_.getJObjectTy(), kObject); |
Logan Chien | 61c65dc | 2012-02-29 03:22:30 +0800 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | |
| 3586 | llvm::Value* MethodCompiler:: |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 3587 | EmitLoadDexCacheStringFieldAddr(uint32_t string_idx) { |
| 3588 | llvm::Value* string_dex_cache_addr = |
| 3589 | EmitLoadDexCacheAddr(Method::DexCacheStringsOffset()); |
| 3590 | |
| 3591 | llvm::Value* string_idx_value = irb_.getPtrEquivInt(string_idx); |
| 3592 | |
| 3593 | return EmitArrayGEP(string_dex_cache_addr, string_idx_value, |
Ian Rogers | 04ec04e | 2012-02-28 16:15:33 -0800 | [diff] [blame] | 3594 | irb_.getJObjectTy(), kObject); |
Logan Chien | bb4d12a | 2012-02-17 14:10:01 +0800 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 3598 | CompiledMethod *MethodCompiler::Compile() { |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 3599 | // Code generation |
| 3600 | CreateFunction(); |
| 3601 | |
| 3602 | EmitPrologue(); |
| 3603 | EmitInstructions(); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3604 | EmitPrologueLastBranch(); |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 3605 | |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 3606 | // Verify the generated bitcode |
TDYa127 | 853cd09 | 2012-04-21 22:15:31 -0700 | [diff] [blame] | 3607 | VERIFY_LLVM_FUNCTION(*func_); |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 3608 | |
Logan Chien | 8b977d3 | 2012-02-21 19:14:55 +0800 | [diff] [blame] | 3609 | // Add the memory usage approximation of the compilation unit |
| 3610 | cunit_->AddMemUsageApproximation(code_item_->insns_size_in_code_units_ * 900); |
| 3611 | // NOTE: From statistic, the bitcode size is 4.5 times bigger than the |
| 3612 | // Dex file. Besides, we have to convert the code unit into bytes. |
| 3613 | // Thus, we got our magic number 9. |
| 3614 | |
Logan Chien | 110bcba | 2012-04-16 19:11:28 +0800 | [diff] [blame] | 3615 | CompiledMethod* compiled_method = |
| 3616 | new CompiledMethod(cunit_->GetInstructionSet(), |
| 3617 | cunit_->GetElfIndex(), |
| 3618 | elf_func_idx_); |
| 3619 | |
| 3620 | cunit_->RegisterCompiledMethod(func_, compiled_method); |
| 3621 | |
| 3622 | return compiled_method; |
Logan Chien | 0b82710 | 2011-12-20 19:46:14 +0800 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | |
| 3626 | llvm::Value* MethodCompiler::EmitLoadMethodObjectAddr() { |
| 3627 | return func_->arg_begin(); |
Shih-wei Liao | d1fec81 | 2012-02-13 09:51:10 -0800 | [diff] [blame] | 3628 | } |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 3629 | |
| 3630 | |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3631 | void MethodCompiler::EmitBranchExceptionLandingPad(uint32_t dex_pc) { |
| 3632 | if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) { |
| 3633 | irb_.CreateBr(lpad); |
| 3634 | } else { |
| 3635 | irb_.CreateBr(GetUnwindBasicBlock()); |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | |
| 3640 | void MethodCompiler::EmitGuard_ExceptionLandingPad(uint32_t dex_pc) { |
| 3641 | llvm::Value* exception_pending = |
| 3642 | irb_.CreateCall(irb_.GetRuntime(IsExceptionPending)); |
| 3643 | |
| 3644 | llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 3645 | |
| 3646 | if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) { |
| 3647 | irb_.CreateCondBr(exception_pending, lpad, block_cont); |
| 3648 | } else { |
| 3649 | irb_.CreateCondBr(exception_pending, GetUnwindBasicBlock(), block_cont); |
| 3650 | } |
| 3651 | |
| 3652 | irb_.SetInsertPoint(block_cont); |
| 3653 | } |
| 3654 | |
| 3655 | |
Logan Chien | 924072f | 2012-01-30 15:07:24 +0800 | [diff] [blame] | 3656 | void MethodCompiler::EmitGuard_GarbageCollectionSuspend(uint32_t dex_pc) { |
| 3657 | llvm::Value* runtime_func = irb_.GetRuntime(TestSuspend); |
TDYa127 | 853cd09 | 2012-04-21 22:15:31 -0700 | [diff] [blame] | 3658 | |
| 3659 | llvm::Value* thread_object_addr = irb_.CreateCall(irb_.GetRuntime(GetCurrentThread)); |
| 3660 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 3661 | EmitUpdateDexPC(dex_pc); |
TDYa127 | 853cd09 | 2012-04-21 22:15:31 -0700 | [diff] [blame] | 3662 | |
| 3663 | irb_.CreateCall(runtime_func, thread_object_addr); |
Logan Chien | 924072f | 2012-01-30 15:07:24 +0800 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 3667 | llvm::BasicBlock* MethodCompiler:: |
| 3668 | CreateBasicBlockWithDexPC(uint32_t dex_pc, char const* postfix) { |
| 3669 | std::string name; |
| 3670 | |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3671 | #if !defined(NDEBUG) |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 3672 | if (postfix) { |
TDYa127 | 9948913 | 2012-04-29 01:27:58 -0700 | [diff] [blame] | 3673 | StringAppendF(&name, "B%04x.%s", dex_pc, postfix); |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 3674 | } else { |
TDYa127 | 9948913 | 2012-04-29 01:27:58 -0700 | [diff] [blame] | 3675 | StringAppendF(&name, "B%04x", dex_pc); |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 3676 | } |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3677 | #endif |
Logan Chien | d6c239a | 2011-12-23 15:11:45 +0800 | [diff] [blame] | 3678 | |
| 3679 | return llvm::BasicBlock::Create(*context_, name, func_); |
| 3680 | } |
| 3681 | |
| 3682 | |
| 3683 | llvm::BasicBlock* MethodCompiler::GetBasicBlock(uint32_t dex_pc) { |
| 3684 | DCHECK(dex_pc < code_item_->insns_size_in_code_units_); |
| 3685 | |
| 3686 | llvm::BasicBlock* basic_block = basic_blocks_[dex_pc]; |
| 3687 | |
| 3688 | if (!basic_block) { |
| 3689 | basic_block = CreateBasicBlockWithDexPC(dex_pc); |
| 3690 | basic_blocks_[dex_pc] = basic_block; |
| 3691 | } |
| 3692 | |
| 3693 | return basic_block; |
| 3694 | } |
| 3695 | |
| 3696 | |
| 3697 | llvm::BasicBlock* |
| 3698 | MethodCompiler::GetNextBasicBlock(uint32_t dex_pc) { |
| 3699 | Instruction const* insn = Instruction::At(code_item_->insns_ + dex_pc); |
| 3700 | return GetBasicBlock(dex_pc + insn->SizeInCodeUnits()); |
| 3701 | } |
| 3702 | |
| 3703 | |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3704 | int32_t MethodCompiler::GetTryItemOffset(uint32_t dex_pc) { |
| 3705 | // TODO: Since we are emitting the dex instructions in ascending order |
| 3706 | // w.r.t. address, we can cache the lastest try item offset so that we |
| 3707 | // don't have to do binary search for every query. |
| 3708 | |
| 3709 | int32_t min = 0; |
| 3710 | int32_t max = code_item_->tries_size_ - 1; |
| 3711 | |
| 3712 | while (min <= max) { |
| 3713 | int32_t mid = min + (max - min) / 2; |
| 3714 | |
| 3715 | DexFile::TryItem const* ti = DexFile::GetTryItems(*code_item_, mid); |
| 3716 | uint32_t start = ti->start_addr_; |
| 3717 | uint32_t end = start + ti->insn_count_; |
| 3718 | |
| 3719 | if (dex_pc < start) { |
| 3720 | max = mid - 1; |
| 3721 | } else if (dex_pc >= end) { |
| 3722 | min = mid + 1; |
| 3723 | } else { |
| 3724 | return mid; // found |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | return -1; // not found |
| 3729 | } |
| 3730 | |
| 3731 | |
| 3732 | llvm::BasicBlock* MethodCompiler::GetLandingPadBasicBlock(uint32_t dex_pc) { |
| 3733 | // Find the try item for this address in this method |
| 3734 | int32_t ti_offset = GetTryItemOffset(dex_pc); |
| 3735 | |
| 3736 | if (ti_offset == -1) { |
| 3737 | return NULL; // No landing pad is available for this address. |
| 3738 | } |
| 3739 | |
| 3740 | // Check for the existing landing pad basic block |
| 3741 | DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset)); |
| 3742 | llvm::BasicBlock* block_lpad = basic_block_landing_pads_[ti_offset]; |
| 3743 | |
| 3744 | if (block_lpad) { |
| 3745 | // We have generated landing pad for this try item already. Return the |
| 3746 | // same basic block. |
| 3747 | return block_lpad; |
| 3748 | } |
| 3749 | |
| 3750 | // Get try item from code item |
| 3751 | DexFile::TryItem const* ti = DexFile::GetTryItems(*code_item_, ti_offset); |
| 3752 | |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3753 | std::string lpadname; |
| 3754 | |
| 3755 | #if !defined(NDEBUG) |
| 3756 | StringAppendF(&lpadname, "lpad%d_%04x_to_%04x", ti_offset, ti->start_addr_, ti->handler_off_); |
| 3757 | #endif |
| 3758 | |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3759 | // Create landing pad basic block |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3760 | block_lpad = llvm::BasicBlock::Create(*context_, lpadname, func_); |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3761 | |
| 3762 | // Change IRBuilder insert point |
| 3763 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
| 3764 | irb_.SetInsertPoint(block_lpad); |
| 3765 | |
| 3766 | // Find catch block with matching type |
| 3767 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 3768 | |
Logan Chien | 736df02 | 2012-04-27 16:25:57 +0800 | [diff] [blame] | 3769 | llvm::Value* ti_offset_value = irb_.getInt32(ti_offset); |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3770 | |
| 3771 | llvm::Value* catch_handler_index_value = |
| 3772 | irb_.CreateCall2(irb_.GetRuntime(FindCatchBlock), |
Logan Chien | 736df02 | 2012-04-27 16:25:57 +0800 | [diff] [blame] | 3773 | method_object_addr, ti_offset_value); |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3774 | |
| 3775 | // Switch instruction (Go to unwind basic block by default) |
| 3776 | llvm::SwitchInst* sw = |
| 3777 | irb_.CreateSwitch(catch_handler_index_value, GetUnwindBasicBlock()); |
| 3778 | |
| 3779 | // Cases with matched catch block |
| 3780 | CatchHandlerIterator iter(*code_item_, ti->start_addr_); |
| 3781 | |
| 3782 | for (uint32_t c = 0; iter.HasNext(); iter.Next(), ++c) { |
| 3783 | sw->addCase(irb_.getInt32(c), GetBasicBlock(iter.GetHandlerAddress())); |
| 3784 | } |
| 3785 | |
| 3786 | // Restore the orignal insert point for IRBuilder |
| 3787 | irb_.restoreIP(irb_ip_original); |
| 3788 | |
| 3789 | // Cache this landing pad |
| 3790 | DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset)); |
| 3791 | basic_block_landing_pads_[ti_offset] = block_lpad; |
| 3792 | |
| 3793 | return block_lpad; |
| 3794 | } |
| 3795 | |
| 3796 | |
| 3797 | llvm::BasicBlock* MethodCompiler::GetUnwindBasicBlock() { |
| 3798 | // Check the existing unwinding baisc block block |
| 3799 | if (basic_block_unwind_ != NULL) { |
| 3800 | return basic_block_unwind_; |
| 3801 | } |
| 3802 | |
| 3803 | // Create new basic block for unwinding |
| 3804 | basic_block_unwind_ = |
| 3805 | llvm::BasicBlock::Create(*context_, "exception_unwind", func_); |
| 3806 | |
| 3807 | // Change IRBuilder insert point |
| 3808 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
| 3809 | irb_.SetInsertPoint(basic_block_unwind_); |
| 3810 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 3811 | // Pop the shadow frame |
| 3812 | EmitPopShadowFrame(); |
| 3813 | |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3814 | // Emit the code to return default value (zero) for the given return type. |
Logan Chien | dd361c9 | 2012-04-10 23:40:37 +0800 | [diff] [blame] | 3815 | char ret_shorty = oat_compilation_unit_->GetShorty()[0]; |
Logan Chien | 5bcc04e | 2012-01-30 14:15:12 +0800 | [diff] [blame] | 3816 | if (ret_shorty == 'V') { |
| 3817 | irb_.CreateRetVoid(); |
| 3818 | } else { |
| 3819 | irb_.CreateRet(irb_.getJZero(ret_shorty)); |
| 3820 | } |
| 3821 | |
| 3822 | // Restore the orignal insert point for IRBuilder |
| 3823 | irb_.restoreIP(irb_ip_original); |
| 3824 | |
| 3825 | return basic_block_unwind_; |
| 3826 | } |
| 3827 | |
| 3828 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3829 | llvm::Value* MethodCompiler::AllocDalvikLocalVarReg(RegCategory cat, |
| 3830 | uint32_t reg_idx) { |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3831 | // Get reg_type and reg_name from DalvikReg |
| 3832 | llvm::Type* reg_type = DalvikReg::GetRegCategoryEquivSizeTy(irb_, cat); |
| 3833 | std::string reg_name; |
| 3834 | |
| 3835 | #if !defined(NDEBUG) |
| 3836 | StringAppendF(®_name, "%c%u", DalvikReg::GetRegCategoryNamePrefix(cat), reg_idx); |
| 3837 | #endif |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3838 | |
| 3839 | // Save current IR builder insert point |
| 3840 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3841 | irb_.SetInsertPoint(basic_block_reg_alloca_); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3842 | |
| 3843 | // Alloca |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3844 | llvm::Value* reg_addr = irb_.CreateAlloca(reg_type, 0, reg_name); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3845 | |
| 3846 | // Restore IRBuilder insert point |
| 3847 | irb_.restoreIP(irb_ip_original); |
| 3848 | |
| 3849 | DCHECK_NE(reg_addr, static_cast<llvm::Value*>(NULL)); |
| 3850 | return reg_addr; |
| 3851 | } |
| 3852 | |
| 3853 | |
TDYa127 | 7f5b9be | 2012-04-29 01:31:49 -0700 | [diff] [blame] | 3854 | llvm::Value* MethodCompiler::AllocShadowFrameEntry(uint32_t reg_idx) { |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3855 | std::string reg_name; |
| 3856 | |
| 3857 | #if !defined(NDEBUG) |
| 3858 | StringAppendF(®_name, "o%u", reg_idx); |
| 3859 | #endif |
| 3860 | |
TDYa127 | 7f5b9be | 2012-04-29 01:31:49 -0700 | [diff] [blame] | 3861 | // Save current IR builder insert point |
| 3862 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
| 3863 | |
| 3864 | irb_.SetInsertPoint(basic_block_shadow_frame_alloca_); |
| 3865 | |
| 3866 | llvm::Value* gep_index[] = { |
| 3867 | irb_.getInt32(0), // No pointer displacement |
| 3868 | irb_.getInt32(1), // SIRT |
| 3869 | irb_.getInt32(reg_idx) // Pointer field |
| 3870 | }; |
| 3871 | |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3872 | llvm::Value* reg_addr = irb_.CreateGEP(shadow_frame_, gep_index, reg_name); |
TDYa127 | 7f5b9be | 2012-04-29 01:31:49 -0700 | [diff] [blame] | 3873 | |
| 3874 | // Restore IRBuilder insert point |
| 3875 | irb_.restoreIP(irb_ip_original); |
| 3876 | |
| 3877 | DCHECK_NE(reg_addr, static_cast<llvm::Value*>(NULL)); |
| 3878 | return reg_addr; |
| 3879 | } |
| 3880 | |
| 3881 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3882 | llvm::Value* MethodCompiler::AllocDalvikRetValReg(RegCategory cat) { |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3883 | // Get reg_type and reg_name from DalvikReg |
| 3884 | llvm::Type* reg_type = DalvikReg::GetRegCategoryEquivSizeTy(irb_, cat); |
| 3885 | std::string reg_name; |
| 3886 | |
| 3887 | #if !defined(NDEBUG) |
| 3888 | StringAppendF(®_name, "%c_res", DalvikReg::GetRegCategoryNamePrefix(cat)); |
| 3889 | #endif |
| 3890 | |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3891 | // Save current IR builder insert point |
| 3892 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3893 | irb_.SetInsertPoint(basic_block_reg_alloca_); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3894 | |
| 3895 | // Alloca |
TDYa127 | 67ae8ff | 2012-05-02 19:08:02 -0700 | [diff] [blame^] | 3896 | llvm::Value* reg_addr = irb_.CreateAlloca(reg_type, 0, reg_name); |
Logan Chien | c670a8d | 2011-12-20 21:25:56 +0800 | [diff] [blame] | 3897 | |
| 3898 | // Restore IRBuilder insert point |
| 3899 | irb_.restoreIP(irb_ip_original); |
| 3900 | |
| 3901 | DCHECK_NE(reg_addr, static_cast<llvm::Value*>(NULL)); |
| 3902 | return reg_addr; |
| 3903 | } |
| 3904 | |
| 3905 | |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 3906 | void MethodCompiler::EmitPopShadowFrame() { |
| 3907 | irb_.CreateCall(irb_.GetRuntime(PopShadowFrame)); |
| 3908 | } |
| 3909 | |
| 3910 | |
TDYa127 | c8dc101 | 2012-04-19 07:03:33 -0700 | [diff] [blame] | 3911 | void MethodCompiler::EmitUpdateDexPC(uint32_t dex_pc) { |
| 3912 | irb_.StoreToObjectOffset(shadow_frame_, |
| 3913 | ShadowFrame::DexPCOffset(), |
| 3914 | irb_.getInt32(dex_pc)); |
Logan Chien | 8dfcbea | 2012-02-17 18:50:32 +0800 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | |
Logan Chien | 8342616 | 2011-12-09 09:29:50 +0800 | [diff] [blame] | 3918 | } // namespace compiler_llvm |
| 3919 | } // namespace art |