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