blob: d8392d78fbc088eda5ce25cfc433dfe9dc9a0c1b [file] [log] [blame]
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001/*
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 "ir_builder.h"
18#include "utils_llvm.h"
19
TDYa1275e869b62012-07-25 00:45:39 -070020#include "compiler.h"
Ian Rogers76ae4fe2013-02-27 16:03:41 -080021#include "intrinsic_helper.h"
Ian Rogers98573f92013-01-30 17:26:32 -080022#include "mirror/abstract_method.h"
23#include "mirror/array.h"
TDYa1275e869b62012-07-25 00:45:39 -070024#include "oat_compilation_unit.h"
Shih-wei Liao21d28f52012-06-12 05:55:00 -070025#include "thread.h"
TDYa1275e869b62012-07-25 00:45:39 -070026#include "verifier/method_verifier.h"
Shih-wei Liao21d28f52012-06-12 05:55:00 -070027
buzbee395116c2013-02-27 14:30:25 -080028#include "compiler/dex/compiler_ir.h"
29#include "compiler/dex/quick/codegen.h"
TDYa127920be7c2012-09-10 17:13:22 -070030using art::kMIRIgnoreNullCheck;
31using art::kMIRIgnoreRangeCheck;
32
Shih-wei Liao21d28f52012-06-12 05:55:00 -070033#include <llvm/ADT/STLExtras.h>
34#include <llvm/Intrinsics.h>
Logan Chiend36a2ac2012-08-04 00:37:30 +080035#include <llvm/Metadata.h>
Shih-wei Liao21d28f52012-06-12 05:55:00 -070036#include <llvm/Pass.h>
37#include <llvm/Support/CFG.h>
38#include <llvm/Support/InstIterator.h>
39
40#include <vector>
TDYa127aa558872012-08-16 05:11:07 -070041#include <map>
42#include <utility>
Shih-wei Liao21d28f52012-06-12 05:55:00 -070043
TDYa127920be7c2012-09-10 17:13:22 -070044using namespace art::compiler_llvm;
Shih-wei Liao21d28f52012-06-12 05:55:00 -070045
Ian Rogers76ae4fe2013-02-27 16:03:41 -080046using art::compiler_llvm::IntrinsicHelper;
Shih-wei Liao21d28f52012-06-12 05:55:00 -070047
Shih-wei Liaob2596522012-09-14 16:36:11 -070048namespace art {
buzbee26f10ee2012-12-21 11:16:29 -080049extern char RemapShorty(char shortyType);
Shih-wei Liaob2596522012-09-14 16:36:11 -070050};
51
Shih-wei Liao21d28f52012-06-12 05:55:00 -070052namespace {
53
54class GBCExpanderPass : public llvm::FunctionPass {
55 private:
56 const IntrinsicHelper& intrinsic_helper_;
57 IRBuilder& irb_;
58
59 llvm::LLVMContext& context_;
60 RuntimeSupportBuilder& rtb_;
61
62 private:
63 llvm::AllocaInst* shadow_frame_;
64 llvm::Value* old_shadow_frame_;
Shih-wei Liao21d28f52012-06-12 05:55:00 -070065
66 private:
TDYa127920be7c2012-09-10 17:13:22 -070067 art::Compiler* compiler_;
TDYa1275e869b62012-07-25 00:45:39 -070068
TDYa127920be7c2012-09-10 17:13:22 -070069 const art::DexFile* dex_file_;
70 const art::DexFile::CodeItem* code_item_;
TDYa1275e869b62012-07-25 00:45:39 -070071
TDYa127920be7c2012-09-10 17:13:22 -070072 art::OatCompilationUnit* oat_compilation_unit_;
TDYa1275e869b62012-07-25 00:45:39 -070073
74 uint32_t method_idx_;
75
76 llvm::Function* func_;
77
78 std::vector<llvm::BasicBlock*> basic_blocks_;
79
80 std::vector<llvm::BasicBlock*> basic_block_landing_pads_;
TDYa12755e5e6c2012-09-11 15:14:42 -070081 llvm::BasicBlock* current_bb_;
TDYa127aa558872012-08-16 05:11:07 -070082 std::map<llvm::BasicBlock*, std::vector<std::pair<llvm::BasicBlock*, llvm::BasicBlock*> > >
83 landing_pad_phi_mapping_;
TDYa1275e869b62012-07-25 00:45:39 -070084 llvm::BasicBlock* basic_block_unwind_;
85
Logan Chien67645d82012-08-17 09:10:54 +080086 bool changed_;
87
TDYa1275e869b62012-07-25 00:45:39 -070088 private:
Shih-wei Liao21d28f52012-06-12 05:55:00 -070089 //----------------------------------------------------------------------------
Logan Chien75e4b602012-07-23 14:24:12 -070090 // Constant for GBC expansion
91 //----------------------------------------------------------------------------
92 enum IntegerShiftKind {
93 kIntegerSHL,
94 kIntegerSHR,
95 kIntegerUSHR,
96 };
97
98 private:
99 //----------------------------------------------------------------------------
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700100 // Helper function for GBC expansion
101 //----------------------------------------------------------------------------
102
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700103 llvm::Value* ExpandToRuntime(runtime_support::RuntimeId rt,
104 llvm::CallInst& inst);
105
TDYa1275e869b62012-07-25 00:45:39 -0700106 uint64_t LV2UInt(llvm::Value* lv) {
107 return llvm::cast<llvm::ConstantInt>(lv)->getZExtValue();
108 }
109
110 int64_t LV2SInt(llvm::Value* lv) {
111 return llvm::cast<llvm::ConstantInt>(lv)->getSExtValue();
112 }
113
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700114 private:
115 // TODO: Almost all Emit* are directly copy-n-paste from MethodCompiler.
116 // Refactor these utility functions from MethodCompiler to avoid forking.
117
Logan Chien67645d82012-08-17 09:10:54 +0800118 void EmitStackOverflowCheck(llvm::Instruction* first_non_alloca);
119
120 void RewriteFunction();
121
122 void RewriteBasicBlock(llvm::BasicBlock* original_block);
123
124 void UpdatePhiInstruction(llvm::BasicBlock* old_basic_block,
125 llvm::BasicBlock* new_basic_block);
126
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700127
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800128 // Sign or zero extend category 1 types < 32bits in size to 32bits.
129 llvm::Value* SignOrZeroExtendCat1Types(llvm::Value* value, JType jty);
130
131 // Truncate category 1 types from 32bits to the given JType size.
132 llvm::Value* TruncateCat1Types(llvm::Value* value, JType jty);
133
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700134 //----------------------------------------------------------------------------
135 // Dex cache code generation helper function
136 //----------------------------------------------------------------------------
TDYa127920be7c2012-09-10 17:13:22 -0700137 llvm::Value* EmitLoadDexCacheAddr(art::MemberOffset dex_cache_offset);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700138
139 llvm::Value* EmitLoadDexCacheStaticStorageFieldAddr(uint32_t type_idx);
140
141 llvm::Value* EmitLoadDexCacheResolvedTypeFieldAddr(uint32_t type_idx);
142
143 llvm::Value* EmitLoadDexCacheResolvedMethodFieldAddr(uint32_t method_idx);
144
145 llvm::Value* EmitLoadDexCacheStringFieldAddr(uint32_t string_idx);
146
147 //----------------------------------------------------------------------------
148 // Code generation helper function
149 //----------------------------------------------------------------------------
150 llvm::Value* EmitLoadMethodObjectAddr();
151
152 llvm::Value* EmitLoadArrayLength(llvm::Value* array);
153
154 llvm::Value* EmitLoadSDCalleeMethodObjectAddr(uint32_t callee_method_idx);
155
156 llvm::Value* EmitLoadVirtualCalleeMethodObjectAddr(int vtable_idx,
157 llvm::Value* this_addr);
158
159 llvm::Value* EmitArrayGEP(llvm::Value* array_addr,
160 llvm::Value* index_value,
161 JType elem_jty);
162
163 private:
164 //----------------------------------------------------------------------------
165 // Expand Greenland intrinsics
166 //----------------------------------------------------------------------------
167 void Expand_TestSuspend(llvm::CallInst& call_inst);
168
TDYa1279a129452012-07-19 03:10:08 -0700169 void Expand_MarkGCCard(llvm::CallInst& call_inst);
170
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700171 llvm::Value* Expand_LoadStringFromDexCache(llvm::Value* string_idx_value);
172
173 llvm::Value* Expand_LoadTypeFromDexCache(llvm::Value* type_idx_value);
174
175 void Expand_LockObject(llvm::Value* obj);
176
177 void Expand_UnlockObject(llvm::Value* obj);
178
179 llvm::Value* Expand_ArrayGet(llvm::Value* array_addr,
180 llvm::Value* index_value,
181 JType elem_jty);
182
183 void Expand_ArrayPut(llvm::Value* new_value,
184 llvm::Value* array_addr,
185 llvm::Value* index_value,
186 JType elem_jty);
187
188 void Expand_FilledNewArray(llvm::CallInst& call_inst);
189
190 llvm::Value* Expand_IGetFast(llvm::Value* field_offset_value,
191 llvm::Value* is_volatile_value,
192 llvm::Value* object_addr,
193 JType field_jty);
194
195 void Expand_IPutFast(llvm::Value* field_offset_value,
196 llvm::Value* is_volatile_value,
197 llvm::Value* object_addr,
198 llvm::Value* new_value,
199 JType field_jty);
200
201 llvm::Value* Expand_SGetFast(llvm::Value* static_storage_addr,
202 llvm::Value* field_offset_value,
203 llvm::Value* is_volatile_value,
204 JType field_jty);
205
206 void Expand_SPutFast(llvm::Value* static_storage_addr,
207 llvm::Value* field_offset_value,
208 llvm::Value* is_volatile_value,
209 llvm::Value* new_value,
210 JType field_jty);
211
212 llvm::Value* Expand_LoadDeclaringClassSSB(llvm::Value* method_object_addr);
213
214 llvm::Value* Expand_LoadClassSSBFromDexCache(llvm::Value* type_idx_value);
215
216 llvm::Value*
217 Expand_GetSDCalleeMethodObjAddrFast(llvm::Value* callee_method_idx_value);
218
219 llvm::Value*
220 Expand_GetVirtualCalleeMethodObjAddrFast(llvm::Value* vtable_idx_value,
221 llvm::Value* this_addr);
222
223 llvm::Value* Expand_Invoke(llvm::CallInst& call_inst);
224
TDYa1274ec8ccd2012-08-11 07:04:57 -0700225 llvm::Value* Expand_DivRem(llvm::CallInst& call_inst, bool is_div, JType op_jty);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700226
TDYa127ce4cc0d2012-11-18 16:59:53 -0800227 void Expand_AllocaShadowFrame(llvm::Value* num_vregs_value);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700228
TDYa1278e950c12012-11-02 09:58:19 -0700229 void Expand_SetVReg(llvm::Value* entry_idx, llvm::Value* obj);
230
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700231 void Expand_PopShadowFrame();
232
233 void Expand_UpdateDexPC(llvm::Value* dex_pc_value);
234
TDYa127a1b21852012-07-23 03:20:39 -0700235 //----------------------------------------------------------------------------
236 // Quick
237 //----------------------------------------------------------------------------
238
239 llvm::Value* Expand_FPCompare(llvm::Value* src1_value,
240 llvm::Value* src2_value,
241 bool gt_bias);
242
243 llvm::Value* Expand_LongCompare(llvm::Value* src1_value, llvm::Value* src2_value);
244
245 llvm::Value* EmitCompareResultSelection(llvm::Value* cmp_eq,
246 llvm::Value* cmp_lt);
247
TDYa127f71bf5a2012-07-29 20:09:52 -0700248 llvm::Value* EmitLoadConstantClass(uint32_t dex_pc, uint32_t type_idx);
TDYa1275a26d442012-07-26 18:58:38 -0700249 llvm::Value* EmitLoadStaticStorage(uint32_t dex_pc, uint32_t type_idx);
250
TDYa1275e869b62012-07-25 00:45:39 -0700251 llvm::Value* Expand_HLIGet(llvm::CallInst& call_inst, JType field_jty);
252 void Expand_HLIPut(llvm::CallInst& call_inst, JType field_jty);
253
TDYa1275a26d442012-07-26 18:58:38 -0700254 llvm::Value* Expand_HLSget(llvm::CallInst& call_inst, JType field_jty);
255 void Expand_HLSput(llvm::CallInst& call_inst, JType field_jty);
256
257 llvm::Value* Expand_HLArrayGet(llvm::CallInst& call_inst, JType field_jty);
258 void Expand_HLArrayPut(llvm::CallInst& call_inst, JType field_jty);
259
TDYa127f71bf5a2012-07-29 20:09:52 -0700260 llvm::Value* Expand_ConstString(llvm::CallInst& call_inst);
261 llvm::Value* Expand_ConstClass(llvm::CallInst& call_inst);
262
263 void Expand_MonitorEnter(llvm::CallInst& call_inst);
264 void Expand_MonitorExit(llvm::CallInst& call_inst);
265
266 void Expand_HLCheckCast(llvm::CallInst& call_inst);
267 llvm::Value* Expand_InstanceOf(llvm::CallInst& call_inst);
268
269 llvm::Value* Expand_NewInstance(llvm::CallInst& call_inst);
270
271 llvm::Value* Expand_HLInvoke(llvm::CallInst& call_inst);
272
273 llvm::Value* Expand_OptArrayLength(llvm::CallInst& call_inst);
274 llvm::Value* Expand_NewArray(llvm::CallInst& call_inst);
275 llvm::Value* Expand_HLFilledNewArray(llvm::CallInst& call_inst);
276 void Expand_HLFillArrayData(llvm::CallInst& call_inst);
277
278 llvm::Value* EmitAllocNewArray(uint32_t dex_pc,
279 llvm::Value* array_length_value,
280 uint32_t type_idx,
281 bool is_filled_new_array);
282
283 llvm::Value* EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx,
TDYa127920be7c2012-09-10 17:13:22 -0700284 art::InvokeType invoke_type,
TDYa127f71bf5a2012-07-29 20:09:52 -0700285 llvm::Value* this_addr,
286 uint32_t dex_pc,
287 bool is_fast_path);
288
TDYa1275e869b62012-07-25 00:45:39 -0700289 void EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr);
290
291 void EmitUpdateDexPC(uint32_t dex_pc);
292
293 void EmitGuard_DivZeroException(uint32_t dex_pc,
294 llvm::Value* denominator,
295 JType op_jty);
296
297 void EmitGuard_NullPointerException(uint32_t dex_pc,
298 llvm::Value* object);
299
300 void EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc,
301 llvm::Value* array,
302 llvm::Value* index);
303
TDYa1275e869b62012-07-25 00:45:39 -0700304 llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static);
305
306 llvm::BasicBlock* GetBasicBlock(uint32_t dex_pc);
307
308 llvm::BasicBlock* CreateBasicBlockWithDexPC(uint32_t dex_pc,
309 const char* postfix);
310
311 int32_t GetTryItemOffset(uint32_t dex_pc);
312
313 llvm::BasicBlock* GetLandingPadBasicBlock(uint32_t dex_pc);
314
315 llvm::BasicBlock* GetUnwindBasicBlock();
316
317 void EmitGuard_ExceptionLandingPad(uint32_t dex_pc);
318
319 void EmitBranchExceptionLandingPad(uint32_t dex_pc);
320
Logan Chien75e4b602012-07-23 14:24:12 -0700321 //----------------------------------------------------------------------------
322 // Expand Arithmetic Helper Intrinsics
323 //----------------------------------------------------------------------------
324
325 llvm::Value* Expand_IntegerShift(llvm::Value* src1_value,
326 llvm::Value* src2_value,
327 IntegerShiftKind kind,
328 JType op_jty);
329
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700330 public:
331 static char ID;
332
333 GBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb)
334 : llvm::FunctionPass(ID), intrinsic_helper_(intrinsic_helper), irb_(irb),
Logan Chiene5b8f8b2012-08-13 11:45:05 +0800335 context_(irb.getContext()), rtb_(irb.Runtime()),
TDYa1278e950c12012-11-02 09:58:19 -0700336 shadow_frame_(NULL), old_shadow_frame_(NULL),
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700337 compiler_(NULL), dex_file_(NULL), code_item_(NULL),
Logan Chien67645d82012-08-17 09:10:54 +0800338 oat_compilation_unit_(NULL), method_idx_(-1u), func_(NULL),
339 changed_(false)
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700340 { }
341
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700342 GBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb,
TDYa127920be7c2012-09-10 17:13:22 -0700343 art::Compiler* compiler, art::OatCompilationUnit* oat_compilation_unit)
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700344 : llvm::FunctionPass(ID), intrinsic_helper_(intrinsic_helper), irb_(irb),
345 context_(irb.getContext()), rtb_(irb.Runtime()),
TDYa1278e950c12012-11-02 09:58:19 -0700346 shadow_frame_(NULL), old_shadow_frame_(NULL),
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700347 compiler_(compiler),
348 dex_file_(oat_compilation_unit->GetDexFile()),
349 code_item_(oat_compilation_unit->GetCodeItem()),
350 oat_compilation_unit_(oat_compilation_unit),
351 method_idx_(oat_compilation_unit->GetDexMethodIndex()),
352 func_(NULL), changed_(false)
353 { }
354
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700355 bool runOnFunction(llvm::Function& func);
356
357 private:
Logan Chien67645d82012-08-17 09:10:54 +0800358 void InsertStackOverflowCheck(llvm::Function& func);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700359
360 llvm::Value* ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id,
361 llvm::CallInst& call_inst);
362
363};
364
365char GBCExpanderPass::ID = 0;
366
367bool GBCExpanderPass::runOnFunction(llvm::Function& func) {
TDYa127b672d1e2012-06-28 21:21:45 -0700368 // Runtime support or stub
369 if (func.getName().startswith("art_") || func.getName().startswith("Art")) {
370 return false;
371 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700372
Logan Chien67645d82012-08-17 09:10:54 +0800373 // Setup rewrite context
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700374 shadow_frame_ = NULL;
375 old_shadow_frame_ = NULL;
TDYa1275e869b62012-07-25 00:45:39 -0700376 func_ = &func;
Logan Chien67645d82012-08-17 09:10:54 +0800377 changed_ = false; // Assume unchanged
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700378
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700379 basic_blocks_.resize(code_item_->insns_size_in_code_units_);
380 basic_block_landing_pads_.resize(code_item_->tries_size_, NULL);
381 basic_block_unwind_ = NULL;
382 for (llvm::Function::iterator bb_iter = func_->begin(), bb_end = func_->end();
383 bb_iter != bb_end;
384 ++bb_iter) {
385 if (bb_iter->begin()->getMetadata("DexOff") == NULL) {
386 continue;
387 }
388 uint32_t dex_pc = LV2UInt(bb_iter->begin()->getMetadata("DexOff")->getOperand(0));
389 basic_blocks_[dex_pc] = bb_iter;
390 }
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -0700391
Logan Chien67645d82012-08-17 09:10:54 +0800392 // Insert stack overflow check
393 InsertStackOverflowCheck(func); // TODO: Use intrinsic.
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700394
Logan Chien67645d82012-08-17 09:10:54 +0800395 // Rewrite the intrinsics
396 RewriteFunction();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700397
398 VERIFY_LLVM_FUNCTION(func);
399
Logan Chien67645d82012-08-17 09:10:54 +0800400 return changed_;
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700401}
402
Logan Chien67645d82012-08-17 09:10:54 +0800403void GBCExpanderPass::RewriteBasicBlock(llvm::BasicBlock* original_block) {
404 llvm::BasicBlock* curr_basic_block = original_block;
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700405
Logan Chien67645d82012-08-17 09:10:54 +0800406 llvm::BasicBlock::iterator inst_iter = original_block->begin();
407 llvm::BasicBlock::iterator inst_end = original_block->end();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700408
Logan Chien67645d82012-08-17 09:10:54 +0800409 while (inst_iter != inst_end) {
410 llvm::CallInst* call_inst = llvm::dyn_cast<llvm::CallInst>(inst_iter);
411 IntrinsicHelper::IntrinsicId intr_id = IntrinsicHelper::UnknownId;
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700412
Logan Chien67645d82012-08-17 09:10:54 +0800413 if (call_inst) {
414 llvm::Function* callee_func = call_inst->getCalledFunction();
415 intr_id = intrinsic_helper_.GetIntrinsicId(callee_func);
416 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700417
Logan Chien67645d82012-08-17 09:10:54 +0800418 if (intr_id == IntrinsicHelper::UnknownId) {
419 // This is not intrinsic call. Skip this instruction.
420 ++inst_iter;
421 continue;
422 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700423
Logan Chien67645d82012-08-17 09:10:54 +0800424 // Rewrite the intrinsic and change the function
425 changed_ = true;
426 irb_.SetInsertPoint(inst_iter);
427
428 // Expand the intrinsic
429 if (llvm::Value* new_value = ExpandIntrinsic(intr_id, *call_inst)) {
430 inst_iter->replaceAllUsesWith(new_value);
431 }
432
433 // Remove the old intrinsic call instruction
434 llvm::BasicBlock::iterator old_inst = inst_iter++;
435 old_inst->eraseFromParent();
436
437 // Splice the instruction to the new basic block
438 llvm::BasicBlock* next_basic_block = irb_.GetInsertBlock();
439 if (next_basic_block != curr_basic_block) {
440 next_basic_block->getInstList().splice(
441 irb_.GetInsertPoint(), curr_basic_block->getInstList(),
442 inst_iter, inst_end);
443 curr_basic_block = next_basic_block;
444 inst_end = curr_basic_block->end();
445 }
446 }
447}
448
449
450void GBCExpanderPass::RewriteFunction() {
451 size_t num_basic_blocks = func_->getBasicBlockList().size();
452 // NOTE: We are not using (bb_iter != bb_end) as the for-loop condition,
453 // because we will create new basic block while expanding the intrinsics.
454 // We only want to iterate through the input basic blocks.
455
TDYa127aa558872012-08-16 05:11:07 -0700456 landing_pad_phi_mapping_.clear();
457
Logan Chien67645d82012-08-17 09:10:54 +0800458 for (llvm::Function::iterator bb_iter = func_->begin();
459 num_basic_blocks > 0; ++bb_iter, --num_basic_blocks) {
Shih-wei Liao627d8c42012-08-24 08:31:18 -0700460 // Set insert point to current basic block.
461 irb_.SetInsertPoint(bb_iter);
Logan Chien67645d82012-08-17 09:10:54 +0800462
TDYa12755e5e6c2012-09-11 15:14:42 -0700463 current_bb_ = bb_iter;
TDYa127aa558872012-08-16 05:11:07 -0700464
Logan Chien67645d82012-08-17 09:10:54 +0800465 // Rewrite the basic block
466 RewriteBasicBlock(bb_iter);
467
468 // Update the phi-instructions in the successor basic block
469 llvm::BasicBlock* last_block = irb_.GetInsertBlock();
470 if (last_block != bb_iter) {
471 UpdatePhiInstruction(bb_iter, last_block);
472 }
473 }
TDYa127aa558872012-08-16 05:11:07 -0700474
475 typedef std::map<llvm::PHINode*, llvm::PHINode*> HandlerPHIMap;
476 HandlerPHIMap handler_phi;
477 // Iterate every used landing pad basic block
478 for (size_t i = 0, ei = basic_block_landing_pads_.size(); i != ei; ++i) {
479 llvm::BasicBlock* lbb = basic_block_landing_pads_[i];
480 if (lbb == NULL) {
481 continue;
482 }
483
484 llvm::TerminatorInst* term_inst = lbb->getTerminator();
485 std::vector<std::pair<llvm::BasicBlock*, llvm::BasicBlock*> >& rewrite_pair
486 = landing_pad_phi_mapping_[lbb];
487 irb_.SetInsertPoint(lbb->begin());
488
489 // Iterate every succeeding basic block (catch block)
490 for (unsigned succ_iter = 0, succ_end = term_inst->getNumSuccessors();
491 succ_iter != succ_end; ++succ_iter) {
492 llvm::BasicBlock* succ_basic_block = term_inst->getSuccessor(succ_iter);
493
494 // Iterate every phi instructions in the succeeding basic block
495 for (llvm::BasicBlock::iterator
496 inst_iter = succ_basic_block->begin(),
497 inst_end = succ_basic_block->end();
498 inst_iter != inst_end; ++inst_iter) {
499 llvm::PHINode *phi = llvm::dyn_cast<llvm::PHINode>(inst_iter);
500
501 if (!phi) {
502 break; // Meet non-phi instruction. Done.
503 }
504
505 if (handler_phi[phi] == NULL) {
506 handler_phi[phi] = llvm::PHINode::Create(phi->getType(), 1);
507 }
508
509 // Create new_phi in landing pad
510 llvm::PHINode* new_phi = irb_.CreatePHI(phi->getType(), rewrite_pair.size());
511 // Insert all incoming value into new_phi by rewrite_pair
512 for (size_t j = 0, ej = rewrite_pair.size(); j != ej; ++j) {
513 llvm::BasicBlock* old_bb = rewrite_pair[j].first;
514 llvm::BasicBlock* new_bb = rewrite_pair[j].second;
515 new_phi->addIncoming(phi->getIncomingValueForBlock(old_bb), new_bb);
516 }
517 // Delete all incoming value from phi by rewrite_pair
518 for (size_t j = 0, ej = rewrite_pair.size(); j != ej; ++j) {
519 llvm::BasicBlock* old_bb = rewrite_pair[j].first;
520 int old_bb_idx = phi->getBasicBlockIndex(old_bb);
521 if (old_bb_idx >= 0) {
522 phi->removeIncomingValue(old_bb_idx, false);
523 }
524 }
525 // Insert new_phi into new handler phi
526 handler_phi[phi]->addIncoming(new_phi, lbb);
527 }
528 }
529 }
530
531 // Replace all handler phi
532 // We can't just use the old handler phi, because some exception edges will disappear after we
533 // compute fast-path.
534 for (HandlerPHIMap::iterator it = handler_phi.begin(); it != handler_phi.end(); ++it) {
535 llvm::PHINode* old_phi = it->first;
536 llvm::PHINode* new_phi = it->second;
537 new_phi->insertBefore(old_phi);
538 old_phi->replaceAllUsesWith(new_phi);
539 old_phi->eraseFromParent();
540 }
Logan Chien67645d82012-08-17 09:10:54 +0800541}
542
543void GBCExpanderPass::UpdatePhiInstruction(llvm::BasicBlock* old_basic_block,
544 llvm::BasicBlock* new_basic_block) {
545 llvm::TerminatorInst* term_inst = new_basic_block->getTerminator();
546
547 if (!term_inst) {
548 return; // No terminating instruction in new_basic_block. Nothing to do.
549 }
550
551 // Iterate every succeeding basic block
552 for (unsigned succ_iter = 0, succ_end = term_inst->getNumSuccessors();
553 succ_iter != succ_end; ++succ_iter) {
554 llvm::BasicBlock* succ_basic_block = term_inst->getSuccessor(succ_iter);
555
556 // Iterate every phi instructions in the succeeding basic block
557 for (llvm::BasicBlock::iterator
558 inst_iter = succ_basic_block->begin(),
559 inst_end = succ_basic_block->end();
560 inst_iter != inst_end; ++inst_iter) {
561 llvm::PHINode *phi = llvm::dyn_cast<llvm::PHINode>(inst_iter);
562
563 if (!phi) {
564 break; // Meet non-phi instruction. Done.
565 }
566
567 // Update the incoming block of this phi instruction
568 for (llvm::PHINode::block_iterator
569 ibb_iter = phi->block_begin(), ibb_end = phi->block_end();
570 ibb_iter != ibb_end; ++ibb_iter) {
571 if (*ibb_iter == old_basic_block) {
572 *ibb_iter = new_basic_block;
573 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700574 }
575 }
576 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700577}
578
579llvm::Value* GBCExpanderPass::ExpandToRuntime(runtime_support::RuntimeId rt,
580 llvm::CallInst& inst) {
581 // Some GBC intrinsic can directly replace with IBC runtime. "Directly" means
582 // the arguments passed to the GBC intrinsic are as the same as IBC runtime
583 // function, therefore only called function is needed to change.
584 unsigned num_args = inst.getNumArgOperands();
585
586 if (num_args <= 0) {
587 return irb_.CreateCall(irb_.GetRuntime(rt));
588 } else {
589 std::vector<llvm::Value*> args;
590 for (unsigned i = 0; i < num_args; i++) {
591 args.push_back(inst.getArgOperand(i));
592 }
593
594 return irb_.CreateCall(irb_.GetRuntime(rt), args);
595 }
596}
597
Logan Chien67645d82012-08-17 09:10:54 +0800598void
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700599GBCExpanderPass::EmitStackOverflowCheck(llvm::Instruction* first_non_alloca) {
600 llvm::Function* func = first_non_alloca->getParent()->getParent();
601 llvm::Module* module = func->getParent();
602
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700603 // Call llvm intrinsic function to get frame address.
604 llvm::Function* frameaddress =
605 llvm::Intrinsic::getDeclaration(module, llvm::Intrinsic::frameaddress);
606
607 // The type of llvm::frameaddress is: i8* @llvm.frameaddress(i32)
608 llvm::Value* frame_address = irb_.CreateCall(frameaddress, irb_.getInt32(0));
609
610 // Cast i8* to int
611 frame_address = irb_.CreatePtrToInt(frame_address, irb_.getPtrEquivIntTy());
612
613 // Get thread.stack_end_
614 llvm::Value* stack_end =
TDYa127920be7c2012-09-10 17:13:22 -0700615 irb_.Runtime().EmitLoadFromThreadOffset(art::Thread::StackEndOffset().Int32Value(),
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700616 irb_.getPtrEquivIntTy(),
617 kTBAARuntimeInfo);
618
619 // Check the frame address < thread.stack_end_ ?
620 llvm::Value* is_stack_overflow = irb_.CreateICmpULT(frame_address, stack_end);
621
622 llvm::BasicBlock* block_exception =
623 llvm::BasicBlock::Create(context_, "stack_overflow", func);
624
625 llvm::BasicBlock* block_continue =
626 llvm::BasicBlock::Create(context_, "stack_overflow_cont", func);
627
628 irb_.CreateCondBr(is_stack_overflow, block_exception, block_continue, kUnlikely);
629
630 // If stack overflow, throw exception.
631 irb_.SetInsertPoint(block_exception);
632 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowStackOverflowException));
633
634 // Unwind.
635 llvm::Type* ret_type = func->getReturnType();
636 if (ret_type->isVoidTy()) {
637 irb_.CreateRetVoid();
638 } else {
639 // The return value is ignored when there's an exception. MethodCompiler
640 // returns zero value under the the corresponding return type in this case.
641 // GBCExpander returns LLVM undef value here for brevity
642 irb_.CreateRet(llvm::UndefValue::get(ret_type));
643 }
644
645 irb_.SetInsertPoint(block_continue);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700646}
647
TDYa127920be7c2012-09-10 17:13:22 -0700648llvm::Value* GBCExpanderPass::EmitLoadDexCacheAddr(art::MemberOffset offset) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700649 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
650
651 return irb_.LoadFromObjectOffset(method_object_addr,
652 offset.Int32Value(),
653 irb_.getJObjectTy(),
654 kTBAAConstJObject);
655}
656
657llvm::Value*
658GBCExpanderPass::EmitLoadDexCacheStaticStorageFieldAddr(uint32_t type_idx) {
659 llvm::Value* static_storage_dex_cache_addr =
Ian Rogers98573f92013-01-30 17:26:32 -0800660 EmitLoadDexCacheAddr(art::mirror::AbstractMethod::DexCacheInitializedStaticStorageOffset());
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700661
662 llvm::Value* type_idx_value = irb_.getPtrEquivInt(type_idx);
663
664 return EmitArrayGEP(static_storage_dex_cache_addr, type_idx_value, kObject);
665}
666
667llvm::Value*
668GBCExpanderPass::EmitLoadDexCacheResolvedTypeFieldAddr(uint32_t type_idx) {
669 llvm::Value* resolved_type_dex_cache_addr =
Ian Rogers98573f92013-01-30 17:26:32 -0800670 EmitLoadDexCacheAddr(art::mirror::AbstractMethod::DexCacheResolvedTypesOffset());
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700671
672 llvm::Value* type_idx_value = irb_.getPtrEquivInt(type_idx);
673
674 return EmitArrayGEP(resolved_type_dex_cache_addr, type_idx_value, kObject);
675}
676
677llvm::Value* GBCExpanderPass::
678EmitLoadDexCacheResolvedMethodFieldAddr(uint32_t method_idx) {
679 llvm::Value* resolved_method_dex_cache_addr =
Ian Rogers98573f92013-01-30 17:26:32 -0800680 EmitLoadDexCacheAddr(art::mirror::AbstractMethod::DexCacheResolvedMethodsOffset());
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700681
682 llvm::Value* method_idx_value = irb_.getPtrEquivInt(method_idx);
683
684 return EmitArrayGEP(resolved_method_dex_cache_addr, method_idx_value, kObject);
685}
686
687llvm::Value* GBCExpanderPass::
688EmitLoadDexCacheStringFieldAddr(uint32_t string_idx) {
689 llvm::Value* string_dex_cache_addr =
Ian Rogers98573f92013-01-30 17:26:32 -0800690 EmitLoadDexCacheAddr(art::mirror::AbstractMethod::DexCacheStringsOffset());
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700691
692 llvm::Value* string_idx_value = irb_.getPtrEquivInt(string_idx);
693
694 return EmitArrayGEP(string_dex_cache_addr, string_idx_value, kObject);
695}
696
697llvm::Value* GBCExpanderPass::EmitLoadMethodObjectAddr() {
698 llvm::Function* parent_func = irb_.GetInsertBlock()->getParent();
699 return parent_func->arg_begin();
700}
701
702llvm::Value* GBCExpanderPass::EmitLoadArrayLength(llvm::Value* array) {
703 // Load array length
704 return irb_.LoadFromObjectOffset(array,
Ian Rogers98573f92013-01-30 17:26:32 -0800705 art::mirror::Array::LengthOffset().Int32Value(),
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700706 irb_.getJIntTy(),
707 kTBAAConstJObject);
708
709}
710
711llvm::Value*
712GBCExpanderPass::EmitLoadSDCalleeMethodObjectAddr(uint32_t callee_method_idx) {
713 llvm::Value* callee_method_object_field_addr =
714 EmitLoadDexCacheResolvedMethodFieldAddr(callee_method_idx);
715
TDYa127ce4cc0d2012-11-18 16:59:53 -0800716 return irb_.CreateLoad(callee_method_object_field_addr, kTBAARuntimeInfo);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700717}
718
719llvm::Value* GBCExpanderPass::
720EmitLoadVirtualCalleeMethodObjectAddr(int vtable_idx, llvm::Value* this_addr) {
721 // Load class object of *this* pointer
722 llvm::Value* class_object_addr =
723 irb_.LoadFromObjectOffset(this_addr,
Ian Rogers98573f92013-01-30 17:26:32 -0800724 art::mirror::Object::ClassOffset().Int32Value(),
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700725 irb_.getJObjectTy(),
726 kTBAAConstJObject);
727
728 // Load vtable address
729 llvm::Value* vtable_addr =
730 irb_.LoadFromObjectOffset(class_object_addr,
Ian Rogers98573f92013-01-30 17:26:32 -0800731 art::mirror::Class::VTableOffset().Int32Value(),
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700732 irb_.getJObjectTy(),
733 kTBAAConstJObject);
734
735 // Load callee method object
736 llvm::Value* vtable_idx_value =
737 irb_.getPtrEquivInt(static_cast<uint64_t>(vtable_idx));
738
739 llvm::Value* method_field_addr =
740 EmitArrayGEP(vtable_addr, vtable_idx_value, kObject);
741
742 return irb_.CreateLoad(method_field_addr, kTBAAConstJObject);
743}
744
745// Emit Array GetElementPtr
746llvm::Value* GBCExpanderPass::EmitArrayGEP(llvm::Value* array_addr,
747 llvm::Value* index_value,
748 JType elem_jty) {
749
750 int data_offset;
751 if (elem_jty == kLong || elem_jty == kDouble ||
Ian Rogers98573f92013-01-30 17:26:32 -0800752 (elem_jty == kObject && sizeof(uint64_t) == sizeof(art::mirror::Object*))) {
753 data_offset = art::mirror::Array::DataOffset(sizeof(int64_t)).Int32Value();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700754 } else {
Ian Rogers98573f92013-01-30 17:26:32 -0800755 data_offset = art::mirror::Array::DataOffset(sizeof(int32_t)).Int32Value();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700756 }
757
758 llvm::Constant* data_offset_value =
759 irb_.getPtrEquivInt(data_offset);
760
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800761 llvm::Type* elem_type = irb_.getJType(elem_jty);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700762
763 llvm::Value* array_data_addr =
764 irb_.CreatePtrDisp(array_addr, data_offset_value,
765 elem_type->getPointerTo());
766
767 return irb_.CreateGEP(array_data_addr, index_value);
768}
769
770void GBCExpanderPass::Expand_TestSuspend(llvm::CallInst& call_inst) {
TDYa127ce4cc0d2012-11-18 16:59:53 -0800771 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
772
773 llvm::Value* suspend_count =
774 irb_.Runtime().EmitLoadFromThreadOffset(art::Thread::ThreadFlagsOffset().Int32Value(),
775 irb_.getInt16Ty(),
776 kTBAARuntimeInfo);
777 llvm::Value* is_suspend = irb_.CreateICmpNE(suspend_count, irb_.getInt16(0));
778
779 llvm::BasicBlock* basic_block_suspend = CreateBasicBlockWithDexPC(dex_pc, "suspend");
780 llvm::BasicBlock* basic_block_cont = CreateBasicBlockWithDexPC(dex_pc, "suspend_cont");
781
782 irb_.CreateCondBr(is_suspend, basic_block_suspend, basic_block_cont, kUnlikely);
783
784 irb_.SetInsertPoint(basic_block_suspend);
785 if (dex_pc != art::DexFile::kDexNoIndex) {
786 EmitUpdateDexPC(dex_pc);
787 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700788 irb_.Runtime().EmitTestSuspend();
Jeff Hao11ffc2d2013-02-01 11:52:17 -0800789
790 llvm::BasicBlock* basic_block_exception = CreateBasicBlockWithDexPC(dex_pc, "exception");
791 llvm::Value* exception_pending = irb_.Runtime().EmitIsExceptionPending();
792 irb_.CreateCondBr(exception_pending, basic_block_exception, basic_block_cont, kUnlikely);
793
794 irb_.SetInsertPoint(basic_block_exception);
795 llvm::Type* ret_type = call_inst.getParent()->getParent()->getReturnType();
796 if (ret_type->isVoidTy()) {
797 irb_.CreateRetVoid();
798 } else {
799 // The return value is ignored when there's an exception.
800 irb_.CreateRet(llvm::UndefValue::get(ret_type));
801 }
TDYa127ce4cc0d2012-11-18 16:59:53 -0800802
803 irb_.SetInsertPoint(basic_block_cont);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700804 return;
805}
806
TDYa1279a129452012-07-19 03:10:08 -0700807void GBCExpanderPass::Expand_MarkGCCard(llvm::CallInst& call_inst) {
TDYa1279a129452012-07-19 03:10:08 -0700808 irb_.Runtime().EmitMarkGCCard(call_inst.getArgOperand(0), call_inst.getArgOperand(1));
TDYa1279a129452012-07-19 03:10:08 -0700809 return;
810}
811
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700812llvm::Value*
813GBCExpanderPass::Expand_LoadStringFromDexCache(llvm::Value* string_idx_value) {
814 uint32_t string_idx =
815 llvm::cast<llvm::ConstantInt>(string_idx_value)->getZExtValue();
816
817 llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx);
818
TDYa127ce4cc0d2012-11-18 16:59:53 -0800819 return irb_.CreateLoad(string_field_addr, kTBAARuntimeInfo);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700820}
821
822llvm::Value*
823GBCExpanderPass::Expand_LoadTypeFromDexCache(llvm::Value* type_idx_value) {
824 uint32_t type_idx =
825 llvm::cast<llvm::ConstantInt>(type_idx_value)->getZExtValue();
826
827 llvm::Value* type_field_addr =
828 EmitLoadDexCacheResolvedTypeFieldAddr(type_idx);
829
TDYa127ce4cc0d2012-11-18 16:59:53 -0800830 return irb_.CreateLoad(type_field_addr, kTBAARuntimeInfo);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700831}
832
833void GBCExpanderPass::Expand_LockObject(llvm::Value* obj) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700834 rtb_.EmitLockObject(obj);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700835 return;
836}
837
838void GBCExpanderPass::Expand_UnlockObject(llvm::Value* obj) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700839 rtb_.EmitUnlockObject(obj);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700840 return;
841}
842
843llvm::Value* GBCExpanderPass::Expand_ArrayGet(llvm::Value* array_addr,
844 llvm::Value* index_value,
845 JType elem_jty) {
846 llvm::Value* array_elem_addr =
847 EmitArrayGEP(array_addr, index_value, elem_jty);
848
849 return irb_.CreateLoad(array_elem_addr, kTBAAHeapArray, elem_jty);
850}
851
852void GBCExpanderPass::Expand_ArrayPut(llvm::Value* new_value,
853 llvm::Value* array_addr,
854 llvm::Value* index_value,
855 JType elem_jty) {
856 llvm::Value* array_elem_addr =
857 EmitArrayGEP(array_addr, index_value, elem_jty);
858
859 irb_.CreateStore(new_value, array_elem_addr, kTBAAHeapArray, elem_jty);
860
861 return;
862}
863
864void GBCExpanderPass::Expand_FilledNewArray(llvm::CallInst& call_inst) {
865 // Most of the codes refer to MethodCompiler::EmitInsn_FilledNewArray
866 llvm::Value* array = call_inst.getArgOperand(0);
867
868 uint32_t element_jty =
869 llvm::cast<llvm::ConstantInt>(call_inst.getArgOperand(1))->getZExtValue();
870
871 DCHECK(call_inst.getNumArgOperands() > 2);
872 unsigned num_elements = (call_inst.getNumArgOperands() - 2);
873
874 bool is_elem_int_ty = (static_cast<JType>(element_jty) == kInt);
875
876 uint32_t alignment;
877 llvm::Constant* elem_size;
878 llvm::PointerType* field_type;
879
880 // NOTE: Currently filled-new-array only supports 'L', '[', and 'I'
881 // as the element, thus we are only checking 2 cases: primitive int and
882 // non-primitive type.
883 if (is_elem_int_ty) {
884 alignment = sizeof(int32_t);
885 elem_size = irb_.getPtrEquivInt(sizeof(int32_t));
886 field_type = irb_.getJIntTy()->getPointerTo();
887 } else {
888 alignment = irb_.getSizeOfPtrEquivInt();
889 elem_size = irb_.getSizeOfPtrEquivIntValue();
890 field_type = irb_.getJObjectTy()->getPointerTo();
891 }
892
893 llvm::Value* data_field_offset =
Ian Rogers98573f92013-01-30 17:26:32 -0800894 irb_.getPtrEquivInt(art::mirror::Array::DataOffset(alignment).Int32Value());
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700895
896 llvm::Value* data_field_addr =
897 irb_.CreatePtrDisp(array, data_field_offset, field_type);
898
899 for (unsigned i = 0; i < num_elements; ++i) {
900 // Values to fill the array begin at the 3rd argument
901 llvm::Value* reg_value = call_inst.getArgOperand(2 + i);
902
903 irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray);
904
905 data_field_addr =
906 irb_.CreatePtrDisp(data_field_addr, elem_size, field_type);
907 }
908
909 return;
910}
911
912llvm::Value* GBCExpanderPass::Expand_IGetFast(llvm::Value* field_offset_value,
913 llvm::Value* /*is_volatile_value*/,
914 llvm::Value* object_addr,
915 JType field_jty) {
916 int field_offset =
917 llvm::cast<llvm::ConstantInt>(field_offset_value)->getSExtValue();
918
919 DCHECK_GE(field_offset, 0);
920
921 llvm::PointerType* field_type =
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800922 irb_.getJType(field_jty)->getPointerTo();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700923
924 field_offset_value = irb_.getPtrEquivInt(field_offset);
925
926 llvm::Value* field_addr =
927 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
928
929 // TODO: Check is_volatile. We need to generate atomic load instruction
930 // when is_volatile is true.
931 return irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty);
932}
933
934void GBCExpanderPass::Expand_IPutFast(llvm::Value* field_offset_value,
935 llvm::Value* /* is_volatile_value */,
936 llvm::Value* object_addr,
937 llvm::Value* new_value,
938 JType field_jty) {
939 int field_offset =
940 llvm::cast<llvm::ConstantInt>(field_offset_value)->getSExtValue();
941
942 DCHECK_GE(field_offset, 0);
943
944 llvm::PointerType* field_type =
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800945 irb_.getJType(field_jty)->getPointerTo();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700946
947 field_offset_value = irb_.getPtrEquivInt(field_offset);
948
949 llvm::Value* field_addr =
950 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
951
952 // TODO: Check is_volatile. We need to generate atomic store instruction
953 // when is_volatile is true.
954 irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty);
955
956 return;
957}
958
959llvm::Value* GBCExpanderPass::Expand_SGetFast(llvm::Value* static_storage_addr,
960 llvm::Value* field_offset_value,
961 llvm::Value* /*is_volatile_value*/,
962 JType field_jty) {
963 int field_offset =
964 llvm::cast<llvm::ConstantInt>(field_offset_value)->getSExtValue();
965
966 DCHECK_GE(field_offset, 0);
967
968 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
969
970 llvm::Value* static_field_addr =
971 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800972 irb_.getJType(field_jty)->getPointerTo());
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700973
974 // TODO: Check is_volatile. We need to generate atomic store instruction
975 // when is_volatile is true.
976 return irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty);
977}
978
979void GBCExpanderPass::Expand_SPutFast(llvm::Value* static_storage_addr,
980 llvm::Value* field_offset_value,
981 llvm::Value* /* is_volatile_value */,
982 llvm::Value* new_value,
983 JType field_jty) {
984 int field_offset =
985 llvm::cast<llvm::ConstantInt>(field_offset_value)->getSExtValue();
986
987 DCHECK_GE(field_offset, 0);
988
989 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
990
991 llvm::Value* static_field_addr =
992 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
Ian Rogers76ae4fe2013-02-27 16:03:41 -0800993 irb_.getJType(field_jty)->getPointerTo());
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700994
995 // TODO: Check is_volatile. We need to generate atomic store instruction
996 // when is_volatile is true.
997 irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty);
998
999 return;
1000}
1001
1002llvm::Value*
1003GBCExpanderPass::Expand_LoadDeclaringClassSSB(llvm::Value* method_object_addr) {
1004 return irb_.LoadFromObjectOffset(method_object_addr,
Ian Rogers98573f92013-01-30 17:26:32 -08001005 art::mirror::AbstractMethod::DeclaringClassOffset().Int32Value(),
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001006 irb_.getJObjectTy(),
1007 kTBAAConstJObject);
1008}
1009
1010llvm::Value*
1011GBCExpanderPass::Expand_LoadClassSSBFromDexCache(llvm::Value* type_idx_value) {
1012 uint32_t type_idx =
1013 llvm::cast<llvm::ConstantInt>(type_idx_value)->getZExtValue();
1014
1015 llvm::Value* storage_field_addr =
1016 EmitLoadDexCacheStaticStorageFieldAddr(type_idx);
1017
TDYa127ce4cc0d2012-11-18 16:59:53 -08001018 return irb_.CreateLoad(storage_field_addr, kTBAARuntimeInfo);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001019}
1020
1021llvm::Value*
1022GBCExpanderPass::Expand_GetSDCalleeMethodObjAddrFast(llvm::Value* callee_method_idx_value) {
1023 uint32_t callee_method_idx =
1024 llvm::cast<llvm::ConstantInt>(callee_method_idx_value)->getZExtValue();
1025
1026 return EmitLoadSDCalleeMethodObjectAddr(callee_method_idx);
1027}
1028
1029llvm::Value* GBCExpanderPass::Expand_GetVirtualCalleeMethodObjAddrFast(
1030 llvm::Value* vtable_idx_value,
1031 llvm::Value* this_addr) {
1032 int vtable_idx =
1033 llvm::cast<llvm::ConstantInt>(vtable_idx_value)->getSExtValue();
1034
1035 return EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr);
1036}
1037
1038llvm::Value* GBCExpanderPass::Expand_Invoke(llvm::CallInst& call_inst) {
1039 // Most of the codes refer to MethodCompiler::EmitInsn_Invoke
1040 llvm::Value* callee_method_object_addr = call_inst.getArgOperand(0);
1041 unsigned num_args = call_inst.getNumArgOperands();
1042 llvm::Type* ret_type = call_inst.getType();
1043
1044 // Determine the function type of the callee method
1045 std::vector<llvm::Type*> args_type;
1046 std::vector<llvm::Value*> args;
1047 for (unsigned i = 0; i < num_args; i++) {
1048 args.push_back(call_inst.getArgOperand(i));
1049 args_type.push_back(args[i]->getType());
1050 }
1051
1052 llvm::FunctionType* callee_method_type =
1053 llvm::FunctionType::get(ret_type, args_type, false);
1054
1055 llvm::Value* code_addr =
1056 irb_.LoadFromObjectOffset(callee_method_object_addr,
Ian Rogers98573f92013-01-30 17:26:32 -08001057 art::mirror::AbstractMethod::GetCodeOffset().Int32Value(),
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001058 callee_method_type->getPointerTo(),
TDYa127ce4cc0d2012-11-18 16:59:53 -08001059 kTBAARuntimeInfo);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001060
1061 // Invoke callee
1062 llvm::Value* retval = irb_.CreateCall(code_addr, args);
1063
1064 return retval;
1065}
1066
TDYa1274ec8ccd2012-08-11 07:04:57 -07001067llvm::Value* GBCExpanderPass::Expand_DivRem(llvm::CallInst& call_inst,
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001068 bool is_div, JType op_jty) {
TDYa1274ec8ccd2012-08-11 07:04:57 -07001069 llvm::Value* dividend = call_inst.getArgOperand(0);
1070 llvm::Value* divisor = call_inst.getArgOperand(1);
TDYa1274ec8ccd2012-08-11 07:04:57 -07001071 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1072 EmitGuard_DivZeroException(dex_pc, divisor, op_jty);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001073 // Most of the codes refer to MethodCompiler::EmitIntDivRemResultComputation
1074
1075 // Check the special case: MININT / -1 = MININT
1076 // That case will cause overflow, which is undefined behavior in llvm.
1077 // So we check the divisor is -1 or not, if the divisor is -1, we do
1078 // the special path to avoid undefined behavior.
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001079 llvm::Type* op_type = irb_.getJType(op_jty);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001080 llvm::Value* zero = irb_.getJZero(op_jty);
1081 llvm::Value* neg_one = llvm::ConstantInt::getSigned(op_type, -1);
1082
TDYa1275e869b62012-07-25 00:45:39 -07001083 llvm::Function* parent = irb_.GetInsertBlock()->getParent();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001084 llvm::BasicBlock* eq_neg_one = llvm::BasicBlock::Create(context_, "", parent);
1085 llvm::BasicBlock* ne_neg_one = llvm::BasicBlock::Create(context_, "", parent);
1086 llvm::BasicBlock* neg_one_cont =
1087 llvm::BasicBlock::Create(context_, "", parent);
1088
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001089 llvm::Value* is_equal_neg_one = irb_.CreateICmpEQ(divisor, neg_one);
1090 irb_.CreateCondBr(is_equal_neg_one, eq_neg_one, ne_neg_one, kUnlikely);
1091
1092 // If divisor == -1
1093 irb_.SetInsertPoint(eq_neg_one);
1094 llvm::Value* eq_result;
1095 if (is_div) {
1096 // We can just change from "dividend div -1" to "neg dividend". The sub
1097 // don't care the sign/unsigned because of two's complement representation.
1098 // And the behavior is what we want:
1099 // -(2^n) (2^n)-1
1100 // MININT < k <= MAXINT -> mul k -1 = -k
1101 // MININT == k -> mul k -1 = k
1102 //
1103 // LLVM use sub to represent 'neg'
1104 eq_result = irb_.CreateSub(zero, dividend);
1105 } else {
1106 // Everything modulo -1 will be 0.
1107 eq_result = zero;
1108 }
1109 irb_.CreateBr(neg_one_cont);
1110
1111 // If divisor != -1, just do the division.
1112 irb_.SetInsertPoint(ne_neg_one);
1113 llvm::Value* ne_result;
1114 if (is_div) {
1115 ne_result = irb_.CreateSDiv(dividend, divisor);
1116 } else {
1117 ne_result = irb_.CreateSRem(dividend, divisor);
1118 }
1119 irb_.CreateBr(neg_one_cont);
1120
1121 irb_.SetInsertPoint(neg_one_cont);
1122 llvm::PHINode* result = irb_.CreatePHI(op_type, 2);
1123 result->addIncoming(eq_result, eq_neg_one);
1124 result->addIncoming(ne_result, ne_neg_one);
1125
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001126 return result;
1127}
1128
TDYa127ce4cc0d2012-11-18 16:59:53 -08001129void GBCExpanderPass::Expand_AllocaShadowFrame(llvm::Value* num_vregs_value) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001130 // Most of the codes refer to MethodCompiler::EmitPrologueAllocShadowFrame and
1131 // MethodCompiler::EmitPushShadowFrame
TDYa1278e950c12012-11-02 09:58:19 -07001132 uint16_t num_vregs =
1133 llvm::cast<llvm::ConstantInt>(num_vregs_value)->getZExtValue();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001134
1135 llvm::StructType* shadow_frame_type =
TDYa127ce4cc0d2012-11-18 16:59:53 -08001136 irb_.getShadowFrameTy(num_vregs);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001137
Sebastien Hertz77209702013-02-28 16:34:13 +01001138 // Create allocas at the start of entry block.
1139 llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
1140 llvm::BasicBlock* entry_block = &func_->front();
1141 irb_.SetInsertPoint(&entry_block->front());
1142
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001143 shadow_frame_ = irb_.CreateAlloca(shadow_frame_type);
1144
1145 // Alloca a pointer to old shadow frame
1146 old_shadow_frame_ =
1147 irb_.CreateAlloca(shadow_frame_type->getElementType(0)->getPointerTo());
1148
Sebastien Hertz77209702013-02-28 16:34:13 +01001149 irb_.restoreIP(irb_ip_original);
1150
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001151 // Push the shadow frame
1152 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1153
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001154 llvm::Value* shadow_frame_upcast =
1155 irb_.CreateConstGEP2_32(shadow_frame_, 0, 0);
1156
1157 llvm::Value* result = rtb_.EmitPushShadowFrame(shadow_frame_upcast,
1158 method_object_addr,
TDYa1278e950c12012-11-02 09:58:19 -07001159 num_vregs);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001160
1161 irb_.CreateStore(result, old_shadow_frame_, kTBAARegister);
1162
1163 return;
1164}
1165
TDYa1278e950c12012-11-02 09:58:19 -07001166void GBCExpanderPass::Expand_SetVReg(llvm::Value* entry_idx,
1167 llvm::Value* value) {
1168 DCHECK(shadow_frame_ != NULL);
1169
1170 llvm::Value* gep_index[] = {
1171 irb_.getInt32(0), // No pointer displacement
TDYa127ce4cc0d2012-11-18 16:59:53 -08001172 irb_.getInt32(1), // VRegs
TDYa1278e950c12012-11-02 09:58:19 -07001173 entry_idx // Pointer field
1174 };
1175
1176 llvm::Value* vreg_addr = irb_.CreateGEP(shadow_frame_, gep_index);
1177
1178 irb_.CreateStore(value,
1179 irb_.CreateBitCast(vreg_addr, value->getType()->getPointerTo()),
1180 kTBAAShadowFrame);
1181 return;
1182}
1183
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001184void GBCExpanderPass::Expand_PopShadowFrame() {
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07001185 if (old_shadow_frame_ == NULL) {
1186 return;
1187 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001188 rtb_.EmitPopShadowFrame(irb_.CreateLoad(old_shadow_frame_, kTBAARegister));
1189 return;
1190}
1191
1192void GBCExpanderPass::Expand_UpdateDexPC(llvm::Value* dex_pc_value) {
1193 irb_.StoreToObjectOffset(shadow_frame_,
TDYa127920be7c2012-09-10 17:13:22 -07001194 art::ShadowFrame::DexPCOffset(),
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001195 dex_pc_value,
1196 kTBAAShadowFrame);
1197 return;
1198}
1199
Logan Chien67645d82012-08-17 09:10:54 +08001200void GBCExpanderPass::InsertStackOverflowCheck(llvm::Function& func) {
jeffhao40283122013-01-15 13:15:24 -08001201 // All alloca instructions are generated in the first basic block of the
1202 // function, and there are no alloca instructions after the first non-alloca
1203 // instruction.
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001204
Logan Chien67645d82012-08-17 09:10:54 +08001205 llvm::BasicBlock* first_basic_block = &func.front();
1206
1207 // Look for first non-alloca instruction
1208 llvm::BasicBlock::iterator first_non_alloca = first_basic_block->begin();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001209 while (llvm::isa<llvm::AllocaInst>(first_non_alloca)) {
1210 ++first_non_alloca;
1211 }
1212
Logan Chien67645d82012-08-17 09:10:54 +08001213 irb_.SetInsertPoint(first_non_alloca);
1214
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001215 // Insert stack overflow check codes before first_non_alloca (i.e., after all
1216 // alloca instructions)
Logan Chien67645d82012-08-17 09:10:54 +08001217 EmitStackOverflowCheck(&*first_non_alloca);
1218
TDYa127890ea892012-08-22 10:49:42 -07001219 irb_.Runtime().EmitTestSuspend();
TDYa127890ea892012-08-22 10:49:42 -07001220
Logan Chien67645d82012-08-17 09:10:54 +08001221 llvm::BasicBlock* next_basic_block = irb_.GetInsertBlock();
1222 if (next_basic_block != first_basic_block) {
1223 // Splice the rest of the instruction to the continuing basic block
1224 next_basic_block->getInstList().splice(
1225 irb_.GetInsertPoint(), first_basic_block->getInstList(),
1226 first_non_alloca, first_basic_block->end());
1227
1228 // Rewrite the basic block
1229 RewriteBasicBlock(next_basic_block);
1230
1231 // Update the phi-instructions in the successor basic block
1232 UpdatePhiInstruction(first_basic_block, irb_.GetInsertBlock());
1233 }
1234
1235 // We have changed the basic block
1236 changed_ = true;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001237}
1238
TDYa1275e869b62012-07-25 00:45:39 -07001239// ==== High-level intrinsic expander ==========================================
1240
TDYa127a1b21852012-07-23 03:20:39 -07001241llvm::Value* GBCExpanderPass::Expand_FPCompare(llvm::Value* src1_value,
1242 llvm::Value* src2_value,
1243 bool gt_bias) {
1244 llvm::Value* cmp_eq = irb_.CreateFCmpOEQ(src1_value, src2_value);
1245 llvm::Value* cmp_lt;
1246
1247 if (gt_bias) {
1248 cmp_lt = irb_.CreateFCmpOLT(src1_value, src2_value);
1249 } else {
1250 cmp_lt = irb_.CreateFCmpULT(src1_value, src2_value);
1251 }
1252
1253 return EmitCompareResultSelection(cmp_eq, cmp_lt);
1254}
1255
1256llvm::Value* GBCExpanderPass::Expand_LongCompare(llvm::Value* src1_value, llvm::Value* src2_value) {
1257 llvm::Value* cmp_eq = irb_.CreateICmpEQ(src1_value, src2_value);
1258 llvm::Value* cmp_lt = irb_.CreateICmpSLT(src1_value, src2_value);
1259
1260 return EmitCompareResultSelection(cmp_eq, cmp_lt);
1261}
1262
1263llvm::Value* GBCExpanderPass::EmitCompareResultSelection(llvm::Value* cmp_eq,
1264 llvm::Value* cmp_lt) {
1265
1266 llvm::Constant* zero = irb_.getJInt(0);
1267 llvm::Constant* pos1 = irb_.getJInt(1);
1268 llvm::Constant* neg1 = irb_.getJInt(-1);
1269
1270 llvm::Value* result_lt = irb_.CreateSelect(cmp_lt, neg1, pos1);
1271 llvm::Value* result_eq = irb_.CreateSelect(cmp_eq, zero, result_lt);
1272
1273 return result_eq;
1274}
1275
Logan Chien75e4b602012-07-23 14:24:12 -07001276llvm::Value* GBCExpanderPass::Expand_IntegerShift(llvm::Value* src1_value,
1277 llvm::Value* src2_value,
1278 IntegerShiftKind kind,
1279 JType op_jty) {
1280 DCHECK(op_jty == kInt || op_jty == kLong);
1281
1282 // Mask and zero-extend RHS properly
1283 if (op_jty == kInt) {
1284 src2_value = irb_.CreateAnd(src2_value, 0x1f);
1285 } else {
1286 llvm::Value* masked_src2_value = irb_.CreateAnd(src2_value, 0x3f);
1287 src2_value = irb_.CreateZExt(masked_src2_value, irb_.getJLongTy());
1288 }
1289
1290 // Create integer shift llvm instruction
1291 switch (kind) {
1292 case kIntegerSHL:
1293 return irb_.CreateShl(src1_value, src2_value);
1294
1295 case kIntegerSHR:
1296 return irb_.CreateAShr(src1_value, src2_value);
1297
1298 case kIntegerUSHR:
1299 return irb_.CreateLShr(src1_value, src2_value);
1300
1301 default:
1302 LOG(FATAL) << "Unknown integer shift kind: " << kind;
1303 return NULL;
1304 }
1305}
1306
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001307llvm::Value* GBCExpanderPass::SignOrZeroExtendCat1Types(llvm::Value* value, JType jty) {
1308 switch (jty) {
1309 case kBoolean:
1310 case kChar:
1311 return irb_.CreateZExt(value, irb_.getJType(kInt));
1312 case kByte:
1313 case kShort:
1314 return irb_.CreateSExt(value, irb_.getJType(kInt));
1315 case kVoid:
1316 case kInt:
1317 case kLong:
1318 case kFloat:
1319 case kDouble:
1320 case kObject:
1321 return value; // Nothing to do.
1322 default:
1323 LOG(FATAL) << "Unknown java type: " << jty;
1324 return NULL;
1325 }
1326}
1327
1328llvm::Value* GBCExpanderPass::TruncateCat1Types(llvm::Value* value, JType jty) {
1329 switch (jty) {
1330 case kBoolean:
1331 case kChar:
1332 case kByte:
1333 case kShort:
1334 return irb_.CreateTrunc(value, irb_.getJType(jty));
1335 case kVoid:
1336 case kInt:
1337 case kLong:
1338 case kFloat:
1339 case kDouble:
1340 case kObject:
1341 return value; // Nothing to do.
1342 default:
1343 LOG(FATAL) << "Unknown java type: " << jty;
1344 return NULL;
1345 }
1346}
1347
TDYa1275a26d442012-07-26 18:58:38 -07001348llvm::Value* GBCExpanderPass::Expand_HLArrayGet(llvm::CallInst& call_inst,
1349 JType elem_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001350 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1351 llvm::Value* array_addr = call_inst.getArgOperand(1);
1352 llvm::Value* index_value = call_inst.getArgOperand(2);
TDYa127920be7c2012-09-10 17:13:22 -07001353 int opt_flags = LV2UInt(call_inst.getArgOperand(0));
TDYa1275a26d442012-07-26 18:58:38 -07001354
TDYa127920be7c2012-09-10 17:13:22 -07001355 if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) {
1356 EmitGuard_NullPointerException(dex_pc, array_addr);
1357 }
1358 if (!(opt_flags & MIR_IGNORE_RANGE_CHECK)) {
1359 EmitGuard_ArrayIndexOutOfBoundsException(dex_pc, array_addr, index_value);
1360 }
TDYa1275a26d442012-07-26 18:58:38 -07001361
1362 llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty);
1363
1364 llvm::Value* array_elem_value = irb_.CreateLoad(array_elem_addr, kTBAAHeapArray, elem_jty);
1365
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001366 return SignOrZeroExtendCat1Types(array_elem_value, elem_jty);
TDYa1275a26d442012-07-26 18:58:38 -07001367}
1368
1369
1370void GBCExpanderPass::Expand_HLArrayPut(llvm::CallInst& call_inst,
1371 JType elem_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001372 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1373 llvm::Value* new_value = call_inst.getArgOperand(1);
1374 llvm::Value* array_addr = call_inst.getArgOperand(2);
1375 llvm::Value* index_value = call_inst.getArgOperand(3);
TDYa127920be7c2012-09-10 17:13:22 -07001376 int opt_flags = LV2UInt(call_inst.getArgOperand(0));
TDYa1275a26d442012-07-26 18:58:38 -07001377
TDYa127920be7c2012-09-10 17:13:22 -07001378 if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) {
1379 EmitGuard_NullPointerException(dex_pc, array_addr);
1380 }
1381 if (!(opt_flags & MIR_IGNORE_RANGE_CHECK)) {
1382 EmitGuard_ArrayIndexOutOfBoundsException(dex_pc, array_addr, index_value);
1383 }
TDYa1275a26d442012-07-26 18:58:38 -07001384
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001385 new_value = TruncateCat1Types(new_value, elem_jty);
TDYa1275a26d442012-07-26 18:58:38 -07001386
1387 llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty);
1388
1389 if (elem_jty == kObject) { // If put an object, check the type, and mark GC card table.
1390 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::CheckPutArrayElement);
1391
1392 irb_.CreateCall2(runtime_func, new_value, array_addr);
1393
1394 EmitGuard_ExceptionLandingPad(dex_pc);
1395
1396 EmitMarkGCCard(new_value, array_addr);
1397 }
1398
1399 irb_.CreateStore(new_value, array_elem_addr, kTBAAHeapArray, elem_jty);
1400
1401 return;
1402}
1403
TDYa1275e869b62012-07-25 00:45:39 -07001404llvm::Value* GBCExpanderPass::Expand_HLIGet(llvm::CallInst& call_inst,
1405 JType field_jty) {
TDYa1275e869b62012-07-25 00:45:39 -07001406 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1407 llvm::Value* object_addr = call_inst.getArgOperand(1);
1408 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(2));
TDYa127920be7c2012-09-10 17:13:22 -07001409 int opt_flags = LV2UInt(call_inst.getArgOperand(0));
TDYa1275e869b62012-07-25 00:45:39 -07001410
TDYa127920be7c2012-09-10 17:13:22 -07001411 if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) {
1412 EmitGuard_NullPointerException(dex_pc, object_addr);
1413 }
TDYa1275e869b62012-07-25 00:45:39 -07001414
1415 llvm::Value* field_value;
1416
1417 int field_offset;
1418 bool is_volatile;
1419 bool is_fast_path = compiler_->ComputeInstanceFieldInfo(
1420 field_idx, oat_compilation_unit_, field_offset, is_volatile, false);
1421
1422 if (!is_fast_path) {
1423 llvm::Function* runtime_func;
1424
1425 if (field_jty == kObject) {
1426 runtime_func = irb_.GetRuntime(runtime_support::GetObjectInstance);
1427 } else if (field_jty == kLong || field_jty == kDouble) {
1428 runtime_func = irb_.GetRuntime(runtime_support::Get64Instance);
1429 } else {
1430 runtime_func = irb_.GetRuntime(runtime_support::Get32Instance);
1431 }
1432
1433 llvm::ConstantInt* field_idx_value = irb_.getInt32(field_idx);
1434
1435 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1436
1437 EmitUpdateDexPC(dex_pc);
1438
1439 field_value = irb_.CreateCall3(runtime_func, field_idx_value,
1440 method_object_addr, object_addr);
1441
1442 EmitGuard_ExceptionLandingPad(dex_pc);
1443
1444 } else {
1445 DCHECK_GE(field_offset, 0);
1446
1447 llvm::PointerType* field_type =
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001448 irb_.getJType(field_jty)->getPointerTo();
TDYa1275e869b62012-07-25 00:45:39 -07001449
1450 llvm::ConstantInt* field_offset_value = irb_.getPtrEquivInt(field_offset);
1451
1452 llvm::Value* field_addr =
1453 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
1454
1455 // TODO: Check is_volatile. We need to generate atomic load instruction
1456 // when is_volatile is true.
1457 field_value = irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty);
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001458 field_value = SignOrZeroExtendCat1Types(field_value, field_jty);
TDYa1275e869b62012-07-25 00:45:39 -07001459 }
1460
1461 if (field_jty == kFloat || field_jty == kDouble) {
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001462 field_value = irb_.CreateBitCast(field_value, irb_.getJType(field_jty));
TDYa1275e869b62012-07-25 00:45:39 -07001463 }
1464
1465 return field_value;
1466}
1467
1468void GBCExpanderPass::Expand_HLIPut(llvm::CallInst& call_inst,
1469 JType field_jty) {
TDYa1275e869b62012-07-25 00:45:39 -07001470 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07001471 llvm::Value* new_value = call_inst.getArgOperand(1);
1472 llvm::Value* object_addr = call_inst.getArgOperand(2);
TDYa1275e869b62012-07-25 00:45:39 -07001473 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(3));
TDYa127920be7c2012-09-10 17:13:22 -07001474 int opt_flags = LV2UInt(call_inst.getArgOperand(0));
TDYa1275e869b62012-07-25 00:45:39 -07001475
1476 if (field_jty == kFloat || field_jty == kDouble) {
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001477 new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty));
TDYa1275e869b62012-07-25 00:45:39 -07001478 }
1479
TDYa127920be7c2012-09-10 17:13:22 -07001480 if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) {
1481 EmitGuard_NullPointerException(dex_pc, object_addr);
1482 }
TDYa1275e869b62012-07-25 00:45:39 -07001483
1484 int field_offset;
1485 bool is_volatile;
1486 bool is_fast_path = compiler_->ComputeInstanceFieldInfo(
1487 field_idx, oat_compilation_unit_, field_offset, is_volatile, true);
1488
1489 if (!is_fast_path) {
1490 llvm::Function* runtime_func;
1491
1492 if (field_jty == kObject) {
1493 runtime_func = irb_.GetRuntime(runtime_support::SetObjectInstance);
1494 } else if (field_jty == kLong || field_jty == kDouble) {
1495 runtime_func = irb_.GetRuntime(runtime_support::Set64Instance);
1496 } else {
1497 runtime_func = irb_.GetRuntime(runtime_support::Set32Instance);
1498 }
1499
1500 llvm::Value* field_idx_value = irb_.getInt32(field_idx);
1501
1502 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1503
1504 EmitUpdateDexPC(dex_pc);
1505
1506 irb_.CreateCall4(runtime_func, field_idx_value,
1507 method_object_addr, object_addr, new_value);
1508
1509 EmitGuard_ExceptionLandingPad(dex_pc);
1510
1511 } else {
1512 DCHECK_GE(field_offset, 0);
1513
1514 llvm::PointerType* field_type =
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001515 irb_.getJType(field_jty)->getPointerTo();
TDYa1275e869b62012-07-25 00:45:39 -07001516
1517 llvm::Value* field_offset_value = irb_.getPtrEquivInt(field_offset);
1518
1519 llvm::Value* field_addr =
1520 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
1521
1522 // TODO: Check is_volatile. We need to generate atomic store instruction
1523 // when is_volatile is true.
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001524 new_value = TruncateCat1Types(new_value, field_jty);
TDYa1275e869b62012-07-25 00:45:39 -07001525 irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty);
1526
1527 if (field_jty == kObject) { // If put an object, mark the GC card table.
1528 EmitMarkGCCard(new_value, object_addr);
1529 }
1530 }
1531
1532 return;
1533}
1534
TDYa127f71bf5a2012-07-29 20:09:52 -07001535llvm::Value* GBCExpanderPass::EmitLoadConstantClass(uint32_t dex_pc,
1536 uint32_t type_idx) {
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07001537 if (!compiler_->CanAccessTypeWithoutChecks(method_idx_, *dex_file_, type_idx)) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001538 llvm::Value* type_idx_value = irb_.getInt32(type_idx);
1539
1540 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1541
1542 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1543
1544 llvm::Function* runtime_func =
1545 irb_.GetRuntime(runtime_support::InitializeTypeAndVerifyAccess);
1546
1547 EmitUpdateDexPC(dex_pc);
1548
1549 llvm::Value* type_object_addr =
1550 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1551
1552 EmitGuard_ExceptionLandingPad(dex_pc);
1553
1554 return type_object_addr;
1555
1556 } else {
1557 // Try to load the class (type) object from the test cache.
1558 llvm::Value* type_field_addr =
1559 EmitLoadDexCacheResolvedTypeFieldAddr(type_idx);
1560
TDYa127ce4cc0d2012-11-18 16:59:53 -08001561 llvm::Value* type_object_addr = irb_.CreateLoad(type_field_addr, kTBAARuntimeInfo);
TDYa127f71bf5a2012-07-29 20:09:52 -07001562
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07001563 if (compiler_->CanAssumeTypeIsPresentInDexCache(*dex_file_, type_idx)) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001564 return type_object_addr;
1565 }
1566
1567 llvm::BasicBlock* block_original = irb_.GetInsertBlock();
1568
1569 // Test whether class (type) object is in the dex cache or not
1570 llvm::Value* equal_null =
1571 irb_.CreateICmpEQ(type_object_addr, irb_.getJNull());
1572
1573 llvm::BasicBlock* block_cont =
1574 CreateBasicBlockWithDexPC(dex_pc, "cont");
1575
1576 llvm::BasicBlock* block_load_class =
1577 CreateBasicBlockWithDexPC(dex_pc, "load_class");
1578
1579 irb_.CreateCondBr(equal_null, block_load_class, block_cont, kUnlikely);
1580
1581 // Failback routine to load the class object
1582 irb_.SetInsertPoint(block_load_class);
1583
1584 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeType);
1585
1586 llvm::Constant* type_idx_value = irb_.getInt32(type_idx);
1587
1588 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1589
1590 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1591
1592 EmitUpdateDexPC(dex_pc);
1593
1594 llvm::Value* loaded_type_object_addr =
1595 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1596
1597 EmitGuard_ExceptionLandingPad(dex_pc);
1598
1599 llvm::BasicBlock* block_after_load_class = irb_.GetInsertBlock();
1600
1601 irb_.CreateBr(block_cont);
1602
1603 // Now the class object must be loaded
1604 irb_.SetInsertPoint(block_cont);
1605
1606 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1607
1608 phi->addIncoming(type_object_addr, block_original);
1609 phi->addIncoming(loaded_type_object_addr, block_after_load_class);
1610
1611 return phi;
1612 }
1613}
1614
TDYa1275a26d442012-07-26 18:58:38 -07001615llvm::Value* GBCExpanderPass::EmitLoadStaticStorage(uint32_t dex_pc,
1616 uint32_t type_idx) {
1617 llvm::BasicBlock* block_load_static =
1618 CreateBasicBlockWithDexPC(dex_pc, "load_static");
1619
1620 llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont");
1621
1622 // Load static storage from dex cache
1623 llvm::Value* storage_field_addr =
1624 EmitLoadDexCacheStaticStorageFieldAddr(type_idx);
1625
TDYa127ce4cc0d2012-11-18 16:59:53 -08001626 llvm::Value* storage_object_addr = irb_.CreateLoad(storage_field_addr, kTBAARuntimeInfo);
TDYa1275a26d442012-07-26 18:58:38 -07001627
1628 llvm::BasicBlock* block_original = irb_.GetInsertBlock();
1629
1630 // Test: Is the static storage of this class initialized?
1631 llvm::Value* equal_null =
1632 irb_.CreateICmpEQ(storage_object_addr, irb_.getJNull());
1633
1634 irb_.CreateCondBr(equal_null, block_load_static, block_cont, kUnlikely);
1635
1636 // Failback routine to load the class object
1637 irb_.SetInsertPoint(block_load_static);
1638
1639 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeStaticStorage);
1640
1641 llvm::Constant* type_idx_value = irb_.getInt32(type_idx);
1642
1643 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1644
1645 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1646
1647 EmitUpdateDexPC(dex_pc);
1648
1649 llvm::Value* loaded_storage_object_addr =
1650 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1651
1652 EmitGuard_ExceptionLandingPad(dex_pc);
1653
1654 llvm::BasicBlock* block_after_load_static = irb_.GetInsertBlock();
1655
1656 irb_.CreateBr(block_cont);
1657
1658 // Now the class object must be loaded
1659 irb_.SetInsertPoint(block_cont);
1660
1661 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1662
1663 phi->addIncoming(storage_object_addr, block_original);
1664 phi->addIncoming(loaded_storage_object_addr, block_after_load_static);
1665
1666 return phi;
1667}
1668
1669llvm::Value* GBCExpanderPass::Expand_HLSget(llvm::CallInst& call_inst,
1670 JType field_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001671 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1672 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0));
1673
1674 int field_offset;
1675 int ssb_index;
1676 bool is_referrers_class;
1677 bool is_volatile;
1678
1679 bool is_fast_path = compiler_->ComputeStaticFieldInfo(
1680 field_idx, oat_compilation_unit_, field_offset, ssb_index,
1681 is_referrers_class, is_volatile, false);
1682
1683 llvm::Value* static_field_value;
1684
1685 if (!is_fast_path) {
1686 llvm::Function* runtime_func;
1687
1688 if (field_jty == kObject) {
1689 runtime_func = irb_.GetRuntime(runtime_support::GetObjectStatic);
1690 } else if (field_jty == kLong || field_jty == kDouble) {
1691 runtime_func = irb_.GetRuntime(runtime_support::Get64Static);
1692 } else {
1693 runtime_func = irb_.GetRuntime(runtime_support::Get32Static);
1694 }
1695
1696 llvm::Constant* field_idx_value = irb_.getInt32(field_idx);
1697
1698 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1699
1700 EmitUpdateDexPC(dex_pc);
1701
1702 static_field_value =
1703 irb_.CreateCall2(runtime_func, field_idx_value, method_object_addr);
1704
1705 EmitGuard_ExceptionLandingPad(dex_pc);
1706
1707 } else {
1708 DCHECK_GE(field_offset, 0);
1709
1710 llvm::Value* static_storage_addr = NULL;
1711
1712 if (is_referrers_class) {
1713 // Fast path, static storage base is this method's class
1714 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1715
1716 static_storage_addr =
1717 irb_.LoadFromObjectOffset(method_object_addr,
Ian Rogers98573f92013-01-30 17:26:32 -08001718 art::mirror::AbstractMethod::DeclaringClassOffset().Int32Value(),
TDYa1275a26d442012-07-26 18:58:38 -07001719 irb_.getJObjectTy(),
1720 kTBAAConstJObject);
1721 } else {
1722 // Medium path, static storage base in a different class which
1723 // requires checks that the other class is initialized
1724 DCHECK_GE(ssb_index, 0);
1725 static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index);
1726 }
1727
1728 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
1729
1730 llvm::Value* static_field_addr =
1731 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001732 irb_.getJType(field_jty)->getPointerTo());
TDYa1275a26d442012-07-26 18:58:38 -07001733
1734 // TODO: Check is_volatile. We need to generate atomic load instruction
1735 // when is_volatile is true.
1736 static_field_value = irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty);
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001737 static_field_value = SignOrZeroExtendCat1Types(static_field_value, field_jty);
TDYa1275a26d442012-07-26 18:58:38 -07001738 }
1739
1740 if (field_jty == kFloat || field_jty == kDouble) {
1741 static_field_value =
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001742 irb_.CreateBitCast(static_field_value, irb_.getJType(field_jty));
TDYa1275a26d442012-07-26 18:58:38 -07001743 }
1744
1745 return static_field_value;
1746}
1747
1748void GBCExpanderPass::Expand_HLSput(llvm::CallInst& call_inst,
1749 JType field_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001750 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1751 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0));
1752 llvm::Value* new_value = call_inst.getArgOperand(1);
1753
1754 if (field_jty == kFloat || field_jty == kDouble) {
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001755 new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty));
TDYa1275a26d442012-07-26 18:58:38 -07001756 }
1757
1758 int field_offset;
1759 int ssb_index;
1760 bool is_referrers_class;
1761 bool is_volatile;
1762
1763 bool is_fast_path = compiler_->ComputeStaticFieldInfo(
1764 field_idx, oat_compilation_unit_, field_offset, ssb_index,
1765 is_referrers_class, is_volatile, true);
1766
1767 if (!is_fast_path) {
1768 llvm::Function* runtime_func;
1769
1770 if (field_jty == kObject) {
1771 runtime_func = irb_.GetRuntime(runtime_support::SetObjectStatic);
1772 } else if (field_jty == kLong || field_jty == kDouble) {
1773 runtime_func = irb_.GetRuntime(runtime_support::Set64Static);
1774 } else {
1775 runtime_func = irb_.GetRuntime(runtime_support::Set32Static);
1776 }
1777
1778 llvm::Constant* field_idx_value = irb_.getInt32(field_idx);
1779
1780 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1781
1782 EmitUpdateDexPC(dex_pc);
1783
1784 irb_.CreateCall3(runtime_func, field_idx_value,
1785 method_object_addr, new_value);
1786
1787 EmitGuard_ExceptionLandingPad(dex_pc);
1788
1789 } else {
1790 DCHECK_GE(field_offset, 0);
1791
1792 llvm::Value* static_storage_addr = NULL;
1793
1794 if (is_referrers_class) {
1795 // Fast path, static storage base is this method's class
1796 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1797
1798 static_storage_addr =
1799 irb_.LoadFromObjectOffset(method_object_addr,
Ian Rogers98573f92013-01-30 17:26:32 -08001800 art::mirror::AbstractMethod::DeclaringClassOffset().Int32Value(),
TDYa1275a26d442012-07-26 18:58:38 -07001801 irb_.getJObjectTy(),
1802 kTBAAConstJObject);
1803 } else {
1804 // Medium path, static storage base in a different class which
1805 // requires checks that the other class is initialized
1806 DCHECK_GE(ssb_index, 0);
1807 static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index);
1808 }
1809
1810 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
1811
1812 llvm::Value* static_field_addr =
1813 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001814 irb_.getJType(field_jty)->getPointerTo());
TDYa1275a26d442012-07-26 18:58:38 -07001815
1816 // TODO: Check is_volatile. We need to generate atomic store instruction
1817 // when is_volatile is true.
Ian Rogers76ae4fe2013-02-27 16:03:41 -08001818 new_value = TruncateCat1Types(new_value, field_jty);
TDYa1275a26d442012-07-26 18:58:38 -07001819 irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty);
1820
1821 if (field_jty == kObject) { // If put an object, mark the GC card table.
1822 EmitMarkGCCard(new_value, static_storage_addr);
1823 }
1824 }
1825
1826 return;
1827}
1828
TDYa127f71bf5a2012-07-29 20:09:52 -07001829llvm::Value* GBCExpanderPass::Expand_ConstString(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001830 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1831 uint32_t string_idx = LV2UInt(call_inst.getArgOperand(0));
1832
1833 llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx);
1834
TDYa127ce4cc0d2012-11-18 16:59:53 -08001835 llvm::Value* string_addr = irb_.CreateLoad(string_field_addr, kTBAARuntimeInfo);
TDYa127f71bf5a2012-07-29 20:09:52 -07001836
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07001837 if (!compiler_->CanAssumeStringIsPresentInDexCache(*dex_file_, string_idx)) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001838 llvm::BasicBlock* block_str_exist =
1839 CreateBasicBlockWithDexPC(dex_pc, "str_exist");
1840
1841 llvm::BasicBlock* block_str_resolve =
1842 CreateBasicBlockWithDexPC(dex_pc, "str_resolve");
1843
1844 llvm::BasicBlock* block_cont =
1845 CreateBasicBlockWithDexPC(dex_pc, "str_cont");
1846
1847 // Test: Is the string resolved and in the dex cache?
1848 llvm::Value* equal_null = irb_.CreateICmpEQ(string_addr, irb_.getJNull());
1849
1850 irb_.CreateCondBr(equal_null, block_str_resolve, block_str_exist, kUnlikely);
1851
1852 // String is resolved, go to next basic block.
1853 irb_.SetInsertPoint(block_str_exist);
1854 irb_.CreateBr(block_cont);
1855
1856 // String is not resolved yet, resolve it now.
1857 irb_.SetInsertPoint(block_str_resolve);
1858
1859 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::ResolveString);
1860
1861 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1862
1863 llvm::Value* string_idx_value = irb_.getInt32(string_idx);
1864
1865 EmitUpdateDexPC(dex_pc);
1866
1867 llvm::Value* result = irb_.CreateCall2(runtime_func, method_object_addr,
1868 string_idx_value);
1869
1870 EmitGuard_ExceptionLandingPad(dex_pc);
1871
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07001872 irb_.CreateBr(block_cont);
1873
1874
TDYa127f71bf5a2012-07-29 20:09:52 -07001875 llvm::BasicBlock* block_pre_cont = irb_.GetInsertBlock();
1876
1877 irb_.SetInsertPoint(block_cont);
1878
1879 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1880
1881 phi->addIncoming(string_addr, block_str_exist);
1882 phi->addIncoming(result, block_pre_cont);
1883
1884 string_addr = phi;
1885 }
1886
1887 return string_addr;
1888}
1889
1890llvm::Value* GBCExpanderPass::Expand_ConstClass(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001891 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1892 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1893
1894 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
1895
1896 return type_object_addr;
1897}
1898
1899void GBCExpanderPass::Expand_MonitorEnter(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001900 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1901 llvm::Value* object_addr = call_inst.getArgOperand(1);
TDYa127920be7c2012-09-10 17:13:22 -07001902 int opt_flags = LV2UInt(call_inst.getArgOperand(0));
TDYa127f71bf5a2012-07-29 20:09:52 -07001903
TDYa127920be7c2012-09-10 17:13:22 -07001904 if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) {
1905 EmitGuard_NullPointerException(dex_pc, object_addr);
1906 }
TDYa127f71bf5a2012-07-29 20:09:52 -07001907
TDYa127ce4cc0d2012-11-18 16:59:53 -08001908 EmitUpdateDexPC(dex_pc);
1909
TDYa127f71bf5a2012-07-29 20:09:52 -07001910 irb_.Runtime().EmitLockObject(object_addr);
1911
1912 return;
1913}
1914
1915void GBCExpanderPass::Expand_MonitorExit(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001916 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1917 llvm::Value* object_addr = call_inst.getArgOperand(1);
TDYa127920be7c2012-09-10 17:13:22 -07001918 int opt_flags = LV2UInt(call_inst.getArgOperand(0));
TDYa127f71bf5a2012-07-29 20:09:52 -07001919
TDYa127920be7c2012-09-10 17:13:22 -07001920 if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) {
1921 EmitGuard_NullPointerException(dex_pc, object_addr);
1922 }
TDYa127f71bf5a2012-07-29 20:09:52 -07001923
1924 EmitUpdateDexPC(dex_pc);
1925
1926 irb_.Runtime().EmitUnlockObject(object_addr);
1927
1928 EmitGuard_ExceptionLandingPad(dex_pc);
1929
1930 return;
1931}
1932
1933void GBCExpanderPass::Expand_HLCheckCast(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001934 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1935 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1936 llvm::Value* object_addr = call_inst.getArgOperand(1);
1937
1938 llvm::BasicBlock* block_test_class =
1939 CreateBasicBlockWithDexPC(dex_pc, "test_class");
1940
1941 llvm::BasicBlock* block_test_sub_class =
1942 CreateBasicBlockWithDexPC(dex_pc, "test_sub_class");
1943
1944 llvm::BasicBlock* block_cont =
1945 CreateBasicBlockWithDexPC(dex_pc, "checkcast_cont");
1946
1947 // Test: Is the reference equal to null? Act as no-op when it is null.
1948 llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull());
1949
1950 irb_.CreateCondBr(equal_null,
1951 block_cont,
1952 block_test_class);
1953
1954 // Test: Is the object instantiated from the given class?
1955 irb_.SetInsertPoint(block_test_class);
1956 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
Ian Rogers98573f92013-01-30 17:26:32 -08001957 DCHECK_EQ(art::mirror::Object::ClassOffset().Int32Value(), 0);
TDYa127f71bf5a2012-07-29 20:09:52 -07001958
1959 llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy();
1960
1961 llvm::Value* object_type_field_addr =
1962 irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo());
1963
1964 llvm::Value* object_type_object_addr =
1965 irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject);
1966
1967 llvm::Value* equal_class =
1968 irb_.CreateICmpEQ(type_object_addr, object_type_object_addr);
1969
1970 irb_.CreateCondBr(equal_class,
1971 block_cont,
1972 block_test_sub_class);
1973
1974 // Test: Is the object instantiated from the subclass of the given class?
1975 irb_.SetInsertPoint(block_test_sub_class);
1976
1977 EmitUpdateDexPC(dex_pc);
1978
1979 irb_.CreateCall2(irb_.GetRuntime(runtime_support::CheckCast),
1980 type_object_addr, object_type_object_addr);
1981
1982 EmitGuard_ExceptionLandingPad(dex_pc);
1983
1984 irb_.CreateBr(block_cont);
1985
1986 irb_.SetInsertPoint(block_cont);
1987
1988 return;
1989}
1990
1991llvm::Value* GBCExpanderPass::Expand_InstanceOf(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001992 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1993 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1994 llvm::Value* object_addr = call_inst.getArgOperand(1);
1995
1996 llvm::BasicBlock* block_nullp =
1997 CreateBasicBlockWithDexPC(dex_pc, "nullp");
1998
1999 llvm::BasicBlock* block_test_class =
2000 CreateBasicBlockWithDexPC(dex_pc, "test_class");
2001
2002 llvm::BasicBlock* block_class_equals =
2003 CreateBasicBlockWithDexPC(dex_pc, "class_eq");
2004
2005 llvm::BasicBlock* block_test_sub_class =
2006 CreateBasicBlockWithDexPC(dex_pc, "test_sub_class");
2007
2008 llvm::BasicBlock* block_cont =
2009 CreateBasicBlockWithDexPC(dex_pc, "instance_of_cont");
2010
2011 // Overview of the following code :
2012 // We check for null, if so, then false, otherwise check for class == . If so
2013 // then true, otherwise do callout slowpath.
2014 //
2015 // Test: Is the reference equal to null? Set 0 when it is null.
2016 llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull());
2017
2018 irb_.CreateCondBr(equal_null, block_nullp, block_test_class);
2019
2020 irb_.SetInsertPoint(block_nullp);
2021 irb_.CreateBr(block_cont);
2022
2023 // Test: Is the object instantiated from the given class?
2024 irb_.SetInsertPoint(block_test_class);
2025 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
Ian Rogers98573f92013-01-30 17:26:32 -08002026 DCHECK_EQ(art::mirror::Object::ClassOffset().Int32Value(), 0);
TDYa127f71bf5a2012-07-29 20:09:52 -07002027
2028 llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy();
2029
2030 llvm::Value* object_type_field_addr =
2031 irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo());
2032
2033 llvm::Value* object_type_object_addr =
2034 irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject);
2035
2036 llvm::Value* equal_class =
2037 irb_.CreateICmpEQ(type_object_addr, object_type_object_addr);
2038
2039 irb_.CreateCondBr(equal_class, block_class_equals, block_test_sub_class);
2040
2041 irb_.SetInsertPoint(block_class_equals);
2042 irb_.CreateBr(block_cont);
2043
2044 // Test: Is the object instantiated from the subclass of the given class?
2045 irb_.SetInsertPoint(block_test_sub_class);
2046 llvm::Value* result =
2047 irb_.CreateCall2(irb_.GetRuntime(runtime_support::IsAssignable),
2048 type_object_addr, object_type_object_addr);
2049 irb_.CreateBr(block_cont);
2050
2051 irb_.SetInsertPoint(block_cont);
2052
2053 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJIntTy(), 3);
2054
2055 phi->addIncoming(irb_.getJInt(0), block_nullp);
2056 phi->addIncoming(irb_.getJInt(1), block_class_equals);
2057 phi->addIncoming(result, block_test_sub_class);
2058
2059 return phi;
2060}
2061
2062llvm::Value* GBCExpanderPass::Expand_NewInstance(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002063 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2064 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
2065
2066 llvm::Function* runtime_func;
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07002067 if (compiler_->CanAccessInstantiableTypeWithoutChecks(method_idx_, *dex_file_, type_idx)) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002068 runtime_func = irb_.GetRuntime(runtime_support::AllocObject);
2069 } else {
2070 runtime_func = irb_.GetRuntime(runtime_support::AllocObjectWithAccessCheck);
2071 }
2072
2073 llvm::Constant* type_index_value = irb_.getInt32(type_idx);
2074
2075 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2076
2077 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2078
2079 EmitUpdateDexPC(dex_pc);
2080
2081 llvm::Value* object_addr =
2082 irb_.CreateCall3(runtime_func, type_index_value, method_object_addr, thread_object_addr);
2083
2084 EmitGuard_ExceptionLandingPad(dex_pc);
2085
2086 return object_addr;
2087}
2088
2089llvm::Value* GBCExpanderPass::Expand_HLInvoke(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002090 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
TDYa127920be7c2012-09-10 17:13:22 -07002091 art::InvokeType invoke_type = static_cast<art::InvokeType>(LV2UInt(call_inst.getArgOperand(0)));
2092 bool is_static = (invoke_type == art::kStatic);
TDYa127f71bf5a2012-07-29 20:09:52 -07002093 uint32_t callee_method_idx = LV2UInt(call_inst.getArgOperand(1));
TDYa127920be7c2012-09-10 17:13:22 -07002094 int opt_flags = LV2UInt(call_inst.getArgOperand(2));
TDYa127f71bf5a2012-07-29 20:09:52 -07002095
2096 // Compute invoke related information for compiler decision
2097 int vtable_idx = -1;
2098 uintptr_t direct_code = 0;
2099 uintptr_t direct_method = 0;
2100 bool is_fast_path = compiler_->
2101 ComputeInvokeInfo(callee_method_idx, oat_compilation_unit_,
2102 invoke_type, vtable_idx, direct_code, direct_method);
2103
2104 // Load *this* actual parameter
2105 llvm::Value* this_addr = NULL;
2106
2107 if (!is_static) {
2108 // Test: Is *this* parameter equal to null?
2109 this_addr = call_inst.getArgOperand(3);
2110 }
2111
2112 // Load the method object
2113 llvm::Value* callee_method_object_addr = NULL;
2114
2115 if (!is_fast_path) {
2116 callee_method_object_addr =
2117 EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, invoke_type,
2118 this_addr, dex_pc, is_fast_path);
2119
TDYa127920be7c2012-09-10 17:13:22 -07002120 if (!is_static && !(opt_flags & MIR_IGNORE_NULL_CHECK)) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002121 EmitGuard_NullPointerException(dex_pc, this_addr);
2122 }
2123 } else {
TDYa127920be7c2012-09-10 17:13:22 -07002124 if (!is_static && !(opt_flags & MIR_IGNORE_NULL_CHECK)) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002125 EmitGuard_NullPointerException(dex_pc, this_addr);
2126 }
2127
2128 switch (invoke_type) {
TDYa127920be7c2012-09-10 17:13:22 -07002129 case art::kStatic:
2130 case art::kDirect:
TDYa127f71bf5a2012-07-29 20:09:52 -07002131 if (direct_method != 0u &&
2132 direct_method != static_cast<uintptr_t>(-1)) {
2133 callee_method_object_addr =
2134 irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_method),
2135 irb_.getJObjectTy());
2136 } else {
2137 callee_method_object_addr =
2138 EmitLoadSDCalleeMethodObjectAddr(callee_method_idx);
2139 }
2140 break;
2141
TDYa127920be7c2012-09-10 17:13:22 -07002142 case art::kVirtual:
TDYa127f71bf5a2012-07-29 20:09:52 -07002143 DCHECK(vtable_idx != -1);
2144 callee_method_object_addr =
2145 EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr);
2146 break;
2147
TDYa127920be7c2012-09-10 17:13:22 -07002148 case art::kSuper:
TDYa127f71bf5a2012-07-29 20:09:52 -07002149 LOG(FATAL) << "invoke-super should be promoted to invoke-direct in "
2150 "the fast path.";
2151 break;
2152
TDYa127920be7c2012-09-10 17:13:22 -07002153 case art::kInterface:
TDYa127f71bf5a2012-07-29 20:09:52 -07002154 callee_method_object_addr =
2155 EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx,
2156 invoke_type, this_addr,
2157 dex_pc, is_fast_path);
2158 break;
2159 }
2160 }
2161
2162 // Load the actual parameter
2163 std::vector<llvm::Value*> args;
2164
2165 args.push_back(callee_method_object_addr); // method object for callee
2166
2167 for (uint32_t i = 3; i < call_inst.getNumArgOperands(); ++i) {
2168 args.push_back(call_inst.getArgOperand(i));
2169 }
2170
2171 llvm::Value* code_addr;
2172 if (direct_code != 0u &&
2173 direct_code != static_cast<uintptr_t>(-1)) {
2174 code_addr =
2175 irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_code),
2176 GetFunctionType(callee_method_idx, is_static)->getPointerTo());
2177 } else {
2178 code_addr =
2179 irb_.LoadFromObjectOffset(callee_method_object_addr,
Ian Rogers98573f92013-01-30 17:26:32 -08002180 art::mirror::AbstractMethod::GetCodeOffset().Int32Value(),
TDYa127f71bf5a2012-07-29 20:09:52 -07002181 GetFunctionType(callee_method_idx, is_static)->getPointerTo(),
TDYa127ce4cc0d2012-11-18 16:59:53 -08002182 kTBAARuntimeInfo);
TDYa127f71bf5a2012-07-29 20:09:52 -07002183 }
2184
2185 // Invoke callee
2186 EmitUpdateDexPC(dex_pc);
2187 llvm::Value* retval = irb_.CreateCall(code_addr, args);
2188 EmitGuard_ExceptionLandingPad(dex_pc);
2189
2190 return retval;
2191}
2192
2193llvm::Value* GBCExpanderPass::Expand_OptArrayLength(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002194 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2195 // Get the array object address
2196 llvm::Value* array_addr = call_inst.getArgOperand(1);
TDYa127920be7c2012-09-10 17:13:22 -07002197 int opt_flags = LV2UInt(call_inst.getArgOperand(0));
TDYa127f71bf5a2012-07-29 20:09:52 -07002198
TDYa127920be7c2012-09-10 17:13:22 -07002199 if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) {
2200 EmitGuard_NullPointerException(dex_pc, array_addr);
2201 }
TDYa127f71bf5a2012-07-29 20:09:52 -07002202
2203 // Get the array length and store it to the register
2204 return EmitLoadArrayLength(array_addr);
2205}
2206
2207llvm::Value* GBCExpanderPass::Expand_NewArray(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002208 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2209 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
2210 llvm::Value* length = call_inst.getArgOperand(1);
2211
2212 return EmitAllocNewArray(dex_pc, length, type_idx, false);
2213}
2214
2215llvm::Value* GBCExpanderPass::Expand_HLFilledNewArray(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002216 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2217 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(1));
2218 uint32_t length = call_inst.getNumArgOperands() - 3;
2219
2220 llvm::Value* object_addr =
2221 EmitAllocNewArray(dex_pc, irb_.getInt32(length), type_idx, true);
2222
2223 if (length > 0) {
2224 // Check for the element type
2225 uint32_t type_desc_len = 0;
2226 const char* type_desc =
2227 dex_file_->StringByTypeIdx(type_idx, &type_desc_len);
2228
2229 DCHECK_GE(type_desc_len, 2u); // should be guaranteed by verifier
2230 DCHECK_EQ(type_desc[0], '['); // should be guaranteed by verifier
2231 bool is_elem_int_ty = (type_desc[1] == 'I');
2232
2233 uint32_t alignment;
2234 llvm::Constant* elem_size;
2235 llvm::PointerType* field_type;
2236
2237 // NOTE: Currently filled-new-array only supports 'L', '[', and 'I'
2238 // as the element, thus we are only checking 2 cases: primitive int and
2239 // non-primitive type.
2240 if (is_elem_int_ty) {
2241 alignment = sizeof(int32_t);
2242 elem_size = irb_.getPtrEquivInt(sizeof(int32_t));
2243 field_type = irb_.getJIntTy()->getPointerTo();
2244 } else {
2245 alignment = irb_.getSizeOfPtrEquivInt();
2246 elem_size = irb_.getSizeOfPtrEquivIntValue();
2247 field_type = irb_.getJObjectTy()->getPointerTo();
2248 }
2249
2250 llvm::Value* data_field_offset =
Ian Rogers98573f92013-01-30 17:26:32 -08002251 irb_.getPtrEquivInt(art::mirror::Array::DataOffset(alignment).Int32Value());
TDYa127f71bf5a2012-07-29 20:09:52 -07002252
2253 llvm::Value* data_field_addr =
2254 irb_.CreatePtrDisp(object_addr, data_field_offset, field_type);
2255
2256 // TODO: Tune this code. Currently we are generating one instruction for
2257 // one element which may be very space consuming. Maybe changing to use
2258 // memcpy may help; however, since we can't guarantee that the alloca of
2259 // dalvik register are continuous, we can't perform such optimization yet.
2260 for (uint32_t i = 0; i < length; ++i) {
2261 llvm::Value* reg_value = call_inst.getArgOperand(i+3);
2262
2263 irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray);
2264
2265 data_field_addr =
2266 irb_.CreatePtrDisp(data_field_addr, elem_size, field_type);
2267 }
2268 }
2269
2270 return object_addr;
2271}
2272
2273void GBCExpanderPass::Expand_HLFillArrayData(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002274 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2275 int32_t payload_offset = static_cast<int32_t>(dex_pc) +
2276 LV2SInt(call_inst.getArgOperand(0));
2277 llvm::Value* array_addr = call_inst.getArgOperand(1);
2278
TDYa127920be7c2012-09-10 17:13:22 -07002279 const art::Instruction::ArrayDataPayload* payload =
2280 reinterpret_cast<const art::Instruction::ArrayDataPayload*>(
TDYa127f71bf5a2012-07-29 20:09:52 -07002281 code_item_->insns_ + payload_offset);
2282
2283 if (payload->element_count == 0) {
2284 // When the number of the elements in the payload is zero, we don't have
2285 // to copy any numbers. However, we should check whether the array object
2286 // address is equal to null or not.
2287 EmitGuard_NullPointerException(dex_pc, array_addr);
2288 } else {
2289 // To save the code size, we are going to call the runtime function to
2290 // copy the content from DexFile.
2291
2292 // NOTE: We will check for the NullPointerException in the runtime.
2293
2294 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::FillArrayData);
2295
2296 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2297
2298 EmitUpdateDexPC(dex_pc);
2299
2300 irb_.CreateCall4(runtime_func,
2301 method_object_addr, irb_.getInt32(dex_pc),
2302 array_addr, irb_.getInt32(payload_offset));
2303
2304 EmitGuard_ExceptionLandingPad(dex_pc);
2305 }
2306
2307 return;
2308}
2309
2310llvm::Value* GBCExpanderPass::EmitAllocNewArray(uint32_t dex_pc,
2311 llvm::Value* array_length_value,
2312 uint32_t type_idx,
2313 bool is_filled_new_array) {
2314 llvm::Function* runtime_func;
2315
2316 bool skip_access_check =
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07002317 compiler_->CanAccessTypeWithoutChecks(method_idx_, *dex_file_, type_idx);
TDYa127f71bf5a2012-07-29 20:09:52 -07002318
2319
2320 if (is_filled_new_array) {
2321 runtime_func = skip_access_check ?
2322 irb_.GetRuntime(runtime_support::CheckAndAllocArray) :
2323 irb_.GetRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck);
2324 } else {
2325 runtime_func = skip_access_check ?
2326 irb_.GetRuntime(runtime_support::AllocArray) :
2327 irb_.GetRuntime(runtime_support::AllocArrayWithAccessCheck);
2328 }
2329
2330 llvm::Constant* type_index_value = irb_.getInt32(type_idx);
2331
2332 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2333
2334 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2335
2336 EmitUpdateDexPC(dex_pc);
2337
2338 llvm::Value* object_addr =
2339 irb_.CreateCall4(runtime_func, type_index_value, method_object_addr,
2340 array_length_value, thread_object_addr);
2341
2342 EmitGuard_ExceptionLandingPad(dex_pc);
2343
2344 return object_addr;
2345}
2346
2347llvm::Value* GBCExpanderPass::
2348EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx,
TDYa127920be7c2012-09-10 17:13:22 -07002349 art::InvokeType invoke_type,
TDYa127f71bf5a2012-07-29 20:09:52 -07002350 llvm::Value* this_addr,
2351 uint32_t dex_pc,
2352 bool is_fast_path) {
2353
2354 llvm::Function* runtime_func = NULL;
2355
2356 switch (invoke_type) {
TDYa127920be7c2012-09-10 17:13:22 -07002357 case art::kStatic:
TDYa127f71bf5a2012-07-29 20:09:52 -07002358 runtime_func = irb_.GetRuntime(runtime_support::FindStaticMethodWithAccessCheck);
2359 break;
2360
TDYa127920be7c2012-09-10 17:13:22 -07002361 case art::kDirect:
TDYa127f71bf5a2012-07-29 20:09:52 -07002362 runtime_func = irb_.GetRuntime(runtime_support::FindDirectMethodWithAccessCheck);
2363 break;
2364
TDYa127920be7c2012-09-10 17:13:22 -07002365 case art::kVirtual:
TDYa127f71bf5a2012-07-29 20:09:52 -07002366 runtime_func = irb_.GetRuntime(runtime_support::FindVirtualMethodWithAccessCheck);
2367 break;
2368
TDYa127920be7c2012-09-10 17:13:22 -07002369 case art::kSuper:
TDYa127f71bf5a2012-07-29 20:09:52 -07002370 runtime_func = irb_.GetRuntime(runtime_support::FindSuperMethodWithAccessCheck);
2371 break;
2372
TDYa127920be7c2012-09-10 17:13:22 -07002373 case art::kInterface:
TDYa127f71bf5a2012-07-29 20:09:52 -07002374 if (is_fast_path) {
2375 runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethod);
2376 } else {
2377 runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethodWithAccessCheck);
2378 }
2379 break;
2380 }
2381
2382 llvm::Value* callee_method_idx_value = irb_.getInt32(callee_method_idx);
2383
2384 if (this_addr == NULL) {
TDYa127920be7c2012-09-10 17:13:22 -07002385 DCHECK_EQ(invoke_type, art::kStatic);
TDYa127f71bf5a2012-07-29 20:09:52 -07002386 this_addr = irb_.getJNull();
2387 }
2388
2389 llvm::Value* caller_method_object_addr = EmitLoadMethodObjectAddr();
2390
2391 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2392
2393 EmitUpdateDexPC(dex_pc);
2394
2395 llvm::Value* callee_method_object_addr =
2396 irb_.CreateCall4(runtime_func,
2397 callee_method_idx_value,
2398 this_addr,
2399 caller_method_object_addr,
2400 thread_object_addr);
2401
2402 EmitGuard_ExceptionLandingPad(dex_pc);
2403
2404 return callee_method_object_addr;
2405}
2406
TDYa1275e869b62012-07-25 00:45:39 -07002407void GBCExpanderPass::EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr) {
2408 // Using runtime support, let the target can override by InlineAssembly.
2409 irb_.Runtime().EmitMarkGCCard(value, target_addr);
2410}
2411
2412void GBCExpanderPass::EmitUpdateDexPC(uint32_t dex_pc) {
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07002413 if (shadow_frame_ == NULL) {
2414 return;
2415 }
TDYa1275e869b62012-07-25 00:45:39 -07002416 irb_.StoreToObjectOffset(shadow_frame_,
TDYa127920be7c2012-09-10 17:13:22 -07002417 art::ShadowFrame::DexPCOffset(),
TDYa1275e869b62012-07-25 00:45:39 -07002418 irb_.getInt32(dex_pc),
2419 kTBAAShadowFrame);
2420}
2421
2422void GBCExpanderPass::EmitGuard_DivZeroException(uint32_t dex_pc,
2423 llvm::Value* denominator,
2424 JType op_jty) {
2425 DCHECK(op_jty == kInt || op_jty == kLong) << op_jty;
2426
2427 llvm::Constant* zero = irb_.getJZero(op_jty);
2428
2429 llvm::Value* equal_zero = irb_.CreateICmpEQ(denominator, zero);
2430
2431 llvm::BasicBlock* block_exception = CreateBasicBlockWithDexPC(dex_pc, "div0");
2432
2433 llvm::BasicBlock* block_continue = CreateBasicBlockWithDexPC(dex_pc, "cont");
2434
2435 irb_.CreateCondBr(equal_zero, block_exception, block_continue, kUnlikely);
2436
2437 irb_.SetInsertPoint(block_exception);
2438 EmitUpdateDexPC(dex_pc);
2439 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowDivZeroException));
2440 EmitBranchExceptionLandingPad(dex_pc);
2441
2442 irb_.SetInsertPoint(block_continue);
2443}
2444
2445void GBCExpanderPass::EmitGuard_NullPointerException(uint32_t dex_pc,
2446 llvm::Value* object) {
2447 llvm::Value* equal_null = irb_.CreateICmpEQ(object, irb_.getJNull());
2448
2449 llvm::BasicBlock* block_exception =
2450 CreateBasicBlockWithDexPC(dex_pc, "nullp");
2451
2452 llvm::BasicBlock* block_continue =
2453 CreateBasicBlockWithDexPC(dex_pc, "cont");
2454
2455 irb_.CreateCondBr(equal_null, block_exception, block_continue, kUnlikely);
2456
2457 irb_.SetInsertPoint(block_exception);
2458 EmitUpdateDexPC(dex_pc);
2459 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowNullPointerException),
2460 irb_.getInt32(dex_pc));
2461 EmitBranchExceptionLandingPad(dex_pc);
2462
2463 irb_.SetInsertPoint(block_continue);
2464}
2465
2466void
2467GBCExpanderPass::EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc,
2468 llvm::Value* array,
2469 llvm::Value* index) {
2470 llvm::Value* array_len = EmitLoadArrayLength(array);
2471
2472 llvm::Value* cmp = irb_.CreateICmpUGE(index, array_len);
2473
2474 llvm::BasicBlock* block_exception =
2475 CreateBasicBlockWithDexPC(dex_pc, "overflow");
2476
2477 llvm::BasicBlock* block_continue =
2478 CreateBasicBlockWithDexPC(dex_pc, "cont");
2479
2480 irb_.CreateCondBr(cmp, block_exception, block_continue, kUnlikely);
2481
2482 irb_.SetInsertPoint(block_exception);
2483
2484 EmitUpdateDexPC(dex_pc);
2485 irb_.CreateCall2(irb_.GetRuntime(runtime_support::ThrowIndexOutOfBounds), index, array_len);
2486 EmitBranchExceptionLandingPad(dex_pc);
2487
2488 irb_.SetInsertPoint(block_continue);
2489}
2490
TDYa1275e869b62012-07-25 00:45:39 -07002491llvm::FunctionType* GBCExpanderPass::GetFunctionType(uint32_t method_idx,
2492 bool is_static) {
2493 // Get method signature
TDYa127920be7c2012-09-10 17:13:22 -07002494 art::DexFile::MethodId const& method_id = dex_file_->GetMethodId(method_idx);
TDYa1275e869b62012-07-25 00:45:39 -07002495
2496 uint32_t shorty_size;
2497 const char* shorty = dex_file_->GetMethodShorty(method_id, &shorty_size);
2498 CHECK_GE(shorty_size, 1u);
2499
2500 // Get return type
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07002501
2502 char ret_shorty = shorty[0];
buzbee26f10ee2012-12-21 11:16:29 -08002503 ret_shorty = art::RemapShorty(ret_shorty);
Ian Rogers76ae4fe2013-02-27 16:03:41 -08002504 llvm::Type* ret_type = irb_.getJType(ret_shorty);
TDYa1275e869b62012-07-25 00:45:39 -07002505
2506 // Get argument type
2507 std::vector<llvm::Type*> args_type;
2508
2509 args_type.push_back(irb_.getJObjectTy()); // method object pointer
2510
2511 if (!is_static) {
Ian Rogers76ae4fe2013-02-27 16:03:41 -08002512 args_type.push_back(irb_.getJType('L')); // "this" object pointer
TDYa1275e869b62012-07-25 00:45:39 -07002513 }
2514
2515 for (uint32_t i = 1; i < shorty_size; ++i) {
buzbee26f10ee2012-12-21 11:16:29 -08002516 char shorty_type = art::RemapShorty(shorty[i]);
Ian Rogers76ae4fe2013-02-27 16:03:41 -08002517 args_type.push_back(irb_.getJType(shorty_type));
TDYa1275e869b62012-07-25 00:45:39 -07002518 }
2519
2520 return llvm::FunctionType::get(ret_type, args_type, false);
2521}
2522
2523
2524llvm::BasicBlock* GBCExpanderPass::
2525CreateBasicBlockWithDexPC(uint32_t dex_pc, const char* postfix) {
2526 std::string name;
2527
2528#if !defined(NDEBUG)
TDYa127920be7c2012-09-10 17:13:22 -07002529 art::StringAppendF(&name, "B%04x.%s", dex_pc, postfix);
TDYa1275e869b62012-07-25 00:45:39 -07002530#endif
2531
2532 return llvm::BasicBlock::Create(context_, name, func_);
2533}
2534
2535llvm::BasicBlock* GBCExpanderPass::GetBasicBlock(uint32_t dex_pc) {
2536 DCHECK(dex_pc < code_item_->insns_size_in_code_units_);
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07002537 CHECK(basic_blocks_[dex_pc] != NULL);
TDYa1275e869b62012-07-25 00:45:39 -07002538 return basic_blocks_[dex_pc];
2539}
2540
2541int32_t GBCExpanderPass::GetTryItemOffset(uint32_t dex_pc) {
2542 int32_t min = 0;
2543 int32_t max = code_item_->tries_size_ - 1;
2544
2545 while (min <= max) {
2546 int32_t mid = min + (max - min) / 2;
2547
TDYa127920be7c2012-09-10 17:13:22 -07002548 const art::DexFile::TryItem* ti = art::DexFile::GetTryItems(*code_item_, mid);
TDYa1275e869b62012-07-25 00:45:39 -07002549 uint32_t start = ti->start_addr_;
2550 uint32_t end = start + ti->insn_count_;
2551
2552 if (dex_pc < start) {
2553 max = mid - 1;
2554 } else if (dex_pc >= end) {
2555 min = mid + 1;
2556 } else {
2557 return mid; // found
2558 }
2559 }
2560
2561 return -1; // not found
2562}
2563
2564llvm::BasicBlock* GBCExpanderPass::GetLandingPadBasicBlock(uint32_t dex_pc) {
2565 // Find the try item for this address in this method
2566 int32_t ti_offset = GetTryItemOffset(dex_pc);
2567
2568 if (ti_offset == -1) {
2569 return NULL; // No landing pad is available for this address.
2570 }
2571
2572 // Check for the existing landing pad basic block
2573 DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset));
2574 llvm::BasicBlock* block_lpad = basic_block_landing_pads_[ti_offset];
2575
2576 if (block_lpad) {
2577 // We have generated landing pad for this try item already. Return the
2578 // same basic block.
2579 return block_lpad;
2580 }
2581
2582 // Get try item from code item
TDYa127920be7c2012-09-10 17:13:22 -07002583 const art::DexFile::TryItem* ti = art::DexFile::GetTryItems(*code_item_, ti_offset);
TDYa1275e869b62012-07-25 00:45:39 -07002584
2585 std::string lpadname;
2586
2587#if !defined(NDEBUG)
TDYa127920be7c2012-09-10 17:13:22 -07002588 art::StringAppendF(&lpadname, "lpad%d_%04x_to_%04x", ti_offset, ti->start_addr_, ti->handler_off_);
TDYa1275e869b62012-07-25 00:45:39 -07002589#endif
2590
2591 // Create landing pad basic block
2592 block_lpad = llvm::BasicBlock::Create(context_, lpadname, func_);
2593
2594 // Change IRBuilder insert point
2595 llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
2596 irb_.SetInsertPoint(block_lpad);
2597
2598 // Find catch block with matching type
2599 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2600
2601 llvm::Value* ti_offset_value = irb_.getInt32(ti_offset);
2602
2603 llvm::Value* catch_handler_index_value =
2604 irb_.CreateCall2(irb_.GetRuntime(runtime_support::FindCatchBlock),
2605 method_object_addr, ti_offset_value);
2606
2607 // Switch instruction (Go to unwind basic block by default)
2608 llvm::SwitchInst* sw =
2609 irb_.CreateSwitch(catch_handler_index_value, GetUnwindBasicBlock());
2610
2611 // Cases with matched catch block
TDYa127920be7c2012-09-10 17:13:22 -07002612 art::CatchHandlerIterator iter(*code_item_, ti->start_addr_);
TDYa1275e869b62012-07-25 00:45:39 -07002613
2614 for (uint32_t c = 0; iter.HasNext(); iter.Next(), ++c) {
2615 sw->addCase(irb_.getInt32(c), GetBasicBlock(iter.GetHandlerAddress()));
2616 }
2617
2618 // Restore the orignal insert point for IRBuilder
2619 irb_.restoreIP(irb_ip_original);
2620
2621 // Cache this landing pad
2622 DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset));
2623 basic_block_landing_pads_[ti_offset] = block_lpad;
2624
2625 return block_lpad;
2626}
2627
2628llvm::BasicBlock* GBCExpanderPass::GetUnwindBasicBlock() {
2629 // Check the existing unwinding baisc block block
2630 if (basic_block_unwind_ != NULL) {
2631 return basic_block_unwind_;
2632 }
2633
2634 // Create new basic block for unwinding
2635 basic_block_unwind_ =
2636 llvm::BasicBlock::Create(context_, "exception_unwind", func_);
2637
2638 // Change IRBuilder insert point
2639 llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
2640 irb_.SetInsertPoint(basic_block_unwind_);
2641
2642 // Pop the shadow frame
2643 Expand_PopShadowFrame();
2644
2645 // Emit the code to return default value (zero) for the given return type.
2646 char ret_shorty = oat_compilation_unit_->GetShorty()[0];
buzbee26f10ee2012-12-21 11:16:29 -08002647 ret_shorty = art::RemapShorty(ret_shorty);
TDYa1275e869b62012-07-25 00:45:39 -07002648 if (ret_shorty == 'V') {
2649 irb_.CreateRetVoid();
2650 } else {
2651 irb_.CreateRet(irb_.getJZero(ret_shorty));
2652 }
2653
2654 // Restore the orignal insert point for IRBuilder
2655 irb_.restoreIP(irb_ip_original);
2656
2657 return basic_block_unwind_;
2658}
2659
2660void GBCExpanderPass::EmitBranchExceptionLandingPad(uint32_t dex_pc) {
2661 if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) {
TDYa12755e5e6c2012-09-11 15:14:42 -07002662 landing_pad_phi_mapping_[lpad].push_back(std::make_pair(current_bb_->getUniquePredecessor(),
TDYa127aa558872012-08-16 05:11:07 -07002663 irb_.GetInsertBlock()));
TDYa1275e869b62012-07-25 00:45:39 -07002664 irb_.CreateBr(lpad);
2665 } else {
2666 irb_.CreateBr(GetUnwindBasicBlock());
2667 }
2668}
2669
2670void GBCExpanderPass::EmitGuard_ExceptionLandingPad(uint32_t dex_pc) {
Jeff Hao9a142652013-01-17 23:10:19 +00002671 llvm::Value* exception_pending = irb_.Runtime().EmitIsExceptionPending();
2672
TDYa1275e869b62012-07-25 00:45:39 -07002673 llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont");
2674
2675 if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) {
TDYa12755e5e6c2012-09-11 15:14:42 -07002676 landing_pad_phi_mapping_[lpad].push_back(std::make_pair(current_bb_->getUniquePredecessor(),
TDYa127aa558872012-08-16 05:11:07 -07002677 irb_.GetInsertBlock()));
Jeff Hao9a142652013-01-17 23:10:19 +00002678 irb_.CreateCondBr(exception_pending, lpad, block_cont, kUnlikely);
TDYa1275e869b62012-07-25 00:45:39 -07002679 } else {
Jeff Hao9a142652013-01-17 23:10:19 +00002680 irb_.CreateCondBr(exception_pending, GetUnwindBasicBlock(), block_cont, kUnlikely);
TDYa1275e869b62012-07-25 00:45:39 -07002681 }
2682
2683 irb_.SetInsertPoint(block_cont);
2684}
2685
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002686llvm::Value*
2687GBCExpanderPass::ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id,
2688 llvm::CallInst& call_inst) {
2689 switch (intr_id) {
2690 //==- Thread -----------------------------------------------------------==//
2691 case IntrinsicHelper::GetCurrentThread: {
TDYa127b672d1e2012-06-28 21:21:45 -07002692 return irb_.Runtime().EmitGetCurrentThread();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002693 }
Logan Chien75e4b602012-07-23 14:24:12 -07002694 case IntrinsicHelper::CheckSuspend: {
TDYa127ce4cc0d2012-11-18 16:59:53 -08002695 Expand_TestSuspend(call_inst);
TDYa127890ea892012-08-22 10:49:42 -07002696 return NULL;
2697 }
2698 case IntrinsicHelper::TestSuspend: {
Logan Chiend54a23d2012-07-24 11:19:23 -07002699 Expand_TestSuspend(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002700 return NULL;
2701 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002702 case IntrinsicHelper::MarkGCCard: {
TDYa1279a129452012-07-19 03:10:08 -07002703 Expand_MarkGCCard(call_inst);
2704 return NULL;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002705 }
Logan Chien75e4b602012-07-23 14:24:12 -07002706
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002707 //==- Exception --------------------------------------------------------==//
2708 case IntrinsicHelper::ThrowException: {
2709 return ExpandToRuntime(runtime_support::ThrowException, call_inst);
2710 }
TDYa127f71bf5a2012-07-29 20:09:52 -07002711 case IntrinsicHelper::HLThrowException: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002712 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2713
2714 EmitUpdateDexPC(dex_pc);
2715
2716 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowException),
2717 call_inst.getArgOperand(0));
2718
2719 EmitGuard_ExceptionLandingPad(dex_pc);
2720 return NULL;
2721 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002722 case IntrinsicHelper::GetException: {
TDYa127823433d2012-09-26 16:03:51 -07002723 return irb_.Runtime().EmitGetAndClearException();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002724 }
2725 case IntrinsicHelper::IsExceptionPending: {
2726 return irb_.Runtime().EmitIsExceptionPending();
2727 }
2728 case IntrinsicHelper::FindCatchBlock: {
2729 return ExpandToRuntime(runtime_support::FindCatchBlock, call_inst);
2730 }
2731 case IntrinsicHelper::ThrowDivZeroException: {
2732 return ExpandToRuntime(runtime_support::ThrowDivZeroException, call_inst);
2733 }
2734 case IntrinsicHelper::ThrowNullPointerException: {
2735 return ExpandToRuntime(runtime_support::ThrowNullPointerException, call_inst);
2736 }
2737 case IntrinsicHelper::ThrowIndexOutOfBounds: {
2738 return ExpandToRuntime(runtime_support::ThrowIndexOutOfBounds, call_inst);
2739 }
Logan Chien75e4b602012-07-23 14:24:12 -07002740
2741 //==- Const String -----------------------------------------------------==//
2742 case IntrinsicHelper::ConstString: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002743 return Expand_ConstString(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002744 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002745 case IntrinsicHelper::LoadStringFromDexCache: {
2746 return Expand_LoadStringFromDexCache(call_inst.getArgOperand(0));
2747 }
2748 case IntrinsicHelper::ResolveString: {
2749 return ExpandToRuntime(runtime_support::ResolveString, call_inst);
2750 }
Logan Chien75e4b602012-07-23 14:24:12 -07002751
2752 //==- Const Class ------------------------------------------------------==//
2753 case IntrinsicHelper::ConstClass: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002754 return Expand_ConstClass(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002755 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002756 case IntrinsicHelper::InitializeTypeAndVerifyAccess: {
2757 return ExpandToRuntime(runtime_support::InitializeTypeAndVerifyAccess, call_inst);
2758 }
2759 case IntrinsicHelper::LoadTypeFromDexCache: {
2760 return Expand_LoadTypeFromDexCache(call_inst.getArgOperand(0));
2761 }
2762 case IntrinsicHelper::InitializeType: {
2763 return ExpandToRuntime(runtime_support::InitializeType, call_inst);
2764 }
Logan Chien75e4b602012-07-23 14:24:12 -07002765
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002766 //==- Lock -------------------------------------------------------------==//
2767 case IntrinsicHelper::LockObject: {
2768 Expand_LockObject(call_inst.getArgOperand(0));
2769 return NULL;
2770 }
2771 case IntrinsicHelper::UnlockObject: {
2772 Expand_UnlockObject(call_inst.getArgOperand(0));
2773 return NULL;
2774 }
Logan Chien75e4b602012-07-23 14:24:12 -07002775
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002776 //==- Cast -------------------------------------------------------------==//
2777 case IntrinsicHelper::CheckCast: {
2778 return ExpandToRuntime(runtime_support::CheckCast, call_inst);
2779 }
Logan Chien75e4b602012-07-23 14:24:12 -07002780 case IntrinsicHelper::HLCheckCast: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002781 Expand_HLCheckCast(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002782 return NULL;
2783 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002784 case IntrinsicHelper::IsAssignable: {
2785 return ExpandToRuntime(runtime_support::IsAssignable, call_inst);
2786 }
Logan Chien75e4b602012-07-23 14:24:12 -07002787
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002788 //==- Alloc ------------------------------------------------------------==//
2789 case IntrinsicHelper::AllocObject: {
2790 return ExpandToRuntime(runtime_support::AllocObject, call_inst);
2791 }
2792 case IntrinsicHelper::AllocObjectWithAccessCheck: {
2793 return ExpandToRuntime(runtime_support::AllocObjectWithAccessCheck, call_inst);
2794 }
Logan Chien75e4b602012-07-23 14:24:12 -07002795
2796 //==- Instance ---------------------------------------------------------==//
2797 case IntrinsicHelper::NewInstance: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002798 return Expand_NewInstance(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002799 }
2800 case IntrinsicHelper::InstanceOf: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002801 return Expand_InstanceOf(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002802 }
2803
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002804 //==- Array ------------------------------------------------------------==//
Logan Chien75e4b602012-07-23 14:24:12 -07002805 case IntrinsicHelper::NewArray: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002806 return Expand_NewArray(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002807 }
2808 case IntrinsicHelper::OptArrayLength: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002809 return Expand_OptArrayLength(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002810 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002811 case IntrinsicHelper::ArrayLength: {
2812 return EmitLoadArrayLength(call_inst.getArgOperand(0));
2813 }
2814 case IntrinsicHelper::AllocArray: {
2815 return ExpandToRuntime(runtime_support::AllocArray, call_inst);
2816 }
2817 case IntrinsicHelper::AllocArrayWithAccessCheck: {
2818 return ExpandToRuntime(runtime_support::AllocArrayWithAccessCheck,
2819 call_inst);
2820 }
2821 case IntrinsicHelper::CheckAndAllocArray: {
2822 return ExpandToRuntime(runtime_support::CheckAndAllocArray, call_inst);
2823 }
2824 case IntrinsicHelper::CheckAndAllocArrayWithAccessCheck: {
2825 return ExpandToRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck,
2826 call_inst);
2827 }
2828 case IntrinsicHelper::ArrayGet: {
2829 return Expand_ArrayGet(call_inst.getArgOperand(0),
2830 call_inst.getArgOperand(1),
2831 kInt);
2832 }
2833 case IntrinsicHelper::ArrayGetWide: {
2834 return Expand_ArrayGet(call_inst.getArgOperand(0),
2835 call_inst.getArgOperand(1),
2836 kLong);
2837 }
2838 case IntrinsicHelper::ArrayGetObject: {
2839 return Expand_ArrayGet(call_inst.getArgOperand(0),
2840 call_inst.getArgOperand(1),
2841 kObject);
2842 }
2843 case IntrinsicHelper::ArrayGetBoolean: {
2844 return Expand_ArrayGet(call_inst.getArgOperand(0),
2845 call_inst.getArgOperand(1),
2846 kBoolean);
2847 }
2848 case IntrinsicHelper::ArrayGetByte: {
2849 return Expand_ArrayGet(call_inst.getArgOperand(0),
2850 call_inst.getArgOperand(1),
2851 kByte);
2852 }
2853 case IntrinsicHelper::ArrayGetChar: {
2854 return Expand_ArrayGet(call_inst.getArgOperand(0),
2855 call_inst.getArgOperand(1),
2856 kChar);
2857 }
2858 case IntrinsicHelper::ArrayGetShort: {
2859 return Expand_ArrayGet(call_inst.getArgOperand(0),
2860 call_inst.getArgOperand(1),
2861 kShort);
2862 }
2863 case IntrinsicHelper::ArrayPut: {
2864 Expand_ArrayPut(call_inst.getArgOperand(0),
2865 call_inst.getArgOperand(1),
2866 call_inst.getArgOperand(2),
2867 kInt);
2868 return NULL;
2869 }
2870 case IntrinsicHelper::ArrayPutWide: {
2871 Expand_ArrayPut(call_inst.getArgOperand(0),
2872 call_inst.getArgOperand(1),
2873 call_inst.getArgOperand(2),
2874 kLong);
2875 return NULL;
2876 }
2877 case IntrinsicHelper::ArrayPutObject: {
2878 Expand_ArrayPut(call_inst.getArgOperand(0),
2879 call_inst.getArgOperand(1),
2880 call_inst.getArgOperand(2),
2881 kObject);
2882 return NULL;
2883 }
2884 case IntrinsicHelper::ArrayPutBoolean: {
2885 Expand_ArrayPut(call_inst.getArgOperand(0),
2886 call_inst.getArgOperand(1),
2887 call_inst.getArgOperand(2),
2888 kBoolean);
2889 return NULL;
2890 }
2891 case IntrinsicHelper::ArrayPutByte: {
2892 Expand_ArrayPut(call_inst.getArgOperand(0),
2893 call_inst.getArgOperand(1),
2894 call_inst.getArgOperand(2),
2895 kByte);
2896 return NULL;
2897 }
2898 case IntrinsicHelper::ArrayPutChar: {
2899 Expand_ArrayPut(call_inst.getArgOperand(0),
2900 call_inst.getArgOperand(1),
2901 call_inst.getArgOperand(2),
2902 kChar);
2903 return NULL;
2904 }
2905 case IntrinsicHelper::ArrayPutShort: {
2906 Expand_ArrayPut(call_inst.getArgOperand(0),
2907 call_inst.getArgOperand(1),
2908 call_inst.getArgOperand(2),
2909 kShort);
2910 return NULL;
2911 }
2912 case IntrinsicHelper::CheckPutArrayElement: {
2913 return ExpandToRuntime(runtime_support::CheckPutArrayElement, call_inst);
2914 }
2915 case IntrinsicHelper::FilledNewArray: {
2916 Expand_FilledNewArray(call_inst);
2917 return NULL;
2918 }
2919 case IntrinsicHelper::FillArrayData: {
2920 return ExpandToRuntime(runtime_support::FillArrayData, call_inst);
2921 }
Logan Chien75e4b602012-07-23 14:24:12 -07002922 case IntrinsicHelper::HLFillArrayData: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002923 Expand_HLFillArrayData(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002924 return NULL;
2925 }
2926 case IntrinsicHelper::HLFilledNewArray: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002927 return Expand_HLFilledNewArray(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002928 }
2929
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002930 //==- Instance Field ---------------------------------------------------==//
2931 case IntrinsicHelper::InstanceFieldGet:
2932 case IntrinsicHelper::InstanceFieldGetBoolean:
2933 case IntrinsicHelper::InstanceFieldGetByte:
2934 case IntrinsicHelper::InstanceFieldGetChar:
2935 case IntrinsicHelper::InstanceFieldGetShort: {
2936 return ExpandToRuntime(runtime_support::Get32Instance, call_inst);
2937 }
2938 case IntrinsicHelper::InstanceFieldGetWide: {
2939 return ExpandToRuntime(runtime_support::Get64Instance, call_inst);
2940 }
2941 case IntrinsicHelper::InstanceFieldGetObject: {
2942 return ExpandToRuntime(runtime_support::GetObjectInstance, call_inst);
2943 }
2944 case IntrinsicHelper::InstanceFieldGetFast: {
2945 return Expand_IGetFast(call_inst.getArgOperand(0),
2946 call_inst.getArgOperand(1),
2947 call_inst.getArgOperand(2),
2948 kInt);
2949 }
2950 case IntrinsicHelper::InstanceFieldGetWideFast: {
2951 return Expand_IGetFast(call_inst.getArgOperand(0),
2952 call_inst.getArgOperand(1),
2953 call_inst.getArgOperand(2),
2954 kLong);
2955 }
2956 case IntrinsicHelper::InstanceFieldGetObjectFast: {
2957 return Expand_IGetFast(call_inst.getArgOperand(0),
2958 call_inst.getArgOperand(1),
2959 call_inst.getArgOperand(2),
2960 kObject);
2961 }
2962 case IntrinsicHelper::InstanceFieldGetBooleanFast: {
2963 return Expand_IGetFast(call_inst.getArgOperand(0),
2964 call_inst.getArgOperand(1),
2965 call_inst.getArgOperand(2),
2966 kBoolean);
2967 }
2968 case IntrinsicHelper::InstanceFieldGetByteFast: {
2969 return Expand_IGetFast(call_inst.getArgOperand(0),
2970 call_inst.getArgOperand(1),
2971 call_inst.getArgOperand(2),
2972 kByte);
2973 }
2974 case IntrinsicHelper::InstanceFieldGetCharFast: {
2975 return Expand_IGetFast(call_inst.getArgOperand(0),
2976 call_inst.getArgOperand(1),
2977 call_inst.getArgOperand(2),
2978 kChar);
2979 }
2980 case IntrinsicHelper::InstanceFieldGetShortFast: {
2981 return Expand_IGetFast(call_inst.getArgOperand(0),
2982 call_inst.getArgOperand(1),
2983 call_inst.getArgOperand(2),
2984 kShort);
2985 }
2986 case IntrinsicHelper::InstanceFieldPut:
2987 case IntrinsicHelper::InstanceFieldPutBoolean:
2988 case IntrinsicHelper::InstanceFieldPutByte:
2989 case IntrinsicHelper::InstanceFieldPutChar:
2990 case IntrinsicHelper::InstanceFieldPutShort: {
2991 return ExpandToRuntime(runtime_support::Set32Instance, call_inst);
2992 }
2993 case IntrinsicHelper::InstanceFieldPutWide: {
2994 return ExpandToRuntime(runtime_support::Set64Instance, call_inst);
2995 }
2996 case IntrinsicHelper::InstanceFieldPutObject: {
2997 return ExpandToRuntime(runtime_support::SetObjectInstance, call_inst);
2998 }
2999 case IntrinsicHelper::InstanceFieldPutFast: {
3000 Expand_IPutFast(call_inst.getArgOperand(0),
3001 call_inst.getArgOperand(1),
3002 call_inst.getArgOperand(2),
3003 call_inst.getArgOperand(3),
3004 kInt);
3005 return NULL;
3006 }
3007 case IntrinsicHelper::InstanceFieldPutWideFast: {
3008 Expand_IPutFast(call_inst.getArgOperand(0),
3009 call_inst.getArgOperand(1),
3010 call_inst.getArgOperand(2),
3011 call_inst.getArgOperand(3),
3012 kLong);
3013 return NULL;
3014 }
3015 case IntrinsicHelper::InstanceFieldPutObjectFast: {
3016 Expand_IPutFast(call_inst.getArgOperand(0),
3017 call_inst.getArgOperand(1),
3018 call_inst.getArgOperand(2),
3019 call_inst.getArgOperand(3),
3020 kObject);
3021 return NULL;
3022 }
3023 case IntrinsicHelper::InstanceFieldPutBooleanFast: {
3024 Expand_IPutFast(call_inst.getArgOperand(0),
3025 call_inst.getArgOperand(1),
3026 call_inst.getArgOperand(2),
3027 call_inst.getArgOperand(3),
3028 kBoolean);
3029 return NULL;
3030 }
3031 case IntrinsicHelper::InstanceFieldPutByteFast: {
3032 Expand_IPutFast(call_inst.getArgOperand(0),
3033 call_inst.getArgOperand(1),
3034 call_inst.getArgOperand(2),
3035 call_inst.getArgOperand(3),
3036 kByte);
3037 return NULL;
3038 }
3039 case IntrinsicHelper::InstanceFieldPutCharFast: {
3040 Expand_IPutFast(call_inst.getArgOperand(0),
3041 call_inst.getArgOperand(1),
3042 call_inst.getArgOperand(2),
3043 call_inst.getArgOperand(3),
3044 kChar);
3045 return NULL;
3046 }
3047 case IntrinsicHelper::InstanceFieldPutShortFast: {
3048 Expand_IPutFast(call_inst.getArgOperand(0),
3049 call_inst.getArgOperand(1),
3050 call_inst.getArgOperand(2),
3051 call_inst.getArgOperand(3),
3052 kShort);
3053 return NULL;
3054 }
Logan Chien75e4b602012-07-23 14:24:12 -07003055
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003056 //==- Static Field -----------------------------------------------------==//
3057 case IntrinsicHelper::StaticFieldGet:
3058 case IntrinsicHelper::StaticFieldGetBoolean:
3059 case IntrinsicHelper::StaticFieldGetByte:
3060 case IntrinsicHelper::StaticFieldGetChar:
3061 case IntrinsicHelper::StaticFieldGetShort: {
3062 return ExpandToRuntime(runtime_support::Get32Static, call_inst);
3063 }
3064 case IntrinsicHelper::StaticFieldGetWide: {
3065 return ExpandToRuntime(runtime_support::Get64Static, call_inst);
3066 }
3067 case IntrinsicHelper::StaticFieldGetObject: {
3068 return ExpandToRuntime(runtime_support::GetObjectStatic, call_inst);
3069 }
3070 case IntrinsicHelper::StaticFieldGetFast: {
3071 return Expand_SGetFast(call_inst.getArgOperand(0),
3072 call_inst.getArgOperand(1),
3073 call_inst.getArgOperand(2),
3074 kInt);
3075 }
3076 case IntrinsicHelper::StaticFieldGetWideFast: {
3077 return Expand_SGetFast(call_inst.getArgOperand(0),
3078 call_inst.getArgOperand(1),
3079 call_inst.getArgOperand(2),
3080 kLong);
3081 }
3082 case IntrinsicHelper::StaticFieldGetObjectFast: {
3083 return Expand_SGetFast(call_inst.getArgOperand(0),
3084 call_inst.getArgOperand(1),
3085 call_inst.getArgOperand(2),
3086 kObject);
3087 }
3088 case IntrinsicHelper::StaticFieldGetBooleanFast: {
3089 return Expand_SGetFast(call_inst.getArgOperand(0),
3090 call_inst.getArgOperand(1),
3091 call_inst.getArgOperand(2),
3092 kBoolean);
3093 }
3094 case IntrinsicHelper::StaticFieldGetByteFast: {
3095 return Expand_SGetFast(call_inst.getArgOperand(0),
3096 call_inst.getArgOperand(1),
3097 call_inst.getArgOperand(2),
3098 kByte);
3099 }
3100 case IntrinsicHelper::StaticFieldGetCharFast: {
3101 return Expand_SGetFast(call_inst.getArgOperand(0),
3102 call_inst.getArgOperand(1),
3103 call_inst.getArgOperand(2),
3104 kChar);
3105 }
3106 case IntrinsicHelper::StaticFieldGetShortFast: {
3107 return Expand_SGetFast(call_inst.getArgOperand(0),
3108 call_inst.getArgOperand(1),
3109 call_inst.getArgOperand(2),
3110 kShort);
3111 }
3112 case IntrinsicHelper::StaticFieldPut:
3113 case IntrinsicHelper::StaticFieldPutBoolean:
3114 case IntrinsicHelper::StaticFieldPutByte:
3115 case IntrinsicHelper::StaticFieldPutChar:
3116 case IntrinsicHelper::StaticFieldPutShort: {
3117 return ExpandToRuntime(runtime_support::Set32Static, call_inst);
3118 }
3119 case IntrinsicHelper::StaticFieldPutWide: {
3120 return ExpandToRuntime(runtime_support::Set64Static, call_inst);
3121 }
3122 case IntrinsicHelper::StaticFieldPutObject: {
3123 return ExpandToRuntime(runtime_support::SetObjectStatic, call_inst);
3124 }
3125 case IntrinsicHelper::StaticFieldPutFast: {
3126 Expand_SPutFast(call_inst.getArgOperand(0),
3127 call_inst.getArgOperand(1),
3128 call_inst.getArgOperand(2),
3129 call_inst.getArgOperand(3),
3130 kInt);
3131 return NULL;
3132 }
3133 case IntrinsicHelper::StaticFieldPutWideFast: {
3134 Expand_SPutFast(call_inst.getArgOperand(0),
3135 call_inst.getArgOperand(1),
3136 call_inst.getArgOperand(2),
3137 call_inst.getArgOperand(3),
3138 kLong);
3139 return NULL;
3140 }
3141 case IntrinsicHelper::StaticFieldPutObjectFast: {
3142 Expand_SPutFast(call_inst.getArgOperand(0),
3143 call_inst.getArgOperand(1),
3144 call_inst.getArgOperand(2),
3145 call_inst.getArgOperand(3),
3146 kObject);
3147 return NULL;
3148 }
3149 case IntrinsicHelper::StaticFieldPutBooleanFast: {
3150 Expand_SPutFast(call_inst.getArgOperand(0),
3151 call_inst.getArgOperand(1),
3152 call_inst.getArgOperand(2),
3153 call_inst.getArgOperand(3),
3154 kBoolean);
3155 return NULL;
3156 }
3157 case IntrinsicHelper::StaticFieldPutByteFast: {
3158 Expand_SPutFast(call_inst.getArgOperand(0),
3159 call_inst.getArgOperand(1),
3160 call_inst.getArgOperand(2),
3161 call_inst.getArgOperand(3),
3162 kByte);
3163 return NULL;
3164 }
3165 case IntrinsicHelper::StaticFieldPutCharFast: {
3166 Expand_SPutFast(call_inst.getArgOperand(0),
3167 call_inst.getArgOperand(1),
3168 call_inst.getArgOperand(2),
3169 call_inst.getArgOperand(3),
3170 kChar);
3171 return NULL;
3172 }
3173 case IntrinsicHelper::StaticFieldPutShortFast: {
3174 Expand_SPutFast(call_inst.getArgOperand(0),
3175 call_inst.getArgOperand(1),
3176 call_inst.getArgOperand(2),
3177 call_inst.getArgOperand(3),
3178 kShort);
3179 return NULL;
3180 }
3181 case IntrinsicHelper::LoadDeclaringClassSSB: {
3182 return Expand_LoadDeclaringClassSSB(call_inst.getArgOperand(0));
3183 }
3184 case IntrinsicHelper::LoadClassSSBFromDexCache: {
3185 return Expand_LoadClassSSBFromDexCache(call_inst.getArgOperand(0));
3186 }
3187 case IntrinsicHelper::InitializeAndLoadClassSSB: {
3188 return ExpandToRuntime(runtime_support::InitializeStaticStorage, call_inst);
3189 }
Logan Chien75e4b602012-07-23 14:24:12 -07003190
3191 //==- High-level Array -------------------------------------------------==//
3192 case IntrinsicHelper::HLArrayGet: {
TDYa1275a26d442012-07-26 18:58:38 -07003193 return Expand_HLArrayGet(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003194 }
3195 case IntrinsicHelper::HLArrayGetBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003196 return Expand_HLArrayGet(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003197 }
3198 case IntrinsicHelper::HLArrayGetByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003199 return Expand_HLArrayGet(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003200 }
3201 case IntrinsicHelper::HLArrayGetChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003202 return Expand_HLArrayGet(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003203 }
3204 case IntrinsicHelper::HLArrayGetShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003205 return Expand_HLArrayGet(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003206 }
3207 case IntrinsicHelper::HLArrayGetFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003208 return Expand_HLArrayGet(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003209 }
3210 case IntrinsicHelper::HLArrayGetWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003211 return Expand_HLArrayGet(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003212 }
3213 case IntrinsicHelper::HLArrayGetDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003214 return Expand_HLArrayGet(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003215 }
3216 case IntrinsicHelper::HLArrayGetObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003217 return Expand_HLArrayGet(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003218 }
3219 case IntrinsicHelper::HLArrayPut: {
TDYa1275a26d442012-07-26 18:58:38 -07003220 Expand_HLArrayPut(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003221 return NULL;
3222 }
3223 case IntrinsicHelper::HLArrayPutBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003224 Expand_HLArrayPut(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003225 return NULL;
3226 }
3227 case IntrinsicHelper::HLArrayPutByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003228 Expand_HLArrayPut(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003229 return NULL;
3230 }
3231 case IntrinsicHelper::HLArrayPutChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003232 Expand_HLArrayPut(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003233 return NULL;
3234 }
3235 case IntrinsicHelper::HLArrayPutShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003236 Expand_HLArrayPut(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003237 return NULL;
3238 }
3239 case IntrinsicHelper::HLArrayPutFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003240 Expand_HLArrayPut(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003241 return NULL;
3242 }
3243 case IntrinsicHelper::HLArrayPutWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003244 Expand_HLArrayPut(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003245 return NULL;
3246 }
3247 case IntrinsicHelper::HLArrayPutDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003248 Expand_HLArrayPut(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003249 return NULL;
3250 }
3251 case IntrinsicHelper::HLArrayPutObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003252 Expand_HLArrayPut(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003253 return NULL;
3254 }
3255
3256 //==- High-level Instance ----------------------------------------------==//
3257 case IntrinsicHelper::HLIGet: {
TDYa1275e869b62012-07-25 00:45:39 -07003258 return Expand_HLIGet(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003259 }
3260 case IntrinsicHelper::HLIGetBoolean: {
TDYa1275e869b62012-07-25 00:45:39 -07003261 return Expand_HLIGet(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003262 }
3263 case IntrinsicHelper::HLIGetByte: {
TDYa1275e869b62012-07-25 00:45:39 -07003264 return Expand_HLIGet(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003265 }
3266 case IntrinsicHelper::HLIGetChar: {
TDYa1275e869b62012-07-25 00:45:39 -07003267 return Expand_HLIGet(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003268 }
3269 case IntrinsicHelper::HLIGetShort: {
TDYa1275e869b62012-07-25 00:45:39 -07003270 return Expand_HLIGet(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003271 }
3272 case IntrinsicHelper::HLIGetFloat: {
TDYa1275e869b62012-07-25 00:45:39 -07003273 return Expand_HLIGet(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003274 }
3275 case IntrinsicHelper::HLIGetWide: {
TDYa1275e869b62012-07-25 00:45:39 -07003276 return Expand_HLIGet(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003277 }
3278 case IntrinsicHelper::HLIGetDouble: {
TDYa1275e869b62012-07-25 00:45:39 -07003279 return Expand_HLIGet(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003280 }
3281 case IntrinsicHelper::HLIGetObject: {
TDYa1275e869b62012-07-25 00:45:39 -07003282 return Expand_HLIGet(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003283 }
3284 case IntrinsicHelper::HLIPut: {
TDYa1275e869b62012-07-25 00:45:39 -07003285 Expand_HLIPut(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003286 return NULL;
3287 }
3288 case IntrinsicHelper::HLIPutBoolean: {
TDYa1275e869b62012-07-25 00:45:39 -07003289 Expand_HLIPut(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003290 return NULL;
3291 }
3292 case IntrinsicHelper::HLIPutByte: {
TDYa1275e869b62012-07-25 00:45:39 -07003293 Expand_HLIPut(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003294 return NULL;
3295 }
3296 case IntrinsicHelper::HLIPutChar: {
TDYa1275e869b62012-07-25 00:45:39 -07003297 Expand_HLIPut(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003298 return NULL;
3299 }
3300 case IntrinsicHelper::HLIPutShort: {
TDYa1275e869b62012-07-25 00:45:39 -07003301 Expand_HLIPut(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003302 return NULL;
3303 }
3304 case IntrinsicHelper::HLIPutFloat: {
TDYa1275e869b62012-07-25 00:45:39 -07003305 Expand_HLIPut(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003306 return NULL;
3307 }
3308 case IntrinsicHelper::HLIPutWide: {
TDYa1275e869b62012-07-25 00:45:39 -07003309 Expand_HLIPut(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003310 return NULL;
3311 }
3312 case IntrinsicHelper::HLIPutDouble: {
TDYa1275e869b62012-07-25 00:45:39 -07003313 Expand_HLIPut(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003314 return NULL;
3315 }
3316 case IntrinsicHelper::HLIPutObject: {
TDYa1275e869b62012-07-25 00:45:39 -07003317 Expand_HLIPut(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003318 return NULL;
3319 }
3320
3321 //==- High-level Invoke ------------------------------------------------==//
TDYa127f71bf5a2012-07-29 20:09:52 -07003322 case IntrinsicHelper::HLInvokeVoid:
3323 case IntrinsicHelper::HLInvokeObj:
3324 case IntrinsicHelper::HLInvokeInt:
3325 case IntrinsicHelper::HLInvokeFloat:
3326 case IntrinsicHelper::HLInvokeLong:
Logan Chien75e4b602012-07-23 14:24:12 -07003327 case IntrinsicHelper::HLInvokeDouble: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003328 return Expand_HLInvoke(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003329 }
3330
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003331 //==- Invoke -----------------------------------------------------------==//
3332 case IntrinsicHelper::FindStaticMethodWithAccessCheck: {
3333 return ExpandToRuntime(runtime_support::FindStaticMethodWithAccessCheck, call_inst);
3334 }
3335 case IntrinsicHelper::FindDirectMethodWithAccessCheck: {
3336 return ExpandToRuntime(runtime_support::FindDirectMethodWithAccessCheck, call_inst);
3337 }
3338 case IntrinsicHelper::FindVirtualMethodWithAccessCheck: {
3339 return ExpandToRuntime(runtime_support::FindVirtualMethodWithAccessCheck, call_inst);
3340 }
3341 case IntrinsicHelper::FindSuperMethodWithAccessCheck: {
3342 return ExpandToRuntime(runtime_support::FindSuperMethodWithAccessCheck, call_inst);
3343 }
3344 case IntrinsicHelper::FindInterfaceMethodWithAccessCheck: {
3345 return ExpandToRuntime(runtime_support::FindInterfaceMethodWithAccessCheck, call_inst);
3346 }
3347 case IntrinsicHelper::GetSDCalleeMethodObjAddrFast: {
3348 return Expand_GetSDCalleeMethodObjAddrFast(call_inst.getArgOperand(0));
3349 }
3350 case IntrinsicHelper::GetVirtualCalleeMethodObjAddrFast: {
3351 return Expand_GetVirtualCalleeMethodObjAddrFast(
3352 call_inst.getArgOperand(0), call_inst.getArgOperand(1));
3353 }
3354 case IntrinsicHelper::GetInterfaceCalleeMethodObjAddrFast: {
3355 return ExpandToRuntime(runtime_support::FindInterfaceMethod, call_inst);
3356 }
3357 case IntrinsicHelper::InvokeRetVoid:
3358 case IntrinsicHelper::InvokeRetBoolean:
3359 case IntrinsicHelper::InvokeRetByte:
3360 case IntrinsicHelper::InvokeRetChar:
3361 case IntrinsicHelper::InvokeRetShort:
3362 case IntrinsicHelper::InvokeRetInt:
3363 case IntrinsicHelper::InvokeRetLong:
3364 case IntrinsicHelper::InvokeRetFloat:
3365 case IntrinsicHelper::InvokeRetDouble:
3366 case IntrinsicHelper::InvokeRetObject: {
3367 return Expand_Invoke(call_inst);
3368 }
Logan Chien75e4b602012-07-23 14:24:12 -07003369
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003370 //==- Math -------------------------------------------------------------==//
3371 case IntrinsicHelper::DivInt: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003372 return Expand_DivRem(call_inst, /* is_div */true, kInt);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003373 }
3374 case IntrinsicHelper::RemInt: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003375 return Expand_DivRem(call_inst, /* is_div */false, kInt);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003376 }
3377 case IntrinsicHelper::DivLong: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003378 return Expand_DivRem(call_inst, /* is_div */true, kLong);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003379 }
3380 case IntrinsicHelper::RemLong: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003381 return Expand_DivRem(call_inst, /* is_div */false, kLong);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003382 }
3383 case IntrinsicHelper::D2L: {
3384 return ExpandToRuntime(runtime_support::art_d2l, call_inst);
3385 }
3386 case IntrinsicHelper::D2I: {
3387 return ExpandToRuntime(runtime_support::art_d2i, call_inst);
3388 }
3389 case IntrinsicHelper::F2L: {
3390 return ExpandToRuntime(runtime_support::art_f2l, call_inst);
3391 }
3392 case IntrinsicHelper::F2I: {
3393 return ExpandToRuntime(runtime_support::art_f2i, call_inst);
3394 }
Logan Chien75e4b602012-07-23 14:24:12 -07003395
3396 //==- High-level Static ------------------------------------------------==//
3397 case IntrinsicHelper::HLSget: {
TDYa1275a26d442012-07-26 18:58:38 -07003398 return Expand_HLSget(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003399 }
3400 case IntrinsicHelper::HLSgetBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003401 return Expand_HLSget(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003402 }
3403 case IntrinsicHelper::HLSgetByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003404 return Expand_HLSget(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003405 }
3406 case IntrinsicHelper::HLSgetChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003407 return Expand_HLSget(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003408 }
3409 case IntrinsicHelper::HLSgetShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003410 return Expand_HLSget(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003411 }
3412 case IntrinsicHelper::HLSgetFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003413 return Expand_HLSget(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003414 }
3415 case IntrinsicHelper::HLSgetWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003416 return Expand_HLSget(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003417 }
3418 case IntrinsicHelper::HLSgetDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003419 return Expand_HLSget(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003420 }
3421 case IntrinsicHelper::HLSgetObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003422 return Expand_HLSget(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003423 }
3424 case IntrinsicHelper::HLSput: {
TDYa1275a26d442012-07-26 18:58:38 -07003425 Expand_HLSput(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003426 return NULL;
3427 }
3428 case IntrinsicHelper::HLSputBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003429 Expand_HLSput(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003430 return NULL;
3431 }
3432 case IntrinsicHelper::HLSputByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003433 Expand_HLSput(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003434 return NULL;
3435 }
3436 case IntrinsicHelper::HLSputChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003437 Expand_HLSput(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003438 return NULL;
3439 }
3440 case IntrinsicHelper::HLSputShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003441 Expand_HLSput(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003442 return NULL;
3443 }
3444 case IntrinsicHelper::HLSputFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003445 Expand_HLSput(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003446 return NULL;
3447 }
3448 case IntrinsicHelper::HLSputWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003449 Expand_HLSput(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003450 return NULL;
3451 }
3452 case IntrinsicHelper::HLSputDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003453 Expand_HLSput(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003454 return NULL;
3455 }
3456 case IntrinsicHelper::HLSputObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003457 Expand_HLSput(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003458 return NULL;
3459 }
3460
3461 //==- High-level Monitor -----------------------------------------------==//
3462 case IntrinsicHelper::MonitorEnter: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003463 Expand_MonitorEnter(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003464 return NULL;
3465 }
3466 case IntrinsicHelper::MonitorExit: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003467 Expand_MonitorExit(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003468 return NULL;
3469 }
3470
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003471 //==- Shadow Frame -----------------------------------------------------==//
3472 case IntrinsicHelper::AllocaShadowFrame: {
TDYa127ce4cc0d2012-11-18 16:59:53 -08003473 Expand_AllocaShadowFrame(call_inst.getArgOperand(0));
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003474 return NULL;
3475 }
TDYa1278e950c12012-11-02 09:58:19 -07003476 case IntrinsicHelper::SetVReg: {
3477 Expand_SetVReg(call_inst.getArgOperand(0),
3478 call_inst.getArgOperand(1));
3479 return NULL;
3480 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003481 case IntrinsicHelper::PopShadowFrame: {
3482 Expand_PopShadowFrame();
3483 return NULL;
3484 }
3485 case IntrinsicHelper::UpdateDexPC: {
3486 Expand_UpdateDexPC(call_inst.getArgOperand(0));
3487 return NULL;
3488 }
TDYa127a1b21852012-07-23 03:20:39 -07003489
Logan Chien75e4b602012-07-23 14:24:12 -07003490 //==- Comparison -------------------------------------------------------==//
3491 case IntrinsicHelper::CmplFloat:
3492 case IntrinsicHelper::CmplDouble: {
3493 return Expand_FPCompare(call_inst.getArgOperand(0),
3494 call_inst.getArgOperand(1),
3495 false);
3496 }
3497 case IntrinsicHelper::CmpgFloat:
3498 case IntrinsicHelper::CmpgDouble: {
3499 return Expand_FPCompare(call_inst.getArgOperand(0),
3500 call_inst.getArgOperand(1),
3501 true);
3502 }
3503 case IntrinsicHelper::CmpLong: {
3504 return Expand_LongCompare(call_inst.getArgOperand(0),
3505 call_inst.getArgOperand(1));
3506 }
TDYa127a1b21852012-07-23 03:20:39 -07003507
Logan Chien75e4b602012-07-23 14:24:12 -07003508 //==- Const ------------------------------------------------------------==//
TDYa127920be7c2012-09-10 17:13:22 -07003509 case IntrinsicHelper::ConstInt:
3510 case IntrinsicHelper::ConstLong: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003511 return call_inst.getArgOperand(0);
Logan Chien75e4b602012-07-23 14:24:12 -07003512 }
TDYa127920be7c2012-09-10 17:13:22 -07003513 case IntrinsicHelper::ConstFloat: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003514 return irb_.CreateBitCast(call_inst.getArgOperand(0),
3515 irb_.getJFloatTy());
Logan Chien75e4b602012-07-23 14:24:12 -07003516 }
TDYa127920be7c2012-09-10 17:13:22 -07003517 case IntrinsicHelper::ConstDouble: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003518 return irb_.CreateBitCast(call_inst.getArgOperand(0),
3519 irb_.getJDoubleTy());
3520 }
TDYa127920be7c2012-09-10 17:13:22 -07003521 case IntrinsicHelper::ConstObj: {
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07003522 CHECK(LV2UInt(call_inst.getArgOperand(0)) == 0);
3523 return irb_.getJNull();
Logan Chien75e4b602012-07-23 14:24:12 -07003524 }
3525
3526 //==- Method Info ------------------------------------------------------==//
TDYa127920be7c2012-09-10 17:13:22 -07003527 case IntrinsicHelper::MethodInfo: {
Shih-wei Liaob2596522012-09-14 16:36:11 -07003528 // Nothing to be done, because MethodInfo carries optional hints that are
3529 // not needed by the portable path.
Logan Chien75e4b602012-07-23 14:24:12 -07003530 return NULL;
3531 }
3532
3533 //==- Copy -------------------------------------------------------------==//
TDYa127920be7c2012-09-10 17:13:22 -07003534 case IntrinsicHelper::CopyInt:
3535 case IntrinsicHelper::CopyFloat:
3536 case IntrinsicHelper::CopyLong:
3537 case IntrinsicHelper::CopyDouble:
3538 case IntrinsicHelper::CopyObj: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003539 return call_inst.getArgOperand(0);
Logan Chien75e4b602012-07-23 14:24:12 -07003540 }
3541
3542 //==- Shift ------------------------------------------------------------==//
TDYa127920be7c2012-09-10 17:13:22 -07003543 case IntrinsicHelper::SHLLong: {
Logan Chien75e4b602012-07-23 14:24:12 -07003544 return Expand_IntegerShift(call_inst.getArgOperand(0),
3545 call_inst.getArgOperand(1),
3546 kIntegerSHL, kLong);
3547 }
TDYa127920be7c2012-09-10 17:13:22 -07003548 case IntrinsicHelper::SHRLong: {
Logan Chien75e4b602012-07-23 14:24:12 -07003549 return Expand_IntegerShift(call_inst.getArgOperand(0),
3550 call_inst.getArgOperand(1),
3551 kIntegerSHR, kLong);
3552 }
TDYa127920be7c2012-09-10 17:13:22 -07003553 case IntrinsicHelper::USHRLong: {
Logan Chien75e4b602012-07-23 14:24:12 -07003554 return Expand_IntegerShift(call_inst.getArgOperand(0),
3555 call_inst.getArgOperand(1),
3556 kIntegerUSHR, kLong);
3557 }
TDYa127920be7c2012-09-10 17:13:22 -07003558 case IntrinsicHelper::SHLInt: {
Logan Chien75e4b602012-07-23 14:24:12 -07003559 return Expand_IntegerShift(call_inst.getArgOperand(0),
3560 call_inst.getArgOperand(1),
3561 kIntegerSHL, kInt);
3562 }
TDYa127920be7c2012-09-10 17:13:22 -07003563 case IntrinsicHelper::SHRInt: {
Logan Chien75e4b602012-07-23 14:24:12 -07003564 return Expand_IntegerShift(call_inst.getArgOperand(0),
3565 call_inst.getArgOperand(1),
3566 kIntegerSHR, kInt);
3567 }
TDYa127920be7c2012-09-10 17:13:22 -07003568 case IntrinsicHelper::USHRInt: {
Logan Chien75e4b602012-07-23 14:24:12 -07003569 return Expand_IntegerShift(call_inst.getArgOperand(0),
3570 call_inst.getArgOperand(1),
3571 kIntegerUSHR, kInt);
3572 }
3573
3574 //==- Conversion -------------------------------------------------------==//
TDYa127a1b21852012-07-23 03:20:39 -07003575 case IntrinsicHelper::IntToChar: {
3576 return irb_.CreateZExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJCharTy()),
3577 irb_.getJIntTy());
3578 }
3579 case IntrinsicHelper::IntToShort: {
3580 return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJShortTy()),
3581 irb_.getJIntTy());
3582 }
3583 case IntrinsicHelper::IntToByte: {
3584 return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJByteTy()),
3585 irb_.getJIntTy());
3586 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003587
TDYa12787caa7e2012-08-25 23:23:27 -07003588 //==- Exception --------------------------------------------------------==//
3589 case IntrinsicHelper::CatchTargets: {
TDYa12755e5e6c2012-09-11 15:14:42 -07003590 UpdatePhiInstruction(current_bb_, irb_.GetInsertBlock());
TDYa12787caa7e2012-08-25 23:23:27 -07003591 llvm::SwitchInst* si = llvm::dyn_cast<llvm::SwitchInst>(call_inst.getNextNode());
3592 CHECK(si != NULL);
3593 irb_.CreateBr(si->getDefaultDest());
3594 si->eraseFromParent();
3595 return call_inst.getArgOperand(0);
3596 }
3597
Logan Chien75e4b602012-07-23 14:24:12 -07003598 //==- Unknown Cases ----------------------------------------------------==//
3599 case IntrinsicHelper::MaxIntrinsicId:
3600 case IntrinsicHelper::UnknownId:
3601 //default:
3602 // NOTE: "default" is intentionally commented so that C/C++ compiler will
3603 // give some warning on unmatched cases.
3604 // NOTE: We should not implement these cases.
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003605 break;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003606 }
Logan Chien75e4b602012-07-23 14:24:12 -07003607 UNIMPLEMENTED(FATAL) << "Unexpected GBC intrinsic: " << static_cast<int>(intr_id);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003608 return NULL;
3609}
3610
3611} // anonymous namespace
3612
3613namespace art {
Shih-wei Liaob2596522012-09-14 16:36:11 -07003614
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003615namespace compiler_llvm {
3616
3617llvm::FunctionPass*
3618CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb) {
3619 return new GBCExpanderPass(intrinsic_helper, irb);
3620}
3621
Shih-wei Liaobb33f2f2012-08-23 13:20:00 -07003622llvm::FunctionPass*
3623CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb,
3624 Compiler* compiler, OatCompilationUnit* oat_compilation_unit) {
3625 if (compiler != NULL) {
3626 return new GBCExpanderPass(intrinsic_helper, irb,
3627 compiler, oat_compilation_unit);
3628 } else {
3629 return new GBCExpanderPass(intrinsic_helper, irb);
3630 }
3631}
3632
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003633} // namespace compiler_llvm
3634} // namespace art