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