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 | |
| 1434 | // TODO: Check is_volatile. We need to generate atomic load instruction |
| 1435 | // when is_volatile is true. |
| 1436 | field_value = irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty); |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1437 | field_value = SignOrZeroExtendCat1Types(field_value, field_jty); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1440 | return field_value; |
| 1441 | } |
| 1442 | |
| 1443 | void GBCExpanderPass::Expand_HLIPut(llvm::CallInst& call_inst, |
| 1444 | JType field_jty) { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1445 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1446 | llvm::Value* new_value = call_inst.getArgOperand(1); |
| 1447 | llvm::Value* object_addr = call_inst.getArgOperand(2); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1448 | uint32_t field_idx = LV2UInt(call_inst.getArgOperand(3)); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1449 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1450 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 1451 | EmitGuard_NullPointerException(dex_pc, object_addr, opt_flags); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1452 | |
| 1453 | int field_offset; |
| 1454 | bool is_volatile; |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 1455 | bool is_fast_path = driver_->ComputeInstanceFieldInfo( |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 1456 | field_idx, dex_compilation_unit_, field_offset, is_volatile, true); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1457 | |
| 1458 | if (!is_fast_path) { |
| 1459 | llvm::Function* runtime_func; |
| 1460 | |
Ian Rogers | 1b2b71f | 2013-03-01 11:31:30 -0800 | [diff] [blame] | 1461 | if (field_jty == kFloat) { |
| 1462 | new_value = irb_.CreateBitCast(new_value, irb_.getJType(kInt)); |
| 1463 | } else if (field_jty == kDouble) { |
| 1464 | new_value = irb_.CreateBitCast(new_value, irb_.getJType(kLong)); |
| 1465 | } |
| 1466 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1467 | if (field_jty == kObject) { |
| 1468 | runtime_func = irb_.GetRuntime(runtime_support::SetObjectInstance); |
| 1469 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 1470 | runtime_func = irb_.GetRuntime(runtime_support::Set64Instance); |
| 1471 | } else { |
| 1472 | runtime_func = irb_.GetRuntime(runtime_support::Set32Instance); |
| 1473 | } |
| 1474 | |
| 1475 | llvm::Value* field_idx_value = irb_.getInt32(field_idx); |
| 1476 | |
| 1477 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1478 | |
| 1479 | EmitUpdateDexPC(dex_pc); |
| 1480 | |
| 1481 | irb_.CreateCall4(runtime_func, field_idx_value, |
| 1482 | method_object_addr, object_addr, new_value); |
| 1483 | |
| 1484 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1485 | |
| 1486 | } else { |
| 1487 | DCHECK_GE(field_offset, 0); |
| 1488 | |
| 1489 | llvm::PointerType* field_type = |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1490 | irb_.getJType(field_jty)->getPointerTo(); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1491 | |
| 1492 | llvm::Value* field_offset_value = irb_.getPtrEquivInt(field_offset); |
| 1493 | |
| 1494 | llvm::Value* field_addr = |
| 1495 | irb_.CreatePtrDisp(object_addr, field_offset_value, field_type); |
| 1496 | |
| 1497 | // TODO: Check is_volatile. We need to generate atomic store instruction |
| 1498 | // when is_volatile is true. |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1499 | new_value = TruncateCat1Types(new_value, field_jty); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1500 | irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty); |
| 1501 | |
| 1502 | if (field_jty == kObject) { // If put an object, mark the GC card table. |
| 1503 | EmitMarkGCCard(new_value, object_addr); |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | return; |
| 1508 | } |
| 1509 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1510 | llvm::Value* GBCExpanderPass::EmitLoadConstantClass(uint32_t dex_pc, |
| 1511 | uint32_t type_idx) { |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 1512 | if (!driver_->CanAccessTypeWithoutChecks(dex_compilation_unit_->GetDexMethodIndex(), |
| 1513 | *dex_compilation_unit_->GetDexFile(), type_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1514 | llvm::Value* type_idx_value = irb_.getInt32(type_idx); |
| 1515 | |
| 1516 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1517 | |
| 1518 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 1519 | |
| 1520 | llvm::Function* runtime_func = |
| 1521 | irb_.GetRuntime(runtime_support::InitializeTypeAndVerifyAccess); |
| 1522 | |
| 1523 | EmitUpdateDexPC(dex_pc); |
| 1524 | |
| 1525 | llvm::Value* type_object_addr = |
| 1526 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
| 1527 | |
| 1528 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1529 | |
| 1530 | return type_object_addr; |
| 1531 | |
| 1532 | } else { |
| 1533 | // Try to load the class (type) object from the test cache. |
| 1534 | llvm::Value* type_field_addr = |
| 1535 | EmitLoadDexCacheResolvedTypeFieldAddr(type_idx); |
| 1536 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 1537 | llvm::Value* type_object_addr = irb_.CreateLoad(type_field_addr, kTBAARuntimeInfo); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1538 | |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 1539 | if (driver_->CanAssumeTypeIsPresentInDexCache(*dex_compilation_unit_->GetDexFile(), type_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1540 | return type_object_addr; |
| 1541 | } |
| 1542 | |
| 1543 | llvm::BasicBlock* block_original = irb_.GetInsertBlock(); |
| 1544 | |
| 1545 | // Test whether class (type) object is in the dex cache or not |
| 1546 | llvm::Value* equal_null = |
| 1547 | irb_.CreateICmpEQ(type_object_addr, irb_.getJNull()); |
| 1548 | |
| 1549 | llvm::BasicBlock* block_cont = |
| 1550 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 1551 | |
| 1552 | llvm::BasicBlock* block_load_class = |
| 1553 | CreateBasicBlockWithDexPC(dex_pc, "load_class"); |
| 1554 | |
| 1555 | irb_.CreateCondBr(equal_null, block_load_class, block_cont, kUnlikely); |
| 1556 | |
| 1557 | // Failback routine to load the class object |
| 1558 | irb_.SetInsertPoint(block_load_class); |
| 1559 | |
| 1560 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeType); |
| 1561 | |
| 1562 | llvm::Constant* type_idx_value = irb_.getInt32(type_idx); |
| 1563 | |
| 1564 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1565 | |
| 1566 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 1567 | |
| 1568 | EmitUpdateDexPC(dex_pc); |
| 1569 | |
| 1570 | llvm::Value* loaded_type_object_addr = |
| 1571 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
| 1572 | |
| 1573 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1574 | |
| 1575 | llvm::BasicBlock* block_after_load_class = irb_.GetInsertBlock(); |
| 1576 | |
| 1577 | irb_.CreateBr(block_cont); |
| 1578 | |
| 1579 | // Now the class object must be loaded |
| 1580 | irb_.SetInsertPoint(block_cont); |
| 1581 | |
| 1582 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 1583 | |
| 1584 | phi->addIncoming(type_object_addr, block_original); |
| 1585 | phi->addIncoming(loaded_type_object_addr, block_after_load_class); |
| 1586 | |
| 1587 | return phi; |
| 1588 | } |
| 1589 | } |
| 1590 | |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1591 | llvm::Value* GBCExpanderPass::EmitLoadStaticStorage(uint32_t dex_pc, |
| 1592 | uint32_t type_idx) { |
| 1593 | llvm::BasicBlock* block_load_static = |
| 1594 | CreateBasicBlockWithDexPC(dex_pc, "load_static"); |
| 1595 | |
| 1596 | llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 1597 | |
| 1598 | // Load static storage from dex cache |
| 1599 | llvm::Value* storage_field_addr = |
| 1600 | EmitLoadDexCacheStaticStorageFieldAddr(type_idx); |
| 1601 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 1602 | llvm::Value* storage_object_addr = irb_.CreateLoad(storage_field_addr, kTBAARuntimeInfo); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1603 | |
| 1604 | llvm::BasicBlock* block_original = irb_.GetInsertBlock(); |
| 1605 | |
| 1606 | // Test: Is the static storage of this class initialized? |
| 1607 | llvm::Value* equal_null = |
| 1608 | irb_.CreateICmpEQ(storage_object_addr, irb_.getJNull()); |
| 1609 | |
| 1610 | irb_.CreateCondBr(equal_null, block_load_static, block_cont, kUnlikely); |
| 1611 | |
| 1612 | // Failback routine to load the class object |
| 1613 | irb_.SetInsertPoint(block_load_static); |
| 1614 | |
| 1615 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeStaticStorage); |
| 1616 | |
| 1617 | llvm::Constant* type_idx_value = irb_.getInt32(type_idx); |
| 1618 | |
| 1619 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1620 | |
| 1621 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 1622 | |
| 1623 | EmitUpdateDexPC(dex_pc); |
| 1624 | |
| 1625 | llvm::Value* loaded_storage_object_addr = |
| 1626 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
| 1627 | |
| 1628 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1629 | |
| 1630 | llvm::BasicBlock* block_after_load_static = irb_.GetInsertBlock(); |
| 1631 | |
| 1632 | irb_.CreateBr(block_cont); |
| 1633 | |
| 1634 | // Now the class object must be loaded |
| 1635 | irb_.SetInsertPoint(block_cont); |
| 1636 | |
| 1637 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 1638 | |
| 1639 | phi->addIncoming(storage_object_addr, block_original); |
| 1640 | phi->addIncoming(loaded_storage_object_addr, block_after_load_static); |
| 1641 | |
| 1642 | return phi; |
| 1643 | } |
| 1644 | |
| 1645 | llvm::Value* GBCExpanderPass::Expand_HLSget(llvm::CallInst& call_inst, |
| 1646 | JType field_jty) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1647 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1648 | uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1649 | |
| 1650 | int field_offset; |
| 1651 | int ssb_index; |
| 1652 | bool is_referrers_class; |
| 1653 | bool is_volatile; |
| 1654 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 1655 | bool is_fast_path = driver_->ComputeStaticFieldInfo( |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 1656 | field_idx, dex_compilation_unit_, field_offset, ssb_index, |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1657 | is_referrers_class, is_volatile, false); |
| 1658 | |
| 1659 | llvm::Value* static_field_value; |
| 1660 | |
| 1661 | if (!is_fast_path) { |
| 1662 | llvm::Function* runtime_func; |
| 1663 | |
| 1664 | if (field_jty == kObject) { |
| 1665 | runtime_func = irb_.GetRuntime(runtime_support::GetObjectStatic); |
| 1666 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 1667 | runtime_func = irb_.GetRuntime(runtime_support::Get64Static); |
| 1668 | } else { |
| 1669 | runtime_func = irb_.GetRuntime(runtime_support::Get32Static); |
| 1670 | } |
| 1671 | |
| 1672 | llvm::Constant* field_idx_value = irb_.getInt32(field_idx); |
| 1673 | |
| 1674 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1675 | |
| 1676 | EmitUpdateDexPC(dex_pc); |
| 1677 | |
| 1678 | static_field_value = |
| 1679 | irb_.CreateCall2(runtime_func, field_idx_value, method_object_addr); |
| 1680 | |
| 1681 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1682 | |
Ian Rogers | 1b2b71f | 2013-03-01 11:31:30 -0800 | [diff] [blame] | 1683 | if (field_jty == kFloat || field_jty == kDouble) { |
| 1684 | static_field_value = irb_.CreateBitCast(static_field_value, irb_.getJType(field_jty)); |
| 1685 | } |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1686 | } else { |
| 1687 | DCHECK_GE(field_offset, 0); |
| 1688 | |
| 1689 | llvm::Value* static_storage_addr = NULL; |
| 1690 | |
| 1691 | if (is_referrers_class) { |
| 1692 | // Fast path, static storage base is this method's class |
| 1693 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1694 | |
| 1695 | static_storage_addr = |
| 1696 | irb_.LoadFromObjectOffset(method_object_addr, |
Ian Rogers | 98573f9 | 2013-01-30 17:26:32 -0800 | [diff] [blame] | 1697 | art::mirror::AbstractMethod::DeclaringClassOffset().Int32Value(), |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1698 | irb_.getJObjectTy(), |
| 1699 | kTBAAConstJObject); |
| 1700 | } else { |
| 1701 | // Medium path, static storage base in a different class which |
| 1702 | // requires checks that the other class is initialized |
| 1703 | DCHECK_GE(ssb_index, 0); |
| 1704 | static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index); |
| 1705 | } |
| 1706 | |
| 1707 | llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset); |
| 1708 | |
| 1709 | llvm::Value* static_field_addr = |
| 1710 | irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value, |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1711 | irb_.getJType(field_jty)->getPointerTo()); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1712 | |
| 1713 | // TODO: Check is_volatile. We need to generate atomic load instruction |
| 1714 | // when is_volatile is true. |
| 1715 | static_field_value = irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty); |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1716 | static_field_value = SignOrZeroExtendCat1Types(static_field_value, field_jty); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1719 | return static_field_value; |
| 1720 | } |
| 1721 | |
| 1722 | void GBCExpanderPass::Expand_HLSput(llvm::CallInst& call_inst, |
| 1723 | JType field_jty) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1724 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1725 | uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1726 | llvm::Value* new_value = call_inst.getArgOperand(1); |
| 1727 | |
| 1728 | if (field_jty == kFloat || field_jty == kDouble) { |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1729 | new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty)); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | int field_offset; |
| 1733 | int ssb_index; |
| 1734 | bool is_referrers_class; |
| 1735 | bool is_volatile; |
| 1736 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 1737 | bool is_fast_path = driver_->ComputeStaticFieldInfo( |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 1738 | field_idx, dex_compilation_unit_, field_offset, ssb_index, |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1739 | is_referrers_class, is_volatile, true); |
| 1740 | |
| 1741 | if (!is_fast_path) { |
| 1742 | llvm::Function* runtime_func; |
| 1743 | |
| 1744 | if (field_jty == kObject) { |
| 1745 | runtime_func = irb_.GetRuntime(runtime_support::SetObjectStatic); |
| 1746 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 1747 | runtime_func = irb_.GetRuntime(runtime_support::Set64Static); |
| 1748 | } else { |
| 1749 | runtime_func = irb_.GetRuntime(runtime_support::Set32Static); |
| 1750 | } |
| 1751 | |
Ian Rogers | 1b2b71f | 2013-03-01 11:31:30 -0800 | [diff] [blame] | 1752 | if (field_jty == kFloat) { |
| 1753 | new_value = irb_.CreateBitCast(new_value, irb_.getJType(kInt)); |
| 1754 | } else if (field_jty == kDouble) { |
| 1755 | new_value = irb_.CreateBitCast(new_value, irb_.getJType(kLong)); |
| 1756 | } |
| 1757 | |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1758 | llvm::Constant* field_idx_value = irb_.getInt32(field_idx); |
| 1759 | |
| 1760 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1761 | |
| 1762 | EmitUpdateDexPC(dex_pc); |
| 1763 | |
| 1764 | irb_.CreateCall3(runtime_func, field_idx_value, |
| 1765 | method_object_addr, new_value); |
| 1766 | |
| 1767 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1768 | |
| 1769 | } else { |
| 1770 | DCHECK_GE(field_offset, 0); |
| 1771 | |
| 1772 | llvm::Value* static_storage_addr = NULL; |
| 1773 | |
| 1774 | if (is_referrers_class) { |
| 1775 | // Fast path, static storage base is this method's class |
| 1776 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1777 | |
| 1778 | static_storage_addr = |
| 1779 | irb_.LoadFromObjectOffset(method_object_addr, |
Ian Rogers | 98573f9 | 2013-01-30 17:26:32 -0800 | [diff] [blame] | 1780 | art::mirror::AbstractMethod::DeclaringClassOffset().Int32Value(), |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1781 | irb_.getJObjectTy(), |
| 1782 | kTBAAConstJObject); |
| 1783 | } else { |
| 1784 | // Medium path, static storage base in a different class which |
| 1785 | // requires checks that the other class is initialized |
| 1786 | DCHECK_GE(ssb_index, 0); |
| 1787 | static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index); |
| 1788 | } |
| 1789 | |
| 1790 | llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset); |
| 1791 | |
| 1792 | llvm::Value* static_field_addr = |
| 1793 | irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value, |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1794 | irb_.getJType(field_jty)->getPointerTo()); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1795 | |
| 1796 | // TODO: Check is_volatile. We need to generate atomic store instruction |
| 1797 | // when is_volatile is true. |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 1798 | new_value = TruncateCat1Types(new_value, field_jty); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1799 | irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty); |
| 1800 | |
| 1801 | if (field_jty == kObject) { // If put an object, mark the GC card table. |
| 1802 | EmitMarkGCCard(new_value, static_storage_addr); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | return; |
| 1807 | } |
| 1808 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1809 | llvm::Value* GBCExpanderPass::Expand_ConstString(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1810 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1811 | uint32_t string_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1812 | |
| 1813 | llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx); |
| 1814 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 1815 | llvm::Value* string_addr = irb_.CreateLoad(string_field_addr, kTBAARuntimeInfo); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1816 | |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 1817 | if (!driver_->CanAssumeStringIsPresentInDexCache(*dex_compilation_unit_->GetDexFile(), |
| 1818 | string_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1819 | llvm::BasicBlock* block_str_exist = |
| 1820 | CreateBasicBlockWithDexPC(dex_pc, "str_exist"); |
| 1821 | |
| 1822 | llvm::BasicBlock* block_str_resolve = |
| 1823 | CreateBasicBlockWithDexPC(dex_pc, "str_resolve"); |
| 1824 | |
| 1825 | llvm::BasicBlock* block_cont = |
| 1826 | CreateBasicBlockWithDexPC(dex_pc, "str_cont"); |
| 1827 | |
| 1828 | // Test: Is the string resolved and in the dex cache? |
| 1829 | llvm::Value* equal_null = irb_.CreateICmpEQ(string_addr, irb_.getJNull()); |
| 1830 | |
| 1831 | irb_.CreateCondBr(equal_null, block_str_resolve, block_str_exist, kUnlikely); |
| 1832 | |
| 1833 | // String is resolved, go to next basic block. |
| 1834 | irb_.SetInsertPoint(block_str_exist); |
| 1835 | irb_.CreateBr(block_cont); |
| 1836 | |
| 1837 | // String is not resolved yet, resolve it now. |
| 1838 | irb_.SetInsertPoint(block_str_resolve); |
| 1839 | |
| 1840 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::ResolveString); |
| 1841 | |
| 1842 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1843 | |
| 1844 | llvm::Value* string_idx_value = irb_.getInt32(string_idx); |
| 1845 | |
| 1846 | EmitUpdateDexPC(dex_pc); |
| 1847 | |
| 1848 | llvm::Value* result = irb_.CreateCall2(runtime_func, method_object_addr, |
| 1849 | string_idx_value); |
| 1850 | |
| 1851 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1852 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1853 | irb_.CreateBr(block_cont); |
| 1854 | |
| 1855 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1856 | llvm::BasicBlock* block_pre_cont = irb_.GetInsertBlock(); |
| 1857 | |
| 1858 | irb_.SetInsertPoint(block_cont); |
| 1859 | |
| 1860 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 1861 | |
| 1862 | phi->addIncoming(string_addr, block_str_exist); |
| 1863 | phi->addIncoming(result, block_pre_cont); |
| 1864 | |
| 1865 | string_addr = phi; |
| 1866 | } |
| 1867 | |
| 1868 | return string_addr; |
| 1869 | } |
| 1870 | |
| 1871 | llvm::Value* GBCExpanderPass::Expand_ConstClass(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1872 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1873 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1874 | |
| 1875 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx); |
| 1876 | |
| 1877 | return type_object_addr; |
| 1878 | } |
| 1879 | |
| 1880 | void GBCExpanderPass::Expand_MonitorEnter(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1881 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1882 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1883 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1884 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 1885 | EmitGuard_NullPointerException(dex_pc, object_addr, opt_flags); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1886 | |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 1887 | EmitUpdateDexPC(dex_pc); |
| 1888 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1889 | irb_.Runtime().EmitLockObject(object_addr); |
| 1890 | |
| 1891 | return; |
| 1892 | } |
| 1893 | |
| 1894 | void GBCExpanderPass::Expand_MonitorExit(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1895 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1896 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1897 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1898 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 1899 | EmitGuard_NullPointerException(dex_pc, object_addr, opt_flags); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1900 | |
| 1901 | EmitUpdateDexPC(dex_pc); |
| 1902 | |
| 1903 | irb_.Runtime().EmitUnlockObject(object_addr); |
| 1904 | |
| 1905 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1906 | |
| 1907 | return; |
| 1908 | } |
| 1909 | |
| 1910 | void GBCExpanderPass::Expand_HLCheckCast(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 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1913 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
| 1914 | |
| 1915 | llvm::BasicBlock* block_test_class = |
| 1916 | CreateBasicBlockWithDexPC(dex_pc, "test_class"); |
| 1917 | |
| 1918 | llvm::BasicBlock* block_test_sub_class = |
| 1919 | CreateBasicBlockWithDexPC(dex_pc, "test_sub_class"); |
| 1920 | |
| 1921 | llvm::BasicBlock* block_cont = |
| 1922 | CreateBasicBlockWithDexPC(dex_pc, "checkcast_cont"); |
| 1923 | |
| 1924 | // Test: Is the reference equal to null? Act as no-op when it is null. |
| 1925 | llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull()); |
| 1926 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 1927 | irb_.CreateCondBr(equal_null, block_cont, block_test_class, kUnlikely); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1928 | |
| 1929 | // Test: Is the object instantiated from the given class? |
| 1930 | irb_.SetInsertPoint(block_test_class); |
| 1931 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx); |
Ian Rogers | 98573f9 | 2013-01-30 17:26:32 -0800 | [diff] [blame] | 1932 | DCHECK_EQ(art::mirror::Object::ClassOffset().Int32Value(), 0); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1933 | |
| 1934 | llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy(); |
| 1935 | |
| 1936 | llvm::Value* object_type_field_addr = |
| 1937 | irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo()); |
| 1938 | |
| 1939 | llvm::Value* object_type_object_addr = |
| 1940 | irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject); |
| 1941 | |
| 1942 | llvm::Value* equal_class = |
| 1943 | irb_.CreateICmpEQ(type_object_addr, object_type_object_addr); |
| 1944 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 1945 | irb_.CreateCondBr(equal_class, block_cont, block_test_sub_class, kLikely); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1946 | |
| 1947 | // Test: Is the object instantiated from the subclass of the given class? |
| 1948 | irb_.SetInsertPoint(block_test_sub_class); |
| 1949 | |
| 1950 | EmitUpdateDexPC(dex_pc); |
| 1951 | |
| 1952 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::CheckCast), |
| 1953 | type_object_addr, object_type_object_addr); |
| 1954 | |
| 1955 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1956 | |
| 1957 | irb_.CreateBr(block_cont); |
| 1958 | |
| 1959 | irb_.SetInsertPoint(block_cont); |
| 1960 | |
| 1961 | return; |
| 1962 | } |
| 1963 | |
| 1964 | llvm::Value* GBCExpanderPass::Expand_InstanceOf(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1965 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1966 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1967 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
| 1968 | |
| 1969 | llvm::BasicBlock* block_nullp = |
| 1970 | CreateBasicBlockWithDexPC(dex_pc, "nullp"); |
| 1971 | |
| 1972 | llvm::BasicBlock* block_test_class = |
| 1973 | CreateBasicBlockWithDexPC(dex_pc, "test_class"); |
| 1974 | |
| 1975 | llvm::BasicBlock* block_class_equals = |
| 1976 | CreateBasicBlockWithDexPC(dex_pc, "class_eq"); |
| 1977 | |
| 1978 | llvm::BasicBlock* block_test_sub_class = |
| 1979 | CreateBasicBlockWithDexPC(dex_pc, "test_sub_class"); |
| 1980 | |
| 1981 | llvm::BasicBlock* block_cont = |
| 1982 | CreateBasicBlockWithDexPC(dex_pc, "instance_of_cont"); |
| 1983 | |
| 1984 | // Overview of the following code : |
| 1985 | // We check for null, if so, then false, otherwise check for class == . If so |
| 1986 | // then true, otherwise do callout slowpath. |
| 1987 | // |
| 1988 | // Test: Is the reference equal to null? Set 0 when it is null. |
| 1989 | llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull()); |
| 1990 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 1991 | irb_.CreateCondBr(equal_null, block_nullp, block_test_class, kUnlikely); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1992 | |
| 1993 | irb_.SetInsertPoint(block_nullp); |
| 1994 | irb_.CreateBr(block_cont); |
| 1995 | |
| 1996 | // Test: Is the object instantiated from the given class? |
| 1997 | irb_.SetInsertPoint(block_test_class); |
| 1998 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx); |
Ian Rogers | 98573f9 | 2013-01-30 17:26:32 -0800 | [diff] [blame] | 1999 | DCHECK_EQ(art::mirror::Object::ClassOffset().Int32Value(), 0); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2000 | |
| 2001 | llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy(); |
| 2002 | |
| 2003 | llvm::Value* object_type_field_addr = |
| 2004 | irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo()); |
| 2005 | |
| 2006 | llvm::Value* object_type_object_addr = |
| 2007 | irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject); |
| 2008 | |
| 2009 | llvm::Value* equal_class = |
| 2010 | irb_.CreateICmpEQ(type_object_addr, object_type_object_addr); |
| 2011 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2012 | irb_.CreateCondBr(equal_class, block_class_equals, block_test_sub_class, kLikely); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2013 | |
| 2014 | irb_.SetInsertPoint(block_class_equals); |
| 2015 | irb_.CreateBr(block_cont); |
| 2016 | |
| 2017 | // Test: Is the object instantiated from the subclass of the given class? |
| 2018 | irb_.SetInsertPoint(block_test_sub_class); |
| 2019 | llvm::Value* result = |
| 2020 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::IsAssignable), |
| 2021 | type_object_addr, object_type_object_addr); |
| 2022 | irb_.CreateBr(block_cont); |
| 2023 | |
| 2024 | irb_.SetInsertPoint(block_cont); |
| 2025 | |
| 2026 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJIntTy(), 3); |
| 2027 | |
| 2028 | phi->addIncoming(irb_.getJInt(0), block_nullp); |
| 2029 | phi->addIncoming(irb_.getJInt(1), block_class_equals); |
| 2030 | phi->addIncoming(result, block_test_sub_class); |
| 2031 | |
| 2032 | return phi; |
| 2033 | } |
| 2034 | |
| 2035 | llvm::Value* GBCExpanderPass::Expand_NewInstance(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2036 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2037 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 2038 | |
| 2039 | llvm::Function* runtime_func; |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2040 | if (driver_->CanAccessInstantiableTypeWithoutChecks(dex_compilation_unit_->GetDexMethodIndex(), |
| 2041 | *dex_compilation_unit_->GetDexFile(), |
| 2042 | type_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2043 | runtime_func = irb_.GetRuntime(runtime_support::AllocObject); |
| 2044 | } else { |
| 2045 | runtime_func = irb_.GetRuntime(runtime_support::AllocObjectWithAccessCheck); |
| 2046 | } |
| 2047 | |
| 2048 | llvm::Constant* type_index_value = irb_.getInt32(type_idx); |
| 2049 | |
| 2050 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2051 | |
| 2052 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 2053 | |
| 2054 | EmitUpdateDexPC(dex_pc); |
| 2055 | |
| 2056 | llvm::Value* object_addr = |
| 2057 | irb_.CreateCall3(runtime_func, type_index_value, method_object_addr, thread_object_addr); |
| 2058 | |
| 2059 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2060 | |
| 2061 | return object_addr; |
| 2062 | } |
| 2063 | |
| 2064 | llvm::Value* GBCExpanderPass::Expand_HLInvoke(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2065 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2066 | art::InvokeType invoke_type = static_cast<art::InvokeType>(LV2UInt(call_inst.getArgOperand(0))); |
| 2067 | bool is_static = (invoke_type == art::kStatic); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2068 | uint32_t callee_method_idx = LV2UInt(call_inst.getArgOperand(1)); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2069 | int opt_flags = LV2UInt(call_inst.getArgOperand(2)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2070 | |
| 2071 | // Compute invoke related information for compiler decision |
| 2072 | int vtable_idx = -1; |
| 2073 | uintptr_t direct_code = 0; |
| 2074 | uintptr_t direct_method = 0; |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 2075 | bool is_fast_path = driver_-> |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2076 | ComputeInvokeInfo(callee_method_idx, dex_compilation_unit_, |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2077 | invoke_type, vtable_idx, direct_code, direct_method); |
| 2078 | |
| 2079 | // Load *this* actual parameter |
| 2080 | llvm::Value* this_addr = NULL; |
| 2081 | |
| 2082 | if (!is_static) { |
| 2083 | // Test: Is *this* parameter equal to null? |
| 2084 | this_addr = call_inst.getArgOperand(3); |
| 2085 | } |
| 2086 | |
| 2087 | // Load the method object |
| 2088 | llvm::Value* callee_method_object_addr = NULL; |
| 2089 | |
| 2090 | if (!is_fast_path) { |
| 2091 | callee_method_object_addr = |
| 2092 | EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, invoke_type, |
| 2093 | this_addr, dex_pc, is_fast_path); |
| 2094 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2095 | if (!is_static) { |
| 2096 | EmitGuard_NullPointerException(dex_pc, this_addr, opt_flags); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2097 | } |
| 2098 | } else { |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2099 | if (!is_static) { |
| 2100 | EmitGuard_NullPointerException(dex_pc, this_addr, opt_flags); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | switch (invoke_type) { |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2104 | case art::kStatic: |
| 2105 | case art::kDirect: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2106 | if (direct_method != 0u && |
| 2107 | direct_method != static_cast<uintptr_t>(-1)) { |
| 2108 | callee_method_object_addr = |
| 2109 | irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_method), |
| 2110 | irb_.getJObjectTy()); |
| 2111 | } else { |
| 2112 | callee_method_object_addr = |
| 2113 | EmitLoadSDCalleeMethodObjectAddr(callee_method_idx); |
| 2114 | } |
| 2115 | break; |
| 2116 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2117 | case art::kVirtual: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2118 | DCHECK(vtable_idx != -1); |
| 2119 | callee_method_object_addr = |
| 2120 | EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr); |
| 2121 | break; |
| 2122 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2123 | case art::kSuper: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2124 | LOG(FATAL) << "invoke-super should be promoted to invoke-direct in " |
| 2125 | "the fast path."; |
| 2126 | break; |
| 2127 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2128 | case art::kInterface: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2129 | callee_method_object_addr = |
| 2130 | EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, |
| 2131 | invoke_type, this_addr, |
| 2132 | dex_pc, is_fast_path); |
| 2133 | break; |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | // Load the actual parameter |
| 2138 | std::vector<llvm::Value*> args; |
| 2139 | |
| 2140 | args.push_back(callee_method_object_addr); // method object for callee |
| 2141 | |
| 2142 | for (uint32_t i = 3; i < call_inst.getNumArgOperands(); ++i) { |
| 2143 | args.push_back(call_inst.getArgOperand(i)); |
| 2144 | } |
| 2145 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2146 | // Generate the load of the Method*. We base the return type on that of the call as method's |
| 2147 | // returning a value are void calls if the return value is unused. |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2148 | llvm::Value* code_addr; |
| 2149 | if (direct_code != 0u && |
| 2150 | direct_code != static_cast<uintptr_t>(-1)) { |
| 2151 | code_addr = |
| 2152 | irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_code), |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2153 | GetFunctionType(call_inst.getType(), callee_method_idx, is_static)->getPointerTo()); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2154 | } else { |
| 2155 | code_addr = |
| 2156 | irb_.LoadFromObjectOffset(callee_method_object_addr, |
Ian Rogers | 98573f9 | 2013-01-30 17:26:32 -0800 | [diff] [blame] | 2157 | art::mirror::AbstractMethod::GetCodeOffset().Int32Value(), |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2158 | GetFunctionType(call_inst.getType(), callee_method_idx, is_static)->getPointerTo(), |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 2159 | kTBAARuntimeInfo); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | // Invoke callee |
| 2163 | EmitUpdateDexPC(dex_pc); |
| 2164 | llvm::Value* retval = irb_.CreateCall(code_addr, args); |
| 2165 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2166 | |
| 2167 | return retval; |
| 2168 | } |
| 2169 | |
| 2170 | llvm::Value* GBCExpanderPass::Expand_OptArrayLength(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2171 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2172 | // Get the array object address |
| 2173 | llvm::Value* array_addr = call_inst.getArgOperand(1); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2174 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2175 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2176 | EmitGuard_NullPointerException(dex_pc, array_addr, opt_flags); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2177 | |
| 2178 | // Get the array length and store it to the register |
| 2179 | return EmitLoadArrayLength(array_addr); |
| 2180 | } |
| 2181 | |
| 2182 | llvm::Value* GBCExpanderPass::Expand_NewArray(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2183 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2184 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 2185 | llvm::Value* length = call_inst.getArgOperand(1); |
| 2186 | |
| 2187 | return EmitAllocNewArray(dex_pc, length, type_idx, false); |
| 2188 | } |
| 2189 | |
| 2190 | llvm::Value* GBCExpanderPass::Expand_HLFilledNewArray(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2191 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2192 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(1)); |
| 2193 | uint32_t length = call_inst.getNumArgOperands() - 3; |
| 2194 | |
| 2195 | llvm::Value* object_addr = |
| 2196 | EmitAllocNewArray(dex_pc, irb_.getInt32(length), type_idx, true); |
| 2197 | |
| 2198 | if (length > 0) { |
| 2199 | // Check for the element type |
| 2200 | uint32_t type_desc_len = 0; |
| 2201 | const char* type_desc = |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2202 | dex_compilation_unit_->GetDexFile()->StringByTypeIdx(type_idx, &type_desc_len); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2203 | |
| 2204 | DCHECK_GE(type_desc_len, 2u); // should be guaranteed by verifier |
| 2205 | DCHECK_EQ(type_desc[0], '['); // should be guaranteed by verifier |
| 2206 | bool is_elem_int_ty = (type_desc[1] == 'I'); |
| 2207 | |
| 2208 | uint32_t alignment; |
| 2209 | llvm::Constant* elem_size; |
| 2210 | llvm::PointerType* field_type; |
| 2211 | |
| 2212 | // NOTE: Currently filled-new-array only supports 'L', '[', and 'I' |
| 2213 | // as the element, thus we are only checking 2 cases: primitive int and |
| 2214 | // non-primitive type. |
| 2215 | if (is_elem_int_ty) { |
| 2216 | alignment = sizeof(int32_t); |
| 2217 | elem_size = irb_.getPtrEquivInt(sizeof(int32_t)); |
| 2218 | field_type = irb_.getJIntTy()->getPointerTo(); |
| 2219 | } else { |
| 2220 | alignment = irb_.getSizeOfPtrEquivInt(); |
| 2221 | elem_size = irb_.getSizeOfPtrEquivIntValue(); |
| 2222 | field_type = irb_.getJObjectTy()->getPointerTo(); |
| 2223 | } |
| 2224 | |
| 2225 | llvm::Value* data_field_offset = |
Ian Rogers | 98573f9 | 2013-01-30 17:26:32 -0800 | [diff] [blame] | 2226 | irb_.getPtrEquivInt(art::mirror::Array::DataOffset(alignment).Int32Value()); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2227 | |
| 2228 | llvm::Value* data_field_addr = |
| 2229 | irb_.CreatePtrDisp(object_addr, data_field_offset, field_type); |
| 2230 | |
| 2231 | // TODO: Tune this code. Currently we are generating one instruction for |
| 2232 | // one element which may be very space consuming. Maybe changing to use |
| 2233 | // memcpy may help; however, since we can't guarantee that the alloca of |
| 2234 | // dalvik register are continuous, we can't perform such optimization yet. |
| 2235 | for (uint32_t i = 0; i < length; ++i) { |
| 2236 | llvm::Value* reg_value = call_inst.getArgOperand(i+3); |
| 2237 | |
| 2238 | irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray); |
| 2239 | |
| 2240 | data_field_addr = |
| 2241 | irb_.CreatePtrDisp(data_field_addr, elem_size, field_type); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | return object_addr; |
| 2246 | } |
| 2247 | |
| 2248 | void GBCExpanderPass::Expand_HLFillArrayData(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2249 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2250 | int32_t payload_offset = static_cast<int32_t>(dex_pc) + |
| 2251 | LV2SInt(call_inst.getArgOperand(0)); |
| 2252 | llvm::Value* array_addr = call_inst.getArgOperand(1); |
| 2253 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2254 | const art::Instruction::ArrayDataPayload* payload = |
| 2255 | reinterpret_cast<const art::Instruction::ArrayDataPayload*>( |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2256 | dex_compilation_unit_->GetCodeItem()->insns_ + payload_offset); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2257 | |
| 2258 | if (payload->element_count == 0) { |
| 2259 | // When the number of the elements in the payload is zero, we don't have |
| 2260 | // to copy any numbers. However, we should check whether the array object |
| 2261 | // address is equal to null or not. |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2262 | EmitGuard_NullPointerException(dex_pc, array_addr, 0); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2263 | } else { |
| 2264 | // To save the code size, we are going to call the runtime function to |
| 2265 | // copy the content from DexFile. |
| 2266 | |
| 2267 | // NOTE: We will check for the NullPointerException in the runtime. |
| 2268 | |
| 2269 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::FillArrayData); |
| 2270 | |
| 2271 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2272 | |
| 2273 | EmitUpdateDexPC(dex_pc); |
| 2274 | |
| 2275 | irb_.CreateCall4(runtime_func, |
| 2276 | method_object_addr, irb_.getInt32(dex_pc), |
| 2277 | array_addr, irb_.getInt32(payload_offset)); |
| 2278 | |
| 2279 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2280 | } |
| 2281 | |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | llvm::Value* GBCExpanderPass::EmitAllocNewArray(uint32_t dex_pc, |
| 2286 | llvm::Value* array_length_value, |
| 2287 | uint32_t type_idx, |
| 2288 | bool is_filled_new_array) { |
| 2289 | llvm::Function* runtime_func; |
| 2290 | |
| 2291 | bool skip_access_check = |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2292 | driver_->CanAccessTypeWithoutChecks(dex_compilation_unit_->GetDexMethodIndex(), |
| 2293 | *dex_compilation_unit_->GetDexFile(), type_idx); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2294 | |
| 2295 | |
| 2296 | if (is_filled_new_array) { |
| 2297 | runtime_func = skip_access_check ? |
| 2298 | irb_.GetRuntime(runtime_support::CheckAndAllocArray) : |
| 2299 | irb_.GetRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck); |
| 2300 | } else { |
| 2301 | runtime_func = skip_access_check ? |
| 2302 | irb_.GetRuntime(runtime_support::AllocArray) : |
| 2303 | irb_.GetRuntime(runtime_support::AllocArrayWithAccessCheck); |
| 2304 | } |
| 2305 | |
| 2306 | llvm::Constant* type_index_value = irb_.getInt32(type_idx); |
| 2307 | |
| 2308 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2309 | |
| 2310 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 2311 | |
| 2312 | EmitUpdateDexPC(dex_pc); |
| 2313 | |
| 2314 | llvm::Value* object_addr = |
| 2315 | irb_.CreateCall4(runtime_func, type_index_value, method_object_addr, |
| 2316 | array_length_value, thread_object_addr); |
| 2317 | |
| 2318 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2319 | |
| 2320 | return object_addr; |
| 2321 | } |
| 2322 | |
| 2323 | llvm::Value* GBCExpanderPass:: |
| 2324 | EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx, |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2325 | art::InvokeType invoke_type, |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2326 | llvm::Value* this_addr, |
| 2327 | uint32_t dex_pc, |
| 2328 | bool is_fast_path) { |
| 2329 | |
| 2330 | llvm::Function* runtime_func = NULL; |
| 2331 | |
| 2332 | switch (invoke_type) { |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2333 | case art::kStatic: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2334 | runtime_func = irb_.GetRuntime(runtime_support::FindStaticMethodWithAccessCheck); |
| 2335 | break; |
| 2336 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2337 | case art::kDirect: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2338 | runtime_func = irb_.GetRuntime(runtime_support::FindDirectMethodWithAccessCheck); |
| 2339 | break; |
| 2340 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2341 | case art::kVirtual: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2342 | runtime_func = irb_.GetRuntime(runtime_support::FindVirtualMethodWithAccessCheck); |
| 2343 | break; |
| 2344 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2345 | case art::kSuper: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2346 | runtime_func = irb_.GetRuntime(runtime_support::FindSuperMethodWithAccessCheck); |
| 2347 | break; |
| 2348 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2349 | case art::kInterface: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2350 | if (is_fast_path) { |
| 2351 | runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethod); |
| 2352 | } else { |
| 2353 | runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethodWithAccessCheck); |
| 2354 | } |
| 2355 | break; |
| 2356 | } |
| 2357 | |
| 2358 | llvm::Value* callee_method_idx_value = irb_.getInt32(callee_method_idx); |
| 2359 | |
| 2360 | if (this_addr == NULL) { |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2361 | DCHECK_EQ(invoke_type, art::kStatic); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2362 | this_addr = irb_.getJNull(); |
| 2363 | } |
| 2364 | |
| 2365 | llvm::Value* caller_method_object_addr = EmitLoadMethodObjectAddr(); |
| 2366 | |
| 2367 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 2368 | |
| 2369 | EmitUpdateDexPC(dex_pc); |
| 2370 | |
| 2371 | llvm::Value* callee_method_object_addr = |
| 2372 | irb_.CreateCall4(runtime_func, |
| 2373 | callee_method_idx_value, |
| 2374 | this_addr, |
| 2375 | caller_method_object_addr, |
| 2376 | thread_object_addr); |
| 2377 | |
| 2378 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2379 | |
| 2380 | return callee_method_object_addr; |
| 2381 | } |
| 2382 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2383 | void GBCExpanderPass::EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr) { |
| 2384 | // Using runtime support, let the target can override by InlineAssembly. |
| 2385 | irb_.Runtime().EmitMarkGCCard(value, target_addr); |
| 2386 | } |
| 2387 | |
| 2388 | void GBCExpanderPass::EmitUpdateDexPC(uint32_t dex_pc) { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2389 | if (shadow_frame_ == NULL) { |
| 2390 | return; |
| 2391 | } |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2392 | irb_.StoreToObjectOffset(shadow_frame_, |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2393 | art::ShadowFrame::DexPCOffset(), |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2394 | irb_.getInt32(dex_pc), |
| 2395 | kTBAAShadowFrame); |
| 2396 | } |
| 2397 | |
| 2398 | void GBCExpanderPass::EmitGuard_DivZeroException(uint32_t dex_pc, |
| 2399 | llvm::Value* denominator, |
| 2400 | JType op_jty) { |
| 2401 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 2402 | |
| 2403 | llvm::Constant* zero = irb_.getJZero(op_jty); |
| 2404 | |
| 2405 | llvm::Value* equal_zero = irb_.CreateICmpEQ(denominator, zero); |
| 2406 | |
| 2407 | llvm::BasicBlock* block_exception = CreateBasicBlockWithDexPC(dex_pc, "div0"); |
| 2408 | |
| 2409 | llvm::BasicBlock* block_continue = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2410 | |
| 2411 | irb_.CreateCondBr(equal_zero, block_exception, block_continue, kUnlikely); |
| 2412 | |
| 2413 | irb_.SetInsertPoint(block_exception); |
| 2414 | EmitUpdateDexPC(dex_pc); |
| 2415 | irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowDivZeroException)); |
| 2416 | EmitBranchExceptionLandingPad(dex_pc); |
| 2417 | |
| 2418 | irb_.SetInsertPoint(block_continue); |
| 2419 | } |
| 2420 | |
| 2421 | void GBCExpanderPass::EmitGuard_NullPointerException(uint32_t dex_pc, |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2422 | llvm::Value* object, |
| 2423 | int opt_flags) { |
| 2424 | bool ignore_null_check = ((opt_flags & MIR_IGNORE_NULL_CHECK) != 0); |
| 2425 | if (ignore_null_check) { |
| 2426 | llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc); |
| 2427 | if (lpad) { |
| 2428 | // There is at least one catch: create a "fake" conditional branch to |
| 2429 | // keep the exception edge to the catch block. |
| 2430 | landing_pad_phi_mapping_[lpad].push_back( |
| 2431 | std::make_pair(current_bb_->getUniquePredecessor(), |
| 2432 | irb_.GetInsertBlock())); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2433 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2434 | llvm::BasicBlock* block_continue = |
| 2435 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2436 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2437 | irb_.CreateCondBr(irb_.getFalse(), lpad, block_continue, kUnlikely); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2438 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2439 | irb_.SetInsertPoint(block_continue); |
| 2440 | } |
| 2441 | } else { |
| 2442 | llvm::Value* equal_null = irb_.CreateICmpEQ(object, irb_.getJNull()); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2443 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2444 | llvm::BasicBlock* block_exception = |
| 2445 | CreateBasicBlockWithDexPC(dex_pc, "nullp"); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2446 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2447 | llvm::BasicBlock* block_continue = |
| 2448 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2449 | |
| 2450 | irb_.CreateCondBr(equal_null, block_exception, block_continue, kUnlikely); |
| 2451 | |
| 2452 | irb_.SetInsertPoint(block_exception); |
| 2453 | EmitUpdateDexPC(dex_pc); |
| 2454 | irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowNullPointerException), |
| 2455 | irb_.getInt32(dex_pc)); |
| 2456 | EmitBranchExceptionLandingPad(dex_pc); |
| 2457 | |
| 2458 | irb_.SetInsertPoint(block_continue); |
| 2459 | } |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | void |
| 2463 | GBCExpanderPass::EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc, |
| 2464 | llvm::Value* array, |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2465 | llvm::Value* index, |
| 2466 | int opt_flags) { |
| 2467 | bool ignore_range_check = ((opt_flags & MIR_IGNORE_RANGE_CHECK) != 0); |
| 2468 | if (ignore_range_check) { |
| 2469 | llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc); |
| 2470 | if (lpad) { |
| 2471 | // There is at least one catch: create a "fake" conditional branch to |
| 2472 | // keep the exception edge to the catch block. |
| 2473 | landing_pad_phi_mapping_[lpad].push_back( |
| 2474 | std::make_pair(current_bb_->getUniquePredecessor(), |
| 2475 | irb_.GetInsertBlock())); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2476 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2477 | llvm::BasicBlock* block_continue = |
| 2478 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2479 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2480 | irb_.CreateCondBr(irb_.getFalse(), lpad, block_continue, kUnlikely); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2481 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2482 | irb_.SetInsertPoint(block_continue); |
| 2483 | } |
| 2484 | } else { |
| 2485 | llvm::Value* array_len = EmitLoadArrayLength(array); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2486 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2487 | llvm::Value* cmp = irb_.CreateICmpUGE(index, array_len); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2488 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2489 | llvm::BasicBlock* block_exception = |
| 2490 | CreateBasicBlockWithDexPC(dex_pc, "overflow"); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2491 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2492 | llvm::BasicBlock* block_continue = |
| 2493 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2494 | |
Sebastien Hertz | 2ffe4f1 | 2013-03-01 12:12:30 +0100 | [diff] [blame] | 2495 | irb_.CreateCondBr(cmp, block_exception, block_continue, kUnlikely); |
| 2496 | |
| 2497 | irb_.SetInsertPoint(block_exception); |
| 2498 | |
| 2499 | EmitUpdateDexPC(dex_pc); |
| 2500 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::ThrowIndexOutOfBounds), index, array_len); |
| 2501 | EmitBranchExceptionLandingPad(dex_pc); |
| 2502 | |
| 2503 | irb_.SetInsertPoint(block_continue); |
| 2504 | } |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2507 | llvm::FunctionType* GBCExpanderPass::GetFunctionType(llvm::Type* ret_type, uint32_t method_idx, |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2508 | bool is_static) { |
| 2509 | // Get method signature |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2510 | art::DexFile::MethodId const& method_id = |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2511 | dex_compilation_unit_->GetDexFile()->GetMethodId(method_idx); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2512 | |
| 2513 | uint32_t shorty_size; |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2514 | const char* shorty = dex_compilation_unit_->GetDexFile()->GetMethodShorty(method_id, &shorty_size); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2515 | CHECK_GE(shorty_size, 1u); |
| 2516 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2517 | // Get argument type |
| 2518 | std::vector<llvm::Type*> args_type; |
| 2519 | |
| 2520 | args_type.push_back(irb_.getJObjectTy()); // method object pointer |
| 2521 | |
| 2522 | if (!is_static) { |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 2523 | args_type.push_back(irb_.getJType('L')); // "this" object pointer |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | for (uint32_t i = 1; i < shorty_size; ++i) { |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 2527 | char shorty_type = art::RemapShorty(shorty[i]); |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 2528 | args_type.push_back(irb_.getJType(shorty_type)); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | return llvm::FunctionType::get(ret_type, args_type, false); |
| 2532 | } |
| 2533 | |
| 2534 | |
| 2535 | llvm::BasicBlock* GBCExpanderPass:: |
| 2536 | CreateBasicBlockWithDexPC(uint32_t dex_pc, const char* postfix) { |
| 2537 | std::string name; |
| 2538 | |
| 2539 | #if !defined(NDEBUG) |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2540 | art::StringAppendF(&name, "B%04x.%s", dex_pc, postfix); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2541 | #endif |
| 2542 | |
| 2543 | return llvm::BasicBlock::Create(context_, name, func_); |
| 2544 | } |
| 2545 | |
| 2546 | llvm::BasicBlock* GBCExpanderPass::GetBasicBlock(uint32_t dex_pc) { |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2547 | 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] | 2548 | CHECK(basic_blocks_[dex_pc] != NULL); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2549 | return basic_blocks_[dex_pc]; |
| 2550 | } |
| 2551 | |
| 2552 | int32_t GBCExpanderPass::GetTryItemOffset(uint32_t dex_pc) { |
| 2553 | int32_t min = 0; |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2554 | int32_t max = dex_compilation_unit_->GetCodeItem()->tries_size_ - 1; |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2555 | |
| 2556 | while (min <= max) { |
| 2557 | int32_t mid = min + (max - min) / 2; |
| 2558 | |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2559 | const art::DexFile::TryItem* ti = |
| 2560 | art::DexFile::GetTryItems(*dex_compilation_unit_->GetCodeItem(), mid); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2561 | uint32_t start = ti->start_addr_; |
| 2562 | uint32_t end = start + ti->insn_count_; |
| 2563 | |
| 2564 | if (dex_pc < start) { |
| 2565 | max = mid - 1; |
| 2566 | } else if (dex_pc >= end) { |
| 2567 | min = mid + 1; |
| 2568 | } else { |
| 2569 | return mid; // found |
| 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | return -1; // not found |
| 2574 | } |
| 2575 | |
| 2576 | llvm::BasicBlock* GBCExpanderPass::GetLandingPadBasicBlock(uint32_t dex_pc) { |
| 2577 | // Find the try item for this address in this method |
| 2578 | int32_t ti_offset = GetTryItemOffset(dex_pc); |
| 2579 | |
| 2580 | if (ti_offset == -1) { |
| 2581 | return NULL; // No landing pad is available for this address. |
| 2582 | } |
| 2583 | |
| 2584 | // Check for the existing landing pad basic block |
| 2585 | DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset)); |
| 2586 | llvm::BasicBlock* block_lpad = basic_block_landing_pads_[ti_offset]; |
| 2587 | |
| 2588 | if (block_lpad) { |
| 2589 | // We have generated landing pad for this try item already. Return the |
| 2590 | // same basic block. |
| 2591 | return block_lpad; |
| 2592 | } |
| 2593 | |
| 2594 | // Get try item from code item |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2595 | const art::DexFile::TryItem* ti = art::DexFile::GetTryItems(*dex_compilation_unit_->GetCodeItem(), |
Ian Rogers | 8e69605 | 2013-03-04 09:00:40 -0800 | [diff] [blame] | 2596 | ti_offset); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2597 | |
| 2598 | std::string lpadname; |
| 2599 | |
| 2600 | #if !defined(NDEBUG) |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2601 | 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] | 2602 | #endif |
| 2603 | |
| 2604 | // Create landing pad basic block |
| 2605 | block_lpad = llvm::BasicBlock::Create(context_, lpadname, func_); |
| 2606 | |
| 2607 | // Change IRBuilder insert point |
| 2608 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
| 2609 | irb_.SetInsertPoint(block_lpad); |
| 2610 | |
| 2611 | // Find catch block with matching type |
| 2612 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2613 | |
| 2614 | llvm::Value* ti_offset_value = irb_.getInt32(ti_offset); |
| 2615 | |
| 2616 | llvm::Value* catch_handler_index_value = |
| 2617 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::FindCatchBlock), |
| 2618 | method_object_addr, ti_offset_value); |
| 2619 | |
| 2620 | // Switch instruction (Go to unwind basic block by default) |
| 2621 | llvm::SwitchInst* sw = |
| 2622 | irb_.CreateSwitch(catch_handler_index_value, GetUnwindBasicBlock()); |
| 2623 | |
| 2624 | // Cases with matched catch block |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 2625 | art::CatchHandlerIterator iter(*dex_compilation_unit_->GetCodeItem(), ti->start_addr_); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2626 | |
| 2627 | for (uint32_t c = 0; iter.HasNext(); iter.Next(), ++c) { |
| 2628 | sw->addCase(irb_.getInt32(c), GetBasicBlock(iter.GetHandlerAddress())); |
| 2629 | } |
| 2630 | |
| 2631 | // Restore the orignal insert point for IRBuilder |
| 2632 | irb_.restoreIP(irb_ip_original); |
| 2633 | |
| 2634 | // Cache this landing pad |
| 2635 | DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset)); |
| 2636 | basic_block_landing_pads_[ti_offset] = block_lpad; |
| 2637 | |
| 2638 | return block_lpad; |
| 2639 | } |
| 2640 | |
| 2641 | llvm::BasicBlock* GBCExpanderPass::GetUnwindBasicBlock() { |
| 2642 | // Check the existing unwinding baisc block block |
| 2643 | if (basic_block_unwind_ != NULL) { |
| 2644 | return basic_block_unwind_; |
| 2645 | } |
| 2646 | |
| 2647 | // Create new basic block for unwinding |
| 2648 | basic_block_unwind_ = |
| 2649 | llvm::BasicBlock::Create(context_, "exception_unwind", func_); |
| 2650 | |
| 2651 | // Change IRBuilder insert point |
| 2652 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
| 2653 | irb_.SetInsertPoint(basic_block_unwind_); |
| 2654 | |
| 2655 | // Pop the shadow frame |
| 2656 | Expand_PopShadowFrame(); |
| 2657 | |
| 2658 | // 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] | 2659 | char ret_shorty = dex_compilation_unit_->GetShorty()[0]; |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 2660 | ret_shorty = art::RemapShorty(ret_shorty); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2661 | if (ret_shorty == 'V') { |
| 2662 | irb_.CreateRetVoid(); |
| 2663 | } else { |
| 2664 | irb_.CreateRet(irb_.getJZero(ret_shorty)); |
| 2665 | } |
| 2666 | |
| 2667 | // Restore the orignal insert point for IRBuilder |
| 2668 | irb_.restoreIP(irb_ip_original); |
| 2669 | |
| 2670 | return basic_block_unwind_; |
| 2671 | } |
| 2672 | |
| 2673 | void GBCExpanderPass::EmitBranchExceptionLandingPad(uint32_t dex_pc) { |
| 2674 | if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 2675 | landing_pad_phi_mapping_[lpad].push_back(std::make_pair(current_bb_->getUniquePredecessor(), |
TDYa127 | aa55887 | 2012-08-16 05:11:07 -0700 | [diff] [blame] | 2676 | irb_.GetInsertBlock())); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2677 | irb_.CreateBr(lpad); |
| 2678 | } else { |
| 2679 | irb_.CreateBr(GetUnwindBasicBlock()); |
| 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | void GBCExpanderPass::EmitGuard_ExceptionLandingPad(uint32_t dex_pc) { |
Jeff Hao | 9a14265 | 2013-01-17 23:10:19 +0000 | [diff] [blame] | 2684 | llvm::Value* exception_pending = irb_.Runtime().EmitIsExceptionPending(); |
| 2685 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2686 | llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2687 | |
| 2688 | if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 2689 | landing_pad_phi_mapping_[lpad].push_back(std::make_pair(current_bb_->getUniquePredecessor(), |
TDYa127 | aa55887 | 2012-08-16 05:11:07 -0700 | [diff] [blame] | 2690 | irb_.GetInsertBlock())); |
Jeff Hao | 9a14265 | 2013-01-17 23:10:19 +0000 | [diff] [blame] | 2691 | irb_.CreateCondBr(exception_pending, lpad, block_cont, kUnlikely); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2692 | } else { |
Jeff Hao | 9a14265 | 2013-01-17 23:10:19 +0000 | [diff] [blame] | 2693 | irb_.CreateCondBr(exception_pending, GetUnwindBasicBlock(), block_cont, kUnlikely); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | irb_.SetInsertPoint(block_cont); |
| 2697 | } |
| 2698 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2699 | llvm::Value* |
| 2700 | GBCExpanderPass::ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id, |
| 2701 | llvm::CallInst& call_inst) { |
| 2702 | switch (intr_id) { |
| 2703 | //==- Thread -----------------------------------------------------------==// |
| 2704 | case IntrinsicHelper::GetCurrentThread: { |
TDYa127 | b672d1e | 2012-06-28 21:21:45 -0700 | [diff] [blame] | 2705 | return irb_.Runtime().EmitGetCurrentThread(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2706 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2707 | case IntrinsicHelper::CheckSuspend: { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 2708 | Expand_TestSuspend(call_inst); |
TDYa127 | 890ea89 | 2012-08-22 10:49:42 -0700 | [diff] [blame] | 2709 | return NULL; |
| 2710 | } |
| 2711 | case IntrinsicHelper::TestSuspend: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 2712 | Expand_TestSuspend(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2713 | return NULL; |
| 2714 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2715 | case IntrinsicHelper::MarkGCCard: { |
TDYa127 | 9a12945 | 2012-07-19 03:10:08 -0700 | [diff] [blame] | 2716 | Expand_MarkGCCard(call_inst); |
| 2717 | return NULL; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2718 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2719 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2720 | //==- Exception --------------------------------------------------------==// |
| 2721 | case IntrinsicHelper::ThrowException: { |
| 2722 | return ExpandToRuntime(runtime_support::ThrowException, call_inst); |
| 2723 | } |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2724 | case IntrinsicHelper::HLThrowException: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2725 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2726 | |
| 2727 | EmitUpdateDexPC(dex_pc); |
| 2728 | |
| 2729 | irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowException), |
| 2730 | call_inst.getArgOperand(0)); |
| 2731 | |
| 2732 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2733 | return NULL; |
| 2734 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2735 | case IntrinsicHelper::GetException: { |
TDYa127 | 823433d | 2012-09-26 16:03:51 -0700 | [diff] [blame] | 2736 | return irb_.Runtime().EmitGetAndClearException(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2737 | } |
| 2738 | case IntrinsicHelper::IsExceptionPending: { |
| 2739 | return irb_.Runtime().EmitIsExceptionPending(); |
| 2740 | } |
| 2741 | case IntrinsicHelper::FindCatchBlock: { |
| 2742 | return ExpandToRuntime(runtime_support::FindCatchBlock, call_inst); |
| 2743 | } |
| 2744 | case IntrinsicHelper::ThrowDivZeroException: { |
| 2745 | return ExpandToRuntime(runtime_support::ThrowDivZeroException, call_inst); |
| 2746 | } |
| 2747 | case IntrinsicHelper::ThrowNullPointerException: { |
| 2748 | return ExpandToRuntime(runtime_support::ThrowNullPointerException, call_inst); |
| 2749 | } |
| 2750 | case IntrinsicHelper::ThrowIndexOutOfBounds: { |
| 2751 | return ExpandToRuntime(runtime_support::ThrowIndexOutOfBounds, call_inst); |
| 2752 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2753 | |
| 2754 | //==- Const String -----------------------------------------------------==// |
| 2755 | case IntrinsicHelper::ConstString: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2756 | return Expand_ConstString(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2757 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2758 | case IntrinsicHelper::LoadStringFromDexCache: { |
| 2759 | return Expand_LoadStringFromDexCache(call_inst.getArgOperand(0)); |
| 2760 | } |
| 2761 | case IntrinsicHelper::ResolveString: { |
| 2762 | return ExpandToRuntime(runtime_support::ResolveString, call_inst); |
| 2763 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2764 | |
| 2765 | //==- Const Class ------------------------------------------------------==// |
| 2766 | case IntrinsicHelper::ConstClass: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2767 | return Expand_ConstClass(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2768 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2769 | case IntrinsicHelper::InitializeTypeAndVerifyAccess: { |
| 2770 | return ExpandToRuntime(runtime_support::InitializeTypeAndVerifyAccess, call_inst); |
| 2771 | } |
| 2772 | case IntrinsicHelper::LoadTypeFromDexCache: { |
| 2773 | return Expand_LoadTypeFromDexCache(call_inst.getArgOperand(0)); |
| 2774 | } |
| 2775 | case IntrinsicHelper::InitializeType: { |
| 2776 | return ExpandToRuntime(runtime_support::InitializeType, call_inst); |
| 2777 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2778 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2779 | //==- Lock -------------------------------------------------------------==// |
| 2780 | case IntrinsicHelper::LockObject: { |
| 2781 | Expand_LockObject(call_inst.getArgOperand(0)); |
| 2782 | return NULL; |
| 2783 | } |
| 2784 | case IntrinsicHelper::UnlockObject: { |
| 2785 | Expand_UnlockObject(call_inst.getArgOperand(0)); |
| 2786 | return NULL; |
| 2787 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2788 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2789 | //==- Cast -------------------------------------------------------------==// |
| 2790 | case IntrinsicHelper::CheckCast: { |
| 2791 | return ExpandToRuntime(runtime_support::CheckCast, call_inst); |
| 2792 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2793 | case IntrinsicHelper::HLCheckCast: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2794 | Expand_HLCheckCast(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2795 | return NULL; |
| 2796 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2797 | case IntrinsicHelper::IsAssignable: { |
| 2798 | return ExpandToRuntime(runtime_support::IsAssignable, call_inst); |
| 2799 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2800 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2801 | //==- Alloc ------------------------------------------------------------==// |
| 2802 | case IntrinsicHelper::AllocObject: { |
| 2803 | return ExpandToRuntime(runtime_support::AllocObject, call_inst); |
| 2804 | } |
| 2805 | case IntrinsicHelper::AllocObjectWithAccessCheck: { |
| 2806 | return ExpandToRuntime(runtime_support::AllocObjectWithAccessCheck, call_inst); |
| 2807 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2808 | |
| 2809 | //==- Instance ---------------------------------------------------------==// |
| 2810 | case IntrinsicHelper::NewInstance: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2811 | return Expand_NewInstance(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2812 | } |
| 2813 | case IntrinsicHelper::InstanceOf: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2814 | return Expand_InstanceOf(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2817 | //==- Array ------------------------------------------------------------==// |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2818 | case IntrinsicHelper::NewArray: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2819 | return Expand_NewArray(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2820 | } |
| 2821 | case IntrinsicHelper::OptArrayLength: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2822 | return Expand_OptArrayLength(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2823 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2824 | case IntrinsicHelper::ArrayLength: { |
| 2825 | return EmitLoadArrayLength(call_inst.getArgOperand(0)); |
| 2826 | } |
| 2827 | case IntrinsicHelper::AllocArray: { |
| 2828 | return ExpandToRuntime(runtime_support::AllocArray, call_inst); |
| 2829 | } |
| 2830 | case IntrinsicHelper::AllocArrayWithAccessCheck: { |
| 2831 | return ExpandToRuntime(runtime_support::AllocArrayWithAccessCheck, |
| 2832 | call_inst); |
| 2833 | } |
| 2834 | case IntrinsicHelper::CheckAndAllocArray: { |
| 2835 | return ExpandToRuntime(runtime_support::CheckAndAllocArray, call_inst); |
| 2836 | } |
| 2837 | case IntrinsicHelper::CheckAndAllocArrayWithAccessCheck: { |
| 2838 | return ExpandToRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck, |
| 2839 | call_inst); |
| 2840 | } |
| 2841 | case IntrinsicHelper::ArrayGet: { |
| 2842 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2843 | call_inst.getArgOperand(1), |
| 2844 | kInt); |
| 2845 | } |
| 2846 | case IntrinsicHelper::ArrayGetWide: { |
| 2847 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2848 | call_inst.getArgOperand(1), |
| 2849 | kLong); |
| 2850 | } |
| 2851 | case IntrinsicHelper::ArrayGetObject: { |
| 2852 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2853 | call_inst.getArgOperand(1), |
| 2854 | kObject); |
| 2855 | } |
| 2856 | case IntrinsicHelper::ArrayGetBoolean: { |
| 2857 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2858 | call_inst.getArgOperand(1), |
| 2859 | kBoolean); |
| 2860 | } |
| 2861 | case IntrinsicHelper::ArrayGetByte: { |
| 2862 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2863 | call_inst.getArgOperand(1), |
| 2864 | kByte); |
| 2865 | } |
| 2866 | case IntrinsicHelper::ArrayGetChar: { |
| 2867 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2868 | call_inst.getArgOperand(1), |
| 2869 | kChar); |
| 2870 | } |
| 2871 | case IntrinsicHelper::ArrayGetShort: { |
| 2872 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2873 | call_inst.getArgOperand(1), |
| 2874 | kShort); |
| 2875 | } |
| 2876 | case IntrinsicHelper::ArrayPut: { |
| 2877 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2878 | call_inst.getArgOperand(1), |
| 2879 | call_inst.getArgOperand(2), |
| 2880 | kInt); |
| 2881 | return NULL; |
| 2882 | } |
| 2883 | case IntrinsicHelper::ArrayPutWide: { |
| 2884 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2885 | call_inst.getArgOperand(1), |
| 2886 | call_inst.getArgOperand(2), |
| 2887 | kLong); |
| 2888 | return NULL; |
| 2889 | } |
| 2890 | case IntrinsicHelper::ArrayPutObject: { |
| 2891 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2892 | call_inst.getArgOperand(1), |
| 2893 | call_inst.getArgOperand(2), |
| 2894 | kObject); |
| 2895 | return NULL; |
| 2896 | } |
| 2897 | case IntrinsicHelper::ArrayPutBoolean: { |
| 2898 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2899 | call_inst.getArgOperand(1), |
| 2900 | call_inst.getArgOperand(2), |
| 2901 | kBoolean); |
| 2902 | return NULL; |
| 2903 | } |
| 2904 | case IntrinsicHelper::ArrayPutByte: { |
| 2905 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2906 | call_inst.getArgOperand(1), |
| 2907 | call_inst.getArgOperand(2), |
| 2908 | kByte); |
| 2909 | return NULL; |
| 2910 | } |
| 2911 | case IntrinsicHelper::ArrayPutChar: { |
| 2912 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2913 | call_inst.getArgOperand(1), |
| 2914 | call_inst.getArgOperand(2), |
| 2915 | kChar); |
| 2916 | return NULL; |
| 2917 | } |
| 2918 | case IntrinsicHelper::ArrayPutShort: { |
| 2919 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2920 | call_inst.getArgOperand(1), |
| 2921 | call_inst.getArgOperand(2), |
| 2922 | kShort); |
| 2923 | return NULL; |
| 2924 | } |
| 2925 | case IntrinsicHelper::CheckPutArrayElement: { |
| 2926 | return ExpandToRuntime(runtime_support::CheckPutArrayElement, call_inst); |
| 2927 | } |
| 2928 | case IntrinsicHelper::FilledNewArray: { |
| 2929 | Expand_FilledNewArray(call_inst); |
| 2930 | return NULL; |
| 2931 | } |
| 2932 | case IntrinsicHelper::FillArrayData: { |
| 2933 | return ExpandToRuntime(runtime_support::FillArrayData, call_inst); |
| 2934 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2935 | case IntrinsicHelper::HLFillArrayData: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2936 | Expand_HLFillArrayData(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2937 | return NULL; |
| 2938 | } |
| 2939 | case IntrinsicHelper::HLFilledNewArray: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2940 | return Expand_HLFilledNewArray(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2943 | //==- Instance Field ---------------------------------------------------==// |
| 2944 | case IntrinsicHelper::InstanceFieldGet: |
| 2945 | case IntrinsicHelper::InstanceFieldGetBoolean: |
| 2946 | case IntrinsicHelper::InstanceFieldGetByte: |
| 2947 | case IntrinsicHelper::InstanceFieldGetChar: |
| 2948 | case IntrinsicHelper::InstanceFieldGetShort: { |
| 2949 | return ExpandToRuntime(runtime_support::Get32Instance, call_inst); |
| 2950 | } |
| 2951 | case IntrinsicHelper::InstanceFieldGetWide: { |
| 2952 | return ExpandToRuntime(runtime_support::Get64Instance, call_inst); |
| 2953 | } |
| 2954 | case IntrinsicHelper::InstanceFieldGetObject: { |
| 2955 | return ExpandToRuntime(runtime_support::GetObjectInstance, call_inst); |
| 2956 | } |
| 2957 | case IntrinsicHelper::InstanceFieldGetFast: { |
| 2958 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2959 | call_inst.getArgOperand(1), |
| 2960 | call_inst.getArgOperand(2), |
| 2961 | kInt); |
| 2962 | } |
| 2963 | case IntrinsicHelper::InstanceFieldGetWideFast: { |
| 2964 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2965 | call_inst.getArgOperand(1), |
| 2966 | call_inst.getArgOperand(2), |
| 2967 | kLong); |
| 2968 | } |
| 2969 | case IntrinsicHelper::InstanceFieldGetObjectFast: { |
| 2970 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2971 | call_inst.getArgOperand(1), |
| 2972 | call_inst.getArgOperand(2), |
| 2973 | kObject); |
| 2974 | } |
| 2975 | case IntrinsicHelper::InstanceFieldGetBooleanFast: { |
| 2976 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2977 | call_inst.getArgOperand(1), |
| 2978 | call_inst.getArgOperand(2), |
| 2979 | kBoolean); |
| 2980 | } |
| 2981 | case IntrinsicHelper::InstanceFieldGetByteFast: { |
| 2982 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2983 | call_inst.getArgOperand(1), |
| 2984 | call_inst.getArgOperand(2), |
| 2985 | kByte); |
| 2986 | } |
| 2987 | case IntrinsicHelper::InstanceFieldGetCharFast: { |
| 2988 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2989 | call_inst.getArgOperand(1), |
| 2990 | call_inst.getArgOperand(2), |
| 2991 | kChar); |
| 2992 | } |
| 2993 | case IntrinsicHelper::InstanceFieldGetShortFast: { |
| 2994 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2995 | call_inst.getArgOperand(1), |
| 2996 | call_inst.getArgOperand(2), |
| 2997 | kShort); |
| 2998 | } |
| 2999 | case IntrinsicHelper::InstanceFieldPut: |
| 3000 | case IntrinsicHelper::InstanceFieldPutBoolean: |
| 3001 | case IntrinsicHelper::InstanceFieldPutByte: |
| 3002 | case IntrinsicHelper::InstanceFieldPutChar: |
| 3003 | case IntrinsicHelper::InstanceFieldPutShort: { |
| 3004 | return ExpandToRuntime(runtime_support::Set32Instance, call_inst); |
| 3005 | } |
| 3006 | case IntrinsicHelper::InstanceFieldPutWide: { |
| 3007 | return ExpandToRuntime(runtime_support::Set64Instance, call_inst); |
| 3008 | } |
| 3009 | case IntrinsicHelper::InstanceFieldPutObject: { |
| 3010 | return ExpandToRuntime(runtime_support::SetObjectInstance, call_inst); |
| 3011 | } |
| 3012 | case IntrinsicHelper::InstanceFieldPutFast: { |
| 3013 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3014 | call_inst.getArgOperand(1), |
| 3015 | call_inst.getArgOperand(2), |
| 3016 | call_inst.getArgOperand(3), |
| 3017 | kInt); |
| 3018 | return NULL; |
| 3019 | } |
| 3020 | case IntrinsicHelper::InstanceFieldPutWideFast: { |
| 3021 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3022 | call_inst.getArgOperand(1), |
| 3023 | call_inst.getArgOperand(2), |
| 3024 | call_inst.getArgOperand(3), |
| 3025 | kLong); |
| 3026 | return NULL; |
| 3027 | } |
| 3028 | case IntrinsicHelper::InstanceFieldPutObjectFast: { |
| 3029 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3030 | call_inst.getArgOperand(1), |
| 3031 | call_inst.getArgOperand(2), |
| 3032 | call_inst.getArgOperand(3), |
| 3033 | kObject); |
| 3034 | return NULL; |
| 3035 | } |
| 3036 | case IntrinsicHelper::InstanceFieldPutBooleanFast: { |
| 3037 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3038 | call_inst.getArgOperand(1), |
| 3039 | call_inst.getArgOperand(2), |
| 3040 | call_inst.getArgOperand(3), |
| 3041 | kBoolean); |
| 3042 | return NULL; |
| 3043 | } |
| 3044 | case IntrinsicHelper::InstanceFieldPutByteFast: { |
| 3045 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3046 | call_inst.getArgOperand(1), |
| 3047 | call_inst.getArgOperand(2), |
| 3048 | call_inst.getArgOperand(3), |
| 3049 | kByte); |
| 3050 | return NULL; |
| 3051 | } |
| 3052 | case IntrinsicHelper::InstanceFieldPutCharFast: { |
| 3053 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3054 | call_inst.getArgOperand(1), |
| 3055 | call_inst.getArgOperand(2), |
| 3056 | call_inst.getArgOperand(3), |
| 3057 | kChar); |
| 3058 | return NULL; |
| 3059 | } |
| 3060 | case IntrinsicHelper::InstanceFieldPutShortFast: { |
| 3061 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3062 | call_inst.getArgOperand(1), |
| 3063 | call_inst.getArgOperand(2), |
| 3064 | call_inst.getArgOperand(3), |
| 3065 | kShort); |
| 3066 | return NULL; |
| 3067 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3068 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3069 | //==- Static Field -----------------------------------------------------==// |
| 3070 | case IntrinsicHelper::StaticFieldGet: |
| 3071 | case IntrinsicHelper::StaticFieldGetBoolean: |
| 3072 | case IntrinsicHelper::StaticFieldGetByte: |
| 3073 | case IntrinsicHelper::StaticFieldGetChar: |
| 3074 | case IntrinsicHelper::StaticFieldGetShort: { |
| 3075 | return ExpandToRuntime(runtime_support::Get32Static, call_inst); |
| 3076 | } |
| 3077 | case IntrinsicHelper::StaticFieldGetWide: { |
| 3078 | return ExpandToRuntime(runtime_support::Get64Static, call_inst); |
| 3079 | } |
| 3080 | case IntrinsicHelper::StaticFieldGetObject: { |
| 3081 | return ExpandToRuntime(runtime_support::GetObjectStatic, call_inst); |
| 3082 | } |
| 3083 | case IntrinsicHelper::StaticFieldGetFast: { |
| 3084 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3085 | call_inst.getArgOperand(1), |
| 3086 | call_inst.getArgOperand(2), |
| 3087 | kInt); |
| 3088 | } |
| 3089 | case IntrinsicHelper::StaticFieldGetWideFast: { |
| 3090 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3091 | call_inst.getArgOperand(1), |
| 3092 | call_inst.getArgOperand(2), |
| 3093 | kLong); |
| 3094 | } |
| 3095 | case IntrinsicHelper::StaticFieldGetObjectFast: { |
| 3096 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3097 | call_inst.getArgOperand(1), |
| 3098 | call_inst.getArgOperand(2), |
| 3099 | kObject); |
| 3100 | } |
| 3101 | case IntrinsicHelper::StaticFieldGetBooleanFast: { |
| 3102 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3103 | call_inst.getArgOperand(1), |
| 3104 | call_inst.getArgOperand(2), |
| 3105 | kBoolean); |
| 3106 | } |
| 3107 | case IntrinsicHelper::StaticFieldGetByteFast: { |
| 3108 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3109 | call_inst.getArgOperand(1), |
| 3110 | call_inst.getArgOperand(2), |
| 3111 | kByte); |
| 3112 | } |
| 3113 | case IntrinsicHelper::StaticFieldGetCharFast: { |
| 3114 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3115 | call_inst.getArgOperand(1), |
| 3116 | call_inst.getArgOperand(2), |
| 3117 | kChar); |
| 3118 | } |
| 3119 | case IntrinsicHelper::StaticFieldGetShortFast: { |
| 3120 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3121 | call_inst.getArgOperand(1), |
| 3122 | call_inst.getArgOperand(2), |
| 3123 | kShort); |
| 3124 | } |
| 3125 | case IntrinsicHelper::StaticFieldPut: |
| 3126 | case IntrinsicHelper::StaticFieldPutBoolean: |
| 3127 | case IntrinsicHelper::StaticFieldPutByte: |
| 3128 | case IntrinsicHelper::StaticFieldPutChar: |
| 3129 | case IntrinsicHelper::StaticFieldPutShort: { |
| 3130 | return ExpandToRuntime(runtime_support::Set32Static, call_inst); |
| 3131 | } |
| 3132 | case IntrinsicHelper::StaticFieldPutWide: { |
| 3133 | return ExpandToRuntime(runtime_support::Set64Static, call_inst); |
| 3134 | } |
| 3135 | case IntrinsicHelper::StaticFieldPutObject: { |
| 3136 | return ExpandToRuntime(runtime_support::SetObjectStatic, call_inst); |
| 3137 | } |
| 3138 | case IntrinsicHelper::StaticFieldPutFast: { |
| 3139 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3140 | call_inst.getArgOperand(1), |
| 3141 | call_inst.getArgOperand(2), |
| 3142 | call_inst.getArgOperand(3), |
| 3143 | kInt); |
| 3144 | return NULL; |
| 3145 | } |
| 3146 | case IntrinsicHelper::StaticFieldPutWideFast: { |
| 3147 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3148 | call_inst.getArgOperand(1), |
| 3149 | call_inst.getArgOperand(2), |
| 3150 | call_inst.getArgOperand(3), |
| 3151 | kLong); |
| 3152 | return NULL; |
| 3153 | } |
| 3154 | case IntrinsicHelper::StaticFieldPutObjectFast: { |
| 3155 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3156 | call_inst.getArgOperand(1), |
| 3157 | call_inst.getArgOperand(2), |
| 3158 | call_inst.getArgOperand(3), |
| 3159 | kObject); |
| 3160 | return NULL; |
| 3161 | } |
| 3162 | case IntrinsicHelper::StaticFieldPutBooleanFast: { |
| 3163 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3164 | call_inst.getArgOperand(1), |
| 3165 | call_inst.getArgOperand(2), |
| 3166 | call_inst.getArgOperand(3), |
| 3167 | kBoolean); |
| 3168 | return NULL; |
| 3169 | } |
| 3170 | case IntrinsicHelper::StaticFieldPutByteFast: { |
| 3171 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3172 | call_inst.getArgOperand(1), |
| 3173 | call_inst.getArgOperand(2), |
| 3174 | call_inst.getArgOperand(3), |
| 3175 | kByte); |
| 3176 | return NULL; |
| 3177 | } |
| 3178 | case IntrinsicHelper::StaticFieldPutCharFast: { |
| 3179 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3180 | call_inst.getArgOperand(1), |
| 3181 | call_inst.getArgOperand(2), |
| 3182 | call_inst.getArgOperand(3), |
| 3183 | kChar); |
| 3184 | return NULL; |
| 3185 | } |
| 3186 | case IntrinsicHelper::StaticFieldPutShortFast: { |
| 3187 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3188 | call_inst.getArgOperand(1), |
| 3189 | call_inst.getArgOperand(2), |
| 3190 | call_inst.getArgOperand(3), |
| 3191 | kShort); |
| 3192 | return NULL; |
| 3193 | } |
| 3194 | case IntrinsicHelper::LoadDeclaringClassSSB: { |
| 3195 | return Expand_LoadDeclaringClassSSB(call_inst.getArgOperand(0)); |
| 3196 | } |
| 3197 | case IntrinsicHelper::LoadClassSSBFromDexCache: { |
| 3198 | return Expand_LoadClassSSBFromDexCache(call_inst.getArgOperand(0)); |
| 3199 | } |
| 3200 | case IntrinsicHelper::InitializeAndLoadClassSSB: { |
| 3201 | return ExpandToRuntime(runtime_support::InitializeStaticStorage, call_inst); |
| 3202 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3203 | |
| 3204 | //==- High-level Array -------------------------------------------------==// |
| 3205 | case IntrinsicHelper::HLArrayGet: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3206 | return Expand_HLArrayGet(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3207 | } |
| 3208 | case IntrinsicHelper::HLArrayGetBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3209 | return Expand_HLArrayGet(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3210 | } |
| 3211 | case IntrinsicHelper::HLArrayGetByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3212 | return Expand_HLArrayGet(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3213 | } |
| 3214 | case IntrinsicHelper::HLArrayGetChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3215 | return Expand_HLArrayGet(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3216 | } |
| 3217 | case IntrinsicHelper::HLArrayGetShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3218 | return Expand_HLArrayGet(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3219 | } |
| 3220 | case IntrinsicHelper::HLArrayGetFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3221 | return Expand_HLArrayGet(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3222 | } |
| 3223 | case IntrinsicHelper::HLArrayGetWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3224 | return Expand_HLArrayGet(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3225 | } |
| 3226 | case IntrinsicHelper::HLArrayGetDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3227 | return Expand_HLArrayGet(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3228 | } |
| 3229 | case IntrinsicHelper::HLArrayGetObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3230 | return Expand_HLArrayGet(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3231 | } |
| 3232 | case IntrinsicHelper::HLArrayPut: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3233 | Expand_HLArrayPut(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3234 | return NULL; |
| 3235 | } |
| 3236 | case IntrinsicHelper::HLArrayPutBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3237 | Expand_HLArrayPut(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3238 | return NULL; |
| 3239 | } |
| 3240 | case IntrinsicHelper::HLArrayPutByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3241 | Expand_HLArrayPut(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3242 | return NULL; |
| 3243 | } |
| 3244 | case IntrinsicHelper::HLArrayPutChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3245 | Expand_HLArrayPut(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3246 | return NULL; |
| 3247 | } |
| 3248 | case IntrinsicHelper::HLArrayPutShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3249 | Expand_HLArrayPut(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3250 | return NULL; |
| 3251 | } |
| 3252 | case IntrinsicHelper::HLArrayPutFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3253 | Expand_HLArrayPut(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3254 | return NULL; |
| 3255 | } |
| 3256 | case IntrinsicHelper::HLArrayPutWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3257 | Expand_HLArrayPut(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3258 | return NULL; |
| 3259 | } |
| 3260 | case IntrinsicHelper::HLArrayPutDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3261 | Expand_HLArrayPut(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3262 | return NULL; |
| 3263 | } |
| 3264 | case IntrinsicHelper::HLArrayPutObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3265 | Expand_HLArrayPut(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3266 | return NULL; |
| 3267 | } |
| 3268 | |
| 3269 | //==- High-level Instance ----------------------------------------------==// |
| 3270 | case IntrinsicHelper::HLIGet: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3271 | return Expand_HLIGet(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3272 | } |
| 3273 | case IntrinsicHelper::HLIGetBoolean: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3274 | return Expand_HLIGet(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3275 | } |
| 3276 | case IntrinsicHelper::HLIGetByte: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3277 | return Expand_HLIGet(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3278 | } |
| 3279 | case IntrinsicHelper::HLIGetChar: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3280 | return Expand_HLIGet(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3281 | } |
| 3282 | case IntrinsicHelper::HLIGetShort: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3283 | return Expand_HLIGet(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3284 | } |
| 3285 | case IntrinsicHelper::HLIGetFloat: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3286 | return Expand_HLIGet(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3287 | } |
| 3288 | case IntrinsicHelper::HLIGetWide: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3289 | return Expand_HLIGet(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3290 | } |
| 3291 | case IntrinsicHelper::HLIGetDouble: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3292 | return Expand_HLIGet(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3293 | } |
| 3294 | case IntrinsicHelper::HLIGetObject: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3295 | return Expand_HLIGet(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3296 | } |
| 3297 | case IntrinsicHelper::HLIPut: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3298 | Expand_HLIPut(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3299 | return NULL; |
| 3300 | } |
| 3301 | case IntrinsicHelper::HLIPutBoolean: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3302 | Expand_HLIPut(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3303 | return NULL; |
| 3304 | } |
| 3305 | case IntrinsicHelper::HLIPutByte: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3306 | Expand_HLIPut(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3307 | return NULL; |
| 3308 | } |
| 3309 | case IntrinsicHelper::HLIPutChar: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3310 | Expand_HLIPut(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3311 | return NULL; |
| 3312 | } |
| 3313 | case IntrinsicHelper::HLIPutShort: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3314 | Expand_HLIPut(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3315 | return NULL; |
| 3316 | } |
| 3317 | case IntrinsicHelper::HLIPutFloat: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3318 | Expand_HLIPut(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3319 | return NULL; |
| 3320 | } |
| 3321 | case IntrinsicHelper::HLIPutWide: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3322 | Expand_HLIPut(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3323 | return NULL; |
| 3324 | } |
| 3325 | case IntrinsicHelper::HLIPutDouble: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3326 | Expand_HLIPut(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3327 | return NULL; |
| 3328 | } |
| 3329 | case IntrinsicHelper::HLIPutObject: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3330 | Expand_HLIPut(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3331 | return NULL; |
| 3332 | } |
| 3333 | |
| 3334 | //==- High-level Invoke ------------------------------------------------==// |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3335 | case IntrinsicHelper::HLInvokeVoid: |
| 3336 | case IntrinsicHelper::HLInvokeObj: |
| 3337 | case IntrinsicHelper::HLInvokeInt: |
| 3338 | case IntrinsicHelper::HLInvokeFloat: |
| 3339 | case IntrinsicHelper::HLInvokeLong: |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3340 | case IntrinsicHelper::HLInvokeDouble: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3341 | return Expand_HLInvoke(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3342 | } |
| 3343 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3344 | //==- Invoke -----------------------------------------------------------==// |
| 3345 | case IntrinsicHelper::FindStaticMethodWithAccessCheck: { |
| 3346 | return ExpandToRuntime(runtime_support::FindStaticMethodWithAccessCheck, call_inst); |
| 3347 | } |
| 3348 | case IntrinsicHelper::FindDirectMethodWithAccessCheck: { |
| 3349 | return ExpandToRuntime(runtime_support::FindDirectMethodWithAccessCheck, call_inst); |
| 3350 | } |
| 3351 | case IntrinsicHelper::FindVirtualMethodWithAccessCheck: { |
| 3352 | return ExpandToRuntime(runtime_support::FindVirtualMethodWithAccessCheck, call_inst); |
| 3353 | } |
| 3354 | case IntrinsicHelper::FindSuperMethodWithAccessCheck: { |
| 3355 | return ExpandToRuntime(runtime_support::FindSuperMethodWithAccessCheck, call_inst); |
| 3356 | } |
| 3357 | case IntrinsicHelper::FindInterfaceMethodWithAccessCheck: { |
| 3358 | return ExpandToRuntime(runtime_support::FindInterfaceMethodWithAccessCheck, call_inst); |
| 3359 | } |
| 3360 | case IntrinsicHelper::GetSDCalleeMethodObjAddrFast: { |
| 3361 | return Expand_GetSDCalleeMethodObjAddrFast(call_inst.getArgOperand(0)); |
| 3362 | } |
| 3363 | case IntrinsicHelper::GetVirtualCalleeMethodObjAddrFast: { |
| 3364 | return Expand_GetVirtualCalleeMethodObjAddrFast( |
| 3365 | call_inst.getArgOperand(0), call_inst.getArgOperand(1)); |
| 3366 | } |
| 3367 | case IntrinsicHelper::GetInterfaceCalleeMethodObjAddrFast: { |
| 3368 | return ExpandToRuntime(runtime_support::FindInterfaceMethod, call_inst); |
| 3369 | } |
| 3370 | case IntrinsicHelper::InvokeRetVoid: |
| 3371 | case IntrinsicHelper::InvokeRetBoolean: |
| 3372 | case IntrinsicHelper::InvokeRetByte: |
| 3373 | case IntrinsicHelper::InvokeRetChar: |
| 3374 | case IntrinsicHelper::InvokeRetShort: |
| 3375 | case IntrinsicHelper::InvokeRetInt: |
| 3376 | case IntrinsicHelper::InvokeRetLong: |
| 3377 | case IntrinsicHelper::InvokeRetFloat: |
| 3378 | case IntrinsicHelper::InvokeRetDouble: |
| 3379 | case IntrinsicHelper::InvokeRetObject: { |
| 3380 | return Expand_Invoke(call_inst); |
| 3381 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3382 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3383 | //==- Math -------------------------------------------------------------==// |
| 3384 | case IntrinsicHelper::DivInt: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3385 | return Expand_DivRem(call_inst, /* is_div */true, kInt); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3386 | } |
| 3387 | case IntrinsicHelper::RemInt: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3388 | return Expand_DivRem(call_inst, /* is_div */false, kInt); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3389 | } |
| 3390 | case IntrinsicHelper::DivLong: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3391 | return Expand_DivRem(call_inst, /* is_div */true, kLong); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3392 | } |
| 3393 | case IntrinsicHelper::RemLong: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3394 | return Expand_DivRem(call_inst, /* is_div */false, kLong); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3395 | } |
| 3396 | case IntrinsicHelper::D2L: { |
| 3397 | return ExpandToRuntime(runtime_support::art_d2l, call_inst); |
| 3398 | } |
| 3399 | case IntrinsicHelper::D2I: { |
| 3400 | return ExpandToRuntime(runtime_support::art_d2i, call_inst); |
| 3401 | } |
| 3402 | case IntrinsicHelper::F2L: { |
| 3403 | return ExpandToRuntime(runtime_support::art_f2l, call_inst); |
| 3404 | } |
| 3405 | case IntrinsicHelper::F2I: { |
| 3406 | return ExpandToRuntime(runtime_support::art_f2i, call_inst); |
| 3407 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3408 | |
| 3409 | //==- High-level Static ------------------------------------------------==// |
| 3410 | case IntrinsicHelper::HLSget: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3411 | return Expand_HLSget(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3412 | } |
| 3413 | case IntrinsicHelper::HLSgetBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3414 | return Expand_HLSget(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3415 | } |
| 3416 | case IntrinsicHelper::HLSgetByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3417 | return Expand_HLSget(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3418 | } |
| 3419 | case IntrinsicHelper::HLSgetChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3420 | return Expand_HLSget(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3421 | } |
| 3422 | case IntrinsicHelper::HLSgetShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3423 | return Expand_HLSget(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3424 | } |
| 3425 | case IntrinsicHelper::HLSgetFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3426 | return Expand_HLSget(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3427 | } |
| 3428 | case IntrinsicHelper::HLSgetWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3429 | return Expand_HLSget(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3430 | } |
| 3431 | case IntrinsicHelper::HLSgetDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3432 | return Expand_HLSget(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3433 | } |
| 3434 | case IntrinsicHelper::HLSgetObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3435 | return Expand_HLSget(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3436 | } |
| 3437 | case IntrinsicHelper::HLSput: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3438 | Expand_HLSput(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3439 | return NULL; |
| 3440 | } |
| 3441 | case IntrinsicHelper::HLSputBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3442 | Expand_HLSput(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3443 | return NULL; |
| 3444 | } |
| 3445 | case IntrinsicHelper::HLSputByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3446 | Expand_HLSput(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3447 | return NULL; |
| 3448 | } |
| 3449 | case IntrinsicHelper::HLSputChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3450 | Expand_HLSput(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3451 | return NULL; |
| 3452 | } |
| 3453 | case IntrinsicHelper::HLSputShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3454 | Expand_HLSput(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3455 | return NULL; |
| 3456 | } |
| 3457 | case IntrinsicHelper::HLSputFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3458 | Expand_HLSput(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3459 | return NULL; |
| 3460 | } |
| 3461 | case IntrinsicHelper::HLSputWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3462 | Expand_HLSput(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3463 | return NULL; |
| 3464 | } |
| 3465 | case IntrinsicHelper::HLSputDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3466 | Expand_HLSput(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3467 | return NULL; |
| 3468 | } |
| 3469 | case IntrinsicHelper::HLSputObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3470 | Expand_HLSput(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3471 | return NULL; |
| 3472 | } |
| 3473 | |
| 3474 | //==- High-level Monitor -----------------------------------------------==// |
| 3475 | case IntrinsicHelper::MonitorEnter: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3476 | Expand_MonitorEnter(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3477 | return NULL; |
| 3478 | } |
| 3479 | case IntrinsicHelper::MonitorExit: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3480 | Expand_MonitorExit(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3481 | return NULL; |
| 3482 | } |
| 3483 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3484 | //==- Shadow Frame -----------------------------------------------------==// |
| 3485 | case IntrinsicHelper::AllocaShadowFrame: { |
TDYa127 | ce4cc0d | 2012-11-18 16:59:53 -0800 | [diff] [blame] | 3486 | Expand_AllocaShadowFrame(call_inst.getArgOperand(0)); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3487 | return NULL; |
| 3488 | } |
TDYa127 | 8e950c1 | 2012-11-02 09:58:19 -0700 | [diff] [blame] | 3489 | case IntrinsicHelper::SetVReg: { |
| 3490 | Expand_SetVReg(call_inst.getArgOperand(0), |
| 3491 | call_inst.getArgOperand(1)); |
| 3492 | return NULL; |
| 3493 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3494 | case IntrinsicHelper::PopShadowFrame: { |
| 3495 | Expand_PopShadowFrame(); |
| 3496 | return NULL; |
| 3497 | } |
| 3498 | case IntrinsicHelper::UpdateDexPC: { |
| 3499 | Expand_UpdateDexPC(call_inst.getArgOperand(0)); |
| 3500 | return NULL; |
| 3501 | } |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 3502 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3503 | //==- Comparison -------------------------------------------------------==// |
| 3504 | case IntrinsicHelper::CmplFloat: |
| 3505 | case IntrinsicHelper::CmplDouble: { |
| 3506 | return Expand_FPCompare(call_inst.getArgOperand(0), |
| 3507 | call_inst.getArgOperand(1), |
| 3508 | false); |
| 3509 | } |
| 3510 | case IntrinsicHelper::CmpgFloat: |
| 3511 | case IntrinsicHelper::CmpgDouble: { |
| 3512 | return Expand_FPCompare(call_inst.getArgOperand(0), |
| 3513 | call_inst.getArgOperand(1), |
| 3514 | true); |
| 3515 | } |
| 3516 | case IntrinsicHelper::CmpLong: { |
| 3517 | return Expand_LongCompare(call_inst.getArgOperand(0), |
| 3518 | call_inst.getArgOperand(1)); |
| 3519 | } |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 3520 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3521 | //==- Const ------------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3522 | case IntrinsicHelper::ConstInt: |
| 3523 | case IntrinsicHelper::ConstLong: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 3524 | return call_inst.getArgOperand(0); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3525 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3526 | case IntrinsicHelper::ConstFloat: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 3527 | return irb_.CreateBitCast(call_inst.getArgOperand(0), |
| 3528 | irb_.getJFloatTy()); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3529 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3530 | case IntrinsicHelper::ConstDouble: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 3531 | return irb_.CreateBitCast(call_inst.getArgOperand(0), |
| 3532 | irb_.getJDoubleTy()); |
| 3533 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3534 | case IntrinsicHelper::ConstObj: { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 3535 | CHECK(LV2UInt(call_inst.getArgOperand(0)) == 0); |
| 3536 | return irb_.getJNull(); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | //==- Method Info ------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3540 | case IntrinsicHelper::MethodInfo: { |
Shih-wei Liao | b259652 | 2012-09-14 16:36:11 -0700 | [diff] [blame] | 3541 | // Nothing to be done, because MethodInfo carries optional hints that are |
| 3542 | // not needed by the portable path. |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3543 | return NULL; |
| 3544 | } |
| 3545 | |
| 3546 | //==- Copy -------------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3547 | case IntrinsicHelper::CopyInt: |
| 3548 | case IntrinsicHelper::CopyFloat: |
| 3549 | case IntrinsicHelper::CopyLong: |
| 3550 | case IntrinsicHelper::CopyDouble: |
| 3551 | case IntrinsicHelper::CopyObj: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 3552 | return call_inst.getArgOperand(0); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | //==- Shift ------------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3556 | case IntrinsicHelper::SHLLong: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3557 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3558 | call_inst.getArgOperand(1), |
| 3559 | kIntegerSHL, kLong); |
| 3560 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3561 | case IntrinsicHelper::SHRLong: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3562 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3563 | call_inst.getArgOperand(1), |
| 3564 | kIntegerSHR, kLong); |
| 3565 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3566 | case IntrinsicHelper::USHRLong: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3567 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3568 | call_inst.getArgOperand(1), |
| 3569 | kIntegerUSHR, kLong); |
| 3570 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3571 | case IntrinsicHelper::SHLInt: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3572 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3573 | call_inst.getArgOperand(1), |
| 3574 | kIntegerSHL, kInt); |
| 3575 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3576 | case IntrinsicHelper::SHRInt: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3577 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3578 | call_inst.getArgOperand(1), |
| 3579 | kIntegerSHR, kInt); |
| 3580 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3581 | case IntrinsicHelper::USHRInt: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3582 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3583 | call_inst.getArgOperand(1), |
| 3584 | kIntegerUSHR, kInt); |
| 3585 | } |
| 3586 | |
| 3587 | //==- Conversion -------------------------------------------------------==// |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 3588 | case IntrinsicHelper::IntToChar: { |
| 3589 | return irb_.CreateZExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJCharTy()), |
| 3590 | irb_.getJIntTy()); |
| 3591 | } |
| 3592 | case IntrinsicHelper::IntToShort: { |
| 3593 | return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJShortTy()), |
| 3594 | irb_.getJIntTy()); |
| 3595 | } |
| 3596 | case IntrinsicHelper::IntToByte: { |
| 3597 | return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJByteTy()), |
| 3598 | irb_.getJIntTy()); |
| 3599 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3600 | |
TDYa127 | 87caa7e | 2012-08-25 23:23:27 -0700 | [diff] [blame] | 3601 | //==- Exception --------------------------------------------------------==// |
| 3602 | case IntrinsicHelper::CatchTargets: { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 3603 | UpdatePhiInstruction(current_bb_, irb_.GetInsertBlock()); |
TDYa127 | 87caa7e | 2012-08-25 23:23:27 -0700 | [diff] [blame] | 3604 | llvm::SwitchInst* si = llvm::dyn_cast<llvm::SwitchInst>(call_inst.getNextNode()); |
| 3605 | CHECK(si != NULL); |
| 3606 | irb_.CreateBr(si->getDefaultDest()); |
| 3607 | si->eraseFromParent(); |
| 3608 | return call_inst.getArgOperand(0); |
| 3609 | } |
| 3610 | |
Sebastien Hertz | 0d43d54 | 2013-02-27 19:02:16 +0100 | [diff] [blame] | 3611 | //==- Constructor barrier-----------------------------------------------==// |
| 3612 | case IntrinsicHelper::ConstructorBarrier: { |
| 3613 | irb_.CreateMemoryBarrier(art::kStoreStore); |
| 3614 | return NULL; |
| 3615 | } |
| 3616 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3617 | //==- Unknown Cases ----------------------------------------------------==// |
| 3618 | case IntrinsicHelper::MaxIntrinsicId: |
| 3619 | case IntrinsicHelper::UnknownId: |
| 3620 | //default: |
| 3621 | // NOTE: "default" is intentionally commented so that C/C++ compiler will |
| 3622 | // give some warning on unmatched cases. |
| 3623 | // NOTE: We should not implement these cases. |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3624 | break; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3625 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3626 | UNIMPLEMENTED(FATAL) << "Unexpected GBC intrinsic: " << static_cast<int>(intr_id); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3627 | return NULL; |
| 3628 | } |
| 3629 | |
| 3630 | } // anonymous namespace |
| 3631 | |
| 3632 | namespace art { |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame^] | 3633 | namespace llvm { |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3634 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame^] | 3635 | ::llvm::FunctionPass* |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 3636 | CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb, |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 3637 | CompilerDriver* driver, DexCompilationUnit* dex_compilation_unit) { |
| 3638 | return new GBCExpanderPass(intrinsic_helper, irb, driver, dex_compilation_unit); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame^] | 3641 | } // namespace llvm |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3642 | } // namespace art |