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