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