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