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 | 6c27968 | 2012-10-16 18:07:43 -0700 | [diff] [blame] | 63 | uint16_t num_shadow_frame_refs_; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 64 | |
| 65 | private: |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 66 | art::Compiler* compiler_; |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 67 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 68 | const art::DexFile* dex_file_; |
| 69 | const art::DexFile::CodeItem* code_item_; |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 70 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 71 | art::OatCompilationUnit* oat_compilation_unit_; |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 72 | |
| 73 | uint32_t method_idx_; |
| 74 | |
| 75 | llvm::Function* func_; |
| 76 | |
| 77 | std::vector<llvm::BasicBlock*> basic_blocks_; |
| 78 | |
| 79 | std::vector<llvm::BasicBlock*> basic_block_landing_pads_; |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 80 | llvm::BasicBlock* current_bb_; |
TDYa127 | aa55887 | 2012-08-16 05:11:07 -0700 | [diff] [blame] | 81 | std::map<llvm::BasicBlock*, std::vector<std::pair<llvm::BasicBlock*, llvm::BasicBlock*> > > |
| 82 | landing_pad_phi_mapping_; |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 83 | llvm::BasicBlock* basic_block_unwind_; |
| 84 | |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 85 | bool changed_; |
| 86 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 87 | private: |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 88 | //---------------------------------------------------------------------------- |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 89 | // Constant for GBC expansion |
| 90 | //---------------------------------------------------------------------------- |
| 91 | enum IntegerShiftKind { |
| 92 | kIntegerSHL, |
| 93 | kIntegerSHR, |
| 94 | kIntegerUSHR, |
| 95 | }; |
| 96 | |
| 97 | private: |
| 98 | //---------------------------------------------------------------------------- |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 99 | // Helper function for GBC expansion |
| 100 | //---------------------------------------------------------------------------- |
| 101 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 102 | llvm::Value* ExpandToRuntime(runtime_support::RuntimeId rt, |
| 103 | llvm::CallInst& inst); |
| 104 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 105 | uint64_t LV2UInt(llvm::Value* lv) { |
| 106 | return llvm::cast<llvm::ConstantInt>(lv)->getZExtValue(); |
| 107 | } |
| 108 | |
| 109 | int64_t LV2SInt(llvm::Value* lv) { |
| 110 | return llvm::cast<llvm::ConstantInt>(lv)->getSExtValue(); |
| 111 | } |
| 112 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 113 | private: |
| 114 | // TODO: Almost all Emit* are directly copy-n-paste from MethodCompiler. |
| 115 | // Refactor these utility functions from MethodCompiler to avoid forking. |
| 116 | |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 117 | void EmitStackOverflowCheck(llvm::Instruction* first_non_alloca); |
| 118 | |
| 119 | void RewriteFunction(); |
| 120 | |
| 121 | void RewriteBasicBlock(llvm::BasicBlock* original_block); |
| 122 | |
| 123 | void UpdatePhiInstruction(llvm::BasicBlock* old_basic_block, |
| 124 | llvm::BasicBlock* new_basic_block); |
| 125 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 126 | |
| 127 | //---------------------------------------------------------------------------- |
| 128 | // Dex cache code generation helper function |
| 129 | //---------------------------------------------------------------------------- |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 130 | llvm::Value* EmitLoadDexCacheAddr(art::MemberOffset dex_cache_offset); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 131 | |
| 132 | llvm::Value* EmitLoadDexCacheStaticStorageFieldAddr(uint32_t type_idx); |
| 133 | |
| 134 | llvm::Value* EmitLoadDexCacheResolvedTypeFieldAddr(uint32_t type_idx); |
| 135 | |
| 136 | llvm::Value* EmitLoadDexCacheResolvedMethodFieldAddr(uint32_t method_idx); |
| 137 | |
| 138 | llvm::Value* EmitLoadDexCacheStringFieldAddr(uint32_t string_idx); |
| 139 | |
| 140 | //---------------------------------------------------------------------------- |
| 141 | // Code generation helper function |
| 142 | //---------------------------------------------------------------------------- |
| 143 | llvm::Value* EmitLoadMethodObjectAddr(); |
| 144 | |
| 145 | llvm::Value* EmitLoadArrayLength(llvm::Value* array); |
| 146 | |
| 147 | llvm::Value* EmitLoadSDCalleeMethodObjectAddr(uint32_t callee_method_idx); |
| 148 | |
| 149 | llvm::Value* EmitLoadVirtualCalleeMethodObjectAddr(int vtable_idx, |
| 150 | llvm::Value* this_addr); |
| 151 | |
| 152 | llvm::Value* EmitArrayGEP(llvm::Value* array_addr, |
| 153 | llvm::Value* index_value, |
| 154 | JType elem_jty); |
| 155 | |
| 156 | private: |
| 157 | //---------------------------------------------------------------------------- |
| 158 | // Expand Greenland intrinsics |
| 159 | //---------------------------------------------------------------------------- |
| 160 | void Expand_TestSuspend(llvm::CallInst& call_inst); |
| 161 | |
TDYa127 | 9a12945 | 2012-07-19 03:10:08 -0700 | [diff] [blame] | 162 | void Expand_MarkGCCard(llvm::CallInst& call_inst); |
| 163 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 164 | llvm::Value* Expand_LoadStringFromDexCache(llvm::Value* string_idx_value); |
| 165 | |
| 166 | llvm::Value* Expand_LoadTypeFromDexCache(llvm::Value* type_idx_value); |
| 167 | |
| 168 | void Expand_LockObject(llvm::Value* obj); |
| 169 | |
| 170 | void Expand_UnlockObject(llvm::Value* obj); |
| 171 | |
| 172 | llvm::Value* Expand_ArrayGet(llvm::Value* array_addr, |
| 173 | llvm::Value* index_value, |
| 174 | JType elem_jty); |
| 175 | |
| 176 | void Expand_ArrayPut(llvm::Value* new_value, |
| 177 | llvm::Value* array_addr, |
| 178 | llvm::Value* index_value, |
| 179 | JType elem_jty); |
| 180 | |
| 181 | void Expand_FilledNewArray(llvm::CallInst& call_inst); |
| 182 | |
| 183 | llvm::Value* Expand_IGetFast(llvm::Value* field_offset_value, |
| 184 | llvm::Value* is_volatile_value, |
| 185 | llvm::Value* object_addr, |
| 186 | JType field_jty); |
| 187 | |
| 188 | void Expand_IPutFast(llvm::Value* field_offset_value, |
| 189 | llvm::Value* is_volatile_value, |
| 190 | llvm::Value* object_addr, |
| 191 | llvm::Value* new_value, |
| 192 | JType field_jty); |
| 193 | |
| 194 | llvm::Value* Expand_SGetFast(llvm::Value* static_storage_addr, |
| 195 | llvm::Value* field_offset_value, |
| 196 | llvm::Value* is_volatile_value, |
| 197 | JType field_jty); |
| 198 | |
| 199 | void Expand_SPutFast(llvm::Value* static_storage_addr, |
| 200 | llvm::Value* field_offset_value, |
| 201 | llvm::Value* is_volatile_value, |
| 202 | llvm::Value* new_value, |
| 203 | JType field_jty); |
| 204 | |
| 205 | llvm::Value* Expand_LoadDeclaringClassSSB(llvm::Value* method_object_addr); |
| 206 | |
| 207 | llvm::Value* Expand_LoadClassSSBFromDexCache(llvm::Value* type_idx_value); |
| 208 | |
| 209 | llvm::Value* |
| 210 | Expand_GetSDCalleeMethodObjAddrFast(llvm::Value* callee_method_idx_value); |
| 211 | |
| 212 | llvm::Value* |
| 213 | Expand_GetVirtualCalleeMethodObjAddrFast(llvm::Value* vtable_idx_value, |
| 214 | llvm::Value* this_addr); |
| 215 | |
| 216 | llvm::Value* Expand_Invoke(llvm::CallInst& call_inst); |
| 217 | |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 218 | 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] | 219 | |
| 220 | void Expand_AllocaShadowFrame(llvm::Value* num_entry_value); |
| 221 | |
| 222 | void Expand_SetShadowFrameEntry(llvm::Value* obj, llvm::Value* entry_idx); |
| 223 | |
| 224 | void Expand_PopShadowFrame(); |
| 225 | |
| 226 | void Expand_UpdateDexPC(llvm::Value* dex_pc_value); |
| 227 | |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 228 | //---------------------------------------------------------------------------- |
| 229 | // Quick |
| 230 | //---------------------------------------------------------------------------- |
| 231 | |
| 232 | llvm::Value* Expand_FPCompare(llvm::Value* src1_value, |
| 233 | llvm::Value* src2_value, |
| 234 | bool gt_bias); |
| 235 | |
| 236 | llvm::Value* Expand_LongCompare(llvm::Value* src1_value, llvm::Value* src2_value); |
| 237 | |
| 238 | llvm::Value* EmitCompareResultSelection(llvm::Value* cmp_eq, |
| 239 | llvm::Value* cmp_lt); |
| 240 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 241 | llvm::Value* EmitLoadConstantClass(uint32_t dex_pc, uint32_t type_idx); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 242 | llvm::Value* EmitLoadStaticStorage(uint32_t dex_pc, uint32_t type_idx); |
| 243 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 244 | llvm::Value* Expand_HLIGet(llvm::CallInst& call_inst, JType field_jty); |
| 245 | void Expand_HLIPut(llvm::CallInst& call_inst, JType field_jty); |
| 246 | |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 247 | llvm::Value* Expand_HLSget(llvm::CallInst& call_inst, JType field_jty); |
| 248 | void Expand_HLSput(llvm::CallInst& call_inst, JType field_jty); |
| 249 | |
| 250 | llvm::Value* Expand_HLArrayGet(llvm::CallInst& call_inst, JType field_jty); |
| 251 | void Expand_HLArrayPut(llvm::CallInst& call_inst, JType field_jty); |
| 252 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 253 | llvm::Value* Expand_ConstString(llvm::CallInst& call_inst); |
| 254 | llvm::Value* Expand_ConstClass(llvm::CallInst& call_inst); |
| 255 | |
| 256 | void Expand_MonitorEnter(llvm::CallInst& call_inst); |
| 257 | void Expand_MonitorExit(llvm::CallInst& call_inst); |
| 258 | |
| 259 | void Expand_HLCheckCast(llvm::CallInst& call_inst); |
| 260 | llvm::Value* Expand_InstanceOf(llvm::CallInst& call_inst); |
| 261 | |
| 262 | llvm::Value* Expand_NewInstance(llvm::CallInst& call_inst); |
| 263 | |
| 264 | llvm::Value* Expand_HLInvoke(llvm::CallInst& call_inst); |
| 265 | |
| 266 | llvm::Value* Expand_OptArrayLength(llvm::CallInst& call_inst); |
| 267 | llvm::Value* Expand_NewArray(llvm::CallInst& call_inst); |
| 268 | llvm::Value* Expand_HLFilledNewArray(llvm::CallInst& call_inst); |
| 269 | void Expand_HLFillArrayData(llvm::CallInst& call_inst); |
| 270 | |
| 271 | llvm::Value* EmitAllocNewArray(uint32_t dex_pc, |
| 272 | llvm::Value* array_length_value, |
| 273 | uint32_t type_idx, |
| 274 | bool is_filled_new_array); |
| 275 | |
| 276 | llvm::Value* EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx, |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 277 | art::InvokeType invoke_type, |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 278 | llvm::Value* this_addr, |
| 279 | uint32_t dex_pc, |
| 280 | bool is_fast_path); |
| 281 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 282 | void EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr); |
| 283 | |
| 284 | void EmitUpdateDexPC(uint32_t dex_pc); |
| 285 | |
| 286 | void EmitGuard_DivZeroException(uint32_t dex_pc, |
| 287 | llvm::Value* denominator, |
| 288 | JType op_jty); |
| 289 | |
| 290 | void EmitGuard_NullPointerException(uint32_t dex_pc, |
| 291 | llvm::Value* object); |
| 292 | |
| 293 | void EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc, |
| 294 | llvm::Value* array, |
| 295 | llvm::Value* index); |
| 296 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 297 | llvm::FunctionType* GetFunctionType(uint32_t method_idx, bool is_static); |
| 298 | |
| 299 | llvm::BasicBlock* GetBasicBlock(uint32_t dex_pc); |
| 300 | |
| 301 | llvm::BasicBlock* CreateBasicBlockWithDexPC(uint32_t dex_pc, |
| 302 | const char* postfix); |
| 303 | |
| 304 | int32_t GetTryItemOffset(uint32_t dex_pc); |
| 305 | |
| 306 | llvm::BasicBlock* GetLandingPadBasicBlock(uint32_t dex_pc); |
| 307 | |
| 308 | llvm::BasicBlock* GetUnwindBasicBlock(); |
| 309 | |
| 310 | void EmitGuard_ExceptionLandingPad(uint32_t dex_pc); |
| 311 | |
| 312 | void EmitBranchExceptionLandingPad(uint32_t dex_pc); |
| 313 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 314 | //---------------------------------------------------------------------------- |
| 315 | // Expand Arithmetic Helper Intrinsics |
| 316 | //---------------------------------------------------------------------------- |
| 317 | |
| 318 | llvm::Value* Expand_IntegerShift(llvm::Value* src1_value, |
| 319 | llvm::Value* src2_value, |
| 320 | IntegerShiftKind kind, |
| 321 | JType op_jty); |
| 322 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 323 | public: |
| 324 | static char ID; |
| 325 | |
| 326 | GBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb) |
| 327 | : llvm::FunctionPass(ID), intrinsic_helper_(intrinsic_helper), irb_(irb), |
Logan Chien | e5b8f8b | 2012-08-13 11:45:05 +0800 | [diff] [blame] | 328 | context_(irb.getContext()), rtb_(irb.Runtime()), |
Shih-wei Liao | 6c27968 | 2012-10-16 18:07:43 -0700 | [diff] [blame] | 329 | shadow_frame_(NULL), old_shadow_frame_(NULL), num_shadow_frame_refs_(0), |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 330 | compiler_(NULL), dex_file_(NULL), code_item_(NULL), |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 331 | oat_compilation_unit_(NULL), method_idx_(-1u), func_(NULL), |
| 332 | changed_(false) |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 333 | { } |
| 334 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 335 | GBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb, |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 336 | art::Compiler* compiler, art::OatCompilationUnit* oat_compilation_unit) |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 337 | : llvm::FunctionPass(ID), intrinsic_helper_(intrinsic_helper), irb_(irb), |
| 338 | context_(irb.getContext()), rtb_(irb.Runtime()), |
Shih-wei Liao | 6c27968 | 2012-10-16 18:07:43 -0700 | [diff] [blame] | 339 | shadow_frame_(NULL), old_shadow_frame_(NULL), num_shadow_frame_refs_(0), |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 340 | compiler_(compiler), |
| 341 | dex_file_(oat_compilation_unit->GetDexFile()), |
| 342 | code_item_(oat_compilation_unit->GetCodeItem()), |
| 343 | oat_compilation_unit_(oat_compilation_unit), |
| 344 | method_idx_(oat_compilation_unit->GetDexMethodIndex()), |
| 345 | func_(NULL), changed_(false) |
| 346 | { } |
| 347 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 348 | bool runOnFunction(llvm::Function& func); |
| 349 | |
| 350 | private: |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 351 | void InsertStackOverflowCheck(llvm::Function& func); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 352 | |
| 353 | llvm::Value* ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id, |
| 354 | llvm::CallInst& call_inst); |
| 355 | |
| 356 | }; |
| 357 | |
| 358 | char GBCExpanderPass::ID = 0; |
| 359 | |
| 360 | bool GBCExpanderPass::runOnFunction(llvm::Function& func) { |
TDYa127 | b672d1e | 2012-06-28 21:21:45 -0700 | [diff] [blame] | 361 | // Runtime support or stub |
| 362 | if (func.getName().startswith("art_") || func.getName().startswith("Art")) { |
| 363 | return false; |
| 364 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 365 | |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 366 | // Setup rewrite context |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 367 | shadow_frame_ = NULL; |
| 368 | old_shadow_frame_ = NULL; |
Shih-wei Liao | 6c27968 | 2012-10-16 18:07:43 -0700 | [diff] [blame] | 369 | num_shadow_frame_refs_ = 0; |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 370 | func_ = &func; |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 371 | changed_ = false; // Assume unchanged |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 372 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 373 | #if defined(ART_USE_QUICK_COMPILER) |
| 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); |
| 1035 | #if defined(ART_USE_QUICK_COMPILER) |
| 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 | |
| 1095 | void GBCExpanderPass::Expand_AllocaShadowFrame(llvm::Value* num_entry_value) { |
| 1096 | // Most of the codes refer to MethodCompiler::EmitPrologueAllocShadowFrame and |
| 1097 | // MethodCompiler::EmitPushShadowFrame |
Shih-wei Liao | 6c27968 | 2012-10-16 18:07:43 -0700 | [diff] [blame] | 1098 | num_shadow_frame_refs_ = |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1099 | llvm::cast<llvm::ConstantInt>(num_entry_value)->getZExtValue(); |
| 1100 | |
| 1101 | llvm::StructType* shadow_frame_type = |
Shih-wei Liao | 6c27968 | 2012-10-16 18:07:43 -0700 | [diff] [blame] | 1102 | irb_.getShadowFrameTy(num_shadow_frame_refs_); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1103 | |
| 1104 | shadow_frame_ = irb_.CreateAlloca(shadow_frame_type); |
| 1105 | |
| 1106 | // Alloca a pointer to old shadow frame |
| 1107 | old_shadow_frame_ = |
| 1108 | irb_.CreateAlloca(shadow_frame_type->getElementType(0)->getPointerTo()); |
| 1109 | |
| 1110 | // Zero-initialization of the shadow frame table |
| 1111 | llvm::Value* shadow_frame_table = |
| 1112 | irb_.CreateConstGEP2_32(shadow_frame_, 0, 1); |
| 1113 | llvm::Type* table_type = shadow_frame_type->getElementType(1); |
| 1114 | |
| 1115 | llvm::ConstantAggregateZero* zero_initializer = |
| 1116 | llvm::ConstantAggregateZero::get(table_type); |
| 1117 | |
| 1118 | irb_.CreateStore(zero_initializer, shadow_frame_table, kTBAAShadowFrame); |
| 1119 | |
| 1120 | // Push the shadow frame |
| 1121 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1122 | |
| 1123 | // Push the shadow frame |
| 1124 | llvm::Value* shadow_frame_upcast = |
| 1125 | irb_.CreateConstGEP2_32(shadow_frame_, 0, 0); |
| 1126 | |
| 1127 | llvm::Value* result = rtb_.EmitPushShadowFrame(shadow_frame_upcast, |
| 1128 | method_object_addr, |
Shih-wei Liao | 6c27968 | 2012-10-16 18:07:43 -0700 | [diff] [blame] | 1129 | num_shadow_frame_refs_, |
| 1130 | 0); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1131 | |
| 1132 | irb_.CreateStore(result, old_shadow_frame_, kTBAARegister); |
| 1133 | |
| 1134 | return; |
| 1135 | } |
| 1136 | |
| 1137 | void GBCExpanderPass::Expand_SetShadowFrameEntry(llvm::Value* obj, |
| 1138 | llvm::Value* entry_idx) { |
| 1139 | DCHECK(shadow_frame_ != NULL); |
| 1140 | |
| 1141 | llvm::Value* gep_index[] = { |
| 1142 | irb_.getInt32(0), // No pointer displacement |
| 1143 | irb_.getInt32(1), // SIRT |
| 1144 | entry_idx // Pointer field |
| 1145 | }; |
| 1146 | |
| 1147 | llvm::Value* entry_addr = irb_.CreateGEP(shadow_frame_, gep_index); |
TDYa127 | 347166a | 2012-08-23 12:23:44 -0700 | [diff] [blame] | 1148 | #if defined(ART_USE_QUICK_COMPILER) |
| 1149 | if (obj->getType() != irb_.getJObjectTy()) { |
| 1150 | obj = irb_.getJNull(); |
| 1151 | } |
| 1152 | #endif |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1153 | irb_.CreateStore(obj, entry_addr, kTBAAShadowFrame); |
| 1154 | return; |
| 1155 | } |
| 1156 | |
| 1157 | void GBCExpanderPass::Expand_PopShadowFrame() { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1158 | #if defined(ART_USE_QUICK_COMPILER) |
| 1159 | if (old_shadow_frame_ == NULL) { |
| 1160 | return; |
| 1161 | } |
| 1162 | #endif |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1163 | rtb_.EmitPopShadowFrame(irb_.CreateLoad(old_shadow_frame_, kTBAARegister)); |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | void GBCExpanderPass::Expand_UpdateDexPC(llvm::Value* dex_pc_value) { |
| 1168 | irb_.StoreToObjectOffset(shadow_frame_, |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1169 | art::ShadowFrame::DexPCOffset(), |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1170 | dex_pc_value, |
| 1171 | kTBAAShadowFrame); |
| 1172 | return; |
| 1173 | } |
| 1174 | |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 1175 | void GBCExpanderPass::InsertStackOverflowCheck(llvm::Function& func) { |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1176 | // DexLang generates all alloca instruction in the first basic block of the |
| 1177 | // FUNC and also there's no any alloca instructions after the first non-alloca |
| 1178 | // instruction |
| 1179 | |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 1180 | llvm::BasicBlock* first_basic_block = &func.front(); |
| 1181 | |
| 1182 | // Look for first non-alloca instruction |
| 1183 | llvm::BasicBlock::iterator first_non_alloca = first_basic_block->begin(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1184 | while (llvm::isa<llvm::AllocaInst>(first_non_alloca)) { |
| 1185 | ++first_non_alloca; |
| 1186 | } |
| 1187 | |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 1188 | irb_.SetInsertPoint(first_non_alloca); |
| 1189 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1190 | // Insert stack overflow check codes before first_non_alloca (i.e., after all |
| 1191 | // alloca instructions) |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 1192 | EmitStackOverflowCheck(&*first_non_alloca); |
| 1193 | |
TDYa127 | 890ea89 | 2012-08-22 10:49:42 -0700 | [diff] [blame] | 1194 | #if defined(ART_USE_QUICK_COMPILER) |
| 1195 | irb_.Runtime().EmitTestSuspend(); |
| 1196 | #endif |
| 1197 | |
Logan Chien | 67645d8 | 2012-08-17 09:10:54 +0800 | [diff] [blame] | 1198 | llvm::BasicBlock* next_basic_block = irb_.GetInsertBlock(); |
| 1199 | if (next_basic_block != first_basic_block) { |
| 1200 | // Splice the rest of the instruction to the continuing basic block |
| 1201 | next_basic_block->getInstList().splice( |
| 1202 | irb_.GetInsertPoint(), first_basic_block->getInstList(), |
| 1203 | first_non_alloca, first_basic_block->end()); |
| 1204 | |
| 1205 | // Rewrite the basic block |
| 1206 | RewriteBasicBlock(next_basic_block); |
| 1207 | |
| 1208 | // Update the phi-instructions in the successor basic block |
| 1209 | UpdatePhiInstruction(first_basic_block, irb_.GetInsertBlock()); |
| 1210 | } |
| 1211 | |
| 1212 | // We have changed the basic block |
| 1213 | changed_ = true; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1216 | // ==== High-level intrinsic expander ========================================== |
| 1217 | |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 1218 | llvm::Value* GBCExpanderPass::Expand_FPCompare(llvm::Value* src1_value, |
| 1219 | llvm::Value* src2_value, |
| 1220 | bool gt_bias) { |
| 1221 | llvm::Value* cmp_eq = irb_.CreateFCmpOEQ(src1_value, src2_value); |
| 1222 | llvm::Value* cmp_lt; |
| 1223 | |
| 1224 | if (gt_bias) { |
| 1225 | cmp_lt = irb_.CreateFCmpOLT(src1_value, src2_value); |
| 1226 | } else { |
| 1227 | cmp_lt = irb_.CreateFCmpULT(src1_value, src2_value); |
| 1228 | } |
| 1229 | |
| 1230 | return EmitCompareResultSelection(cmp_eq, cmp_lt); |
| 1231 | } |
| 1232 | |
| 1233 | llvm::Value* GBCExpanderPass::Expand_LongCompare(llvm::Value* src1_value, llvm::Value* src2_value) { |
| 1234 | llvm::Value* cmp_eq = irb_.CreateICmpEQ(src1_value, src2_value); |
| 1235 | llvm::Value* cmp_lt = irb_.CreateICmpSLT(src1_value, src2_value); |
| 1236 | |
| 1237 | return EmitCompareResultSelection(cmp_eq, cmp_lt); |
| 1238 | } |
| 1239 | |
| 1240 | llvm::Value* GBCExpanderPass::EmitCompareResultSelection(llvm::Value* cmp_eq, |
| 1241 | llvm::Value* cmp_lt) { |
| 1242 | |
| 1243 | llvm::Constant* zero = irb_.getJInt(0); |
| 1244 | llvm::Constant* pos1 = irb_.getJInt(1); |
| 1245 | llvm::Constant* neg1 = irb_.getJInt(-1); |
| 1246 | |
| 1247 | llvm::Value* result_lt = irb_.CreateSelect(cmp_lt, neg1, pos1); |
| 1248 | llvm::Value* result_eq = irb_.CreateSelect(cmp_eq, zero, result_lt); |
| 1249 | |
| 1250 | return result_eq; |
| 1251 | } |
| 1252 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 1253 | llvm::Value* GBCExpanderPass::Expand_IntegerShift(llvm::Value* src1_value, |
| 1254 | llvm::Value* src2_value, |
| 1255 | IntegerShiftKind kind, |
| 1256 | JType op_jty) { |
| 1257 | DCHECK(op_jty == kInt || op_jty == kLong); |
| 1258 | |
| 1259 | // Mask and zero-extend RHS properly |
| 1260 | if (op_jty == kInt) { |
| 1261 | src2_value = irb_.CreateAnd(src2_value, 0x1f); |
| 1262 | } else { |
| 1263 | llvm::Value* masked_src2_value = irb_.CreateAnd(src2_value, 0x3f); |
| 1264 | src2_value = irb_.CreateZExt(masked_src2_value, irb_.getJLongTy()); |
| 1265 | } |
| 1266 | |
| 1267 | // Create integer shift llvm instruction |
| 1268 | switch (kind) { |
| 1269 | case kIntegerSHL: |
| 1270 | return irb_.CreateShl(src1_value, src2_value); |
| 1271 | |
| 1272 | case kIntegerSHR: |
| 1273 | return irb_.CreateAShr(src1_value, src2_value); |
| 1274 | |
| 1275 | case kIntegerUSHR: |
| 1276 | return irb_.CreateLShr(src1_value, src2_value); |
| 1277 | |
| 1278 | default: |
| 1279 | LOG(FATAL) << "Unknown integer shift kind: " << kind; |
| 1280 | return NULL; |
| 1281 | } |
| 1282 | } |
| 1283 | |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1284 | llvm::Value* GBCExpanderPass::Expand_HLArrayGet(llvm::CallInst& call_inst, |
| 1285 | JType elem_jty) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1286 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1287 | llvm::Value* array_addr = call_inst.getArgOperand(1); |
| 1288 | llvm::Value* index_value = call_inst.getArgOperand(2); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1289 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1290 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1291 | if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 1292 | EmitGuard_NullPointerException(dex_pc, array_addr); |
| 1293 | } |
| 1294 | if (!(opt_flags & MIR_IGNORE_RANGE_CHECK)) { |
| 1295 | EmitGuard_ArrayIndexOutOfBoundsException(dex_pc, array_addr, index_value); |
| 1296 | } |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1297 | |
| 1298 | llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty); |
| 1299 | |
| 1300 | llvm::Value* array_elem_value = irb_.CreateLoad(array_elem_addr, kTBAAHeapArray, elem_jty); |
| 1301 | |
| 1302 | switch (elem_jty) { |
| 1303 | case kVoid: |
| 1304 | break; |
| 1305 | |
| 1306 | case kBoolean: |
| 1307 | case kChar: |
| 1308 | array_elem_value = irb_.CreateZExt(array_elem_value, irb_.getJType(elem_jty, kReg)); |
| 1309 | break; |
| 1310 | |
| 1311 | case kByte: |
| 1312 | case kShort: |
| 1313 | array_elem_value = irb_.CreateSExt(array_elem_value, irb_.getJType(elem_jty, kReg)); |
| 1314 | break; |
| 1315 | |
| 1316 | case kInt: |
| 1317 | case kLong: |
| 1318 | case kFloat: |
| 1319 | case kDouble: |
| 1320 | case kObject: |
| 1321 | break; |
| 1322 | |
| 1323 | default: |
| 1324 | LOG(FATAL) << "Unknown java type: " << elem_jty; |
| 1325 | } |
| 1326 | |
| 1327 | return array_elem_value; |
| 1328 | } |
| 1329 | |
| 1330 | |
| 1331 | void GBCExpanderPass::Expand_HLArrayPut(llvm::CallInst& call_inst, |
| 1332 | JType elem_jty) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1333 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1334 | llvm::Value* new_value = call_inst.getArgOperand(1); |
| 1335 | llvm::Value* array_addr = call_inst.getArgOperand(2); |
| 1336 | llvm::Value* index_value = call_inst.getArgOperand(3); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1337 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1338 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1339 | if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 1340 | EmitGuard_NullPointerException(dex_pc, array_addr); |
| 1341 | } |
| 1342 | if (!(opt_flags & MIR_IGNORE_RANGE_CHECK)) { |
| 1343 | EmitGuard_ArrayIndexOutOfBoundsException(dex_pc, array_addr, index_value); |
| 1344 | } |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1345 | |
| 1346 | switch (elem_jty) { |
| 1347 | case kVoid: |
| 1348 | break; |
| 1349 | |
| 1350 | case kBoolean: |
| 1351 | case kChar: |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1352 | case kByte: |
| 1353 | case kShort: |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1354 | new_value = irb_.CreateTrunc(new_value, irb_.getJType(elem_jty, kArray)); |
| 1355 | break; |
| 1356 | |
| 1357 | case kInt: |
| 1358 | case kLong: |
| 1359 | case kFloat: |
| 1360 | case kDouble: |
| 1361 | case kObject: |
| 1362 | break; |
| 1363 | |
| 1364 | default: |
| 1365 | LOG(FATAL) << "Unknown java type: " << elem_jty; |
| 1366 | } |
| 1367 | |
| 1368 | llvm::Value* array_elem_addr = EmitArrayGEP(array_addr, index_value, elem_jty); |
| 1369 | |
| 1370 | if (elem_jty == kObject) { // If put an object, check the type, and mark GC card table. |
| 1371 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::CheckPutArrayElement); |
| 1372 | |
| 1373 | irb_.CreateCall2(runtime_func, new_value, array_addr); |
| 1374 | |
| 1375 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1376 | |
| 1377 | EmitMarkGCCard(new_value, array_addr); |
| 1378 | } |
| 1379 | |
| 1380 | irb_.CreateStore(new_value, array_elem_addr, kTBAAHeapArray, elem_jty); |
| 1381 | |
| 1382 | return; |
| 1383 | } |
| 1384 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1385 | llvm::Value* GBCExpanderPass::Expand_HLIGet(llvm::CallInst& call_inst, |
| 1386 | JType field_jty) { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1387 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1388 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
| 1389 | uint32_t field_idx = LV2UInt(call_inst.getArgOperand(2)); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1390 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1391 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1392 | if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 1393 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 1394 | } |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1395 | |
| 1396 | llvm::Value* field_value; |
| 1397 | |
| 1398 | int field_offset; |
| 1399 | bool is_volatile; |
| 1400 | bool is_fast_path = compiler_->ComputeInstanceFieldInfo( |
| 1401 | field_idx, oat_compilation_unit_, field_offset, is_volatile, false); |
| 1402 | |
| 1403 | if (!is_fast_path) { |
| 1404 | llvm::Function* runtime_func; |
| 1405 | |
| 1406 | if (field_jty == kObject) { |
| 1407 | runtime_func = irb_.GetRuntime(runtime_support::GetObjectInstance); |
| 1408 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 1409 | runtime_func = irb_.GetRuntime(runtime_support::Get64Instance); |
| 1410 | } else { |
| 1411 | runtime_func = irb_.GetRuntime(runtime_support::Get32Instance); |
| 1412 | } |
| 1413 | |
| 1414 | llvm::ConstantInt* field_idx_value = irb_.getInt32(field_idx); |
| 1415 | |
| 1416 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1417 | |
| 1418 | EmitUpdateDexPC(dex_pc); |
| 1419 | |
| 1420 | field_value = irb_.CreateCall3(runtime_func, field_idx_value, |
| 1421 | method_object_addr, object_addr); |
| 1422 | |
| 1423 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1424 | |
| 1425 | } else { |
| 1426 | DCHECK_GE(field_offset, 0); |
| 1427 | |
| 1428 | llvm::PointerType* field_type = |
| 1429 | irb_.getJType(field_jty, kField)->getPointerTo(); |
| 1430 | |
| 1431 | llvm::ConstantInt* field_offset_value = irb_.getPtrEquivInt(field_offset); |
| 1432 | |
| 1433 | llvm::Value* field_addr = |
| 1434 | irb_.CreatePtrDisp(object_addr, field_offset_value, field_type); |
| 1435 | |
| 1436 | // TODO: Check is_volatile. We need to generate atomic load instruction |
| 1437 | // when is_volatile is true. |
| 1438 | field_value = irb_.CreateLoad(field_addr, kTBAAHeapInstance, field_jty); |
| 1439 | } |
| 1440 | |
| 1441 | if (field_jty == kFloat || field_jty == kDouble) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1442 | field_value = irb_.CreateBitCast(field_value, irb_.getJType(field_jty, kAccurate)); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | return field_value; |
| 1446 | } |
| 1447 | |
| 1448 | void GBCExpanderPass::Expand_HLIPut(llvm::CallInst& call_inst, |
| 1449 | JType field_jty) { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1450 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1451 | llvm::Value* new_value = call_inst.getArgOperand(1); |
| 1452 | llvm::Value* object_addr = call_inst.getArgOperand(2); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1453 | uint32_t field_idx = LV2UInt(call_inst.getArgOperand(3)); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1454 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1455 | |
| 1456 | if (field_jty == kFloat || field_jty == kDouble) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1457 | new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty, kField)); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1460 | if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 1461 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 1462 | } |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 1463 | |
| 1464 | int field_offset; |
| 1465 | bool is_volatile; |
| 1466 | bool is_fast_path = compiler_->ComputeInstanceFieldInfo( |
| 1467 | field_idx, oat_compilation_unit_, field_offset, is_volatile, true); |
| 1468 | |
| 1469 | if (!is_fast_path) { |
| 1470 | llvm::Function* runtime_func; |
| 1471 | |
| 1472 | if (field_jty == kObject) { |
| 1473 | runtime_func = irb_.GetRuntime(runtime_support::SetObjectInstance); |
| 1474 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 1475 | runtime_func = irb_.GetRuntime(runtime_support::Set64Instance); |
| 1476 | } else { |
| 1477 | runtime_func = irb_.GetRuntime(runtime_support::Set32Instance); |
| 1478 | } |
| 1479 | |
| 1480 | llvm::Value* field_idx_value = irb_.getInt32(field_idx); |
| 1481 | |
| 1482 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1483 | |
| 1484 | EmitUpdateDexPC(dex_pc); |
| 1485 | |
| 1486 | irb_.CreateCall4(runtime_func, field_idx_value, |
| 1487 | method_object_addr, object_addr, new_value); |
| 1488 | |
| 1489 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1490 | |
| 1491 | } else { |
| 1492 | DCHECK_GE(field_offset, 0); |
| 1493 | |
| 1494 | llvm::PointerType* field_type = |
| 1495 | irb_.getJType(field_jty, kField)->getPointerTo(); |
| 1496 | |
| 1497 | llvm::Value* field_offset_value = irb_.getPtrEquivInt(field_offset); |
| 1498 | |
| 1499 | llvm::Value* field_addr = |
| 1500 | irb_.CreatePtrDisp(object_addr, field_offset_value, field_type); |
| 1501 | |
| 1502 | // TODO: Check is_volatile. We need to generate atomic store instruction |
| 1503 | // when is_volatile is true. |
| 1504 | irb_.CreateStore(new_value, field_addr, kTBAAHeapInstance, field_jty); |
| 1505 | |
| 1506 | if (field_jty == kObject) { // If put an object, mark the GC card table. |
| 1507 | EmitMarkGCCard(new_value, object_addr); |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | return; |
| 1512 | } |
| 1513 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1514 | llvm::Value* GBCExpanderPass::EmitLoadConstantClass(uint32_t dex_pc, |
| 1515 | uint32_t type_idx) { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1516 | if (!compiler_->CanAccessTypeWithoutChecks(method_idx_, *dex_file_, type_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1517 | llvm::Value* type_idx_value = irb_.getInt32(type_idx); |
| 1518 | |
| 1519 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1520 | |
| 1521 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 1522 | |
| 1523 | llvm::Function* runtime_func = |
| 1524 | irb_.GetRuntime(runtime_support::InitializeTypeAndVerifyAccess); |
| 1525 | |
| 1526 | EmitUpdateDexPC(dex_pc); |
| 1527 | |
| 1528 | llvm::Value* type_object_addr = |
| 1529 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
| 1530 | |
| 1531 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1532 | |
| 1533 | return type_object_addr; |
| 1534 | |
| 1535 | } else { |
| 1536 | // Try to load the class (type) object from the test cache. |
| 1537 | llvm::Value* type_field_addr = |
| 1538 | EmitLoadDexCacheResolvedTypeFieldAddr(type_idx); |
| 1539 | |
| 1540 | llvm::Value* type_object_addr = irb_.CreateLoad(type_field_addr, kTBAAJRuntime); |
| 1541 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1542 | if (compiler_->CanAssumeTypeIsPresentInDexCache(*dex_file_, type_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1543 | return type_object_addr; |
| 1544 | } |
| 1545 | |
| 1546 | llvm::BasicBlock* block_original = irb_.GetInsertBlock(); |
| 1547 | |
| 1548 | // Test whether class (type) object is in the dex cache or not |
| 1549 | llvm::Value* equal_null = |
| 1550 | irb_.CreateICmpEQ(type_object_addr, irb_.getJNull()); |
| 1551 | |
| 1552 | llvm::BasicBlock* block_cont = |
| 1553 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 1554 | |
| 1555 | llvm::BasicBlock* block_load_class = |
| 1556 | CreateBasicBlockWithDexPC(dex_pc, "load_class"); |
| 1557 | |
| 1558 | irb_.CreateCondBr(equal_null, block_load_class, block_cont, kUnlikely); |
| 1559 | |
| 1560 | // Failback routine to load the class object |
| 1561 | irb_.SetInsertPoint(block_load_class); |
| 1562 | |
| 1563 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeType); |
| 1564 | |
| 1565 | llvm::Constant* type_idx_value = irb_.getInt32(type_idx); |
| 1566 | |
| 1567 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1568 | |
| 1569 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 1570 | |
| 1571 | EmitUpdateDexPC(dex_pc); |
| 1572 | |
| 1573 | llvm::Value* loaded_type_object_addr = |
| 1574 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
| 1575 | |
| 1576 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1577 | |
| 1578 | llvm::BasicBlock* block_after_load_class = irb_.GetInsertBlock(); |
| 1579 | |
| 1580 | irb_.CreateBr(block_cont); |
| 1581 | |
| 1582 | // Now the class object must be loaded |
| 1583 | irb_.SetInsertPoint(block_cont); |
| 1584 | |
| 1585 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 1586 | |
| 1587 | phi->addIncoming(type_object_addr, block_original); |
| 1588 | phi->addIncoming(loaded_type_object_addr, block_after_load_class); |
| 1589 | |
| 1590 | return phi; |
| 1591 | } |
| 1592 | } |
| 1593 | |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1594 | llvm::Value* GBCExpanderPass::EmitLoadStaticStorage(uint32_t dex_pc, |
| 1595 | uint32_t type_idx) { |
| 1596 | llvm::BasicBlock* block_load_static = |
| 1597 | CreateBasicBlockWithDexPC(dex_pc, "load_static"); |
| 1598 | |
| 1599 | llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 1600 | |
| 1601 | // Load static storage from dex cache |
| 1602 | llvm::Value* storage_field_addr = |
| 1603 | EmitLoadDexCacheStaticStorageFieldAddr(type_idx); |
| 1604 | |
| 1605 | llvm::Value* storage_object_addr = irb_.CreateLoad(storage_field_addr, kTBAAJRuntime); |
| 1606 | |
| 1607 | llvm::BasicBlock* block_original = irb_.GetInsertBlock(); |
| 1608 | |
| 1609 | // Test: Is the static storage of this class initialized? |
| 1610 | llvm::Value* equal_null = |
| 1611 | irb_.CreateICmpEQ(storage_object_addr, irb_.getJNull()); |
| 1612 | |
| 1613 | irb_.CreateCondBr(equal_null, block_load_static, block_cont, kUnlikely); |
| 1614 | |
| 1615 | // Failback routine to load the class object |
| 1616 | irb_.SetInsertPoint(block_load_static); |
| 1617 | |
| 1618 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::InitializeStaticStorage); |
| 1619 | |
| 1620 | llvm::Constant* type_idx_value = irb_.getInt32(type_idx); |
| 1621 | |
| 1622 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1623 | |
| 1624 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 1625 | |
| 1626 | EmitUpdateDexPC(dex_pc); |
| 1627 | |
| 1628 | llvm::Value* loaded_storage_object_addr = |
| 1629 | irb_.CreateCall3(runtime_func, type_idx_value, method_object_addr, thread_object_addr); |
| 1630 | |
| 1631 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1632 | |
| 1633 | llvm::BasicBlock* block_after_load_static = irb_.GetInsertBlock(); |
| 1634 | |
| 1635 | irb_.CreateBr(block_cont); |
| 1636 | |
| 1637 | // Now the class object must be loaded |
| 1638 | irb_.SetInsertPoint(block_cont); |
| 1639 | |
| 1640 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 1641 | |
| 1642 | phi->addIncoming(storage_object_addr, block_original); |
| 1643 | phi->addIncoming(loaded_storage_object_addr, block_after_load_static); |
| 1644 | |
| 1645 | return phi; |
| 1646 | } |
| 1647 | |
| 1648 | llvm::Value* GBCExpanderPass::Expand_HLSget(llvm::CallInst& call_inst, |
| 1649 | JType field_jty) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1650 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1651 | uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1652 | |
| 1653 | int field_offset; |
| 1654 | int ssb_index; |
| 1655 | bool is_referrers_class; |
| 1656 | bool is_volatile; |
| 1657 | |
| 1658 | bool is_fast_path = compiler_->ComputeStaticFieldInfo( |
| 1659 | field_idx, oat_compilation_unit_, field_offset, ssb_index, |
| 1660 | is_referrers_class, is_volatile, false); |
| 1661 | |
| 1662 | llvm::Value* static_field_value; |
| 1663 | |
| 1664 | if (!is_fast_path) { |
| 1665 | llvm::Function* runtime_func; |
| 1666 | |
| 1667 | if (field_jty == kObject) { |
| 1668 | runtime_func = irb_.GetRuntime(runtime_support::GetObjectStatic); |
| 1669 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 1670 | runtime_func = irb_.GetRuntime(runtime_support::Get64Static); |
| 1671 | } else { |
| 1672 | runtime_func = irb_.GetRuntime(runtime_support::Get32Static); |
| 1673 | } |
| 1674 | |
| 1675 | llvm::Constant* field_idx_value = irb_.getInt32(field_idx); |
| 1676 | |
| 1677 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1678 | |
| 1679 | EmitUpdateDexPC(dex_pc); |
| 1680 | |
| 1681 | static_field_value = |
| 1682 | irb_.CreateCall2(runtime_func, field_idx_value, method_object_addr); |
| 1683 | |
| 1684 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1685 | |
| 1686 | } else { |
| 1687 | DCHECK_GE(field_offset, 0); |
| 1688 | |
| 1689 | llvm::Value* static_storage_addr = NULL; |
| 1690 | |
| 1691 | if (is_referrers_class) { |
| 1692 | // Fast path, static storage base is this method's class |
| 1693 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1694 | |
| 1695 | static_storage_addr = |
| 1696 | irb_.LoadFromObjectOffset(method_object_addr, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 1697 | art::AbstractMethod::DeclaringClassOffset().Int32Value(), |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1698 | irb_.getJObjectTy(), |
| 1699 | kTBAAConstJObject); |
| 1700 | } else { |
| 1701 | // Medium path, static storage base in a different class which |
| 1702 | // requires checks that the other class is initialized |
| 1703 | DCHECK_GE(ssb_index, 0); |
| 1704 | static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index); |
| 1705 | } |
| 1706 | |
| 1707 | llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset); |
| 1708 | |
| 1709 | llvm::Value* static_field_addr = |
| 1710 | irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value, |
| 1711 | irb_.getJType(field_jty, kField)->getPointerTo()); |
| 1712 | |
| 1713 | // TODO: Check is_volatile. We need to generate atomic load instruction |
| 1714 | // when is_volatile is true. |
| 1715 | static_field_value = irb_.CreateLoad(static_field_addr, kTBAAHeapStatic, field_jty); |
| 1716 | } |
| 1717 | |
| 1718 | if (field_jty == kFloat || field_jty == kDouble) { |
| 1719 | static_field_value = |
| 1720 | irb_.CreateBitCast(static_field_value, irb_.getJType(field_jty, kAccurate)); |
| 1721 | } |
| 1722 | |
| 1723 | return static_field_value; |
| 1724 | } |
| 1725 | |
| 1726 | void GBCExpanderPass::Expand_HLSput(llvm::CallInst& call_inst, |
| 1727 | JType field_jty) { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1728 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1729 | uint32_t field_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1730 | llvm::Value* new_value = call_inst.getArgOperand(1); |
| 1731 | |
| 1732 | if (field_jty == kFloat || field_jty == kDouble) { |
| 1733 | new_value = irb_.CreateBitCast(new_value, irb_.getJType(field_jty, kField)); |
| 1734 | } |
| 1735 | |
| 1736 | int field_offset; |
| 1737 | int ssb_index; |
| 1738 | bool is_referrers_class; |
| 1739 | bool is_volatile; |
| 1740 | |
| 1741 | bool is_fast_path = compiler_->ComputeStaticFieldInfo( |
| 1742 | field_idx, oat_compilation_unit_, field_offset, ssb_index, |
| 1743 | is_referrers_class, is_volatile, true); |
| 1744 | |
| 1745 | if (!is_fast_path) { |
| 1746 | llvm::Function* runtime_func; |
| 1747 | |
| 1748 | if (field_jty == kObject) { |
| 1749 | runtime_func = irb_.GetRuntime(runtime_support::SetObjectStatic); |
| 1750 | } else if (field_jty == kLong || field_jty == kDouble) { |
| 1751 | runtime_func = irb_.GetRuntime(runtime_support::Set64Static); |
| 1752 | } else { |
| 1753 | runtime_func = irb_.GetRuntime(runtime_support::Set32Static); |
| 1754 | } |
| 1755 | |
| 1756 | llvm::Constant* field_idx_value = irb_.getInt32(field_idx); |
| 1757 | |
| 1758 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1759 | |
| 1760 | EmitUpdateDexPC(dex_pc); |
| 1761 | |
| 1762 | irb_.CreateCall3(runtime_func, field_idx_value, |
| 1763 | method_object_addr, new_value); |
| 1764 | |
| 1765 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1766 | |
| 1767 | } else { |
| 1768 | DCHECK_GE(field_offset, 0); |
| 1769 | |
| 1770 | llvm::Value* static_storage_addr = NULL; |
| 1771 | |
| 1772 | if (is_referrers_class) { |
| 1773 | // Fast path, static storage base is this method's class |
| 1774 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1775 | |
| 1776 | static_storage_addr = |
| 1777 | irb_.LoadFromObjectOffset(method_object_addr, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 1778 | art::AbstractMethod::DeclaringClassOffset().Int32Value(), |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 1779 | irb_.getJObjectTy(), |
| 1780 | kTBAAConstJObject); |
| 1781 | } else { |
| 1782 | // Medium path, static storage base in a different class which |
| 1783 | // requires checks that the other class is initialized |
| 1784 | DCHECK_GE(ssb_index, 0); |
| 1785 | static_storage_addr = EmitLoadStaticStorage(dex_pc, ssb_index); |
| 1786 | } |
| 1787 | |
| 1788 | llvm::Value* static_field_offset_value = irb_.getPtrEquivInt(field_offset); |
| 1789 | |
| 1790 | llvm::Value* static_field_addr = |
| 1791 | irb_.CreatePtrDisp(static_storage_addr, static_field_offset_value, |
| 1792 | irb_.getJType(field_jty, kField)->getPointerTo()); |
| 1793 | |
| 1794 | // TODO: Check is_volatile. We need to generate atomic store instruction |
| 1795 | // when is_volatile is true. |
| 1796 | irb_.CreateStore(new_value, static_field_addr, kTBAAHeapStatic, field_jty); |
| 1797 | |
| 1798 | if (field_jty == kObject) { // If put an object, mark the GC card table. |
| 1799 | EmitMarkGCCard(new_value, static_storage_addr); |
| 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | return; |
| 1804 | } |
| 1805 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1806 | llvm::Value* GBCExpanderPass::Expand_ConstString(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1807 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1808 | uint32_t string_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1809 | |
| 1810 | llvm::Value* string_field_addr = EmitLoadDexCacheStringFieldAddr(string_idx); |
| 1811 | |
| 1812 | llvm::Value* string_addr = irb_.CreateLoad(string_field_addr, kTBAAJRuntime); |
| 1813 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1814 | if (!compiler_->CanAssumeStringIsPresentInDexCache(*dex_file_, string_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1815 | llvm::BasicBlock* block_str_exist = |
| 1816 | CreateBasicBlockWithDexPC(dex_pc, "str_exist"); |
| 1817 | |
| 1818 | llvm::BasicBlock* block_str_resolve = |
| 1819 | CreateBasicBlockWithDexPC(dex_pc, "str_resolve"); |
| 1820 | |
| 1821 | llvm::BasicBlock* block_cont = |
| 1822 | CreateBasicBlockWithDexPC(dex_pc, "str_cont"); |
| 1823 | |
| 1824 | // Test: Is the string resolved and in the dex cache? |
| 1825 | llvm::Value* equal_null = irb_.CreateICmpEQ(string_addr, irb_.getJNull()); |
| 1826 | |
| 1827 | irb_.CreateCondBr(equal_null, block_str_resolve, block_str_exist, kUnlikely); |
| 1828 | |
| 1829 | // String is resolved, go to next basic block. |
| 1830 | irb_.SetInsertPoint(block_str_exist); |
| 1831 | irb_.CreateBr(block_cont); |
| 1832 | |
| 1833 | // String is not resolved yet, resolve it now. |
| 1834 | irb_.SetInsertPoint(block_str_resolve); |
| 1835 | |
| 1836 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::ResolveString); |
| 1837 | |
| 1838 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 1839 | |
| 1840 | llvm::Value* string_idx_value = irb_.getInt32(string_idx); |
| 1841 | |
| 1842 | EmitUpdateDexPC(dex_pc); |
| 1843 | |
| 1844 | llvm::Value* result = irb_.CreateCall2(runtime_func, method_object_addr, |
| 1845 | string_idx_value); |
| 1846 | |
| 1847 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1848 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 1849 | irb_.CreateBr(block_cont); |
| 1850 | |
| 1851 | |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1852 | llvm::BasicBlock* block_pre_cont = irb_.GetInsertBlock(); |
| 1853 | |
| 1854 | irb_.SetInsertPoint(block_cont); |
| 1855 | |
| 1856 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJObjectTy(), 2); |
| 1857 | |
| 1858 | phi->addIncoming(string_addr, block_str_exist); |
| 1859 | phi->addIncoming(result, block_pre_cont); |
| 1860 | |
| 1861 | string_addr = phi; |
| 1862 | } |
| 1863 | |
| 1864 | return string_addr; |
| 1865 | } |
| 1866 | |
| 1867 | llvm::Value* GBCExpanderPass::Expand_ConstClass(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1868 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1869 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1870 | |
| 1871 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx); |
| 1872 | |
| 1873 | return type_object_addr; |
| 1874 | } |
| 1875 | |
| 1876 | void GBCExpanderPass::Expand_MonitorEnter(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1877 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1878 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1879 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1880 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1881 | if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 1882 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 1883 | } |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1884 | |
| 1885 | irb_.Runtime().EmitLockObject(object_addr); |
| 1886 | |
| 1887 | return; |
| 1888 | } |
| 1889 | |
| 1890 | void GBCExpanderPass::Expand_MonitorExit(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1891 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1892 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1893 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1894 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1895 | if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 1896 | EmitGuard_NullPointerException(dex_pc, object_addr); |
| 1897 | } |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1898 | |
| 1899 | EmitUpdateDexPC(dex_pc); |
| 1900 | |
| 1901 | irb_.Runtime().EmitUnlockObject(object_addr); |
| 1902 | |
| 1903 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1904 | |
| 1905 | return; |
| 1906 | } |
| 1907 | |
| 1908 | void GBCExpanderPass::Expand_HLCheckCast(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1909 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1910 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1911 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
| 1912 | |
| 1913 | llvm::BasicBlock* block_test_class = |
| 1914 | CreateBasicBlockWithDexPC(dex_pc, "test_class"); |
| 1915 | |
| 1916 | llvm::BasicBlock* block_test_sub_class = |
| 1917 | CreateBasicBlockWithDexPC(dex_pc, "test_sub_class"); |
| 1918 | |
| 1919 | llvm::BasicBlock* block_cont = |
| 1920 | CreateBasicBlockWithDexPC(dex_pc, "checkcast_cont"); |
| 1921 | |
| 1922 | // Test: Is the reference equal to null? Act as no-op when it is null. |
| 1923 | llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull()); |
| 1924 | |
| 1925 | irb_.CreateCondBr(equal_null, |
| 1926 | block_cont, |
| 1927 | block_test_class); |
| 1928 | |
| 1929 | // Test: Is the object instantiated from the given class? |
| 1930 | irb_.SetInsertPoint(block_test_class); |
| 1931 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 1932 | DCHECK_EQ(art::Object::ClassOffset().Int32Value(), 0); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1933 | |
| 1934 | llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy(); |
| 1935 | |
| 1936 | llvm::Value* object_type_field_addr = |
| 1937 | irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo()); |
| 1938 | |
| 1939 | llvm::Value* object_type_object_addr = |
| 1940 | irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject); |
| 1941 | |
| 1942 | llvm::Value* equal_class = |
| 1943 | irb_.CreateICmpEQ(type_object_addr, object_type_object_addr); |
| 1944 | |
| 1945 | irb_.CreateCondBr(equal_class, |
| 1946 | block_cont, |
| 1947 | block_test_sub_class); |
| 1948 | |
| 1949 | // Test: Is the object instantiated from the subclass of the given class? |
| 1950 | irb_.SetInsertPoint(block_test_sub_class); |
| 1951 | |
| 1952 | EmitUpdateDexPC(dex_pc); |
| 1953 | |
| 1954 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::CheckCast), |
| 1955 | type_object_addr, object_type_object_addr); |
| 1956 | |
| 1957 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 1958 | |
| 1959 | irb_.CreateBr(block_cont); |
| 1960 | |
| 1961 | irb_.SetInsertPoint(block_cont); |
| 1962 | |
| 1963 | return; |
| 1964 | } |
| 1965 | |
| 1966 | llvm::Value* GBCExpanderPass::Expand_InstanceOf(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 1967 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 1968 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 1969 | llvm::Value* object_addr = call_inst.getArgOperand(1); |
| 1970 | |
| 1971 | llvm::BasicBlock* block_nullp = |
| 1972 | CreateBasicBlockWithDexPC(dex_pc, "nullp"); |
| 1973 | |
| 1974 | llvm::BasicBlock* block_test_class = |
| 1975 | CreateBasicBlockWithDexPC(dex_pc, "test_class"); |
| 1976 | |
| 1977 | llvm::BasicBlock* block_class_equals = |
| 1978 | CreateBasicBlockWithDexPC(dex_pc, "class_eq"); |
| 1979 | |
| 1980 | llvm::BasicBlock* block_test_sub_class = |
| 1981 | CreateBasicBlockWithDexPC(dex_pc, "test_sub_class"); |
| 1982 | |
| 1983 | llvm::BasicBlock* block_cont = |
| 1984 | CreateBasicBlockWithDexPC(dex_pc, "instance_of_cont"); |
| 1985 | |
| 1986 | // Overview of the following code : |
| 1987 | // We check for null, if so, then false, otherwise check for class == . If so |
| 1988 | // then true, otherwise do callout slowpath. |
| 1989 | // |
| 1990 | // Test: Is the reference equal to null? Set 0 when it is null. |
| 1991 | llvm::Value* equal_null = irb_.CreateICmpEQ(object_addr, irb_.getJNull()); |
| 1992 | |
| 1993 | irb_.CreateCondBr(equal_null, block_nullp, block_test_class); |
| 1994 | |
| 1995 | irb_.SetInsertPoint(block_nullp); |
| 1996 | irb_.CreateBr(block_cont); |
| 1997 | |
| 1998 | // Test: Is the object instantiated from the given class? |
| 1999 | irb_.SetInsertPoint(block_test_class); |
| 2000 | llvm::Value* type_object_addr = EmitLoadConstantClass(dex_pc, type_idx); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2001 | DCHECK_EQ(art::Object::ClassOffset().Int32Value(), 0); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2002 | |
| 2003 | llvm::PointerType* jobject_ptr_ty = irb_.getJObjectTy(); |
| 2004 | |
| 2005 | llvm::Value* object_type_field_addr = |
| 2006 | irb_.CreateBitCast(object_addr, jobject_ptr_ty->getPointerTo()); |
| 2007 | |
| 2008 | llvm::Value* object_type_object_addr = |
| 2009 | irb_.CreateLoad(object_type_field_addr, kTBAAConstJObject); |
| 2010 | |
| 2011 | llvm::Value* equal_class = |
| 2012 | irb_.CreateICmpEQ(type_object_addr, object_type_object_addr); |
| 2013 | |
| 2014 | irb_.CreateCondBr(equal_class, block_class_equals, block_test_sub_class); |
| 2015 | |
| 2016 | irb_.SetInsertPoint(block_class_equals); |
| 2017 | irb_.CreateBr(block_cont); |
| 2018 | |
| 2019 | // Test: Is the object instantiated from the subclass of the given class? |
| 2020 | irb_.SetInsertPoint(block_test_sub_class); |
| 2021 | llvm::Value* result = |
| 2022 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::IsAssignable), |
| 2023 | type_object_addr, object_type_object_addr); |
| 2024 | irb_.CreateBr(block_cont); |
| 2025 | |
| 2026 | irb_.SetInsertPoint(block_cont); |
| 2027 | |
| 2028 | llvm::PHINode* phi = irb_.CreatePHI(irb_.getJIntTy(), 3); |
| 2029 | |
| 2030 | phi->addIncoming(irb_.getJInt(0), block_nullp); |
| 2031 | phi->addIncoming(irb_.getJInt(1), block_class_equals); |
| 2032 | phi->addIncoming(result, block_test_sub_class); |
| 2033 | |
| 2034 | return phi; |
| 2035 | } |
| 2036 | |
| 2037 | llvm::Value* GBCExpanderPass::Expand_NewInstance(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2038 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2039 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 2040 | |
| 2041 | llvm::Function* runtime_func; |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2042 | if (compiler_->CanAccessInstantiableTypeWithoutChecks(method_idx_, *dex_file_, type_idx)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2043 | runtime_func = irb_.GetRuntime(runtime_support::AllocObject); |
| 2044 | } else { |
| 2045 | runtime_func = irb_.GetRuntime(runtime_support::AllocObjectWithAccessCheck); |
| 2046 | } |
| 2047 | |
| 2048 | llvm::Constant* type_index_value = irb_.getInt32(type_idx); |
| 2049 | |
| 2050 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2051 | |
| 2052 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 2053 | |
| 2054 | EmitUpdateDexPC(dex_pc); |
| 2055 | |
| 2056 | llvm::Value* object_addr = |
| 2057 | irb_.CreateCall3(runtime_func, type_index_value, method_object_addr, thread_object_addr); |
| 2058 | |
| 2059 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2060 | |
| 2061 | return object_addr; |
| 2062 | } |
| 2063 | |
| 2064 | llvm::Value* GBCExpanderPass::Expand_HLInvoke(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2065 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2066 | art::InvokeType invoke_type = static_cast<art::InvokeType>(LV2UInt(call_inst.getArgOperand(0))); |
| 2067 | bool is_static = (invoke_type == art::kStatic); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2068 | uint32_t callee_method_idx = LV2UInt(call_inst.getArgOperand(1)); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2069 | int opt_flags = LV2UInt(call_inst.getArgOperand(2)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2070 | |
| 2071 | // Compute invoke related information for compiler decision |
| 2072 | int vtable_idx = -1; |
| 2073 | uintptr_t direct_code = 0; |
| 2074 | uintptr_t direct_method = 0; |
| 2075 | bool is_fast_path = compiler_-> |
| 2076 | ComputeInvokeInfo(callee_method_idx, oat_compilation_unit_, |
| 2077 | invoke_type, vtable_idx, direct_code, direct_method); |
| 2078 | |
| 2079 | // Load *this* actual parameter |
| 2080 | llvm::Value* this_addr = NULL; |
| 2081 | |
| 2082 | if (!is_static) { |
| 2083 | // Test: Is *this* parameter equal to null? |
| 2084 | this_addr = call_inst.getArgOperand(3); |
| 2085 | } |
| 2086 | |
| 2087 | // Load the method object |
| 2088 | llvm::Value* callee_method_object_addr = NULL; |
| 2089 | |
| 2090 | if (!is_fast_path) { |
| 2091 | callee_method_object_addr = |
| 2092 | EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, invoke_type, |
| 2093 | this_addr, dex_pc, is_fast_path); |
| 2094 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2095 | if (!is_static && !(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2096 | EmitGuard_NullPointerException(dex_pc, this_addr); |
| 2097 | } |
| 2098 | } else { |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2099 | if (!is_static && !(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2100 | EmitGuard_NullPointerException(dex_pc, this_addr); |
| 2101 | } |
| 2102 | |
| 2103 | switch (invoke_type) { |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2104 | case art::kStatic: |
| 2105 | case art::kDirect: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2106 | if (direct_method != 0u && |
| 2107 | direct_method != static_cast<uintptr_t>(-1)) { |
| 2108 | callee_method_object_addr = |
| 2109 | irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_method), |
| 2110 | irb_.getJObjectTy()); |
| 2111 | } else { |
| 2112 | callee_method_object_addr = |
| 2113 | EmitLoadSDCalleeMethodObjectAddr(callee_method_idx); |
| 2114 | } |
| 2115 | break; |
| 2116 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2117 | case art::kVirtual: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2118 | DCHECK(vtable_idx != -1); |
| 2119 | callee_method_object_addr = |
| 2120 | EmitLoadVirtualCalleeMethodObjectAddr(vtable_idx, this_addr); |
| 2121 | break; |
| 2122 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2123 | case art::kSuper: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2124 | LOG(FATAL) << "invoke-super should be promoted to invoke-direct in " |
| 2125 | "the fast path."; |
| 2126 | break; |
| 2127 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2128 | case art::kInterface: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2129 | callee_method_object_addr = |
| 2130 | EmitCallRuntimeForCalleeMethodObjectAddr(callee_method_idx, |
| 2131 | invoke_type, this_addr, |
| 2132 | dex_pc, is_fast_path); |
| 2133 | break; |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | // Load the actual parameter |
| 2138 | std::vector<llvm::Value*> args; |
| 2139 | |
| 2140 | args.push_back(callee_method_object_addr); // method object for callee |
| 2141 | |
| 2142 | for (uint32_t i = 3; i < call_inst.getNumArgOperands(); ++i) { |
| 2143 | args.push_back(call_inst.getArgOperand(i)); |
| 2144 | } |
| 2145 | |
| 2146 | llvm::Value* code_addr; |
| 2147 | if (direct_code != 0u && |
| 2148 | direct_code != static_cast<uintptr_t>(-1)) { |
| 2149 | code_addr = |
| 2150 | irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_code), |
| 2151 | GetFunctionType(callee_method_idx, is_static)->getPointerTo()); |
| 2152 | } else { |
| 2153 | code_addr = |
| 2154 | irb_.LoadFromObjectOffset(callee_method_object_addr, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 2155 | art::AbstractMethod::GetCodeOffset().Int32Value(), |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2156 | GetFunctionType(callee_method_idx, is_static)->getPointerTo(), |
| 2157 | kTBAAJRuntime); |
| 2158 | } |
| 2159 | |
| 2160 | // Invoke callee |
| 2161 | EmitUpdateDexPC(dex_pc); |
| 2162 | llvm::Value* retval = irb_.CreateCall(code_addr, args); |
| 2163 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2164 | |
| 2165 | return retval; |
| 2166 | } |
| 2167 | |
| 2168 | llvm::Value* GBCExpanderPass::Expand_OptArrayLength(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2169 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2170 | // Get the array object address |
| 2171 | llvm::Value* array_addr = call_inst.getArgOperand(1); |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2172 | int opt_flags = LV2UInt(call_inst.getArgOperand(0)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2173 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2174 | if (!(opt_flags & MIR_IGNORE_NULL_CHECK)) { |
| 2175 | EmitGuard_NullPointerException(dex_pc, array_addr); |
| 2176 | } |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2177 | |
| 2178 | // Get the array length and store it to the register |
| 2179 | return EmitLoadArrayLength(array_addr); |
| 2180 | } |
| 2181 | |
| 2182 | llvm::Value* GBCExpanderPass::Expand_NewArray(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2183 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2184 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(0)); |
| 2185 | llvm::Value* length = call_inst.getArgOperand(1); |
| 2186 | |
| 2187 | return EmitAllocNewArray(dex_pc, length, type_idx, false); |
| 2188 | } |
| 2189 | |
| 2190 | llvm::Value* GBCExpanderPass::Expand_HLFilledNewArray(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2191 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2192 | uint32_t type_idx = LV2UInt(call_inst.getArgOperand(1)); |
| 2193 | uint32_t length = call_inst.getNumArgOperands() - 3; |
| 2194 | |
| 2195 | llvm::Value* object_addr = |
| 2196 | EmitAllocNewArray(dex_pc, irb_.getInt32(length), type_idx, true); |
| 2197 | |
| 2198 | if (length > 0) { |
| 2199 | // Check for the element type |
| 2200 | uint32_t type_desc_len = 0; |
| 2201 | const char* type_desc = |
| 2202 | dex_file_->StringByTypeIdx(type_idx, &type_desc_len); |
| 2203 | |
| 2204 | DCHECK_GE(type_desc_len, 2u); // should be guaranteed by verifier |
| 2205 | DCHECK_EQ(type_desc[0], '['); // should be guaranteed by verifier |
| 2206 | bool is_elem_int_ty = (type_desc[1] == 'I'); |
| 2207 | |
| 2208 | uint32_t alignment; |
| 2209 | llvm::Constant* elem_size; |
| 2210 | llvm::PointerType* field_type; |
| 2211 | |
| 2212 | // NOTE: Currently filled-new-array only supports 'L', '[', and 'I' |
| 2213 | // as the element, thus we are only checking 2 cases: primitive int and |
| 2214 | // non-primitive type. |
| 2215 | if (is_elem_int_ty) { |
| 2216 | alignment = sizeof(int32_t); |
| 2217 | elem_size = irb_.getPtrEquivInt(sizeof(int32_t)); |
| 2218 | field_type = irb_.getJIntTy()->getPointerTo(); |
| 2219 | } else { |
| 2220 | alignment = irb_.getSizeOfPtrEquivInt(); |
| 2221 | elem_size = irb_.getSizeOfPtrEquivIntValue(); |
| 2222 | field_type = irb_.getJObjectTy()->getPointerTo(); |
| 2223 | } |
| 2224 | |
| 2225 | llvm::Value* data_field_offset = |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2226 | irb_.getPtrEquivInt(art::Array::DataOffset(alignment).Int32Value()); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2227 | |
| 2228 | llvm::Value* data_field_addr = |
| 2229 | irb_.CreatePtrDisp(object_addr, data_field_offset, field_type); |
| 2230 | |
| 2231 | // TODO: Tune this code. Currently we are generating one instruction for |
| 2232 | // one element which may be very space consuming. Maybe changing to use |
| 2233 | // memcpy may help; however, since we can't guarantee that the alloca of |
| 2234 | // dalvik register are continuous, we can't perform such optimization yet. |
| 2235 | for (uint32_t i = 0; i < length; ++i) { |
| 2236 | llvm::Value* reg_value = call_inst.getArgOperand(i+3); |
| 2237 | |
| 2238 | irb_.CreateStore(reg_value, data_field_addr, kTBAAHeapArray); |
| 2239 | |
| 2240 | data_field_addr = |
| 2241 | irb_.CreatePtrDisp(data_field_addr, elem_size, field_type); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | return object_addr; |
| 2246 | } |
| 2247 | |
| 2248 | void GBCExpanderPass::Expand_HLFillArrayData(llvm::CallInst& call_inst) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2249 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2250 | int32_t payload_offset = static_cast<int32_t>(dex_pc) + |
| 2251 | LV2SInt(call_inst.getArgOperand(0)); |
| 2252 | llvm::Value* array_addr = call_inst.getArgOperand(1); |
| 2253 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2254 | const art::Instruction::ArrayDataPayload* payload = |
| 2255 | reinterpret_cast<const art::Instruction::ArrayDataPayload*>( |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2256 | code_item_->insns_ + payload_offset); |
| 2257 | |
| 2258 | if (payload->element_count == 0) { |
| 2259 | // When the number of the elements in the payload is zero, we don't have |
| 2260 | // to copy any numbers. However, we should check whether the array object |
| 2261 | // address is equal to null or not. |
| 2262 | EmitGuard_NullPointerException(dex_pc, array_addr); |
| 2263 | } else { |
| 2264 | // To save the code size, we are going to call the runtime function to |
| 2265 | // copy the content from DexFile. |
| 2266 | |
| 2267 | // NOTE: We will check for the NullPointerException in the runtime. |
| 2268 | |
| 2269 | llvm::Function* runtime_func = irb_.GetRuntime(runtime_support::FillArrayData); |
| 2270 | |
| 2271 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2272 | |
| 2273 | EmitUpdateDexPC(dex_pc); |
| 2274 | |
| 2275 | irb_.CreateCall4(runtime_func, |
| 2276 | method_object_addr, irb_.getInt32(dex_pc), |
| 2277 | array_addr, irb_.getInt32(payload_offset)); |
| 2278 | |
| 2279 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2280 | } |
| 2281 | |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | llvm::Value* GBCExpanderPass::EmitAllocNewArray(uint32_t dex_pc, |
| 2286 | llvm::Value* array_length_value, |
| 2287 | uint32_t type_idx, |
| 2288 | bool is_filled_new_array) { |
| 2289 | llvm::Function* runtime_func; |
| 2290 | |
| 2291 | bool skip_access_check = |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2292 | compiler_->CanAccessTypeWithoutChecks(method_idx_, *dex_file_, type_idx); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2293 | |
| 2294 | |
| 2295 | if (is_filled_new_array) { |
| 2296 | runtime_func = skip_access_check ? |
| 2297 | irb_.GetRuntime(runtime_support::CheckAndAllocArray) : |
| 2298 | irb_.GetRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck); |
| 2299 | } else { |
| 2300 | runtime_func = skip_access_check ? |
| 2301 | irb_.GetRuntime(runtime_support::AllocArray) : |
| 2302 | irb_.GetRuntime(runtime_support::AllocArrayWithAccessCheck); |
| 2303 | } |
| 2304 | |
| 2305 | llvm::Constant* type_index_value = irb_.getInt32(type_idx); |
| 2306 | |
| 2307 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2308 | |
| 2309 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 2310 | |
| 2311 | EmitUpdateDexPC(dex_pc); |
| 2312 | |
| 2313 | llvm::Value* object_addr = |
| 2314 | irb_.CreateCall4(runtime_func, type_index_value, method_object_addr, |
| 2315 | array_length_value, thread_object_addr); |
| 2316 | |
| 2317 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2318 | |
| 2319 | return object_addr; |
| 2320 | } |
| 2321 | |
| 2322 | llvm::Value* GBCExpanderPass:: |
| 2323 | EmitCallRuntimeForCalleeMethodObjectAddr(uint32_t callee_method_idx, |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2324 | art::InvokeType invoke_type, |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2325 | llvm::Value* this_addr, |
| 2326 | uint32_t dex_pc, |
| 2327 | bool is_fast_path) { |
| 2328 | |
| 2329 | llvm::Function* runtime_func = NULL; |
| 2330 | |
| 2331 | switch (invoke_type) { |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2332 | case art::kStatic: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2333 | runtime_func = irb_.GetRuntime(runtime_support::FindStaticMethodWithAccessCheck); |
| 2334 | break; |
| 2335 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2336 | case art::kDirect: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2337 | runtime_func = irb_.GetRuntime(runtime_support::FindDirectMethodWithAccessCheck); |
| 2338 | break; |
| 2339 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2340 | case art::kVirtual: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2341 | runtime_func = irb_.GetRuntime(runtime_support::FindVirtualMethodWithAccessCheck); |
| 2342 | break; |
| 2343 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2344 | case art::kSuper: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2345 | runtime_func = irb_.GetRuntime(runtime_support::FindSuperMethodWithAccessCheck); |
| 2346 | break; |
| 2347 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2348 | case art::kInterface: |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2349 | if (is_fast_path) { |
| 2350 | runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethod); |
| 2351 | } else { |
| 2352 | runtime_func = irb_.GetRuntime(runtime_support::FindInterfaceMethodWithAccessCheck); |
| 2353 | } |
| 2354 | break; |
| 2355 | } |
| 2356 | |
| 2357 | llvm::Value* callee_method_idx_value = irb_.getInt32(callee_method_idx); |
| 2358 | |
| 2359 | if (this_addr == NULL) { |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2360 | DCHECK_EQ(invoke_type, art::kStatic); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2361 | this_addr = irb_.getJNull(); |
| 2362 | } |
| 2363 | |
| 2364 | llvm::Value* caller_method_object_addr = EmitLoadMethodObjectAddr(); |
| 2365 | |
| 2366 | llvm::Value* thread_object_addr = irb_.Runtime().EmitGetCurrentThread(); |
| 2367 | |
| 2368 | EmitUpdateDexPC(dex_pc); |
| 2369 | |
| 2370 | llvm::Value* callee_method_object_addr = |
| 2371 | irb_.CreateCall4(runtime_func, |
| 2372 | callee_method_idx_value, |
| 2373 | this_addr, |
| 2374 | caller_method_object_addr, |
| 2375 | thread_object_addr); |
| 2376 | |
| 2377 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2378 | |
| 2379 | return callee_method_object_addr; |
| 2380 | } |
| 2381 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2382 | void GBCExpanderPass::EmitMarkGCCard(llvm::Value* value, llvm::Value* target_addr) { |
| 2383 | // Using runtime support, let the target can override by InlineAssembly. |
| 2384 | irb_.Runtime().EmitMarkGCCard(value, target_addr); |
| 2385 | } |
| 2386 | |
| 2387 | void GBCExpanderPass::EmitUpdateDexPC(uint32_t dex_pc) { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2388 | #if defined(ART_USE_QUICK_COMPILER) |
| 2389 | if (shadow_frame_ == NULL) { |
| 2390 | return; |
| 2391 | } |
| 2392 | #endif |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2393 | irb_.StoreToObjectOffset(shadow_frame_, |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2394 | art::ShadowFrame::DexPCOffset(), |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2395 | irb_.getInt32(dex_pc), |
| 2396 | kTBAAShadowFrame); |
| 2397 | } |
| 2398 | |
| 2399 | void GBCExpanderPass::EmitGuard_DivZeroException(uint32_t dex_pc, |
| 2400 | llvm::Value* denominator, |
| 2401 | JType op_jty) { |
| 2402 | DCHECK(op_jty == kInt || op_jty == kLong) << op_jty; |
| 2403 | |
| 2404 | llvm::Constant* zero = irb_.getJZero(op_jty); |
| 2405 | |
| 2406 | llvm::Value* equal_zero = irb_.CreateICmpEQ(denominator, zero); |
| 2407 | |
| 2408 | llvm::BasicBlock* block_exception = CreateBasicBlockWithDexPC(dex_pc, "div0"); |
| 2409 | |
| 2410 | llvm::BasicBlock* block_continue = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2411 | |
| 2412 | irb_.CreateCondBr(equal_zero, block_exception, block_continue, kUnlikely); |
| 2413 | |
| 2414 | irb_.SetInsertPoint(block_exception); |
| 2415 | EmitUpdateDexPC(dex_pc); |
| 2416 | irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowDivZeroException)); |
| 2417 | EmitBranchExceptionLandingPad(dex_pc); |
| 2418 | |
| 2419 | irb_.SetInsertPoint(block_continue); |
| 2420 | } |
| 2421 | |
| 2422 | void GBCExpanderPass::EmitGuard_NullPointerException(uint32_t dex_pc, |
| 2423 | llvm::Value* object) { |
| 2424 | llvm::Value* equal_null = irb_.CreateICmpEQ(object, irb_.getJNull()); |
| 2425 | |
| 2426 | llvm::BasicBlock* block_exception = |
| 2427 | CreateBasicBlockWithDexPC(dex_pc, "nullp"); |
| 2428 | |
| 2429 | llvm::BasicBlock* block_continue = |
| 2430 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2431 | |
| 2432 | irb_.CreateCondBr(equal_null, block_exception, block_continue, kUnlikely); |
| 2433 | |
| 2434 | irb_.SetInsertPoint(block_exception); |
| 2435 | EmitUpdateDexPC(dex_pc); |
| 2436 | irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowNullPointerException), |
| 2437 | irb_.getInt32(dex_pc)); |
| 2438 | EmitBranchExceptionLandingPad(dex_pc); |
| 2439 | |
| 2440 | irb_.SetInsertPoint(block_continue); |
| 2441 | } |
| 2442 | |
| 2443 | void |
| 2444 | GBCExpanderPass::EmitGuard_ArrayIndexOutOfBoundsException(uint32_t dex_pc, |
| 2445 | llvm::Value* array, |
| 2446 | llvm::Value* index) { |
| 2447 | llvm::Value* array_len = EmitLoadArrayLength(array); |
| 2448 | |
| 2449 | llvm::Value* cmp = irb_.CreateICmpUGE(index, array_len); |
| 2450 | |
| 2451 | llvm::BasicBlock* block_exception = |
| 2452 | CreateBasicBlockWithDexPC(dex_pc, "overflow"); |
| 2453 | |
| 2454 | llvm::BasicBlock* block_continue = |
| 2455 | CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2456 | |
| 2457 | irb_.CreateCondBr(cmp, block_exception, block_continue, kUnlikely); |
| 2458 | |
| 2459 | irb_.SetInsertPoint(block_exception); |
| 2460 | |
| 2461 | EmitUpdateDexPC(dex_pc); |
| 2462 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::ThrowIndexOutOfBounds), index, array_len); |
| 2463 | EmitBranchExceptionLandingPad(dex_pc); |
| 2464 | |
| 2465 | irb_.SetInsertPoint(block_continue); |
| 2466 | } |
| 2467 | |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2468 | llvm::FunctionType* GBCExpanderPass::GetFunctionType(uint32_t method_idx, |
| 2469 | bool is_static) { |
| 2470 | // Get method signature |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2471 | art::DexFile::MethodId const& method_id = dex_file_->GetMethodId(method_idx); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2472 | |
| 2473 | uint32_t shorty_size; |
| 2474 | const char* shorty = dex_file_->GetMethodShorty(method_id, &shorty_size); |
| 2475 | CHECK_GE(shorty_size, 1u); |
| 2476 | |
| 2477 | // Get return type |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2478 | |
| 2479 | char ret_shorty = shorty[0]; |
| 2480 | #if defined(ART_USE_QUICK_COMPILER) |
Shih-wei Liao | b259652 | 2012-09-14 16:36:11 -0700 | [diff] [blame] | 2481 | ret_shorty = art::remapShorty(ret_shorty); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2482 | #endif |
| 2483 | llvm::Type* ret_type = irb_.getJType(ret_shorty, kAccurate); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2484 | |
| 2485 | // Get argument type |
| 2486 | std::vector<llvm::Type*> args_type; |
| 2487 | |
| 2488 | args_type.push_back(irb_.getJObjectTy()); // method object pointer |
| 2489 | |
| 2490 | if (!is_static) { |
| 2491 | args_type.push_back(irb_.getJType('L', kAccurate)); // "this" object pointer |
| 2492 | } |
| 2493 | |
| 2494 | for (uint32_t i = 1; i < shorty_size; ++i) { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2495 | #if defined(ART_USE_QUICK_COMPILER) |
Shih-wei Liao | b259652 | 2012-09-14 16:36:11 -0700 | [diff] [blame] | 2496 | char shorty_type = art::remapShorty(shorty[i]); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2497 | args_type.push_back(irb_.getJType(shorty_type, kAccurate)); |
| 2498 | #else |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2499 | args_type.push_back(irb_.getJType(shorty[i], kAccurate)); |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2500 | #endif |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | return llvm::FunctionType::get(ret_type, args_type, false); |
| 2504 | } |
| 2505 | |
| 2506 | |
| 2507 | llvm::BasicBlock* GBCExpanderPass:: |
| 2508 | CreateBasicBlockWithDexPC(uint32_t dex_pc, const char* postfix) { |
| 2509 | std::string name; |
| 2510 | |
| 2511 | #if !defined(NDEBUG) |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2512 | art::StringAppendF(&name, "B%04x.%s", dex_pc, postfix); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2513 | #endif |
| 2514 | |
| 2515 | return llvm::BasicBlock::Create(context_, name, func_); |
| 2516 | } |
| 2517 | |
| 2518 | llvm::BasicBlock* GBCExpanderPass::GetBasicBlock(uint32_t dex_pc) { |
| 2519 | DCHECK(dex_pc < code_item_->insns_size_in_code_units_); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2520 | CHECK(basic_blocks_[dex_pc] != NULL); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2521 | return basic_blocks_[dex_pc]; |
| 2522 | } |
| 2523 | |
| 2524 | int32_t GBCExpanderPass::GetTryItemOffset(uint32_t dex_pc) { |
| 2525 | int32_t min = 0; |
| 2526 | int32_t max = code_item_->tries_size_ - 1; |
| 2527 | |
| 2528 | while (min <= max) { |
| 2529 | int32_t mid = min + (max - min) / 2; |
| 2530 | |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2531 | const art::DexFile::TryItem* ti = art::DexFile::GetTryItems(*code_item_, mid); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2532 | uint32_t start = ti->start_addr_; |
| 2533 | uint32_t end = start + ti->insn_count_; |
| 2534 | |
| 2535 | if (dex_pc < start) { |
| 2536 | max = mid - 1; |
| 2537 | } else if (dex_pc >= end) { |
| 2538 | min = mid + 1; |
| 2539 | } else { |
| 2540 | return mid; // found |
| 2541 | } |
| 2542 | } |
| 2543 | |
| 2544 | return -1; // not found |
| 2545 | } |
| 2546 | |
| 2547 | llvm::BasicBlock* GBCExpanderPass::GetLandingPadBasicBlock(uint32_t dex_pc) { |
| 2548 | // Find the try item for this address in this method |
| 2549 | int32_t ti_offset = GetTryItemOffset(dex_pc); |
| 2550 | |
| 2551 | if (ti_offset == -1) { |
| 2552 | return NULL; // No landing pad is available for this address. |
| 2553 | } |
| 2554 | |
| 2555 | // Check for the existing landing pad basic block |
| 2556 | DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset)); |
| 2557 | llvm::BasicBlock* block_lpad = basic_block_landing_pads_[ti_offset]; |
| 2558 | |
| 2559 | if (block_lpad) { |
| 2560 | // We have generated landing pad for this try item already. Return the |
| 2561 | // same basic block. |
| 2562 | return block_lpad; |
| 2563 | } |
| 2564 | |
| 2565 | // Get try item from code item |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2566 | const art::DexFile::TryItem* ti = art::DexFile::GetTryItems(*code_item_, ti_offset); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2567 | |
| 2568 | std::string lpadname; |
| 2569 | |
| 2570 | #if !defined(NDEBUG) |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2571 | 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] | 2572 | #endif |
| 2573 | |
| 2574 | // Create landing pad basic block |
| 2575 | block_lpad = llvm::BasicBlock::Create(context_, lpadname, func_); |
| 2576 | |
| 2577 | // Change IRBuilder insert point |
| 2578 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
| 2579 | irb_.SetInsertPoint(block_lpad); |
| 2580 | |
| 2581 | // Find catch block with matching type |
| 2582 | llvm::Value* method_object_addr = EmitLoadMethodObjectAddr(); |
| 2583 | |
| 2584 | llvm::Value* ti_offset_value = irb_.getInt32(ti_offset); |
| 2585 | |
| 2586 | llvm::Value* catch_handler_index_value = |
| 2587 | irb_.CreateCall2(irb_.GetRuntime(runtime_support::FindCatchBlock), |
| 2588 | method_object_addr, ti_offset_value); |
| 2589 | |
| 2590 | // Switch instruction (Go to unwind basic block by default) |
| 2591 | llvm::SwitchInst* sw = |
| 2592 | irb_.CreateSwitch(catch_handler_index_value, GetUnwindBasicBlock()); |
| 2593 | |
| 2594 | // Cases with matched catch block |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 2595 | art::CatchHandlerIterator iter(*code_item_, ti->start_addr_); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2596 | |
| 2597 | for (uint32_t c = 0; iter.HasNext(); iter.Next(), ++c) { |
| 2598 | sw->addCase(irb_.getInt32(c), GetBasicBlock(iter.GetHandlerAddress())); |
| 2599 | } |
| 2600 | |
| 2601 | // Restore the orignal insert point for IRBuilder |
| 2602 | irb_.restoreIP(irb_ip_original); |
| 2603 | |
| 2604 | // Cache this landing pad |
| 2605 | DCHECK_GT(basic_block_landing_pads_.size(), static_cast<size_t>(ti_offset)); |
| 2606 | basic_block_landing_pads_[ti_offset] = block_lpad; |
| 2607 | |
| 2608 | return block_lpad; |
| 2609 | } |
| 2610 | |
| 2611 | llvm::BasicBlock* GBCExpanderPass::GetUnwindBasicBlock() { |
| 2612 | // Check the existing unwinding baisc block block |
| 2613 | if (basic_block_unwind_ != NULL) { |
| 2614 | return basic_block_unwind_; |
| 2615 | } |
| 2616 | |
| 2617 | // Create new basic block for unwinding |
| 2618 | basic_block_unwind_ = |
| 2619 | llvm::BasicBlock::Create(context_, "exception_unwind", func_); |
| 2620 | |
| 2621 | // Change IRBuilder insert point |
| 2622 | llvm::IRBuilderBase::InsertPoint irb_ip_original = irb_.saveIP(); |
| 2623 | irb_.SetInsertPoint(basic_block_unwind_); |
| 2624 | |
| 2625 | // Pop the shadow frame |
| 2626 | Expand_PopShadowFrame(); |
| 2627 | |
| 2628 | // Emit the code to return default value (zero) for the given return type. |
| 2629 | char ret_shorty = oat_compilation_unit_->GetShorty()[0]; |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2630 | #if defined(ART_USE_QUICK_COMPILER) |
Shih-wei Liao | b259652 | 2012-09-14 16:36:11 -0700 | [diff] [blame] | 2631 | ret_shorty = art::remapShorty(ret_shorty); |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 2632 | #endif |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2633 | if (ret_shorty == 'V') { |
| 2634 | irb_.CreateRetVoid(); |
| 2635 | } else { |
| 2636 | irb_.CreateRet(irb_.getJZero(ret_shorty)); |
| 2637 | } |
| 2638 | |
| 2639 | // Restore the orignal insert point for IRBuilder |
| 2640 | irb_.restoreIP(irb_ip_original); |
| 2641 | |
| 2642 | return basic_block_unwind_; |
| 2643 | } |
| 2644 | |
| 2645 | void GBCExpanderPass::EmitBranchExceptionLandingPad(uint32_t dex_pc) { |
| 2646 | if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 2647 | landing_pad_phi_mapping_[lpad].push_back(std::make_pair(current_bb_->getUniquePredecessor(), |
TDYa127 | aa55887 | 2012-08-16 05:11:07 -0700 | [diff] [blame] | 2648 | irb_.GetInsertBlock())); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2649 | irb_.CreateBr(lpad); |
| 2650 | } else { |
| 2651 | irb_.CreateBr(GetUnwindBasicBlock()); |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | void GBCExpanderPass::EmitGuard_ExceptionLandingPad(uint32_t dex_pc) { |
| 2656 | llvm::Value* exception_pending = irb_.Runtime().EmitIsExceptionPending(); |
| 2657 | |
| 2658 | llvm::BasicBlock* block_cont = CreateBasicBlockWithDexPC(dex_pc, "cont"); |
| 2659 | |
| 2660 | if (llvm::BasicBlock* lpad = GetLandingPadBasicBlock(dex_pc)) { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 2661 | landing_pad_phi_mapping_[lpad].push_back(std::make_pair(current_bb_->getUniquePredecessor(), |
TDYa127 | aa55887 | 2012-08-16 05:11:07 -0700 | [diff] [blame] | 2662 | irb_.GetInsertBlock())); |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 2663 | irb_.CreateCondBr(exception_pending, lpad, block_cont, kUnlikely); |
| 2664 | } else { |
| 2665 | irb_.CreateCondBr(exception_pending, GetUnwindBasicBlock(), block_cont, kUnlikely); |
| 2666 | } |
| 2667 | |
| 2668 | irb_.SetInsertPoint(block_cont); |
| 2669 | } |
| 2670 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2671 | llvm::Value* |
| 2672 | GBCExpanderPass::ExpandIntrinsic(IntrinsicHelper::IntrinsicId intr_id, |
| 2673 | llvm::CallInst& call_inst) { |
| 2674 | switch (intr_id) { |
| 2675 | //==- Thread -----------------------------------------------------------==// |
| 2676 | case IntrinsicHelper::GetCurrentThread: { |
TDYa127 | b672d1e | 2012-06-28 21:21:45 -0700 | [diff] [blame] | 2677 | return irb_.Runtime().EmitGetCurrentThread(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2678 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2679 | case IntrinsicHelper::CheckSuspend: { |
TDYa127 | 890ea89 | 2012-08-22 10:49:42 -0700 | [diff] [blame] | 2680 | // We will add suspend by ourselves. |
| 2681 | return NULL; |
| 2682 | } |
| 2683 | case IntrinsicHelper::TestSuspend: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 2684 | Expand_TestSuspend(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2685 | return NULL; |
| 2686 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2687 | case IntrinsicHelper::MarkGCCard: { |
TDYa127 | 9a12945 | 2012-07-19 03:10:08 -0700 | [diff] [blame] | 2688 | Expand_MarkGCCard(call_inst); |
| 2689 | return NULL; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2690 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2691 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2692 | //==- Exception --------------------------------------------------------==// |
| 2693 | case IntrinsicHelper::ThrowException: { |
| 2694 | return ExpandToRuntime(runtime_support::ThrowException, call_inst); |
| 2695 | } |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2696 | case IntrinsicHelper::HLThrowException: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2697 | uint32_t dex_pc = LV2UInt(call_inst.getMetadata("DexOff")->getOperand(0)); |
| 2698 | |
| 2699 | EmitUpdateDexPC(dex_pc); |
| 2700 | |
| 2701 | irb_.CreateCall(irb_.GetRuntime(runtime_support::ThrowException), |
| 2702 | call_inst.getArgOperand(0)); |
| 2703 | |
| 2704 | EmitGuard_ExceptionLandingPad(dex_pc); |
| 2705 | return NULL; |
| 2706 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2707 | case IntrinsicHelper::GetException: { |
TDYa127 | 823433d | 2012-09-26 16:03:51 -0700 | [diff] [blame] | 2708 | return irb_.Runtime().EmitGetAndClearException(); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2709 | } |
| 2710 | case IntrinsicHelper::IsExceptionPending: { |
| 2711 | return irb_.Runtime().EmitIsExceptionPending(); |
| 2712 | } |
| 2713 | case IntrinsicHelper::FindCatchBlock: { |
| 2714 | return ExpandToRuntime(runtime_support::FindCatchBlock, call_inst); |
| 2715 | } |
| 2716 | case IntrinsicHelper::ThrowDivZeroException: { |
| 2717 | return ExpandToRuntime(runtime_support::ThrowDivZeroException, call_inst); |
| 2718 | } |
| 2719 | case IntrinsicHelper::ThrowNullPointerException: { |
| 2720 | return ExpandToRuntime(runtime_support::ThrowNullPointerException, call_inst); |
| 2721 | } |
| 2722 | case IntrinsicHelper::ThrowIndexOutOfBounds: { |
| 2723 | return ExpandToRuntime(runtime_support::ThrowIndexOutOfBounds, call_inst); |
| 2724 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2725 | |
| 2726 | //==- Const String -----------------------------------------------------==// |
| 2727 | case IntrinsicHelper::ConstString: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2728 | return Expand_ConstString(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2729 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2730 | case IntrinsicHelper::LoadStringFromDexCache: { |
| 2731 | return Expand_LoadStringFromDexCache(call_inst.getArgOperand(0)); |
| 2732 | } |
| 2733 | case IntrinsicHelper::ResolveString: { |
| 2734 | return ExpandToRuntime(runtime_support::ResolveString, call_inst); |
| 2735 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2736 | |
| 2737 | //==- Const Class ------------------------------------------------------==// |
| 2738 | case IntrinsicHelper::ConstClass: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2739 | return Expand_ConstClass(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2740 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2741 | case IntrinsicHelper::InitializeTypeAndVerifyAccess: { |
| 2742 | return ExpandToRuntime(runtime_support::InitializeTypeAndVerifyAccess, call_inst); |
| 2743 | } |
| 2744 | case IntrinsicHelper::LoadTypeFromDexCache: { |
| 2745 | return Expand_LoadTypeFromDexCache(call_inst.getArgOperand(0)); |
| 2746 | } |
| 2747 | case IntrinsicHelper::InitializeType: { |
| 2748 | return ExpandToRuntime(runtime_support::InitializeType, call_inst); |
| 2749 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2750 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2751 | //==- Lock -------------------------------------------------------------==// |
| 2752 | case IntrinsicHelper::LockObject: { |
| 2753 | Expand_LockObject(call_inst.getArgOperand(0)); |
| 2754 | return NULL; |
| 2755 | } |
| 2756 | case IntrinsicHelper::UnlockObject: { |
| 2757 | Expand_UnlockObject(call_inst.getArgOperand(0)); |
| 2758 | return NULL; |
| 2759 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2760 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2761 | //==- Cast -------------------------------------------------------------==// |
| 2762 | case IntrinsicHelper::CheckCast: { |
| 2763 | return ExpandToRuntime(runtime_support::CheckCast, call_inst); |
| 2764 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2765 | case IntrinsicHelper::HLCheckCast: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2766 | Expand_HLCheckCast(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2767 | return NULL; |
| 2768 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2769 | case IntrinsicHelper::IsAssignable: { |
| 2770 | return ExpandToRuntime(runtime_support::IsAssignable, 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 | //==- Alloc ------------------------------------------------------------==// |
| 2774 | case IntrinsicHelper::AllocObject: { |
| 2775 | return ExpandToRuntime(runtime_support::AllocObject, call_inst); |
| 2776 | } |
| 2777 | case IntrinsicHelper::AllocObjectWithAccessCheck: { |
| 2778 | return ExpandToRuntime(runtime_support::AllocObjectWithAccessCheck, call_inst); |
| 2779 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2780 | |
| 2781 | //==- Instance ---------------------------------------------------------==// |
| 2782 | case IntrinsicHelper::NewInstance: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2783 | return Expand_NewInstance(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2784 | } |
| 2785 | case IntrinsicHelper::InstanceOf: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2786 | return Expand_InstanceOf(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2789 | //==- Array ------------------------------------------------------------==// |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2790 | case IntrinsicHelper::NewArray: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2791 | return Expand_NewArray(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2792 | } |
| 2793 | case IntrinsicHelper::OptArrayLength: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2794 | return Expand_OptArrayLength(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2795 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2796 | case IntrinsicHelper::ArrayLength: { |
| 2797 | return EmitLoadArrayLength(call_inst.getArgOperand(0)); |
| 2798 | } |
| 2799 | case IntrinsicHelper::AllocArray: { |
| 2800 | return ExpandToRuntime(runtime_support::AllocArray, call_inst); |
| 2801 | } |
| 2802 | case IntrinsicHelper::AllocArrayWithAccessCheck: { |
| 2803 | return ExpandToRuntime(runtime_support::AllocArrayWithAccessCheck, |
| 2804 | call_inst); |
| 2805 | } |
| 2806 | case IntrinsicHelper::CheckAndAllocArray: { |
| 2807 | return ExpandToRuntime(runtime_support::CheckAndAllocArray, call_inst); |
| 2808 | } |
| 2809 | case IntrinsicHelper::CheckAndAllocArrayWithAccessCheck: { |
| 2810 | return ExpandToRuntime(runtime_support::CheckAndAllocArrayWithAccessCheck, |
| 2811 | call_inst); |
| 2812 | } |
| 2813 | case IntrinsicHelper::ArrayGet: { |
| 2814 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2815 | call_inst.getArgOperand(1), |
| 2816 | kInt); |
| 2817 | } |
| 2818 | case IntrinsicHelper::ArrayGetWide: { |
| 2819 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2820 | call_inst.getArgOperand(1), |
| 2821 | kLong); |
| 2822 | } |
| 2823 | case IntrinsicHelper::ArrayGetObject: { |
| 2824 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2825 | call_inst.getArgOperand(1), |
| 2826 | kObject); |
| 2827 | } |
| 2828 | case IntrinsicHelper::ArrayGetBoolean: { |
| 2829 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2830 | call_inst.getArgOperand(1), |
| 2831 | kBoolean); |
| 2832 | } |
| 2833 | case IntrinsicHelper::ArrayGetByte: { |
| 2834 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2835 | call_inst.getArgOperand(1), |
| 2836 | kByte); |
| 2837 | } |
| 2838 | case IntrinsicHelper::ArrayGetChar: { |
| 2839 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2840 | call_inst.getArgOperand(1), |
| 2841 | kChar); |
| 2842 | } |
| 2843 | case IntrinsicHelper::ArrayGetShort: { |
| 2844 | return Expand_ArrayGet(call_inst.getArgOperand(0), |
| 2845 | call_inst.getArgOperand(1), |
| 2846 | kShort); |
| 2847 | } |
| 2848 | case IntrinsicHelper::ArrayPut: { |
| 2849 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2850 | call_inst.getArgOperand(1), |
| 2851 | call_inst.getArgOperand(2), |
| 2852 | kInt); |
| 2853 | return NULL; |
| 2854 | } |
| 2855 | case IntrinsicHelper::ArrayPutWide: { |
| 2856 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2857 | call_inst.getArgOperand(1), |
| 2858 | call_inst.getArgOperand(2), |
| 2859 | kLong); |
| 2860 | return NULL; |
| 2861 | } |
| 2862 | case IntrinsicHelper::ArrayPutObject: { |
| 2863 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2864 | call_inst.getArgOperand(1), |
| 2865 | call_inst.getArgOperand(2), |
| 2866 | kObject); |
| 2867 | return NULL; |
| 2868 | } |
| 2869 | case IntrinsicHelper::ArrayPutBoolean: { |
| 2870 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2871 | call_inst.getArgOperand(1), |
| 2872 | call_inst.getArgOperand(2), |
| 2873 | kBoolean); |
| 2874 | return NULL; |
| 2875 | } |
| 2876 | case IntrinsicHelper::ArrayPutByte: { |
| 2877 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2878 | call_inst.getArgOperand(1), |
| 2879 | call_inst.getArgOperand(2), |
| 2880 | kByte); |
| 2881 | return NULL; |
| 2882 | } |
| 2883 | case IntrinsicHelper::ArrayPutChar: { |
| 2884 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2885 | call_inst.getArgOperand(1), |
| 2886 | call_inst.getArgOperand(2), |
| 2887 | kChar); |
| 2888 | return NULL; |
| 2889 | } |
| 2890 | case IntrinsicHelper::ArrayPutShort: { |
| 2891 | Expand_ArrayPut(call_inst.getArgOperand(0), |
| 2892 | call_inst.getArgOperand(1), |
| 2893 | call_inst.getArgOperand(2), |
| 2894 | kShort); |
| 2895 | return NULL; |
| 2896 | } |
| 2897 | case IntrinsicHelper::CheckPutArrayElement: { |
| 2898 | return ExpandToRuntime(runtime_support::CheckPutArrayElement, call_inst); |
| 2899 | } |
| 2900 | case IntrinsicHelper::FilledNewArray: { |
| 2901 | Expand_FilledNewArray(call_inst); |
| 2902 | return NULL; |
| 2903 | } |
| 2904 | case IntrinsicHelper::FillArrayData: { |
| 2905 | return ExpandToRuntime(runtime_support::FillArrayData, call_inst); |
| 2906 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2907 | case IntrinsicHelper::HLFillArrayData: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2908 | Expand_HLFillArrayData(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2909 | return NULL; |
| 2910 | } |
| 2911 | case IntrinsicHelper::HLFilledNewArray: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 2912 | return Expand_HLFilledNewArray(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 2915 | //==- Instance Field ---------------------------------------------------==// |
| 2916 | case IntrinsicHelper::InstanceFieldGet: |
| 2917 | case IntrinsicHelper::InstanceFieldGetBoolean: |
| 2918 | case IntrinsicHelper::InstanceFieldGetByte: |
| 2919 | case IntrinsicHelper::InstanceFieldGetChar: |
| 2920 | case IntrinsicHelper::InstanceFieldGetShort: { |
| 2921 | return ExpandToRuntime(runtime_support::Get32Instance, call_inst); |
| 2922 | } |
| 2923 | case IntrinsicHelper::InstanceFieldGetWide: { |
| 2924 | return ExpandToRuntime(runtime_support::Get64Instance, call_inst); |
| 2925 | } |
| 2926 | case IntrinsicHelper::InstanceFieldGetObject: { |
| 2927 | return ExpandToRuntime(runtime_support::GetObjectInstance, call_inst); |
| 2928 | } |
| 2929 | case IntrinsicHelper::InstanceFieldGetFast: { |
| 2930 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2931 | call_inst.getArgOperand(1), |
| 2932 | call_inst.getArgOperand(2), |
| 2933 | kInt); |
| 2934 | } |
| 2935 | case IntrinsicHelper::InstanceFieldGetWideFast: { |
| 2936 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2937 | call_inst.getArgOperand(1), |
| 2938 | call_inst.getArgOperand(2), |
| 2939 | kLong); |
| 2940 | } |
| 2941 | case IntrinsicHelper::InstanceFieldGetObjectFast: { |
| 2942 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2943 | call_inst.getArgOperand(1), |
| 2944 | call_inst.getArgOperand(2), |
| 2945 | kObject); |
| 2946 | } |
| 2947 | case IntrinsicHelper::InstanceFieldGetBooleanFast: { |
| 2948 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2949 | call_inst.getArgOperand(1), |
| 2950 | call_inst.getArgOperand(2), |
| 2951 | kBoolean); |
| 2952 | } |
| 2953 | case IntrinsicHelper::InstanceFieldGetByteFast: { |
| 2954 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2955 | call_inst.getArgOperand(1), |
| 2956 | call_inst.getArgOperand(2), |
| 2957 | kByte); |
| 2958 | } |
| 2959 | case IntrinsicHelper::InstanceFieldGetCharFast: { |
| 2960 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2961 | call_inst.getArgOperand(1), |
| 2962 | call_inst.getArgOperand(2), |
| 2963 | kChar); |
| 2964 | } |
| 2965 | case IntrinsicHelper::InstanceFieldGetShortFast: { |
| 2966 | return Expand_IGetFast(call_inst.getArgOperand(0), |
| 2967 | call_inst.getArgOperand(1), |
| 2968 | call_inst.getArgOperand(2), |
| 2969 | kShort); |
| 2970 | } |
| 2971 | case IntrinsicHelper::InstanceFieldPut: |
| 2972 | case IntrinsicHelper::InstanceFieldPutBoolean: |
| 2973 | case IntrinsicHelper::InstanceFieldPutByte: |
| 2974 | case IntrinsicHelper::InstanceFieldPutChar: |
| 2975 | case IntrinsicHelper::InstanceFieldPutShort: { |
| 2976 | return ExpandToRuntime(runtime_support::Set32Instance, call_inst); |
| 2977 | } |
| 2978 | case IntrinsicHelper::InstanceFieldPutWide: { |
| 2979 | return ExpandToRuntime(runtime_support::Set64Instance, call_inst); |
| 2980 | } |
| 2981 | case IntrinsicHelper::InstanceFieldPutObject: { |
| 2982 | return ExpandToRuntime(runtime_support::SetObjectInstance, call_inst); |
| 2983 | } |
| 2984 | case IntrinsicHelper::InstanceFieldPutFast: { |
| 2985 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 2986 | call_inst.getArgOperand(1), |
| 2987 | call_inst.getArgOperand(2), |
| 2988 | call_inst.getArgOperand(3), |
| 2989 | kInt); |
| 2990 | return NULL; |
| 2991 | } |
| 2992 | case IntrinsicHelper::InstanceFieldPutWideFast: { |
| 2993 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 2994 | call_inst.getArgOperand(1), |
| 2995 | call_inst.getArgOperand(2), |
| 2996 | call_inst.getArgOperand(3), |
| 2997 | kLong); |
| 2998 | return NULL; |
| 2999 | } |
| 3000 | case IntrinsicHelper::InstanceFieldPutObjectFast: { |
| 3001 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3002 | call_inst.getArgOperand(1), |
| 3003 | call_inst.getArgOperand(2), |
| 3004 | call_inst.getArgOperand(3), |
| 3005 | kObject); |
| 3006 | return NULL; |
| 3007 | } |
| 3008 | case IntrinsicHelper::InstanceFieldPutBooleanFast: { |
| 3009 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3010 | call_inst.getArgOperand(1), |
| 3011 | call_inst.getArgOperand(2), |
| 3012 | call_inst.getArgOperand(3), |
| 3013 | kBoolean); |
| 3014 | return NULL; |
| 3015 | } |
| 3016 | case IntrinsicHelper::InstanceFieldPutByteFast: { |
| 3017 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3018 | call_inst.getArgOperand(1), |
| 3019 | call_inst.getArgOperand(2), |
| 3020 | call_inst.getArgOperand(3), |
| 3021 | kByte); |
| 3022 | return NULL; |
| 3023 | } |
| 3024 | case IntrinsicHelper::InstanceFieldPutCharFast: { |
| 3025 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3026 | call_inst.getArgOperand(1), |
| 3027 | call_inst.getArgOperand(2), |
| 3028 | call_inst.getArgOperand(3), |
| 3029 | kChar); |
| 3030 | return NULL; |
| 3031 | } |
| 3032 | case IntrinsicHelper::InstanceFieldPutShortFast: { |
| 3033 | Expand_IPutFast(call_inst.getArgOperand(0), |
| 3034 | call_inst.getArgOperand(1), |
| 3035 | call_inst.getArgOperand(2), |
| 3036 | call_inst.getArgOperand(3), |
| 3037 | kShort); |
| 3038 | return NULL; |
| 3039 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3040 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3041 | //==- Static Field -----------------------------------------------------==// |
| 3042 | case IntrinsicHelper::StaticFieldGet: |
| 3043 | case IntrinsicHelper::StaticFieldGetBoolean: |
| 3044 | case IntrinsicHelper::StaticFieldGetByte: |
| 3045 | case IntrinsicHelper::StaticFieldGetChar: |
| 3046 | case IntrinsicHelper::StaticFieldGetShort: { |
| 3047 | return ExpandToRuntime(runtime_support::Get32Static, call_inst); |
| 3048 | } |
| 3049 | case IntrinsicHelper::StaticFieldGetWide: { |
| 3050 | return ExpandToRuntime(runtime_support::Get64Static, call_inst); |
| 3051 | } |
| 3052 | case IntrinsicHelper::StaticFieldGetObject: { |
| 3053 | return ExpandToRuntime(runtime_support::GetObjectStatic, call_inst); |
| 3054 | } |
| 3055 | case IntrinsicHelper::StaticFieldGetFast: { |
| 3056 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3057 | call_inst.getArgOperand(1), |
| 3058 | call_inst.getArgOperand(2), |
| 3059 | kInt); |
| 3060 | } |
| 3061 | case IntrinsicHelper::StaticFieldGetWideFast: { |
| 3062 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3063 | call_inst.getArgOperand(1), |
| 3064 | call_inst.getArgOperand(2), |
| 3065 | kLong); |
| 3066 | } |
| 3067 | case IntrinsicHelper::StaticFieldGetObjectFast: { |
| 3068 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3069 | call_inst.getArgOperand(1), |
| 3070 | call_inst.getArgOperand(2), |
| 3071 | kObject); |
| 3072 | } |
| 3073 | case IntrinsicHelper::StaticFieldGetBooleanFast: { |
| 3074 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3075 | call_inst.getArgOperand(1), |
| 3076 | call_inst.getArgOperand(2), |
| 3077 | kBoolean); |
| 3078 | } |
| 3079 | case IntrinsicHelper::StaticFieldGetByteFast: { |
| 3080 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3081 | call_inst.getArgOperand(1), |
| 3082 | call_inst.getArgOperand(2), |
| 3083 | kByte); |
| 3084 | } |
| 3085 | case IntrinsicHelper::StaticFieldGetCharFast: { |
| 3086 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3087 | call_inst.getArgOperand(1), |
| 3088 | call_inst.getArgOperand(2), |
| 3089 | kChar); |
| 3090 | } |
| 3091 | case IntrinsicHelper::StaticFieldGetShortFast: { |
| 3092 | return Expand_SGetFast(call_inst.getArgOperand(0), |
| 3093 | call_inst.getArgOperand(1), |
| 3094 | call_inst.getArgOperand(2), |
| 3095 | kShort); |
| 3096 | } |
| 3097 | case IntrinsicHelper::StaticFieldPut: |
| 3098 | case IntrinsicHelper::StaticFieldPutBoolean: |
| 3099 | case IntrinsicHelper::StaticFieldPutByte: |
| 3100 | case IntrinsicHelper::StaticFieldPutChar: |
| 3101 | case IntrinsicHelper::StaticFieldPutShort: { |
| 3102 | return ExpandToRuntime(runtime_support::Set32Static, call_inst); |
| 3103 | } |
| 3104 | case IntrinsicHelper::StaticFieldPutWide: { |
| 3105 | return ExpandToRuntime(runtime_support::Set64Static, call_inst); |
| 3106 | } |
| 3107 | case IntrinsicHelper::StaticFieldPutObject: { |
| 3108 | return ExpandToRuntime(runtime_support::SetObjectStatic, call_inst); |
| 3109 | } |
| 3110 | case IntrinsicHelper::StaticFieldPutFast: { |
| 3111 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3112 | call_inst.getArgOperand(1), |
| 3113 | call_inst.getArgOperand(2), |
| 3114 | call_inst.getArgOperand(3), |
| 3115 | kInt); |
| 3116 | return NULL; |
| 3117 | } |
| 3118 | case IntrinsicHelper::StaticFieldPutWideFast: { |
| 3119 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3120 | call_inst.getArgOperand(1), |
| 3121 | call_inst.getArgOperand(2), |
| 3122 | call_inst.getArgOperand(3), |
| 3123 | kLong); |
| 3124 | return NULL; |
| 3125 | } |
| 3126 | case IntrinsicHelper::StaticFieldPutObjectFast: { |
| 3127 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3128 | call_inst.getArgOperand(1), |
| 3129 | call_inst.getArgOperand(2), |
| 3130 | call_inst.getArgOperand(3), |
| 3131 | kObject); |
| 3132 | return NULL; |
| 3133 | } |
| 3134 | case IntrinsicHelper::StaticFieldPutBooleanFast: { |
| 3135 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3136 | call_inst.getArgOperand(1), |
| 3137 | call_inst.getArgOperand(2), |
| 3138 | call_inst.getArgOperand(3), |
| 3139 | kBoolean); |
| 3140 | return NULL; |
| 3141 | } |
| 3142 | case IntrinsicHelper::StaticFieldPutByteFast: { |
| 3143 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3144 | call_inst.getArgOperand(1), |
| 3145 | call_inst.getArgOperand(2), |
| 3146 | call_inst.getArgOperand(3), |
| 3147 | kByte); |
| 3148 | return NULL; |
| 3149 | } |
| 3150 | case IntrinsicHelper::StaticFieldPutCharFast: { |
| 3151 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3152 | call_inst.getArgOperand(1), |
| 3153 | call_inst.getArgOperand(2), |
| 3154 | call_inst.getArgOperand(3), |
| 3155 | kChar); |
| 3156 | return NULL; |
| 3157 | } |
| 3158 | case IntrinsicHelper::StaticFieldPutShortFast: { |
| 3159 | Expand_SPutFast(call_inst.getArgOperand(0), |
| 3160 | call_inst.getArgOperand(1), |
| 3161 | call_inst.getArgOperand(2), |
| 3162 | call_inst.getArgOperand(3), |
| 3163 | kShort); |
| 3164 | return NULL; |
| 3165 | } |
| 3166 | case IntrinsicHelper::LoadDeclaringClassSSB: { |
| 3167 | return Expand_LoadDeclaringClassSSB(call_inst.getArgOperand(0)); |
| 3168 | } |
| 3169 | case IntrinsicHelper::LoadClassSSBFromDexCache: { |
| 3170 | return Expand_LoadClassSSBFromDexCache(call_inst.getArgOperand(0)); |
| 3171 | } |
| 3172 | case IntrinsicHelper::InitializeAndLoadClassSSB: { |
| 3173 | return ExpandToRuntime(runtime_support::InitializeStaticStorage, call_inst); |
| 3174 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3175 | |
| 3176 | //==- High-level Array -------------------------------------------------==// |
| 3177 | case IntrinsicHelper::HLArrayGet: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3178 | return Expand_HLArrayGet(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3179 | } |
| 3180 | case IntrinsicHelper::HLArrayGetBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3181 | return Expand_HLArrayGet(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3182 | } |
| 3183 | case IntrinsicHelper::HLArrayGetByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3184 | return Expand_HLArrayGet(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3185 | } |
| 3186 | case IntrinsicHelper::HLArrayGetChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3187 | return Expand_HLArrayGet(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3188 | } |
| 3189 | case IntrinsicHelper::HLArrayGetShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3190 | return Expand_HLArrayGet(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3191 | } |
| 3192 | case IntrinsicHelper::HLArrayGetFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3193 | return Expand_HLArrayGet(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3194 | } |
| 3195 | case IntrinsicHelper::HLArrayGetWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3196 | return Expand_HLArrayGet(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3197 | } |
| 3198 | case IntrinsicHelper::HLArrayGetDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3199 | return Expand_HLArrayGet(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3200 | } |
| 3201 | case IntrinsicHelper::HLArrayGetObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3202 | return Expand_HLArrayGet(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3203 | } |
| 3204 | case IntrinsicHelper::HLArrayPut: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3205 | Expand_HLArrayPut(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3206 | return NULL; |
| 3207 | } |
| 3208 | case IntrinsicHelper::HLArrayPutBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3209 | Expand_HLArrayPut(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3210 | return NULL; |
| 3211 | } |
| 3212 | case IntrinsicHelper::HLArrayPutByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3213 | Expand_HLArrayPut(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3214 | return NULL; |
| 3215 | } |
| 3216 | case IntrinsicHelper::HLArrayPutChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3217 | Expand_HLArrayPut(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3218 | return NULL; |
| 3219 | } |
| 3220 | case IntrinsicHelper::HLArrayPutShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3221 | Expand_HLArrayPut(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3222 | return NULL; |
| 3223 | } |
| 3224 | case IntrinsicHelper::HLArrayPutFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3225 | Expand_HLArrayPut(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3226 | return NULL; |
| 3227 | } |
| 3228 | case IntrinsicHelper::HLArrayPutWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3229 | Expand_HLArrayPut(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3230 | return NULL; |
| 3231 | } |
| 3232 | case IntrinsicHelper::HLArrayPutDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3233 | Expand_HLArrayPut(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3234 | return NULL; |
| 3235 | } |
| 3236 | case IntrinsicHelper::HLArrayPutObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3237 | Expand_HLArrayPut(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3238 | return NULL; |
| 3239 | } |
| 3240 | |
| 3241 | //==- High-level Instance ----------------------------------------------==// |
| 3242 | case IntrinsicHelper::HLIGet: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3243 | return Expand_HLIGet(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3244 | } |
| 3245 | case IntrinsicHelper::HLIGetBoolean: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3246 | return Expand_HLIGet(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3247 | } |
| 3248 | case IntrinsicHelper::HLIGetByte: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3249 | return Expand_HLIGet(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3250 | } |
| 3251 | case IntrinsicHelper::HLIGetChar: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3252 | return Expand_HLIGet(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3253 | } |
| 3254 | case IntrinsicHelper::HLIGetShort: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3255 | return Expand_HLIGet(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3256 | } |
| 3257 | case IntrinsicHelper::HLIGetFloat: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3258 | return Expand_HLIGet(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3259 | } |
| 3260 | case IntrinsicHelper::HLIGetWide: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3261 | return Expand_HLIGet(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3262 | } |
| 3263 | case IntrinsicHelper::HLIGetDouble: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3264 | return Expand_HLIGet(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3265 | } |
| 3266 | case IntrinsicHelper::HLIGetObject: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3267 | return Expand_HLIGet(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3268 | } |
| 3269 | case IntrinsicHelper::HLIPut: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3270 | Expand_HLIPut(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3271 | return NULL; |
| 3272 | } |
| 3273 | case IntrinsicHelper::HLIPutBoolean: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3274 | Expand_HLIPut(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3275 | return NULL; |
| 3276 | } |
| 3277 | case IntrinsicHelper::HLIPutByte: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3278 | Expand_HLIPut(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3279 | return NULL; |
| 3280 | } |
| 3281 | case IntrinsicHelper::HLIPutChar: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3282 | Expand_HLIPut(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3283 | return NULL; |
| 3284 | } |
| 3285 | case IntrinsicHelper::HLIPutShort: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3286 | Expand_HLIPut(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3287 | return NULL; |
| 3288 | } |
| 3289 | case IntrinsicHelper::HLIPutFloat: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3290 | Expand_HLIPut(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3291 | return NULL; |
| 3292 | } |
| 3293 | case IntrinsicHelper::HLIPutWide: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3294 | Expand_HLIPut(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3295 | return NULL; |
| 3296 | } |
| 3297 | case IntrinsicHelper::HLIPutDouble: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3298 | Expand_HLIPut(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3299 | return NULL; |
| 3300 | } |
| 3301 | case IntrinsicHelper::HLIPutObject: { |
TDYa127 | 5e869b6 | 2012-07-25 00:45:39 -0700 | [diff] [blame] | 3302 | Expand_HLIPut(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3303 | return NULL; |
| 3304 | } |
| 3305 | |
| 3306 | //==- High-level Invoke ------------------------------------------------==// |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3307 | case IntrinsicHelper::HLInvokeVoid: |
| 3308 | case IntrinsicHelper::HLInvokeObj: |
| 3309 | case IntrinsicHelper::HLInvokeInt: |
| 3310 | case IntrinsicHelper::HLInvokeFloat: |
| 3311 | case IntrinsicHelper::HLInvokeLong: |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3312 | case IntrinsicHelper::HLInvokeDouble: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3313 | return Expand_HLInvoke(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3316 | //==- Invoke -----------------------------------------------------------==// |
| 3317 | case IntrinsicHelper::FindStaticMethodWithAccessCheck: { |
| 3318 | return ExpandToRuntime(runtime_support::FindStaticMethodWithAccessCheck, call_inst); |
| 3319 | } |
| 3320 | case IntrinsicHelper::FindDirectMethodWithAccessCheck: { |
| 3321 | return ExpandToRuntime(runtime_support::FindDirectMethodWithAccessCheck, call_inst); |
| 3322 | } |
| 3323 | case IntrinsicHelper::FindVirtualMethodWithAccessCheck: { |
| 3324 | return ExpandToRuntime(runtime_support::FindVirtualMethodWithAccessCheck, call_inst); |
| 3325 | } |
| 3326 | case IntrinsicHelper::FindSuperMethodWithAccessCheck: { |
| 3327 | return ExpandToRuntime(runtime_support::FindSuperMethodWithAccessCheck, call_inst); |
| 3328 | } |
| 3329 | case IntrinsicHelper::FindInterfaceMethodWithAccessCheck: { |
| 3330 | return ExpandToRuntime(runtime_support::FindInterfaceMethodWithAccessCheck, call_inst); |
| 3331 | } |
| 3332 | case IntrinsicHelper::GetSDCalleeMethodObjAddrFast: { |
| 3333 | return Expand_GetSDCalleeMethodObjAddrFast(call_inst.getArgOperand(0)); |
| 3334 | } |
| 3335 | case IntrinsicHelper::GetVirtualCalleeMethodObjAddrFast: { |
| 3336 | return Expand_GetVirtualCalleeMethodObjAddrFast( |
| 3337 | call_inst.getArgOperand(0), call_inst.getArgOperand(1)); |
| 3338 | } |
| 3339 | case IntrinsicHelper::GetInterfaceCalleeMethodObjAddrFast: { |
| 3340 | return ExpandToRuntime(runtime_support::FindInterfaceMethod, call_inst); |
| 3341 | } |
| 3342 | case IntrinsicHelper::InvokeRetVoid: |
| 3343 | case IntrinsicHelper::InvokeRetBoolean: |
| 3344 | case IntrinsicHelper::InvokeRetByte: |
| 3345 | case IntrinsicHelper::InvokeRetChar: |
| 3346 | case IntrinsicHelper::InvokeRetShort: |
| 3347 | case IntrinsicHelper::InvokeRetInt: |
| 3348 | case IntrinsicHelper::InvokeRetLong: |
| 3349 | case IntrinsicHelper::InvokeRetFloat: |
| 3350 | case IntrinsicHelper::InvokeRetDouble: |
| 3351 | case IntrinsicHelper::InvokeRetObject: { |
| 3352 | return Expand_Invoke(call_inst); |
| 3353 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3354 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3355 | //==- Math -------------------------------------------------------------==// |
| 3356 | case IntrinsicHelper::DivInt: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3357 | return Expand_DivRem(call_inst, /* is_div */true, kInt); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3358 | } |
| 3359 | case IntrinsicHelper::RemInt: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3360 | return Expand_DivRem(call_inst, /* is_div */false, kInt); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3361 | } |
| 3362 | case IntrinsicHelper::DivLong: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3363 | return Expand_DivRem(call_inst, /* is_div */true, kLong); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3364 | } |
| 3365 | case IntrinsicHelper::RemLong: { |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3366 | return Expand_DivRem(call_inst, /* is_div */false, kLong); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3367 | } |
| 3368 | case IntrinsicHelper::D2L: { |
| 3369 | return ExpandToRuntime(runtime_support::art_d2l, call_inst); |
| 3370 | } |
| 3371 | case IntrinsicHelper::D2I: { |
| 3372 | return ExpandToRuntime(runtime_support::art_d2i, call_inst); |
| 3373 | } |
| 3374 | case IntrinsicHelper::F2L: { |
| 3375 | return ExpandToRuntime(runtime_support::art_f2l, call_inst); |
| 3376 | } |
| 3377 | case IntrinsicHelper::F2I: { |
| 3378 | return ExpandToRuntime(runtime_support::art_f2i, call_inst); |
| 3379 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3380 | |
| 3381 | //==- High-level Static ------------------------------------------------==// |
| 3382 | case IntrinsicHelper::HLSget: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3383 | return Expand_HLSget(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3384 | } |
| 3385 | case IntrinsicHelper::HLSgetBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3386 | return Expand_HLSget(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3387 | } |
| 3388 | case IntrinsicHelper::HLSgetByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3389 | return Expand_HLSget(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3390 | } |
| 3391 | case IntrinsicHelper::HLSgetChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3392 | return Expand_HLSget(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3393 | } |
| 3394 | case IntrinsicHelper::HLSgetShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3395 | return Expand_HLSget(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3396 | } |
| 3397 | case IntrinsicHelper::HLSgetFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3398 | return Expand_HLSget(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3399 | } |
| 3400 | case IntrinsicHelper::HLSgetWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3401 | return Expand_HLSget(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3402 | } |
| 3403 | case IntrinsicHelper::HLSgetDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3404 | return Expand_HLSget(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3405 | } |
| 3406 | case IntrinsicHelper::HLSgetObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3407 | return Expand_HLSget(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3408 | } |
| 3409 | case IntrinsicHelper::HLSput: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3410 | Expand_HLSput(call_inst, kInt); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3411 | return NULL; |
| 3412 | } |
| 3413 | case IntrinsicHelper::HLSputBoolean: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3414 | Expand_HLSput(call_inst, kBoolean); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3415 | return NULL; |
| 3416 | } |
| 3417 | case IntrinsicHelper::HLSputByte: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3418 | Expand_HLSput(call_inst, kByte); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3419 | return NULL; |
| 3420 | } |
| 3421 | case IntrinsicHelper::HLSputChar: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3422 | Expand_HLSput(call_inst, kChar); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3423 | return NULL; |
| 3424 | } |
| 3425 | case IntrinsicHelper::HLSputShort: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3426 | Expand_HLSput(call_inst, kShort); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3427 | return NULL; |
| 3428 | } |
| 3429 | case IntrinsicHelper::HLSputFloat: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3430 | Expand_HLSput(call_inst, kFloat); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3431 | return NULL; |
| 3432 | } |
| 3433 | case IntrinsicHelper::HLSputWide: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3434 | Expand_HLSput(call_inst, kLong); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3435 | return NULL; |
| 3436 | } |
| 3437 | case IntrinsicHelper::HLSputDouble: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3438 | Expand_HLSput(call_inst, kDouble); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3439 | return NULL; |
| 3440 | } |
| 3441 | case IntrinsicHelper::HLSputObject: { |
TDYa127 | 5a26d44 | 2012-07-26 18:58:38 -0700 | [diff] [blame] | 3442 | Expand_HLSput(call_inst, kObject); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3443 | return NULL; |
| 3444 | } |
| 3445 | |
| 3446 | //==- High-level Monitor -----------------------------------------------==// |
| 3447 | case IntrinsicHelper::MonitorEnter: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3448 | Expand_MonitorEnter(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3449 | return NULL; |
| 3450 | } |
| 3451 | case IntrinsicHelper::MonitorExit: { |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3452 | Expand_MonitorExit(call_inst); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3453 | return NULL; |
| 3454 | } |
| 3455 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3456 | //==- Shadow Frame -----------------------------------------------------==// |
| 3457 | case IntrinsicHelper::AllocaShadowFrame: { |
| 3458 | Expand_AllocaShadowFrame(call_inst.getArgOperand(0)); |
| 3459 | return NULL; |
| 3460 | } |
| 3461 | case IntrinsicHelper::SetShadowFrameEntry: { |
| 3462 | Expand_SetShadowFrameEntry(call_inst.getArgOperand(0), |
| 3463 | call_inst.getArgOperand(1)); |
| 3464 | return NULL; |
| 3465 | } |
| 3466 | case IntrinsicHelper::PopShadowFrame: { |
| 3467 | Expand_PopShadowFrame(); |
| 3468 | return NULL; |
| 3469 | } |
| 3470 | case IntrinsicHelper::UpdateDexPC: { |
| 3471 | Expand_UpdateDexPC(call_inst.getArgOperand(0)); |
| 3472 | return NULL; |
| 3473 | } |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 3474 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3475 | //==- Comparison -------------------------------------------------------==// |
| 3476 | case IntrinsicHelper::CmplFloat: |
| 3477 | case IntrinsicHelper::CmplDouble: { |
| 3478 | return Expand_FPCompare(call_inst.getArgOperand(0), |
| 3479 | call_inst.getArgOperand(1), |
| 3480 | false); |
| 3481 | } |
| 3482 | case IntrinsicHelper::CmpgFloat: |
| 3483 | case IntrinsicHelper::CmpgDouble: { |
| 3484 | return Expand_FPCompare(call_inst.getArgOperand(0), |
| 3485 | call_inst.getArgOperand(1), |
| 3486 | true); |
| 3487 | } |
| 3488 | case IntrinsicHelper::CmpLong: { |
| 3489 | return Expand_LongCompare(call_inst.getArgOperand(0), |
| 3490 | call_inst.getArgOperand(1)); |
| 3491 | } |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 3492 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3493 | //==- Const ------------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3494 | case IntrinsicHelper::ConstInt: |
| 3495 | case IntrinsicHelper::ConstLong: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 3496 | return call_inst.getArgOperand(0); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3497 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3498 | case IntrinsicHelper::ConstFloat: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 3499 | return irb_.CreateBitCast(call_inst.getArgOperand(0), |
| 3500 | irb_.getJFloatTy()); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3501 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3502 | case IntrinsicHelper::ConstDouble: { |
Logan Chien | d54a23d | 2012-07-24 11:19:23 -0700 | [diff] [blame] | 3503 | return irb_.CreateBitCast(call_inst.getArgOperand(0), |
| 3504 | irb_.getJDoubleTy()); |
| 3505 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3506 | case IntrinsicHelper::ConstObj: { |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 3507 | CHECK(LV2UInt(call_inst.getArgOperand(0)) == 0); |
| 3508 | return irb_.getJNull(); |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | //==- Method Info ------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3512 | case IntrinsicHelper::MethodInfo: { |
Shih-wei Liao | b259652 | 2012-09-14 16:36:11 -0700 | [diff] [blame] | 3513 | // Nothing to be done, because MethodInfo carries optional hints that are |
| 3514 | // not needed by the portable path. |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3515 | return NULL; |
| 3516 | } |
| 3517 | |
| 3518 | //==- Copy -------------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3519 | case IntrinsicHelper::CopyInt: |
| 3520 | case IntrinsicHelper::CopyFloat: |
| 3521 | case IntrinsicHelper::CopyLong: |
| 3522 | case IntrinsicHelper::CopyDouble: |
| 3523 | case IntrinsicHelper::CopyObj: { |
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 | } |
| 3526 | |
| 3527 | //==- Shift ------------------------------------------------------------==// |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3528 | case IntrinsicHelper::SHLLong: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3529 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3530 | call_inst.getArgOperand(1), |
| 3531 | kIntegerSHL, kLong); |
| 3532 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3533 | case IntrinsicHelper::SHRLong: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3534 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3535 | call_inst.getArgOperand(1), |
| 3536 | kIntegerSHR, kLong); |
| 3537 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3538 | case IntrinsicHelper::USHRLong: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3539 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3540 | call_inst.getArgOperand(1), |
| 3541 | kIntegerUSHR, kLong); |
| 3542 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3543 | case IntrinsicHelper::SHLInt: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3544 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3545 | call_inst.getArgOperand(1), |
| 3546 | kIntegerSHL, kInt); |
| 3547 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3548 | case IntrinsicHelper::SHRInt: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3549 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3550 | call_inst.getArgOperand(1), |
| 3551 | kIntegerSHR, kInt); |
| 3552 | } |
TDYa127 | 920be7c | 2012-09-10 17:13:22 -0700 | [diff] [blame] | 3553 | case IntrinsicHelper::USHRInt: { |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3554 | return Expand_IntegerShift(call_inst.getArgOperand(0), |
| 3555 | call_inst.getArgOperand(1), |
| 3556 | kIntegerUSHR, kInt); |
| 3557 | } |
| 3558 | |
| 3559 | //==- Conversion -------------------------------------------------------==// |
TDYa127 | a1b2185 | 2012-07-23 03:20:39 -0700 | [diff] [blame] | 3560 | case IntrinsicHelper::IntToChar: { |
| 3561 | return irb_.CreateZExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJCharTy()), |
| 3562 | irb_.getJIntTy()); |
| 3563 | } |
| 3564 | case IntrinsicHelper::IntToShort: { |
| 3565 | return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJShortTy()), |
| 3566 | irb_.getJIntTy()); |
| 3567 | } |
| 3568 | case IntrinsicHelper::IntToByte: { |
| 3569 | return irb_.CreateSExt(irb_.CreateTrunc(call_inst.getArgOperand(0), irb_.getJByteTy()), |
| 3570 | irb_.getJIntTy()); |
| 3571 | } |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3572 | |
TDYa127 | 87caa7e | 2012-08-25 23:23:27 -0700 | [diff] [blame] | 3573 | //==- Exception --------------------------------------------------------==// |
| 3574 | case IntrinsicHelper::CatchTargets: { |
TDYa127 | 55e5e6c | 2012-09-11 15:14:42 -0700 | [diff] [blame] | 3575 | UpdatePhiInstruction(current_bb_, irb_.GetInsertBlock()); |
TDYa127 | 87caa7e | 2012-08-25 23:23:27 -0700 | [diff] [blame] | 3576 | llvm::SwitchInst* si = llvm::dyn_cast<llvm::SwitchInst>(call_inst.getNextNode()); |
| 3577 | CHECK(si != NULL); |
| 3578 | irb_.CreateBr(si->getDefaultDest()); |
| 3579 | si->eraseFromParent(); |
| 3580 | return call_inst.getArgOperand(0); |
| 3581 | } |
| 3582 | |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3583 | //==- Unknown Cases ----------------------------------------------------==// |
| 3584 | case IntrinsicHelper::MaxIntrinsicId: |
| 3585 | case IntrinsicHelper::UnknownId: |
| 3586 | //default: |
| 3587 | // NOTE: "default" is intentionally commented so that C/C++ compiler will |
| 3588 | // give some warning on unmatched cases. |
| 3589 | // NOTE: We should not implement these cases. |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3590 | break; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3591 | } |
Logan Chien | 75e4b60 | 2012-07-23 14:24:12 -0700 | [diff] [blame] | 3592 | UNIMPLEMENTED(FATAL) << "Unexpected GBC intrinsic: " << static_cast<int>(intr_id); |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3593 | return NULL; |
| 3594 | } |
| 3595 | |
| 3596 | } // anonymous namespace |
| 3597 | |
| 3598 | namespace art { |
Shih-wei Liao | b259652 | 2012-09-14 16:36:11 -0700 | [diff] [blame] | 3599 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3600 | namespace compiler_llvm { |
| 3601 | |
| 3602 | llvm::FunctionPass* |
| 3603 | CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb) { |
| 3604 | return new GBCExpanderPass(intrinsic_helper, irb); |
| 3605 | } |
| 3606 | |
Shih-wei Liao | bb33f2f | 2012-08-23 13:20:00 -0700 | [diff] [blame] | 3607 | llvm::FunctionPass* |
| 3608 | CreateGBCExpanderPass(const IntrinsicHelper& intrinsic_helper, IRBuilder& irb, |
| 3609 | Compiler* compiler, OatCompilationUnit* oat_compilation_unit) { |
| 3610 | if (compiler != NULL) { |
| 3611 | return new GBCExpanderPass(intrinsic_helper, irb, |
| 3612 | compiler, oat_compilation_unit); |
| 3613 | } else { |
| 3614 | return new GBCExpanderPass(intrinsic_helper, irb); |
| 3615 | } |
| 3616 | } |
| 3617 | |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3618 | } // namespace compiler_llvm |
| 3619 | } // namespace art |