blob: 9d7f1ae2ed7451126913e6104ff151755a517575 [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
TDYa127890ea892012-08-22 10:49:42 -07001172#if defined(ART_USE_QUICK_COMPILER)
1173 irb_.Runtime().EmitTestSuspend();
1174#endif
1175
Logan Chien67645d82012-08-17 09:10:54 +08001176 llvm::BasicBlock* next_basic_block = irb_.GetInsertBlock();
1177 if (next_basic_block != first_basic_block) {
1178 // Splice the rest of the instruction to the continuing basic block
1179 next_basic_block->getInstList().splice(
1180 irb_.GetInsertPoint(), first_basic_block->getInstList(),
1181 first_non_alloca, first_basic_block->end());
1182
1183 // Rewrite the basic block
1184 RewriteBasicBlock(next_basic_block);
1185
1186 // Update the phi-instructions in the successor basic block
1187 UpdatePhiInstruction(first_basic_block, irb_.GetInsertBlock());
1188 }
1189
1190 // We have changed the basic block
1191 changed_ = true;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001192}
1193
TDYa1275e869b62012-07-25 00:45:39 -07001194// ==== High-level intrinsic expander ==========================================
1195
TDYa127a1b21852012-07-23 03:20:39 -07001196llvm::Value* GBCExpanderPass::Expand_FPCompare(llvm::Value* src1_value,
1197 llvm::Value* src2_value,
1198 bool gt_bias) {
1199 llvm::Value* cmp_eq = irb_.CreateFCmpOEQ(src1_value, src2_value);
1200 llvm::Value* cmp_lt;
1201
1202 if (gt_bias) {
1203 cmp_lt = irb_.CreateFCmpOLT(src1_value, src2_value);
1204 } else {
1205 cmp_lt = irb_.CreateFCmpULT(src1_value, src2_value);
1206 }
1207
1208 return EmitCompareResultSelection(cmp_eq, cmp_lt);
1209}
1210
1211llvm::Value* GBCExpanderPass::Expand_LongCompare(llvm::Value* src1_value, llvm::Value* src2_value) {
1212 llvm::Value* cmp_eq = irb_.CreateICmpEQ(src1_value, src2_value);
1213 llvm::Value* cmp_lt = irb_.CreateICmpSLT(src1_value, src2_value);
1214
1215 return EmitCompareResultSelection(cmp_eq, cmp_lt);
1216}
1217
1218llvm::Value* GBCExpanderPass::EmitCompareResultSelection(llvm::Value* cmp_eq,
1219 llvm::Value* cmp_lt) {
1220
1221 llvm::Constant* zero = irb_.getJInt(0);
1222 llvm::Constant* pos1 = irb_.getJInt(1);
1223 llvm::Constant* neg1 = irb_.getJInt(-1);
1224
1225 llvm::Value* result_lt = irb_.CreateSelect(cmp_lt, neg1, pos1);
1226 llvm::Value* result_eq = irb_.CreateSelect(cmp_eq, zero, result_lt);
1227
1228 return result_eq;
1229}
1230
Logan Chien75e4b602012-07-23 14:24:12 -07001231llvm::Value* GBCExpanderPass::Expand_IntegerShift(llvm::Value* src1_value,
1232 llvm::Value* src2_value,
1233 IntegerShiftKind kind,
1234 JType op_jty) {
1235 DCHECK(op_jty == kInt || op_jty == kLong);
1236
1237 // Mask and zero-extend RHS properly
1238 if (op_jty == kInt) {
1239 src2_value = irb_.CreateAnd(src2_value, 0x1f);
1240 } else {
1241 llvm::Value* masked_src2_value = irb_.CreateAnd(src2_value, 0x3f);
1242 src2_value = irb_.CreateZExt(masked_src2_value, irb_.getJLongTy());
1243 }
1244
1245 // Create integer shift llvm instruction
1246 switch (kind) {
1247 case kIntegerSHL:
1248 return irb_.CreateShl(src1_value, src2_value);
1249
1250 case kIntegerSHR:
1251 return irb_.CreateAShr(src1_value, src2_value);
1252
1253 case kIntegerUSHR:
1254 return irb_.CreateLShr(src1_value, src2_value);
1255
1256 default:
1257 LOG(FATAL) << "Unknown integer shift kind: " << kind;
1258 return NULL;
1259 }
1260}
1261
TDYa1275a26d442012-07-26 18:58:38 -07001262llvm::Value* GBCExpanderPass::Expand_HLArrayGet(llvm::CallInst& call_inst,
1263 JType elem_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001264 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1265 llvm::Value* array_addr = call_inst.getArgOperand(1);
1266 llvm::Value* index_value = call_inst.getArgOperand(2);
1267
1268 // TODO: opt_flags
1269 EmitGuard_ArrayException(dex_pc, array_addr, index_value);
1270
1271 llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty);
1272
1273 llvm::Value* array_elem_value = irb_.CreateLoad(array_elem_addr, kTBAAHeapArray, elem_jty);
1274
1275 switch (elem_jty) {
1276 case kVoid:
1277 break;
1278
1279 case kBoolean:
1280 case kChar:
1281 array_elem_value = irb_.CreateZExt(array_elem_value, irb_.getJType(elem_jty, kReg));
1282 break;
1283
1284 case kByte:
1285 case kShort:
1286 array_elem_value = irb_.CreateSExt(array_elem_value, irb_.getJType(elem_jty, kReg));
1287 break;
1288
1289 case kInt:
1290 case kLong:
1291 case kFloat:
1292 case kDouble:
1293 case kObject:
1294 break;
1295
1296 default:
1297 LOG(FATAL) << "Unknown java type: " << elem_jty;
1298 }
1299
1300 return array_elem_value;
1301}
1302
1303
1304void GBCExpanderPass::Expand_HLArrayPut(llvm::CallInst& call_inst,
1305 JType elem_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001306 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1307 llvm::Value* new_value = call_inst.getArgOperand(1);
1308 llvm::Value* array_addr = call_inst.getArgOperand(2);
1309 llvm::Value* index_value = call_inst.getArgOperand(3);
1310
1311 // TODO: opt_flags
1312 EmitGuard_ArrayException(dex_pc, array_addr, index_value);
1313
1314 switch (elem_jty) {
1315 case kVoid:
1316 break;
1317
1318 case kBoolean:
1319 case kChar:
1320 new_value = irb_.CreateTrunc(new_value, irb_.getJType(elem_jty, kArray));
1321 break;
1322
1323 case kInt:
1324 case kLong:
1325 case kFloat:
1326 case kDouble:
1327 case kObject:
1328 break;
1329
1330 default:
1331 LOG(FATAL) << "Unknown java type: " << elem_jty;
1332 }
1333
1334 llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty);
1335
1336 if (elem_jty == kObject) { // If put an object, check the type, and mark GC card table.
1337 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::CheckPutArrayElement);
1338
1339 irb_.CreateCall2(runtime_func, new_value, array_addr);
1340
1341 EmitGuard_ExceptionLandingPad(dex_pc);
1342
1343 EmitMarkGCCard(new_value, array_addr);
1344 }
1345
1346 irb_.CreateStore(new_value, array_elem_addr, kTBAAHeapArray, elem_jty);
1347
1348 return;
1349}
1350
TDYa1275e869b62012-07-25 00:45:39 -07001351llvm::Value* GBCExpanderPass::Expand_HLIGet(llvm::CallInst& call_inst,
1352 JType field_jty) {
TDYa1275e869b62012-07-25 00:45:39 -07001353 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1354 llvm::Value* object_addr = call_inst.getArgOperand(1);
1355 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(2));
1356
1357 // TODO: opt_flags
1358 EmitGuard_NullPointerException(dex_pc, object_addr);
1359
1360 llvm::Value* field_value;
1361
1362 int field_offset;
1363 bool is_volatile;
1364 bool is_fast_path = compiler_->ComputeInstanceFieldInfo(
1365 field_idx, oat_compilation_unit_, field_offset, is_volatile, false);
1366
1367 if (!is_fast_path) {
1368 llvm::Function* runtime_func;
1369
1370 if (field_jty == kObject) {
1371 runtime_func = irb_.GetRuntime(runtime_support::GetObjectInstance);
1372 } else if (field_jty == kLong || field_jty == kDouble) {
1373 runtime_func = irb_.GetRuntime(runtime_support::Get64Instance);
1374 } else {
1375 runtime_func = irb_.GetRuntime(runtime_support::Get32Instance);
1376 }
1377
1378 llvm::ConstantInt* field_idx_value = irb_.getInt32(field_idx);
1379
1380 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1381
1382 EmitUpdateDexPC(dex_pc);
1383
1384 field_value = irb_.CreateCall3(runtime_func, field_idx_value,
1385 method_object_addr, object_addr);
1386
1387 EmitGuard_ExceptionLandingPad(dex_pc);
1388
1389 } else {
1390 DCHECK_GE(field_offset, 0);
1391
1392 llvm::PointerType* field_type =
1393 irb_.getJType(field_jty, kField)->getPointerTo();
1394
1395 llvm::ConstantInt* field_offset_value = irb_.getPtrEquivInt(field_offset);
1396
1397 llvm::Value* field_addr =
1398 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
1399
1400 // TODO: Check is_volatile. We need to generate atomic load instruction
1401 // when is_volatile is true.
1402 field_value = irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty);
1403 }
1404
1405 if (field_jty == kFloat || field_jty == kDouble) {
TDYa1275a26d442012-07-26 18:58:38 -07001406 field_value = irb_.CreateBitCast(field_value, irb_.getJType(field_jty, kAccurate));
TDYa1275e869b62012-07-25 00:45:39 -07001407 }
1408
1409 return field_value;
1410}
1411
1412void GBCExpanderPass::Expand_HLIPut(llvm::CallInst& call_inst,
1413 JType field_jty) {
TDYa1275e869b62012-07-25 00:45:39 -07001414 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1415 llvm::Value* object_addr = call_inst.getArgOperand(1);
1416 llvm::Value* new_value = call_inst.getArgOperand(2);
1417 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(3));
1418
1419 if (field_jty == kFloat || field_jty == kDouble) {
TDYa1275a26d442012-07-26 18:58:38 -07001420 new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty, kField));
TDYa1275e869b62012-07-25 00:45:39 -07001421 }
1422
1423 // TODO: opt_flags
1424 EmitGuard_NullPointerException(dex_pc, object_addr);
1425
1426 int field_offset;
1427 bool is_volatile;
1428 bool is_fast_path = compiler_->ComputeInstanceFieldInfo(
1429 field_idx, oat_compilation_unit_, field_offset, is_volatile, true);
1430
1431 if (!is_fast_path) {
1432 llvm::Function* runtime_func;
1433
1434 if (field_jty == kObject) {
1435 runtime_func = irb_.GetRuntime(runtime_support::SetObjectInstance);
1436 } else if (field_jty == kLong || field_jty == kDouble) {
1437 runtime_func = irb_.GetRuntime(runtime_support::Set64Instance);
1438 } else {
1439 runtime_func = irb_.GetRuntime(runtime_support::Set32Instance);
1440 }
1441
1442 llvm::Value* field_idx_value = irb_.getInt32(field_idx);
1443
1444 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1445
1446 EmitUpdateDexPC(dex_pc);
1447
1448 irb_.CreateCall4(runtime_func, field_idx_value,
1449 method_object_addr, object_addr, new_value);
1450
1451 EmitGuard_ExceptionLandingPad(dex_pc);
1452
1453 } else {
1454 DCHECK_GE(field_offset, 0);
1455
1456 llvm::PointerType* field_type =
1457 irb_.getJType(field_jty, kField)->getPointerTo();
1458
1459 llvm::Value* field_offset_value = irb_.getPtrEquivInt(field_offset);
1460
1461 llvm::Value* field_addr =
1462 irb_.CreatePtrDisp(object_addr, field_offset_value, field_type);
1463
1464 // TODO: Check is_volatile. We need to generate atomic store instruction
1465 // when is_volatile is true.
1466 irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty);
1467
1468 if (field_jty == kObject) { // If put an object, mark the GC card table.
1469 EmitMarkGCCard(new_value, object_addr);
1470 }
1471 }
1472
1473 return;
1474}
1475
TDYa127f71bf5a2012-07-29 20:09:52 -07001476llvm::Value* GBCExpanderPass::EmitLoadConstantClass(uint32_t dex_pc,
1477 uint32_t type_idx) {
1478 if (!compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_,
1479 *dex_file_, type_idx)) {
1480 llvm::Value* type_idx_value = irb_.getInt32(type_idx);
1481
1482 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1483
1484 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1485
1486 llvm::Function* runtime_func =
1487 irb_.GetRuntime(runtime_support::InitializeTypeAndVerifyAccess);
1488
1489 EmitUpdateDexPC(dex_pc);
1490
1491 llvm::Value* type_object_addr =
1492 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1493
1494 EmitGuard_ExceptionLandingPad(dex_pc);
1495
1496 return type_object_addr;
1497
1498 } else {
1499 // Try to load the class (type) object from the test cache.
1500 llvm::Value* type_field_addr =
1501 EmitLoadDexCacheResolvedTypeFieldAddr(type_idx);
1502
1503 llvm::Value* type_object_addr = irb_.CreateLoad(type_field_addr, kTBAAJRuntime);
1504
1505 if (compiler_->CanAssumeTypeIsPresentInDexCache(dex_cache_, type_idx)) {
1506 return type_object_addr;
1507 }
1508
1509 llvm::BasicBlock* block_original = irb_.GetInsertBlock();
1510
1511 // Test whether class (type) object is in the dex cache or not
1512 llvm::Value* equal_null =
1513 irb_.CreateICmpEQ(type_object_addr, irb_.getJNull());
1514
1515 llvm::BasicBlock* block_cont =
1516 CreateBasicBlockWithDexPC(dex_pc, "cont");
1517
1518 llvm::BasicBlock* block_load_class =
1519 CreateBasicBlockWithDexPC(dex_pc, "load_class");
1520
1521 irb_.CreateCondBr(equal_null, block_load_class, block_cont, kUnlikely);
1522
1523 // Failback routine to load the class object
1524 irb_.SetInsertPoint(block_load_class);
1525
1526 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeType);
1527
1528 llvm::Constant* type_idx_value = irb_.getInt32(type_idx);
1529
1530 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1531
1532 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1533
1534 EmitUpdateDexPC(dex_pc);
1535
1536 llvm::Value* loaded_type_object_addr =
1537 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1538
1539 EmitGuard_ExceptionLandingPad(dex_pc);
1540
1541 llvm::BasicBlock* block_after_load_class = irb_.GetInsertBlock();
1542
1543 irb_.CreateBr(block_cont);
1544
1545 // Now the class object must be loaded
1546 irb_.SetInsertPoint(block_cont);
1547
1548 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1549
1550 phi->addIncoming(type_object_addr, block_original);
1551 phi->addIncoming(loaded_type_object_addr, block_after_load_class);
1552
1553 return phi;
1554 }
1555}
1556
TDYa1275a26d442012-07-26 18:58:38 -07001557llvm::Value* GBCExpanderPass::EmitLoadStaticStorage(uint32_t dex_pc,
1558 uint32_t type_idx) {
1559 llvm::BasicBlock* block_load_static =
1560 CreateBasicBlockWithDexPC(dex_pc, "load_static");
1561
1562 llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont");
1563
1564 // Load static storage from dex cache
1565 llvm::Value* storage_field_addr =
1566 EmitLoadDexCacheStaticStorageFieldAddr(type_idx);
1567
1568 llvm::Value* storage_object_addr = irb_.CreateLoad(storage_field_addr, kTBAAJRuntime);
1569
1570 llvm::BasicBlock* block_original = irb_.GetInsertBlock();
1571
1572 // Test: Is the static storage of this class initialized?
1573 llvm::Value* equal_null =
1574 irb_.CreateICmpEQ(storage_object_addr, irb_.getJNull());
1575
1576 irb_.CreateCondBr(equal_null, block_load_static, block_cont, kUnlikely);
1577
1578 // Failback routine to load the class object
1579 irb_.SetInsertPoint(block_load_static);
1580
1581 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeStaticStorage);
1582
1583 llvm::Constant* type_idx_value = irb_.getInt32(type_idx);
1584
1585 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1586
1587 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
1588
1589 EmitUpdateDexPC(dex_pc);
1590
1591 llvm::Value* loaded_storage_object_addr =
1592 irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr);
1593
1594 EmitGuard_ExceptionLandingPad(dex_pc);
1595
1596 llvm::BasicBlock* block_after_load_static = irb_.GetInsertBlock();
1597
1598 irb_.CreateBr(block_cont);
1599
1600 // Now the class object must be loaded
1601 irb_.SetInsertPoint(block_cont);
1602
1603 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1604
1605 phi->addIncoming(storage_object_addr, block_original);
1606 phi->addIncoming(loaded_storage_object_addr, block_after_load_static);
1607
1608 return phi;
1609}
1610
1611llvm::Value* GBCExpanderPass::Expand_HLSget(llvm::CallInst& call_inst,
1612 JType field_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001613 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1614 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0));
1615
1616 int field_offset;
1617 int ssb_index;
1618 bool is_referrers_class;
1619 bool is_volatile;
1620
1621 bool is_fast_path = compiler_->ComputeStaticFieldInfo(
1622 field_idx, oat_compilation_unit_, field_offset, ssb_index,
1623 is_referrers_class, is_volatile, false);
1624
1625 llvm::Value* static_field_value;
1626
1627 if (!is_fast_path) {
1628 llvm::Function* runtime_func;
1629
1630 if (field_jty == kObject) {
1631 runtime_func = irb_.GetRuntime(runtime_support::GetObjectStatic);
1632 } else if (field_jty == kLong || field_jty == kDouble) {
1633 runtime_func = irb_.GetRuntime(runtime_support::Get64Static);
1634 } else {
1635 runtime_func = irb_.GetRuntime(runtime_support::Get32Static);
1636 }
1637
1638 llvm::Constant* field_idx_value = irb_.getInt32(field_idx);
1639
1640 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1641
1642 EmitUpdateDexPC(dex_pc);
1643
1644 static_field_value =
1645 irb_.CreateCall2(runtime_func, field_idx_value, method_object_addr);
1646
1647 EmitGuard_ExceptionLandingPad(dex_pc);
1648
1649 } else {
1650 DCHECK_GE(field_offset, 0);
1651
1652 llvm::Value* static_storage_addr = NULL;
1653
1654 if (is_referrers_class) {
1655 // Fast path, static storage base is this method's class
1656 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1657
1658 static_storage_addr =
1659 irb_.LoadFromObjectOffset(method_object_addr,
1660 Method::DeclaringClassOffset().Int32Value(),
1661 irb_.getJObjectTy(),
1662 kTBAAConstJObject);
1663 } else {
1664 // Medium path, static storage base in a different class which
1665 // requires checks that the other class is initialized
1666 DCHECK_GE(ssb_index, 0);
1667 static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index);
1668 }
1669
1670 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
1671
1672 llvm::Value* static_field_addr =
1673 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
1674 irb_.getJType(field_jty, kField)->getPointerTo());
1675
1676 // TODO: Check is_volatile. We need to generate atomic load instruction
1677 // when is_volatile is true.
1678 static_field_value = irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty);
1679 }
1680
1681 if (field_jty == kFloat || field_jty == kDouble) {
1682 static_field_value =
1683 irb_.CreateBitCast(static_field_value, irb_.getJType(field_jty, kAccurate));
1684 }
1685
1686 return static_field_value;
1687}
1688
1689void GBCExpanderPass::Expand_HLSput(llvm::CallInst& call_inst,
1690 JType field_jty) {
TDYa1275a26d442012-07-26 18:58:38 -07001691 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1692 uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0));
1693 llvm::Value* new_value = call_inst.getArgOperand(1);
1694
1695 if (field_jty == kFloat || field_jty == kDouble) {
1696 new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty, kField));
1697 }
1698
1699 int field_offset;
1700 int ssb_index;
1701 bool is_referrers_class;
1702 bool is_volatile;
1703
1704 bool is_fast_path = compiler_->ComputeStaticFieldInfo(
1705 field_idx, oat_compilation_unit_, field_offset, ssb_index,
1706 is_referrers_class, is_volatile, true);
1707
1708 if (!is_fast_path) {
1709 llvm::Function* runtime_func;
1710
1711 if (field_jty == kObject) {
1712 runtime_func = irb_.GetRuntime(runtime_support::SetObjectStatic);
1713 } else if (field_jty == kLong || field_jty == kDouble) {
1714 runtime_func = irb_.GetRuntime(runtime_support::Set64Static);
1715 } else {
1716 runtime_func = irb_.GetRuntime(runtime_support::Set32Static);
1717 }
1718
1719 llvm::Constant* field_idx_value = irb_.getInt32(field_idx);
1720
1721 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1722
1723 EmitUpdateDexPC(dex_pc);
1724
1725 irb_.CreateCall3(runtime_func, field_idx_value,
1726 method_object_addr, new_value);
1727
1728 EmitGuard_ExceptionLandingPad(dex_pc);
1729
1730 } else {
1731 DCHECK_GE(field_offset, 0);
1732
1733 llvm::Value* static_storage_addr = NULL;
1734
1735 if (is_referrers_class) {
1736 // Fast path, static storage base is this method's class
1737 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1738
1739 static_storage_addr =
1740 irb_.LoadFromObjectOffset(method_object_addr,
1741 Method::DeclaringClassOffset().Int32Value(),
1742 irb_.getJObjectTy(),
1743 kTBAAConstJObject);
1744 } else {
1745 // Medium path, static storage base in a different class which
1746 // requires checks that the other class is initialized
1747 DCHECK_GE(ssb_index, 0);
1748 static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index);
1749 }
1750
1751 llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset);
1752
1753 llvm::Value* static_field_addr =
1754 irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value,
1755 irb_.getJType(field_jty, kField)->getPointerTo());
1756
1757 // TODO: Check is_volatile. We need to generate atomic store instruction
1758 // when is_volatile is true.
1759 irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty);
1760
1761 if (field_jty == kObject) { // If put an object, mark the GC card table.
1762 EmitMarkGCCard(new_value, static_storage_addr);
1763 }
1764 }
1765
1766 return;
1767}
1768
TDYa127f71bf5a2012-07-29 20:09:52 -07001769llvm::Value* GBCExpanderPass::Expand_ConstString(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001770 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1771 uint32_t string_idx = LV2UInt(call_inst.getArgOperand(0));
1772
1773 llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx);
1774
1775 llvm::Value* string_addr = irb_.CreateLoad(string_field_addr, kTBAAJRuntime);
1776
1777 if (!compiler_->CanAssumeStringIsPresentInDexCache(dex_cache_, string_idx)) {
1778 llvm::BasicBlock* block_str_exist =
1779 CreateBasicBlockWithDexPC(dex_pc, "str_exist");
1780
1781 llvm::BasicBlock* block_str_resolve =
1782 CreateBasicBlockWithDexPC(dex_pc, "str_resolve");
1783
1784 llvm::BasicBlock* block_cont =
1785 CreateBasicBlockWithDexPC(dex_pc, "str_cont");
1786
1787 // Test: Is the string resolved and in the dex cache?
1788 llvm::Value* equal_null = irb_.CreateICmpEQ(string_addr, irb_.getJNull());
1789
1790 irb_.CreateCondBr(equal_null, block_str_resolve, block_str_exist, kUnlikely);
1791
1792 // String is resolved, go to next basic block.
1793 irb_.SetInsertPoint(block_str_exist);
1794 irb_.CreateBr(block_cont);
1795
1796 // String is not resolved yet, resolve it now.
1797 irb_.SetInsertPoint(block_str_resolve);
1798
1799 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::ResolveString);
1800
1801 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
1802
1803 llvm::Value* string_idx_value = irb_.getInt32(string_idx);
1804
1805 EmitUpdateDexPC(dex_pc);
1806
1807 llvm::Value* result = irb_.CreateCall2(runtime_func, method_object_addr,
1808 string_idx_value);
1809
1810 EmitGuard_ExceptionLandingPad(dex_pc);
1811
1812 llvm::BasicBlock* block_pre_cont = irb_.GetInsertBlock();
1813
1814 irb_.SetInsertPoint(block_cont);
1815
1816 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2);
1817
1818 phi->addIncoming(string_addr, block_str_exist);
1819 phi->addIncoming(result, block_pre_cont);
1820
1821 string_addr = phi;
1822 }
1823
1824 return string_addr;
1825}
1826
1827llvm::Value* GBCExpanderPass::Expand_ConstClass(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001828 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1829 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1830
1831 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
1832
1833 return type_object_addr;
1834}
1835
1836void GBCExpanderPass::Expand_MonitorEnter(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001837 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1838 llvm::Value* object_addr = call_inst.getArgOperand(1);
1839
1840 // TODO: opt_flags
1841 EmitGuard_NullPointerException(dex_pc, object_addr);
1842
1843 irb_.Runtime().EmitLockObject(object_addr);
1844
1845 return;
1846}
1847
1848void GBCExpanderPass::Expand_MonitorExit(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001849 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1850 llvm::Value* object_addr = call_inst.getArgOperand(1);
1851
1852 // TODO: opt_flags
1853 EmitGuard_NullPointerException(dex_pc, object_addr);
1854
1855 EmitUpdateDexPC(dex_pc);
1856
1857 irb_.Runtime().EmitUnlockObject(object_addr);
1858
1859 EmitGuard_ExceptionLandingPad(dex_pc);
1860
1861 return;
1862}
1863
1864void GBCExpanderPass::Expand_HLCheckCast(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001865 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1866 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1867 llvm::Value* object_addr = call_inst.getArgOperand(1);
1868
1869 llvm::BasicBlock* block_test_class =
1870 CreateBasicBlockWithDexPC(dex_pc, "test_class");
1871
1872 llvm::BasicBlock* block_test_sub_class =
1873 CreateBasicBlockWithDexPC(dex_pc, "test_sub_class");
1874
1875 llvm::BasicBlock* block_cont =
1876 CreateBasicBlockWithDexPC(dex_pc, "checkcast_cont");
1877
1878 // Test: Is the reference equal to null? Act as no-op when it is null.
1879 llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull());
1880
1881 irb_.CreateCondBr(equal_null,
1882 block_cont,
1883 block_test_class);
1884
1885 // Test: Is the object instantiated from the given class?
1886 irb_.SetInsertPoint(block_test_class);
1887 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
1888 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
1889
1890 llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy();
1891
1892 llvm::Value* object_type_field_addr =
1893 irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo());
1894
1895 llvm::Value* object_type_object_addr =
1896 irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject);
1897
1898 llvm::Value* equal_class =
1899 irb_.CreateICmpEQ(type_object_addr, object_type_object_addr);
1900
1901 irb_.CreateCondBr(equal_class,
1902 block_cont,
1903 block_test_sub_class);
1904
1905 // Test: Is the object instantiated from the subclass of the given class?
1906 irb_.SetInsertPoint(block_test_sub_class);
1907
1908 EmitUpdateDexPC(dex_pc);
1909
1910 irb_.CreateCall2(irb_.GetRuntime(runtime_support::CheckCast),
1911 type_object_addr, object_type_object_addr);
1912
1913 EmitGuard_ExceptionLandingPad(dex_pc);
1914
1915 irb_.CreateBr(block_cont);
1916
1917 irb_.SetInsertPoint(block_cont);
1918
1919 return;
1920}
1921
1922llvm::Value* GBCExpanderPass::Expand_InstanceOf(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001923 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1924 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1925 llvm::Value* object_addr = call_inst.getArgOperand(1);
1926
1927 llvm::BasicBlock* block_nullp =
1928 CreateBasicBlockWithDexPC(dex_pc, "nullp");
1929
1930 llvm::BasicBlock* block_test_class =
1931 CreateBasicBlockWithDexPC(dex_pc, "test_class");
1932
1933 llvm::BasicBlock* block_class_equals =
1934 CreateBasicBlockWithDexPC(dex_pc, "class_eq");
1935
1936 llvm::BasicBlock* block_test_sub_class =
1937 CreateBasicBlockWithDexPC(dex_pc, "test_sub_class");
1938
1939 llvm::BasicBlock* block_cont =
1940 CreateBasicBlockWithDexPC(dex_pc, "instance_of_cont");
1941
1942 // Overview of the following code :
1943 // We check for null, if so, then false, otherwise check for class == . If so
1944 // then true, otherwise do callout slowpath.
1945 //
1946 // Test: Is the reference equal to null? Set 0 when it is null.
1947 llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull());
1948
1949 irb_.CreateCondBr(equal_null, block_nullp, block_test_class);
1950
1951 irb_.SetInsertPoint(block_nullp);
1952 irb_.CreateBr(block_cont);
1953
1954 // Test: Is the object instantiated from the given class?
1955 irb_.SetInsertPoint(block_test_class);
1956 llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx);
1957 DCHECK_EQ(Object::ClassOffset().Int32Value(), 0);
1958
1959 llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy();
1960
1961 llvm::Value* object_type_field_addr =
1962 irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo());
1963
1964 llvm::Value* object_type_object_addr =
1965 irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject);
1966
1967 llvm::Value* equal_class =
1968 irb_.CreateICmpEQ(type_object_addr, object_type_object_addr);
1969
1970 irb_.CreateCondBr(equal_class, block_class_equals, block_test_sub_class);
1971
1972 irb_.SetInsertPoint(block_class_equals);
1973 irb_.CreateBr(block_cont);
1974
1975 // Test: Is the object instantiated from the subclass of the given class?
1976 irb_.SetInsertPoint(block_test_sub_class);
1977 llvm::Value* result =
1978 irb_.CreateCall2(irb_.GetRuntime(runtime_support::IsAssignable),
1979 type_object_addr, object_type_object_addr);
1980 irb_.CreateBr(block_cont);
1981
1982 irb_.SetInsertPoint(block_cont);
1983
1984 llvm::PHINode* phi = irb_.CreatePHI(irb_.getJIntTy(), 3);
1985
1986 phi->addIncoming(irb_.getJInt(0), block_nullp);
1987 phi->addIncoming(irb_.getJInt(1), block_class_equals);
1988 phi->addIncoming(result, block_test_sub_class);
1989
1990 return phi;
1991}
1992
1993llvm::Value* GBCExpanderPass::Expand_NewInstance(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07001994 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
1995 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
1996
1997 llvm::Function* runtime_func;
1998 if (compiler_->CanAccessInstantiableTypeWithoutChecks(
1999 method_idx_, dex_cache_, *dex_file_, type_idx)) {
2000 runtime_func = irb_.GetRuntime(runtime_support::AllocObject);
2001 } else {
2002 runtime_func = irb_.GetRuntime(runtime_support::AllocObjectWithAccessCheck);
2003 }
2004
2005 llvm::Constant* type_index_value = irb_.getInt32(type_idx);
2006
2007 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2008
2009 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2010
2011 EmitUpdateDexPC(dex_pc);
2012
2013 llvm::Value* object_addr =
2014 irb_.CreateCall3(runtime_func, type_index_value, method_object_addr, thread_object_addr);
2015
2016 EmitGuard_ExceptionLandingPad(dex_pc);
2017
2018 return object_addr;
2019}
2020
2021llvm::Value* GBCExpanderPass::Expand_HLInvoke(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002022 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2023 InvokeType invoke_type = static_cast<InvokeType>(LV2UInt(call_inst.getArgOperand(0)));
2024 bool is_static = (invoke_type == kStatic);
2025 uint32_t callee_method_idx = LV2UInt(call_inst.getArgOperand(1));
2026
2027 // Compute invoke related information for compiler decision
2028 int vtable_idx = -1;
2029 uintptr_t direct_code = 0;
2030 uintptr_t direct_method = 0;
2031 bool is_fast_path = compiler_->
2032 ComputeInvokeInfo(callee_method_idx, oat_compilation_unit_,
2033 invoke_type, vtable_idx, direct_code, direct_method);
2034
2035 // Load *this* actual parameter
2036 llvm::Value* this_addr = NULL;
2037
2038 if (!is_static) {
2039 // Test: Is *this* parameter equal to null?
2040 this_addr = call_inst.getArgOperand(3);
2041 }
2042
2043 // Load the method object
2044 llvm::Value* callee_method_object_addr = NULL;
2045
2046 if (!is_fast_path) {
2047 callee_method_object_addr =
2048 EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, invoke_type,
2049 this_addr, dex_pc, is_fast_path);
2050
2051 // TODO: opt_flags
2052 if (!is_static) {
2053 EmitGuard_NullPointerException(dex_pc, this_addr);
2054 }
2055 } else {
2056 // TODO: opt_flags
2057 if (!is_static) {
2058 EmitGuard_NullPointerException(dex_pc, this_addr);
2059 }
2060
2061 switch (invoke_type) {
2062 case kStatic:
2063 case kDirect:
2064 if (direct_method != 0u &&
2065 direct_method != static_cast<uintptr_t>(-1)) {
2066 callee_method_object_addr =
2067 irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_method),
2068 irb_.getJObjectTy());
2069 } else {
2070 callee_method_object_addr =
2071 EmitLoadSDCalleeMethodObjectAddr(callee_method_idx);
2072 }
2073 break;
2074
2075 case kVirtual:
2076 DCHECK(vtable_idx != -1);
2077 callee_method_object_addr =
2078 EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr);
2079 break;
2080
2081 case kSuper:
2082 LOG(FATAL) << "invoke-super should be promoted to invoke-direct in "
2083 "the fast path.";
2084 break;
2085
2086 case kInterface:
2087 callee_method_object_addr =
2088 EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx,
2089 invoke_type, this_addr,
2090 dex_pc, is_fast_path);
2091 break;
2092 }
2093 }
2094
2095 // Load the actual parameter
2096 std::vector<llvm::Value*> args;
2097
2098 args.push_back(callee_method_object_addr); // method object for callee
2099
2100 for (uint32_t i = 3; i < call_inst.getNumArgOperands(); ++i) {
2101 args.push_back(call_inst.getArgOperand(i));
2102 }
2103
2104 llvm::Value* code_addr;
2105 if (direct_code != 0u &&
2106 direct_code != static_cast<uintptr_t>(-1)) {
2107 code_addr =
2108 irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_code),
2109 GetFunctionType(callee_method_idx, is_static)->getPointerTo());
2110 } else {
2111 code_addr =
2112 irb_.LoadFromObjectOffset(callee_method_object_addr,
2113 Method::GetCodeOffset().Int32Value(),
2114 GetFunctionType(callee_method_idx, is_static)->getPointerTo(),
2115 kTBAAJRuntime);
2116 }
2117
2118 // Invoke callee
2119 EmitUpdateDexPC(dex_pc);
2120 llvm::Value* retval = irb_.CreateCall(code_addr, args);
2121 EmitGuard_ExceptionLandingPad(dex_pc);
2122
2123 return retval;
2124}
2125
2126llvm::Value* GBCExpanderPass::Expand_OptArrayLength(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002127 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2128 // Get the array object address
2129 llvm::Value* array_addr = call_inst.getArgOperand(1);
2130
2131 // TODO: opt_flags
2132 EmitGuard_NullPointerException(dex_pc, array_addr);
2133
2134 // Get the array length and store it to the register
2135 return EmitLoadArrayLength(array_addr);
2136}
2137
2138llvm::Value* GBCExpanderPass::Expand_NewArray(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002139 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2140 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0));
2141 llvm::Value* length = call_inst.getArgOperand(1);
2142
2143 return EmitAllocNewArray(dex_pc, length, type_idx, false);
2144}
2145
2146llvm::Value* GBCExpanderPass::Expand_HLFilledNewArray(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002147 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2148 uint32_t type_idx = LV2UInt(call_inst.getArgOperand(1));
2149 uint32_t length = call_inst.getNumArgOperands() - 3;
2150
2151 llvm::Value* object_addr =
2152 EmitAllocNewArray(dex_pc, irb_.getInt32(length), type_idx, true);
2153
2154 if (length > 0) {
2155 // Check for the element type
2156 uint32_t type_desc_len = 0;
2157 const char* type_desc =
2158 dex_file_->StringByTypeIdx(type_idx, &type_desc_len);
2159
2160 DCHECK_GE(type_desc_len, 2u); // should be guaranteed by verifier
2161 DCHECK_EQ(type_desc[0], '['); // should be guaranteed by verifier
2162 bool is_elem_int_ty = (type_desc[1] == 'I');
2163
2164 uint32_t alignment;
2165 llvm::Constant* elem_size;
2166 llvm::PointerType* field_type;
2167
2168 // NOTE: Currently filled-new-array only supports 'L', '[', and 'I'
2169 // as the element, thus we are only checking 2 cases: primitive int and
2170 // non-primitive type.
2171 if (is_elem_int_ty) {
2172 alignment = sizeof(int32_t);
2173 elem_size = irb_.getPtrEquivInt(sizeof(int32_t));
2174 field_type = irb_.getJIntTy()->getPointerTo();
2175 } else {
2176 alignment = irb_.getSizeOfPtrEquivInt();
2177 elem_size = irb_.getSizeOfPtrEquivIntValue();
2178 field_type = irb_.getJObjectTy()->getPointerTo();
2179 }
2180
2181 llvm::Value* data_field_offset =
2182 irb_.getPtrEquivInt(Array::DataOffset(alignment).Int32Value());
2183
2184 llvm::Value* data_field_addr =
2185 irb_.CreatePtrDisp(object_addr, data_field_offset, field_type);
2186
2187 // TODO: Tune this code. Currently we are generating one instruction for
2188 // one element which may be very space consuming. Maybe changing to use
2189 // memcpy may help; however, since we can't guarantee that the alloca of
2190 // dalvik register are continuous, we can't perform such optimization yet.
2191 for (uint32_t i = 0; i < length; ++i) {
2192 llvm::Value* reg_value = call_inst.getArgOperand(i+3);
2193
2194 irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray);
2195
2196 data_field_addr =
2197 irb_.CreatePtrDisp(data_field_addr, elem_size, field_type);
2198 }
2199 }
2200
2201 return object_addr;
2202}
2203
2204void GBCExpanderPass::Expand_HLFillArrayData(llvm::CallInst& call_inst) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002205 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2206 int32_t payload_offset = static_cast<int32_t>(dex_pc) +
2207 LV2SInt(call_inst.getArgOperand(0));
2208 llvm::Value* array_addr = call_inst.getArgOperand(1);
2209
2210 const Instruction::ArrayDataPayload* payload =
2211 reinterpret_cast<const Instruction::ArrayDataPayload*>(
2212 code_item_->insns_ + payload_offset);
2213
2214 if (payload->element_count == 0) {
2215 // When the number of the elements in the payload is zero, we don't have
2216 // to copy any numbers. However, we should check whether the array object
2217 // address is equal to null or not.
2218 EmitGuard_NullPointerException(dex_pc, array_addr);
2219 } else {
2220 // To save the code size, we are going to call the runtime function to
2221 // copy the content from DexFile.
2222
2223 // NOTE: We will check for the NullPointerException in the runtime.
2224
2225 llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::FillArrayData);
2226
2227 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2228
2229 EmitUpdateDexPC(dex_pc);
2230
2231 irb_.CreateCall4(runtime_func,
2232 method_object_addr, irb_.getInt32(dex_pc),
2233 array_addr, irb_.getInt32(payload_offset));
2234
2235 EmitGuard_ExceptionLandingPad(dex_pc);
2236 }
2237
2238 return;
2239}
2240
2241llvm::Value* GBCExpanderPass::EmitAllocNewArray(uint32_t dex_pc,
2242 llvm::Value* array_length_value,
2243 uint32_t type_idx,
2244 bool is_filled_new_array) {
2245 llvm::Function* runtime_func;
2246
2247 bool skip_access_check =
2248 compiler_->CanAccessTypeWithoutChecks(method_idx_, dex_cache_,
2249 *dex_file_, type_idx);
2250
2251
2252 if (is_filled_new_array) {
2253 runtime_func = skip_access_check ?
2254 irb_.GetRuntime(runtime_support::CheckAndAllocArray) :
2255 irb_.GetRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck);
2256 } else {
2257 runtime_func = skip_access_check ?
2258 irb_.GetRuntime(runtime_support::AllocArray) :
2259 irb_.GetRuntime(runtime_support::AllocArrayWithAccessCheck);
2260 }
2261
2262 llvm::Constant* type_index_value = irb_.getInt32(type_idx);
2263
2264 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2265
2266 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2267
2268 EmitUpdateDexPC(dex_pc);
2269
2270 llvm::Value* object_addr =
2271 irb_.CreateCall4(runtime_func, type_index_value, method_object_addr,
2272 array_length_value, thread_object_addr);
2273
2274 EmitGuard_ExceptionLandingPad(dex_pc);
2275
2276 return object_addr;
2277}
2278
2279llvm::Value* GBCExpanderPass::
2280EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx,
2281 InvokeType invoke_type,
2282 llvm::Value* this_addr,
2283 uint32_t dex_pc,
2284 bool is_fast_path) {
2285
2286 llvm::Function* runtime_func = NULL;
2287
2288 switch (invoke_type) {
2289 case kStatic:
2290 runtime_func = irb_.GetRuntime(runtime_support::FindStaticMethodWithAccessCheck);
2291 break;
2292
2293 case kDirect:
2294 runtime_func = irb_.GetRuntime(runtime_support::FindDirectMethodWithAccessCheck);
2295 break;
2296
2297 case kVirtual:
2298 runtime_func = irb_.GetRuntime(runtime_support::FindVirtualMethodWithAccessCheck);
2299 break;
2300
2301 case kSuper:
2302 runtime_func = irb_.GetRuntime(runtime_support::FindSuperMethodWithAccessCheck);
2303 break;
2304
2305 case kInterface:
2306 if (is_fast_path) {
2307 runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethod);
2308 } else {
2309 runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethodWithAccessCheck);
2310 }
2311 break;
2312 }
2313
2314 llvm::Value* callee_method_idx_value = irb_.getInt32(callee_method_idx);
2315
2316 if (this_addr == NULL) {
2317 DCHECK_EQ(invoke_type, kStatic);
2318 this_addr = irb_.getJNull();
2319 }
2320
2321 llvm::Value* caller_method_object_addr = EmitLoadMethodObjectAddr();
2322
2323 llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread();
2324
2325 EmitUpdateDexPC(dex_pc);
2326
2327 llvm::Value* callee_method_object_addr =
2328 irb_.CreateCall4(runtime_func,
2329 callee_method_idx_value,
2330 this_addr,
2331 caller_method_object_addr,
2332 thread_object_addr);
2333
2334 EmitGuard_ExceptionLandingPad(dex_pc);
2335
2336 return callee_method_object_addr;
2337}
2338
TDYa1275e869b62012-07-25 00:45:39 -07002339void GBCExpanderPass::EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr) {
2340 // Using runtime support, let the target can override by InlineAssembly.
2341 irb_.Runtime().EmitMarkGCCard(value, target_addr);
2342}
2343
2344void GBCExpanderPass::EmitUpdateDexPC(uint32_t dex_pc) {
2345 irb_.StoreToObjectOffset(shadow_frame_,
2346 ShadowFrame::DexPCOffset(),
2347 irb_.getInt32(dex_pc),
2348 kTBAAShadowFrame);
2349}
2350
2351void GBCExpanderPass::EmitGuard_DivZeroException(uint32_t dex_pc,
2352 llvm::Value* denominator,
2353 JType op_jty) {
2354 DCHECK(op_jty == kInt || op_jty == kLong) << op_jty;
2355
2356 llvm::Constant* zero = irb_.getJZero(op_jty);
2357
2358 llvm::Value* equal_zero = irb_.CreateICmpEQ(denominator, zero);
2359
2360 llvm::BasicBlock* block_exception = CreateBasicBlockWithDexPC(dex_pc, "div0");
2361
2362 llvm::BasicBlock* block_continue = CreateBasicBlockWithDexPC(dex_pc, "cont");
2363
2364 irb_.CreateCondBr(equal_zero, block_exception, block_continue, kUnlikely);
2365
2366 irb_.SetInsertPoint(block_exception);
2367 EmitUpdateDexPC(dex_pc);
2368 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowDivZeroException));
2369 EmitBranchExceptionLandingPad(dex_pc);
2370
2371 irb_.SetInsertPoint(block_continue);
2372}
2373
2374void GBCExpanderPass::EmitGuard_NullPointerException(uint32_t dex_pc,
2375 llvm::Value* object) {
2376 llvm::Value* equal_null = irb_.CreateICmpEQ(object, irb_.getJNull());
2377
2378 llvm::BasicBlock* block_exception =
2379 CreateBasicBlockWithDexPC(dex_pc, "nullp");
2380
2381 llvm::BasicBlock* block_continue =
2382 CreateBasicBlockWithDexPC(dex_pc, "cont");
2383
2384 irb_.CreateCondBr(equal_null, block_exception, block_continue, kUnlikely);
2385
2386 irb_.SetInsertPoint(block_exception);
2387 EmitUpdateDexPC(dex_pc);
2388 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowNullPointerException),
2389 irb_.getInt32(dex_pc));
2390 EmitBranchExceptionLandingPad(dex_pc);
2391
2392 irb_.SetInsertPoint(block_continue);
2393}
2394
2395void
2396GBCExpanderPass::EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc,
2397 llvm::Value* array,
2398 llvm::Value* index) {
2399 llvm::Value* array_len = EmitLoadArrayLength(array);
2400
2401 llvm::Value* cmp = irb_.CreateICmpUGE(index, array_len);
2402
2403 llvm::BasicBlock* block_exception =
2404 CreateBasicBlockWithDexPC(dex_pc, "overflow");
2405
2406 llvm::BasicBlock* block_continue =
2407 CreateBasicBlockWithDexPC(dex_pc, "cont");
2408
2409 irb_.CreateCondBr(cmp, block_exception, block_continue, kUnlikely);
2410
2411 irb_.SetInsertPoint(block_exception);
2412
2413 EmitUpdateDexPC(dex_pc);
2414 irb_.CreateCall2(irb_.GetRuntime(runtime_support::ThrowIndexOutOfBounds), index, array_len);
2415 EmitBranchExceptionLandingPad(dex_pc);
2416
2417 irb_.SetInsertPoint(block_continue);
2418}
2419
2420void GBCExpanderPass::EmitGuard_ArrayException(uint32_t dex_pc,
2421 llvm::Value* array,
2422 llvm::Value* index) {
2423 EmitGuard_NullPointerException(dex_pc, array);
2424 EmitGuard_ArrayIndexOutOfBoundsException(dex_pc, array, index);
2425}
2426
2427llvm::FunctionType* GBCExpanderPass::GetFunctionType(uint32_t method_idx,
2428 bool is_static) {
2429 // Get method signature
2430 DexFile::MethodId const& method_id = dex_file_->GetMethodId(method_idx);
2431
2432 uint32_t shorty_size;
2433 const char* shorty = dex_file_->GetMethodShorty(method_id, &shorty_size);
2434 CHECK_GE(shorty_size, 1u);
2435
2436 // Get return type
2437 llvm::Type* ret_type = irb_.getJType(shorty[0], kAccurate);
2438
2439 // Get argument type
2440 std::vector<llvm::Type*> args_type;
2441
2442 args_type.push_back(irb_.getJObjectTy()); // method object pointer
2443
2444 if (!is_static) {
2445 args_type.push_back(irb_.getJType('L', kAccurate)); // "this" object pointer
2446 }
2447
2448 for (uint32_t i = 1; i < shorty_size; ++i) {
TDYa127f71bf5a2012-07-29 20:09:52 -07002449#if defined(ART_USE_QUICK_COMPILER)
2450 char shorty_type = shorty[i];
2451 switch(shorty_type) {
2452 case 'Z' : shorty_type = 'I'; break;
2453 case 'B' : shorty_type = 'I'; break;
2454 case 'S' : shorty_type = 'I'; break;
2455 case 'C' : shorty_type = 'I'; break;
2456 default: break;
2457 }
2458 args_type.push_back(irb_.getJType(shorty_type, kAccurate));
2459#else
TDYa1275e869b62012-07-25 00:45:39 -07002460 args_type.push_back(irb_.getJType(shorty[i], kAccurate));
TDYa127f71bf5a2012-07-29 20:09:52 -07002461#endif
TDYa1275e869b62012-07-25 00:45:39 -07002462 }
2463
2464 return llvm::FunctionType::get(ret_type, args_type, false);
2465}
2466
2467
2468llvm::BasicBlock* GBCExpanderPass::
2469CreateBasicBlockWithDexPC(uint32_t dex_pc, const char* postfix) {
2470 std::string name;
2471
2472#if !defined(NDEBUG)
2473 StringAppendF(&name, "B%04x.%s", dex_pc, postfix);
2474#endif
2475
2476 return llvm::BasicBlock::Create(context_, name, func_);
2477}
2478
2479llvm::BasicBlock* GBCExpanderPass::GetBasicBlock(uint32_t dex_pc) {
2480 DCHECK(dex_pc < code_item_->insns_size_in_code_units_);
2481
2482 return basic_blocks_[dex_pc];
2483}
2484
2485int32_t GBCExpanderPass::GetTryItemOffset(uint32_t dex_pc) {
2486 int32_t min = 0;
2487 int32_t max = code_item_->tries_size_ - 1;
2488
2489 while (min <= max) {
2490 int32_t mid = min + (max - min) / 2;
2491
2492 const DexFile::TryItem* ti = DexFile::GetTryItems(*code_item_, mid);
2493 uint32_t start = ti->start_addr_;
2494 uint32_t end = start + ti->insn_count_;
2495
2496 if (dex_pc < start) {
2497 max = mid - 1;
2498 } else if (dex_pc >= end) {
2499 min = mid + 1;
2500 } else {
2501 return mid; // found
2502 }
2503 }
2504
2505 return -1; // not found
2506}
2507
2508llvm::BasicBlock* GBCExpanderPass::GetLandingPadBasicBlock(uint32_t dex_pc) {
2509 // Find the try item for this address in this method
2510 int32_t ti_offset = GetTryItemOffset(dex_pc);
2511
2512 if (ti_offset == -1) {
2513 return NULL; // No landing pad is available for this address.
2514 }
2515
2516 // Check for the existing landing pad basic block
2517 DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset));
2518 llvm::BasicBlock* block_lpad = basic_block_landing_pads_[ti_offset];
2519
2520 if (block_lpad) {
2521 // We have generated landing pad for this try item already. Return the
2522 // same basic block.
2523 return block_lpad;
2524 }
2525
2526 // Get try item from code item
2527 const DexFile::TryItem* ti = DexFile::GetTryItems(*code_item_, ti_offset);
2528
2529 std::string lpadname;
2530
2531#if !defined(NDEBUG)
2532 StringAppendF(&lpadname, "lpad%d_%04x_to_%04x", ti_offset, ti->start_addr_, ti->handler_off_);
2533#endif
2534
2535 // Create landing pad basic block
2536 block_lpad = llvm::BasicBlock::Create(context_, lpadname, func_);
2537
2538 // Change IRBuilder insert point
2539 llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
2540 irb_.SetInsertPoint(block_lpad);
2541
2542 // Find catch block with matching type
2543 llvm::Value* method_object_addr = EmitLoadMethodObjectAddr();
2544
2545 llvm::Value* ti_offset_value = irb_.getInt32(ti_offset);
2546
2547 llvm::Value* catch_handler_index_value =
2548 irb_.CreateCall2(irb_.GetRuntime(runtime_support::FindCatchBlock),
2549 method_object_addr, ti_offset_value);
2550
2551 // Switch instruction (Go to unwind basic block by default)
2552 llvm::SwitchInst* sw =
2553 irb_.CreateSwitch(catch_handler_index_value, GetUnwindBasicBlock());
2554
2555 // Cases with matched catch block
2556 CatchHandlerIterator iter(*code_item_, ti->start_addr_);
2557
2558 for (uint32_t c = 0; iter.HasNext(); iter.Next(), ++c) {
2559 sw->addCase(irb_.getInt32(c), GetBasicBlock(iter.GetHandlerAddress()));
2560 }
2561
2562 // Restore the orignal insert point for IRBuilder
2563 irb_.restoreIP(irb_ip_original);
2564
2565 // Cache this landing pad
2566 DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset));
2567 basic_block_landing_pads_[ti_offset] = block_lpad;
2568
2569 return block_lpad;
2570}
2571
2572llvm::BasicBlock* GBCExpanderPass::GetUnwindBasicBlock() {
2573 // Check the existing unwinding baisc block block
2574 if (basic_block_unwind_ != NULL) {
2575 return basic_block_unwind_;
2576 }
2577
2578 // Create new basic block for unwinding
2579 basic_block_unwind_ =
2580 llvm::BasicBlock::Create(context_, "exception_unwind", func_);
2581
2582 // Change IRBuilder insert point
2583 llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP();
2584 irb_.SetInsertPoint(basic_block_unwind_);
2585
2586 // Pop the shadow frame
2587 Expand_PopShadowFrame();
2588
2589 // Emit the code to return default value (zero) for the given return type.
2590 char ret_shorty = oat_compilation_unit_->GetShorty()[0];
2591 if (ret_shorty == 'V') {
2592 irb_.CreateRetVoid();
2593 } else {
2594 irb_.CreateRet(irb_.getJZero(ret_shorty));
2595 }
2596
2597 // Restore the orignal insert point for IRBuilder
2598 irb_.restoreIP(irb_ip_original);
2599
2600 return basic_block_unwind_;
2601}
2602
2603void GBCExpanderPass::EmitBranchExceptionLandingPad(uint32_t dex_pc) {
2604 if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) {
TDYa127aa558872012-08-16 05:11:07 -07002605 landing_pad_phi_mapping_[lpad].push_back(std::make_pair(old_basic_block_,
2606 irb_.GetInsertBlock()));
TDYa1275e869b62012-07-25 00:45:39 -07002607 irb_.CreateBr(lpad);
2608 } else {
2609 irb_.CreateBr(GetUnwindBasicBlock());
2610 }
2611}
2612
2613void GBCExpanderPass::EmitGuard_ExceptionLandingPad(uint32_t dex_pc) {
2614 llvm::Value* exception_pending = irb_.Runtime().EmitIsExceptionPending();
2615
2616 llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont");
2617
2618 if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) {
TDYa127aa558872012-08-16 05:11:07 -07002619 landing_pad_phi_mapping_[lpad].push_back(std::make_pair(old_basic_block_,
2620 irb_.GetInsertBlock()));
TDYa1275e869b62012-07-25 00:45:39 -07002621 irb_.CreateCondBr(exception_pending, lpad, block_cont, kUnlikely);
2622 } else {
2623 irb_.CreateCondBr(exception_pending, GetUnwindBasicBlock(), block_cont, kUnlikely);
2624 }
2625
2626 irb_.SetInsertPoint(block_cont);
2627}
2628
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002629llvm::Value*
2630GBCExpanderPass::ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id,
2631 llvm::CallInst& call_inst) {
2632 switch (intr_id) {
2633 //==- Thread -----------------------------------------------------------==//
2634 case IntrinsicHelper::GetCurrentThread: {
TDYa127b672d1e2012-06-28 21:21:45 -07002635 return irb_.Runtime().EmitGetCurrentThread();
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002636 }
Logan Chien75e4b602012-07-23 14:24:12 -07002637 case IntrinsicHelper::CheckSuspend: {
TDYa127890ea892012-08-22 10:49:42 -07002638 // We will add suspend by ourselves.
2639 return NULL;
2640 }
2641 case IntrinsicHelper::TestSuspend: {
Logan Chiend54a23d2012-07-24 11:19:23 -07002642 Expand_TestSuspend(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002643 return NULL;
2644 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002645 case IntrinsicHelper::MarkGCCard: {
TDYa1279a129452012-07-19 03:10:08 -07002646 Expand_MarkGCCard(call_inst);
2647 return NULL;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002648 }
Logan Chien75e4b602012-07-23 14:24:12 -07002649
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002650 //==- Exception --------------------------------------------------------==//
2651 case IntrinsicHelper::ThrowException: {
2652 return ExpandToRuntime(runtime_support::ThrowException, call_inst);
2653 }
TDYa127f71bf5a2012-07-29 20:09:52 -07002654 case IntrinsicHelper::HLThrowException: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002655 uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0));
2656
2657 EmitUpdateDexPC(dex_pc);
2658
2659 irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowException),
2660 call_inst.getArgOperand(0));
2661
2662 EmitGuard_ExceptionLandingPad(dex_pc);
2663 return NULL;
2664 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002665 case IntrinsicHelper::GetException: {
2666 return Expand_GetException();
2667 }
2668 case IntrinsicHelper::IsExceptionPending: {
2669 return irb_.Runtime().EmitIsExceptionPending();
2670 }
2671 case IntrinsicHelper::FindCatchBlock: {
2672 return ExpandToRuntime(runtime_support::FindCatchBlock, call_inst);
2673 }
2674 case IntrinsicHelper::ThrowDivZeroException: {
2675 return ExpandToRuntime(runtime_support::ThrowDivZeroException, call_inst);
2676 }
2677 case IntrinsicHelper::ThrowNullPointerException: {
2678 return ExpandToRuntime(runtime_support::ThrowNullPointerException, call_inst);
2679 }
2680 case IntrinsicHelper::ThrowIndexOutOfBounds: {
2681 return ExpandToRuntime(runtime_support::ThrowIndexOutOfBounds, call_inst);
2682 }
Logan Chien75e4b602012-07-23 14:24:12 -07002683
2684 //==- Const String -----------------------------------------------------==//
2685 case IntrinsicHelper::ConstString: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002686 return Expand_ConstString(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002687 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002688 case IntrinsicHelper::LoadStringFromDexCache: {
2689 return Expand_LoadStringFromDexCache(call_inst.getArgOperand(0));
2690 }
2691 case IntrinsicHelper::ResolveString: {
2692 return ExpandToRuntime(runtime_support::ResolveString, call_inst);
2693 }
Logan Chien75e4b602012-07-23 14:24:12 -07002694
2695 //==- Const Class ------------------------------------------------------==//
2696 case IntrinsicHelper::ConstClass: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002697 return Expand_ConstClass(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002698 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002699 case IntrinsicHelper::InitializeTypeAndVerifyAccess: {
2700 return ExpandToRuntime(runtime_support::InitializeTypeAndVerifyAccess, call_inst);
2701 }
2702 case IntrinsicHelper::LoadTypeFromDexCache: {
2703 return Expand_LoadTypeFromDexCache(call_inst.getArgOperand(0));
2704 }
2705 case IntrinsicHelper::InitializeType: {
2706 return ExpandToRuntime(runtime_support::InitializeType, call_inst);
2707 }
Logan Chien75e4b602012-07-23 14:24:12 -07002708
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002709 //==- Lock -------------------------------------------------------------==//
2710 case IntrinsicHelper::LockObject: {
2711 Expand_LockObject(call_inst.getArgOperand(0));
2712 return NULL;
2713 }
2714 case IntrinsicHelper::UnlockObject: {
2715 Expand_UnlockObject(call_inst.getArgOperand(0));
2716 return NULL;
2717 }
Logan Chien75e4b602012-07-23 14:24:12 -07002718
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002719 //==- Cast -------------------------------------------------------------==//
2720 case IntrinsicHelper::CheckCast: {
2721 return ExpandToRuntime(runtime_support::CheckCast, call_inst);
2722 }
Logan Chien75e4b602012-07-23 14:24:12 -07002723 case IntrinsicHelper::HLCheckCast: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002724 Expand_HLCheckCast(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002725 return NULL;
2726 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002727 case IntrinsicHelper::IsAssignable: {
2728 return ExpandToRuntime(runtime_support::IsAssignable, call_inst);
2729 }
Logan Chien75e4b602012-07-23 14:24:12 -07002730
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002731 //==- Alloc ------------------------------------------------------------==//
2732 case IntrinsicHelper::AllocObject: {
2733 return ExpandToRuntime(runtime_support::AllocObject, call_inst);
2734 }
2735 case IntrinsicHelper::AllocObjectWithAccessCheck: {
2736 return ExpandToRuntime(runtime_support::AllocObjectWithAccessCheck, call_inst);
2737 }
Logan Chien75e4b602012-07-23 14:24:12 -07002738
2739 //==- Instance ---------------------------------------------------------==//
2740 case IntrinsicHelper::NewInstance: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002741 return Expand_NewInstance(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002742 }
2743 case IntrinsicHelper::InstanceOf: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002744 return Expand_InstanceOf(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002745 }
2746
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002747 //==- Array ------------------------------------------------------------==//
Logan Chien75e4b602012-07-23 14:24:12 -07002748 case IntrinsicHelper::NewArray: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002749 return Expand_NewArray(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002750 }
2751 case IntrinsicHelper::OptArrayLength: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002752 return Expand_OptArrayLength(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002753 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002754 case IntrinsicHelper::ArrayLength: {
2755 return EmitLoadArrayLength(call_inst.getArgOperand(0));
2756 }
2757 case IntrinsicHelper::AllocArray: {
2758 return ExpandToRuntime(runtime_support::AllocArray, call_inst);
2759 }
2760 case IntrinsicHelper::AllocArrayWithAccessCheck: {
2761 return ExpandToRuntime(runtime_support::AllocArrayWithAccessCheck,
2762 call_inst);
2763 }
2764 case IntrinsicHelper::CheckAndAllocArray: {
2765 return ExpandToRuntime(runtime_support::CheckAndAllocArray, call_inst);
2766 }
2767 case IntrinsicHelper::CheckAndAllocArrayWithAccessCheck: {
2768 return ExpandToRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck,
2769 call_inst);
2770 }
2771 case IntrinsicHelper::ArrayGet: {
2772 return Expand_ArrayGet(call_inst.getArgOperand(0),
2773 call_inst.getArgOperand(1),
2774 kInt);
2775 }
2776 case IntrinsicHelper::ArrayGetWide: {
2777 return Expand_ArrayGet(call_inst.getArgOperand(0),
2778 call_inst.getArgOperand(1),
2779 kLong);
2780 }
2781 case IntrinsicHelper::ArrayGetObject: {
2782 return Expand_ArrayGet(call_inst.getArgOperand(0),
2783 call_inst.getArgOperand(1),
2784 kObject);
2785 }
2786 case IntrinsicHelper::ArrayGetBoolean: {
2787 return Expand_ArrayGet(call_inst.getArgOperand(0),
2788 call_inst.getArgOperand(1),
2789 kBoolean);
2790 }
2791 case IntrinsicHelper::ArrayGetByte: {
2792 return Expand_ArrayGet(call_inst.getArgOperand(0),
2793 call_inst.getArgOperand(1),
2794 kByte);
2795 }
2796 case IntrinsicHelper::ArrayGetChar: {
2797 return Expand_ArrayGet(call_inst.getArgOperand(0),
2798 call_inst.getArgOperand(1),
2799 kChar);
2800 }
2801 case IntrinsicHelper::ArrayGetShort: {
2802 return Expand_ArrayGet(call_inst.getArgOperand(0),
2803 call_inst.getArgOperand(1),
2804 kShort);
2805 }
2806 case IntrinsicHelper::ArrayPut: {
2807 Expand_ArrayPut(call_inst.getArgOperand(0),
2808 call_inst.getArgOperand(1),
2809 call_inst.getArgOperand(2),
2810 kInt);
2811 return NULL;
2812 }
2813 case IntrinsicHelper::ArrayPutWide: {
2814 Expand_ArrayPut(call_inst.getArgOperand(0),
2815 call_inst.getArgOperand(1),
2816 call_inst.getArgOperand(2),
2817 kLong);
2818 return NULL;
2819 }
2820 case IntrinsicHelper::ArrayPutObject: {
2821 Expand_ArrayPut(call_inst.getArgOperand(0),
2822 call_inst.getArgOperand(1),
2823 call_inst.getArgOperand(2),
2824 kObject);
2825 return NULL;
2826 }
2827 case IntrinsicHelper::ArrayPutBoolean: {
2828 Expand_ArrayPut(call_inst.getArgOperand(0),
2829 call_inst.getArgOperand(1),
2830 call_inst.getArgOperand(2),
2831 kBoolean);
2832 return NULL;
2833 }
2834 case IntrinsicHelper::ArrayPutByte: {
2835 Expand_ArrayPut(call_inst.getArgOperand(0),
2836 call_inst.getArgOperand(1),
2837 call_inst.getArgOperand(2),
2838 kByte);
2839 return NULL;
2840 }
2841 case IntrinsicHelper::ArrayPutChar: {
2842 Expand_ArrayPut(call_inst.getArgOperand(0),
2843 call_inst.getArgOperand(1),
2844 call_inst.getArgOperand(2),
2845 kChar);
2846 return NULL;
2847 }
2848 case IntrinsicHelper::ArrayPutShort: {
2849 Expand_ArrayPut(call_inst.getArgOperand(0),
2850 call_inst.getArgOperand(1),
2851 call_inst.getArgOperand(2),
2852 kShort);
2853 return NULL;
2854 }
2855 case IntrinsicHelper::CheckPutArrayElement: {
2856 return ExpandToRuntime(runtime_support::CheckPutArrayElement, call_inst);
2857 }
2858 case IntrinsicHelper::FilledNewArray: {
2859 Expand_FilledNewArray(call_inst);
2860 return NULL;
2861 }
2862 case IntrinsicHelper::FillArrayData: {
2863 return ExpandToRuntime(runtime_support::FillArrayData, call_inst);
2864 }
Logan Chien75e4b602012-07-23 14:24:12 -07002865 case IntrinsicHelper::HLFillArrayData: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002866 Expand_HLFillArrayData(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002867 return NULL;
2868 }
2869 case IntrinsicHelper::HLFilledNewArray: {
TDYa127f71bf5a2012-07-29 20:09:52 -07002870 return Expand_HLFilledNewArray(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07002871 }
2872
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002873 //==- Instance Field ---------------------------------------------------==//
2874 case IntrinsicHelper::InstanceFieldGet:
2875 case IntrinsicHelper::InstanceFieldGetBoolean:
2876 case IntrinsicHelper::InstanceFieldGetByte:
2877 case IntrinsicHelper::InstanceFieldGetChar:
2878 case IntrinsicHelper::InstanceFieldGetShort: {
2879 return ExpandToRuntime(runtime_support::Get32Instance, call_inst);
2880 }
2881 case IntrinsicHelper::InstanceFieldGetWide: {
2882 return ExpandToRuntime(runtime_support::Get64Instance, call_inst);
2883 }
2884 case IntrinsicHelper::InstanceFieldGetObject: {
2885 return ExpandToRuntime(runtime_support::GetObjectInstance, call_inst);
2886 }
2887 case IntrinsicHelper::InstanceFieldGetFast: {
2888 return Expand_IGetFast(call_inst.getArgOperand(0),
2889 call_inst.getArgOperand(1),
2890 call_inst.getArgOperand(2),
2891 kInt);
2892 }
2893 case IntrinsicHelper::InstanceFieldGetWideFast: {
2894 return Expand_IGetFast(call_inst.getArgOperand(0),
2895 call_inst.getArgOperand(1),
2896 call_inst.getArgOperand(2),
2897 kLong);
2898 }
2899 case IntrinsicHelper::InstanceFieldGetObjectFast: {
2900 return Expand_IGetFast(call_inst.getArgOperand(0),
2901 call_inst.getArgOperand(1),
2902 call_inst.getArgOperand(2),
2903 kObject);
2904 }
2905 case IntrinsicHelper::InstanceFieldGetBooleanFast: {
2906 return Expand_IGetFast(call_inst.getArgOperand(0),
2907 call_inst.getArgOperand(1),
2908 call_inst.getArgOperand(2),
2909 kBoolean);
2910 }
2911 case IntrinsicHelper::InstanceFieldGetByteFast: {
2912 return Expand_IGetFast(call_inst.getArgOperand(0),
2913 call_inst.getArgOperand(1),
2914 call_inst.getArgOperand(2),
2915 kByte);
2916 }
2917 case IntrinsicHelper::InstanceFieldGetCharFast: {
2918 return Expand_IGetFast(call_inst.getArgOperand(0),
2919 call_inst.getArgOperand(1),
2920 call_inst.getArgOperand(2),
2921 kChar);
2922 }
2923 case IntrinsicHelper::InstanceFieldGetShortFast: {
2924 return Expand_IGetFast(call_inst.getArgOperand(0),
2925 call_inst.getArgOperand(1),
2926 call_inst.getArgOperand(2),
2927 kShort);
2928 }
2929 case IntrinsicHelper::InstanceFieldPut:
2930 case IntrinsicHelper::InstanceFieldPutBoolean:
2931 case IntrinsicHelper::InstanceFieldPutByte:
2932 case IntrinsicHelper::InstanceFieldPutChar:
2933 case IntrinsicHelper::InstanceFieldPutShort: {
2934 return ExpandToRuntime(runtime_support::Set32Instance, call_inst);
2935 }
2936 case IntrinsicHelper::InstanceFieldPutWide: {
2937 return ExpandToRuntime(runtime_support::Set64Instance, call_inst);
2938 }
2939 case IntrinsicHelper::InstanceFieldPutObject: {
2940 return ExpandToRuntime(runtime_support::SetObjectInstance, call_inst);
2941 }
2942 case IntrinsicHelper::InstanceFieldPutFast: {
2943 Expand_IPutFast(call_inst.getArgOperand(0),
2944 call_inst.getArgOperand(1),
2945 call_inst.getArgOperand(2),
2946 call_inst.getArgOperand(3),
2947 kInt);
2948 return NULL;
2949 }
2950 case IntrinsicHelper::InstanceFieldPutWideFast: {
2951 Expand_IPutFast(call_inst.getArgOperand(0),
2952 call_inst.getArgOperand(1),
2953 call_inst.getArgOperand(2),
2954 call_inst.getArgOperand(3),
2955 kLong);
2956 return NULL;
2957 }
2958 case IntrinsicHelper::InstanceFieldPutObjectFast: {
2959 Expand_IPutFast(call_inst.getArgOperand(0),
2960 call_inst.getArgOperand(1),
2961 call_inst.getArgOperand(2),
2962 call_inst.getArgOperand(3),
2963 kObject);
2964 return NULL;
2965 }
2966 case IntrinsicHelper::InstanceFieldPutBooleanFast: {
2967 Expand_IPutFast(call_inst.getArgOperand(0),
2968 call_inst.getArgOperand(1),
2969 call_inst.getArgOperand(2),
2970 call_inst.getArgOperand(3),
2971 kBoolean);
2972 return NULL;
2973 }
2974 case IntrinsicHelper::InstanceFieldPutByteFast: {
2975 Expand_IPutFast(call_inst.getArgOperand(0),
2976 call_inst.getArgOperand(1),
2977 call_inst.getArgOperand(2),
2978 call_inst.getArgOperand(3),
2979 kByte);
2980 return NULL;
2981 }
2982 case IntrinsicHelper::InstanceFieldPutCharFast: {
2983 Expand_IPutFast(call_inst.getArgOperand(0),
2984 call_inst.getArgOperand(1),
2985 call_inst.getArgOperand(2),
2986 call_inst.getArgOperand(3),
2987 kChar);
2988 return NULL;
2989 }
2990 case IntrinsicHelper::InstanceFieldPutShortFast: {
2991 Expand_IPutFast(call_inst.getArgOperand(0),
2992 call_inst.getArgOperand(1),
2993 call_inst.getArgOperand(2),
2994 call_inst.getArgOperand(3),
2995 kShort);
2996 return NULL;
2997 }
Logan Chien75e4b602012-07-23 14:24:12 -07002998
Shih-wei Liao21d28f52012-06-12 05:55:00 -07002999 //==- Static Field -----------------------------------------------------==//
3000 case IntrinsicHelper::StaticFieldGet:
3001 case IntrinsicHelper::StaticFieldGetBoolean:
3002 case IntrinsicHelper::StaticFieldGetByte:
3003 case IntrinsicHelper::StaticFieldGetChar:
3004 case IntrinsicHelper::StaticFieldGetShort: {
3005 return ExpandToRuntime(runtime_support::Get32Static, call_inst);
3006 }
3007 case IntrinsicHelper::StaticFieldGetWide: {
3008 return ExpandToRuntime(runtime_support::Get64Static, call_inst);
3009 }
3010 case IntrinsicHelper::StaticFieldGetObject: {
3011 return ExpandToRuntime(runtime_support::GetObjectStatic, call_inst);
3012 }
3013 case IntrinsicHelper::StaticFieldGetFast: {
3014 return Expand_SGetFast(call_inst.getArgOperand(0),
3015 call_inst.getArgOperand(1),
3016 call_inst.getArgOperand(2),
3017 kInt);
3018 }
3019 case IntrinsicHelper::StaticFieldGetWideFast: {
3020 return Expand_SGetFast(call_inst.getArgOperand(0),
3021 call_inst.getArgOperand(1),
3022 call_inst.getArgOperand(2),
3023 kLong);
3024 }
3025 case IntrinsicHelper::StaticFieldGetObjectFast: {
3026 return Expand_SGetFast(call_inst.getArgOperand(0),
3027 call_inst.getArgOperand(1),
3028 call_inst.getArgOperand(2),
3029 kObject);
3030 }
3031 case IntrinsicHelper::StaticFieldGetBooleanFast: {
3032 return Expand_SGetFast(call_inst.getArgOperand(0),
3033 call_inst.getArgOperand(1),
3034 call_inst.getArgOperand(2),
3035 kBoolean);
3036 }
3037 case IntrinsicHelper::StaticFieldGetByteFast: {
3038 return Expand_SGetFast(call_inst.getArgOperand(0),
3039 call_inst.getArgOperand(1),
3040 call_inst.getArgOperand(2),
3041 kByte);
3042 }
3043 case IntrinsicHelper::StaticFieldGetCharFast: {
3044 return Expand_SGetFast(call_inst.getArgOperand(0),
3045 call_inst.getArgOperand(1),
3046 call_inst.getArgOperand(2),
3047 kChar);
3048 }
3049 case IntrinsicHelper::StaticFieldGetShortFast: {
3050 return Expand_SGetFast(call_inst.getArgOperand(0),
3051 call_inst.getArgOperand(1),
3052 call_inst.getArgOperand(2),
3053 kShort);
3054 }
3055 case IntrinsicHelper::StaticFieldPut:
3056 case IntrinsicHelper::StaticFieldPutBoolean:
3057 case IntrinsicHelper::StaticFieldPutByte:
3058 case IntrinsicHelper::StaticFieldPutChar:
3059 case IntrinsicHelper::StaticFieldPutShort: {
3060 return ExpandToRuntime(runtime_support::Set32Static, call_inst);
3061 }
3062 case IntrinsicHelper::StaticFieldPutWide: {
3063 return ExpandToRuntime(runtime_support::Set64Static, call_inst);
3064 }
3065 case IntrinsicHelper::StaticFieldPutObject: {
3066 return ExpandToRuntime(runtime_support::SetObjectStatic, call_inst);
3067 }
3068 case IntrinsicHelper::StaticFieldPutFast: {
3069 Expand_SPutFast(call_inst.getArgOperand(0),
3070 call_inst.getArgOperand(1),
3071 call_inst.getArgOperand(2),
3072 call_inst.getArgOperand(3),
3073 kInt);
3074 return NULL;
3075 }
3076 case IntrinsicHelper::StaticFieldPutWideFast: {
3077 Expand_SPutFast(call_inst.getArgOperand(0),
3078 call_inst.getArgOperand(1),
3079 call_inst.getArgOperand(2),
3080 call_inst.getArgOperand(3),
3081 kLong);
3082 return NULL;
3083 }
3084 case IntrinsicHelper::StaticFieldPutObjectFast: {
3085 Expand_SPutFast(call_inst.getArgOperand(0),
3086 call_inst.getArgOperand(1),
3087 call_inst.getArgOperand(2),
3088 call_inst.getArgOperand(3),
3089 kObject);
3090 return NULL;
3091 }
3092 case IntrinsicHelper::StaticFieldPutBooleanFast: {
3093 Expand_SPutFast(call_inst.getArgOperand(0),
3094 call_inst.getArgOperand(1),
3095 call_inst.getArgOperand(2),
3096 call_inst.getArgOperand(3),
3097 kBoolean);
3098 return NULL;
3099 }
3100 case IntrinsicHelper::StaticFieldPutByteFast: {
3101 Expand_SPutFast(call_inst.getArgOperand(0),
3102 call_inst.getArgOperand(1),
3103 call_inst.getArgOperand(2),
3104 call_inst.getArgOperand(3),
3105 kByte);
3106 return NULL;
3107 }
3108 case IntrinsicHelper::StaticFieldPutCharFast: {
3109 Expand_SPutFast(call_inst.getArgOperand(0),
3110 call_inst.getArgOperand(1),
3111 call_inst.getArgOperand(2),
3112 call_inst.getArgOperand(3),
3113 kChar);
3114 return NULL;
3115 }
3116 case IntrinsicHelper::StaticFieldPutShortFast: {
3117 Expand_SPutFast(call_inst.getArgOperand(0),
3118 call_inst.getArgOperand(1),
3119 call_inst.getArgOperand(2),
3120 call_inst.getArgOperand(3),
3121 kShort);
3122 return NULL;
3123 }
3124 case IntrinsicHelper::LoadDeclaringClassSSB: {
3125 return Expand_LoadDeclaringClassSSB(call_inst.getArgOperand(0));
3126 }
3127 case IntrinsicHelper::LoadClassSSBFromDexCache: {
3128 return Expand_LoadClassSSBFromDexCache(call_inst.getArgOperand(0));
3129 }
3130 case IntrinsicHelper::InitializeAndLoadClassSSB: {
3131 return ExpandToRuntime(runtime_support::InitializeStaticStorage, call_inst);
3132 }
Logan Chien75e4b602012-07-23 14:24:12 -07003133
3134 //==- High-level Array -------------------------------------------------==//
3135 case IntrinsicHelper::HLArrayGet: {
TDYa1275a26d442012-07-26 18:58:38 -07003136 return Expand_HLArrayGet(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003137 }
3138 case IntrinsicHelper::HLArrayGetBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003139 return Expand_HLArrayGet(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003140 }
3141 case IntrinsicHelper::HLArrayGetByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003142 return Expand_HLArrayGet(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003143 }
3144 case IntrinsicHelper::HLArrayGetChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003145 return Expand_HLArrayGet(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003146 }
3147 case IntrinsicHelper::HLArrayGetShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003148 return Expand_HLArrayGet(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003149 }
3150 case IntrinsicHelper::HLArrayGetFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003151 return Expand_HLArrayGet(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003152 }
3153 case IntrinsicHelper::HLArrayGetWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003154 return Expand_HLArrayGet(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003155 }
3156 case IntrinsicHelper::HLArrayGetDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003157 return Expand_HLArrayGet(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003158 }
3159 case IntrinsicHelper::HLArrayGetObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003160 return Expand_HLArrayGet(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003161 }
3162 case IntrinsicHelper::HLArrayPut: {
TDYa1275a26d442012-07-26 18:58:38 -07003163 Expand_HLArrayPut(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003164 return NULL;
3165 }
3166 case IntrinsicHelper::HLArrayPutBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003167 Expand_HLArrayPut(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003168 return NULL;
3169 }
3170 case IntrinsicHelper::HLArrayPutByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003171 Expand_HLArrayPut(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003172 return NULL;
3173 }
3174 case IntrinsicHelper::HLArrayPutChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003175 Expand_HLArrayPut(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003176 return NULL;
3177 }
3178 case IntrinsicHelper::HLArrayPutShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003179 Expand_HLArrayPut(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003180 return NULL;
3181 }
3182 case IntrinsicHelper::HLArrayPutFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003183 Expand_HLArrayPut(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003184 return NULL;
3185 }
3186 case IntrinsicHelper::HLArrayPutWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003187 Expand_HLArrayPut(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003188 return NULL;
3189 }
3190 case IntrinsicHelper::HLArrayPutDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003191 Expand_HLArrayPut(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003192 return NULL;
3193 }
3194 case IntrinsicHelper::HLArrayPutObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003195 Expand_HLArrayPut(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003196 return NULL;
3197 }
3198
3199 //==- High-level Instance ----------------------------------------------==//
3200 case IntrinsicHelper::HLIGet: {
TDYa1275e869b62012-07-25 00:45:39 -07003201 return Expand_HLIGet(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003202 }
3203 case IntrinsicHelper::HLIGetBoolean: {
TDYa1275e869b62012-07-25 00:45:39 -07003204 return Expand_HLIGet(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003205 }
3206 case IntrinsicHelper::HLIGetByte: {
TDYa1275e869b62012-07-25 00:45:39 -07003207 return Expand_HLIGet(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003208 }
3209 case IntrinsicHelper::HLIGetChar: {
TDYa1275e869b62012-07-25 00:45:39 -07003210 return Expand_HLIGet(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003211 }
3212 case IntrinsicHelper::HLIGetShort: {
TDYa1275e869b62012-07-25 00:45:39 -07003213 return Expand_HLIGet(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003214 }
3215 case IntrinsicHelper::HLIGetFloat: {
TDYa1275e869b62012-07-25 00:45:39 -07003216 return Expand_HLIGet(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003217 }
3218 case IntrinsicHelper::HLIGetWide: {
TDYa1275e869b62012-07-25 00:45:39 -07003219 return Expand_HLIGet(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003220 }
3221 case IntrinsicHelper::HLIGetDouble: {
TDYa1275e869b62012-07-25 00:45:39 -07003222 return Expand_HLIGet(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003223 }
3224 case IntrinsicHelper::HLIGetObject: {
TDYa1275e869b62012-07-25 00:45:39 -07003225 return Expand_HLIGet(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003226 }
3227 case IntrinsicHelper::HLIPut: {
TDYa1275e869b62012-07-25 00:45:39 -07003228 Expand_HLIPut(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003229 return NULL;
3230 }
3231 case IntrinsicHelper::HLIPutBoolean: {
TDYa1275e869b62012-07-25 00:45:39 -07003232 Expand_HLIPut(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003233 return NULL;
3234 }
3235 case IntrinsicHelper::HLIPutByte: {
TDYa1275e869b62012-07-25 00:45:39 -07003236 Expand_HLIPut(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003237 return NULL;
3238 }
3239 case IntrinsicHelper::HLIPutChar: {
TDYa1275e869b62012-07-25 00:45:39 -07003240 Expand_HLIPut(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003241 return NULL;
3242 }
3243 case IntrinsicHelper::HLIPutShort: {
TDYa1275e869b62012-07-25 00:45:39 -07003244 Expand_HLIPut(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003245 return NULL;
3246 }
3247 case IntrinsicHelper::HLIPutFloat: {
TDYa1275e869b62012-07-25 00:45:39 -07003248 Expand_HLIPut(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003249 return NULL;
3250 }
3251 case IntrinsicHelper::HLIPutWide: {
TDYa1275e869b62012-07-25 00:45:39 -07003252 Expand_HLIPut(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003253 return NULL;
3254 }
3255 case IntrinsicHelper::HLIPutDouble: {
TDYa1275e869b62012-07-25 00:45:39 -07003256 Expand_HLIPut(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003257 return NULL;
3258 }
3259 case IntrinsicHelper::HLIPutObject: {
TDYa1275e869b62012-07-25 00:45:39 -07003260 Expand_HLIPut(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003261 return NULL;
3262 }
3263
3264 //==- High-level Invoke ------------------------------------------------==//
TDYa127f71bf5a2012-07-29 20:09:52 -07003265 case IntrinsicHelper::HLInvokeVoid:
3266 case IntrinsicHelper::HLInvokeObj:
3267 case IntrinsicHelper::HLInvokeInt:
3268 case IntrinsicHelper::HLInvokeFloat:
3269 case IntrinsicHelper::HLInvokeLong:
Logan Chien75e4b602012-07-23 14:24:12 -07003270 case IntrinsicHelper::HLInvokeDouble: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003271 return Expand_HLInvoke(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003272 }
3273
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003274 //==- Invoke -----------------------------------------------------------==//
3275 case IntrinsicHelper::FindStaticMethodWithAccessCheck: {
3276 return ExpandToRuntime(runtime_support::FindStaticMethodWithAccessCheck, call_inst);
3277 }
3278 case IntrinsicHelper::FindDirectMethodWithAccessCheck: {
3279 return ExpandToRuntime(runtime_support::FindDirectMethodWithAccessCheck, call_inst);
3280 }
3281 case IntrinsicHelper::FindVirtualMethodWithAccessCheck: {
3282 return ExpandToRuntime(runtime_support::FindVirtualMethodWithAccessCheck, call_inst);
3283 }
3284 case IntrinsicHelper::FindSuperMethodWithAccessCheck: {
3285 return ExpandToRuntime(runtime_support::FindSuperMethodWithAccessCheck, call_inst);
3286 }
3287 case IntrinsicHelper::FindInterfaceMethodWithAccessCheck: {
3288 return ExpandToRuntime(runtime_support::FindInterfaceMethodWithAccessCheck, call_inst);
3289 }
3290 case IntrinsicHelper::GetSDCalleeMethodObjAddrFast: {
3291 return Expand_GetSDCalleeMethodObjAddrFast(call_inst.getArgOperand(0));
3292 }
3293 case IntrinsicHelper::GetVirtualCalleeMethodObjAddrFast: {
3294 return Expand_GetVirtualCalleeMethodObjAddrFast(
3295 call_inst.getArgOperand(0), call_inst.getArgOperand(1));
3296 }
3297 case IntrinsicHelper::GetInterfaceCalleeMethodObjAddrFast: {
3298 return ExpandToRuntime(runtime_support::FindInterfaceMethod, call_inst);
3299 }
3300 case IntrinsicHelper::InvokeRetVoid:
3301 case IntrinsicHelper::InvokeRetBoolean:
3302 case IntrinsicHelper::InvokeRetByte:
3303 case IntrinsicHelper::InvokeRetChar:
3304 case IntrinsicHelper::InvokeRetShort:
3305 case IntrinsicHelper::InvokeRetInt:
3306 case IntrinsicHelper::InvokeRetLong:
3307 case IntrinsicHelper::InvokeRetFloat:
3308 case IntrinsicHelper::InvokeRetDouble:
3309 case IntrinsicHelper::InvokeRetObject: {
3310 return Expand_Invoke(call_inst);
3311 }
Logan Chien75e4b602012-07-23 14:24:12 -07003312
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003313 //==- Math -------------------------------------------------------------==//
3314 case IntrinsicHelper::DivInt: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003315 return Expand_DivRem(call_inst, /* is_div */true, kInt);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003316 }
3317 case IntrinsicHelper::RemInt: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003318 return Expand_DivRem(call_inst, /* is_div */false, kInt);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003319 }
3320 case IntrinsicHelper::DivLong: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003321 return Expand_DivRem(call_inst, /* is_div */true, kLong);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003322 }
3323 case IntrinsicHelper::RemLong: {
TDYa1274ec8ccd2012-08-11 07:04:57 -07003324 return Expand_DivRem(call_inst, /* is_div */false, kLong);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003325 }
3326 case IntrinsicHelper::D2L: {
3327 return ExpandToRuntime(runtime_support::art_d2l, call_inst);
3328 }
3329 case IntrinsicHelper::D2I: {
3330 return ExpandToRuntime(runtime_support::art_d2i, call_inst);
3331 }
3332 case IntrinsicHelper::F2L: {
3333 return ExpandToRuntime(runtime_support::art_f2l, call_inst);
3334 }
3335 case IntrinsicHelper::F2I: {
3336 return ExpandToRuntime(runtime_support::art_f2i, call_inst);
3337 }
Logan Chien75e4b602012-07-23 14:24:12 -07003338
3339 //==- High-level Static ------------------------------------------------==//
3340 case IntrinsicHelper::HLSget: {
TDYa1275a26d442012-07-26 18:58:38 -07003341 return Expand_HLSget(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003342 }
3343 case IntrinsicHelper::HLSgetBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003344 return Expand_HLSget(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003345 }
3346 case IntrinsicHelper::HLSgetByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003347 return Expand_HLSget(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003348 }
3349 case IntrinsicHelper::HLSgetChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003350 return Expand_HLSget(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003351 }
3352 case IntrinsicHelper::HLSgetShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003353 return Expand_HLSget(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003354 }
3355 case IntrinsicHelper::HLSgetFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003356 return Expand_HLSget(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003357 }
3358 case IntrinsicHelper::HLSgetWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003359 return Expand_HLSget(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003360 }
3361 case IntrinsicHelper::HLSgetDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003362 return Expand_HLSget(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003363 }
3364 case IntrinsicHelper::HLSgetObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003365 return Expand_HLSget(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003366 }
3367 case IntrinsicHelper::HLSput: {
TDYa1275a26d442012-07-26 18:58:38 -07003368 Expand_HLSput(call_inst, kInt);
Logan Chien75e4b602012-07-23 14:24:12 -07003369 return NULL;
3370 }
3371 case IntrinsicHelper::HLSputBoolean: {
TDYa1275a26d442012-07-26 18:58:38 -07003372 Expand_HLSput(call_inst, kBoolean);
Logan Chien75e4b602012-07-23 14:24:12 -07003373 return NULL;
3374 }
3375 case IntrinsicHelper::HLSputByte: {
TDYa1275a26d442012-07-26 18:58:38 -07003376 Expand_HLSput(call_inst, kByte);
Logan Chien75e4b602012-07-23 14:24:12 -07003377 return NULL;
3378 }
3379 case IntrinsicHelper::HLSputChar: {
TDYa1275a26d442012-07-26 18:58:38 -07003380 Expand_HLSput(call_inst, kChar);
Logan Chien75e4b602012-07-23 14:24:12 -07003381 return NULL;
3382 }
3383 case IntrinsicHelper::HLSputShort: {
TDYa1275a26d442012-07-26 18:58:38 -07003384 Expand_HLSput(call_inst, kShort);
Logan Chien75e4b602012-07-23 14:24:12 -07003385 return NULL;
3386 }
3387 case IntrinsicHelper::HLSputFloat: {
TDYa1275a26d442012-07-26 18:58:38 -07003388 Expand_HLSput(call_inst, kFloat);
Logan Chien75e4b602012-07-23 14:24:12 -07003389 return NULL;
3390 }
3391 case IntrinsicHelper::HLSputWide: {
TDYa1275a26d442012-07-26 18:58:38 -07003392 Expand_HLSput(call_inst, kLong);
Logan Chien75e4b602012-07-23 14:24:12 -07003393 return NULL;
3394 }
3395 case IntrinsicHelper::HLSputDouble: {
TDYa1275a26d442012-07-26 18:58:38 -07003396 Expand_HLSput(call_inst, kDouble);
Logan Chien75e4b602012-07-23 14:24:12 -07003397 return NULL;
3398 }
3399 case IntrinsicHelper::HLSputObject: {
TDYa1275a26d442012-07-26 18:58:38 -07003400 Expand_HLSput(call_inst, kObject);
Logan Chien75e4b602012-07-23 14:24:12 -07003401 return NULL;
3402 }
3403
3404 //==- High-level Monitor -----------------------------------------------==//
3405 case IntrinsicHelper::MonitorEnter: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003406 Expand_MonitorEnter(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003407 return NULL;
3408 }
3409 case IntrinsicHelper::MonitorExit: {
TDYa127f71bf5a2012-07-29 20:09:52 -07003410 Expand_MonitorExit(call_inst);
Logan Chien75e4b602012-07-23 14:24:12 -07003411 return NULL;
3412 }
3413
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003414 //==- Shadow Frame -----------------------------------------------------==//
3415 case IntrinsicHelper::AllocaShadowFrame: {
3416 Expand_AllocaShadowFrame(call_inst.getArgOperand(0));
3417 return NULL;
3418 }
3419 case IntrinsicHelper::SetShadowFrameEntry: {
3420 Expand_SetShadowFrameEntry(call_inst.getArgOperand(0),
3421 call_inst.getArgOperand(1));
3422 return NULL;
3423 }
3424 case IntrinsicHelper::PopShadowFrame: {
3425 Expand_PopShadowFrame();
3426 return NULL;
3427 }
3428 case IntrinsicHelper::UpdateDexPC: {
3429 Expand_UpdateDexPC(call_inst.getArgOperand(0));
3430 return NULL;
3431 }
TDYa127a1b21852012-07-23 03:20:39 -07003432
Logan Chien75e4b602012-07-23 14:24:12 -07003433 //==- Comparison -------------------------------------------------------==//
3434 case IntrinsicHelper::CmplFloat:
3435 case IntrinsicHelper::CmplDouble: {
3436 return Expand_FPCompare(call_inst.getArgOperand(0),
3437 call_inst.getArgOperand(1),
3438 false);
3439 }
3440 case IntrinsicHelper::CmpgFloat:
3441 case IntrinsicHelper::CmpgDouble: {
3442 return Expand_FPCompare(call_inst.getArgOperand(0),
3443 call_inst.getArgOperand(1),
3444 true);
3445 }
3446 case IntrinsicHelper::CmpLong: {
3447 return Expand_LongCompare(call_inst.getArgOperand(0),
3448 call_inst.getArgOperand(1));
3449 }
TDYa127a1b21852012-07-23 03:20:39 -07003450
Logan Chien75e4b602012-07-23 14:24:12 -07003451 //==- Switch -----------------------------------------------------------==//
3452 case greenland::IntrinsicHelper::SparseSwitch: {
TDYa1275e869b62012-07-25 00:45:39 -07003453 // Nothing to be done.
Logan Chien75e4b602012-07-23 14:24:12 -07003454 return NULL;
3455 }
3456 case greenland::IntrinsicHelper::PackedSwitch: {
TDYa1275e869b62012-07-25 00:45:39 -07003457 // Nothing to be done.
Logan Chien75e4b602012-07-23 14:24:12 -07003458 return NULL;
3459 }
3460
3461 //==- Const ------------------------------------------------------------==//
Logan Chiend54a23d2012-07-24 11:19:23 -07003462 case greenland::IntrinsicHelper::ConstInt:
Logan Chien75e4b602012-07-23 14:24:12 -07003463 case greenland::IntrinsicHelper::ConstLong: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003464 return call_inst.getArgOperand(0);
Logan Chien75e4b602012-07-23 14:24:12 -07003465 }
3466 case greenland::IntrinsicHelper::ConstFloat: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003467 return irb_.CreateBitCast(call_inst.getArgOperand(0),
3468 irb_.getJFloatTy());
Logan Chien75e4b602012-07-23 14:24:12 -07003469 }
3470 case greenland::IntrinsicHelper::ConstDouble: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003471 return irb_.CreateBitCast(call_inst.getArgOperand(0),
3472 irb_.getJDoubleTy());
3473 }
3474 case greenland::IntrinsicHelper::ConstObj: {
3475 LOG(FATAL) << "ConstObj should not occur at all";
Logan Chien75e4b602012-07-23 14:24:12 -07003476 return NULL;
3477 }
3478
3479 //==- Method Info ------------------------------------------------------==//
3480 case greenland::IntrinsicHelper::MethodInfo: {
TDYa1275e869b62012-07-25 00:45:39 -07003481 // Nothing to be done.
Logan Chien75e4b602012-07-23 14:24:12 -07003482 return NULL;
3483 }
3484
3485 //==- Copy -------------------------------------------------------------==//
Logan Chiend54a23d2012-07-24 11:19:23 -07003486 case greenland::IntrinsicHelper::CopyInt:
3487 case greenland::IntrinsicHelper::CopyFloat:
3488 case greenland::IntrinsicHelper::CopyLong:
TDYa1275e869b62012-07-25 00:45:39 -07003489 case greenland::IntrinsicHelper::CopyDouble:
Logan Chien75e4b602012-07-23 14:24:12 -07003490 case greenland::IntrinsicHelper::CopyObj: {
Logan Chiend54a23d2012-07-24 11:19:23 -07003491 return call_inst.getArgOperand(0);
Logan Chien75e4b602012-07-23 14:24:12 -07003492 }
3493
3494 //==- Shift ------------------------------------------------------------==//
3495 case greenland::IntrinsicHelper::SHLLong: {
3496 return Expand_IntegerShift(call_inst.getArgOperand(0),
3497 call_inst.getArgOperand(1),
3498 kIntegerSHL, kLong);
3499 }
3500 case greenland::IntrinsicHelper::SHRLong: {
3501 return Expand_IntegerShift(call_inst.getArgOperand(0),
3502 call_inst.getArgOperand(1),
3503 kIntegerSHR, kLong);
3504 }
3505 case greenland::IntrinsicHelper::USHRLong: {
3506 return Expand_IntegerShift(call_inst.getArgOperand(0),
3507 call_inst.getArgOperand(1),
3508 kIntegerUSHR, kLong);
3509 }
3510 case greenland::IntrinsicHelper::SHLInt: {
3511 return Expand_IntegerShift(call_inst.getArgOperand(0),
3512 call_inst.getArgOperand(1),
3513 kIntegerSHL, kInt);
3514 }
3515 case greenland::IntrinsicHelper::SHRInt: {
3516 return Expand_IntegerShift(call_inst.getArgOperand(0),
3517 call_inst.getArgOperand(1),
3518 kIntegerSHR, kInt);
3519 }
3520 case greenland::IntrinsicHelper::USHRInt: {
3521 return Expand_IntegerShift(call_inst.getArgOperand(0),
3522 call_inst.getArgOperand(1),
3523 kIntegerUSHR, kInt);
3524 }
3525
3526 //==- Conversion -------------------------------------------------------==//
TDYa127a1b21852012-07-23 03:20:39 -07003527 case IntrinsicHelper::IntToChar: {
3528 return irb_.CreateZExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJCharTy()),
3529 irb_.getJIntTy());
3530 }
3531 case IntrinsicHelper::IntToShort: {
3532 return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJShortTy()),
3533 irb_.getJIntTy());
3534 }
3535 case IntrinsicHelper::IntToByte: {
3536 return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJByteTy()),
3537 irb_.getJIntTy());
3538 }
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003539
Logan Chien75e4b602012-07-23 14:24:12 -07003540 //==- Unknown Cases ----------------------------------------------------==//
3541 case IntrinsicHelper::MaxIntrinsicId:
3542 case IntrinsicHelper::UnknownId:
3543 //default:
3544 // NOTE: "default" is intentionally commented so that C/C++ compiler will
3545 // give some warning on unmatched cases.
3546 // NOTE: We should not implement these cases.
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003547 break;
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003548 }
Logan Chien75e4b602012-07-23 14:24:12 -07003549 UNIMPLEMENTED(FATAL) << "Unexpected GBC intrinsic: " << static_cast<int>(intr_id);
Shih-wei Liao21d28f52012-06-12 05:55:00 -07003550 return NULL;
3551}
3552
3553} // anonymous namespace
3554
3555namespace art {
3556namespace compiler_llvm {
3557
3558llvm::FunctionPass*
3559CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb) {
3560 return new GBCExpanderPass(intrinsic_helper, irb);
3561}
3562
3563} // namespace compiler_llvm
3564} // namespace art