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