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