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