blob: 412dbf76319eb0b176893d2419ac2a4cee81998b [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"
Shih-wei Liao21d28f52012-06-12 05:55:00 -070021#include "greenland/intrinsic_helper.h"
TDYa1275e869b62012-07-25 00:45:39 -070022#include "oat_compilation_unit.h"
Shih-wei Liao21d28f52012-06-12 05:55:00 -070023#include "object.h"
24#include "thread.h"
TDYa1275e869b62012-07-25 00:45:39 -070025#include "verifier/method_verifier.h"
Shih-wei Liao21d28f52012-06-12 05:55:00 -070026
27#include <llvm/ADT/STLExtras.h>
28#include <llvm/Intrinsics.h>
Logan Chiend36a2ac2012-08-04 00:37:30 +080029#include <llvm/Metadata.h>
Shih-wei Liao21d28f52012-06-12 05:55:00 -070030#include <llvm/Pass.h>
31#include <llvm/Support/CFG.h>
32#include <llvm/Support/InstIterator.h>
33
34#include <vector>
TDYa127aa558872012-08-16 05:11:07 -070035#include <map>
36#include <utility>
Shih-wei Liao21d28f52012-06-12 05:55:00 -070037
38using namespace art;
39using namespace compiler_llvm;
40
41using art::greenland::IntrinsicHelper;
42
43namespace {
44
45class GBCExpanderPass : public llvm::FunctionPass {
46 private:
47 const IntrinsicHelper& intrinsic_helper_;
48 IRBuilder& irb_;
49
50 llvm::LLVMContext& context_;
51 RuntimeSupportBuilder& rtb_;
52
53 private:
54 llvm::AllocaInst* shadow_frame_;
55 llvm::Value* old_shadow_frame_;
56 uint32_t shadow_frame_size_;
57
58 private:
TDYa1275e869b62012-07-25 00:45:39 -070059 Compiler* compiler_;
60
61 const DexFile* dex_file_;
62 DexCache* dex_cache_;
63 const DexFile::CodeItem* code_item_;
64
65 OatCompilationUnit* oat_compilation_unit_;
66
67 uint32_t method_idx_;
68
69 llvm::Function* func_;
70
71 std::vector<llvm::BasicBlock*> basic_blocks_;
72
73 std::vector<llvm::BasicBlock*> basic_block_landing_pads_;
TDYa127aa558872012-08-16 05:11:07 -070074 llvm::BasicBlock* old_basic_block_;
75 std::map<llvm::BasicBlock*, std::vector<std::pair<llvm::BasicBlock*, llvm::BasicBlock*> > >
76 landing_pad_phi_mapping_;
TDYa1275e869b62012-07-25 00:45:39 -070077 llvm::BasicBlock* basic_block_unwind_;
78
Logan Chien67645d82012-08-17 09:10:54 +080079 bool changed_;
80
TDYa1275e869b62012-07-25 00:45:39 -070081 private:
Shih-wei Liao21d28f52012-06-12 05:55:00 -070082 //----------------------------------------------------------------------------
Logan Chien75e4b602012-07-23 14:24:12 -070083 // Constant for GBC expansion
84 //----------------------------------------------------------------------------
85 enum IntegerShiftKind {
86 kIntegerSHL,
87 kIntegerSHR,
88 kIntegerUSHR,
89 };
90
91 private:
92 //----------------------------------------------------------------------------
Shih-wei Liao21d28f52012-06-12 05:55:00 -070093 // Helper function for GBC expansion
94 //----------------------------------------------------------------------------
95
Shih-wei Liao21d28f52012-06-12 05:55:00 -070096 llvm::Value* ExpandToRuntime(runtime_support::RuntimeId rt,
97 llvm::CallInst& inst);
98
TDYa1275e869b62012-07-25 00:45:39 -070099 uint64_t LV2UInt(llvm::Value* lv) {
100 return llvm::cast<llvm::ConstantInt>(lv)->getZExtValue();
101 }
102
103 int64_t LV2SInt(llvm::Value* lv) {
104 return llvm::cast<llvm::ConstantInt>(lv)->getSExtValue();
105 }
106
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700107 private:
108 // TODO: Almost all Emit* are directly copy-n-paste from MethodCompiler.
109 // Refactor these utility functions from MethodCompiler to avoid forking.
110
Logan Chien67645d82012-08-17 09:10:54 +0800111 void EmitStackOverflowCheck(llvm::Instruction* first_non_alloca);
112
113 void RewriteFunction();
114
115 void RewriteBasicBlock(llvm::BasicBlock* original_block);
116
117 void UpdatePhiInstruction(llvm::BasicBlock* old_basic_block,
118 llvm::BasicBlock* new_basic_block);
119
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700120
121 //----------------------------------------------------------------------------
122 // Dex cache code generation helper function
123 //----------------------------------------------------------------------------
124 llvm::Value* EmitLoadDexCacheAddr(MemberOffset dex_cache_offset);
125
126 llvm::Value* EmitLoadDexCacheStaticStorageFieldAddr(uint32_t type_idx);
127
128 llvm::Value* EmitLoadDexCacheResolvedTypeFieldAddr(uint32_t type_idx);
129
130 llvm::Value* EmitLoadDexCacheResolvedMethodFieldAddr(uint32_t method_idx);
131
132 llvm::Value* EmitLoadDexCacheStringFieldAddr(uint32_t string_idx);
133
134 //----------------------------------------------------------------------------
135 // Code generation helper function
136 //----------------------------------------------------------------------------
137 llvm::Value* EmitLoadMethodObjectAddr();
138
139 llvm::Value* EmitLoadArrayLength(llvm::Value* array);
140
141 llvm::Value* EmitLoadSDCalleeMethodObjectAddr(uint32_t callee_method_idx);
142
143 llvm::Value* EmitLoadVirtualCalleeMethodObjectAddr(int vtable_idx,
144 llvm::Value* this_addr);
145
146 llvm::Value* EmitArrayGEP(llvm::Value* array_addr,
147 llvm::Value* index_value,
148 JType elem_jty);
149
150 private:
151 //----------------------------------------------------------------------------
152 // Expand Greenland intrinsics
153 //----------------------------------------------------------------------------
154 void Expand_TestSuspend(llvm::CallInst& call_inst);
155
TDYa1279a129452012-07-19 03:10:08 -0700156 void Expand_MarkGCCard(llvm::CallInst& call_inst);
157
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700158 llvm::Value* Expand_GetException();
159
160 llvm::Value* Expand_LoadStringFromDexCache(llvm::Value* string_idx_value);
161
162 llvm::Value* Expand_LoadTypeFromDexCache(llvm::Value* type_idx_value);
163
164 void Expand_LockObject(llvm::Value* obj);
165
166 void Expand_UnlockObject(llvm::Value* obj);
167
168 llvm::Value* Expand_ArrayGet(llvm::Value* array_addr,
169 llvm::Value* index_value,
170 JType elem_jty);
171
172 void Expand_ArrayPut(llvm::Value* new_value,
173 llvm::Value* array_addr,
174 llvm::Value* index_value,
175 JType elem_jty);
176
177 void Expand_FilledNewArray(llvm::CallInst& call_inst);
178
179 llvm::Value* Expand_IGetFast(llvm::Value* field_offset_value,
180 llvm::Value* is_volatile_value,
181 llvm::Value* object_addr,
182 JType field_jty);
183
184 void Expand_IPutFast(llvm::Value* field_offset_value,
185 llvm::Value* is_volatile_value,
186 llvm::Value* object_addr,
187 llvm::Value* new_value,
188 JType field_jty);
189
190 llvm::Value* Expand_SGetFast(llvm::Value* static_storage_addr,
191 llvm::Value* field_offset_value,
192 llvm::Value* is_volatile_value,
193 JType field_jty);
194
195 void Expand_SPutFast(llvm::Value* static_storage_addr,
196 llvm::Value* field_offset_value,
197 llvm::Value* is_volatile_value,
198 llvm::Value* new_value,
199 JType field_jty);
200
201 llvm::Value* Expand_LoadDeclaringClassSSB(llvm::Value* method_object_addr);
202
203 llvm::Value* Expand_LoadClassSSBFromDexCache(llvm::Value* type_idx_value);
204
205 llvm::Value*
206 Expand_GetSDCalleeMethodObjAddrFast(llvm::Value* callee_method_idx_value);
207
208 llvm::Value*
209 Expand_GetVirtualCalleeMethodObjAddrFast(llvm::Value* vtable_idx_value,
210 llvm::Value* this_addr);
211
212 llvm::Value* Expand_Invoke(llvm::CallInst& call_inst);
213
TDYa1274ec8ccd2012-08-11 07:04:57 -0700214 llvm::Value* Expand_DivRem(llvm::CallInst& call_inst, bool is_div, JType op_jty);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700215
216 void Expand_AllocaShadowFrame(llvm::Value* num_entry_value);
217
218 void Expand_SetShadowFrameEntry(llvm::Value* obj, llvm::Value* entry_idx);
219
220 void Expand_PopShadowFrame();
221
222 void Expand_UpdateDexPC(llvm::Value* dex_pc_value);
223
TDYa127a1b21852012-07-23 03:20:39 -0700224 //----------------------------------------------------------------------------
225 // Quick
226 //----------------------------------------------------------------------------
227
228 llvm::Value* Expand_FPCompare(llvm::Value* src1_value,
229 llvm::Value* src2_value,
230 bool gt_bias);
231
232 llvm::Value* Expand_LongCompare(llvm::Value* src1_value, llvm::Value* src2_value);
233
234 llvm::Value* EmitCompareResultSelection(llvm::Value* cmp_eq,
235 llvm::Value* cmp_lt);
236
TDYa127f71bf5a2012-07-29 20:09:52 -0700237 llvm::Value* EmitLoadConstantClass(uint32_t dex_pc, uint32_t type_idx);
TDYa1275a26d442012-07-26 18:58:38 -0700238 llvm::Value* EmitLoadStaticStorage(uint32_t dex_pc, uint32_t type_idx);
239
TDYa1275e869b62012-07-25 00:45:39 -0700240 llvm::Value* Expand_HLIGet(llvm::CallInst& call_inst, JType field_jty);
241 void Expand_HLIPut(llvm::CallInst& call_inst, JType field_jty);
242
TDYa1275a26d442012-07-26 18:58:38 -0700243 llvm::Value* Expand_HLSget(llvm::CallInst& call_inst, JType field_jty);
244 void Expand_HLSput(llvm::CallInst& call_inst, JType field_jty);
245
246 llvm::Value* Expand_HLArrayGet(llvm::CallInst& call_inst, JType field_jty);
247 void Expand_HLArrayPut(llvm::CallInst& call_inst, JType field_jty);
248
TDYa127f71bf5a2012-07-29 20:09:52 -0700249 llvm::Value* Expand_ConstString(llvm::CallInst& call_inst);
250 llvm::Value* Expand_ConstClass(llvm::CallInst& call_inst);
251
252 void Expand_MonitorEnter(llvm::CallInst& call_inst);
253 void Expand_MonitorExit(llvm::CallInst& call_inst);
254
255 void Expand_HLCheckCast(llvm::CallInst& call_inst);
256 llvm::Value* Expand_InstanceOf(llvm::CallInst& call_inst);
257
258 llvm::Value* Expand_NewInstance(llvm::CallInst& call_inst);
259
260 llvm::Value* Expand_HLInvoke(llvm::CallInst& call_inst);
261
262 llvm::Value* Expand_OptArrayLength(llvm::CallInst& call_inst);
263 llvm::Value* Expand_NewArray(llvm::CallInst& call_inst);
264 llvm::Value* Expand_HLFilledNewArray(llvm::CallInst& call_inst);
265 void Expand_HLFillArrayData(llvm::CallInst& call_inst);
266
267 llvm::Value* EmitAllocNewArray(uint32_t dex_pc,
268 llvm::Value* array_length_value,
269 uint32_t type_idx,
270 bool is_filled_new_array);
271
272 llvm::Value* EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx,
273 InvokeType invoke_type,
274 llvm::Value* this_addr,
275 uint32_t dex_pc,
276 bool is_fast_path);
277
TDYa1275e869b62012-07-25 00:45:39 -0700278 void EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr);
279
280 void EmitUpdateDexPC(uint32_t dex_pc);
281
282 void EmitGuard_DivZeroException(uint32_t dex_pc,
283 llvm::Value* denominator,
284 JType op_jty);
285
286 void EmitGuard_NullPointerException(uint32_t dex_pc,
287 llvm::Value* object);
288
289 void EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc,
290 llvm::Value* array,
291 llvm::Value* index);
292
293 void EmitGuard_ArrayException(uint32_t dex_pc,
294 llvm::Value* array,
295 llvm::Value* index);
296
297 llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static);
298
299 llvm::BasicBlock* GetBasicBlock(uint32_t dex_pc);
300
301 llvm::BasicBlock* CreateBasicBlockWithDexPC(uint32_t dex_pc,
302 const char* postfix);
303
304 int32_t GetTryItemOffset(uint32_t dex_pc);
305
306 llvm::BasicBlock* GetLandingPadBasicBlock(uint32_t dex_pc);
307
308 llvm::BasicBlock* GetUnwindBasicBlock();
309
310 void EmitGuard_ExceptionLandingPad(uint32_t dex_pc);
311
312 void EmitBranchExceptionLandingPad(uint32_t dex_pc);
313
Logan Chien75e4b602012-07-23 14:24:12 -0700314 //----------------------------------------------------------------------------
315 // Expand Arithmetic Helper Intrinsics
316 //----------------------------------------------------------------------------
317
318 llvm::Value* Expand_IntegerShift(llvm::Value* src1_value,
319 llvm::Value* src2_value,
320 IntegerShiftKind kind,
321 JType op_jty);
322
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700323 public:
324 static char ID;
325
326 GBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb)
327 : llvm::FunctionPass(ID), intrinsic_helper_(intrinsic_helper), irb_(irb),
Logan Chiene5b8f8b2012-08-13 11:45:05 +0800328 context_(irb.getContext()), rtb_(irb.Runtime()),
329
330 // TODO: Initialize these fields correctly.
331 shadow_frame_(NULL), old_shadow_frame_(NULL), shadow_frame_size_(0),
332 compiler_(NULL), dex_file_(NULL), dex_cache_(NULL), code_item_(NULL),
Logan Chien67645d82012-08-17 09:10:54 +0800333 oat_compilation_unit_(NULL), method_idx_(-1u), func_(NULL),
334 changed_(false)
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700335 { }
336
337 bool runOnFunction(llvm::Function& func);
338
339 private:
Logan Chien67645d82012-08-17 09:10:54 +0800340 void InsertStackOverflowCheck(llvm::Function& func);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700341
342 llvm::Value* ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id,
343 llvm::CallInst& call_inst);
344
345};
346
347char GBCExpanderPass::ID = 0;
348
349bool GBCExpanderPass::runOnFunction(llvm::Function& func) {
TDYa127b672d1e2012-06-28 21:21:45 -0700350 // Runtime support or stub
351 if (func.getName().startswith("art_") || func.getName().startswith("Art")) {
352 return false;
353 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700354
Logan Chien67645d82012-08-17 09:10:54 +0800355 // Setup rewrite context
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700356 shadow_frame_ = NULL;
357 old_shadow_frame_ = NULL;
358 shadow_frame_size_ = 0;
TDYa1275e869b62012-07-25 00:45:39 -0700359 func_ = &func;
Logan Chien67645d82012-08-17 09:10:54 +0800360 changed_ = false; // Assume unchanged
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700361
Logan Chien67645d82012-08-17 09:10:54 +0800362 // Insert stack overflow check
363 InsertStackOverflowCheck(func); // TODO: Use intrinsic.
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700364
Logan Chien67645d82012-08-17 09:10:54 +0800365 // Rewrite the intrinsics
366 RewriteFunction();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700367
368 VERIFY_LLVM_FUNCTION(func);
369
Logan Chien67645d82012-08-17 09:10:54 +0800370 return changed_;
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700371}
372
Logan Chien67645d82012-08-17 09:10:54 +0800373void GBCExpanderPass::RewriteBasicBlock(llvm::BasicBlock* original_block) {
374 llvm::BasicBlock* curr_basic_block = original_block;
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700375
Logan Chien67645d82012-08-17 09:10:54 +0800376 llvm::BasicBlock::iterator inst_iter = original_block->begin();
377 llvm::BasicBlock::iterator inst_end = original_block->end();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700378
Logan Chien67645d82012-08-17 09:10:54 +0800379 while (inst_iter != inst_end) {
380 llvm::CallInst* call_inst = llvm::dyn_cast<llvm::CallInst>(inst_iter);
381 IntrinsicHelper::IntrinsicId intr_id = IntrinsicHelper::UnknownId;
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700382
Logan Chien67645d82012-08-17 09:10:54 +0800383 if (call_inst) {
384 llvm::Function* callee_func = call_inst->getCalledFunction();
385 intr_id = intrinsic_helper_.GetIntrinsicId(callee_func);
386 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700387
Logan Chien67645d82012-08-17 09:10:54 +0800388 if (intr_id == IntrinsicHelper::UnknownId) {
389 // This is not intrinsic call. Skip this instruction.
390 ++inst_iter;
391 continue;
392 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700393
Logan Chien67645d82012-08-17 09:10:54 +0800394 // Rewrite the intrinsic and change the function
395 changed_ = true;
396 irb_.SetInsertPoint(inst_iter);
397
398 // Expand the intrinsic
399 if (llvm::Value* new_value = ExpandIntrinsic(intr_id, *call_inst)) {
400 inst_iter->replaceAllUsesWith(new_value);
401 }
402
403 // Remove the old intrinsic call instruction
404 llvm::BasicBlock::iterator old_inst = inst_iter++;
405 old_inst->eraseFromParent();
406
407 // Splice the instruction to the new basic block
408 llvm::BasicBlock* next_basic_block = irb_.GetInsertBlock();
409 if (next_basic_block != curr_basic_block) {
410 next_basic_block->getInstList().splice(
411 irb_.GetInsertPoint(), curr_basic_block->getInstList(),
412 inst_iter, inst_end);
413 curr_basic_block = next_basic_block;
414 inst_end = curr_basic_block->end();
415 }
416 }
417}
418
419
420void GBCExpanderPass::RewriteFunction() {
421 size_t num_basic_blocks = func_->getBasicBlockList().size();
422 // NOTE: We are not using (bb_iter != bb_end) as the for-loop condition,
423 // because we will create new basic block while expanding the intrinsics.
424 // We only want to iterate through the input basic blocks.
425
TDYa127aa558872012-08-16 05:11:07 -0700426 landing_pad_phi_mapping_.clear();
427
Logan Chien67645d82012-08-17 09:10:54 +0800428 for (llvm::Function::iterator bb_iter = func_->begin();
429 num_basic_blocks > 0; ++bb_iter, --num_basic_blocks) {
Shih-wei Liao627d8c42012-08-24 08:31:18 -0700430 // Set insert point to current basic block.
431 irb_.SetInsertPoint(bb_iter);
Logan Chien67645d82012-08-17 09:10:54 +0800432
TDYa127aa558872012-08-16 05:11:07 -0700433 old_basic_block_ = bb_iter;
434
Logan Chien67645d82012-08-17 09:10:54 +0800435 // Rewrite the basic block
436 RewriteBasicBlock(bb_iter);
437
438 // Update the phi-instructions in the successor basic block
439 llvm::BasicBlock* last_block = irb_.GetInsertBlock();
440 if (last_block != bb_iter) {
441 UpdatePhiInstruction(bb_iter, last_block);
442 }
443 }
TDYa127aa558872012-08-16 05:11:07 -0700444
445 typedef std::map<llvm::PHINode*, llvm::PHINode*> HandlerPHIMap;
446 HandlerPHIMap handler_phi;
447 // Iterate every used landing pad basic block
448 for (size_t i = 0, ei = basic_block_landing_pads_.size(); i != ei; ++i) {
449 llvm::BasicBlock* lbb = basic_block_landing_pads_[i];
450 if (lbb == NULL) {
451 continue;
452 }
453
454 llvm::TerminatorInst* term_inst = lbb->getTerminator();
455 std::vector<std::pair<llvm::BasicBlock*, llvm::BasicBlock*> >& rewrite_pair
456 = landing_pad_phi_mapping_[lbb];
457 irb_.SetInsertPoint(lbb->begin());
458
459 // Iterate every succeeding basic block (catch block)
460 for (unsigned succ_iter = 0, succ_end = term_inst->getNumSuccessors();
461 succ_iter != succ_end; ++succ_iter) {
462 llvm::BasicBlock* succ_basic_block = term_inst->getSuccessor(succ_iter);
463
464 // Iterate every phi instructions in the succeeding basic block
465 for (llvm::BasicBlock::iterator
466 inst_iter = succ_basic_block->begin(),
467 inst_end = succ_basic_block->end();
468 inst_iter != inst_end; ++inst_iter) {
469 llvm::PHINode *phi = llvm::dyn_cast<llvm::PHINode>(inst_iter);
470
471 if (!phi) {
472 break; // Meet non-phi instruction. Done.
473 }
474
475 if (handler_phi[phi] == NULL) {
476 handler_phi[phi] = llvm::PHINode::Create(phi->getType(), 1);
477 }
478
479 // Create new_phi in landing pad
480 llvm::PHINode* new_phi = irb_.CreatePHI(phi->getType(), rewrite_pair.size());
481 // Insert all incoming value into new_phi by rewrite_pair
482 for (size_t j = 0, ej = rewrite_pair.size(); j != ej; ++j) {
483 llvm::BasicBlock* old_bb = rewrite_pair[j].first;
484 llvm::BasicBlock* new_bb = rewrite_pair[j].second;
485 new_phi->addIncoming(phi->getIncomingValueForBlock(old_bb), new_bb);
486 }
487 // Delete all incoming value from phi by rewrite_pair
488 for (size_t j = 0, ej = rewrite_pair.size(); j != ej; ++j) {
489 llvm::BasicBlock* old_bb = rewrite_pair[j].first;
490 int old_bb_idx = phi->getBasicBlockIndex(old_bb);
491 if (old_bb_idx >= 0) {
492 phi->removeIncomingValue(old_bb_idx, false);
493 }
494 }
495 // Insert new_phi into new handler phi
496 handler_phi[phi]->addIncoming(new_phi, lbb);
497 }
498 }
499 }
500
501 // Replace all handler phi
502 // We can't just use the old handler phi, because some exception edges will disappear after we
503 // compute fast-path.
504 for (HandlerPHIMap::iterator it = handler_phi.begin(); it != handler_phi.end(); ++it) {
505 llvm::PHINode* old_phi = it->first;
506 llvm::PHINode* new_phi = it->second;
507 new_phi->insertBefore(old_phi);
508 old_phi->replaceAllUsesWith(new_phi);
509 old_phi->eraseFromParent();
510 }
Logan Chien67645d82012-08-17 09:10:54 +0800511}
512
513void GBCExpanderPass::UpdatePhiInstruction(llvm::BasicBlock* old_basic_block,
514 llvm::BasicBlock* new_basic_block) {
515 llvm::TerminatorInst* term_inst = new_basic_block->getTerminator();
516
517 if (!term_inst) {
518 return; // No terminating instruction in new_basic_block. Nothing to do.
519 }
520
521 // Iterate every succeeding basic block
522 for (unsigned succ_iter = 0, succ_end = term_inst->getNumSuccessors();
523 succ_iter != succ_end; ++succ_iter) {
524 llvm::BasicBlock* succ_basic_block = term_inst->getSuccessor(succ_iter);
525
526 // Iterate every phi instructions in the succeeding basic block
527 for (llvm::BasicBlock::iterator
528 inst_iter = succ_basic_block->begin(),
529 inst_end = succ_basic_block->end();
530 inst_iter != inst_end; ++inst_iter) {
531 llvm::PHINode *phi = llvm::dyn_cast<llvm::PHINode>(inst_iter);
532
533 if (!phi) {
534 break; // Meet non-phi instruction. Done.
535 }
536
537 // Update the incoming block of this phi instruction
538 for (llvm::PHINode::block_iterator
539 ibb_iter = phi->block_begin(), ibb_end = phi->block_end();
540 ibb_iter != ibb_end; ++ibb_iter) {
541 if (*ibb_iter == old_basic_block) {
542 *ibb_iter = new_basic_block;
543 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700544 }
545 }
546 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700547}
548
549llvm::Value* GBCExpanderPass::ExpandToRuntime(runtime_support::RuntimeId rt,
550 llvm::CallInst& inst) {
551 // Some GBC intrinsic can directly replace with IBC runtime. "Directly" means
552 // the arguments passed to the GBC intrinsic are as the same as IBC runtime
553 // function, therefore only called function is needed to change.
554 unsigned num_args = inst.getNumArgOperands();
555
556 if (num_args <= 0) {
557 return irb_.CreateCall(irb_.GetRuntime(rt));
558 } else {
559 std::vector<llvm::Value*> args;
560 for (unsigned i = 0; i < num_args; i++) {
561 args.push_back(inst.getArgOperand(i));
562 }
563
564 return irb_.CreateCall(irb_.GetRuntime(rt), args);
565 }
566}
567
Logan Chien67645d82012-08-17 09:10:54 +0800568void
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700569GBCExpanderPass::EmitStackOverflowCheck(llvm::Instruction* first_non_alloca) {
570 llvm::Function* func = first_non_alloca->getParent()->getParent();
571 llvm::Module* module = func->getParent();
572
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700573 // Call llvm intrinsic function to get frame address.
574 llvm::Function* frameaddress =
575 llvm::Intrinsic::getDeclaration(module, llvm::Intrinsic::frameaddress);
576
577 // The type of llvm::frameaddress is: i8* @llvm.frameaddress(i32)
578 llvm::Value* frame_address = irb_.CreateCall(frameaddress, irb_.getInt32(0));
579
580 // Cast i8* to int
581 frame_address = irb_.CreatePtrToInt(frame_address, irb_.getPtrEquivIntTy());
582
583 // Get thread.stack_end_
584 llvm::Value* stack_end =
585 irb_.Runtime().EmitLoadFromThreadOffset(Thread::StackEndOffset().Int32Value(),
586 irb_.getPtrEquivIntTy(),
587 kTBAARuntimeInfo);
588
589 // Check the frame address < thread.stack_end_ ?
590 llvm::Value* is_stack_overflow = irb_.CreateICmpULT(frame_address, stack_end);
591
592 llvm::BasicBlock* block_exception =
593 llvm::BasicBlock::Create(context_, "stack_overflow", func);
594
595 llvm::BasicBlock* block_continue =
596 llvm::BasicBlock::Create(context_, "stack_overflow_cont", func);
597
598 irb_.CreateCondBr(is_stack_overflow, block_exception, block_continue, kUnlikely);
599
600 // If stack overflow, throw exception.
601 irb_.SetInsertPoint(block_exception);
602 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowStackOverflowException));
603
604 // Unwind.
605 llvm::Type* ret_type = func->getReturnType();
606 if (ret_type->isVoidTy()) {
607 irb_.CreateRetVoid();
608 } else {
609 // The return value is ignored when there's an exception. MethodCompiler
610 // returns zero value under the the corresponding return type in this case.
611 // GBCExpander returns LLVM undef value here for brevity
612 irb_.CreateRet(llvm::UndefValue::get(ret_type));
613 }
614
615 irb_.SetInsertPoint(block_continue);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700616}
617
618llvm::Value* GBCExpanderPass::EmitLoadDexCacheAddr(MemberOffset offset) {
619 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
620
621 return irb_.LoadFromObjectOffset(method_object_addr,
622 offset.Int32Value(),
623 irb_.getJObjectTy(),
624 kTBAAConstJObject);
625}
626
627llvm::Value*
628GBCExpanderPass::EmitLoadDexCacheStaticStorageFieldAddr(uint32_t type_idx) {
629 llvm::Value* static_storage_dex_cache_addr =
630 EmitLoadDexCacheAddr(Method::DexCacheInitializedStaticStorageOffset());
631
632 llvm::Value* type_idx_value = irb_.getPtrEquivInt(type_idx);
633
634 return EmitArrayGEP(static_storage_dex_cache_addr, type_idx_value, kObject);
635}
636
637llvm::Value*
638GBCExpanderPass::EmitLoadDexCacheResolvedTypeFieldAddr(uint32_t type_idx) {
639 llvm::Value* resolved_type_dex_cache_addr =
640 EmitLoadDexCacheAddr(Method::DexCacheResolvedTypesOffset());
641
642 llvm::Value* type_idx_value = irb_.getPtrEquivInt(type_idx);
643
644 return EmitArrayGEP(resolved_type_dex_cache_addr, type_idx_value, kObject);
645}
646
647llvm::Value* GBCExpanderPass::
648EmitLoadDexCacheResolvedMethodFieldAddr(uint32_t method_idx) {
649 llvm::Value* resolved_method_dex_cache_addr =
650 EmitLoadDexCacheAddr(Method::DexCacheResolvedMethodsOffset());
651
652 llvm::Value* method_idx_value = irb_.getPtrEquivInt(method_idx);
653
654 return EmitArrayGEP(resolved_method_dex_cache_addr, method_idx_value, kObject);
655}
656
657llvm::Value* GBCExpanderPass::
658EmitLoadDexCacheStringFieldAddr(uint32_t string_idx) {
659 llvm::Value* string_dex_cache_addr =
660 EmitLoadDexCacheAddr(Method::DexCacheStringsOffset());
661
662 llvm::Value* string_idx_value = irb_.getPtrEquivInt(string_idx);
663
664 return EmitArrayGEP(string_dex_cache_addr, string_idx_value, kObject);
665}
666
667llvm::Value* GBCExpanderPass::EmitLoadMethodObjectAddr() {
668 llvm::Function* parent_func = irb_.GetInsertBlock()->getParent();
669 return parent_func->arg_begin();
670}
671
672llvm::Value* GBCExpanderPass::EmitLoadArrayLength(llvm::Value* array) {
673 // Load array length
674 return irb_.LoadFromObjectOffset(array,
675 Array::LengthOffset().Int32Value(),
676 irb_.getJIntTy(),
677 kTBAAConstJObject);
678
679}
680
681llvm::Value*
682GBCExpanderPass::EmitLoadSDCalleeMethodObjectAddr(uint32_t callee_method_idx) {
683 llvm::Value* callee_method_object_field_addr =
684 EmitLoadDexCacheResolvedMethodFieldAddr(callee_method_idx);
685
686 return irb_.CreateLoad(callee_method_object_field_addr, kTBAAJRuntime);
687}
688
689llvm::Value* GBCExpanderPass::
690EmitLoadVirtualCalleeMethodObjectAddr(int vtable_idx, llvm::Value* this_addr) {
691 // Load class object of *this* pointer
692 llvm::Value* class_object_addr =
693 irb_.LoadFromObjectOffset(this_addr,
694 Object::ClassOffset().Int32Value(),
695 irb_.getJObjectTy(),
696 kTBAAConstJObject);
697
698 // Load vtable address
699 llvm::Value* vtable_addr =
700 irb_.LoadFromObjectOffset(class_object_addr,
701 Class::VTableOffset().Int32Value(),
702 irb_.getJObjectTy(),
703 kTBAAConstJObject);
704
705 // Load callee method object
706 llvm::Value* vtable_idx_value =
707 irb_.getPtrEquivInt(static_cast<uint64_t>(vtable_idx));
708
709 llvm::Value* method_field_addr =
710 EmitArrayGEP(vtable_addr, vtable_idx_value, kObject);
711
712 return irb_.CreateLoad(method_field_addr, kTBAAConstJObject);
713}
714
715// Emit Array GetElementPtr
716llvm::Value* GBCExpanderPass::EmitArrayGEP(llvm::Value* array_addr,
717 llvm::Value* index_value,
718 JType elem_jty) {
719
720 int data_offset;
721 if (elem_jty == kLong || elem_jty == kDouble ||
722 (elem_jty == kObject && sizeof(uint64_t) == sizeof(Object*))) {
723 data_offset = Array::DataOffset(sizeof(int64_t)).Int32Value();
724 } else {
725 data_offset = Array::DataOffset(sizeof(int32_t)).Int32Value();
726 }
727
728 llvm::Constant* data_offset_value =
729 irb_.getPtrEquivInt(data_offset);
730
731 llvm::Type* elem_type = irb_.getJType(elem_jty, kArray);
732
733 llvm::Value* array_data_addr =
734 irb_.CreatePtrDisp(array_addr, data_offset_value,
735 elem_type->getPointerTo());
736
737 return irb_.CreateGEP(array_data_addr, index_value);
738}
739
740void GBCExpanderPass::Expand_TestSuspend(llvm::CallInst& call_inst) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700741 irb_.Runtime().EmitTestSuspend();
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700742 return;
743}
744
TDYa1279a129452012-07-19 03:10:08 -0700745void GBCExpanderPass::Expand_MarkGCCard(llvm::CallInst& call_inst) {
TDYa1279a129452012-07-19 03:10:08 -0700746 irb_.Runtime().EmitMarkGCCard(call_inst.getArgOperand(0), call_inst.getArgOperand(1));
TDYa1279a129452012-07-19 03:10:08 -0700747 return;
748}
749
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700750llvm::Value* GBCExpanderPass::Expand_GetException() {
751 // Get thread-local exception field address
752 llvm::Value* exception_object_addr =
753 irb_.Runtime().EmitLoadFromThreadOffset(Thread::ExceptionOffset().Int32Value(),
754 irb_.getJObjectTy(),
755 kTBAAJRuntime);
756
757 // Set thread-local exception field address to NULL
758 irb_.Runtime().EmitStoreToThreadOffset(Thread::ExceptionOffset().Int32Value(),
759 irb_.getJNull(),
760 kTBAAJRuntime);
761
762 return exception_object_addr;
763}
764
765llvm::Value*
766GBCExpanderPass::Expand_LoadStringFromDexCache(llvm::Value* string_idx_value) {
767 uint32_t string_idx =
768 llvm::cast<llvm::ConstantInt>(string_idx_value)->getZExtValue();
769
770 llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx);
771
772 return irb_.CreateLoad(string_field_addr, kTBAAJRuntime);
773}
774
775llvm::Value*
776GBCExpanderPass::Expand_LoadTypeFromDexCache(llvm::Value* type_idx_value) {
777 uint32_t type_idx =
778 llvm::cast<llvm::ConstantInt>(type_idx_value)->getZExtValue();
779
780 llvm::Value* type_field_addr =
781 EmitLoadDexCacheResolvedTypeFieldAddr(type_idx);
782
783 return irb_.CreateLoad(type_field_addr, kTBAAJRuntime);
784}
785
786void GBCExpanderPass::Expand_LockObject(llvm::Value* obj) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700787 rtb_.EmitLockObject(obj);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700788 return;
789}
790
791void GBCExpanderPass::Expand_UnlockObject(llvm::Value* obj) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700792 rtb_.EmitUnlockObject(obj);
Shih-wei Liao21d28f52012-06-12 05:55:00 -0700793 return;
794}
795
796llvm::Value* GBCExpanderPass::Expand_ArrayGet(llvm::Value* array_addr,
797 llvm::Value* index_value,
798 JType elem_jty) {
799 llvm::Value* array_elem_addr =
800 EmitArrayGEP(array_addr, index_value, elem_jty);
801
802 return irb_.CreateLoad(array_elem_addr, kTBAAHeapArray, elem_jty);
803}
804
805void GBCExpanderPass::Expand_ArrayPut(llvm::Value* new_value,
806 llvm::Value* array_addr,
807 llvm::Value* index_value,
808 JType elem_jty) {
809 llvm::Value* array_elem_addr =
810 EmitArrayGEP(array_addr, index_value, elem_jty);
811
812 irb_.CreateStore(new_value, array_elem_addr, kTBAAHeapArray, elem_jty);
813
814 return;
815}
816
817void GBCExpanderPass::Expand_FilledNewArray(llvm::CallInst& call_inst) {
818 // Most of the codes refer to MethodCompiler::EmitInsn_FilledNewArray
819 llvm::Value* array = call_inst.getArgOperand(0);
820
821 uint32_t element_jty =
822 llvm::cast<llvm::ConstantInt>(call_inst.getArgOperand(1))->getZExtValue();
823
824 DCHECK(call_inst.getNumArgOperands() > 2);
825 unsigned num_elements = (call_inst.getNumArgOperands() - 2);
826
827 bool is_elem_int_ty = (static_cast<JType>(element_jty) == kInt);
828
829 uint32_t alignment;
830 llvm::Constant* elem_size;
831 llvm::PointerType* field_type;
832
833 // NOTE: Currently filled-new-array only supports 'L', '[', and 'I'
834 // as the element, thus we are only checking 2 cases: primitive int and
835 // non-primitive type.
836 if (is_elem_int_ty) {
837 alignment = sizeof(int32_t);
838 elem_size = irb_.getPtrEquivInt(sizeof(int32_t));
839 field_type = irb_.getJIntTy()->getPointerTo();
840 } else {
841 alignment = irb_.getSizeOfPtrEquivInt();
842 elem_size = irb_.getSizeOfPtrEquivIntValue();
843 field_type = irb_.getJObjectTy()->getPointerTo();
844 }
845
846 llvm::Value* data_field_offset =
847 irb_.getPtrEquivInt(Array::DataOffset(alignment).Int32Value());
848
849 llvm::Value* data_field_addr =
850 irb_.CreatePtrDisp(array, data_field_offset, field_type);
851
852 for (unsigned i = 0; i < num_elements; ++i) {
853 // Values to fill the array begin at the 3rd argument
854 llvm::Value* reg_value = call_inst.getArgOperand(2 + i);
855
856 irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray);
857
858 data_field_addr =
859 irb_.CreatePtrDisp(data_field_addr, elem_size, field_type);
860 }
861
862 return;
863}
864
865llvm::Value* GBCExpanderPass::Expand_IGetFast(llvm::Value* field_offset_value,
866 llvm::Value* /*is_volatile_value*/,
867 llvm::Value* object_addr,
868 JType field_jty) {
869 int field_offset =
870 llvm::cast<llvm::ConstantInt>(field_offset_value)->getSExtValue();
871
872 DCHECK_GE(field_offset, 0);
873
874 llvm::PointerType* field_type =
875 irb_.getJType(field_jty, kField)->getPointerTo();
876
877 field_offset_value = irb_.getPtrEquivInt(field_offset);
878
879 llvm::Value* field_addr =
880 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
881
882 // TODO: Check is_volatile. We need to generate atomic load instruction
883 // when is_volatile is true.
884 return irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty);
885}
886
887void GBCExpanderPass::Expand_IPutFast(llvm::Value* field_offset_value,
888 llvm::Value* /* is_volatile_value */,
889 llvm::Value* object_addr,
890 llvm::Value* new_value,
891 JType field_jty) {
892 int field_offset =
893 llvm::cast<llvm::ConstantInt>(field_offset_value)->getSExtValue();
894
895 DCHECK_GE(field_offset, 0);
896
897 llvm::PointerType* field_type =
898 irb_.getJType(field_jty, kField)->getPointerTo();
899
900 field_offset_value = irb_.getPtrEquivInt(field_offset);
901
902 llvm::Value* field_addr =
903 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
904
905 // TODO: Check is_volatile. We need to generate atomic store instruction
906 // when is_volatile is true.
907 irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty);
908
909 return;
910}
911
912llvm::Value* GBCExpanderPass::Expand_SGetFast(llvm::Value* static_storage_addr,
913 llvm::Value* field_offset_value,
914 llvm::Value* /*is_volatile_value*/,
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::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
922
923 llvm::Value* static_field_addr =
924 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
925 irb_.getJType(field_jty, kField)->getPointerTo());
926
927 // TODO: Check is_volatile. We need to generate atomic store instruction
928 // when is_volatile is true.
929 return irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty);
930}
931
932void GBCExpanderPass::Expand_SPutFast(llvm::Value* static_storage_addr,
933 llvm::Value* field_offset_value,
934 llvm::Value* /* is_volatile_value */,
935 llvm::Value* new_value,
936 JType field_jty) {
937 int field_offset =
938 llvm::cast<llvm::ConstantInt>(field_offset_value)->getSExtValue();
939
940 DCHECK_GE(field_offset, 0);
941
942 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
943
944 llvm::Value* static_field_addr =
945 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
946 irb_.getJType(field_jty, kField)->getPointerTo());
947
948 // TODO: Check is_volatile. We need to generate atomic store instruction
949 // when is_volatile is true.
950 irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty);
951
952 return;
953}
954
955llvm::Value*
956GBCExpanderPass::Expand_LoadDeclaringClassSSB(llvm::Value* method_object_addr) {
957 return irb_.LoadFromObjectOffset(method_object_addr,
958 Method::DeclaringClassOffset().Int32Value(),
959 irb_.getJObjectTy(),
960 kTBAAConstJObject);
961}
962
963llvm::Value*
964GBCExpanderPass::Expand_LoadClassSSBFromDexCache(llvm::Value* type_idx_value) {
965 uint32_t type_idx =
966 llvm::cast<llvm::ConstantInt>(type_idx_value)->getZExtValue();
967
968 llvm::Value* storage_field_addr =
969 EmitLoadDexCacheStaticStorageFieldAddr(type_idx);
970
971 return irb_.CreateLoad(storage_field_addr, kTBAAJRuntime);
972}
973
974llvm::Value*
975GBCExpanderPass::Expand_GetSDCalleeMethodObjAddrFast(llvm::Value* callee_method_idx_value) {
976 uint32_t callee_method_idx =
977 llvm::cast<llvm::ConstantInt>(callee_method_idx_value)->getZExtValue();
978
979 return EmitLoadSDCalleeMethodObjectAddr(callee_method_idx);
980}
981
982llvm::Value* GBCExpanderPass::Expand_GetVirtualCalleeMethodObjAddrFast(
983 llvm::Value* vtable_idx_value,
984 llvm::Value* this_addr) {
985 int vtable_idx =
986 llvm::cast<llvm::ConstantInt>(vtable_idx_value)->getSExtValue();
987
988 return EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr);
989}
990
991llvm::Value* GBCExpanderPass::Expand_Invoke(llvm::CallInst& call_inst) {
992 // Most of the codes refer to MethodCompiler::EmitInsn_Invoke
993 llvm::Value* callee_method_object_addr = call_inst.getArgOperand(0);
994 unsigned num_args = call_inst.getNumArgOperands();
995 llvm::Type* ret_type = call_inst.getType();
996
997 // Determine the function type of the callee method
998 std::vector<llvm::Type*> args_type;
999 std::vector<llvm::Value*> args;
1000 for (unsigned i = 0; i < num_args; i++) {
1001 args.push_back(call_inst.getArgOperand(i));
1002 args_type.push_back(args[i]->getType());
1003 }
1004
1005 llvm::FunctionType* callee_method_type =
1006 llvm::FunctionType::get(ret_type, args_type, false);
1007
1008 llvm::Value* code_addr =
1009 irb_.LoadFromObjectOffset(callee_method_object_addr,
1010 Method::GetCodeOffset().Int32Value(),
1011 callee_method_type->getPointerTo(),
1012 kTBAAJRuntime);
1013
1014 // Invoke callee
1015 llvm::Value* retval = irb_.CreateCall(code_addr, args);
1016
1017 return retval;
1018}
1019
TDYa1274ec8ccd2012-08-11 07:04:57 -07001020llvm::Value* GBCExpanderPass::Expand_DivRem(llvm::CallInst& call_inst,
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001021 bool is_div, JType op_jty) {
TDYa1274ec8ccd2012-08-11 07:04:57 -07001022 llvm::Value* dividend = call_inst.getArgOperand(0);
1023 llvm::Value* divisor = call_inst.getArgOperand(1);
1024#if defined(ART_USE_QUICK_COMPILER)
1025 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1026 EmitGuard_DivZeroException(dex_pc, divisor, op_jty);
1027#endif
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001028 // Most of the codes refer to MethodCompiler::EmitIntDivRemResultComputation
1029
1030 // Check the special case: MININT / -1 = MININT
1031 // That case will cause overflow, which is undefined behavior in llvm.
1032 // So we check the divisor is -1 or not, if the divisor is -1, we do
1033 // the special path to avoid undefined behavior.
1034 llvm::Type* op_type = irb_.getJType(op_jty, kAccurate);
1035 llvm::Value* zero = irb_.getJZero(op_jty);
1036 llvm::Value* neg_one = llvm::ConstantInt::getSigned(op_type, -1);
1037
TDYa1275e869b62012-07-25 00:45:39 -07001038 llvm::Function* parent = irb_.GetInsertBlock()->getParent();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001039 llvm::BasicBlock* eq_neg_one = llvm::BasicBlock::Create(context_, "", parent);
1040 llvm::BasicBlock* ne_neg_one = llvm::BasicBlock::Create(context_, "", parent);
1041 llvm::BasicBlock* neg_one_cont =
1042 llvm::BasicBlock::Create(context_, "", parent);
1043
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001044 llvm::Value* is_equal_neg_one = irb_.CreateICmpEQ(divisor, neg_one);
1045 irb_.CreateCondBr(is_equal_neg_one, eq_neg_one, ne_neg_one, kUnlikely);
1046
1047 // If divisor == -1
1048 irb_.SetInsertPoint(eq_neg_one);
1049 llvm::Value* eq_result;
1050 if (is_div) {
1051 // We can just change from "dividend div -1" to "neg dividend". The sub
1052 // don't care the sign/unsigned because of two's complement representation.
1053 // And the behavior is what we want:
1054 // -(2^n) (2^n)-1
1055 // MININT < k <= MAXINT -> mul k -1 = -k
1056 // MININT == k -> mul k -1 = k
1057 //
1058 // LLVM use sub to represent 'neg'
1059 eq_result = irb_.CreateSub(zero, dividend);
1060 } else {
1061 // Everything modulo -1 will be 0.
1062 eq_result = zero;
1063 }
1064 irb_.CreateBr(neg_one_cont);
1065
1066 // If divisor != -1, just do the division.
1067 irb_.SetInsertPoint(ne_neg_one);
1068 llvm::Value* ne_result;
1069 if (is_div) {
1070 ne_result = irb_.CreateSDiv(dividend, divisor);
1071 } else {
1072 ne_result = irb_.CreateSRem(dividend, divisor);
1073 }
1074 irb_.CreateBr(neg_one_cont);
1075
1076 irb_.SetInsertPoint(neg_one_cont);
1077 llvm::PHINode* result = irb_.CreatePHI(op_type, 2);
1078 result->addIncoming(eq_result, eq_neg_one);
1079 result->addIncoming(ne_result, ne_neg_one);
1080
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001081 return result;
1082}
1083
1084void GBCExpanderPass::Expand_AllocaShadowFrame(llvm::Value* num_entry_value) {
1085 // Most of the codes refer to MethodCompiler::EmitPrologueAllocShadowFrame and
1086 // MethodCompiler::EmitPushShadowFrame
1087 shadow_frame_size_ =
1088 llvm::cast<llvm::ConstantInt>(num_entry_value)->getZExtValue();
1089
1090 llvm::StructType* shadow_frame_type =
1091 irb_.getShadowFrameTy(shadow_frame_size_);
1092
1093 shadow_frame_ = irb_.CreateAlloca(shadow_frame_type);
1094
1095 // Alloca a pointer to old shadow frame
1096 old_shadow_frame_ =
1097 irb_.CreateAlloca(shadow_frame_type->getElementType(0)->getPointerTo());
1098
1099 // Zero-initialization of the shadow frame table
1100 llvm::Value* shadow_frame_table =
1101 irb_.CreateConstGEP2_32(shadow_frame_, 0, 1);
1102 llvm::Type* table_type = shadow_frame_type->getElementType(1);
1103
1104 llvm::ConstantAggregateZero* zero_initializer =
1105 llvm::ConstantAggregateZero::get(table_type);
1106
1107 irb_.CreateStore(zero_initializer, shadow_frame_table, kTBAAShadowFrame);
1108
1109 // Push the shadow frame
1110 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1111
1112 // Push the shadow frame
1113 llvm::Value* shadow_frame_upcast =
1114 irb_.CreateConstGEP2_32(shadow_frame_, 0, 0);
1115
1116 llvm::Value* result = rtb_.EmitPushShadowFrame(shadow_frame_upcast,
1117 method_object_addr,
1118 shadow_frame_size_);
1119
1120 irb_.CreateStore(result, old_shadow_frame_, kTBAARegister);
1121
1122 return;
1123}
1124
1125void GBCExpanderPass::Expand_SetShadowFrameEntry(llvm::Value* obj,
1126 llvm::Value* entry_idx) {
1127 DCHECK(shadow_frame_ != NULL);
1128
1129 llvm::Value* gep_index[] = {
1130 irb_.getInt32(0), // No pointer displacement
1131 irb_.getInt32(1), // SIRT
1132 entry_idx // Pointer field
1133 };
1134
1135 llvm::Value* entry_addr = irb_.CreateGEP(shadow_frame_, gep_index);
1136 irb_.CreateStore(obj, entry_addr, kTBAAShadowFrame);
1137 return;
1138}
1139
1140void GBCExpanderPass::Expand_PopShadowFrame() {
1141 rtb_.EmitPopShadowFrame(irb_.CreateLoad(old_shadow_frame_, kTBAARegister));
1142 return;
1143}
1144
1145void GBCExpanderPass::Expand_UpdateDexPC(llvm::Value* dex_pc_value) {
1146 irb_.StoreToObjectOffset(shadow_frame_,
1147 ShadowFrame::DexPCOffset(),
1148 dex_pc_value,
1149 kTBAAShadowFrame);
1150 return;
1151}
1152
Logan Chien67645d82012-08-17 09:10:54 +08001153void GBCExpanderPass::InsertStackOverflowCheck(llvm::Function& func) {
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001154 // DexLang generates all alloca instruction in the first basic block of the
1155 // FUNC and also there's no any alloca instructions after the first non-alloca
1156 // instruction
1157
Logan Chien67645d82012-08-17 09:10:54 +08001158 llvm::BasicBlock* first_basic_block = &func.front();
1159
1160 // Look for first non-alloca instruction
1161 llvm::BasicBlock::iterator first_non_alloca = first_basic_block->begin();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001162 while (llvm::isa<llvm::AllocaInst>(first_non_alloca)) {
1163 ++first_non_alloca;
1164 }
1165
Logan Chien67645d82012-08-17 09:10:54 +08001166 irb_.SetInsertPoint(first_non_alloca);
1167
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001168 // Insert stack overflow check codes before first_non_alloca (i.e., after all
1169 // alloca instructions)
Logan Chien67645d82012-08-17 09:10:54 +08001170 EmitStackOverflowCheck(&*first_non_alloca);
1171
1172 llvm::BasicBlock* next_basic_block = irb_.GetInsertBlock();
1173 if (next_basic_block != first_basic_block) {
1174 // Splice the rest of the instruction to the continuing basic block
1175 next_basic_block->getInstList().splice(
1176 irb_.GetInsertPoint(), first_basic_block->getInstList(),
1177 first_non_alloca, first_basic_block->end());
1178
1179 // Rewrite the basic block
1180 RewriteBasicBlock(next_basic_block);
1181
1182 // Update the phi-instructions in the successor basic block
1183 UpdatePhiInstruction(first_basic_block, irb_.GetInsertBlock());
1184 }
1185
1186 // We have changed the basic block
1187 changed_ = true;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001188}
1189
TDYa1275e869b62012-07-25 00:45:39 -07001190// ==== High-level intrinsic expander ==========================================
1191
TDYa127a1b21852012-07-23 03:20:39 -07001192llvm::Value* GBCExpanderPass::Expand_FPCompare(llvm::Value* src1_value,
1193 llvm::Value* src2_value,
1194 bool gt_bias) {
1195 llvm::Value* cmp_eq = irb_.CreateFCmpOEQ(src1_value, src2_value);
1196 llvm::Value* cmp_lt;
1197
1198 if (gt_bias) {
1199 cmp_lt = irb_.CreateFCmpOLT(src1_value, src2_value);
1200 } else {
1201 cmp_lt = irb_.CreateFCmpULT(src1_value, src2_value);
1202 }
1203
1204 return EmitCompareResultSelection(cmp_eq, cmp_lt);
1205}
1206
1207llvm::Value* GBCExpanderPass::Expand_LongCompare(llvm::Value* src1_value, llvm::Value* src2_value) {
1208 llvm::Value* cmp_eq = irb_.CreateICmpEQ(src1_value, src2_value);
1209 llvm::Value* cmp_lt = irb_.CreateICmpSLT(src1_value, src2_value);
1210
1211 return EmitCompareResultSelection(cmp_eq, cmp_lt);
1212}
1213
1214llvm::Value* GBCExpanderPass::EmitCompareResultSelection(llvm::Value* cmp_eq,
1215 llvm::Value* cmp_lt) {
1216
1217 llvm::Constant* zero = irb_.getJInt(0);
1218 llvm::Constant* pos1 = irb_.getJInt(1);
1219 llvm::Constant* neg1 = irb_.getJInt(-1);
1220
1221 llvm::Value* result_lt = irb_.CreateSelect(cmp_lt, neg1, pos1);
1222 llvm::Value* result_eq = irb_.CreateSelect(cmp_eq, zero, result_lt);
1223
1224 return result_eq;
1225}
1226
Logan Chien75e4b602012-07-23 14:24:12 -07001227llvm::Value* GBCExpanderPass::Expand_IntegerShift(llvm::Value* src1_value,
1228 llvm::Value* src2_value,
1229 IntegerShiftKind kind,
1230 JType op_jty) {
1231 DCHECK(op_jty == kInt || op_jty == kLong);
1232
1233 // Mask and zero-extend RHS properly
1234 if (op_jty == kInt) {
1235 src2_value = irb_.CreateAnd(src2_value, 0x1f);
1236 } else {
1237 llvm::Value* masked_src2_value = irb_.CreateAnd(src2_value, 0x3f);
1238 src2_value = irb_.CreateZExt(masked_src2_value, irb_.getJLongTy());
1239 }
1240
1241 // Create integer shift llvm instruction
1242 switch (kind) {
1243 case kIntegerSHL:
1244 return irb_.CreateShl(src1_value, src2_value);
1245
1246 case kIntegerSHR:
1247 return irb_.CreateAShr(src1_value, src2_value);
1248
1249 case kIntegerUSHR:
1250 return irb_.CreateLShr(src1_value, src2_value);
1251
1252 default:
1253 LOG(FATAL) << "Unknown integer shift kind: " << kind;
1254 return NULL;
1255 }
1256}
1257
TDYa1275a26d442012-07-26 18:58:38 -07001258llvm::Value* GBCExpanderPass::Expand_HLArrayGet(llvm::CallInst& call_inst,
1259 JType elem_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001260 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1261 llvm::Value* array_addr = call_inst.getArgOperand(1);
1262 llvm::Value* index_value = call_inst.getArgOperand(2);
1263
1264 // TODO: opt_flags
1265 EmitGuard_ArrayException(dex_pc, array_addr, index_value);
1266
1267 llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty);
1268
1269 llvm::Value* array_elem_value = irb_.CreateLoad(array_elem_addr, kTBAAHeapArray, elem_jty);
1270
1271 switch (elem_jty) {
1272 case kVoid:
1273 break;
1274
1275 case kBoolean:
1276 case kChar:
1277 array_elem_value = irb_.CreateZExt(array_elem_value, irb_.getJType(elem_jty, kReg));
1278 break;
1279
1280 case kByte:
1281 case kShort:
1282 array_elem_value = irb_.CreateSExt(array_elem_value, irb_.getJType(elem_jty, kReg));
1283 break;
1284
1285 case kInt:
1286 case kLong:
1287 case kFloat:
1288 case kDouble:
1289 case kObject:
1290 break;
1291
1292 default:
1293 LOG(FATAL) << "Unknown java type: " << elem_jty;
1294 }
1295
1296 return array_elem_value;
1297}
1298
1299
1300void GBCExpanderPass::Expand_HLArrayPut(llvm::CallInst& call_inst,
1301 JType elem_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001302 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1303 llvm::Value* new_value = call_inst.getArgOperand(1);
1304 llvm::Value* array_addr = call_inst.getArgOperand(2);
1305 llvm::Value* index_value = call_inst.getArgOperand(3);
1306
1307 // TODO: opt_flags
1308 EmitGuard_ArrayException(dex_pc, array_addr, index_value);
1309
1310 switch (elem_jty) {
1311 case kVoid:
1312 break;
1313
1314 case kBoolean:
1315 case kChar:
1316 new_value = irb_.CreateTrunc(new_value, irb_.getJType(elem_jty, kArray));
1317 break;
1318
1319 case kInt:
1320 case kLong:
1321 case kFloat:
1322 case kDouble:
1323 case kObject:
1324 break;
1325
1326 default:
1327 LOG(FATAL) << "Unknown java type: " << elem_jty;
1328 }
1329
1330 llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty);
1331
1332 if (elem_jty == kObject) { // If put an object, check the type, and mark GC card table.
1333 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::CheckPutArrayElement);
1334
1335 irb_.CreateCall2(runtime_func, new_value, array_addr);
1336
1337 EmitGuard_ExceptionLandingPad(dex_pc);
1338
1339 EmitMarkGCCard(new_value, array_addr);
1340 }
1341
1342 irb_.CreateStore(new_value, array_elem_addr, kTBAAHeapArray, elem_jty);
1343
1344 return;
1345}
1346
TDYa1275e869b62012-07-25 00:45:39 -07001347llvm::Value* GBCExpanderPass::Expand_HLIGet(llvm::CallInst& call_inst,
1348 JType field_jty) {
TDYa1275e869b62012-07-25 00:45:39 -07001349 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1350 llvm::Value* object_addr = call_inst.getArgOperand(1);
1351 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(2));
1352
1353 // TODO: opt_flags
1354 EmitGuard_NullPointerException(dex_pc, object_addr);
1355
1356 llvm::Value* field_value;
1357
1358 int field_offset;
1359 bool is_volatile;
1360 bool is_fast_path = compiler_->ComputeInstanceFieldInfo(
1361 field_idx, oat_compilation_unit_, field_offset, is_volatile, false);
1362
1363 if (!is_fast_path) {
1364 llvm::Function* runtime_func;
1365
1366 if (field_jty == kObject) {
1367 runtime_func = irb_.GetRuntime(runtime_support::GetObjectInstance);
1368 } else if (field_jty == kLong || field_jty == kDouble) {
1369 runtime_func = irb_.GetRuntime(runtime_support::Get64Instance);
1370 } else {
1371 runtime_func = irb_.GetRuntime(runtime_support::Get32Instance);
1372 }
1373
1374 llvm::ConstantInt* field_idx_value = irb_.getInt32(field_idx);
1375
1376 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1377
1378 EmitUpdateDexPC(dex_pc);
1379
1380 field_value = irb_.CreateCall3(runtime_func, field_idx_value,
1381 method_object_addr, object_addr);
1382
1383 EmitGuard_ExceptionLandingPad(dex_pc);
1384
1385 } else {
1386 DCHECK_GE(field_offset, 0);
1387
1388 llvm::PointerType* field_type =
1389 irb_.getJType(field_jty, kField)->getPointerTo();
1390
1391 llvm::ConstantInt* field_offset_value = irb_.getPtrEquivInt(field_offset);
1392
1393 llvm::Value* field_addr =
1394 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
1395
1396 // TODO: Check is_volatile. We need to generate atomic load instruction
1397 // when is_volatile is true.
1398 field_value = irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty);
1399 }
1400
1401 if (field_jty == kFloat || field_jty == kDouble) {
TDYa1275a26d442012-07-26 18:58:38 -07001402 field_value = irb_.CreateBitCast(field_value, irb_.getJType(field_jty, kAccurate));
TDYa1275e869b62012-07-25 00:45:39 -07001403 }
1404
1405 return field_value;
1406}
1407
1408void GBCExpanderPass::Expand_HLIPut(llvm::CallInst& call_inst,
1409 JType field_jty) {
TDYa1275e869b62012-07-25 00:45:39 -07001410 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1411 llvm::Value* object_addr = call_inst.getArgOperand(1);
1412 llvm::Value* new_value = call_inst.getArgOperand(2);
1413 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(3));
1414
1415 if (field_jty == kFloat || field_jty == kDouble) {
TDYa1275a26d442012-07-26 18:58:38 -07001416 new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty, kField));
TDYa1275e869b62012-07-25 00:45:39 -07001417 }
1418
1419 // TODO: opt_flags
1420 EmitGuard_NullPointerException(dex_pc, object_addr);
1421
1422 int field_offset;
1423 bool is_volatile;
1424 bool is_fast_path = compiler_->ComputeInstanceFieldInfo(
1425 field_idx, oat_compilation_unit_, field_offset, is_volatile, true);
1426
1427 if (!is_fast_path) {
1428 llvm::Function* runtime_func;
1429
1430 if (field_jty == kObject) {
1431 runtime_func = irb_.GetRuntime(runtime_support::SetObjectInstance);
1432 } else if (field_jty == kLong || field_jty == kDouble) {
1433 runtime_func = irb_.GetRuntime(runtime_support::Set64Instance);
1434 } else {
1435 runtime_func = irb_.GetRuntime(runtime_support::Set32Instance);
1436 }
1437
1438 llvm::Value* field_idx_value = irb_.getInt32(field_idx);
1439
1440 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1441
1442 EmitUpdateDexPC(dex_pc);
1443
1444 irb_.CreateCall4(runtime_func, field_idx_value,
1445 method_object_addr, object_addr, new_value);
1446
1447 EmitGuard_ExceptionLandingPad(dex_pc);
1448
1449 } else {
1450 DCHECK_GE(field_offset, 0);
1451
1452 llvm::PointerType* field_type =
1453 irb_.getJType(field_jty, kField)->getPointerTo();
1454
1455 llvm::Value* field_offset_value = irb_.getPtrEquivInt(field_offset);
1456
1457 llvm::Value* field_addr =
1458 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
1459
1460 // TODO: Check is_volatile. We need to generate atomic store instruction
1461 // when is_volatile is true.
1462 irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty);
1463
1464 if (field_jty == kObject) { // If put an object, mark the GC card table.
1465 EmitMarkGCCard(new_value, object_addr);
1466 }
1467 }
1468
1469 return;
1470}
1471
TDYa127f71bf5a2012-07-29 20:09:52 -07001472llvm::Value* GBCExpanderPass::EmitLoadConstantClass(uint32_t dex_pc,
1473 uint32_t type_idx) {
1474 if (!compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_,
1475 *dex_file_, type_idx)) {
1476 llvm::Value* type_idx_value = irb_.getInt32(type_idx);
1477
1478 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1479
1480 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1481
1482 llvm::Function* runtime_func =
1483 irb_.GetRuntime(runtime_support::InitializeTypeAndVerifyAccess);
1484
1485 EmitUpdateDexPC(dex_pc);
1486
1487 llvm::Value* type_object_addr =
1488 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1489
1490 EmitGuard_ExceptionLandingPad(dex_pc);
1491
1492 return type_object_addr;
1493
1494 } else {
1495 // Try to load the class (type) object from the test cache.
1496 llvm::Value* type_field_addr =
1497 EmitLoadDexCacheResolvedTypeFieldAddr(type_idx);
1498
1499 llvm::Value* type_object_addr = irb_.CreateLoad(type_field_addr, kTBAAJRuntime);
1500
1501 if (compiler_->CanAssumeTypeIsPresentInDexCache(dex_cache_, type_idx)) {
1502 return type_object_addr;
1503 }
1504
1505 llvm::BasicBlock* block_original = irb_.GetInsertBlock();
1506
1507 // Test whether class (type) object is in the dex cache or not
1508 llvm::Value* equal_null =
1509 irb_.CreateICmpEQ(type_object_addr, irb_.getJNull());
1510
1511 llvm::BasicBlock* block_cont =
1512 CreateBasicBlockWithDexPC(dex_pc, "cont");
1513
1514 llvm::BasicBlock* block_load_class =
1515 CreateBasicBlockWithDexPC(dex_pc, "load_class");
1516
1517 irb_.CreateCondBr(equal_null, block_load_class, block_cont, kUnlikely);
1518
1519 // Failback routine to load the class object
1520 irb_.SetInsertPoint(block_load_class);
1521
1522 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeType);
1523
1524 llvm::Constant* type_idx_value = irb_.getInt32(type_idx);
1525
1526 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1527
1528 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1529
1530 EmitUpdateDexPC(dex_pc);
1531
1532 llvm::Value* loaded_type_object_addr =
1533 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1534
1535 EmitGuard_ExceptionLandingPad(dex_pc);
1536
1537 llvm::BasicBlock* block_after_load_class = irb_.GetInsertBlock();
1538
1539 irb_.CreateBr(block_cont);
1540
1541 // Now the class object must be loaded
1542 irb_.SetInsertPoint(block_cont);
1543
1544 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1545
1546 phi->addIncoming(type_object_addr, block_original);
1547 phi->addIncoming(loaded_type_object_addr, block_after_load_class);
1548
1549 return phi;
1550 }
1551}
1552
TDYa1275a26d442012-07-26 18:58:38 -07001553llvm::Value* GBCExpanderPass::EmitLoadStaticStorage(uint32_t dex_pc,
1554 uint32_t type_idx) {
1555 llvm::BasicBlock* block_load_static =
1556 CreateBasicBlockWithDexPC(dex_pc, "load_static");
1557
1558 llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont");
1559
1560 // Load static storage from dex cache
1561 llvm::Value* storage_field_addr =
1562 EmitLoadDexCacheStaticStorageFieldAddr(type_idx);
1563
1564 llvm::Value* storage_object_addr = irb_.CreateLoad(storage_field_addr, kTBAAJRuntime);
1565
1566 llvm::BasicBlock* block_original = irb_.GetInsertBlock();
1567
1568 // Test: Is the static storage of this class initialized?
1569 llvm::Value* equal_null =
1570 irb_.CreateICmpEQ(storage_object_addr, irb_.getJNull());
1571
1572 irb_.CreateCondBr(equal_null, block_load_static, block_cont, kUnlikely);
1573
1574 // Failback routine to load the class object
1575 irb_.SetInsertPoint(block_load_static);
1576
1577 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeStaticStorage);
1578
1579 llvm::Constant* type_idx_value = irb_.getInt32(type_idx);
1580
1581 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1582
1583 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1584
1585 EmitUpdateDexPC(dex_pc);
1586
1587 llvm::Value* loaded_storage_object_addr =
1588 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1589
1590 EmitGuard_ExceptionLandingPad(dex_pc);
1591
1592 llvm::BasicBlock* block_after_load_static = irb_.GetInsertBlock();
1593
1594 irb_.CreateBr(block_cont);
1595
1596 // Now the class object must be loaded
1597 irb_.SetInsertPoint(block_cont);
1598
1599 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1600
1601 phi->addIncoming(storage_object_addr, block_original);
1602 phi->addIncoming(loaded_storage_object_addr, block_after_load_static);
1603
1604 return phi;
1605}
1606
1607llvm::Value* GBCExpanderPass::Expand_HLSget(llvm::CallInst& call_inst,
1608 JType field_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001609 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1610 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0));
1611
1612 int field_offset;
1613 int ssb_index;
1614 bool is_referrers_class;
1615 bool is_volatile;
1616
1617 bool is_fast_path = compiler_->ComputeStaticFieldInfo(
1618 field_idx, oat_compilation_unit_, field_offset, ssb_index,
1619 is_referrers_class, is_volatile, false);
1620
1621 llvm::Value* static_field_value;
1622
1623 if (!is_fast_path) {
1624 llvm::Function* runtime_func;
1625
1626 if (field_jty == kObject) {
1627 runtime_func = irb_.GetRuntime(runtime_support::GetObjectStatic);
1628 } else if (field_jty == kLong || field_jty == kDouble) {
1629 runtime_func = irb_.GetRuntime(runtime_support::Get64Static);
1630 } else {
1631 runtime_func = irb_.GetRuntime(runtime_support::Get32Static);
1632 }
1633
1634 llvm::Constant* field_idx_value = irb_.getInt32(field_idx);
1635
1636 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1637
1638 EmitUpdateDexPC(dex_pc);
1639
1640 static_field_value =
1641 irb_.CreateCall2(runtime_func, field_idx_value, method_object_addr);
1642
1643 EmitGuard_ExceptionLandingPad(dex_pc);
1644
1645 } else {
1646 DCHECK_GE(field_offset, 0);
1647
1648 llvm::Value* static_storage_addr = NULL;
1649
1650 if (is_referrers_class) {
1651 // Fast path, static storage base is this method's class
1652 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1653
1654 static_storage_addr =
1655 irb_.LoadFromObjectOffset(method_object_addr,
1656 Method::DeclaringClassOffset().Int32Value(),
1657 irb_.getJObjectTy(),
1658 kTBAAConstJObject);
1659 } else {
1660 // Medium path, static storage base in a different class which
1661 // requires checks that the other class is initialized
1662 DCHECK_GE(ssb_index, 0);
1663 static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index);
1664 }
1665
1666 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
1667
1668 llvm::Value* static_field_addr =
1669 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
1670 irb_.getJType(field_jty, kField)->getPointerTo());
1671
1672 // TODO: Check is_volatile. We need to generate atomic load instruction
1673 // when is_volatile is true.
1674 static_field_value = irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty);
1675 }
1676
1677 if (field_jty == kFloat || field_jty == kDouble) {
1678 static_field_value =
1679 irb_.CreateBitCast(static_field_value, irb_.getJType(field_jty, kAccurate));
1680 }
1681
1682 return static_field_value;
1683}
1684
1685void GBCExpanderPass::Expand_HLSput(llvm::CallInst& call_inst,
1686 JType field_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001687 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1688 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0));
1689 llvm::Value* new_value = call_inst.getArgOperand(1);
1690
1691 if (field_jty == kFloat || field_jty == kDouble) {
1692 new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty, kField));
1693 }
1694
1695 int field_offset;
1696 int ssb_index;
1697 bool is_referrers_class;
1698 bool is_volatile;
1699
1700 bool is_fast_path = compiler_->ComputeStaticFieldInfo(
1701 field_idx, oat_compilation_unit_, field_offset, ssb_index,
1702 is_referrers_class, is_volatile, true);
1703
1704 if (!is_fast_path) {
1705 llvm::Function* runtime_func;
1706
1707 if (field_jty == kObject) {
1708 runtime_func = irb_.GetRuntime(runtime_support::SetObjectStatic);
1709 } else if (field_jty == kLong || field_jty == kDouble) {
1710 runtime_func = irb_.GetRuntime(runtime_support::Set64Static);
1711 } else {
1712 runtime_func = irb_.GetRuntime(runtime_support::Set32Static);
1713 }
1714
1715 llvm::Constant* field_idx_value = irb_.getInt32(field_idx);
1716
1717 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1718
1719 EmitUpdateDexPC(dex_pc);
1720
1721 irb_.CreateCall3(runtime_func, field_idx_value,
1722 method_object_addr, new_value);
1723
1724 EmitGuard_ExceptionLandingPad(dex_pc);
1725
1726 } else {
1727 DCHECK_GE(field_offset, 0);
1728
1729 llvm::Value* static_storage_addr = NULL;
1730
1731 if (is_referrers_class) {
1732 // Fast path, static storage base is this method's class
1733 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1734
1735 static_storage_addr =
1736 irb_.LoadFromObjectOffset(method_object_addr,
1737 Method::DeclaringClassOffset().Int32Value(),
1738 irb_.getJObjectTy(),
1739 kTBAAConstJObject);
1740 } else {
1741 // Medium path, static storage base in a different class which
1742 // requires checks that the other class is initialized
1743 DCHECK_GE(ssb_index, 0);
1744 static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index);
1745 }
1746
1747 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
1748
1749 llvm::Value* static_field_addr =
1750 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
1751 irb_.getJType(field_jty, kField)->getPointerTo());
1752
1753 // TODO: Check is_volatile. We need to generate atomic store instruction
1754 // when is_volatile is true.
1755 irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty);
1756
1757 if (field_jty == kObject) { // If put an object, mark the GC card table.
1758 EmitMarkGCCard(new_value, static_storage_addr);
1759 }
1760 }
1761
1762 return;
1763}
1764
TDYa127f71bf5a2012-07-29 20:09:52 -07001765llvm::Value* GBCExpanderPass::Expand_ConstString(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001766 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1767 uint32_t string_idx = LV2UInt(call_inst.getArgOperand(0));
1768
1769 llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx);
1770
1771 llvm::Value* string_addr = irb_.CreateLoad(string_field_addr, kTBAAJRuntime);
1772
1773 if (!compiler_->CanAssumeStringIsPresentInDexCache(dex_cache_, string_idx)) {
1774 llvm::BasicBlock* block_str_exist =
1775 CreateBasicBlockWithDexPC(dex_pc, "str_exist");
1776
1777 llvm::BasicBlock* block_str_resolve =
1778 CreateBasicBlockWithDexPC(dex_pc, "str_resolve");
1779
1780 llvm::BasicBlock* block_cont =
1781 CreateBasicBlockWithDexPC(dex_pc, "str_cont");
1782
1783 // Test: Is the string resolved and in the dex cache?
1784 llvm::Value* equal_null = irb_.CreateICmpEQ(string_addr, irb_.getJNull());
1785
1786 irb_.CreateCondBr(equal_null, block_str_resolve, block_str_exist, kUnlikely);
1787
1788 // String is resolved, go to next basic block.
1789 irb_.SetInsertPoint(block_str_exist);
1790 irb_.CreateBr(block_cont);
1791
1792 // String is not resolved yet, resolve it now.
1793 irb_.SetInsertPoint(block_str_resolve);
1794
1795 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::ResolveString);
1796
1797 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1798
1799 llvm::Value* string_idx_value = irb_.getInt32(string_idx);
1800
1801 EmitUpdateDexPC(dex_pc);
1802
1803 llvm::Value* result = irb_.CreateCall2(runtime_func, method_object_addr,
1804 string_idx_value);
1805
1806 EmitGuard_ExceptionLandingPad(dex_pc);
1807
1808 llvm::BasicBlock* block_pre_cont = irb_.GetInsertBlock();
1809
1810 irb_.SetInsertPoint(block_cont);
1811
1812 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1813
1814 phi->addIncoming(string_addr, block_str_exist);
1815 phi->addIncoming(result, block_pre_cont);
1816
1817 string_addr = phi;
1818 }
1819
1820 return string_addr;
1821}
1822
1823llvm::Value* GBCExpanderPass::Expand_ConstClass(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001824 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1825 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1826
1827 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
1828
1829 return type_object_addr;
1830}
1831
1832void GBCExpanderPass::Expand_MonitorEnter(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001833 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1834 llvm::Value* object_addr = call_inst.getArgOperand(1);
1835
1836 // TODO: opt_flags
1837 EmitGuard_NullPointerException(dex_pc, object_addr);
1838
1839 irb_.Runtime().EmitLockObject(object_addr);
1840
1841 return;
1842}
1843
1844void GBCExpanderPass::Expand_MonitorExit(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001845 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1846 llvm::Value* object_addr = call_inst.getArgOperand(1);
1847
1848 // TODO: opt_flags
1849 EmitGuard_NullPointerException(dex_pc, object_addr);
1850
1851 EmitUpdateDexPC(dex_pc);
1852
1853 irb_.Runtime().EmitUnlockObject(object_addr);
1854
1855 EmitGuard_ExceptionLandingPad(dex_pc);
1856
1857 return;
1858}
1859
1860void GBCExpanderPass::Expand_HLCheckCast(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001861 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1862 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1863 llvm::Value* object_addr = call_inst.getArgOperand(1);
1864
1865 llvm::BasicBlock* block_test_class =
1866 CreateBasicBlockWithDexPC(dex_pc, "test_class");
1867
1868 llvm::BasicBlock* block_test_sub_class =
1869 CreateBasicBlockWithDexPC(dex_pc, "test_sub_class");
1870
1871 llvm::BasicBlock* block_cont =
1872 CreateBasicBlockWithDexPC(dex_pc, "checkcast_cont");
1873
1874 // Test: Is the reference equal to null? Act as no-op when it is null.
1875 llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull());
1876
1877 irb_.CreateCondBr(equal_null,
1878 block_cont,
1879 block_test_class);
1880
1881 // Test: Is the object instantiated from the given class?
1882 irb_.SetInsertPoint(block_test_class);
1883 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
1884 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
1885
1886 llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy();
1887
1888 llvm::Value* object_type_field_addr =
1889 irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo());
1890
1891 llvm::Value* object_type_object_addr =
1892 irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject);
1893
1894 llvm::Value* equal_class =
1895 irb_.CreateICmpEQ(type_object_addr, object_type_object_addr);
1896
1897 irb_.CreateCondBr(equal_class,
1898 block_cont,
1899 block_test_sub_class);
1900
1901 // Test: Is the object instantiated from the subclass of the given class?
1902 irb_.SetInsertPoint(block_test_sub_class);
1903
1904 EmitUpdateDexPC(dex_pc);
1905
1906 irb_.CreateCall2(irb_.GetRuntime(runtime_support::CheckCast),
1907 type_object_addr, object_type_object_addr);
1908
1909 EmitGuard_ExceptionLandingPad(dex_pc);
1910
1911 irb_.CreateBr(block_cont);
1912
1913 irb_.SetInsertPoint(block_cont);
1914
1915 return;
1916}
1917
1918llvm::Value* GBCExpanderPass::Expand_InstanceOf(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001919 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1920 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1921 llvm::Value* object_addr = call_inst.getArgOperand(1);
1922
1923 llvm::BasicBlock* block_nullp =
1924 CreateBasicBlockWithDexPC(dex_pc, "nullp");
1925
1926 llvm::BasicBlock* block_test_class =
1927 CreateBasicBlockWithDexPC(dex_pc, "test_class");
1928
1929 llvm::BasicBlock* block_class_equals =
1930 CreateBasicBlockWithDexPC(dex_pc, "class_eq");
1931
1932 llvm::BasicBlock* block_test_sub_class =
1933 CreateBasicBlockWithDexPC(dex_pc, "test_sub_class");
1934
1935 llvm::BasicBlock* block_cont =
1936 CreateBasicBlockWithDexPC(dex_pc, "instance_of_cont");
1937
1938 // Overview of the following code :
1939 // We check for null, if so, then false, otherwise check for class == . If so
1940 // then true, otherwise do callout slowpath.
1941 //
1942 // Test: Is the reference equal to null? Set 0 when it is null.
1943 llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull());
1944
1945 irb_.CreateCondBr(equal_null, block_nullp, block_test_class);
1946
1947 irb_.SetInsertPoint(block_nullp);
1948 irb_.CreateBr(block_cont);
1949
1950 // Test: Is the object instantiated from the given class?
1951 irb_.SetInsertPoint(block_test_class);
1952 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
1953 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
1954
1955 llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy();
1956
1957 llvm::Value* object_type_field_addr =
1958 irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo());
1959
1960 llvm::Value* object_type_object_addr =
1961 irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject);
1962
1963 llvm::Value* equal_class =
1964 irb_.CreateICmpEQ(type_object_addr, object_type_object_addr);
1965
1966 irb_.CreateCondBr(equal_class, block_class_equals, block_test_sub_class);
1967
1968 irb_.SetInsertPoint(block_class_equals);
1969 irb_.CreateBr(block_cont);
1970
1971 // Test: Is the object instantiated from the subclass of the given class?
1972 irb_.SetInsertPoint(block_test_sub_class);
1973 llvm::Value* result =
1974 irb_.CreateCall2(irb_.GetRuntime(runtime_support::IsAssignable),
1975 type_object_addr, object_type_object_addr);
1976 irb_.CreateBr(block_cont);
1977
1978 irb_.SetInsertPoint(block_cont);
1979
1980 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJIntTy(), 3);
1981
1982 phi->addIncoming(irb_.getJInt(0), block_nullp);
1983 phi->addIncoming(irb_.getJInt(1), block_class_equals);
1984 phi->addIncoming(result, block_test_sub_class);
1985
1986 return phi;
1987}
1988
1989llvm::Value* GBCExpanderPass::Expand_NewInstance(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001990 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1991 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1992
1993 llvm::Function* runtime_func;
1994 if (compiler_->CanAccessInstantiableTypeWithoutChecks(
1995 method_idx_, dex_cache_, *dex_file_, type_idx)) {
1996 runtime_func = irb_.GetRuntime(runtime_support::AllocObject);
1997 } else {
1998 runtime_func = irb_.GetRuntime(runtime_support::AllocObjectWithAccessCheck);
1999 }
2000
2001 llvm::Constant* type_index_value = irb_.getInt32(type_idx);
2002
2003 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2004
2005 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2006
2007 EmitUpdateDexPC(dex_pc);
2008
2009 llvm::Value* object_addr =
2010 irb_.CreateCall3(runtime_func, type_index_value, method_object_addr, thread_object_addr);
2011
2012 EmitGuard_ExceptionLandingPad(dex_pc);
2013
2014 return object_addr;
2015}
2016
2017llvm::Value* GBCExpanderPass::Expand_HLInvoke(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002018 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2019 InvokeType invoke_type = static_cast<InvokeType>(LV2UInt(call_inst.getArgOperand(0)));
2020 bool is_static = (invoke_type == kStatic);
2021 uint32_t callee_method_idx = LV2UInt(call_inst.getArgOperand(1));
2022
2023 // Compute invoke related information for compiler decision
2024 int vtable_idx = -1;
2025 uintptr_t direct_code = 0;
2026 uintptr_t direct_method = 0;
2027 bool is_fast_path = compiler_->
2028 ComputeInvokeInfo(callee_method_idx, oat_compilation_unit_,
2029 invoke_type, vtable_idx, direct_code, direct_method);
2030
2031 // Load *this* actual parameter
2032 llvm::Value* this_addr = NULL;
2033
2034 if (!is_static) {
2035 // Test: Is *this* parameter equal to null?
2036 this_addr = call_inst.getArgOperand(3);
2037 }
2038
2039 // Load the method object
2040 llvm::Value* callee_method_object_addr = NULL;
2041
2042 if (!is_fast_path) {
2043 callee_method_object_addr =
2044 EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, invoke_type,
2045 this_addr, dex_pc, is_fast_path);
2046
2047 // TODO: opt_flags
2048 if (!is_static) {
2049 EmitGuard_NullPointerException(dex_pc, this_addr);
2050 }
2051 } else {
2052 // TODO: opt_flags
2053 if (!is_static) {
2054 EmitGuard_NullPointerException(dex_pc, this_addr);
2055 }
2056
2057 switch (invoke_type) {
2058 case kStatic:
2059 case kDirect:
2060 if (direct_method != 0u &&
2061 direct_method != static_cast<uintptr_t>(-1)) {
2062 callee_method_object_addr =
2063 irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_method),
2064 irb_.getJObjectTy());
2065 } else {
2066 callee_method_object_addr =
2067 EmitLoadSDCalleeMethodObjectAddr(callee_method_idx);
2068 }
2069 break;
2070
2071 case kVirtual:
2072 DCHECK(vtable_idx != -1);
2073 callee_method_object_addr =
2074 EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr);
2075 break;
2076
2077 case kSuper:
2078 LOG(FATAL) << "invoke-super should be promoted to invoke-direct in "
2079 "the fast path.";
2080 break;
2081
2082 case kInterface:
2083 callee_method_object_addr =
2084 EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx,
2085 invoke_type, this_addr,
2086 dex_pc, is_fast_path);
2087 break;
2088 }
2089 }
2090
2091 // Load the actual parameter
2092 std::vector<llvm::Value*> args;
2093
2094 args.push_back(callee_method_object_addr); // method object for callee
2095
2096 for (uint32_t i = 3; i < call_inst.getNumArgOperands(); ++i) {
2097 args.push_back(call_inst.getArgOperand(i));
2098 }
2099
2100 llvm::Value* code_addr;
2101 if (direct_code != 0u &&
2102 direct_code != static_cast<uintptr_t>(-1)) {
2103 code_addr =
2104 irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_code),
2105 GetFunctionType(callee_method_idx, is_static)->getPointerTo());
2106 } else {
2107 code_addr =
2108 irb_.LoadFromObjectOffset(callee_method_object_addr,
2109 Method::GetCodeOffset().Int32Value(),
2110 GetFunctionType(callee_method_idx, is_static)->getPointerTo(),
2111 kTBAAJRuntime);
2112 }
2113
2114 // Invoke callee
2115 EmitUpdateDexPC(dex_pc);
2116 llvm::Value* retval = irb_.CreateCall(code_addr, args);
2117 EmitGuard_ExceptionLandingPad(dex_pc);
2118
2119 return retval;
2120}
2121
2122llvm::Value* GBCExpanderPass::Expand_OptArrayLength(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002123 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2124 // Get the array object address
2125 llvm::Value* array_addr = call_inst.getArgOperand(1);
2126
2127 // TODO: opt_flags
2128 EmitGuard_NullPointerException(dex_pc, array_addr);
2129
2130 // Get the array length and store it to the register
2131 return EmitLoadArrayLength(array_addr);
2132}
2133
2134llvm::Value* GBCExpanderPass::Expand_NewArray(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002135 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2136 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
2137 llvm::Value* length = call_inst.getArgOperand(1);
2138
2139 return EmitAllocNewArray(dex_pc, length, type_idx, false);
2140}
2141
2142llvm::Value* GBCExpanderPass::Expand_HLFilledNewArray(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002143 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2144 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(1));
2145 uint32_t length = call_inst.getNumArgOperands() - 3;
2146
2147 llvm::Value* object_addr =
2148 EmitAllocNewArray(dex_pc, irb_.getInt32(length), type_idx, true);
2149
2150 if (length > 0) {
2151 // Check for the element type
2152 uint32_t type_desc_len = 0;
2153 const char* type_desc =
2154 dex_file_->StringByTypeIdx(type_idx, &type_desc_len);
2155
2156 DCHECK_GE(type_desc_len, 2u); // should be guaranteed by verifier
2157 DCHECK_EQ(type_desc[0], '['); // should be guaranteed by verifier
2158 bool is_elem_int_ty = (type_desc[1] == 'I');
2159
2160 uint32_t alignment;
2161 llvm::Constant* elem_size;
2162 llvm::PointerType* field_type;
2163
2164 // NOTE: Currently filled-new-array only supports 'L', '[', and 'I'
2165 // as the element, thus we are only checking 2 cases: primitive int and
2166 // non-primitive type.
2167 if (is_elem_int_ty) {
2168 alignment = sizeof(int32_t);
2169 elem_size = irb_.getPtrEquivInt(sizeof(int32_t));
2170 field_type = irb_.getJIntTy()->getPointerTo();
2171 } else {
2172 alignment = irb_.getSizeOfPtrEquivInt();
2173 elem_size = irb_.getSizeOfPtrEquivIntValue();
2174 field_type = irb_.getJObjectTy()->getPointerTo();
2175 }
2176
2177 llvm::Value* data_field_offset =
2178 irb_.getPtrEquivInt(Array::DataOffset(alignment).Int32Value());
2179
2180 llvm::Value* data_field_addr =
2181 irb_.CreatePtrDisp(object_addr, data_field_offset, field_type);
2182
2183 // TODO: Tune this code. Currently we are generating one instruction for
2184 // one element which may be very space consuming. Maybe changing to use
2185 // memcpy may help; however, since we can't guarantee that the alloca of
2186 // dalvik register are continuous, we can't perform such optimization yet.
2187 for (uint32_t i = 0; i < length; ++i) {
2188 llvm::Value* reg_value = call_inst.getArgOperand(i+3);
2189
2190 irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray);
2191
2192 data_field_addr =
2193 irb_.CreatePtrDisp(data_field_addr, elem_size, field_type);
2194 }
2195 }
2196
2197 return object_addr;
2198}
2199
2200void GBCExpanderPass::Expand_HLFillArrayData(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002201 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2202 int32_t payload_offset = static_cast<int32_t>(dex_pc) +
2203 LV2SInt(call_inst.getArgOperand(0));
2204 llvm::Value* array_addr = call_inst.getArgOperand(1);
2205
2206 const Instruction::ArrayDataPayload* payload =
2207 reinterpret_cast<const Instruction::ArrayDataPayload*>(
2208 code_item_->insns_ + payload_offset);
2209
2210 if (payload->element_count == 0) {
2211 // When the number of the elements in the payload is zero, we don't have
2212 // to copy any numbers. However, we should check whether the array object
2213 // address is equal to null or not.
2214 EmitGuard_NullPointerException(dex_pc, array_addr);
2215 } else {
2216 // To save the code size, we are going to call the runtime function to
2217 // copy the content from DexFile.
2218
2219 // NOTE: We will check for the NullPointerException in the runtime.
2220
2221 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::FillArrayData);
2222
2223 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2224
2225 EmitUpdateDexPC(dex_pc);
2226
2227 irb_.CreateCall4(runtime_func,
2228 method_object_addr, irb_.getInt32(dex_pc),
2229 array_addr, irb_.getInt32(payload_offset));
2230
2231 EmitGuard_ExceptionLandingPad(dex_pc);
2232 }
2233
2234 return;
2235}
2236
2237llvm::Value* GBCExpanderPass::EmitAllocNewArray(uint32_t dex_pc,
2238 llvm::Value* array_length_value,
2239 uint32_t type_idx,
2240 bool is_filled_new_array) {
2241 llvm::Function* runtime_func;
2242
2243 bool skip_access_check =
2244 compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_,
2245 *dex_file_, type_idx);
2246
2247
2248 if (is_filled_new_array) {
2249 runtime_func = skip_access_check ?
2250 irb_.GetRuntime(runtime_support::CheckAndAllocArray) :
2251 irb_.GetRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck);
2252 } else {
2253 runtime_func = skip_access_check ?
2254 irb_.GetRuntime(runtime_support::AllocArray) :
2255 irb_.GetRuntime(runtime_support::AllocArrayWithAccessCheck);
2256 }
2257
2258 llvm::Constant* type_index_value = irb_.getInt32(type_idx);
2259
2260 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2261
2262 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2263
2264 EmitUpdateDexPC(dex_pc);
2265
2266 llvm::Value* object_addr =
2267 irb_.CreateCall4(runtime_func, type_index_value, method_object_addr,
2268 array_length_value, thread_object_addr);
2269
2270 EmitGuard_ExceptionLandingPad(dex_pc);
2271
2272 return object_addr;
2273}
2274
2275llvm::Value* GBCExpanderPass::
2276EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx,
2277 InvokeType invoke_type,
2278 llvm::Value* this_addr,
2279 uint32_t dex_pc,
2280 bool is_fast_path) {
2281
2282 llvm::Function* runtime_func = NULL;
2283
2284 switch (invoke_type) {
2285 case kStatic:
2286 runtime_func = irb_.GetRuntime(runtime_support::FindStaticMethodWithAccessCheck);
2287 break;
2288
2289 case kDirect:
2290 runtime_func = irb_.GetRuntime(runtime_support::FindDirectMethodWithAccessCheck);
2291 break;
2292
2293 case kVirtual:
2294 runtime_func = irb_.GetRuntime(runtime_support::FindVirtualMethodWithAccessCheck);
2295 break;
2296
2297 case kSuper:
2298 runtime_func = irb_.GetRuntime(runtime_support::FindSuperMethodWithAccessCheck);
2299 break;
2300
2301 case kInterface:
2302 if (is_fast_path) {
2303 runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethod);
2304 } else {
2305 runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethodWithAccessCheck);
2306 }
2307 break;
2308 }
2309
2310 llvm::Value* callee_method_idx_value = irb_.getInt32(callee_method_idx);
2311
2312 if (this_addr == NULL) {
2313 DCHECK_EQ(invoke_type, kStatic);
2314 this_addr = irb_.getJNull();
2315 }
2316
2317 llvm::Value* caller_method_object_addr = EmitLoadMethodObjectAddr();
2318
2319 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2320
2321 EmitUpdateDexPC(dex_pc);
2322
2323 llvm::Value* callee_method_object_addr =
2324 irb_.CreateCall4(runtime_func,
2325 callee_method_idx_value,
2326 this_addr,
2327 caller_method_object_addr,
2328 thread_object_addr);
2329
2330 EmitGuard_ExceptionLandingPad(dex_pc);
2331
2332 return callee_method_object_addr;
2333}
2334
TDYa1275e869b62012-07-25 00:45:39 -07002335void GBCExpanderPass::EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr) {
2336 // Using runtime support, let the target can override by InlineAssembly.
2337 irb_.Runtime().EmitMarkGCCard(value, target_addr);
2338}
2339
2340void GBCExpanderPass::EmitUpdateDexPC(uint32_t dex_pc) {
2341 irb_.StoreToObjectOffset(shadow_frame_,
2342 ShadowFrame::DexPCOffset(),
2343 irb_.getInt32(dex_pc),
2344 kTBAAShadowFrame);
2345}
2346
2347void GBCExpanderPass::EmitGuard_DivZeroException(uint32_t dex_pc,
2348 llvm::Value* denominator,
2349 JType op_jty) {
2350 DCHECK(op_jty == kInt || op_jty == kLong) << op_jty;
2351
2352 llvm::Constant* zero = irb_.getJZero(op_jty);
2353
2354 llvm::Value* equal_zero = irb_.CreateICmpEQ(denominator, zero);
2355
2356 llvm::BasicBlock* block_exception = CreateBasicBlockWithDexPC(dex_pc, "div0");
2357
2358 llvm::BasicBlock* block_continue = CreateBasicBlockWithDexPC(dex_pc, "cont");
2359
2360 irb_.CreateCondBr(equal_zero, block_exception, block_continue, kUnlikely);
2361
2362 irb_.SetInsertPoint(block_exception);
2363 EmitUpdateDexPC(dex_pc);
2364 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowDivZeroException));
2365 EmitBranchExceptionLandingPad(dex_pc);
2366
2367 irb_.SetInsertPoint(block_continue);
2368}
2369
2370void GBCExpanderPass::EmitGuard_NullPointerException(uint32_t dex_pc,
2371 llvm::Value* object) {
2372 llvm::Value* equal_null = irb_.CreateICmpEQ(object, irb_.getJNull());
2373
2374 llvm::BasicBlock* block_exception =
2375 CreateBasicBlockWithDexPC(dex_pc, "nullp");
2376
2377 llvm::BasicBlock* block_continue =
2378 CreateBasicBlockWithDexPC(dex_pc, "cont");
2379
2380 irb_.CreateCondBr(equal_null, block_exception, block_continue, kUnlikely);
2381
2382 irb_.SetInsertPoint(block_exception);
2383 EmitUpdateDexPC(dex_pc);
2384 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowNullPointerException),
2385 irb_.getInt32(dex_pc));
2386 EmitBranchExceptionLandingPad(dex_pc);
2387
2388 irb_.SetInsertPoint(block_continue);
2389}
2390
2391void
2392GBCExpanderPass::EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc,
2393 llvm::Value* array,
2394 llvm::Value* index) {
2395 llvm::Value* array_len = EmitLoadArrayLength(array);
2396
2397 llvm::Value* cmp = irb_.CreateICmpUGE(index, array_len);
2398
2399 llvm::BasicBlock* block_exception =
2400 CreateBasicBlockWithDexPC(dex_pc, "overflow");
2401
2402 llvm::BasicBlock* block_continue =
2403 CreateBasicBlockWithDexPC(dex_pc, "cont");
2404
2405 irb_.CreateCondBr(cmp, block_exception, block_continue, kUnlikely);
2406
2407 irb_.SetInsertPoint(block_exception);
2408
2409 EmitUpdateDexPC(dex_pc);
2410 irb_.CreateCall2(irb_.GetRuntime(runtime_support::ThrowIndexOutOfBounds), index, array_len);
2411 EmitBranchExceptionLandingPad(dex_pc);
2412
2413 irb_.SetInsertPoint(block_continue);
2414}
2415
2416void GBCExpanderPass::EmitGuard_ArrayException(uint32_t dex_pc,
2417 llvm::Value* array,
2418 llvm::Value* index) {
2419 EmitGuard_NullPointerException(dex_pc, array);
2420 EmitGuard_ArrayIndexOutOfBoundsException(dex_pc, array, index);
2421}
2422
2423llvm::FunctionType* GBCExpanderPass::GetFunctionType(uint32_t method_idx,
2424 bool is_static) {
2425 // Get method signature
2426 DexFile::MethodId const& method_id = dex_file_->GetMethodId(method_idx);
2427
2428 uint32_t shorty_size;
2429 const char* shorty = dex_file_->GetMethodShorty(method_id, &shorty_size);
2430 CHECK_GE(shorty_size, 1u);
2431
2432 // Get return type
2433 llvm::Type* ret_type = irb_.getJType(shorty[0], kAccurate);
2434
2435 // Get argument type
2436 std::vector<llvm::Type*> args_type;
2437
2438 args_type.push_back(irb_.getJObjectTy()); // method object pointer
2439
2440 if (!is_static) {
2441 args_type.push_back(irb_.getJType('L', kAccurate)); // "this" object pointer
2442 }
2443
2444 for (uint32_t i = 1; i < shorty_size; ++i) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002445#if defined(ART_USE_QUICK_COMPILER)
2446 char shorty_type = shorty[i];
2447 switch(shorty_type) {
2448 case 'Z' : shorty_type = 'I'; break;
2449 case 'B' : shorty_type = 'I'; break;
2450 case 'S' : shorty_type = 'I'; break;
2451 case 'C' : shorty_type = 'I'; break;
2452 default: break;
2453 }
2454 args_type.push_back(irb_.getJType(shorty_type, kAccurate));
2455#else
TDYa1275e869b62012-07-25 00:45:39 -07002456 args_type.push_back(irb_.getJType(shorty[i], kAccurate));
TDYa127f71bf5a2012-07-29 20:09:52 -07002457#endif
TDYa1275e869b62012-07-25 00:45:39 -07002458 }
2459
2460 return llvm::FunctionType::get(ret_type, args_type, false);
2461}
2462
2463
2464llvm::BasicBlock* GBCExpanderPass::
2465CreateBasicBlockWithDexPC(uint32_t dex_pc, const char* postfix) {
2466 std::string name;
2467
2468#if !defined(NDEBUG)
2469 StringAppendF(&name, "B%04x.%s", dex_pc, postfix);
2470#endif
2471
2472 return llvm::BasicBlock::Create(context_, name, func_);
2473}
2474
2475llvm::BasicBlock* GBCExpanderPass::GetBasicBlock(uint32_t dex_pc) {
2476 DCHECK(dex_pc < code_item_->insns_size_in_code_units_);
2477
2478 return basic_blocks_[dex_pc];
2479}
2480
2481int32_t GBCExpanderPass::GetTryItemOffset(uint32_t dex_pc) {
2482 int32_t min = 0;
2483 int32_t max = code_item_->tries_size_ - 1;
2484
2485 while (min <= max) {
2486 int32_t mid = min + (max - min) / 2;
2487
2488 const DexFile::TryItem* ti = DexFile::GetTryItems(*code_item_, mid);
2489 uint32_t start = ti->start_addr_;
2490 uint32_t end = start + ti->insn_count_;
2491
2492 if (dex_pc < start) {
2493 max = mid - 1;
2494 } else if (dex_pc >= end) {
2495 min = mid + 1;
2496 } else {
2497 return mid; // found
2498 }
2499 }
2500
2501 return -1; // not found
2502}
2503
2504llvm::BasicBlock* GBCExpanderPass::GetLandingPadBasicBlock(uint32_t dex_pc) {
2505 // Find the try item for this address in this method
2506 int32_t ti_offset = GetTryItemOffset(dex_pc);
2507
2508 if (ti_offset == -1) {
2509 return NULL; // No landing pad is available for this address.
2510 }
2511
2512 // Check for the existing landing pad basic block
2513 DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset));
2514 llvm::BasicBlock* block_lpad = basic_block_landing_pads_[ti_offset];
2515
2516 if (block_lpad) {
2517 // We have generated landing pad for this try item already. Return the
2518 // same basic block.
2519 return block_lpad;
2520 }
2521
2522 // Get try item from code item
2523 const DexFile::TryItem* ti = DexFile::GetTryItems(*code_item_, ti_offset);
2524
2525 std::string lpadname;
2526
2527#if !defined(NDEBUG)
2528 StringAppendF(&lpadname, "lpad%d_%04x_to_%04x", ti_offset, ti->start_addr_, ti->handler_off_);
2529#endif
2530
2531 // Create landing pad basic block
2532 block_lpad = llvm::BasicBlock::Create(context_, lpadname, func_);
2533
2534 // Change IRBuilder insert point
2535 llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
2536 irb_.SetInsertPoint(block_lpad);
2537
2538 // Find catch block with matching type
2539 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2540
2541 llvm::Value* ti_offset_value = irb_.getInt32(ti_offset);
2542
2543 llvm::Value* catch_handler_index_value =
2544 irb_.CreateCall2(irb_.GetRuntime(runtime_support::FindCatchBlock),
2545 method_object_addr, ti_offset_value);
2546
2547 // Switch instruction (Go to unwind basic block by default)
2548 llvm::SwitchInst* sw =
2549 irb_.CreateSwitch(catch_handler_index_value, GetUnwindBasicBlock());
2550
2551 // Cases with matched catch block
2552 CatchHandlerIterator iter(*code_item_, ti->start_addr_);
2553
2554 for (uint32_t c = 0; iter.HasNext(); iter.Next(), ++c) {
2555 sw->addCase(irb_.getInt32(c), GetBasicBlock(iter.GetHandlerAddress()));
2556 }
2557
2558 // Restore the orignal insert point for IRBuilder
2559 irb_.restoreIP(irb_ip_original);
2560
2561 // Cache this landing pad
2562 DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset));
2563 basic_block_landing_pads_[ti_offset] = block_lpad;
2564
2565 return block_lpad;
2566}
2567
2568llvm::BasicBlock* GBCExpanderPass::GetUnwindBasicBlock() {
2569 // Check the existing unwinding baisc block block
2570 if (basic_block_unwind_ != NULL) {
2571 return basic_block_unwind_;
2572 }
2573
2574 // Create new basic block for unwinding
2575 basic_block_unwind_ =
2576 llvm::BasicBlock::Create(context_, "exception_unwind", func_);
2577
2578 // Change IRBuilder insert point
2579 llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
2580 irb_.SetInsertPoint(basic_block_unwind_);
2581
2582 // Pop the shadow frame
2583 Expand_PopShadowFrame();
2584
2585 // Emit the code to return default value (zero) for the given return type.
2586 char ret_shorty = oat_compilation_unit_->GetShorty()[0];
2587 if (ret_shorty == 'V') {
2588 irb_.CreateRetVoid();
2589 } else {
2590 irb_.CreateRet(irb_.getJZero(ret_shorty));
2591 }
2592
2593 // Restore the orignal insert point for IRBuilder
2594 irb_.restoreIP(irb_ip_original);
2595
2596 return basic_block_unwind_;
2597}
2598
2599void GBCExpanderPass::EmitBranchExceptionLandingPad(uint32_t dex_pc) {
2600 if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) {
TDYa127aa558872012-08-16 05:11:07 -07002601 landing_pad_phi_mapping_[lpad].push_back(std::make_pair(old_basic_block_,
2602 irb_.GetInsertBlock()));
TDYa1275e869b62012-07-25 00:45:39 -07002603 irb_.CreateBr(lpad);
2604 } else {
2605 irb_.CreateBr(GetUnwindBasicBlock());
2606 }
2607}
2608
2609void GBCExpanderPass::EmitGuard_ExceptionLandingPad(uint32_t dex_pc) {
2610 llvm::Value* exception_pending = irb_.Runtime().EmitIsExceptionPending();
2611
2612 llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont");
2613
2614 if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) {
TDYa127aa558872012-08-16 05:11:07 -07002615 landing_pad_phi_mapping_[lpad].push_back(std::make_pair(old_basic_block_,
2616 irb_.GetInsertBlock()));
TDYa1275e869b62012-07-25 00:45:39 -07002617 irb_.CreateCondBr(exception_pending, lpad, block_cont, kUnlikely);
2618 } else {
2619 irb_.CreateCondBr(exception_pending, GetUnwindBasicBlock(), block_cont, kUnlikely);
2620 }
2621
2622 irb_.SetInsertPoint(block_cont);
2623}
2624
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002625llvm::Value*
2626GBCExpanderPass::ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id,
2627 llvm::CallInst& call_inst) {
2628 switch (intr_id) {
2629 //==- Thread -----------------------------------------------------------==//
2630 case IntrinsicHelper::GetCurrentThread: {
TDYa127b672d1e2012-06-28 21:21:45 -07002631 return irb_.Runtime().EmitGetCurrentThread();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002632 }
Logan Chiend54a23d2012-07-24 11:19:23 -07002633 case IntrinsicHelper::TestSuspend:
Logan Chien75e4b602012-07-23 14:24:12 -07002634 case IntrinsicHelper::CheckSuspend: {
Logan Chiend54a23d2012-07-24 11:19:23 -07002635 Expand_TestSuspend(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002636 return NULL;
2637 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002638 case IntrinsicHelper::MarkGCCard: {
TDYa1279a129452012-07-19 03:10:08 -07002639 Expand_MarkGCCard(call_inst);
2640 return NULL;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002641 }
Logan Chien75e4b602012-07-23 14:24:12 -07002642
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002643 //==- Exception --------------------------------------------------------==//
2644 case IntrinsicHelper::ThrowException: {
2645 return ExpandToRuntime(runtime_support::ThrowException, call_inst);
2646 }
TDYa127f71bf5a2012-07-29 20:09:52 -07002647 case IntrinsicHelper::HLThrowException: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002648 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2649
2650 EmitUpdateDexPC(dex_pc);
2651
2652 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowException),
2653 call_inst.getArgOperand(0));
2654
2655 EmitGuard_ExceptionLandingPad(dex_pc);
2656 return NULL;
2657 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002658 case IntrinsicHelper::GetException: {
2659 return Expand_GetException();
2660 }
2661 case IntrinsicHelper::IsExceptionPending: {
2662 return irb_.Runtime().EmitIsExceptionPending();
2663 }
2664 case IntrinsicHelper::FindCatchBlock: {
2665 return ExpandToRuntime(runtime_support::FindCatchBlock, call_inst);
2666 }
2667 case IntrinsicHelper::ThrowDivZeroException: {
2668 return ExpandToRuntime(runtime_support::ThrowDivZeroException, call_inst);
2669 }
2670 case IntrinsicHelper::ThrowNullPointerException: {
2671 return ExpandToRuntime(runtime_support::ThrowNullPointerException, call_inst);
2672 }
2673 case IntrinsicHelper::ThrowIndexOutOfBounds: {
2674 return ExpandToRuntime(runtime_support::ThrowIndexOutOfBounds, call_inst);
2675 }
Logan Chien75e4b602012-07-23 14:24:12 -07002676
2677 //==- Const String -----------------------------------------------------==//
2678 case IntrinsicHelper::ConstString: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002679 return Expand_ConstString(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002680 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002681 case IntrinsicHelper::LoadStringFromDexCache: {
2682 return Expand_LoadStringFromDexCache(call_inst.getArgOperand(0));
2683 }
2684 case IntrinsicHelper::ResolveString: {
2685 return ExpandToRuntime(runtime_support::ResolveString, call_inst);
2686 }
Logan Chien75e4b602012-07-23 14:24:12 -07002687
2688 //==- Const Class ------------------------------------------------------==//
2689 case IntrinsicHelper::ConstClass: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002690 return Expand_ConstClass(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002691 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002692 case IntrinsicHelper::InitializeTypeAndVerifyAccess: {
2693 return ExpandToRuntime(runtime_support::InitializeTypeAndVerifyAccess, call_inst);
2694 }
2695 case IntrinsicHelper::LoadTypeFromDexCache: {
2696 return Expand_LoadTypeFromDexCache(call_inst.getArgOperand(0));
2697 }
2698 case IntrinsicHelper::InitializeType: {
2699 return ExpandToRuntime(runtime_support::InitializeType, call_inst);
2700 }
Logan Chien75e4b602012-07-23 14:24:12 -07002701
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002702 //==- Lock -------------------------------------------------------------==//
2703 case IntrinsicHelper::LockObject: {
2704 Expand_LockObject(call_inst.getArgOperand(0));
2705 return NULL;
2706 }
2707 case IntrinsicHelper::UnlockObject: {
2708 Expand_UnlockObject(call_inst.getArgOperand(0));
2709 return NULL;
2710 }
Logan Chien75e4b602012-07-23 14:24:12 -07002711
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002712 //==- Cast -------------------------------------------------------------==//
2713 case IntrinsicHelper::CheckCast: {
2714 return ExpandToRuntime(runtime_support::CheckCast, call_inst);
2715 }
Logan Chien75e4b602012-07-23 14:24:12 -07002716 case IntrinsicHelper::HLCheckCast: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002717 Expand_HLCheckCast(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002718 return NULL;
2719 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002720 case IntrinsicHelper::IsAssignable: {
2721 return ExpandToRuntime(runtime_support::IsAssignable, call_inst);
2722 }
Logan Chien75e4b602012-07-23 14:24:12 -07002723
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002724 //==- Alloc ------------------------------------------------------------==//
2725 case IntrinsicHelper::AllocObject: {
2726 return ExpandToRuntime(runtime_support::AllocObject, call_inst);
2727 }
2728 case IntrinsicHelper::AllocObjectWithAccessCheck: {
2729 return ExpandToRuntime(runtime_support::AllocObjectWithAccessCheck, call_inst);
2730 }
Logan Chien75e4b602012-07-23 14:24:12 -07002731
2732 //==- Instance ---------------------------------------------------------==//
2733 case IntrinsicHelper::NewInstance: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002734 return Expand_NewInstance(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002735 }
2736 case IntrinsicHelper::InstanceOf: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002737 return Expand_InstanceOf(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002738 }
2739
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002740 //==- Array ------------------------------------------------------------==//
Logan Chien75e4b602012-07-23 14:24:12 -07002741 case IntrinsicHelper::NewArray: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002742 return Expand_NewArray(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002743 }
2744 case IntrinsicHelper::OptArrayLength: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002745 return Expand_OptArrayLength(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002746 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002747 case IntrinsicHelper::ArrayLength: {
2748 return EmitLoadArrayLength(call_inst.getArgOperand(0));
2749 }
2750 case IntrinsicHelper::AllocArray: {
2751 return ExpandToRuntime(runtime_support::AllocArray, call_inst);
2752 }
2753 case IntrinsicHelper::AllocArrayWithAccessCheck: {
2754 return ExpandToRuntime(runtime_support::AllocArrayWithAccessCheck,
2755 call_inst);
2756 }
2757 case IntrinsicHelper::CheckAndAllocArray: {
2758 return ExpandToRuntime(runtime_support::CheckAndAllocArray, call_inst);
2759 }
2760 case IntrinsicHelper::CheckAndAllocArrayWithAccessCheck: {
2761 return ExpandToRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck,
2762 call_inst);
2763 }
2764 case IntrinsicHelper::ArrayGet: {
2765 return Expand_ArrayGet(call_inst.getArgOperand(0),
2766 call_inst.getArgOperand(1),
2767 kInt);
2768 }
2769 case IntrinsicHelper::ArrayGetWide: {
2770 return Expand_ArrayGet(call_inst.getArgOperand(0),
2771 call_inst.getArgOperand(1),
2772 kLong);
2773 }
2774 case IntrinsicHelper::ArrayGetObject: {
2775 return Expand_ArrayGet(call_inst.getArgOperand(0),
2776 call_inst.getArgOperand(1),
2777 kObject);
2778 }
2779 case IntrinsicHelper::ArrayGetBoolean: {
2780 return Expand_ArrayGet(call_inst.getArgOperand(0),
2781 call_inst.getArgOperand(1),
2782 kBoolean);
2783 }
2784 case IntrinsicHelper::ArrayGetByte: {
2785 return Expand_ArrayGet(call_inst.getArgOperand(0),
2786 call_inst.getArgOperand(1),
2787 kByte);
2788 }
2789 case IntrinsicHelper::ArrayGetChar: {
2790 return Expand_ArrayGet(call_inst.getArgOperand(0),
2791 call_inst.getArgOperand(1),
2792 kChar);
2793 }
2794 case IntrinsicHelper::ArrayGetShort: {
2795 return Expand_ArrayGet(call_inst.getArgOperand(0),
2796 call_inst.getArgOperand(1),
2797 kShort);
2798 }
2799 case IntrinsicHelper::ArrayPut: {
2800 Expand_ArrayPut(call_inst.getArgOperand(0),
2801 call_inst.getArgOperand(1),
2802 call_inst.getArgOperand(2),
2803 kInt);
2804 return NULL;
2805 }
2806 case IntrinsicHelper::ArrayPutWide: {
2807 Expand_ArrayPut(call_inst.getArgOperand(0),
2808 call_inst.getArgOperand(1),
2809 call_inst.getArgOperand(2),
2810 kLong);
2811 return NULL;
2812 }
2813 case IntrinsicHelper::ArrayPutObject: {
2814 Expand_ArrayPut(call_inst.getArgOperand(0),
2815 call_inst.getArgOperand(1),
2816 call_inst.getArgOperand(2),
2817 kObject);
2818 return NULL;
2819 }
2820 case IntrinsicHelper::ArrayPutBoolean: {
2821 Expand_ArrayPut(call_inst.getArgOperand(0),
2822 call_inst.getArgOperand(1),
2823 call_inst.getArgOperand(2),
2824 kBoolean);
2825 return NULL;
2826 }
2827 case IntrinsicHelper::ArrayPutByte: {
2828 Expand_ArrayPut(call_inst.getArgOperand(0),
2829 call_inst.getArgOperand(1),
2830 call_inst.getArgOperand(2),
2831 kByte);
2832 return NULL;
2833 }
2834 case IntrinsicHelper::ArrayPutChar: {
2835 Expand_ArrayPut(call_inst.getArgOperand(0),
2836 call_inst.getArgOperand(1),
2837 call_inst.getArgOperand(2),
2838 kChar);
2839 return NULL;
2840 }
2841 case IntrinsicHelper::ArrayPutShort: {
2842 Expand_ArrayPut(call_inst.getArgOperand(0),
2843 call_inst.getArgOperand(1),
2844 call_inst.getArgOperand(2),
2845 kShort);
2846 return NULL;
2847 }
2848 case IntrinsicHelper::CheckPutArrayElement: {
2849 return ExpandToRuntime(runtime_support::CheckPutArrayElement, call_inst);
2850 }
2851 case IntrinsicHelper::FilledNewArray: {
2852 Expand_FilledNewArray(call_inst);
2853 return NULL;
2854 }
2855 case IntrinsicHelper::FillArrayData: {
2856 return ExpandToRuntime(runtime_support::FillArrayData, call_inst);
2857 }
Logan Chien75e4b602012-07-23 14:24:12 -07002858 case IntrinsicHelper::HLFillArrayData: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002859 Expand_HLFillArrayData(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002860 return NULL;
2861 }
2862 case IntrinsicHelper::HLFilledNewArray: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002863 return Expand_HLFilledNewArray(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002864 }
2865
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002866 //==- Instance Field ---------------------------------------------------==//
2867 case IntrinsicHelper::InstanceFieldGet:
2868 case IntrinsicHelper::InstanceFieldGetBoolean:
2869 case IntrinsicHelper::InstanceFieldGetByte:
2870 case IntrinsicHelper::InstanceFieldGetChar:
2871 case IntrinsicHelper::InstanceFieldGetShort: {
2872 return ExpandToRuntime(runtime_support::Get32Instance, call_inst);
2873 }
2874 case IntrinsicHelper::InstanceFieldGetWide: {
2875 return ExpandToRuntime(runtime_support::Get64Instance, call_inst);
2876 }
2877 case IntrinsicHelper::InstanceFieldGetObject: {
2878 return ExpandToRuntime(runtime_support::GetObjectInstance, call_inst);
2879 }
2880 case IntrinsicHelper::InstanceFieldGetFast: {
2881 return Expand_IGetFast(call_inst.getArgOperand(0),
2882 call_inst.getArgOperand(1),
2883 call_inst.getArgOperand(2),
2884 kInt);
2885 }
2886 case IntrinsicHelper::InstanceFieldGetWideFast: {
2887 return Expand_IGetFast(call_inst.getArgOperand(0),
2888 call_inst.getArgOperand(1),
2889 call_inst.getArgOperand(2),
2890 kLong);
2891 }
2892 case IntrinsicHelper::InstanceFieldGetObjectFast: {
2893 return Expand_IGetFast(call_inst.getArgOperand(0),
2894 call_inst.getArgOperand(1),
2895 call_inst.getArgOperand(2),
2896 kObject);
2897 }
2898 case IntrinsicHelper::InstanceFieldGetBooleanFast: {
2899 return Expand_IGetFast(call_inst.getArgOperand(0),
2900 call_inst.getArgOperand(1),
2901 call_inst.getArgOperand(2),
2902 kBoolean);
2903 }
2904 case IntrinsicHelper::InstanceFieldGetByteFast: {
2905 return Expand_IGetFast(call_inst.getArgOperand(0),
2906 call_inst.getArgOperand(1),
2907 call_inst.getArgOperand(2),
2908 kByte);
2909 }
2910 case IntrinsicHelper::InstanceFieldGetCharFast: {
2911 return Expand_IGetFast(call_inst.getArgOperand(0),
2912 call_inst.getArgOperand(1),
2913 call_inst.getArgOperand(2),
2914 kChar);
2915 }
2916 case IntrinsicHelper::InstanceFieldGetShortFast: {
2917 return Expand_IGetFast(call_inst.getArgOperand(0),
2918 call_inst.getArgOperand(1),
2919 call_inst.getArgOperand(2),
2920 kShort);
2921 }
2922 case IntrinsicHelper::InstanceFieldPut:
2923 case IntrinsicHelper::InstanceFieldPutBoolean:
2924 case IntrinsicHelper::InstanceFieldPutByte:
2925 case IntrinsicHelper::InstanceFieldPutChar:
2926 case IntrinsicHelper::InstanceFieldPutShort: {
2927 return ExpandToRuntime(runtime_support::Set32Instance, call_inst);
2928 }
2929 case IntrinsicHelper::InstanceFieldPutWide: {
2930 return ExpandToRuntime(runtime_support::Set64Instance, call_inst);
2931 }
2932 case IntrinsicHelper::InstanceFieldPutObject: {
2933 return ExpandToRuntime(runtime_support::SetObjectInstance, call_inst);
2934 }
2935 case IntrinsicHelper::InstanceFieldPutFast: {
2936 Expand_IPutFast(call_inst.getArgOperand(0),
2937 call_inst.getArgOperand(1),
2938 call_inst.getArgOperand(2),
2939 call_inst.getArgOperand(3),
2940 kInt);
2941 return NULL;
2942 }
2943 case IntrinsicHelper::InstanceFieldPutWideFast: {
2944 Expand_IPutFast(call_inst.getArgOperand(0),
2945 call_inst.getArgOperand(1),
2946 call_inst.getArgOperand(2),
2947 call_inst.getArgOperand(3),
2948 kLong);
2949 return NULL;
2950 }
2951 case IntrinsicHelper::InstanceFieldPutObjectFast: {
2952 Expand_IPutFast(call_inst.getArgOperand(0),
2953 call_inst.getArgOperand(1),
2954 call_inst.getArgOperand(2),
2955 call_inst.getArgOperand(3),
2956 kObject);
2957 return NULL;
2958 }
2959 case IntrinsicHelper::InstanceFieldPutBooleanFast: {
2960 Expand_IPutFast(call_inst.getArgOperand(0),
2961 call_inst.getArgOperand(1),
2962 call_inst.getArgOperand(2),
2963 call_inst.getArgOperand(3),
2964 kBoolean);
2965 return NULL;
2966 }
2967 case IntrinsicHelper::InstanceFieldPutByteFast: {
2968 Expand_IPutFast(call_inst.getArgOperand(0),
2969 call_inst.getArgOperand(1),
2970 call_inst.getArgOperand(2),
2971 call_inst.getArgOperand(3),
2972 kByte);
2973 return NULL;
2974 }
2975 case IntrinsicHelper::InstanceFieldPutCharFast: {
2976 Expand_IPutFast(call_inst.getArgOperand(0),
2977 call_inst.getArgOperand(1),
2978 call_inst.getArgOperand(2),
2979 call_inst.getArgOperand(3),
2980 kChar);
2981 return NULL;
2982 }
2983 case IntrinsicHelper::InstanceFieldPutShortFast: {
2984 Expand_IPutFast(call_inst.getArgOperand(0),
2985 call_inst.getArgOperand(1),
2986 call_inst.getArgOperand(2),
2987 call_inst.getArgOperand(3),
2988 kShort);
2989 return NULL;
2990 }
Logan Chien75e4b602012-07-23 14:24:12 -07002991
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002992 //==- Static Field -----------------------------------------------------==//
2993 case IntrinsicHelper::StaticFieldGet:
2994 case IntrinsicHelper::StaticFieldGetBoolean:
2995 case IntrinsicHelper::StaticFieldGetByte:
2996 case IntrinsicHelper::StaticFieldGetChar:
2997 case IntrinsicHelper::StaticFieldGetShort: {
2998 return ExpandToRuntime(runtime_support::Get32Static, call_inst);
2999 }
3000 case IntrinsicHelper::StaticFieldGetWide: {
3001 return ExpandToRuntime(runtime_support::Get64Static, call_inst);
3002 }
3003 case IntrinsicHelper::StaticFieldGetObject: {
3004 return ExpandToRuntime(runtime_support::GetObjectStatic, call_inst);
3005 }
3006 case IntrinsicHelper::StaticFieldGetFast: {
3007 return Expand_SGetFast(call_inst.getArgOperand(0),
3008 call_inst.getArgOperand(1),
3009 call_inst.getArgOperand(2),
3010 kInt);
3011 }
3012 case IntrinsicHelper::StaticFieldGetWideFast: {
3013 return Expand_SGetFast(call_inst.getArgOperand(0),
3014 call_inst.getArgOperand(1),
3015 call_inst.getArgOperand(2),
3016 kLong);
3017 }
3018 case IntrinsicHelper::StaticFieldGetObjectFast: {
3019 return Expand_SGetFast(call_inst.getArgOperand(0),
3020 call_inst.getArgOperand(1),
3021 call_inst.getArgOperand(2),
3022 kObject);
3023 }
3024 case IntrinsicHelper::StaticFieldGetBooleanFast: {
3025 return Expand_SGetFast(call_inst.getArgOperand(0),
3026 call_inst.getArgOperand(1),
3027 call_inst.getArgOperand(2),
3028 kBoolean);
3029 }
3030 case IntrinsicHelper::StaticFieldGetByteFast: {
3031 return Expand_SGetFast(call_inst.getArgOperand(0),
3032 call_inst.getArgOperand(1),
3033 call_inst.getArgOperand(2),
3034 kByte);
3035 }
3036 case IntrinsicHelper::StaticFieldGetCharFast: {
3037 return Expand_SGetFast(call_inst.getArgOperand(0),
3038 call_inst.getArgOperand(1),
3039 call_inst.getArgOperand(2),
3040 kChar);
3041 }
3042 case IntrinsicHelper::StaticFieldGetShortFast: {
3043 return Expand_SGetFast(call_inst.getArgOperand(0),
3044 call_inst.getArgOperand(1),
3045 call_inst.getArgOperand(2),
3046 kShort);
3047 }
3048 case IntrinsicHelper::StaticFieldPut:
3049 case IntrinsicHelper::StaticFieldPutBoolean:
3050 case IntrinsicHelper::StaticFieldPutByte:
3051 case IntrinsicHelper::StaticFieldPutChar:
3052 case IntrinsicHelper::StaticFieldPutShort: {
3053 return ExpandToRuntime(runtime_support::Set32Static, call_inst);
3054 }
3055 case IntrinsicHelper::StaticFieldPutWide: {
3056 return ExpandToRuntime(runtime_support::Set64Static, call_inst);
3057 }
3058 case IntrinsicHelper::StaticFieldPutObject: {
3059 return ExpandToRuntime(runtime_support::SetObjectStatic, call_inst);
3060 }
3061 case IntrinsicHelper::StaticFieldPutFast: {
3062 Expand_SPutFast(call_inst.getArgOperand(0),
3063 call_inst.getArgOperand(1),
3064 call_inst.getArgOperand(2),
3065 call_inst.getArgOperand(3),
3066 kInt);
3067 return NULL;
3068 }
3069 case IntrinsicHelper::StaticFieldPutWideFast: {
3070 Expand_SPutFast(call_inst.getArgOperand(0),
3071 call_inst.getArgOperand(1),
3072 call_inst.getArgOperand(2),
3073 call_inst.getArgOperand(3),
3074 kLong);
3075 return NULL;
3076 }
3077 case IntrinsicHelper::StaticFieldPutObjectFast: {
3078 Expand_SPutFast(call_inst.getArgOperand(0),
3079 call_inst.getArgOperand(1),
3080 call_inst.getArgOperand(2),
3081 call_inst.getArgOperand(3),
3082 kObject);
3083 return NULL;
3084 }
3085 case IntrinsicHelper::StaticFieldPutBooleanFast: {
3086 Expand_SPutFast(call_inst.getArgOperand(0),
3087 call_inst.getArgOperand(1),
3088 call_inst.getArgOperand(2),
3089 call_inst.getArgOperand(3),
3090 kBoolean);
3091 return NULL;
3092 }
3093 case IntrinsicHelper::StaticFieldPutByteFast: {
3094 Expand_SPutFast(call_inst.getArgOperand(0),
3095 call_inst.getArgOperand(1),
3096 call_inst.getArgOperand(2),
3097 call_inst.getArgOperand(3),
3098 kByte);
3099 return NULL;
3100 }
3101 case IntrinsicHelper::StaticFieldPutCharFast: {
3102 Expand_SPutFast(call_inst.getArgOperand(0),
3103 call_inst.getArgOperand(1),
3104 call_inst.getArgOperand(2),
3105 call_inst.getArgOperand(3),
3106 kChar);
3107 return NULL;
3108 }
3109 case IntrinsicHelper::StaticFieldPutShortFast: {
3110 Expand_SPutFast(call_inst.getArgOperand(0),
3111 call_inst.getArgOperand(1),
3112 call_inst.getArgOperand(2),
3113 call_inst.getArgOperand(3),
3114 kShort);
3115 return NULL;
3116 }
3117 case IntrinsicHelper::LoadDeclaringClassSSB: {
3118 return Expand_LoadDeclaringClassSSB(call_inst.getArgOperand(0));
3119 }
3120 case IntrinsicHelper::LoadClassSSBFromDexCache: {
3121 return Expand_LoadClassSSBFromDexCache(call_inst.getArgOperand(0));
3122 }
3123 case IntrinsicHelper::InitializeAndLoadClassSSB: {
3124 return ExpandToRuntime(runtime_support::InitializeStaticStorage, call_inst);
3125 }
Logan Chien75e4b602012-07-23 14:24:12 -07003126
3127 //==- High-level Array -------------------------------------------------==//
3128 case IntrinsicHelper::HLArrayGet: {
TDYa1275a26d442012-07-26 18:58:38 -07003129 return Expand_HLArrayGet(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003130 }
3131 case IntrinsicHelper::HLArrayGetBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003132 return Expand_HLArrayGet(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003133 }
3134 case IntrinsicHelper::HLArrayGetByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003135 return Expand_HLArrayGet(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003136 }
3137 case IntrinsicHelper::HLArrayGetChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003138 return Expand_HLArrayGet(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003139 }
3140 case IntrinsicHelper::HLArrayGetShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003141 return Expand_HLArrayGet(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003142 }
3143 case IntrinsicHelper::HLArrayGetFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003144 return Expand_HLArrayGet(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003145 }
3146 case IntrinsicHelper::HLArrayGetWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003147 return Expand_HLArrayGet(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003148 }
3149 case IntrinsicHelper::HLArrayGetDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003150 return Expand_HLArrayGet(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003151 }
3152 case IntrinsicHelper::HLArrayGetObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003153 return Expand_HLArrayGet(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003154 }
3155 case IntrinsicHelper::HLArrayPut: {
TDYa1275a26d442012-07-26 18:58:38 -07003156 Expand_HLArrayPut(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003157 return NULL;
3158 }
3159 case IntrinsicHelper::HLArrayPutBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003160 Expand_HLArrayPut(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003161 return NULL;
3162 }
3163 case IntrinsicHelper::HLArrayPutByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003164 Expand_HLArrayPut(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003165 return NULL;
3166 }
3167 case IntrinsicHelper::HLArrayPutChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003168 Expand_HLArrayPut(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003169 return NULL;
3170 }
3171 case IntrinsicHelper::HLArrayPutShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003172 Expand_HLArrayPut(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003173 return NULL;
3174 }
3175 case IntrinsicHelper::HLArrayPutFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003176 Expand_HLArrayPut(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003177 return NULL;
3178 }
3179 case IntrinsicHelper::HLArrayPutWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003180 Expand_HLArrayPut(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003181 return NULL;
3182 }
3183 case IntrinsicHelper::HLArrayPutDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003184 Expand_HLArrayPut(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003185 return NULL;
3186 }
3187 case IntrinsicHelper::HLArrayPutObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003188 Expand_HLArrayPut(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003189 return NULL;
3190 }
3191
3192 //==- High-level Instance ----------------------------------------------==//
3193 case IntrinsicHelper::HLIGet: {
TDYa1275e869b62012-07-25 00:45:39 -07003194 return Expand_HLIGet(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003195 }
3196 case IntrinsicHelper::HLIGetBoolean: {
TDYa1275e869b62012-07-25 00:45:39 -07003197 return Expand_HLIGet(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003198 }
3199 case IntrinsicHelper::HLIGetByte: {
TDYa1275e869b62012-07-25 00:45:39 -07003200 return Expand_HLIGet(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003201 }
3202 case IntrinsicHelper::HLIGetChar: {
TDYa1275e869b62012-07-25 00:45:39 -07003203 return Expand_HLIGet(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003204 }
3205 case IntrinsicHelper::HLIGetShort: {
TDYa1275e869b62012-07-25 00:45:39 -07003206 return Expand_HLIGet(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003207 }
3208 case IntrinsicHelper::HLIGetFloat: {
TDYa1275e869b62012-07-25 00:45:39 -07003209 return Expand_HLIGet(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003210 }
3211 case IntrinsicHelper::HLIGetWide: {
TDYa1275e869b62012-07-25 00:45:39 -07003212 return Expand_HLIGet(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003213 }
3214 case IntrinsicHelper::HLIGetDouble: {
TDYa1275e869b62012-07-25 00:45:39 -07003215 return Expand_HLIGet(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003216 }
3217 case IntrinsicHelper::HLIGetObject: {
TDYa1275e869b62012-07-25 00:45:39 -07003218 return Expand_HLIGet(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003219 }
3220 case IntrinsicHelper::HLIPut: {
TDYa1275e869b62012-07-25 00:45:39 -07003221 Expand_HLIPut(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003222 return NULL;
3223 }
3224 case IntrinsicHelper::HLIPutBoolean: {
TDYa1275e869b62012-07-25 00:45:39 -07003225 Expand_HLIPut(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003226 return NULL;
3227 }
3228 case IntrinsicHelper::HLIPutByte: {
TDYa1275e869b62012-07-25 00:45:39 -07003229 Expand_HLIPut(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003230 return NULL;
3231 }
3232 case IntrinsicHelper::HLIPutChar: {
TDYa1275e869b62012-07-25 00:45:39 -07003233 Expand_HLIPut(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003234 return NULL;
3235 }
3236 case IntrinsicHelper::HLIPutShort: {
TDYa1275e869b62012-07-25 00:45:39 -07003237 Expand_HLIPut(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003238 return NULL;
3239 }
3240 case IntrinsicHelper::HLIPutFloat: {
TDYa1275e869b62012-07-25 00:45:39 -07003241 Expand_HLIPut(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003242 return NULL;
3243 }
3244 case IntrinsicHelper::HLIPutWide: {
TDYa1275e869b62012-07-25 00:45:39 -07003245 Expand_HLIPut(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003246 return NULL;
3247 }
3248 case IntrinsicHelper::HLIPutDouble: {
TDYa1275e869b62012-07-25 00:45:39 -07003249 Expand_HLIPut(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003250 return NULL;
3251 }
3252 case IntrinsicHelper::HLIPutObject: {
TDYa1275e869b62012-07-25 00:45:39 -07003253 Expand_HLIPut(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003254 return NULL;
3255 }
3256
3257 //==- High-level Invoke ------------------------------------------------==//
TDYa127f71bf5a2012-07-29 20:09:52 -07003258 case IntrinsicHelper::HLInvokeVoid:
3259 case IntrinsicHelper::HLInvokeObj:
3260 case IntrinsicHelper::HLInvokeInt:
3261 case IntrinsicHelper::HLInvokeFloat:
3262 case IntrinsicHelper::HLInvokeLong:
Logan Chien75e4b602012-07-23 14:24:12 -07003263 case IntrinsicHelper::HLInvokeDouble: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003264 return Expand_HLInvoke(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003265 }
3266
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003267 //==- Invoke -----------------------------------------------------------==//
3268 case IntrinsicHelper::FindStaticMethodWithAccessCheck: {
3269 return ExpandToRuntime(runtime_support::FindStaticMethodWithAccessCheck, call_inst);
3270 }
3271 case IntrinsicHelper::FindDirectMethodWithAccessCheck: {
3272 return ExpandToRuntime(runtime_support::FindDirectMethodWithAccessCheck, call_inst);
3273 }
3274 case IntrinsicHelper::FindVirtualMethodWithAccessCheck: {
3275 return ExpandToRuntime(runtime_support::FindVirtualMethodWithAccessCheck, call_inst);
3276 }
3277 case IntrinsicHelper::FindSuperMethodWithAccessCheck: {
3278 return ExpandToRuntime(runtime_support::FindSuperMethodWithAccessCheck, call_inst);
3279 }
3280 case IntrinsicHelper::FindInterfaceMethodWithAccessCheck: {
3281 return ExpandToRuntime(runtime_support::FindInterfaceMethodWithAccessCheck, call_inst);
3282 }
3283 case IntrinsicHelper::GetSDCalleeMethodObjAddrFast: {
3284 return Expand_GetSDCalleeMethodObjAddrFast(call_inst.getArgOperand(0));
3285 }
3286 case IntrinsicHelper::GetVirtualCalleeMethodObjAddrFast: {
3287 return Expand_GetVirtualCalleeMethodObjAddrFast(
3288 call_inst.getArgOperand(0), call_inst.getArgOperand(1));
3289 }
3290 case IntrinsicHelper::GetInterfaceCalleeMethodObjAddrFast: {
3291 return ExpandToRuntime(runtime_support::FindInterfaceMethod, call_inst);
3292 }
3293 case IntrinsicHelper::InvokeRetVoid:
3294 case IntrinsicHelper::InvokeRetBoolean:
3295 case IntrinsicHelper::InvokeRetByte:
3296 case IntrinsicHelper::InvokeRetChar:
3297 case IntrinsicHelper::InvokeRetShort:
3298 case IntrinsicHelper::InvokeRetInt:
3299 case IntrinsicHelper::InvokeRetLong:
3300 case IntrinsicHelper::InvokeRetFloat:
3301 case IntrinsicHelper::InvokeRetDouble:
3302 case IntrinsicHelper::InvokeRetObject: {
3303 return Expand_Invoke(call_inst);
3304 }
Logan Chien75e4b602012-07-23 14:24:12 -07003305
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003306 //==- Math -------------------------------------------------------------==//
3307 case IntrinsicHelper::DivInt: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003308 return Expand_DivRem(call_inst, /* is_div */true, kInt);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003309 }
3310 case IntrinsicHelper::RemInt: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003311 return Expand_DivRem(call_inst, /* is_div */false, kInt);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003312 }
3313 case IntrinsicHelper::DivLong: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003314 return Expand_DivRem(call_inst, /* is_div */true, kLong);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003315 }
3316 case IntrinsicHelper::RemLong: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003317 return Expand_DivRem(call_inst, /* is_div */false, kLong);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003318 }
3319 case IntrinsicHelper::D2L: {
3320 return ExpandToRuntime(runtime_support::art_d2l, call_inst);
3321 }
3322 case IntrinsicHelper::D2I: {
3323 return ExpandToRuntime(runtime_support::art_d2i, call_inst);
3324 }
3325 case IntrinsicHelper::F2L: {
3326 return ExpandToRuntime(runtime_support::art_f2l, call_inst);
3327 }
3328 case IntrinsicHelper::F2I: {
3329 return ExpandToRuntime(runtime_support::art_f2i, call_inst);
3330 }
Logan Chien75e4b602012-07-23 14:24:12 -07003331
3332 //==- High-level Static ------------------------------------------------==//
3333 case IntrinsicHelper::HLSget: {
TDYa1275a26d442012-07-26 18:58:38 -07003334 return Expand_HLSget(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003335 }
3336 case IntrinsicHelper::HLSgetBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003337 return Expand_HLSget(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003338 }
3339 case IntrinsicHelper::HLSgetByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003340 return Expand_HLSget(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003341 }
3342 case IntrinsicHelper::HLSgetChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003343 return Expand_HLSget(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003344 }
3345 case IntrinsicHelper::HLSgetShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003346 return Expand_HLSget(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003347 }
3348 case IntrinsicHelper::HLSgetFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003349 return Expand_HLSget(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003350 }
3351 case IntrinsicHelper::HLSgetWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003352 return Expand_HLSget(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003353 }
3354 case IntrinsicHelper::HLSgetDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003355 return Expand_HLSget(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003356 }
3357 case IntrinsicHelper::HLSgetObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003358 return Expand_HLSget(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003359 }
3360 case IntrinsicHelper::HLSput: {
TDYa1275a26d442012-07-26 18:58:38 -07003361 Expand_HLSput(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003362 return NULL;
3363 }
3364 case IntrinsicHelper::HLSputBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003365 Expand_HLSput(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003366 return NULL;
3367 }
3368 case IntrinsicHelper::HLSputByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003369 Expand_HLSput(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003370 return NULL;
3371 }
3372 case IntrinsicHelper::HLSputChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003373 Expand_HLSput(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003374 return NULL;
3375 }
3376 case IntrinsicHelper::HLSputShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003377 Expand_HLSput(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003378 return NULL;
3379 }
3380 case IntrinsicHelper::HLSputFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003381 Expand_HLSput(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003382 return NULL;
3383 }
3384 case IntrinsicHelper::HLSputWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003385 Expand_HLSput(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003386 return NULL;
3387 }
3388 case IntrinsicHelper::HLSputDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003389 Expand_HLSput(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003390 return NULL;
3391 }
3392 case IntrinsicHelper::HLSputObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003393 Expand_HLSput(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003394 return NULL;
3395 }
3396
3397 //==- High-level Monitor -----------------------------------------------==//
3398 case IntrinsicHelper::MonitorEnter: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003399 Expand_MonitorEnter(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003400 return NULL;
3401 }
3402 case IntrinsicHelper::MonitorExit: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003403 Expand_MonitorExit(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003404 return NULL;
3405 }
3406
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003407 //==- Shadow Frame -----------------------------------------------------==//
3408 case IntrinsicHelper::AllocaShadowFrame: {
3409 Expand_AllocaShadowFrame(call_inst.getArgOperand(0));
3410 return NULL;
3411 }
3412 case IntrinsicHelper::SetShadowFrameEntry: {
3413 Expand_SetShadowFrameEntry(call_inst.getArgOperand(0),
3414 call_inst.getArgOperand(1));
3415 return NULL;
3416 }
3417 case IntrinsicHelper::PopShadowFrame: {
3418 Expand_PopShadowFrame();
3419 return NULL;
3420 }
3421 case IntrinsicHelper::UpdateDexPC: {
3422 Expand_UpdateDexPC(call_inst.getArgOperand(0));
3423 return NULL;
3424 }
TDYa127a1b21852012-07-23 03:20:39 -07003425
Logan Chien75e4b602012-07-23 14:24:12 -07003426 //==- Comparison -------------------------------------------------------==//
3427 case IntrinsicHelper::CmplFloat:
3428 case IntrinsicHelper::CmplDouble: {
3429 return Expand_FPCompare(call_inst.getArgOperand(0),
3430 call_inst.getArgOperand(1),
3431 false);
3432 }
3433 case IntrinsicHelper::CmpgFloat:
3434 case IntrinsicHelper::CmpgDouble: {
3435 return Expand_FPCompare(call_inst.getArgOperand(0),
3436 call_inst.getArgOperand(1),
3437 true);
3438 }
3439 case IntrinsicHelper::CmpLong: {
3440 return Expand_LongCompare(call_inst.getArgOperand(0),
3441 call_inst.getArgOperand(1));
3442 }
TDYa127a1b21852012-07-23 03:20:39 -07003443
Logan Chien75e4b602012-07-23 14:24:12 -07003444 //==- Switch -----------------------------------------------------------==//
3445 case greenland::IntrinsicHelper::SparseSwitch: {
TDYa1275e869b62012-07-25 00:45:39 -07003446 // Nothing to be done.
Logan Chien75e4b602012-07-23 14:24:12 -07003447 return NULL;
3448 }
3449 case greenland::IntrinsicHelper::PackedSwitch: {
TDYa1275e869b62012-07-25 00:45:39 -07003450 // Nothing to be done.
Logan Chien75e4b602012-07-23 14:24:12 -07003451 return NULL;
3452 }
3453
3454 //==- Const ------------------------------------------------------------==//
Logan Chiend54a23d2012-07-24 11:19:23 -07003455 case greenland::IntrinsicHelper::ConstInt:
Logan Chien75e4b602012-07-23 14:24:12 -07003456 case greenland::IntrinsicHelper::ConstLong: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003457 return call_inst.getArgOperand(0);
Logan Chien75e4b602012-07-23 14:24:12 -07003458 }
3459 case greenland::IntrinsicHelper::ConstFloat: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003460 return irb_.CreateBitCast(call_inst.getArgOperand(0),
3461 irb_.getJFloatTy());
Logan Chien75e4b602012-07-23 14:24:12 -07003462 }
3463 case greenland::IntrinsicHelper::ConstDouble: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003464 return irb_.CreateBitCast(call_inst.getArgOperand(0),
3465 irb_.getJDoubleTy());
3466 }
3467 case greenland::IntrinsicHelper::ConstObj: {
3468 LOG(FATAL) << "ConstObj should not occur at all";
Logan Chien75e4b602012-07-23 14:24:12 -07003469 return NULL;
3470 }
3471
3472 //==- Method Info ------------------------------------------------------==//
3473 case greenland::IntrinsicHelper::MethodInfo: {
TDYa1275e869b62012-07-25 00:45:39 -07003474 // Nothing to be done.
Logan Chien75e4b602012-07-23 14:24:12 -07003475 return NULL;
3476 }
3477
3478 //==- Copy -------------------------------------------------------------==//
Logan Chiend54a23d2012-07-24 11:19:23 -07003479 case greenland::IntrinsicHelper::CopyInt:
3480 case greenland::IntrinsicHelper::CopyFloat:
3481 case greenland::IntrinsicHelper::CopyLong:
TDYa1275e869b62012-07-25 00:45:39 -07003482 case greenland::IntrinsicHelper::CopyDouble:
Logan Chien75e4b602012-07-23 14:24:12 -07003483 case greenland::IntrinsicHelper::CopyObj: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003484 return call_inst.getArgOperand(0);
Logan Chien75e4b602012-07-23 14:24:12 -07003485 }
3486
3487 //==- Shift ------------------------------------------------------------==//
3488 case greenland::IntrinsicHelper::SHLLong: {
3489 return Expand_IntegerShift(call_inst.getArgOperand(0),
3490 call_inst.getArgOperand(1),
3491 kIntegerSHL, kLong);
3492 }
3493 case greenland::IntrinsicHelper::SHRLong: {
3494 return Expand_IntegerShift(call_inst.getArgOperand(0),
3495 call_inst.getArgOperand(1),
3496 kIntegerSHR, kLong);
3497 }
3498 case greenland::IntrinsicHelper::USHRLong: {
3499 return Expand_IntegerShift(call_inst.getArgOperand(0),
3500 call_inst.getArgOperand(1),
3501 kIntegerUSHR, kLong);
3502 }
3503 case greenland::IntrinsicHelper::SHLInt: {
3504 return Expand_IntegerShift(call_inst.getArgOperand(0),
3505 call_inst.getArgOperand(1),
3506 kIntegerSHL, kInt);
3507 }
3508 case greenland::IntrinsicHelper::SHRInt: {
3509 return Expand_IntegerShift(call_inst.getArgOperand(0),
3510 call_inst.getArgOperand(1),
3511 kIntegerSHR, kInt);
3512 }
3513 case greenland::IntrinsicHelper::USHRInt: {
3514 return Expand_IntegerShift(call_inst.getArgOperand(0),
3515 call_inst.getArgOperand(1),
3516 kIntegerUSHR, kInt);
3517 }
3518
3519 //==- Conversion -------------------------------------------------------==//
TDYa127a1b21852012-07-23 03:20:39 -07003520 case IntrinsicHelper::IntToChar: {
3521 return irb_.CreateZExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJCharTy()),
3522 irb_.getJIntTy());
3523 }
3524 case IntrinsicHelper::IntToShort: {
3525 return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJShortTy()),
3526 irb_.getJIntTy());
3527 }
3528 case IntrinsicHelper::IntToByte: {
3529 return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJByteTy()),
3530 irb_.getJIntTy());
3531 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003532
Logan Chien75e4b602012-07-23 14:24:12 -07003533 //==- Unknown Cases ----------------------------------------------------==//
3534 case IntrinsicHelper::MaxIntrinsicId:
3535 case IntrinsicHelper::UnknownId:
3536 //default:
3537 // NOTE: "default" is intentionally commented so that C/C++ compiler will
3538 // give some warning on unmatched cases.
3539 // NOTE: We should not implement these cases.
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003540 break;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003541 }
Logan Chien75e4b602012-07-23 14:24:12 -07003542 UNIMPLEMENTED(FATAL) << "Unexpected GBC intrinsic: " << static_cast<int>(intr_id);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003543 return NULL;
3544}
3545
3546} // anonymous namespace
3547
3548namespace art {
3549namespace compiler_llvm {
3550
3551llvm::FunctionPass*
3552CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb) {
3553 return new GBCExpanderPass(intrinsic_helper, irb);
3554}
3555
3556} // namespace compiler_llvm
3557} // namespace art