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