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