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