buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 17 | #include "object_utils.h" |
| 18 | |
| 19 | #include <llvm/Support/ToolOutputFile.h> |
| 20 | #include <llvm/Bitcode/ReaderWriter.h> |
| 21 | #include <llvm/Analysis/Verifier.h> |
| 22 | #include <llvm/Metadata.h> |
| 23 | #include <llvm/ADT/DepthFirstIterator.h> |
| 24 | #include <llvm/Instruction.h> |
| 25 | #include <llvm/Type.h> |
| 26 | #include <llvm/Instructions.h> |
| 27 | #include <llvm/Support/Casting.h> |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 28 | #include <llvm/Support/InstIterator.h> |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 29 | |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 30 | #include "codegen_util.h" |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 31 | #include "compiler/compiler_internals.h" |
| 32 | #include "local_optimizations.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 33 | #include "ralloc_util.h" |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 34 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 35 | static const char* kLabelFormat = "%c0x%x_%d"; |
buzbee | 951c0a1 | 2012-10-03 16:31:39 -0700 | [diff] [blame] | 36 | static const char kInvalidBlock = 0xff; |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 37 | static const char kNormalBlock = 'L'; |
| 38 | static const char kCatchBlock = 'C'; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 39 | |
| 40 | namespace art { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 41 | static RegLocation GetLoc(CompilationUnit* cu, llvm::Value* val); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 42 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 43 | static llvm::BasicBlock* GetLLVMBlock(CompilationUnit* cu, int id) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 44 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 45 | return cu->id_to_block_map.Get(id); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 46 | } |
| 47 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 48 | static llvm::Value* GetLLVMValue(CompilationUnit* cu, int s_reg) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 49 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 50 | return reinterpret_cast<llvm::Value*>(GrowableListGetElement(&cu->llvm_values, s_reg)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 51 | } |
| 52 | |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 53 | static void SetVregOnValue(CompilationUnit* cu, llvm::Value* val, int s_reg) |
| 54 | { |
| 55 | // Set vreg for debugging |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 56 | greenland::IntrinsicHelper::IntrinsicId id = |
| 57 | greenland::IntrinsicHelper::SetVReg; |
| 58 | llvm::Function* func = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 59 | int v_reg = SRegToVReg(cu, s_reg); |
| 60 | llvm::Value* table_slot = cu->irb->getInt32(v_reg); |
| 61 | llvm::Value* args[] = { table_slot, val }; |
| 62 | cu->irb->CreateCall(func, args); |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 63 | } |
| 64 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 65 | // Replace the placeholder value with the real definition |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 66 | static void DefineValueOnly(CompilationUnit* cu, llvm::Value* val, int s_reg) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 67 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 68 | llvm::Value* placeholder = GetLLVMValue(cu, s_reg); |
buzbee | 9a2487f | 2012-07-26 14:01:13 -0700 | [diff] [blame] | 69 | if (placeholder == NULL) { |
| 70 | // This can happen on instruction rewrite on verification failure |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 71 | LOG(WARNING) << "Null placeholder"; |
buzbee | 9a2487f | 2012-07-26 14:01:13 -0700 | [diff] [blame] | 72 | return; |
| 73 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 74 | placeholder->replaceAllUsesWith(val); |
| 75 | val->takeName(placeholder); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 76 | cu->llvm_values.elem_list[s_reg] = reinterpret_cast<uintptr_t>(val); |
buzbee | 4be777b | 2012-07-12 14:38:18 -0700 | [diff] [blame] | 77 | llvm::Instruction* inst = llvm::dyn_cast<llvm::Instruction>(placeholder); |
| 78 | DCHECK(inst != NULL); |
| 79 | inst->eraseFromParent(); |
TDYa127 | 8e950c1 | 2012-11-02 09:58:19 -0700 | [diff] [blame] | 80 | |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void DefineValue(CompilationUnit* cu, llvm::Value* val, int s_reg) |
| 84 | { |
| 85 | DefineValueOnly(cu, val, s_reg); |
| 86 | SetVregOnValue(cu, val, s_reg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 87 | } |
| 88 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 89 | static llvm::Type* LlvmTypeFromLocRec(CompilationUnit* cu, RegLocation loc) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 90 | { |
| 91 | llvm::Type* res = NULL; |
| 92 | if (loc.wide) { |
| 93 | if (loc.fp) |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 94 | res = cu->irb->getDoubleTy(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 95 | else |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 96 | res = cu->irb->getInt64Ty(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 97 | } else { |
| 98 | if (loc.fp) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 99 | res = cu->irb->getFloatTy(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 100 | } else { |
| 101 | if (loc.ref) |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 102 | res = cu->irb->GetJObjectTy(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 103 | else |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 104 | res = cu->irb->getInt32Ty(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | return res; |
| 108 | } |
| 109 | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 110 | /* Create an in-memory RegLocation from an llvm Value. */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 111 | static void CreateLocFromValue(CompilationUnit* cu, llvm::Value* val) |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 112 | { |
| 113 | // NOTE: llvm takes shortcuts with c_str() - get to std::string firstt |
| 114 | std::string s(val->getName().str()); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 115 | const char* val_name = s.c_str(); |
| 116 | SafeMap<llvm::Value*, RegLocation>::iterator it = cu->loc_map.find(val); |
| 117 | DCHECK(it == cu->loc_map.end()) << " - already defined: " << val_name; |
| 118 | int base_sreg = INVALID_SREG; |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 119 | int subscript = -1; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 120 | sscanf(val_name, "v%d_%d", &base_sreg, &subscript); |
| 121 | if ((base_sreg == INVALID_SREG) && (!strcmp(val_name, "method"))) { |
| 122 | base_sreg = SSA_METHOD_BASEREG; |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 123 | subscript = 0; |
| 124 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 125 | DCHECK_NE(base_sreg, INVALID_SREG); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 126 | DCHECK_NE(subscript, -1); |
| 127 | // TODO: redo during C++'ification |
| 128 | RegLocation loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0, INVALID_REG, |
| 129 | INVALID_REG, INVALID_SREG, INVALID_SREG}; |
| 130 | llvm::Type* ty = val->getType(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 131 | loc.wide = ((ty == cu->irb->getInt64Ty()) || |
| 132 | (ty == cu->irb->getDoubleTy())); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 133 | loc.defined = true; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 134 | loc.home = false; // May change during promotion |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 135 | loc.s_reg_low = base_sreg; |
| 136 | loc.orig_sreg = cu->loc_map.size(); |
| 137 | PromotionMap p_map = cu->promotion_map[base_sreg]; |
| 138 | if (ty == cu->irb->getFloatTy()) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 139 | loc.fp = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 140 | if (p_map.fp_location == kLocPhysReg) { |
| 141 | loc.low_reg = p_map.FpReg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 142 | loc.location = kLocPhysReg; |
| 143 | loc.home = true; |
| 144 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 145 | } else if (ty == cu->irb->getDoubleTy()) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 146 | loc.fp = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 147 | PromotionMap p_map_high = cu->promotion_map[base_sreg + 1]; |
| 148 | if ((p_map.fp_location == kLocPhysReg) && |
| 149 | (p_map_high.fp_location == kLocPhysReg) && |
| 150 | ((p_map.FpReg & 0x1) == 0) && |
| 151 | (p_map.FpReg + 1 == p_map_high.FpReg)) { |
| 152 | loc.low_reg = p_map.FpReg; |
| 153 | loc.high_reg = p_map_high.FpReg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 154 | loc.location = kLocPhysReg; |
| 155 | loc.home = true; |
| 156 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 157 | } else if (ty == cu->irb->GetJObjectTy()) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 158 | loc.ref = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 159 | if (p_map.core_location == kLocPhysReg) { |
| 160 | loc.low_reg = p_map.core_reg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 161 | loc.location = kLocPhysReg; |
| 162 | loc.home = true; |
| 163 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 164 | } else if (ty == cu->irb->getInt64Ty()) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 165 | loc.core = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 166 | PromotionMap p_map_high = cu->promotion_map[base_sreg + 1]; |
| 167 | if ((p_map.core_location == kLocPhysReg) && |
| 168 | (p_map_high.core_location == kLocPhysReg)) { |
| 169 | loc.low_reg = p_map.core_reg; |
| 170 | loc.high_reg = p_map_high.core_reg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 171 | loc.location = kLocPhysReg; |
| 172 | loc.home = true; |
| 173 | } |
| 174 | } else { |
| 175 | loc.core = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 176 | if (p_map.core_location == kLocPhysReg) { |
| 177 | loc.low_reg = p_map.core_reg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 178 | loc.location = kLocPhysReg; |
| 179 | loc.home = true; |
| 180 | } |
| 181 | } |
| 182 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 183 | if (cu->verbose && loc.home) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 184 | if (loc.wide) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 185 | LOG(INFO) << "Promoted wide " << s << " to regs " << loc.low_reg << "/" << loc.high_reg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 186 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 187 | LOG(INFO) << "Promoted " << s << " to reg " << loc.low_reg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 190 | cu->loc_map.Put(val, loc); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 191 | } |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 192 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 193 | static void InitIR(CompilationUnit* cu) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 194 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 195 | LLVMInfo* llvm_info = cu->llvm_info; |
| 196 | if (llvm_info == NULL) { |
| 197 | CompilerTls* tls = cu->compiler->GetTls(); |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 198 | CHECK(tls != NULL); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 199 | llvm_info = static_cast<LLVMInfo*>(tls->GetLLVMInfo()); |
| 200 | if (llvm_info == NULL) { |
| 201 | llvm_info = new LLVMInfo(); |
| 202 | tls->SetLLVMInfo(llvm_info); |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 205 | cu->context = llvm_info->GetLLVMContext(); |
| 206 | cu->module = llvm_info->GetLLVMModule(); |
| 207 | cu->intrinsic_helper = llvm_info->GetIntrinsicHelper(); |
| 208 | cu->irb = llvm_info->GetIRBuilder(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 209 | } |
| 210 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 211 | static const char* LlvmSSAName(CompilationUnit* cu, int ssa_reg) { |
| 212 | return GET_ELEM_N(cu->ssa_strings, char*, ssa_reg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 213 | } |
| 214 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 215 | llvm::BasicBlock* FindCaseTarget(CompilationUnit* cu, uint32_t vaddr) |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 216 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 217 | BasicBlock* bb = FindBlock(cu, vaddr); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 218 | DCHECK(bb != NULL); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 219 | return GetLLVMBlock(cu, bb->id); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 220 | } |
| 221 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 222 | static void ConvertPackedSwitch(CompilationUnit* cu, BasicBlock* bb, |
| 223 | int32_t table_offset, RegLocation rl_src) |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 224 | { |
| 225 | const Instruction::PackedSwitchPayload* payload = |
| 226 | reinterpret_cast<const Instruction::PackedSwitchPayload*>( |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 227 | cu->insns + cu->current_dalvik_offset + table_offset); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 228 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 229 | llvm::Value* value = GetLLVMValue(cu, rl_src.orig_sreg); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 230 | |
| 231 | llvm::SwitchInst* sw = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 232 | cu->irb->CreateSwitch(value, GetLLVMBlock(cu, bb->fall_through->id), |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 233 | payload->case_count); |
| 234 | |
| 235 | for (uint16_t i = 0; i < payload->case_count; ++i) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 236 | llvm::BasicBlock* llvm_bb = |
| 237 | FindCaseTarget(cu, cu->current_dalvik_offset + payload->targets[i]); |
| 238 | sw->addCase(cu->irb->getInt32(payload->first_key + i), llvm_bb); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 239 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 240 | llvm::MDNode* switch_node = |
| 241 | llvm::MDNode::get(*cu->context, cu->irb->getInt32(table_offset)); |
| 242 | sw->setMetadata("SwitchTable", switch_node); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 243 | bb->taken = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 244 | bb->fall_through = NULL; |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 245 | } |
| 246 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 247 | static void ConvertSparseSwitch(CompilationUnit* cu, BasicBlock* bb, |
| 248 | int32_t table_offset, RegLocation rl_src) |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 249 | { |
| 250 | const Instruction::SparseSwitchPayload* payload = |
| 251 | reinterpret_cast<const Instruction::SparseSwitchPayload*>( |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 252 | cu->insns + cu->current_dalvik_offset + table_offset); |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 253 | |
| 254 | const int32_t* keys = payload->GetKeys(); |
| 255 | const int32_t* targets = payload->GetTargets(); |
| 256 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 257 | llvm::Value* value = GetLLVMValue(cu, rl_src.orig_sreg); |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 258 | |
| 259 | llvm::SwitchInst* sw = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 260 | cu->irb->CreateSwitch(value, GetLLVMBlock(cu, bb->fall_through->id), |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 261 | payload->case_count); |
| 262 | |
| 263 | for (size_t i = 0; i < payload->case_count; ++i) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 264 | llvm::BasicBlock* llvm_bb = |
| 265 | FindCaseTarget(cu, cu->current_dalvik_offset + targets[i]); |
| 266 | sw->addCase(cu->irb->getInt32(keys[i]), llvm_bb); |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 267 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 268 | llvm::MDNode* switch_node = |
| 269 | llvm::MDNode::get(*cu->context, cu->irb->getInt32(table_offset)); |
| 270 | sw->setMetadata("SwitchTable", switch_node); |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 271 | bb->taken = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 272 | bb->fall_through = NULL; |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 273 | } |
| 274 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 275 | static void ConvertSget(CompilationUnit* cu, int32_t field_index, |
| 276 | greenland::IntrinsicHelper::IntrinsicId id, RegLocation rl_dest) |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 277 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 278 | llvm::Constant* field_idx = cu->irb->getInt32(field_index); |
| 279 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 280 | llvm::Value* res = cu->irb->CreateCall(intr, field_idx); |
| 281 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 282 | } |
| 283 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 284 | static void ConvertSput(CompilationUnit* cu, int32_t field_index, |
| 285 | greenland::IntrinsicHelper::IntrinsicId id, RegLocation rl_src) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 286 | { |
| 287 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 288 | args.push_back(cu->irb->getInt32(field_index)); |
| 289 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 290 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 291 | cu->irb->CreateCall(intr, args); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 292 | } |
| 293 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 294 | static void ConvertFillArrayData(CompilationUnit* cu, int32_t offset, RegLocation rl_array) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 295 | { |
| 296 | greenland::IntrinsicHelper::IntrinsicId id; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 297 | id = greenland::IntrinsicHelper::HLFillArrayData; |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 298 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 299 | args.push_back(cu->irb->getInt32(offset)); |
| 300 | args.push_back(GetLLVMValue(cu, rl_array.orig_sreg)); |
| 301 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 302 | cu->irb->CreateCall(intr, args); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 303 | } |
| 304 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 305 | static llvm::Value* EmitConst(CompilationUnit* cu, llvm::ArrayRef<llvm::Value*> src, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 306 | RegLocation loc) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 307 | { |
| 308 | greenland::IntrinsicHelper::IntrinsicId id; |
| 309 | if (loc.wide) { |
| 310 | if (loc.fp) { |
| 311 | id = greenland::IntrinsicHelper::ConstDouble; |
| 312 | } else { |
| 313 | id = greenland::IntrinsicHelper::ConstLong; |
| 314 | } |
| 315 | } else { |
| 316 | if (loc.fp) { |
| 317 | id = greenland::IntrinsicHelper::ConstFloat; |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 318 | } else if (loc.ref) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 319 | id = greenland::IntrinsicHelper::ConstObj; |
| 320 | } else { |
| 321 | id = greenland::IntrinsicHelper::ConstInt; |
| 322 | } |
| 323 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 324 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 325 | return cu->irb->CreateCall(intr, src); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 326 | } |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 327 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 328 | static void EmitPopShadowFrame(CompilationUnit* cu) |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 329 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 330 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction( |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 331 | greenland::IntrinsicHelper::PopShadowFrame); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 332 | cu->irb->CreateCall(intr); |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 333 | } |
| 334 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 335 | static llvm::Value* EmitCopy(CompilationUnit* cu, llvm::ArrayRef<llvm::Value*> src, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 336 | RegLocation loc) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 337 | { |
| 338 | greenland::IntrinsicHelper::IntrinsicId id; |
| 339 | if (loc.wide) { |
| 340 | if (loc.fp) { |
| 341 | id = greenland::IntrinsicHelper::CopyDouble; |
| 342 | } else { |
| 343 | id = greenland::IntrinsicHelper::CopyLong; |
| 344 | } |
| 345 | } else { |
| 346 | if (loc.fp) { |
| 347 | id = greenland::IntrinsicHelper::CopyFloat; |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 348 | } else if (loc.ref) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 349 | id = greenland::IntrinsicHelper::CopyObj; |
| 350 | } else { |
| 351 | id = greenland::IntrinsicHelper::CopyInt; |
| 352 | } |
| 353 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 354 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 355 | return cu->irb->CreateCall(intr, src); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 356 | } |
| 357 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 358 | static void ConvertMoveException(CompilationUnit* cu, RegLocation rl_dest) |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 359 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 360 | llvm::Function* func = cu->intrinsic_helper->GetIntrinsicFunction( |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 361 | greenland::IntrinsicHelper::GetException); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 362 | llvm::Value* res = cu->irb->CreateCall(func); |
| 363 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 364 | } |
| 365 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 366 | static void ConvertThrow(CompilationUnit* cu, RegLocation rl_src) |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 367 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 368 | llvm::Value* src = GetLLVMValue(cu, rl_src.orig_sreg); |
| 369 | llvm::Function* func = cu->intrinsic_helper->GetIntrinsicFunction( |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 370 | greenland::IntrinsicHelper::HLThrowException); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 371 | cu->irb->CreateCall(func, src); |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 372 | } |
| 373 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 374 | static void ConvertMonitorEnterExit(CompilationUnit* cu, int opt_flags, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 375 | greenland::IntrinsicHelper::IntrinsicId id, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 376 | RegLocation rl_src) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 377 | { |
| 378 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 379 | args.push_back(cu->irb->getInt32(opt_flags)); |
| 380 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 381 | llvm::Function* func = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 382 | cu->irb->CreateCall(func, args); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 383 | } |
| 384 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 385 | static void ConvertArrayLength(CompilationUnit* cu, int opt_flags, |
| 386 | RegLocation rl_dest, RegLocation rl_src) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 387 | { |
| 388 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 389 | args.push_back(cu->irb->getInt32(opt_flags)); |
| 390 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 391 | llvm::Function* func = cu->intrinsic_helper->GetIntrinsicFunction( |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 392 | greenland::IntrinsicHelper::OptArrayLength); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 393 | llvm::Value* res = cu->irb->CreateCall(func, args); |
| 394 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 395 | } |
| 396 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 397 | static void EmitSuspendCheck(CompilationUnit* cu) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 398 | { |
| 399 | greenland::IntrinsicHelper::IntrinsicId id = |
| 400 | greenland::IntrinsicHelper::CheckSuspend; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 401 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 402 | cu->irb->CreateCall(intr); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 403 | } |
| 404 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 405 | static llvm::Value* ConvertCompare(CompilationUnit* cu, ConditionCode cc, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 406 | llvm::Value* src1, llvm::Value* src2) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 407 | { |
| 408 | llvm::Value* res = NULL; |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 409 | DCHECK_EQ(src1->getType(), src2->getType()); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 410 | switch(cc) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 411 | case kCondEq: res = cu->irb->CreateICmpEQ(src1, src2); break; |
| 412 | case kCondNe: res = cu->irb->CreateICmpNE(src1, src2); break; |
| 413 | case kCondLt: res = cu->irb->CreateICmpSLT(src1, src2); break; |
| 414 | case kCondGe: res = cu->irb->CreateICmpSGE(src1, src2); break; |
| 415 | case kCondGt: res = cu->irb->CreateICmpSGT(src1, src2); break; |
| 416 | case kCondLe: res = cu->irb->CreateICmpSLE(src1, src2); break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 417 | default: LOG(FATAL) << "Unexpected cc value " << cc; |
| 418 | } |
| 419 | return res; |
| 420 | } |
| 421 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 422 | static void ConvertCompareAndBranch(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
| 423 | ConditionCode cc, RegLocation rl_src1, RegLocation rl_src2) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 424 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 425 | if (bb->taken->start_offset <= mir->offset) { |
| 426 | EmitSuspendCheck(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 427 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 428 | llvm::Value* src1 = GetLLVMValue(cu, rl_src1.orig_sreg); |
| 429 | llvm::Value* src2 = GetLLVMValue(cu, rl_src2.orig_sreg); |
| 430 | llvm::Value* cond_value = ConvertCompare(cu, cc, src1, src2); |
| 431 | cond_value->setName(StringPrintf("t%d", cu->temp_name++)); |
| 432 | cu->irb->CreateCondBr(cond_value, GetLLVMBlock(cu, bb->taken->id), |
| 433 | GetLLVMBlock(cu, bb->fall_through->id)); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 434 | // Don't redo the fallthrough branch in the BB driver |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 435 | bb->fall_through = NULL; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 436 | } |
| 437 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 438 | static void ConvertCompareZeroAndBranch(CompilationUnit* cu, BasicBlock* bb, |
| 439 | MIR* mir, ConditionCode cc, RegLocation rl_src1) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 440 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 441 | if (bb->taken->start_offset <= mir->offset) { |
| 442 | EmitSuspendCheck(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 443 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 444 | llvm::Value* src1 = GetLLVMValue(cu, rl_src1.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 445 | llvm::Value* src2; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 446 | if (rl_src1.ref) { |
| 447 | src2 = cu->irb->GetJNull(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 448 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 449 | src2 = cu->irb->getInt32(0); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 450 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 451 | llvm::Value* cond_value = ConvertCompare(cu, cc, src1, src2); |
| 452 | cu->irb->CreateCondBr(cond_value, GetLLVMBlock(cu, bb->taken->id), |
| 453 | GetLLVMBlock(cu, bb->fall_through->id)); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 454 | // Don't redo the fallthrough branch in the BB driver |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 455 | bb->fall_through = NULL; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 456 | } |
| 457 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 458 | static llvm::Value* GenDivModOp(CompilationUnit* cu, bool is_div, bool is_long, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 459 | llvm::Value* src1, llvm::Value* src2) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 460 | { |
| 461 | greenland::IntrinsicHelper::IntrinsicId id; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 462 | if (is_long) { |
| 463 | if (is_div) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 464 | id = greenland::IntrinsicHelper::DivLong; |
| 465 | } else { |
| 466 | id = greenland::IntrinsicHelper::RemLong; |
| 467 | } |
Logan Chien | 554e607 | 2012-07-23 20:00:01 -0700 | [diff] [blame] | 468 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 469 | if (is_div) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 470 | id = greenland::IntrinsicHelper::DivInt; |
| 471 | } else { |
| 472 | id = greenland::IntrinsicHelper::RemInt; |
Logan Chien | 554e607 | 2012-07-23 20:00:01 -0700 | [diff] [blame] | 473 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 474 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 475 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 476 | llvm::SmallVector<llvm::Value*, 2>args; |
| 477 | args.push_back(src1); |
| 478 | args.push_back(src2); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 479 | return cu->irb->CreateCall(intr, args); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 480 | } |
| 481 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 482 | static llvm::Value* GenArithOp(CompilationUnit* cu, OpKind op, bool is_long, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 483 | llvm::Value* src1, llvm::Value* src2) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 484 | { |
| 485 | llvm::Value* res = NULL; |
| 486 | switch(op) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 487 | case kOpAdd: res = cu->irb->CreateAdd(src1, src2); break; |
| 488 | case kOpSub: res = cu->irb->CreateSub(src1, src2); break; |
| 489 | case kOpRsub: res = cu->irb->CreateSub(src2, src1); break; |
| 490 | case kOpMul: res = cu->irb->CreateMul(src1, src2); break; |
| 491 | case kOpOr: res = cu->irb->CreateOr(src1, src2); break; |
| 492 | case kOpAnd: res = cu->irb->CreateAnd(src1, src2); break; |
| 493 | case kOpXor: res = cu->irb->CreateXor(src1, src2); break; |
| 494 | case kOpDiv: res = GenDivModOp(cu, true, is_long, src1, src2); break; |
| 495 | case kOpRem: res = GenDivModOp(cu, false, is_long, src1, src2); break; |
| 496 | case kOpLsl: res = cu->irb->CreateShl(src1, src2); break; |
| 497 | case kOpLsr: res = cu->irb->CreateLShr(src1, src2); break; |
| 498 | case kOpAsr: res = cu->irb->CreateAShr(src1, src2); break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 499 | default: |
| 500 | LOG(FATAL) << "Invalid op " << op; |
| 501 | } |
| 502 | return res; |
| 503 | } |
| 504 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 505 | static void ConvertFPArithOp(CompilationUnit* cu, OpKind op, RegLocation rl_dest, |
| 506 | RegLocation rl_src1, RegLocation rl_src2) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 507 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 508 | llvm::Value* src1 = GetLLVMValue(cu, rl_src1.orig_sreg); |
| 509 | llvm::Value* src2 = GetLLVMValue(cu, rl_src2.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 510 | llvm::Value* res = NULL; |
| 511 | switch(op) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 512 | case kOpAdd: res = cu->irb->CreateFAdd(src1, src2); break; |
| 513 | case kOpSub: res = cu->irb->CreateFSub(src1, src2); break; |
| 514 | case kOpMul: res = cu->irb->CreateFMul(src1, src2); break; |
| 515 | case kOpDiv: res = cu->irb->CreateFDiv(src1, src2); break; |
| 516 | case kOpRem: res = cu->irb->CreateFRem(src1, src2); break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 517 | default: |
| 518 | LOG(FATAL) << "Invalid op " << op; |
| 519 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 520 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 521 | } |
| 522 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 523 | static void ConvertShift(CompilationUnit* cu, greenland::IntrinsicHelper::IntrinsicId id, |
| 524 | RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 525 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 526 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 527 | llvm::SmallVector<llvm::Value*, 2>args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 528 | args.push_back(GetLLVMValue(cu, rl_src1.orig_sreg)); |
| 529 | args.push_back(GetLLVMValue(cu, rl_src2.orig_sreg)); |
| 530 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
| 531 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 532 | } |
| 533 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 534 | static void ConvertShiftLit(CompilationUnit* cu, greenland::IntrinsicHelper::IntrinsicId id, |
| 535 | RegLocation rl_dest, RegLocation rl_src, int shift_amount) |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 536 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 537 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 538 | llvm::SmallVector<llvm::Value*, 2>args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 539 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 540 | args.push_back(cu->irb->getInt32(shift_amount)); |
| 541 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
| 542 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 543 | } |
| 544 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 545 | static void ConvertArithOp(CompilationUnit* cu, OpKind op, RegLocation rl_dest, |
| 546 | RegLocation rl_src1, RegLocation rl_src2) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 547 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 548 | llvm::Value* src1 = GetLLVMValue(cu, rl_src1.orig_sreg); |
| 549 | llvm::Value* src2 = GetLLVMValue(cu, rl_src2.orig_sreg); |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 550 | DCHECK_EQ(src1->getType(), src2->getType()); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 551 | llvm::Value* res = GenArithOp(cu, op, rl_dest.wide, src1, src2); |
| 552 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 553 | } |
| 554 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 555 | static void ConvertArithOpLit(CompilationUnit* cu, OpKind op, RegLocation rl_dest, |
| 556 | RegLocation rl_src1, int32_t imm) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 557 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 558 | llvm::Value* src1 = GetLLVMValue(cu, rl_src1.orig_sreg); |
| 559 | llvm::Value* src2 = cu->irb->getInt32(imm); |
| 560 | llvm::Value* res = GenArithOp(cu, op, rl_dest.wide, src1, src2); |
| 561 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 562 | } |
| 563 | |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 564 | /* |
| 565 | * Process arguments for invoke. Note: this code is also used to |
| 566 | * collect and process arguments for NEW_FILLED_ARRAY and NEW_FILLED_ARRAY_RANGE. |
| 567 | * The requirements are similar. |
| 568 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 569 | static void ConvertInvoke(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
| 570 | InvokeType invoke_type, bool is_range, bool is_filled_new_array) |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 571 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 572 | Codegen* cg = cu->cg.get(); |
| 573 | CallInfo* info = cg->NewMemCallInfo(cu, bb, mir, invoke_type, is_range); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 574 | llvm::SmallVector<llvm::Value*, 10> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 575 | // Insert the invoke_type |
| 576 | args.push_back(cu->irb->getInt32(static_cast<int>(invoke_type))); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 577 | // Insert the method_idx |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 578 | args.push_back(cu->irb->getInt32(info->index)); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 579 | // Insert the optimization flags |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 580 | args.push_back(cu->irb->getInt32(info->opt_flags)); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 581 | // Now, insert the actual arguments |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 582 | for (int i = 0; i < info->num_arg_words;) { |
| 583 | llvm::Value* val = GetLLVMValue(cu, info->args[i].orig_sreg); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 584 | args.push_back(val); |
| 585 | i += info->args[i].wide ? 2 : 1; |
| 586 | } |
| 587 | /* |
| 588 | * Choose the invoke return type based on actual usage. Note: may |
| 589 | * be different than shorty. For example, if a function return value |
| 590 | * is not used, we'll treat this as a void invoke. |
| 591 | */ |
| 592 | greenland::IntrinsicHelper::IntrinsicId id; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 593 | if (is_filled_new_array) { |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 594 | id = greenland::IntrinsicHelper::HLFilledNewArray; |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 595 | } else if (info->result.location == kLocInvalid) { |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 596 | id = greenland::IntrinsicHelper::HLInvokeVoid; |
| 597 | } else { |
| 598 | if (info->result.wide) { |
| 599 | if (info->result.fp) { |
| 600 | id = greenland::IntrinsicHelper::HLInvokeDouble; |
| 601 | } else { |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 602 | id = greenland::IntrinsicHelper::HLInvokeLong; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 603 | } |
| 604 | } else if (info->result.ref) { |
| 605 | id = greenland::IntrinsicHelper::HLInvokeObj; |
| 606 | } else if (info->result.fp) { |
| 607 | id = greenland::IntrinsicHelper::HLInvokeFloat; |
| 608 | } else { |
| 609 | id = greenland::IntrinsicHelper::HLInvokeInt; |
| 610 | } |
| 611 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 612 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 613 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 614 | if (info->result.location != kLocInvalid) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 615 | DefineValue(cu, res, info->result.orig_sreg); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 619 | static void ConvertConstObject(CompilationUnit* cu, uint32_t idx, |
| 620 | greenland::IntrinsicHelper::IntrinsicId id, RegLocation rl_dest) |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 621 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 622 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 623 | llvm::Value* index = cu->irb->getInt32(idx); |
| 624 | llvm::Value* res = cu->irb->CreateCall(intr, index); |
| 625 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 626 | } |
| 627 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 628 | static void ConvertCheckCast(CompilationUnit* cu, uint32_t type_idx, RegLocation rl_src) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 629 | { |
| 630 | greenland::IntrinsicHelper::IntrinsicId id; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 631 | id = greenland::IntrinsicHelper::HLCheckCast; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 632 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 633 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 634 | args.push_back(cu->irb->getInt32(type_idx)); |
| 635 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 636 | cu->irb->CreateCall(intr, args); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 637 | } |
| 638 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 639 | static void ConvertNewInstance(CompilationUnit* cu, uint32_t type_idx, RegLocation rl_dest) |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 640 | { |
| 641 | greenland::IntrinsicHelper::IntrinsicId id; |
| 642 | id = greenland::IntrinsicHelper::NewInstance; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 643 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 644 | llvm::Value* index = cu->irb->getInt32(type_idx); |
| 645 | llvm::Value* res = cu->irb->CreateCall(intr, index); |
| 646 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 647 | } |
| 648 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 649 | static void ConvertNewArray(CompilationUnit* cu, uint32_t type_idx, |
| 650 | RegLocation rl_dest, RegLocation rl_src) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 651 | { |
| 652 | greenland::IntrinsicHelper::IntrinsicId id; |
| 653 | id = greenland::IntrinsicHelper::NewArray; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 654 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 655 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 656 | args.push_back(cu->irb->getInt32(type_idx)); |
| 657 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 658 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
| 659 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 660 | } |
| 661 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 662 | static void ConvertAget(CompilationUnit* cu, int opt_flags, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 663 | greenland::IntrinsicHelper::IntrinsicId id, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 664 | RegLocation rl_dest, RegLocation rl_array, RegLocation rl_index) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 665 | { |
| 666 | llvm::SmallVector<llvm::Value*, 3> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 667 | args.push_back(cu->irb->getInt32(opt_flags)); |
| 668 | args.push_back(GetLLVMValue(cu, rl_array.orig_sreg)); |
| 669 | args.push_back(GetLLVMValue(cu, rl_index.orig_sreg)); |
| 670 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 671 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
| 672 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 673 | } |
| 674 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 675 | static void ConvertAput(CompilationUnit* cu, int opt_flags, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 676 | greenland::IntrinsicHelper::IntrinsicId id, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 677 | RegLocation rl_src, RegLocation rl_array, RegLocation rl_index) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 678 | { |
| 679 | llvm::SmallVector<llvm::Value*, 4> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 680 | args.push_back(cu->irb->getInt32(opt_flags)); |
| 681 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 682 | args.push_back(GetLLVMValue(cu, rl_array.orig_sreg)); |
| 683 | args.push_back(GetLLVMValue(cu, rl_index.orig_sreg)); |
| 684 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 685 | cu->irb->CreateCall(intr, args); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 686 | } |
| 687 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 688 | static void ConvertIget(CompilationUnit* cu, int opt_flags, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 689 | greenland::IntrinsicHelper::IntrinsicId id, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 690 | RegLocation rl_dest, RegLocation rl_obj, int field_index) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 691 | { |
| 692 | llvm::SmallVector<llvm::Value*, 3> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 693 | args.push_back(cu->irb->getInt32(opt_flags)); |
| 694 | args.push_back(GetLLVMValue(cu, rl_obj.orig_sreg)); |
| 695 | args.push_back(cu->irb->getInt32(field_index)); |
| 696 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 697 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
| 698 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 699 | } |
| 700 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 701 | static void ConvertIput(CompilationUnit* cu, int opt_flags, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 702 | greenland::IntrinsicHelper::IntrinsicId id, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 703 | RegLocation rl_src, RegLocation rl_obj, int field_index) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 704 | { |
| 705 | llvm::SmallVector<llvm::Value*, 4> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 706 | args.push_back(cu->irb->getInt32(opt_flags)); |
| 707 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 708 | args.push_back(GetLLVMValue(cu, rl_obj.orig_sreg)); |
| 709 | args.push_back(cu->irb->getInt32(field_index)); |
| 710 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 711 | cu->irb->CreateCall(intr, args); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 712 | } |
| 713 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 714 | static void ConvertInstanceOf(CompilationUnit* cu, uint32_t type_idx, |
| 715 | RegLocation rl_dest, RegLocation rl_src) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 716 | { |
| 717 | greenland::IntrinsicHelper::IntrinsicId id; |
| 718 | id = greenland::IntrinsicHelper::InstanceOf; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 719 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 720 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 721 | args.push_back(cu->irb->getInt32(type_idx)); |
| 722 | args.push_back(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 723 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
| 724 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 725 | } |
| 726 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 727 | static void ConvertIntToLong(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 728 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 729 | llvm::Value* res = cu->irb->CreateSExt(GetLLVMValue(cu, rl_src.orig_sreg), |
| 730 | cu->irb->getInt64Ty()); |
| 731 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 732 | } |
| 733 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 734 | static void ConvertLongToInt(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 735 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 736 | llvm::Value* src = GetLLVMValue(cu, rl_src.orig_sreg); |
| 737 | llvm::Value* res = cu->irb->CreateTrunc(src, cu->irb->getInt32Ty()); |
| 738 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 739 | } |
| 740 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 741 | static void ConvertFloatToDouble(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 742 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 743 | llvm::Value* src = GetLLVMValue(cu, rl_src.orig_sreg); |
| 744 | llvm::Value* res = cu->irb->CreateFPExt(src, cu->irb->getDoubleTy()); |
| 745 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 746 | } |
| 747 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 748 | static void ConvertDoubleToFloat(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 749 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 750 | llvm::Value* src = GetLLVMValue(cu, rl_src.orig_sreg); |
| 751 | llvm::Value* res = cu->irb->CreateFPTrunc(src, cu->irb->getFloatTy()); |
| 752 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 753 | } |
| 754 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 755 | static void ConvertWideComparison(CompilationUnit* cu, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 756 | greenland::IntrinsicHelper::IntrinsicId id, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 757 | RegLocation rl_dest, RegLocation rl_src1, |
| 758 | RegLocation rl_src2) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 759 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 760 | DCHECK_EQ(rl_src1.fp, rl_src2.fp); |
| 761 | DCHECK_EQ(rl_src1.wide, rl_src2.wide); |
| 762 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 763 | llvm::SmallVector<llvm::Value*, 2> args; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 764 | args.push_back(GetLLVMValue(cu, rl_src1.orig_sreg)); |
| 765 | args.push_back(GetLLVMValue(cu, rl_src2.orig_sreg)); |
| 766 | llvm::Value* res = cu->irb->CreateCall(intr, args); |
| 767 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 768 | } |
| 769 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 770 | static void ConvertIntNarrowing(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 771 | greenland::IntrinsicHelper::IntrinsicId id) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 772 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 773 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 774 | llvm::Value* res = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 775 | cu->irb->CreateCall(intr, GetLLVMValue(cu, rl_src.orig_sreg)); |
| 776 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 777 | } |
| 778 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 779 | static void ConvertNeg(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 780 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 781 | llvm::Value* res = cu->irb->CreateNeg(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 782 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 783 | } |
| 784 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 785 | static void ConvertIntToFP(CompilationUnit* cu, llvm::Type* ty, RegLocation rl_dest, |
| 786 | RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 787 | { |
| 788 | llvm::Value* res = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 789 | cu->irb->CreateSIToFP(GetLLVMValue(cu, rl_src.orig_sreg), ty); |
| 790 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 791 | } |
| 792 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 793 | static void ConvertFPToInt(CompilationUnit* cu, greenland::IntrinsicHelper::IntrinsicId id, |
| 794 | RegLocation rl_dest, |
| 795 | RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 796 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 797 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 798 | llvm::Value* res = cu->irb->CreateCall(intr, GetLLVMValue(cu, rl_src.orig_sreg)); |
| 799 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 803 | static void ConvertNegFP(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 804 | { |
| 805 | llvm::Value* res = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 806 | cu->irb->CreateFNeg(GetLLVMValue(cu, rl_src.orig_sreg)); |
| 807 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 808 | } |
| 809 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 810 | static void ConvertNot(CompilationUnit* cu, RegLocation rl_dest, RegLocation rl_src) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 811 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 812 | llvm::Value* src = GetLLVMValue(cu, rl_src.orig_sreg); |
| 813 | llvm::Value* res = cu->irb->CreateXor(src, static_cast<uint64_t>(-1)); |
| 814 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 815 | } |
| 816 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 817 | /* |
| 818 | * Target-independent code generation. Use only high-level |
| 819 | * load/store utilities here, or target-dependent genXX() handlers |
| 820 | * when necessary. |
| 821 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 822 | static bool ConvertMIRNode(CompilationUnit* cu, MIR* mir, BasicBlock* bb, |
| 823 | llvm::BasicBlock* llvm_bb, LIR* label_list) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 824 | { |
| 825 | bool res = false; // Assume success |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 826 | RegLocation rl_src[3]; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 827 | RegLocation rl_dest = GetBadLoc(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 828 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 829 | int op_val = opcode; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 830 | uint32_t vB = mir->dalvikInsn.vB; |
| 831 | uint32_t vC = mir->dalvikInsn.vC; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 832 | int opt_flags = mir->optimization_flags; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 833 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 834 | if (cu->verbose) { |
| 835 | if (op_val < kMirOpFirst) { |
| 836 | LOG(INFO) << ".. " << Instruction::Name(opcode) << " 0x" << std::hex << op_val; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 837 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 838 | LOG(INFO) << extended_mir_op_names[op_val - kMirOpFirst] << " 0x" << std::hex << op_val; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 842 | /* Prep Src and Dest locations */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 843 | int next_sreg = 0; |
| 844 | int next_loc = 0; |
| 845 | int attrs = oat_data_flow_attributes[opcode]; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 846 | rl_src[0] = rl_src[1] = rl_src[2] = GetBadLoc(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 847 | if (attrs & DF_UA) { |
| 848 | if (attrs & DF_A_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 849 | rl_src[next_loc++] = GetSrcWide(cu, mir, next_sreg); |
| 850 | next_sreg+= 2; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 851 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 852 | rl_src[next_loc++] = GetSrc(cu, mir, next_sreg); |
| 853 | next_sreg++; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | if (attrs & DF_UB) { |
| 857 | if (attrs & DF_B_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 858 | rl_src[next_loc++] = GetSrcWide(cu, mir, next_sreg); |
| 859 | next_sreg+= 2; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 860 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 861 | rl_src[next_loc++] = GetSrc(cu, mir, next_sreg); |
| 862 | next_sreg++; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | if (attrs & DF_UC) { |
| 866 | if (attrs & DF_C_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 867 | rl_src[next_loc++] = GetSrcWide(cu, mir, next_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 868 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 869 | rl_src[next_loc++] = GetSrc(cu, mir, next_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | if (attrs & DF_DA) { |
| 873 | if (attrs & DF_A_WIDE) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 874 | rl_dest = GetDestWide(cu, mir); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 875 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 876 | rl_dest = GetDest(cu, mir); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | switch (opcode) { |
| 881 | case Instruction::NOP: |
| 882 | break; |
| 883 | |
| 884 | case Instruction::MOVE: |
| 885 | case Instruction::MOVE_OBJECT: |
| 886 | case Instruction::MOVE_16: |
| 887 | case Instruction::MOVE_OBJECT_16: |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 888 | case Instruction::MOVE_OBJECT_FROM16: |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 889 | case Instruction::MOVE_FROM16: |
| 890 | case Instruction::MOVE_WIDE: |
| 891 | case Instruction::MOVE_WIDE_16: |
| 892 | case Instruction::MOVE_WIDE_FROM16: { |
| 893 | /* |
| 894 | * Moves/copies are meaningless in pure SSA register form, |
| 895 | * but we need to preserve them for the conversion back into |
| 896 | * MIR (at least until we stop using the Dalvik register maps). |
| 897 | * Insert a dummy intrinsic copy call, which will be recognized |
| 898 | * by the quick path and removed by the portable path. |
| 899 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 900 | llvm::Value* src = GetLLVMValue(cu, rl_src[0].orig_sreg); |
| 901 | llvm::Value* res = EmitCopy(cu, src, rl_dest); |
| 902 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 903 | } |
| 904 | break; |
| 905 | |
| 906 | case Instruction::CONST: |
| 907 | case Instruction::CONST_4: |
| 908 | case Instruction::CONST_16: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 909 | llvm::Constant* imm_value = cu->irb->GetJInt(vB); |
| 910 | llvm::Value* res = EmitConst(cu, imm_value, rl_dest); |
| 911 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 912 | } |
| 913 | break; |
| 914 | |
| 915 | case Instruction::CONST_WIDE_16: |
| 916 | case Instruction::CONST_WIDE_32: { |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 917 | // Sign extend to 64 bits |
| 918 | int64_t imm = static_cast<int32_t>(vB); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 919 | llvm::Constant* imm_value = cu->irb->GetJLong(imm); |
| 920 | llvm::Value* res = EmitConst(cu, imm_value, rl_dest); |
| 921 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 922 | } |
| 923 | break; |
| 924 | |
| 925 | case Instruction::CONST_HIGH16: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 926 | llvm::Constant* imm_value = cu->irb->GetJInt(vB << 16); |
| 927 | llvm::Value* res = EmitConst(cu, imm_value, rl_dest); |
| 928 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 929 | } |
| 930 | break; |
| 931 | |
| 932 | case Instruction::CONST_WIDE: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 933 | llvm::Constant* imm_value = |
| 934 | cu->irb->GetJLong(mir->dalvikInsn.vB_wide); |
| 935 | llvm::Value* res = EmitConst(cu, imm_value, rl_dest); |
| 936 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 937 | } |
| 938 | break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 939 | case Instruction::CONST_WIDE_HIGH16: { |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 940 | int64_t imm = static_cast<int64_t>(vB) << 48; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 941 | llvm::Constant* imm_value = cu->irb->GetJLong(imm); |
| 942 | llvm::Value* res = EmitConst(cu, imm_value, rl_dest); |
| 943 | DefineValue(cu, res, rl_dest.orig_sreg); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 944 | } |
| 945 | break; |
| 946 | |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 947 | case Instruction::SPUT_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 948 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputObject, |
| 949 | rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 950 | break; |
| 951 | case Instruction::SPUT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 952 | if (rl_src[0].fp) { |
| 953 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputFloat, |
| 954 | rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 955 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 956 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSput, rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 957 | } |
| 958 | break; |
| 959 | case Instruction::SPUT_BOOLEAN: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 960 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputBoolean, |
| 961 | rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 962 | break; |
| 963 | case Instruction::SPUT_BYTE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 964 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputByte, rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 965 | break; |
| 966 | case Instruction::SPUT_CHAR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 967 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputChar, rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 968 | break; |
| 969 | case Instruction::SPUT_SHORT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 970 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputShort, rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 971 | break; |
| 972 | case Instruction::SPUT_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 973 | if (rl_src[0].fp) { |
| 974 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputDouble, |
| 975 | rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 976 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 977 | ConvertSput(cu, vB, greenland::IntrinsicHelper::HLSputWide, |
| 978 | rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 979 | } |
| 980 | break; |
| 981 | |
| 982 | case Instruction::SGET_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 983 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetObject, rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 984 | break; |
| 985 | case Instruction::SGET: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 986 | if (rl_dest.fp) { |
| 987 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetFloat, rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 988 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 989 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSget, rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 990 | } |
| 991 | break; |
| 992 | case Instruction::SGET_BOOLEAN: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 993 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetBoolean, rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 994 | break; |
| 995 | case Instruction::SGET_BYTE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 996 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetByte, rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 997 | break; |
| 998 | case Instruction::SGET_CHAR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 999 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetChar, rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1000 | break; |
| 1001 | case Instruction::SGET_SHORT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1002 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetShort, rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1003 | break; |
| 1004 | case Instruction::SGET_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1005 | if (rl_dest.fp) { |
| 1006 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetDouble, |
| 1007 | rl_dest); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1008 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1009 | ConvertSget(cu, vB, greenland::IntrinsicHelper::HLSgetWide, rl_dest); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 1010 | } |
| 1011 | break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1012 | |
| 1013 | case Instruction::RETURN_WIDE: |
| 1014 | case Instruction::RETURN: |
| 1015 | case Instruction::RETURN_OBJECT: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1016 | if (!(cu->attrs & METHOD_IS_LEAF)) { |
| 1017 | EmitSuspendCheck(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1018 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1019 | EmitPopShadowFrame(cu); |
| 1020 | cu->irb->CreateRet(GetLLVMValue(cu, rl_src[0].orig_sreg)); |
buzbee | 34b8c98 | 2013-02-06 17:43:42 -0800 | [diff] [blame] | 1021 | bb->has_return = true; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1022 | } |
| 1023 | break; |
| 1024 | |
| 1025 | case Instruction::RETURN_VOID: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1026 | if (!(cu->attrs & METHOD_IS_LEAF)) { |
| 1027 | EmitSuspendCheck(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1028 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1029 | EmitPopShadowFrame(cu); |
| 1030 | cu->irb->CreateRetVoid(); |
buzbee | 34b8c98 | 2013-02-06 17:43:42 -0800 | [diff] [blame] | 1031 | bb->has_return = true; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1032 | } |
| 1033 | break; |
| 1034 | |
| 1035 | case Instruction::IF_EQ: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1036 | ConvertCompareAndBranch(cu, bb, mir, kCondEq, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1037 | break; |
| 1038 | case Instruction::IF_NE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1039 | ConvertCompareAndBranch(cu, bb, mir, kCondNe, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1040 | break; |
| 1041 | case Instruction::IF_LT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1042 | ConvertCompareAndBranch(cu, bb, mir, kCondLt, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1043 | break; |
| 1044 | case Instruction::IF_GE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1045 | ConvertCompareAndBranch(cu, bb, mir, kCondGe, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1046 | break; |
| 1047 | case Instruction::IF_GT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1048 | ConvertCompareAndBranch(cu, bb, mir, kCondGt, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1049 | break; |
| 1050 | case Instruction::IF_LE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1051 | ConvertCompareAndBranch(cu, bb, mir, kCondLe, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1052 | break; |
| 1053 | case Instruction::IF_EQZ: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1054 | ConvertCompareZeroAndBranch(cu, bb, mir, kCondEq, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1055 | break; |
| 1056 | case Instruction::IF_NEZ: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1057 | ConvertCompareZeroAndBranch(cu, bb, mir, kCondNe, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1058 | break; |
| 1059 | case Instruction::IF_LTZ: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1060 | ConvertCompareZeroAndBranch(cu, bb, mir, kCondLt, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1061 | break; |
| 1062 | case Instruction::IF_GEZ: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1063 | ConvertCompareZeroAndBranch(cu, bb, mir, kCondGe, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1064 | break; |
| 1065 | case Instruction::IF_GTZ: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1066 | ConvertCompareZeroAndBranch(cu, bb, mir, kCondGt, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1067 | break; |
| 1068 | case Instruction::IF_LEZ: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1069 | ConvertCompareZeroAndBranch(cu, bb, mir, kCondLe, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1070 | break; |
| 1071 | |
| 1072 | case Instruction::GOTO: |
| 1073 | case Instruction::GOTO_16: |
| 1074 | case Instruction::GOTO_32: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1075 | if (bb->taken->start_offset <= bb->start_offset) { |
| 1076 | EmitSuspendCheck(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1077 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1078 | cu->irb->CreateBr(GetLLVMBlock(cu, bb->taken->id)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1079 | } |
| 1080 | break; |
| 1081 | |
| 1082 | case Instruction::ADD_LONG: |
| 1083 | case Instruction::ADD_LONG_2ADDR: |
| 1084 | case Instruction::ADD_INT: |
| 1085 | case Instruction::ADD_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1086 | ConvertArithOp(cu, kOpAdd, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1087 | break; |
| 1088 | case Instruction::SUB_LONG: |
| 1089 | case Instruction::SUB_LONG_2ADDR: |
| 1090 | case Instruction::SUB_INT: |
| 1091 | case Instruction::SUB_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1092 | ConvertArithOp(cu, kOpSub, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1093 | break; |
| 1094 | case Instruction::MUL_LONG: |
| 1095 | case Instruction::MUL_LONG_2ADDR: |
| 1096 | case Instruction::MUL_INT: |
| 1097 | case Instruction::MUL_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1098 | ConvertArithOp(cu, kOpMul, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1099 | break; |
| 1100 | case Instruction::DIV_LONG: |
| 1101 | case Instruction::DIV_LONG_2ADDR: |
| 1102 | case Instruction::DIV_INT: |
| 1103 | case Instruction::DIV_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1104 | ConvertArithOp(cu, kOpDiv, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1105 | break; |
| 1106 | case Instruction::REM_LONG: |
| 1107 | case Instruction::REM_LONG_2ADDR: |
| 1108 | case Instruction::REM_INT: |
| 1109 | case Instruction::REM_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1110 | ConvertArithOp(cu, kOpRem, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1111 | break; |
| 1112 | case Instruction::AND_LONG: |
| 1113 | case Instruction::AND_LONG_2ADDR: |
| 1114 | case Instruction::AND_INT: |
| 1115 | case Instruction::AND_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1116 | ConvertArithOp(cu, kOpAnd, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1117 | break; |
| 1118 | case Instruction::OR_LONG: |
| 1119 | case Instruction::OR_LONG_2ADDR: |
| 1120 | case Instruction::OR_INT: |
| 1121 | case Instruction::OR_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1122 | ConvertArithOp(cu, kOpOr, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1123 | break; |
| 1124 | case Instruction::XOR_LONG: |
| 1125 | case Instruction::XOR_LONG_2ADDR: |
| 1126 | case Instruction::XOR_INT: |
| 1127 | case Instruction::XOR_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1128 | ConvertArithOp(cu, kOpXor, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1129 | break; |
| 1130 | case Instruction::SHL_LONG: |
| 1131 | case Instruction::SHL_LONG_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1132 | ConvertShift(cu, greenland::IntrinsicHelper::SHLLong, |
| 1133 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 1134 | break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1135 | case Instruction::SHL_INT: |
| 1136 | case Instruction::SHL_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1137 | ConvertShift(cu, greenland::IntrinsicHelper::SHLInt, |
| 1138 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1139 | break; |
| 1140 | case Instruction::SHR_LONG: |
| 1141 | case Instruction::SHR_LONG_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1142 | ConvertShift(cu, greenland::IntrinsicHelper::SHRLong, |
| 1143 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 1144 | break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1145 | case Instruction::SHR_INT: |
| 1146 | case Instruction::SHR_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1147 | ConvertShift(cu, greenland::IntrinsicHelper::SHRInt, |
| 1148 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1149 | break; |
| 1150 | case Instruction::USHR_LONG: |
| 1151 | case Instruction::USHR_LONG_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1152 | ConvertShift(cu, greenland::IntrinsicHelper::USHRLong, |
| 1153 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 1154 | break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1155 | case Instruction::USHR_INT: |
| 1156 | case Instruction::USHR_INT_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1157 | ConvertShift(cu, greenland::IntrinsicHelper::USHRInt, |
| 1158 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1159 | break; |
| 1160 | |
| 1161 | case Instruction::ADD_INT_LIT16: |
| 1162 | case Instruction::ADD_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1163 | ConvertArithOpLit(cu, kOpAdd, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | case Instruction::RSUB_INT: |
| 1166 | case Instruction::RSUB_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1167 | ConvertArithOpLit(cu, kOpRsub, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1168 | break; |
| 1169 | case Instruction::MUL_INT_LIT16: |
| 1170 | case Instruction::MUL_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1171 | ConvertArithOpLit(cu, kOpMul, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1172 | break; |
| 1173 | case Instruction::DIV_INT_LIT16: |
| 1174 | case Instruction::DIV_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1175 | ConvertArithOpLit(cu, kOpDiv, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1176 | break; |
| 1177 | case Instruction::REM_INT_LIT16: |
| 1178 | case Instruction::REM_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1179 | ConvertArithOpLit(cu, kOpRem, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | case Instruction::AND_INT_LIT16: |
| 1182 | case Instruction::AND_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1183 | ConvertArithOpLit(cu, kOpAnd, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1184 | break; |
| 1185 | case Instruction::OR_INT_LIT16: |
| 1186 | case Instruction::OR_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1187 | ConvertArithOpLit(cu, kOpOr, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1188 | break; |
| 1189 | case Instruction::XOR_INT_LIT16: |
| 1190 | case Instruction::XOR_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1191 | ConvertArithOpLit(cu, kOpXor, rl_dest, rl_src[0], vC); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1192 | break; |
| 1193 | case Instruction::SHL_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1194 | ConvertShiftLit(cu, greenland::IntrinsicHelper::SHLInt, |
| 1195 | rl_dest, rl_src[0], vC & 0x1f); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1196 | break; |
| 1197 | case Instruction::SHR_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1198 | ConvertShiftLit(cu, greenland::IntrinsicHelper::SHRInt, |
| 1199 | rl_dest, rl_src[0], vC & 0x1f); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1200 | break; |
| 1201 | case Instruction::USHR_INT_LIT8: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1202 | ConvertShiftLit(cu, greenland::IntrinsicHelper::USHRInt, |
| 1203 | rl_dest, rl_src[0], vC & 0x1f); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1204 | break; |
| 1205 | |
| 1206 | case Instruction::ADD_FLOAT: |
| 1207 | case Instruction::ADD_FLOAT_2ADDR: |
| 1208 | case Instruction::ADD_DOUBLE: |
| 1209 | case Instruction::ADD_DOUBLE_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1210 | ConvertFPArithOp(cu, kOpAdd, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1211 | break; |
| 1212 | |
| 1213 | case Instruction::SUB_FLOAT: |
| 1214 | case Instruction::SUB_FLOAT_2ADDR: |
| 1215 | case Instruction::SUB_DOUBLE: |
| 1216 | case Instruction::SUB_DOUBLE_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1217 | ConvertFPArithOp(cu, kOpSub, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1218 | break; |
| 1219 | |
| 1220 | case Instruction::MUL_FLOAT: |
| 1221 | case Instruction::MUL_FLOAT_2ADDR: |
| 1222 | case Instruction::MUL_DOUBLE: |
| 1223 | case Instruction::MUL_DOUBLE_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1224 | ConvertFPArithOp(cu, kOpMul, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1225 | break; |
| 1226 | |
| 1227 | case Instruction::DIV_FLOAT: |
| 1228 | case Instruction::DIV_FLOAT_2ADDR: |
| 1229 | case Instruction::DIV_DOUBLE: |
| 1230 | case Instruction::DIV_DOUBLE_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1231 | ConvertFPArithOp(cu, kOpDiv, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1232 | break; |
| 1233 | |
| 1234 | case Instruction::REM_FLOAT: |
| 1235 | case Instruction::REM_FLOAT_2ADDR: |
| 1236 | case Instruction::REM_DOUBLE: |
| 1237 | case Instruction::REM_DOUBLE_2ADDR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1238 | ConvertFPArithOp(cu, kOpRem, rl_dest, rl_src[0], rl_src[1]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1241 | case Instruction::INVOKE_STATIC: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1242 | ConvertInvoke(cu, bb, mir, kStatic, false /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1243 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1244 | break; |
| 1245 | case Instruction::INVOKE_STATIC_RANGE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1246 | ConvertInvoke(cu, bb, mir, kStatic, true /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1247 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1248 | break; |
| 1249 | |
| 1250 | case Instruction::INVOKE_DIRECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1251 | ConvertInvoke(cu, bb, mir, kDirect, false /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1252 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1253 | break; |
| 1254 | case Instruction::INVOKE_DIRECT_RANGE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1255 | ConvertInvoke(cu, bb, mir, kDirect, true /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1256 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1257 | break; |
| 1258 | |
| 1259 | case Instruction::INVOKE_VIRTUAL: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1260 | ConvertInvoke(cu, bb, mir, kVirtual, false /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1261 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1262 | break; |
| 1263 | case Instruction::INVOKE_VIRTUAL_RANGE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1264 | ConvertInvoke(cu, bb, mir, kVirtual, true /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1265 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1266 | break; |
| 1267 | |
| 1268 | case Instruction::INVOKE_SUPER: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1269 | ConvertInvoke(cu, bb, mir, kSuper, false /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1270 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1271 | break; |
| 1272 | case Instruction::INVOKE_SUPER_RANGE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1273 | ConvertInvoke(cu, bb, mir, kSuper, true /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1274 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1275 | break; |
| 1276 | |
| 1277 | case Instruction::INVOKE_INTERFACE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1278 | ConvertInvoke(cu, bb, mir, kInterface, false /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1279 | false /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1280 | break; |
| 1281 | case Instruction::INVOKE_INTERFACE_RANGE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1282 | ConvertInvoke(cu, bb, mir, kInterface, true /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1283 | false /* NewFilledArray */); |
| 1284 | break; |
| 1285 | case Instruction::FILLED_NEW_ARRAY: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1286 | ConvertInvoke(cu, bb, mir, kInterface, false /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1287 | true /* NewFilledArray */); |
| 1288 | break; |
| 1289 | case Instruction::FILLED_NEW_ARRAY_RANGE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1290 | ConvertInvoke(cu, bb, mir, kInterface, true /*range*/, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1291 | true /* NewFilledArray */); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1292 | break; |
| 1293 | |
| 1294 | case Instruction::CONST_STRING: |
| 1295 | case Instruction::CONST_STRING_JUMBO: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1296 | ConvertConstObject(cu, vB, greenland::IntrinsicHelper::ConstString, |
| 1297 | rl_dest); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1298 | break; |
| 1299 | |
| 1300 | case Instruction::CONST_CLASS: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1301 | ConvertConstObject(cu, vB, greenland::IntrinsicHelper::ConstClass, |
| 1302 | rl_dest); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1303 | break; |
| 1304 | |
| 1305 | case Instruction::CHECK_CAST: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1306 | ConvertCheckCast(cu, vB, rl_src[0]); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1307 | break; |
| 1308 | |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 1309 | case Instruction::NEW_INSTANCE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1310 | ConvertNewInstance(cu, vB, rl_dest); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 1311 | break; |
| 1312 | |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 1313 | case Instruction::MOVE_EXCEPTION: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1314 | ConvertMoveException(cu, rl_dest); |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 1315 | break; |
| 1316 | |
| 1317 | case Instruction::THROW: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1318 | ConvertThrow(cu, rl_src[0]); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1319 | /* |
| 1320 | * If this throw is standalone, terminate. |
| 1321 | * If it might rethrow, force termination |
| 1322 | * of the following block. |
| 1323 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1324 | if (bb->fall_through == NULL) { |
| 1325 | cu->irb->CreateUnreachable(); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1326 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1327 | bb->fall_through->fall_through = NULL; |
| 1328 | bb->fall_through->taken = NULL; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1329 | } |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 1330 | break; |
| 1331 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1332 | case Instruction::MOVE_RESULT_WIDE: |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1333 | case Instruction::MOVE_RESULT: |
| 1334 | case Instruction::MOVE_RESULT_OBJECT: |
buzbee | 9a2487f | 2012-07-26 14:01:13 -0700 | [diff] [blame] | 1335 | /* |
jeffhao | 9a4f003 | 2012-08-30 16:17:40 -0700 | [diff] [blame] | 1336 | * All move_results should have been folded into the preceeding invoke. |
buzbee | 9a2487f | 2012-07-26 14:01:13 -0700 | [diff] [blame] | 1337 | */ |
jeffhao | 9a4f003 | 2012-08-30 16:17:40 -0700 | [diff] [blame] | 1338 | LOG(FATAL) << "Unexpected move_result"; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1339 | break; |
| 1340 | |
| 1341 | case Instruction::MONITOR_ENTER: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1342 | ConvertMonitorEnterExit(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1343 | greenland::IntrinsicHelper::MonitorEnter, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1344 | rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1345 | break; |
| 1346 | |
| 1347 | case Instruction::MONITOR_EXIT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1348 | ConvertMonitorEnterExit(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1349 | greenland::IntrinsicHelper::MonitorExit, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1350 | rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1351 | break; |
| 1352 | |
| 1353 | case Instruction::ARRAY_LENGTH: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1354 | ConvertArrayLength(cu, opt_flags, rl_dest, rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1355 | break; |
| 1356 | |
| 1357 | case Instruction::NEW_ARRAY: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1358 | ConvertNewArray(cu, vC, rl_dest, rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1359 | break; |
| 1360 | |
| 1361 | case Instruction::INSTANCE_OF: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1362 | ConvertInstanceOf(cu, vC, rl_dest, rl_src[0]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1363 | break; |
| 1364 | |
| 1365 | case Instruction::AGET: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1366 | if (rl_dest.fp) { |
| 1367 | ConvertAget(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1368 | greenland::IntrinsicHelper::HLArrayGetFloat, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1369 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1370 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1371 | ConvertAget(cu, opt_flags, greenland::IntrinsicHelper::HLArrayGet, |
| 1372 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1373 | } |
| 1374 | break; |
| 1375 | case Instruction::AGET_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1376 | ConvertAget(cu, opt_flags, greenland::IntrinsicHelper::HLArrayGetObject, |
| 1377 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1378 | break; |
| 1379 | case Instruction::AGET_BOOLEAN: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1380 | ConvertAget(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1381 | greenland::IntrinsicHelper::HLArrayGetBoolean, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1382 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1383 | break; |
| 1384 | case Instruction::AGET_BYTE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1385 | ConvertAget(cu, opt_flags, greenland::IntrinsicHelper::HLArrayGetByte, |
| 1386 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1387 | break; |
| 1388 | case Instruction::AGET_CHAR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1389 | ConvertAget(cu, opt_flags, greenland::IntrinsicHelper::HLArrayGetChar, |
| 1390 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1391 | break; |
| 1392 | case Instruction::AGET_SHORT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1393 | ConvertAget(cu, opt_flags, greenland::IntrinsicHelper::HLArrayGetShort, |
| 1394 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1395 | break; |
| 1396 | case Instruction::AGET_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1397 | if (rl_dest.fp) { |
| 1398 | ConvertAget(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1399 | greenland::IntrinsicHelper::HLArrayGetDouble, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1400 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1401 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1402 | ConvertAget(cu, opt_flags, greenland::IntrinsicHelper::HLArrayGetWide, |
| 1403 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1404 | } |
| 1405 | break; |
| 1406 | |
| 1407 | case Instruction::APUT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1408 | if (rl_src[0].fp) { |
| 1409 | ConvertAput(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1410 | greenland::IntrinsicHelper::HLArrayPutFloat, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1411 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1412 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1413 | ConvertAput(cu, opt_flags, greenland::IntrinsicHelper::HLArrayPut, |
| 1414 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1415 | } |
| 1416 | break; |
| 1417 | case Instruction::APUT_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1418 | ConvertAput(cu, opt_flags, greenland::IntrinsicHelper::HLArrayPutObject, |
| 1419 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | case Instruction::APUT_BOOLEAN: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1422 | ConvertAput(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1423 | greenland::IntrinsicHelper::HLArrayPutBoolean, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1424 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1425 | break; |
| 1426 | case Instruction::APUT_BYTE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1427 | ConvertAput(cu, opt_flags, greenland::IntrinsicHelper::HLArrayPutByte, |
| 1428 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1429 | break; |
| 1430 | case Instruction::APUT_CHAR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1431 | ConvertAput(cu, opt_flags, greenland::IntrinsicHelper::HLArrayPutChar, |
| 1432 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1433 | break; |
| 1434 | case Instruction::APUT_SHORT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1435 | ConvertAput(cu, opt_flags, greenland::IntrinsicHelper::HLArrayPutShort, |
| 1436 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1437 | break; |
| 1438 | case Instruction::APUT_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1439 | if (rl_src[0].fp) { |
| 1440 | ConvertAput(cu, opt_flags, |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1441 | greenland::IntrinsicHelper::HLArrayPutDouble, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1442 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1443 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1444 | ConvertAput(cu, opt_flags, greenland::IntrinsicHelper::HLArrayPutWide, |
| 1445 | rl_src[0], rl_src[1], rl_src[2]); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 1446 | } |
| 1447 | break; |
| 1448 | |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1449 | case Instruction::IGET: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1450 | if (rl_dest.fp) { |
| 1451 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetFloat, |
| 1452 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1453 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1454 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGet, |
| 1455 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1456 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1457 | break; |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1458 | case Instruction::IGET_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1459 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetObject, |
| 1460 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1461 | break; |
| 1462 | case Instruction::IGET_BOOLEAN: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1463 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetBoolean, |
| 1464 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1465 | break; |
| 1466 | case Instruction::IGET_BYTE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1467 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetByte, |
| 1468 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1469 | break; |
| 1470 | case Instruction::IGET_CHAR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1471 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetChar, |
| 1472 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1473 | break; |
| 1474 | case Instruction::IGET_SHORT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1475 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetShort, |
| 1476 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1477 | break; |
| 1478 | case Instruction::IGET_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1479 | if (rl_dest.fp) { |
| 1480 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetDouble, |
| 1481 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1482 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1483 | ConvertIget(cu, opt_flags, greenland::IntrinsicHelper::HLIGetWide, |
| 1484 | rl_dest, rl_src[0], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1485 | } |
| 1486 | break; |
| 1487 | case Instruction::IPUT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1488 | if (rl_src[0].fp) { |
| 1489 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutFloat, |
| 1490 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1491 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1492 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPut, |
| 1493 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1494 | } |
| 1495 | break; |
| 1496 | case Instruction::IPUT_OBJECT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1497 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutObject, |
| 1498 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1499 | break; |
| 1500 | case Instruction::IPUT_BOOLEAN: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1501 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutBoolean, |
| 1502 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1503 | break; |
| 1504 | case Instruction::IPUT_BYTE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1505 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutByte, |
| 1506 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1507 | break; |
| 1508 | case Instruction::IPUT_CHAR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1509 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutChar, |
| 1510 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1511 | break; |
| 1512 | case Instruction::IPUT_SHORT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1513 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutShort, |
| 1514 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1515 | break; |
| 1516 | case Instruction::IPUT_WIDE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1517 | if (rl_src[0].fp) { |
| 1518 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutDouble, |
| 1519 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1520 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1521 | ConvertIput(cu, opt_flags, greenland::IntrinsicHelper::HLIPutWide, |
| 1522 | rl_src[0], rl_src[1], vC); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1523 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1524 | break; |
| 1525 | |
| 1526 | case Instruction::FILL_ARRAY_DATA: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1527 | ConvertFillArrayData(cu, vB, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1528 | break; |
| 1529 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1530 | case Instruction::LONG_TO_INT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1531 | ConvertLongToInt(cu, rl_dest, rl_src[0]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1532 | break; |
| 1533 | |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1534 | case Instruction::INT_TO_LONG: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1535 | ConvertIntToLong(cu, rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1536 | break; |
| 1537 | |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1538 | case Instruction::INT_TO_CHAR: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1539 | ConvertIntNarrowing(cu, rl_dest, rl_src[0], |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1540 | greenland::IntrinsicHelper::IntToChar); |
| 1541 | break; |
| 1542 | case Instruction::INT_TO_BYTE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1543 | ConvertIntNarrowing(cu, rl_dest, rl_src[0], |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1544 | greenland::IntrinsicHelper::IntToByte); |
| 1545 | break; |
| 1546 | case Instruction::INT_TO_SHORT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1547 | ConvertIntNarrowing(cu, rl_dest, rl_src[0], |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 1548 | greenland::IntrinsicHelper::IntToShort); |
| 1549 | break; |
| 1550 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1551 | case Instruction::INT_TO_FLOAT: |
| 1552 | case Instruction::LONG_TO_FLOAT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1553 | ConvertIntToFP(cu, cu->irb->getFloatTy(), rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1554 | break; |
| 1555 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1556 | case Instruction::INT_TO_DOUBLE: |
| 1557 | case Instruction::LONG_TO_DOUBLE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1558 | ConvertIntToFP(cu, cu->irb->getDoubleTy(), rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1559 | break; |
| 1560 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1561 | case Instruction::FLOAT_TO_DOUBLE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1562 | ConvertFloatToDouble(cu, rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1563 | break; |
| 1564 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1565 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1566 | ConvertDoubleToFloat(cu, rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1567 | break; |
| 1568 | |
| 1569 | case Instruction::NEG_LONG: |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1570 | case Instruction::NEG_INT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1571 | ConvertNeg(cu, rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1572 | break; |
| 1573 | |
| 1574 | case Instruction::NEG_FLOAT: |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1575 | case Instruction::NEG_DOUBLE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1576 | ConvertNegFP(cu, rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1577 | break; |
| 1578 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1579 | case Instruction::NOT_LONG: |
| 1580 | case Instruction::NOT_INT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1581 | ConvertNot(cu, rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1582 | break; |
| 1583 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1584 | case Instruction::FLOAT_TO_INT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1585 | ConvertFPToInt(cu, greenland::IntrinsicHelper::F2I, rl_dest, rl_src[0]); |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 1586 | break; |
| 1587 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1588 | case Instruction::DOUBLE_TO_INT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1589 | ConvertFPToInt(cu, greenland::IntrinsicHelper::D2I, rl_dest, rl_src[0]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1590 | break; |
| 1591 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1592 | case Instruction::FLOAT_TO_LONG: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1593 | ConvertFPToInt(cu, greenland::IntrinsicHelper::F2L, rl_dest, rl_src[0]); |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 1594 | break; |
| 1595 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1596 | case Instruction::DOUBLE_TO_LONG: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1597 | ConvertFPToInt(cu, greenland::IntrinsicHelper::D2L, rl_dest, rl_src[0]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1598 | break; |
| 1599 | |
| 1600 | case Instruction::CMPL_FLOAT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1601 | ConvertWideComparison(cu, greenland::IntrinsicHelper::CmplFloat, |
| 1602 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1603 | break; |
| 1604 | case Instruction::CMPG_FLOAT: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1605 | ConvertWideComparison(cu, greenland::IntrinsicHelper::CmpgFloat, |
| 1606 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1607 | break; |
| 1608 | case Instruction::CMPL_DOUBLE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1609 | ConvertWideComparison(cu, greenland::IntrinsicHelper::CmplDouble, |
| 1610 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1611 | break; |
| 1612 | case Instruction::CMPG_DOUBLE: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1613 | ConvertWideComparison(cu, greenland::IntrinsicHelper::CmpgDouble, |
| 1614 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1615 | break; |
| 1616 | case Instruction::CMP_LONG: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1617 | ConvertWideComparison(cu, greenland::IntrinsicHelper::CmpLong, |
| 1618 | rl_dest, rl_src[0], rl_src[1]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1619 | break; |
| 1620 | |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1621 | case Instruction::PACKED_SWITCH: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1622 | ConvertPackedSwitch(cu, bb, vB, rl_src[0]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1623 | break; |
| 1624 | |
| 1625 | case Instruction::SPARSE_SWITCH: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1626 | ConvertSparseSwitch(cu, bb, vB, rl_src[0]); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 1627 | break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1628 | |
| 1629 | default: |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 1630 | UNIMPLEMENTED(FATAL) << "Unsupported Dex opcode 0x" << std::hex << opcode; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1631 | res = true; |
| 1632 | } |
| 1633 | return res; |
| 1634 | } |
| 1635 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1636 | static void SetDexOffset(CompilationUnit* cu, int32_t offset) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1637 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1638 | cu->current_dalvik_offset = offset; |
| 1639 | llvm::SmallVector<llvm::Value*, 1> array_ref; |
| 1640 | array_ref.push_back(cu->irb->getInt32(offset)); |
| 1641 | llvm::MDNode* node = llvm::MDNode::get(*cu->context, array_ref); |
| 1642 | cu->irb->SetDexOffset(node); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | // Attach method info as metadata to special intrinsic |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1646 | static void SetMethodInfo(CompilationUnit* cu) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1647 | { |
| 1648 | // We don't want dex offset on this |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1649 | cu->irb->SetDexOffset(NULL); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1650 | greenland::IntrinsicHelper::IntrinsicId id; |
| 1651 | id = greenland::IntrinsicHelper::MethodInfo; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1652 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 1653 | llvm::Instruction* inst = cu->irb->CreateCall(intr); |
| 1654 | llvm::SmallVector<llvm::Value*, 2> reg_info; |
| 1655 | reg_info.push_back(cu->irb->getInt32(cu->num_ins)); |
| 1656 | reg_info.push_back(cu->irb->getInt32(cu->num_regs)); |
| 1657 | reg_info.push_back(cu->irb->getInt32(cu->num_outs)); |
| 1658 | reg_info.push_back(cu->irb->getInt32(cu->num_compiler_temps)); |
| 1659 | reg_info.push_back(cu->irb->getInt32(cu->num_ssa_regs)); |
| 1660 | llvm::MDNode* reg_info_node = llvm::MDNode::get(*cu->context, reg_info); |
| 1661 | inst->setMetadata("RegInfo", reg_info_node); |
| 1662 | int promo_size = cu->num_dalvik_registers + cu->num_compiler_temps + 1; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1663 | llvm::SmallVector<llvm::Value*, 50> pmap; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1664 | for (int i = 0; i < promo_size; i++) { |
| 1665 | PromotionMap* p = &cu->promotion_map[i]; |
| 1666 | int32_t map_data = ((p->first_in_pair & 0xff) << 24) | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 1667 | ((p->FpReg & 0xff) << 16) | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1668 | ((p->core_reg & 0xff) << 8) | |
| 1669 | ((p->fp_location & 0xf) << 4) | |
| 1670 | (p->core_location & 0xf); |
| 1671 | pmap.push_back(cu->irb->getInt32(map_data)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1672 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1673 | llvm::MDNode* map_node = llvm::MDNode::get(*cu->context, pmap); |
| 1674 | inst->setMetadata("PromotionMap", map_node); |
| 1675 | SetDexOffset(cu, cu->current_dalvik_offset); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 1678 | static void HandlePhiNodes(CompilationUnit* cu, BasicBlock* bb, llvm::BasicBlock* llvm_bb) |
| 1679 | { |
| 1680 | SetDexOffset(cu, bb->start_offset); |
| 1681 | for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 1682 | int opcode = mir->dalvikInsn.opcode; |
| 1683 | if (opcode < kMirOpFirst) { |
| 1684 | // Stop after first non-pseudo MIR op. |
| 1685 | continue; |
| 1686 | } |
| 1687 | if (opcode != kMirOpPhi) { |
| 1688 | // Skip other mir Pseudos. |
| 1689 | continue; |
| 1690 | } |
| 1691 | RegLocation rl_dest = cu->reg_location[mir->ssa_rep->defs[0]]; |
| 1692 | /* |
| 1693 | * The Art compiler's Phi nodes only handle 32-bit operands, |
| 1694 | * representing wide values using a matched set of Phi nodes |
| 1695 | * for the lower and upper halves. In the llvm world, we only |
| 1696 | * want a single Phi for wides. Here we will simply discard |
| 1697 | * the Phi node representing the high word. |
| 1698 | */ |
| 1699 | if (rl_dest.high_word) { |
| 1700 | continue; // No Phi node - handled via low word |
| 1701 | } |
| 1702 | int* incoming = reinterpret_cast<int*>(mir->dalvikInsn.vB); |
| 1703 | llvm::Type* phi_type = |
| 1704 | LlvmTypeFromLocRec(cu, rl_dest); |
| 1705 | llvm::PHINode* phi = cu->irb->CreatePHI(phi_type, mir->ssa_rep->num_uses); |
| 1706 | for (int i = 0; i < mir->ssa_rep->num_uses; i++) { |
| 1707 | RegLocation loc; |
| 1708 | // Don't check width here. |
| 1709 | loc = GetRawSrc(cu, mir, i); |
| 1710 | DCHECK_EQ(rl_dest.wide, loc.wide); |
| 1711 | DCHECK_EQ(rl_dest.wide & rl_dest.high_word, loc.wide & loc.high_word); |
| 1712 | DCHECK_EQ(rl_dest.fp, loc.fp); |
| 1713 | DCHECK_EQ(rl_dest.core, loc.core); |
| 1714 | DCHECK_EQ(rl_dest.ref, loc.ref); |
| 1715 | SafeMap<unsigned int, unsigned int>::iterator it; |
| 1716 | it = cu->block_id_map.find(incoming[i]); |
| 1717 | DCHECK(it != cu->block_id_map.end()); |
| 1718 | DCHECK(GetLLVMValue(cu, loc.orig_sreg) != NULL); |
| 1719 | DCHECK(GetLLVMBlock(cu, it->second) != NULL); |
| 1720 | phi->addIncoming(GetLLVMValue(cu, loc.orig_sreg), |
| 1721 | GetLLVMBlock(cu, it->second)); |
| 1722 | } |
| 1723 | DefineValueOnly(cu, phi, rl_dest.orig_sreg); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | /* Extended MIR instructions like PHI */ |
| 1728 | static void ConvertExtendedMIR(CompilationUnit* cu, BasicBlock* bb, MIR* mir, |
| 1729 | llvm::BasicBlock* llvm_bb) |
| 1730 | { |
| 1731 | |
| 1732 | switch (static_cast<ExtendedMIROpcode>(mir->dalvikInsn.opcode)) { |
| 1733 | case kMirOpPhi: { |
| 1734 | // The llvm Phi node already emitted - just DefineValue() here. |
| 1735 | RegLocation rl_dest = cu->reg_location[mir->ssa_rep->defs[0]]; |
| 1736 | if (!rl_dest.high_word) { |
| 1737 | // Only consider low word of pairs. |
| 1738 | DCHECK(GetLLVMValue(cu, rl_dest.orig_sreg) != NULL); |
| 1739 | llvm::Value* phi = GetLLVMValue(cu, rl_dest.orig_sreg); |
| 1740 | if (1) SetVregOnValue(cu, phi, rl_dest.orig_sreg); |
| 1741 | } |
| 1742 | break; |
| 1743 | } |
| 1744 | case kMirOpCopy: { |
| 1745 | UNIMPLEMENTED(WARNING) << "unimp kMirOpPhi"; |
| 1746 | break; |
| 1747 | } |
| 1748 | case kMirOpNop: |
| 1749 | if ((mir == bb->last_mir_insn) && (bb->taken == NULL) && |
| 1750 | (bb->fall_through == NULL)) { |
| 1751 | cu->irb->CreateUnreachable(); |
| 1752 | } |
| 1753 | break; |
| 1754 | |
| 1755 | // TODO: need GBC intrinsic to take advantage of fused operations |
| 1756 | case kMirOpFusedCmplFloat: |
| 1757 | UNIMPLEMENTED(FATAL) << "kMirOpFusedCmpFloat unsupported"; |
| 1758 | break; |
| 1759 | case kMirOpFusedCmpgFloat: |
| 1760 | UNIMPLEMENTED(FATAL) << "kMirOpFusedCmgFloat unsupported"; |
| 1761 | break; |
| 1762 | case kMirOpFusedCmplDouble: |
| 1763 | UNIMPLEMENTED(FATAL) << "kMirOpFusedCmplDouble unsupported"; |
| 1764 | break; |
| 1765 | case kMirOpFusedCmpgDouble: |
| 1766 | UNIMPLEMENTED(FATAL) << "kMirOpFusedCmpgDouble unsupported"; |
| 1767 | break; |
| 1768 | case kMirOpFusedCmpLong: |
| 1769 | UNIMPLEMENTED(FATAL) << "kMirOpLongCmpBranch unsupported"; |
| 1770 | break; |
| 1771 | default: |
| 1772 | break; |
| 1773 | } |
| 1774 | } |
| 1775 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1776 | /* Handle the content in each basic block */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1777 | static bool BlockBitcodeConversion(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1778 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1779 | if (bb->block_type == kDead) return false; |
| 1780 | llvm::BasicBlock* llvm_bb = GetLLVMBlock(cu, bb->id); |
| 1781 | if (llvm_bb == NULL) { |
| 1782 | CHECK(bb->block_type == kExitBlock); |
buzbee | f5f5a12 | 2012-09-21 13:57:36 -0700 | [diff] [blame] | 1783 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1784 | cu->irb->SetInsertPoint(llvm_bb); |
| 1785 | SetDexOffset(cu, bb->start_offset); |
buzbee | f5f5a12 | 2012-09-21 13:57:36 -0700 | [diff] [blame] | 1786 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1787 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1788 | if (cu->verbose) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1789 | LOG(INFO) << "................................"; |
| 1790 | LOG(INFO) << "Block id " << bb->id; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1791 | if (llvm_bb != NULL) { |
| 1792 | LOG(INFO) << "label " << llvm_bb->getName().str().c_str(); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1793 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1794 | LOG(INFO) << "llvm_bb is NULL"; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1798 | if (bb->block_type == kEntryBlock) { |
| 1799 | SetMethodInfo(cu); |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 1800 | |
| 1801 | { // Allocate shadowframe. |
| 1802 | greenland::IntrinsicHelper::IntrinsicId id = |
| 1803 | greenland::IntrinsicHelper::AllocaShadowFrame; |
| 1804 | llvm::Function* func = cu->intrinsic_helper->GetIntrinsicFunction(id); |
| 1805 | llvm::Value* entries = cu->irb->getInt32(cu->num_dalvik_registers); |
| 1806 | cu->irb->CreateCall(func, entries); |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 1807 | } |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 1808 | |
| 1809 | { // Store arguments to vregs. |
| 1810 | uint16_t arg_reg = cu->num_regs; |
| 1811 | |
| 1812 | llvm::Function::arg_iterator arg_iter(cu->func->arg_begin()); |
| 1813 | llvm::Function::arg_iterator arg_end(cu->func->arg_end()); |
| 1814 | |
| 1815 | const char* shorty = cu->shorty; |
| 1816 | uint32_t shorty_size = strlen(shorty); |
| 1817 | CHECK_GE(shorty_size, 1u); |
| 1818 | |
| 1819 | ++arg_iter; // skip method object |
| 1820 | |
| 1821 | if ((cu->access_flags & kAccStatic) == 0) { |
| 1822 | SetVregOnValue(cu, arg_iter, arg_reg); |
| 1823 | ++arg_iter; |
| 1824 | ++arg_reg; |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 1825 | } |
TDYa127 | dc5daa0 | 2013-01-09 21:31:37 +0800 | [diff] [blame] | 1826 | |
| 1827 | for (uint32_t i = 1; i < shorty_size; ++i, ++arg_iter) { |
| 1828 | SetVregOnValue(cu, arg_iter, arg_reg); |
| 1829 | |
| 1830 | ++arg_reg; |
| 1831 | if (shorty[i] == 'J' || shorty[i] == 'D') { |
| 1832 | // Wide types, such as long and double, are using a pair of registers |
| 1833 | // to store the value, so we have to increase arg_reg again. |
| 1834 | ++arg_reg; |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 1835 | } |
| 1836 | } |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 1837 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1838 | } else if (bb->block_type == kExitBlock) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1839 | /* |
| 1840 | * Because of the differences between how MIR/LIR and llvm handle exit |
| 1841 | * blocks, we won't explicitly covert them. On the llvm-to-lir |
| 1842 | * path, it will need to be regenereated. |
| 1843 | */ |
| 1844 | return false; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1845 | } else if (bb->block_type == kExceptionHandling) { |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1846 | /* |
| 1847 | * Because we're deferring null checking, delete the associated empty |
| 1848 | * exception block. |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1849 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1850 | llvm_bb->eraseFromParent(); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1851 | return false; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
buzbee | 26f10ee | 2012-12-21 11:16:29 -0800 | [diff] [blame] | 1854 | HandlePhiNodes(cu, bb, llvm_bb); |
| 1855 | |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 1856 | for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1857 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1858 | SetDexOffset(cu, mir->offset); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1859 | |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1860 | int opcode = mir->dalvikInsn.opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1861 | Instruction::Format dalvik_format = |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1862 | Instruction::FormatOf(mir->dalvikInsn.opcode); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1863 | |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1864 | if (opcode == kMirOpCheck) { |
| 1865 | // Combine check and work halves of throwing instruction. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1866 | MIR* work_half = mir->meta.throw_insn; |
| 1867 | mir->dalvikInsn.opcode = work_half->dalvikInsn.opcode; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1868 | opcode = mir->dalvikInsn.opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1869 | SSARepresentation* ssa_rep = work_half->ssa_rep; |
| 1870 | work_half->ssa_rep = mir->ssa_rep; |
| 1871 | mir->ssa_rep = ssa_rep; |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 1872 | work_half->meta.original_opcode = work_half->dalvikInsn.opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1873 | work_half->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop); |
| 1874 | if (bb->successor_block_list.block_list_type == kCatch) { |
| 1875 | llvm::Function* intr = cu->intrinsic_helper->GetIntrinsicFunction( |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1876 | greenland::IntrinsicHelper::CatchTargets); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1877 | llvm::Value* switch_key = |
| 1878 | cu->irb->CreateCall(intr, cu->irb->getInt32(mir->offset)); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1879 | GrowableListIterator iter; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1880 | GrowableListIteratorInit(&bb->successor_block_list.blocks, &iter); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1881 | // New basic block to use for work half |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1882 | llvm::BasicBlock* work_bb = |
| 1883 | llvm::BasicBlock::Create(*cu->context, "", cu->func); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1884 | llvm::SwitchInst* sw = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1885 | cu->irb->CreateSwitch(switch_key, work_bb, |
| 1886 | bb->successor_block_list.blocks.num_used); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1887 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1888 | SuccessorBlockInfo *successor_block_info = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 1889 | reinterpret_cast<SuccessorBlockInfo*>(GrowableListIteratorNext(&iter)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1890 | if (successor_block_info == NULL) break; |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1891 | llvm::BasicBlock *target = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1892 | GetLLVMBlock(cu, successor_block_info->block->id); |
| 1893 | int type_index = successor_block_info->key; |
| 1894 | sw->addCase(cu->irb->getInt32(type_index), target); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1895 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1896 | llvm_bb = work_bb; |
| 1897 | cu->irb->SetInsertPoint(llvm_bb); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | if (opcode >= kMirOpFirst) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1902 | ConvertExtendedMIR(cu, bb, mir, llvm_bb); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1903 | continue; |
| 1904 | } |
| 1905 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1906 | bool not_handled = ConvertMIRNode(cu, mir, bb, llvm_bb, |
| 1907 | NULL /* label_list */); |
| 1908 | if (not_handled) { |
| 1909 | Instruction::Code dalvik_opcode = static_cast<Instruction::Code>(opcode); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1910 | LOG(WARNING) << StringPrintf("%#06x: Op %#x (%s) / Fmt %d not handled", |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 1911 | mir->offset, opcode, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1912 | Instruction::Name(dalvik_opcode), |
| 1913 | dalvik_format); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1917 | if (bb->block_type == kEntryBlock) { |
| 1918 | cu->entryTarget_bb = GetLLVMBlock(cu, bb->fall_through->id); |
| 1919 | } else if ((bb->fall_through != NULL) && !bb->has_return) { |
| 1920 | cu->irb->CreateBr(GetLLVMBlock(cu, bb->fall_through->id)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | return false; |
| 1924 | } |
| 1925 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1926 | char RemapShorty(char shorty_type) { |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 1927 | /* |
| 1928 | * TODO: might want to revisit this. Dalvik registers are 32-bits wide, |
| 1929 | * and longs/doubles are represented as a pair of registers. When sub-word |
| 1930 | * arguments (and method results) are passed, they are extended to Dalvik |
| 1931 | * virtual register containers. Because llvm is picky about type consistency, |
| 1932 | * we must either cast the "real" type to 32-bit container multiple Dalvik |
| 1933 | * register types, or always use the expanded values. |
| 1934 | * Here, we're doing the latter. We map the shorty signature to container |
| 1935 | * types (which is valid so long as we always do a real expansion of passed |
| 1936 | * arguments and field loads). |
| 1937 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1938 | switch(shorty_type) { |
| 1939 | case 'Z' : shorty_type = 'I'; break; |
| 1940 | case 'B' : shorty_type = 'I'; break; |
| 1941 | case 'S' : shorty_type = 'I'; break; |
| 1942 | case 'C' : shorty_type = 'I'; break; |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 1943 | default: break; |
| 1944 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1945 | return shorty_type; |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1948 | static llvm::FunctionType* GetFunctionType(CompilationUnit* cu) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1949 | |
| 1950 | // Get return type |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1951 | llvm::Type* ret_type = cu->irb->GetJType(RemapShorty(cu->shorty[0]), |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1952 | greenland::kAccurate); |
| 1953 | |
| 1954 | // Get argument type |
| 1955 | std::vector<llvm::Type*> args_type; |
| 1956 | |
| 1957 | // method object |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1958 | args_type.push_back(cu->irb->GetJMethodTy()); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1959 | |
| 1960 | // Do we have a "this"? |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1961 | if ((cu->access_flags & kAccStatic) == 0) { |
| 1962 | args_type.push_back(cu->irb->GetJObjectTy()); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1965 | for (uint32_t i = 1; i < strlen(cu->shorty); ++i) { |
| 1966 | args_type.push_back(cu->irb->GetJType(RemapShorty(cu->shorty[i]), |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1967 | greenland::kAccurate)); |
| 1968 | } |
| 1969 | |
| 1970 | return llvm::FunctionType::get(ret_type, args_type, false); |
| 1971 | } |
| 1972 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1973 | static bool CreateFunction(CompilationUnit* cu) { |
| 1974 | std::string func_name(PrettyMethod(cu->method_idx, *cu->dex_file, |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1975 | /* with_signature */ false)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1976 | llvm::FunctionType* func_type = GetFunctionType(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1977 | |
| 1978 | if (func_type == NULL) { |
| 1979 | return false; |
| 1980 | } |
| 1981 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1982 | cu->func = llvm::Function::Create(func_type, |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1983 | llvm::Function::ExternalLinkage, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1984 | func_name, cu->module); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1985 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1986 | llvm::Function::arg_iterator arg_iter(cu->func->arg_begin()); |
| 1987 | llvm::Function::arg_iterator arg_end(cu->func->arg_end()); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1988 | |
| 1989 | arg_iter->setName("method"); |
| 1990 | ++arg_iter; |
| 1991 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1992 | int start_sreg = cu->num_regs; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1993 | |
| 1994 | for (unsigned i = 0; arg_iter != arg_end; ++i, ++arg_iter) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1995 | arg_iter->setName(StringPrintf("v%i_0", start_sreg)); |
| 1996 | start_sreg += cu->reg_location[start_sreg].wide ? 2 : 1; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | return true; |
| 2000 | } |
| 2001 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2002 | static bool CreateLLVMBasicBlock(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2003 | { |
| 2004 | // Skip the exit block |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2005 | if ((bb->block_type == kDead) ||(bb->block_type == kExitBlock)) { |
| 2006 | cu->id_to_block_map.Put(bb->id, NULL); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2007 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2008 | int offset = bb->start_offset; |
| 2009 | bool entry_block = (bb->block_type == kEntryBlock); |
| 2010 | llvm::BasicBlock* llvm_bb = |
| 2011 | llvm::BasicBlock::Create(*cu->context, entry_block ? "entry" : |
| 2012 | StringPrintf(kLabelFormat, bb->catch_entry ? kCatchBlock : |
| 2013 | kNormalBlock, offset, bb->id), cu->func); |
| 2014 | if (entry_block) { |
| 2015 | cu->entry_bb = llvm_bb; |
| 2016 | cu->placeholder_bb = |
| 2017 | llvm::BasicBlock::Create(*cu->context, "placeholder", |
| 2018 | cu->func); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2019 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2020 | cu->id_to_block_map.Put(bb->id, llvm_bb); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2021 | } |
| 2022 | return false; |
| 2023 | } |
| 2024 | |
| 2025 | |
| 2026 | /* |
| 2027 | * Convert MIR to LLVM_IR |
| 2028 | * o For each ssa name, create LLVM named value. Type these |
| 2029 | * appropriately, and ignore high half of wide and double operands. |
| 2030 | * o For each MIR basic block, create an LLVM basic block. |
| 2031 | * o Iterate through the MIR a basic block at a time, setting arguments |
| 2032 | * to recovered ssa name. |
| 2033 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2034 | void MethodMIR2Bitcode(CompilationUnit* cu) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2035 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2036 | InitIR(cu); |
| 2037 | CompilerInitGrowableList(cu, &cu->llvm_values, cu->num_ssa_regs); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2038 | |
| 2039 | // Create the function |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2040 | CreateFunction(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2041 | |
| 2042 | // Create an LLVM basic block for each MIR block in dfs preorder |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2043 | DataFlowAnalysisDispatcher(cu, CreateLLVMBasicBlock, |
| 2044 | kPreOrderDFSTraversal, false /* is_iterative */); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2045 | /* |
| 2046 | * Create an llvm named value for each MIR SSA name. Note: we'll use |
| 2047 | * placeholders for all non-argument values (because we haven't seen |
| 2048 | * the definition yet). |
| 2049 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2050 | cu->irb->SetInsertPoint(cu->placeholder_bb); |
| 2051 | llvm::Function::arg_iterator arg_iter(cu->func->arg_begin()); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2052 | arg_iter++; /* Skip path method */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2053 | for (int i = 0; i < cu->num_ssa_regs; i++) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2054 | llvm::Value* val; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2055 | RegLocation rl_temp = cu->reg_location[i]; |
| 2056 | if ((SRegToVReg(cu, i) < 0) || rl_temp.high_word) { |
| 2057 | InsertGrowableList(cu, &cu->llvm_values, 0); |
| 2058 | } else if ((i < cu->num_regs) || |
| 2059 | (i >= (cu->num_regs + cu->num_ins))) { |
| 2060 | llvm::Constant* imm_value = cu->reg_location[i].wide ? |
| 2061 | cu->irb->GetJLong(0) : cu->irb->GetJInt(0); |
| 2062 | val = EmitConst(cu, imm_value, cu->reg_location[i]); |
| 2063 | val->setName(LlvmSSAName(cu, i)); |
| 2064 | InsertGrowableList(cu, &cu->llvm_values, reinterpret_cast<uintptr_t>(val)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2065 | } else { |
| 2066 | // Recover previously-created argument values |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2067 | llvm::Value* arg_val = arg_iter++; |
| 2068 | InsertGrowableList(cu, &cu->llvm_values, reinterpret_cast<uintptr_t>(arg_val)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2069 | } |
| 2070 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2071 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2072 | DataFlowAnalysisDispatcher(cu, BlockBitcodeConversion, |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2073 | kPreOrderDFSTraversal, false /* Iterative */); |
| 2074 | |
buzbee | 4be777b | 2012-07-12 14:38:18 -0700 | [diff] [blame] | 2075 | /* |
| 2076 | * In a few rare cases of verification failure, the verifier will |
| 2077 | * replace one or more Dalvik opcodes with the special |
| 2078 | * throw-verification-failure opcode. This can leave the SSA graph |
| 2079 | * in an invalid state, as definitions may be lost, while uses retained. |
| 2080 | * To work around this problem, we insert placeholder definitions for |
| 2081 | * all Dalvik SSA regs in the "placeholder" block. Here, after |
| 2082 | * bitcode conversion is complete, we examine those placeholder definitions |
| 2083 | * and delete any with no references (which normally is all of them). |
| 2084 | * |
| 2085 | * If any definitions remain, we link the placeholder block into the |
| 2086 | * CFG. Otherwise, it is deleted. |
| 2087 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2088 | for (llvm::BasicBlock::iterator it = cu->placeholder_bb->begin(), |
| 2089 | it_end = cu->placeholder_bb->end(); it != it_end;) { |
buzbee | 4be777b | 2012-07-12 14:38:18 -0700 | [diff] [blame] | 2090 | llvm::Instruction* inst = llvm::dyn_cast<llvm::Instruction>(it++); |
| 2091 | DCHECK(inst != NULL); |
| 2092 | llvm::Value* val = llvm::dyn_cast<llvm::Value>(inst); |
| 2093 | DCHECK(val != NULL); |
| 2094 | if (val->getNumUses() == 0) { |
| 2095 | inst->eraseFromParent(); |
| 2096 | } |
| 2097 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2098 | SetDexOffset(cu, 0); |
| 2099 | if (cu->placeholder_bb->empty()) { |
| 2100 | cu->placeholder_bb->eraseFromParent(); |
buzbee | 4be777b | 2012-07-12 14:38:18 -0700 | [diff] [blame] | 2101 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2102 | cu->irb->SetInsertPoint(cu->placeholder_bb); |
| 2103 | cu->irb->CreateBr(cu->entryTarget_bb); |
| 2104 | cu->entryTarget_bb = cu->placeholder_bb; |
buzbee | 4be777b | 2012-07-12 14:38:18 -0700 | [diff] [blame] | 2105 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2106 | cu->irb->SetInsertPoint(cu->entry_bb); |
| 2107 | cu->irb->CreateBr(cu->entryTarget_bb); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2108 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2109 | if (cu->enable_debug & (1 << kDebugVerifyBitcode)) { |
| 2110 | if (llvm::verifyFunction(*cu->func, llvm::PrintMessageAction)) { |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 2111 | LOG(INFO) << "Bitcode verification FAILED for " |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2112 | << PrettyMethod(cu->method_idx, *cu->dex_file) |
| 2113 | << " of size " << cu->insns_size; |
| 2114 | cu->enable_debug |= (1 << kDebugDumpBitcodeFile); |
Bill Buzbee | c9f40dd | 2012-08-15 11:35:25 -0700 | [diff] [blame] | 2115 | } |
| 2116 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2117 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2118 | if (cu->enable_debug & (1 << kDebugDumpBitcodeFile)) { |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 2119 | // Write bitcode to file |
| 2120 | std::string errmsg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2121 | std::string fname(PrettyMethod(cu->method_idx, *cu->dex_file)); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 2122 | ReplaceSpecialChars(fname); |
buzbee | 6459e7c | 2012-10-02 14:42:41 -0700 | [diff] [blame] | 2123 | // TODO: make configurable change naming mechanism to avoid fname length issues. |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2124 | fname = StringPrintf("/sdcard/Bitcode/%s.bc", fname.c_str()); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2125 | |
buzbee | 6459e7c | 2012-10-02 14:42:41 -0700 | [diff] [blame] | 2126 | if (fname.size() > 240) { |
| 2127 | LOG(INFO) << "Warning: bitcode filename too long. Truncated."; |
| 2128 | fname.resize(240); |
| 2129 | } |
| 2130 | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 2131 | llvm::OwningPtr<llvm::tool_output_file> out_file( |
| 2132 | new llvm::tool_output_file(fname.c_str(), errmsg, |
| 2133 | llvm::raw_fd_ostream::F_Binary)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2134 | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 2135 | if (!errmsg.empty()) { |
| 2136 | LOG(ERROR) << "Failed to create bitcode output file: " << errmsg; |
| 2137 | } |
| 2138 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2139 | llvm::WriteBitcodeToFile(cu->module, out_file->os()); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 2140 | out_file->keep(); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2141 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2144 | static RegLocation GetLoc(CompilationUnit* cu, llvm::Value* val) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2145 | RegLocation res; |
buzbee | b03f487 | 2012-06-11 15:22:11 -0700 | [diff] [blame] | 2146 | DCHECK(val != NULL); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2147 | SafeMap<llvm::Value*, RegLocation>::iterator it = cu->loc_map.find(val); |
| 2148 | if (it == cu->loc_map.end()) { |
| 2149 | std::string val_name = val->getName().str(); |
| 2150 | if (val_name.empty()) { |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2151 | // FIXME: need to be more robust, handle FP and be in a position to |
| 2152 | // manage unnamed temps whose lifetimes span basic block boundaries |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2153 | UNIMPLEMENTED(WARNING) << "Need to handle unnamed llvm temps"; |
| 2154 | memset(&res, 0, sizeof(res)); |
| 2155 | res.location = kLocPhysReg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2156 | res.low_reg = AllocTemp(cu); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2157 | res.home = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2158 | res.s_reg_low = INVALID_SREG; |
| 2159 | res.orig_sreg = INVALID_SREG; |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2160 | llvm::Type* ty = val->getType(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2161 | res.wide = ((ty == cu->irb->getInt64Ty()) || |
| 2162 | (ty == cu->irb->getDoubleTy())); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2163 | if (res.wide) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2164 | res.high_reg = AllocTemp(cu); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2165 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2166 | cu->loc_map.Put(val, res); |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 2167 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2168 | DCHECK_EQ(val_name[0], 'v'); |
| 2169 | int base_sreg = INVALID_SREG; |
| 2170 | sscanf(val_name.c_str(), "v%d_", &base_sreg); |
| 2171 | res = cu->reg_location[base_sreg]; |
| 2172 | cu->loc_map.Put(val, res); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2173 | } |
| 2174 | } else { |
| 2175 | res = it->second; |
| 2176 | } |
| 2177 | return res; |
| 2178 | } |
| 2179 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2180 | static Instruction::Code GetDalvikOpcode(OpKind op, bool is_const, bool is_wide) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2181 | { |
| 2182 | Instruction::Code res = Instruction::NOP; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2183 | if (is_wide) { |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2184 | switch(op) { |
| 2185 | case kOpAdd: res = Instruction::ADD_LONG; break; |
| 2186 | case kOpSub: res = Instruction::SUB_LONG; break; |
| 2187 | case kOpMul: res = Instruction::MUL_LONG; break; |
| 2188 | case kOpDiv: res = Instruction::DIV_LONG; break; |
| 2189 | case kOpRem: res = Instruction::REM_LONG; break; |
| 2190 | case kOpAnd: res = Instruction::AND_LONG; break; |
| 2191 | case kOpOr: res = Instruction::OR_LONG; break; |
| 2192 | case kOpXor: res = Instruction::XOR_LONG; break; |
| 2193 | case kOpLsl: res = Instruction::SHL_LONG; break; |
| 2194 | case kOpLsr: res = Instruction::USHR_LONG; break; |
| 2195 | case kOpAsr: res = Instruction::SHR_LONG; break; |
| 2196 | default: LOG(FATAL) << "Unexpected OpKind " << op; |
| 2197 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2198 | } else if (is_const){ |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2199 | switch(op) { |
| 2200 | case kOpAdd: res = Instruction::ADD_INT_LIT16; break; |
| 2201 | case kOpSub: res = Instruction::RSUB_INT_LIT8; break; |
| 2202 | case kOpMul: res = Instruction::MUL_INT_LIT16; break; |
| 2203 | case kOpDiv: res = Instruction::DIV_INT_LIT16; break; |
| 2204 | case kOpRem: res = Instruction::REM_INT_LIT16; break; |
| 2205 | case kOpAnd: res = Instruction::AND_INT_LIT16; break; |
| 2206 | case kOpOr: res = Instruction::OR_INT_LIT16; break; |
| 2207 | case kOpXor: res = Instruction::XOR_INT_LIT16; break; |
| 2208 | case kOpLsl: res = Instruction::SHL_INT_LIT8; break; |
| 2209 | case kOpLsr: res = Instruction::USHR_INT_LIT8; break; |
| 2210 | case kOpAsr: res = Instruction::SHR_INT_LIT8; break; |
| 2211 | default: LOG(FATAL) << "Unexpected OpKind " << op; |
| 2212 | } |
| 2213 | } else { |
| 2214 | switch(op) { |
| 2215 | case kOpAdd: res = Instruction::ADD_INT; break; |
| 2216 | case kOpSub: res = Instruction::SUB_INT; break; |
| 2217 | case kOpMul: res = Instruction::MUL_INT; break; |
| 2218 | case kOpDiv: res = Instruction::DIV_INT; break; |
| 2219 | case kOpRem: res = Instruction::REM_INT; break; |
| 2220 | case kOpAnd: res = Instruction::AND_INT; break; |
| 2221 | case kOpOr: res = Instruction::OR_INT; break; |
| 2222 | case kOpXor: res = Instruction::XOR_INT; break; |
| 2223 | case kOpLsl: res = Instruction::SHL_INT; break; |
| 2224 | case kOpLsr: res = Instruction::USHR_INT; break; |
| 2225 | case kOpAsr: res = Instruction::SHR_INT; break; |
| 2226 | default: LOG(FATAL) << "Unexpected OpKind " << op; |
| 2227 | } |
| 2228 | } |
| 2229 | return res; |
| 2230 | } |
| 2231 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2232 | static Instruction::Code GetDalvikFPOpcode(OpKind op, bool is_const, bool is_wide) |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2233 | { |
| 2234 | Instruction::Code res = Instruction::NOP; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2235 | if (is_wide) { |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2236 | switch(op) { |
| 2237 | case kOpAdd: res = Instruction::ADD_DOUBLE; break; |
| 2238 | case kOpSub: res = Instruction::SUB_DOUBLE; break; |
| 2239 | case kOpMul: res = Instruction::MUL_DOUBLE; break; |
| 2240 | case kOpDiv: res = Instruction::DIV_DOUBLE; break; |
| 2241 | case kOpRem: res = Instruction::REM_DOUBLE; break; |
| 2242 | default: LOG(FATAL) << "Unexpected OpKind " << op; |
| 2243 | } |
| 2244 | } else { |
| 2245 | switch(op) { |
| 2246 | case kOpAdd: res = Instruction::ADD_FLOAT; break; |
| 2247 | case kOpSub: res = Instruction::SUB_FLOAT; break; |
| 2248 | case kOpMul: res = Instruction::MUL_FLOAT; break; |
| 2249 | case kOpDiv: res = Instruction::DIV_FLOAT; break; |
| 2250 | case kOpRem: res = Instruction::REM_FLOAT; break; |
| 2251 | default: LOG(FATAL) << "Unexpected OpKind " << op; |
| 2252 | } |
| 2253 | } |
| 2254 | return res; |
| 2255 | } |
| 2256 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2257 | static void CvtBinFPOp(CompilationUnit* cu, OpKind op, llvm::Instruction* inst) |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2258 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2259 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2260 | RegLocation rl_dest = GetLoc(cu, inst); |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2261 | /* |
| 2262 | * Normally, we won't ever generate an FP operation with an immediate |
| 2263 | * operand (not supported in Dex instruction set). However, the IR builder |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2264 | * may insert them - in particular for create_neg_fp. Recognize this case |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2265 | * and deal with it. |
| 2266 | */ |
| 2267 | llvm::ConstantFP* op1C = llvm::dyn_cast<llvm::ConstantFP>(inst->getOperand(0)); |
| 2268 | llvm::ConstantFP* op2C = llvm::dyn_cast<llvm::ConstantFP>(inst->getOperand(1)); |
| 2269 | DCHECK(op2C == NULL); |
| 2270 | if ((op1C != NULL) && (op == kOpSub)) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2271 | RegLocation rl_src = GetLoc(cu, inst->getOperand(1)); |
| 2272 | if (rl_dest.wide) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2273 | cg->GenArithOpDouble(cu, Instruction::NEG_DOUBLE, rl_dest, rl_src, rl_src); |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2274 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2275 | cg->GenArithOpFloat(cu, Instruction::NEG_FLOAT, rl_dest, rl_src, rl_src); |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2276 | } |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2277 | } else { |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2278 | DCHECK(op1C == NULL); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2279 | RegLocation rl_src1 = GetLoc(cu, inst->getOperand(0)); |
| 2280 | RegLocation rl_src2 = GetLoc(cu, inst->getOperand(1)); |
| 2281 | Instruction::Code dalvik_op = GetDalvikFPOpcode(op, false, rl_dest.wide); |
| 2282 | if (rl_dest.wide) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2283 | cg->GenArithOpDouble(cu, dalvik_op, rl_dest, rl_src1, rl_src2); |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2284 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2285 | cg->GenArithOpFloat(cu, dalvik_op, rl_dest, rl_src1, rl_src2); |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2286 | } |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2287 | } |
| 2288 | } |
| 2289 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2290 | static void CvtIntNarrowing(CompilationUnit* cu, llvm::Instruction* inst, |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2291 | Instruction::Code opcode) |
| 2292 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2293 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2294 | RegLocation rl_dest = GetLoc(cu, inst); |
| 2295 | RegLocation rl_src = GetLoc(cu, inst->getOperand(0)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2296 | cg->GenIntNarrowing(cu, opcode, rl_dest, rl_src); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2299 | static void CvtIntToFP(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2300 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2301 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2302 | RegLocation rl_dest = GetLoc(cu, inst); |
| 2303 | RegLocation rl_src = GetLoc(cu, inst->getOperand(0)); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2304 | Instruction::Code opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2305 | if (rl_dest.wide) { |
| 2306 | if (rl_src.wide) { |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2307 | opcode = Instruction::LONG_TO_DOUBLE; |
| 2308 | } else { |
| 2309 | opcode = Instruction::INT_TO_DOUBLE; |
| 2310 | } |
| 2311 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2312 | if (rl_src.wide) { |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2313 | opcode = Instruction::LONG_TO_FLOAT; |
| 2314 | } else { |
| 2315 | opcode = Instruction::INT_TO_FLOAT; |
| 2316 | } |
| 2317 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2318 | cg->GenConversion(cu, opcode, rl_dest, rl_src); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2321 | static void CvtFPToInt(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2322 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2323 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2324 | RegLocation rl_dest = GetLoc(cu, call_inst); |
| 2325 | RegLocation rl_src = GetLoc(cu, call_inst->getOperand(0)); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2326 | Instruction::Code opcode; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2327 | if (rl_dest.wide) { |
| 2328 | if (rl_src.wide) { |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2329 | opcode = Instruction::DOUBLE_TO_LONG; |
| 2330 | } else { |
| 2331 | opcode = Instruction::FLOAT_TO_LONG; |
| 2332 | } |
| 2333 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2334 | if (rl_src.wide) { |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2335 | opcode = Instruction::DOUBLE_TO_INT; |
| 2336 | } else { |
| 2337 | opcode = Instruction::FLOAT_TO_INT; |
| 2338 | } |
| 2339 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2340 | cg->GenConversion(cu, opcode, rl_dest, rl_src); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2343 | static void CvtFloatToDouble(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2344 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2345 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2346 | RegLocation rl_dest = GetLoc(cu, inst); |
| 2347 | RegLocation rl_src = GetLoc(cu, inst->getOperand(0)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2348 | cg->GenConversion(cu, Instruction::FLOAT_TO_DOUBLE, rl_dest, rl_src); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2351 | static void CvtTrunc(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2352 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2353 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2354 | RegLocation rl_dest = GetLoc(cu, inst); |
| 2355 | RegLocation rl_src = GetLoc(cu, inst->getOperand(0)); |
| 2356 | rl_src = UpdateLocWide(cu, rl_src); |
| 2357 | rl_src = WideToNarrow(cu, rl_src); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2358 | cg->StoreValue(cu, rl_dest, rl_src); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2361 | static void CvtDoubleToFloat(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2362 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2363 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2364 | RegLocation rl_dest = GetLoc(cu, inst); |
| 2365 | RegLocation rl_src = GetLoc(cu, inst->getOperand(0)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2366 | cg->GenConversion(cu, Instruction::DOUBLE_TO_FLOAT, rl_dest, rl_src); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2370 | static void CvtIntExt(CompilationUnit* cu, llvm::Instruction* inst, bool is_signed) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2371 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2372 | Codegen* cg = cu->cg.get(); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2373 | // TODO: evaluate src/tgt types and add general support for more than int to long |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2374 | RegLocation rl_dest = GetLoc(cu, inst); |
| 2375 | RegLocation rl_src = GetLoc(cu, inst->getOperand(0)); |
| 2376 | DCHECK(rl_dest.wide); |
| 2377 | DCHECK(!rl_src.wide); |
| 2378 | DCHECK(!rl_dest.fp); |
| 2379 | DCHECK(!rl_src.fp); |
| 2380 | RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
| 2381 | if (rl_src.location == kLocPhysReg) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2382 | cg->OpRegCopy(cu, rl_result.low_reg, rl_src.low_reg); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2383 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2384 | cg->LoadValueDirect(cu, rl_src, rl_result.low_reg); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2385 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2386 | if (is_signed) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2387 | cg->OpRegRegImm(cu, kOpAsr, rl_result.high_reg, rl_result.low_reg, 31); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2388 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2389 | cg->LoadConstant(cu, rl_result.high_reg, 0); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2390 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2391 | cg->StoreValueWide(cu, rl_dest, rl_result); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2394 | static void CvtBinOp(CompilationUnit* cu, OpKind op, llvm::Instruction* inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2395 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2396 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2397 | RegLocation rl_dest = GetLoc(cu, inst); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2398 | llvm::Value* lhs = inst->getOperand(0); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 2399 | // Special-case RSUB/NEG |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2400 | llvm::ConstantInt* lhs_imm = llvm::dyn_cast<llvm::ConstantInt>(lhs); |
| 2401 | if ((op == kOpSub) && (lhs_imm != NULL)) { |
| 2402 | RegLocation rl_src1 = GetLoc(cu, inst->getOperand(1)); |
| 2403 | if (rl_src1.wide) { |
| 2404 | DCHECK_EQ(lhs_imm->getSExtValue(), 0); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2405 | cg->GenArithOpLong(cu, Instruction::NEG_LONG, rl_dest, rl_src1, rl_src1); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 2406 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2407 | cg->GenArithOpIntLit(cu, Instruction::RSUB_INT, rl_dest, rl_src1, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2408 | lhs_imm->getSExtValue()); |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 2409 | } |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2410 | return; |
| 2411 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2412 | DCHECK(lhs_imm == NULL); |
| 2413 | RegLocation rl_src1 = GetLoc(cu, inst->getOperand(0)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2414 | llvm::Value* rhs = inst->getOperand(1); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2415 | llvm::ConstantInt* const_rhs = llvm::dyn_cast<llvm::ConstantInt>(rhs); |
| 2416 | if (!rl_dest.wide && (const_rhs != NULL)) { |
| 2417 | Instruction::Code dalvik_op = GetDalvikOpcode(op, true, false); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2418 | cg->GenArithOpIntLit(cu, dalvik_op, rl_dest, rl_src1, const_rhs->getSExtValue()); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2419 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2420 | Instruction::Code dalvik_op = GetDalvikOpcode(op, false, rl_dest.wide); |
| 2421 | RegLocation rl_src2; |
| 2422 | if (const_rhs != NULL) { |
buzbee | 63ebbb6 | 2012-08-03 14:05:41 -0700 | [diff] [blame] | 2423 | // ir_builder converts NOT_LONG to xor src, -1. Restore |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2424 | DCHECK_EQ(dalvik_op, Instruction::XOR_LONG); |
| 2425 | DCHECK_EQ(-1L, const_rhs->getSExtValue()); |
| 2426 | dalvik_op = Instruction::NOT_LONG; |
| 2427 | rl_src2 = rl_src1; |
buzbee | 9a2487f | 2012-07-26 14:01:13 -0700 | [diff] [blame] | 2428 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2429 | rl_src2 = GetLoc(cu, rhs); |
buzbee | 9a2487f | 2012-07-26 14:01:13 -0700 | [diff] [blame] | 2430 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2431 | if (rl_dest.wide) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2432 | cg->GenArithOpLong(cu, dalvik_op, rl_dest, rl_src1, rl_src2); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2433 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2434 | cg->GenArithOpInt(cu, dalvik_op, rl_dest, rl_src1, rl_src2); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | } |
| 2438 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2439 | static void CvtShiftOp(CompilationUnit* cu, Instruction::Code opcode, llvm::CallInst* call_inst) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2440 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2441 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2442 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2443 | RegLocation rl_dest = GetLoc(cu, call_inst); |
| 2444 | RegLocation rl_src = GetLoc(cu, call_inst->getArgOperand(0)); |
| 2445 | llvm::Value* rhs = call_inst->getArgOperand(1); |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 2446 | if (llvm::ConstantInt* src2 = llvm::dyn_cast<llvm::ConstantInt>(rhs)) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2447 | DCHECK(!rl_dest.wide); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2448 | cg->GenArithOpIntLit(cu, opcode, rl_dest, rl_src, src2->getSExtValue()); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2449 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2450 | RegLocation rl_shift = GetLoc(cu, rhs); |
| 2451 | if (call_inst->getType() == cu->irb->getInt64Ty()) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2452 | cg->GenShiftOpLong(cu, opcode, rl_dest, rl_src, rl_shift); |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 2453 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2454 | cg->GenArithOpInt(cu, opcode, rl_dest, rl_src, rl_shift); |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 2455 | } |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2456 | } |
| 2457 | } |
| 2458 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2459 | static void CvtBr(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2460 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2461 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2462 | llvm::BranchInst* br_inst = llvm::dyn_cast<llvm::BranchInst>(inst); |
| 2463 | DCHECK(br_inst != NULL); |
| 2464 | DCHECK(br_inst->isUnconditional()); // May change - but this is all we use now |
| 2465 | llvm::BasicBlock* target_bb = br_inst->getSuccessor(0); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2466 | cg->OpUnconditionalBranch(cu, cu->block_to_label_map.Get(target_bb)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2469 | static void CvtPhi(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2470 | { |
| 2471 | // Nop - these have already been processed |
| 2472 | } |
| 2473 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2474 | static void CvtRet(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2475 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2476 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2477 | llvm::ReturnInst* ret_inst = llvm::dyn_cast<llvm::ReturnInst>(inst); |
| 2478 | llvm::Value* ret_val = ret_inst->getReturnValue(); |
| 2479 | if (ret_val != NULL) { |
| 2480 | RegLocation rl_src = GetLoc(cu, ret_val); |
| 2481 | if (rl_src.wide) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2482 | cg->StoreValueWide(cu, GetReturnWide(cu, rl_src.fp), rl_src); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2483 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2484 | cg->StoreValue(cu, GetReturn(cu, rl_src.fp), rl_src); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2485 | } |
| 2486 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2487 | cg->GenExitSequence(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2490 | static ConditionCode GetCond(llvm::ICmpInst::Predicate llvm_cond) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2491 | { |
| 2492 | ConditionCode res = kCondAl; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2493 | switch(llvm_cond) { |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2494 | case llvm::ICmpInst::ICMP_EQ: res = kCondEq; break; |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2495 | case llvm::ICmpInst::ICMP_NE: res = kCondNe; break; |
| 2496 | case llvm::ICmpInst::ICMP_SLT: res = kCondLt; break; |
| 2497 | case llvm::ICmpInst::ICMP_SGE: res = kCondGe; break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2498 | case llvm::ICmpInst::ICMP_SGT: res = kCondGt; break; |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2499 | case llvm::ICmpInst::ICMP_SLE: res = kCondLe; break; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2500 | default: LOG(FATAL) << "Unexpected llvm condition"; |
| 2501 | } |
| 2502 | return res; |
| 2503 | } |
| 2504 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2505 | static void CvtICmp(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2506 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2507 | // cg->GenCmpLong(cu, rl_dest, rl_src1, rl_src2) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2508 | UNIMPLEMENTED(FATAL); |
| 2509 | } |
| 2510 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2511 | static void CvtICmpBr(CompilationUnit* cu, llvm::Instruction* inst, |
| 2512 | llvm::BranchInst* br_inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2513 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2514 | Codegen* cg = cu->cg.get(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2515 | // Get targets |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2516 | llvm::BasicBlock* taken_bb = br_inst->getSuccessor(0); |
| 2517 | LIR* taken = cu->block_to_label_map.Get(taken_bb); |
| 2518 | llvm::BasicBlock* fallthrough_bb = br_inst->getSuccessor(1); |
| 2519 | LIR* fall_through = cu->block_to_label_map.Get(fallthrough_bb); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2520 | // Get comparison operands |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2521 | llvm::ICmpInst* i_cmp_inst = llvm::dyn_cast<llvm::ICmpInst>(inst); |
| 2522 | ConditionCode cond = GetCond(i_cmp_inst->getPredicate()); |
| 2523 | llvm::Value* lhs = i_cmp_inst->getOperand(0); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2524 | // Not expecting a constant as 1st operand |
| 2525 | DCHECK(llvm::dyn_cast<llvm::ConstantInt>(lhs) == NULL); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2526 | RegLocation rl_src1 = GetLoc(cu, inst->getOperand(0)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2527 | rl_src1 = cg->LoadValue(cu, rl_src1, kCoreReg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2528 | llvm::Value* rhs = inst->getOperand(1); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2529 | if (cu->instruction_set == kMips) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 2530 | // Compare and branch in one shot |
| 2531 | UNIMPLEMENTED(FATAL); |
| 2532 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2533 | //Compare, then branch |
| 2534 | // TODO: handle fused CMP_LONG/IF_xxZ case |
| 2535 | if (llvm::ConstantInt* src2 = llvm::dyn_cast<llvm::ConstantInt>(rhs)) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2536 | cg->OpRegImm(cu, kOpCmp, rl_src1.low_reg, src2->getSExtValue()); |
buzbee | d501889 | 2012-07-11 14:23:40 -0700 | [diff] [blame] | 2537 | } else if (llvm::dyn_cast<llvm::ConstantPointerNull>(rhs) != NULL) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2538 | cg->OpRegImm(cu, kOpCmp, rl_src1.low_reg, 0); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2539 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2540 | RegLocation rl_src2 = GetLoc(cu, rhs); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2541 | rl_src2 = cg->LoadValue(cu, rl_src2, kCoreReg); |
| 2542 | cg->OpRegReg(cu, kOpCmp, rl_src1.low_reg, rl_src2.low_reg); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2543 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2544 | cg->OpCondBranch(cu, cond, taken); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2545 | // Fallthrough |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2546 | cg->OpUnconditionalBranch(cu, fall_through); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2549 | static void CvtCopy(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2550 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2551 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2552 | DCHECK_EQ(call_inst->getNumArgOperands(), 1U); |
| 2553 | RegLocation rl_src = GetLoc(cu, call_inst->getArgOperand(0)); |
| 2554 | RegLocation rl_dest = GetLoc(cu, call_inst); |
| 2555 | DCHECK_EQ(rl_src.wide, rl_dest.wide); |
| 2556 | DCHECK_EQ(rl_src.fp, rl_dest.fp); |
| 2557 | if (rl_src.wide) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2558 | cg->StoreValueWide(cu, rl_dest, rl_src); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2559 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2560 | cg->StoreValue(cu, rl_dest, rl_src); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | // Note: Immediate arg is a ConstantInt regardless of result type |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2565 | static void CvtConst(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2566 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2567 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2568 | DCHECK_EQ(call_inst->getNumArgOperands(), 1U); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2569 | llvm::ConstantInt* src = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2570 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2571 | uint64_t immval = src->getZExtValue(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2572 | RegLocation rl_dest = GetLoc(cu, call_inst); |
| 2573 | RegLocation rl_result = EvalLoc(cu, rl_dest, kAnyReg, true); |
| 2574 | if (rl_dest.wide) { |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 2575 | cg->LoadConstantWide(cu, rl_result.low_reg, rl_result.high_reg, immval); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2576 | cg->StoreValueWide(cu, rl_dest, rl_result); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2577 | } else { |
buzbee | 7da142f | 2012-11-29 16:33:42 -0800 | [diff] [blame] | 2578 | int immediate = immval & 0xffffffff; |
| 2579 | cg->LoadConstantNoClobber(cu, rl_result.low_reg, immediate); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2580 | cg->StoreValue(cu, rl_dest, rl_result); |
buzbee | 7da142f | 2012-11-29 16:33:42 -0800 | [diff] [blame] | 2581 | if (immediate == 0) { |
| 2582 | cg->Workaround7250540(cu, rl_dest, rl_result.low_reg); |
| 2583 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2584 | } |
| 2585 | } |
| 2586 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2587 | static void CvtConstObject(CompilationUnit* cu, llvm::CallInst* call_inst, bool is_string) |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2588 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2589 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2590 | DCHECK_EQ(call_inst->getNumArgOperands(), 1U); |
| 2591 | llvm::ConstantInt* idx_val = |
| 2592 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2593 | uint32_t index = idx_val->getZExtValue(); |
| 2594 | RegLocation rl_dest = GetLoc(cu, call_inst); |
| 2595 | if (is_string) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2596 | cg->GenConstString(cu, index, rl_dest); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2597 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2598 | cg->GenConstClass(cu, index, rl_dest); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2602 | static void CvtFillArrayData(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2603 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2604 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2605 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2606 | llvm::ConstantInt* offset_val = |
| 2607 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2608 | RegLocation rl_src = GetLoc(cu, call_inst->getArgOperand(1)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2609 | cg->GenFillArrayData(cu, offset_val->getSExtValue(), rl_src); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2610 | } |
| 2611 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2612 | static void CvtNewInstance(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2613 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2614 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2615 | DCHECK_EQ(call_inst->getNumArgOperands(), 1U); |
| 2616 | llvm::ConstantInt* type_idx_val = |
| 2617 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2618 | uint32_t type_idx = type_idx_val->getZExtValue(); |
| 2619 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2620 | cg->GenNewInstance(cu, type_idx, rl_dest); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2623 | static void CvtNewArray(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2624 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2625 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2626 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2627 | llvm::ConstantInt* type_idx_val = |
| 2628 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2629 | uint32_t type_idx = type_idx_val->getZExtValue(); |
| 2630 | llvm::Value* len = call_inst->getArgOperand(1); |
| 2631 | RegLocation rl_len = GetLoc(cu, len); |
| 2632 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2633 | cg->GenNewArray(cu, type_idx, rl_dest, rl_len); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2636 | static void CvtInstanceOf(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2637 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2638 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2639 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2640 | llvm::ConstantInt* type_idx_val = |
| 2641 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2642 | uint32_t type_idx = type_idx_val->getZExtValue(); |
| 2643 | llvm::Value* src = call_inst->getArgOperand(1); |
| 2644 | RegLocation rl_src = GetLoc(cu, src); |
| 2645 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2646 | cg->GenInstanceof(cu, type_idx, rl_dest, rl_src); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2649 | static void CvtThrow(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 2650 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2651 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2652 | DCHECK_EQ(call_inst->getNumArgOperands(), 1U); |
| 2653 | llvm::Value* src = call_inst->getArgOperand(0); |
| 2654 | RegLocation rl_src = GetLoc(cu, src); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2655 | cg->GenThrow(cu, rl_src); |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2658 | static void CvtMonitorEnterExit(CompilationUnit* cu, bool is_enter, |
| 2659 | llvm::CallInst* call_inst) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2660 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2661 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2662 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2663 | llvm::ConstantInt* opt_flags = |
| 2664 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2665 | llvm::Value* src = call_inst->getArgOperand(1); |
| 2666 | RegLocation rl_src = GetLoc(cu, src); |
| 2667 | if (is_enter) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2668 | cg->GenMonitorEnter(cu, opt_flags->getZExtValue(), rl_src); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2669 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2670 | cg->GenMonitorExit(cu, opt_flags->getZExtValue(), rl_src); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2674 | static void CvtArrayLength(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2675 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2676 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2677 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2678 | llvm::ConstantInt* opt_flags = |
| 2679 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2680 | llvm::Value* src = call_inst->getArgOperand(1); |
| 2681 | RegLocation rl_src = GetLoc(cu, src); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2682 | rl_src = cg->LoadValue(cu, rl_src, kCoreReg); |
| 2683 | cg->GenNullCheck(cu, rl_src.s_reg_low, rl_src.low_reg, opt_flags->getZExtValue()); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2684 | RegLocation rl_dest = GetLoc(cu, call_inst); |
| 2685 | RegLocation rl_result = EvalLoc(cu, rl_dest, kCoreReg, true); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 2686 | int len_offset = mirror::Array::LengthOffset().Int32Value(); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2687 | cg->LoadWordDisp(cu, rl_src.low_reg, len_offset, rl_result.low_reg); |
| 2688 | cg->StoreValue(cu, rl_dest, rl_result); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2691 | static void CvtMoveException(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 2692 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2693 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2694 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2695 | cg->GenMoveException(cu, rl_dest); |
buzbee | 3241296 | 2012-06-26 16:27:56 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2698 | static void CvtSget(CompilationUnit* cu, llvm::CallInst* call_inst, bool is_wide, bool is_object) |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2699 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2700 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2701 | DCHECK_EQ(call_inst->getNumArgOperands(), 1U); |
| 2702 | llvm::ConstantInt* type_idx_val = |
| 2703 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2704 | uint32_t type_idx = type_idx_val->getZExtValue(); |
| 2705 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2706 | cg->GenSget(cu, type_idx, rl_dest, is_wide, is_object); |
buzbee | 4f1181f | 2012-06-22 13:52:12 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2709 | static void CvtSput(CompilationUnit* cu, llvm::CallInst* call_inst, bool is_wide, bool is_object) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2710 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2711 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2712 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2713 | llvm::ConstantInt* type_idx_val = |
| 2714 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2715 | uint32_t type_idx = type_idx_val->getZExtValue(); |
| 2716 | llvm::Value* src = call_inst->getArgOperand(1); |
| 2717 | RegLocation rl_src = GetLoc(cu, src); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2718 | cg->GenSput(cu, type_idx, rl_src, is_wide, is_object); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2721 | static void CvtAget(CompilationUnit* cu, llvm::CallInst* call_inst, OpSize size, int scale) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2722 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2723 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2724 | DCHECK_EQ(call_inst->getNumArgOperands(), 3U); |
| 2725 | llvm::ConstantInt* opt_flags = |
| 2726 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2727 | RegLocation rl_array = GetLoc(cu, call_inst->getArgOperand(1)); |
| 2728 | RegLocation rl_index = GetLoc(cu, call_inst->getArgOperand(2)); |
| 2729 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2730 | cg->GenArrayGet(cu, opt_flags->getZExtValue(), size, rl_array, rl_index, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2731 | rl_dest, scale); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2734 | static void CvtAput(CompilationUnit* cu, llvm::CallInst* call_inst, OpSize size, |
| 2735 | int scale, bool is_object) |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2736 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2737 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2738 | DCHECK_EQ(call_inst->getNumArgOperands(), 4U); |
| 2739 | llvm::ConstantInt* opt_flags = |
| 2740 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2741 | RegLocation rl_src = GetLoc(cu, call_inst->getArgOperand(1)); |
| 2742 | RegLocation rl_array = GetLoc(cu, call_inst->getArgOperand(2)); |
| 2743 | RegLocation rl_index = GetLoc(cu, call_inst->getArgOperand(3)); |
| 2744 | if (is_object) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2745 | cg->GenArrayObjPut(cu, opt_flags->getZExtValue(), rl_array, rl_index, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2746 | rl_src, scale); |
buzbee | f1f8636 | 2012-07-10 15:18:31 -0700 | [diff] [blame] | 2747 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2748 | cg->GenArrayPut(cu, opt_flags->getZExtValue(), size, rl_array, rl_index, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2749 | rl_src, scale); |
buzbee | f1f8636 | 2012-07-10 15:18:31 -0700 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2753 | static void CvtAputObj(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | f1f8636 | 2012-07-10 15:18:31 -0700 | [diff] [blame] | 2754 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2755 | CvtAput(cu, call_inst, kWord, 2, true /* is_object */); |
buzbee | f1f8636 | 2012-07-10 15:18:31 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2758 | static void CvtAputPrimitive(CompilationUnit* cu, llvm::CallInst* call_inst, |
buzbee | f1f8636 | 2012-07-10 15:18:31 -0700 | [diff] [blame] | 2759 | OpSize size, int scale) |
| 2760 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2761 | CvtAput(cu, call_inst, size, scale, false /* is_object */); |
buzbee | 8fa0fda | 2012-06-27 15:44:52 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2764 | static void CvtIget(CompilationUnit* cu, llvm::CallInst* call_inst, OpSize size, |
| 2765 | bool is_wide, bool is_obj) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2766 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2767 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2768 | DCHECK_EQ(call_inst->getNumArgOperands(), 3U); |
| 2769 | llvm::ConstantInt* opt_flags = |
| 2770 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2771 | RegLocation rl_obj = GetLoc(cu, call_inst->getArgOperand(1)); |
| 2772 | llvm::ConstantInt* field_idx = |
| 2773 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(2)); |
| 2774 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2775 | cg->GenIGet(cu, field_idx->getZExtValue(), opt_flags->getZExtValue(), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2776 | size, rl_dest, rl_obj, is_wide, is_obj); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2779 | static void CvtIput(CompilationUnit* cu, llvm::CallInst* call_inst, OpSize size, |
| 2780 | bool is_wide, bool is_obj) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2781 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2782 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2783 | DCHECK_EQ(call_inst->getNumArgOperands(), 4U); |
| 2784 | llvm::ConstantInt* opt_flags = |
| 2785 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2786 | RegLocation rl_src = GetLoc(cu, call_inst->getArgOperand(1)); |
| 2787 | RegLocation rl_obj = GetLoc(cu, call_inst->getArgOperand(2)); |
| 2788 | llvm::ConstantInt* field_idx = |
| 2789 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(3)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2790 | cg->GenIPut(cu, field_idx->getZExtValue(), opt_flags->getZExtValue(), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2791 | size, rl_src, rl_obj, is_wide, is_obj); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2794 | static void CvtCheckCast(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2795 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2796 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2797 | DCHECK_EQ(call_inst->getNumArgOperands(), 2U); |
| 2798 | llvm::ConstantInt* type_idx = |
| 2799 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2800 | RegLocation rl_src = GetLoc(cu, call_inst->getArgOperand(1)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2801 | cg->GenCheckCast(cu, type_idx->getZExtValue(), rl_src); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2804 | static void CvtFPCompare(CompilationUnit* cu, llvm::CallInst* call_inst, |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 2805 | Instruction::Code opcode) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2806 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2807 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2808 | RegLocation rl_src1 = GetLoc(cu, call_inst->getArgOperand(0)); |
| 2809 | RegLocation rl_src2 = GetLoc(cu, call_inst->getArgOperand(1)); |
| 2810 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2811 | cg->GenCmpFP(cu, opcode, rl_dest, rl_src1, rl_src2); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2814 | static void CvtLongCompare(CompilationUnit* cu, llvm::CallInst* call_inst) |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2815 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2816 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2817 | RegLocation rl_src1 = GetLoc(cu, call_inst->getArgOperand(0)); |
| 2818 | RegLocation rl_src2 = GetLoc(cu, call_inst->getArgOperand(1)); |
| 2819 | RegLocation rl_dest = GetLoc(cu, call_inst); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2820 | cg->GenCmpLong(cu, rl_dest, rl_src1, rl_src2); |
buzbee | 7659263 | 2012-06-29 15:18:35 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2823 | static void CvtSwitch(CompilationUnit* cu, llvm::Instruction* inst) |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 2824 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2825 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2826 | llvm::SwitchInst* sw_inst = llvm::dyn_cast<llvm::SwitchInst>(inst); |
| 2827 | DCHECK(sw_inst != NULL); |
| 2828 | llvm::Value* test_val = sw_inst->getCondition(); |
| 2829 | llvm::MDNode* table_offset_node = sw_inst->getMetadata("SwitchTable"); |
| 2830 | DCHECK(table_offset_node != NULL); |
| 2831 | llvm::ConstantInt* table_offset_value = |
| 2832 | static_cast<llvm::ConstantInt*>(table_offset_node->getOperand(0)); |
| 2833 | int32_t table_offset = table_offset_value->getSExtValue(); |
| 2834 | RegLocation rl_src = GetLoc(cu, test_val); |
| 2835 | const uint16_t* table = cu->insns + cu->current_dalvik_offset + table_offset; |
| 2836 | uint16_t table_magic = *table; |
| 2837 | if (table_magic == 0x100) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2838 | cg->GenPackedSwitch(cu, table_offset, rl_src); |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 2839 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2840 | DCHECK_EQ(table_magic, 0x200); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2841 | cg->GenSparseSwitch(cu, table_offset, rl_src); |
buzbee | a1da8a5 | 2012-07-09 14:00:21 -0700 | [diff] [blame] | 2842 | } |
buzbee | f58c12c | 2012-07-03 15:06:29 -0700 | [diff] [blame] | 2843 | } |
| 2844 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2845 | static void CvtInvoke(CompilationUnit* cu, llvm::CallInst* call_inst, bool is_void, |
| 2846 | bool is_filled_new_array) |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2847 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2848 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2849 | CallInfo* info = static_cast<CallInfo*>(NewMem(cu, sizeof(CallInfo), true, kAllocMisc)); |
| 2850 | if (is_void) { |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2851 | info->result.location = kLocInvalid; |
| 2852 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2853 | info->result = GetLoc(cu, call_inst); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2854 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2855 | llvm::ConstantInt* invoke_type_val = |
| 2856 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(0)); |
| 2857 | llvm::ConstantInt* method_index_val = |
| 2858 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(1)); |
| 2859 | llvm::ConstantInt* opt_flags_val = |
| 2860 | llvm::dyn_cast<llvm::ConstantInt>(call_inst->getArgOperand(2)); |
| 2861 | info->type = static_cast<InvokeType>(invoke_type_val->getZExtValue()); |
| 2862 | info->index = method_index_val->getZExtValue(); |
| 2863 | info->opt_flags = opt_flags_val->getZExtValue(); |
| 2864 | info->offset = cu->current_dalvik_offset; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2865 | |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2866 | // Count the argument words, and then build argument array. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2867 | info->num_arg_words = 0; |
| 2868 | for (unsigned int i = 3; i < call_inst->getNumArgOperands(); i++) { |
| 2869 | RegLocation t_loc = GetLoc(cu, call_inst->getArgOperand(i)); |
| 2870 | info->num_arg_words += t_loc.wide ? 2 : 1; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2871 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2872 | info->args = (info->num_arg_words == 0) ? NULL : static_cast<RegLocation*> |
| 2873 | (NewMem(cu, sizeof(RegLocation) * info->num_arg_words, false, kAllocMisc)); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2874 | // Now, fill in the location records, synthesizing high loc of wide vals |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2875 | for (int i = 3, next = 0; next < info->num_arg_words;) { |
| 2876 | info->args[next] = GetLoc(cu, call_inst->getArgOperand(i++)); |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2877 | if (info->args[next].wide) { |
| 2878 | next++; |
| 2879 | // TODO: Might make sense to mark this as an invalid loc |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2880 | info->args[next].orig_sreg = info->args[next-1].orig_sreg+1; |
| 2881 | info->args[next].s_reg_low = info->args[next-1].s_reg_low+1; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2882 | } |
| 2883 | next++; |
| 2884 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2885 | // TODO - rework such that we no longer need is_range |
| 2886 | info->is_range = (info->num_arg_words > 5); |
buzbee | 4f4dfc7 | 2012-07-02 14:54:44 -0700 | [diff] [blame] | 2887 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2888 | if (is_filled_new_array) { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2889 | cg->GenFilledNewArray(cu, info); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2890 | } else { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2891 | cg->GenInvoke(cu, info); |
buzbee | 101305f | 2012-06-28 18:00:56 -0700 | [diff] [blame] | 2892 | } |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 2895 | /* Look up the RegLocation associated with a Value. Must already be defined */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2896 | static RegLocation ValToLoc(CompilationUnit* cu, llvm::Value* val) |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 2897 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2898 | SafeMap<llvm::Value*, RegLocation>::iterator it = cu->loc_map.find(val); |
| 2899 | DCHECK(it != cu->loc_map.end()) << "Missing definition"; |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 2900 | return it->second; |
| 2901 | } |
| 2902 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2903 | static bool BitcodeBlockCodeGen(CompilationUnit* cu, llvm::BasicBlock* bb) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2904 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2905 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2906 | while (cu->llvm_blocks.find(bb) == cu->llvm_blocks.end()) { |
| 2907 | llvm::BasicBlock* next_bb = NULL; |
| 2908 | cu->llvm_blocks.insert(bb); |
| 2909 | bool is_entry = (bb == &cu->func->getEntryBlock()); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2910 | // Define the starting label |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2911 | LIR* block_label = cu->block_to_label_map.Get(bb); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2912 | // Extract the type and starting offset from the block's name |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2913 | char block_type = kInvalidBlock; |
| 2914 | if (is_entry) { |
| 2915 | block_type = kNormalBlock; |
| 2916 | block_label->operands[0] = 0; |
buzbee | 951c0a1 | 2012-10-03 16:31:39 -0700 | [diff] [blame] | 2917 | } else if (!bb->hasName()) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2918 | block_type = kNormalBlock; |
| 2919 | block_label->operands[0] = DexFile::kDexNoIndex; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2920 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2921 | std::string block_name = bb->getName().str(); |
buzbee | 951c0a1 | 2012-10-03 16:31:39 -0700 | [diff] [blame] | 2922 | int dummy; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2923 | sscanf(block_name.c_str(), kLabelFormat, &block_type, &block_label->operands[0], &dummy); |
| 2924 | cu->current_dalvik_offset = block_label->operands[0]; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2925 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2926 | DCHECK((block_type == kNormalBlock) || (block_type == kCatchBlock)); |
| 2927 | cu->current_dalvik_offset = block_label->operands[0]; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2928 | // Set the label kind |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2929 | block_label->opcode = kPseudoNormalBlockLabel; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2930 | // Insert the label |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2931 | AppendLIR(cu, block_label); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2932 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2933 | LIR* head_lir = NULL; |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 2934 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2935 | if (block_type == kCatchBlock) { |
| 2936 | head_lir = NewLIR0(cu, kPseudoExportedPC); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2937 | } |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 2938 | |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2939 | // Free temp registers and reset redundant store tracking */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2940 | ResetRegPool(cu); |
| 2941 | ResetDefTracking(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2942 | |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2943 | //TODO: restore oat incoming liveness optimization |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2944 | ClobberAllRegs(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 2945 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2946 | if (is_entry) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 2947 | RegLocation* ArgLocs = static_cast<RegLocation*> |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2948 | (NewMem(cu, sizeof(RegLocation) * cu->num_ins, true, kAllocMisc)); |
| 2949 | llvm::Function::arg_iterator it(cu->func->arg_begin()); |
| 2950 | llvm::Function::arg_iterator it_end(cu->func->arg_end()); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2951 | // Skip past Method* |
| 2952 | it++; |
| 2953 | for (unsigned i = 0; it != it_end; ++it) { |
| 2954 | llvm::Value* val = it; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2955 | ArgLocs[i++] = ValToLoc(cu, val); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2956 | llvm::Type* ty = val->getType(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2957 | if ((ty == cu->irb->getInt64Ty()) || (ty == cu->irb->getDoubleTy())) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 2958 | ArgLocs[i] = ArgLocs[i-1]; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2959 | ArgLocs[i].low_reg = ArgLocs[i].high_reg; |
| 2960 | ArgLocs[i].orig_sreg++; |
| 2961 | ArgLocs[i].s_reg_low = INVALID_SREG; |
| 2962 | ArgLocs[i].high_word = true; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2963 | i++; |
| 2964 | } |
| 2965 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 2966 | cg->GenEntrySequence(cu, ArgLocs, cu->method_loc); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | // Visit all of the instructions in the block |
| 2970 | for (llvm::BasicBlock::iterator it = bb->begin(), e = bb->end(); it != e;) { |
| 2971 | llvm::Instruction* inst = it; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2972 | llvm::BasicBlock::iterator next_it = ++it; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2973 | // Extract the Dalvik offset from the instruction |
| 2974 | uint32_t opcode = inst->getOpcode(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2975 | llvm::MDNode* dex_offset_node = inst->getMetadata("DexOff"); |
| 2976 | if (dex_offset_node != NULL) { |
| 2977 | llvm::ConstantInt* dex_offset_value = |
| 2978 | static_cast<llvm::ConstantInt*>(dex_offset_node->getOperand(0)); |
| 2979 | cu->current_dalvik_offset = dex_offset_value->getZExtValue(); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2982 | ResetRegPool(cu); |
| 2983 | if (cu->disable_opt & (1 << kTrackLiveTemps)) { |
| 2984 | ClobberAllRegs(cu); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2987 | if (cu->disable_opt & (1 << kSuppressLoads)) { |
| 2988 | ResetDefTracking(cu); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
| 2991 | #ifndef NDEBUG |
| 2992 | /* Reset temp tracking sanity check */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2993 | cu->live_sreg = INVALID_SREG; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2994 | #endif |
| 2995 | |
| 2996 | // TODO: use llvm opcode name here instead of "boundary" if verbose |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 2997 | LIR* boundary_lir = MarkBoundary(cu, cu->current_dalvik_offset, "boundary"); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 2998 | |
| 2999 | /* Remember the first LIR for thisl block*/ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3000 | if (head_lir == NULL) { |
| 3001 | head_lir = boundary_lir; |
| 3002 | head_lir->def_mask = ENCODE_ALL; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | switch(opcode) { |
| 3006 | |
| 3007 | case llvm::Instruction::ICmp: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3008 | llvm::Instruction* next_inst = next_it; |
| 3009 | llvm::BranchInst* br_inst = llvm::dyn_cast<llvm::BranchInst>(next_inst); |
| 3010 | if (br_inst != NULL /* and... */) { |
| 3011 | CvtICmpBr(cu, inst, br_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3012 | ++it; |
| 3013 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3014 | CvtICmp(cu, inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3015 | } |
| 3016 | } |
| 3017 | break; |
| 3018 | |
| 3019 | case llvm::Instruction::Call: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3020 | llvm::CallInst* call_inst = llvm::dyn_cast<llvm::CallInst>(inst); |
| 3021 | llvm::Function* callee = call_inst->getCalledFunction(); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3022 | greenland::IntrinsicHelper::IntrinsicId id = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3023 | cu->intrinsic_helper->GetIntrinsicId(callee); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3024 | switch (id) { |
| 3025 | case greenland::IntrinsicHelper::AllocaShadowFrame: |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3026 | case greenland::IntrinsicHelper::PopShadowFrame: |
TDYa127 | 8e950c1 | 2012-11-02 09:58:19 -0700 | [diff] [blame] | 3027 | case greenland::IntrinsicHelper::SetVReg: |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3028 | // Ignore shadow frame stuff for quick compiler |
| 3029 | break; |
| 3030 | case greenland::IntrinsicHelper::CopyInt: |
| 3031 | case greenland::IntrinsicHelper::CopyObj: |
| 3032 | case greenland::IntrinsicHelper::CopyFloat: |
| 3033 | case greenland::IntrinsicHelper::CopyLong: |
| 3034 | case greenland::IntrinsicHelper::CopyDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3035 | CvtCopy(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3036 | break; |
| 3037 | case greenland::IntrinsicHelper::ConstInt: |
| 3038 | case greenland::IntrinsicHelper::ConstObj: |
| 3039 | case greenland::IntrinsicHelper::ConstLong: |
| 3040 | case greenland::IntrinsicHelper::ConstFloat: |
| 3041 | case greenland::IntrinsicHelper::ConstDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3042 | CvtConst(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3043 | break; |
| 3044 | case greenland::IntrinsicHelper::DivInt: |
| 3045 | case greenland::IntrinsicHelper::DivLong: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3046 | CvtBinOp(cu, kOpDiv, inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3047 | break; |
| 3048 | case greenland::IntrinsicHelper::RemInt: |
| 3049 | case greenland::IntrinsicHelper::RemLong: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3050 | CvtBinOp(cu, kOpRem, inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3051 | break; |
| 3052 | case greenland::IntrinsicHelper::MethodInfo: |
| 3053 | // Already dealt with - just ignore it here. |
| 3054 | break; |
| 3055 | case greenland::IntrinsicHelper::CheckSuspend: |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 3056 | cg->GenSuspendTest(cu, 0 /* opt_flags already applied */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3057 | break; |
| 3058 | case greenland::IntrinsicHelper::HLInvokeObj: |
| 3059 | case greenland::IntrinsicHelper::HLInvokeFloat: |
| 3060 | case greenland::IntrinsicHelper::HLInvokeDouble: |
| 3061 | case greenland::IntrinsicHelper::HLInvokeLong: |
| 3062 | case greenland::IntrinsicHelper::HLInvokeInt: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3063 | CvtInvoke(cu, call_inst, false /* is_void */, false /* new_array */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3064 | break; |
| 3065 | case greenland::IntrinsicHelper::HLInvokeVoid: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3066 | CvtInvoke(cu, call_inst, true /* is_void */, false /* new_array */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3067 | break; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3068 | case greenland::IntrinsicHelper::HLFilledNewArray: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3069 | CvtInvoke(cu, call_inst, false /* is_void */, true /* new_array */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3070 | break; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3071 | case greenland::IntrinsicHelper::HLFillArrayData: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3072 | CvtFillArrayData(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3073 | break; |
| 3074 | case greenland::IntrinsicHelper::ConstString: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3075 | CvtConstObject(cu, call_inst, true /* is_string */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3076 | break; |
| 3077 | case greenland::IntrinsicHelper::ConstClass: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3078 | CvtConstObject(cu, call_inst, false /* is_string */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3079 | break; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3080 | case greenland::IntrinsicHelper::HLCheckCast: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3081 | CvtCheckCast(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3082 | break; |
| 3083 | case greenland::IntrinsicHelper::NewInstance: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3084 | CvtNewInstance(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3085 | break; |
| 3086 | case greenland::IntrinsicHelper::HLSgetObject: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3087 | CvtSget(cu, call_inst, false /* wide */, true /* Object */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3088 | break; |
| 3089 | case greenland::IntrinsicHelper::HLSget: |
| 3090 | case greenland::IntrinsicHelper::HLSgetFloat: |
| 3091 | case greenland::IntrinsicHelper::HLSgetBoolean: |
| 3092 | case greenland::IntrinsicHelper::HLSgetByte: |
| 3093 | case greenland::IntrinsicHelper::HLSgetChar: |
| 3094 | case greenland::IntrinsicHelper::HLSgetShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3095 | CvtSget(cu, call_inst, false /* wide */, false /* Object */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3096 | break; |
| 3097 | case greenland::IntrinsicHelper::HLSgetWide: |
| 3098 | case greenland::IntrinsicHelper::HLSgetDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3099 | CvtSget(cu, call_inst, true /* wide */, false /* Object */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3100 | break; |
| 3101 | case greenland::IntrinsicHelper::HLSput: |
| 3102 | case greenland::IntrinsicHelper::HLSputFloat: |
| 3103 | case greenland::IntrinsicHelper::HLSputBoolean: |
| 3104 | case greenland::IntrinsicHelper::HLSputByte: |
| 3105 | case greenland::IntrinsicHelper::HLSputChar: |
| 3106 | case greenland::IntrinsicHelper::HLSputShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3107 | CvtSput(cu, call_inst, false /* wide */, false /* Object */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3108 | break; |
| 3109 | case greenland::IntrinsicHelper::HLSputWide: |
| 3110 | case greenland::IntrinsicHelper::HLSputDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3111 | CvtSput(cu, call_inst, true /* wide */, false /* Object */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3112 | break; |
| 3113 | case greenland::IntrinsicHelper::HLSputObject: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3114 | CvtSput(cu, call_inst, false /* wide */, true /* Object */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3115 | break; |
| 3116 | case greenland::IntrinsicHelper::GetException: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3117 | CvtMoveException(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3118 | break; |
TDYa127 | f71bf5a | 2012-07-29 20:09:52 -0700 | [diff] [blame] | 3119 | case greenland::IntrinsicHelper::HLThrowException: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3120 | CvtThrow(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3121 | break; |
| 3122 | case greenland::IntrinsicHelper::MonitorEnter: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3123 | CvtMonitorEnterExit(cu, true /* is_enter */, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3124 | break; |
| 3125 | case greenland::IntrinsicHelper::MonitorExit: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3126 | CvtMonitorEnterExit(cu, false /* is_enter */, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3127 | break; |
Shih-wei Liao | 21d28f5 | 2012-06-12 05:55:00 -0700 | [diff] [blame] | 3128 | case greenland::IntrinsicHelper::OptArrayLength: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3129 | CvtArrayLength(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3130 | break; |
| 3131 | case greenland::IntrinsicHelper::NewArray: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3132 | CvtNewArray(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3133 | break; |
| 3134 | case greenland::IntrinsicHelper::InstanceOf: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3135 | CvtInstanceOf(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3136 | break; |
| 3137 | |
| 3138 | case greenland::IntrinsicHelper::HLArrayGet: |
| 3139 | case greenland::IntrinsicHelper::HLArrayGetObject: |
| 3140 | case greenland::IntrinsicHelper::HLArrayGetFloat: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3141 | CvtAget(cu, call_inst, kWord, 2); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3142 | break; |
| 3143 | case greenland::IntrinsicHelper::HLArrayGetWide: |
| 3144 | case greenland::IntrinsicHelper::HLArrayGetDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3145 | CvtAget(cu, call_inst, kLong, 3); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3146 | break; |
| 3147 | case greenland::IntrinsicHelper::HLArrayGetBoolean: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3148 | CvtAget(cu, call_inst, kUnsignedByte, 0); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3149 | break; |
| 3150 | case greenland::IntrinsicHelper::HLArrayGetByte: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3151 | CvtAget(cu, call_inst, kSignedByte, 0); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3152 | break; |
| 3153 | case greenland::IntrinsicHelper::HLArrayGetChar: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3154 | CvtAget(cu, call_inst, kUnsignedHalf, 1); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3155 | break; |
| 3156 | case greenland::IntrinsicHelper::HLArrayGetShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3157 | CvtAget(cu, call_inst, kSignedHalf, 1); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3158 | break; |
| 3159 | |
| 3160 | case greenland::IntrinsicHelper::HLArrayPut: |
| 3161 | case greenland::IntrinsicHelper::HLArrayPutFloat: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3162 | CvtAputPrimitive(cu, call_inst, kWord, 2); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3163 | break; |
| 3164 | case greenland::IntrinsicHelper::HLArrayPutObject: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3165 | CvtAputObj(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3166 | break; |
| 3167 | case greenland::IntrinsicHelper::HLArrayPutWide: |
| 3168 | case greenland::IntrinsicHelper::HLArrayPutDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3169 | CvtAputPrimitive(cu, call_inst, kLong, 3); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3170 | break; |
| 3171 | case greenland::IntrinsicHelper::HLArrayPutBoolean: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3172 | CvtAputPrimitive(cu, call_inst, kUnsignedByte, 0); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3173 | break; |
| 3174 | case greenland::IntrinsicHelper::HLArrayPutByte: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3175 | CvtAputPrimitive(cu, call_inst, kSignedByte, 0); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3176 | break; |
| 3177 | case greenland::IntrinsicHelper::HLArrayPutChar: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3178 | CvtAputPrimitive(cu, call_inst, kUnsignedHalf, 1); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3179 | break; |
| 3180 | case greenland::IntrinsicHelper::HLArrayPutShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3181 | CvtAputPrimitive(cu, call_inst, kSignedHalf, 1); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3182 | break; |
| 3183 | |
| 3184 | case greenland::IntrinsicHelper::HLIGet: |
| 3185 | case greenland::IntrinsicHelper::HLIGetFloat: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3186 | CvtIget(cu, call_inst, kWord, false /* is_wide */, false /* obj */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3187 | break; |
| 3188 | case greenland::IntrinsicHelper::HLIGetObject: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3189 | CvtIget(cu, call_inst, kWord, false /* is_wide */, true /* obj */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3190 | break; |
| 3191 | case greenland::IntrinsicHelper::HLIGetWide: |
| 3192 | case greenland::IntrinsicHelper::HLIGetDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3193 | CvtIget(cu, call_inst, kLong, true /* is_wide */, false /* obj */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3194 | break; |
| 3195 | case greenland::IntrinsicHelper::HLIGetBoolean: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3196 | CvtIget(cu, call_inst, kUnsignedByte, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3197 | false /* obj */); |
| 3198 | break; |
| 3199 | case greenland::IntrinsicHelper::HLIGetByte: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3200 | CvtIget(cu, call_inst, kSignedByte, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3201 | false /* obj */); |
| 3202 | break; |
| 3203 | case greenland::IntrinsicHelper::HLIGetChar: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3204 | CvtIget(cu, call_inst, kUnsignedHalf, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3205 | false /* obj */); |
| 3206 | break; |
| 3207 | case greenland::IntrinsicHelper::HLIGetShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3208 | CvtIget(cu, call_inst, kSignedHalf, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3209 | false /* obj */); |
| 3210 | break; |
| 3211 | |
| 3212 | case greenland::IntrinsicHelper::HLIPut: |
| 3213 | case greenland::IntrinsicHelper::HLIPutFloat: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3214 | CvtIput(cu, call_inst, kWord, false /* is_wide */, false /* obj */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3215 | break; |
| 3216 | case greenland::IntrinsicHelper::HLIPutObject: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3217 | CvtIput(cu, call_inst, kWord, false /* is_wide */, true /* obj */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3218 | break; |
| 3219 | case greenland::IntrinsicHelper::HLIPutWide: |
| 3220 | case greenland::IntrinsicHelper::HLIPutDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3221 | CvtIput(cu, call_inst, kLong, true /* is_wide */, false /* obj */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3222 | break; |
| 3223 | case greenland::IntrinsicHelper::HLIPutBoolean: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3224 | CvtIput(cu, call_inst, kUnsignedByte, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3225 | false /* obj */); |
| 3226 | break; |
| 3227 | case greenland::IntrinsicHelper::HLIPutByte: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3228 | CvtIput(cu, call_inst, kSignedByte, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3229 | false /* obj */); |
| 3230 | break; |
| 3231 | case greenland::IntrinsicHelper::HLIPutChar: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3232 | CvtIput(cu, call_inst, kUnsignedHalf, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3233 | false /* obj */); |
| 3234 | break; |
| 3235 | case greenland::IntrinsicHelper::HLIPutShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3236 | CvtIput(cu, call_inst, kSignedHalf, false /* is_wide */, |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3237 | false /* obj */); |
| 3238 | break; |
| 3239 | |
| 3240 | case greenland::IntrinsicHelper::IntToChar: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3241 | CvtIntNarrowing(cu, call_inst, Instruction::INT_TO_CHAR); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3242 | break; |
| 3243 | case greenland::IntrinsicHelper::IntToShort: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3244 | CvtIntNarrowing(cu, call_inst, Instruction::INT_TO_SHORT); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3245 | break; |
| 3246 | case greenland::IntrinsicHelper::IntToByte: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3247 | CvtIntNarrowing(cu, call_inst, Instruction::INT_TO_BYTE); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3248 | break; |
| 3249 | |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3250 | case greenland::IntrinsicHelper::F2I: |
| 3251 | case greenland::IntrinsicHelper::D2I: |
| 3252 | case greenland::IntrinsicHelper::F2L: |
| 3253 | case greenland::IntrinsicHelper::D2L: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3254 | CvtFPToInt(cu, call_inst); |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3255 | break; |
| 3256 | |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3257 | case greenland::IntrinsicHelper::CmplFloat: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3258 | CvtFPCompare(cu, call_inst, Instruction::CMPL_FLOAT); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3259 | break; |
| 3260 | case greenland::IntrinsicHelper::CmpgFloat: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3261 | CvtFPCompare(cu, call_inst, Instruction::CMPG_FLOAT); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3262 | break; |
| 3263 | case greenland::IntrinsicHelper::CmplDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3264 | CvtFPCompare(cu, call_inst, Instruction::CMPL_DOUBLE); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3265 | break; |
| 3266 | case greenland::IntrinsicHelper::CmpgDouble: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3267 | CvtFPCompare(cu, call_inst, Instruction::CMPG_DOUBLE); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3268 | break; |
| 3269 | |
| 3270 | case greenland::IntrinsicHelper::CmpLong: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3271 | CvtLongCompare(cu, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3272 | break; |
| 3273 | |
| 3274 | case greenland::IntrinsicHelper::SHLLong: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3275 | CvtShiftOp(cu, Instruction::SHL_LONG, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3276 | break; |
| 3277 | case greenland::IntrinsicHelper::SHRLong: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3278 | CvtShiftOp(cu, Instruction::SHR_LONG, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3279 | break; |
| 3280 | case greenland::IntrinsicHelper::USHRLong: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3281 | CvtShiftOp(cu, Instruction::USHR_LONG, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3282 | break; |
| 3283 | case greenland::IntrinsicHelper::SHLInt: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3284 | CvtShiftOp(cu, Instruction::SHL_INT, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3285 | break; |
| 3286 | case greenland::IntrinsicHelper::SHRInt: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3287 | CvtShiftOp(cu, Instruction::SHR_INT, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3288 | break; |
| 3289 | case greenland::IntrinsicHelper::USHRInt: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3290 | CvtShiftOp(cu, Instruction::USHR_INT, call_inst); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3291 | break; |
| 3292 | |
| 3293 | case greenland::IntrinsicHelper::CatchTargets: { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3294 | llvm::SwitchInst* sw_inst = |
| 3295 | llvm::dyn_cast<llvm::SwitchInst>(next_it); |
| 3296 | DCHECK(sw_inst != NULL); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3297 | /* |
| 3298 | * Discard the edges and the following conditional branch. |
| 3299 | * Do a direct branch to the default target (which is the |
| 3300 | * "work" portion of the pair. |
| 3301 | * TODO: awful code layout - rework |
| 3302 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3303 | llvm::BasicBlock* target_bb = sw_inst->getDefaultDest(); |
| 3304 | DCHECK(target_bb != NULL); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 3305 | cg->OpUnconditionalBranch(cu, cu->block_to_label_map.Get(target_bb)); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3306 | ++it; |
| 3307 | // Set next bb to default target - improves code layout |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3308 | next_bb = target_bb; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3309 | } |
| 3310 | break; |
| 3311 | |
| 3312 | default: |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3313 | LOG(FATAL) << "Unexpected intrinsic " << cu->intrinsic_helper->GetName(id); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3314 | } |
| 3315 | } |
| 3316 | break; |
| 3317 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3318 | case llvm::Instruction::Br: CvtBr(cu, inst); break; |
| 3319 | case llvm::Instruction::Add: CvtBinOp(cu, kOpAdd, inst); break; |
| 3320 | case llvm::Instruction::Sub: CvtBinOp(cu, kOpSub, inst); break; |
| 3321 | case llvm::Instruction::Mul: CvtBinOp(cu, kOpMul, inst); break; |
| 3322 | case llvm::Instruction::SDiv: CvtBinOp(cu, kOpDiv, inst); break; |
| 3323 | case llvm::Instruction::SRem: CvtBinOp(cu, kOpRem, inst); break; |
| 3324 | case llvm::Instruction::And: CvtBinOp(cu, kOpAnd, inst); break; |
| 3325 | case llvm::Instruction::Or: CvtBinOp(cu, kOpOr, inst); break; |
| 3326 | case llvm::Instruction::Xor: CvtBinOp(cu, kOpXor, inst); break; |
| 3327 | case llvm::Instruction::PHI: CvtPhi(cu, inst); break; |
| 3328 | case llvm::Instruction::Ret: CvtRet(cu, inst); break; |
| 3329 | case llvm::Instruction::FAdd: CvtBinFPOp(cu, kOpAdd, inst); break; |
| 3330 | case llvm::Instruction::FSub: CvtBinFPOp(cu, kOpSub, inst); break; |
| 3331 | case llvm::Instruction::FMul: CvtBinFPOp(cu, kOpMul, inst); break; |
| 3332 | case llvm::Instruction::FDiv: CvtBinFPOp(cu, kOpDiv, inst); break; |
| 3333 | case llvm::Instruction::FRem: CvtBinFPOp(cu, kOpRem, inst); break; |
| 3334 | case llvm::Instruction::SIToFP: CvtIntToFP(cu, inst); break; |
| 3335 | case llvm::Instruction::FPTrunc: CvtDoubleToFloat(cu, inst); break; |
| 3336 | case llvm::Instruction::FPExt: CvtFloatToDouble(cu, inst); break; |
| 3337 | case llvm::Instruction::Trunc: CvtTrunc(cu, inst); break; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3338 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3339 | case llvm::Instruction::ZExt: CvtIntExt(cu, inst, false /* signed */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3340 | break; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3341 | case llvm::Instruction::SExt: CvtIntExt(cu, inst, true /* signed */); |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3342 | break; |
| 3343 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3344 | case llvm::Instruction::Switch: CvtSwitch(cu, inst); break; |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3345 | |
| 3346 | case llvm::Instruction::Unreachable: |
| 3347 | break; // FIXME: can we really ignore these? |
| 3348 | |
| 3349 | case llvm::Instruction::Shl: |
| 3350 | case llvm::Instruction::LShr: |
| 3351 | case llvm::Instruction::AShr: |
| 3352 | case llvm::Instruction::Invoke: |
| 3353 | case llvm::Instruction::FPToUI: |
TDYa127 | 4ec8ccd | 2012-08-11 07:04:57 -0700 | [diff] [blame] | 3354 | case llvm::Instruction::FPToSI: |
buzbee | 0967a25 | 2012-09-14 10:43:54 -0700 | [diff] [blame] | 3355 | case llvm::Instruction::UIToFP: |
| 3356 | case llvm::Instruction::PtrToInt: |
| 3357 | case llvm::Instruction::IntToPtr: |
| 3358 | case llvm::Instruction::FCmp: |
| 3359 | case llvm::Instruction::URem: |
| 3360 | case llvm::Instruction::UDiv: |
| 3361 | case llvm::Instruction::Resume: |
| 3362 | case llvm::Instruction::Alloca: |
| 3363 | case llvm::Instruction::GetElementPtr: |
| 3364 | case llvm::Instruction::Fence: |
| 3365 | case llvm::Instruction::AtomicCmpXchg: |
| 3366 | case llvm::Instruction::AtomicRMW: |
| 3367 | case llvm::Instruction::BitCast: |
| 3368 | case llvm::Instruction::VAArg: |
| 3369 | case llvm::Instruction::Select: |
| 3370 | case llvm::Instruction::UserOp1: |
| 3371 | case llvm::Instruction::UserOp2: |
| 3372 | case llvm::Instruction::ExtractElement: |
| 3373 | case llvm::Instruction::InsertElement: |
| 3374 | case llvm::Instruction::ShuffleVector: |
| 3375 | case llvm::Instruction::ExtractValue: |
| 3376 | case llvm::Instruction::InsertValue: |
| 3377 | case llvm::Instruction::LandingPad: |
| 3378 | case llvm::Instruction::IndirectBr: |
| 3379 | case llvm::Instruction::Load: |
| 3380 | case llvm::Instruction::Store: |
| 3381 | LOG(FATAL) << "Unexpected llvm opcode: " << opcode; break; |
| 3382 | |
| 3383 | default: |
| 3384 | LOG(FATAL) << "Unknown llvm opcode: " << inst->getOpcodeName(); |
| 3385 | break; |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3386 | } |
| 3387 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3388 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3389 | if (head_lir != NULL) { |
| 3390 | ApplyLocalOptimizations(cu, head_lir, cu->last_lir_insn); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3391 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3392 | if (next_bb != NULL) { |
| 3393 | bb = next_bb; |
| 3394 | next_bb = NULL; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 3395 | } |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 3396 | } |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3397 | return false; |
| 3398 | } |
| 3399 | |
| 3400 | /* |
| 3401 | * Convert LLVM_IR to MIR: |
| 3402 | * o Iterate through the LLVM_IR and construct a graph using |
| 3403 | * standard MIR building blocks. |
| 3404 | * o Perform a basic-block optimization pass to remove unnecessary |
| 3405 | * store/load sequences. |
| 3406 | * o Convert the LLVM Value operands into RegLocations where applicable. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3407 | * o Create ssa_rep def/use operand arrays for each converted LLVM opcode |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3408 | * o Perform register promotion |
| 3409 | * o Iterate through the graph a basic block at a time, generating |
| 3410 | * LIR. |
| 3411 | * o Assemble LIR as usual. |
| 3412 | * o Profit. |
| 3413 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3414 | void MethodBitcode2LIR(CompilationUnit* cu) |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3415 | { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 3416 | Codegen* cg = cu->cg.get(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3417 | llvm::Function* func = cu->func; |
| 3418 | int num_basic_blocks = func->getBasicBlockList().size(); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3419 | // Allocate a list for LIR basic block labels |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3420 | cu->block_label_list = |
| 3421 | static_cast<LIR*>(NewMem(cu, sizeof(LIR) * num_basic_blocks, true, kAllocLIR)); |
| 3422 | LIR* label_list = cu->block_label_list; |
| 3423 | int next_label = 0; |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 3424 | for (llvm::Function::iterator i = func->begin(), e = func->end(); i != e; ++i) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3425 | cu->block_to_label_map.Put(static_cast<llvm::BasicBlock*>(i), |
| 3426 | &label_list[next_label++]); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3427 | } |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3428 | |
| 3429 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3430 | * Keep honest - clear reg_locations, Value => RegLocation, |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3431 | * promotion map and VmapTables. |
| 3432 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3433 | cu->loc_map.clear(); // Start fresh |
| 3434 | cu->reg_location = NULL; |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 3435 | for (int i = 0; i < cu->num_dalvik_registers + cu->num_compiler_temps + 1; i++) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3436 | cu->promotion_map[i].core_location = kLocDalvikFrame; |
| 3437 | cu->promotion_map[i].fp_location = kLocDalvikFrame; |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3438 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3439 | cu->core_spill_mask = 0; |
| 3440 | cu->num_core_spills = 0; |
| 3441 | cu->fp_spill_mask = 0; |
| 3442 | cu->num_fp_spills = 0; |
| 3443 | cu->core_vmap_table.clear(); |
| 3444 | cu->fp_vmap_table.clear(); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3445 | |
| 3446 | /* |
| 3447 | * At this point, we've lost all knowledge of register promotion. |
| 3448 | * Rebuild that info from the MethodInfo intrinsic (if it |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3449 | * exists - not required for correctness). Normally, this will |
| 3450 | * be the first instruction we encounter, so we won't have to iterate |
| 3451 | * through everything. |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3452 | */ |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 3453 | for (llvm::inst_iterator i = llvm::inst_begin(func), e = llvm::inst_end(func); i != e; ++i) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3454 | llvm::CallInst* call_inst = llvm::dyn_cast<llvm::CallInst>(&*i); |
| 3455 | if (call_inst != NULL) { |
| 3456 | llvm::Function* callee = call_inst->getCalledFunction(); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3457 | greenland::IntrinsicHelper::IntrinsicId id = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3458 | cu->intrinsic_helper->GetIntrinsicId(callee); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3459 | if (id == greenland::IntrinsicHelper::MethodInfo) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3460 | if (cu->verbose) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3461 | LOG(INFO) << "Found MethodInfo"; |
| 3462 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3463 | llvm::MDNode* reg_info_node = call_inst->getMetadata("RegInfo"); |
| 3464 | if (reg_info_node != NULL) { |
| 3465 | llvm::ConstantInt* num_ins_value = |
| 3466 | static_cast<llvm::ConstantInt*>(reg_info_node->getOperand(0)); |
| 3467 | llvm::ConstantInt* num_regs_value = |
| 3468 | static_cast<llvm::ConstantInt*>(reg_info_node->getOperand(1)); |
| 3469 | llvm::ConstantInt* num_outs_value = |
| 3470 | static_cast<llvm::ConstantInt*>(reg_info_node->getOperand(2)); |
| 3471 | llvm::ConstantInt* num_compiler_temps_value = |
| 3472 | static_cast<llvm::ConstantInt*>(reg_info_node->getOperand(3)); |
| 3473 | llvm::ConstantInt* num_ssa_regs_value = |
| 3474 | static_cast<llvm::ConstantInt*>(reg_info_node->getOperand(4)); |
| 3475 | if (cu->verbose) { |
| 3476 | LOG(INFO) << "RegInfo - Ins:" << num_ins_value->getZExtValue() |
| 3477 | << ", Regs:" << num_regs_value->getZExtValue() |
| 3478 | << ", Outs:" << num_outs_value->getZExtValue() |
| 3479 | << ", CTemps:" << num_compiler_temps_value->getZExtValue() |
| 3480 | << ", SSARegs:" << num_ssa_regs_value->getZExtValue(); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3481 | } |
| 3482 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3483 | llvm::MDNode* pmap_info_node = call_inst->getMetadata("PromotionMap"); |
| 3484 | if (pmap_info_node != NULL) { |
| 3485 | int elems = pmap_info_node->getNumOperands(); |
| 3486 | if (cu->verbose) { |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3487 | LOG(INFO) << "PMap size: " << elems; |
| 3488 | } |
| 3489 | for (int i = 0; i < elems; i++) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3490 | llvm::ConstantInt* raw_map_data = |
| 3491 | static_cast<llvm::ConstantInt*>(pmap_info_node->getOperand(i)); |
| 3492 | uint32_t map_data = raw_map_data->getZExtValue(); |
| 3493 | PromotionMap* p = &cu->promotion_map[i]; |
| 3494 | p->first_in_pair = (map_data >> 24) & 0xff; |
| 3495 | p->FpReg = (map_data >> 16) & 0xff; |
| 3496 | p->core_reg = (map_data >> 8) & 0xff; |
| 3497 | p->fp_location = static_cast<RegLocationType>((map_data >> 4) & 0xf); |
| 3498 | if (p->fp_location == kLocPhysReg) { |
| 3499 | RecordFpPromotion(cu, p->FpReg, i); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3500 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3501 | p->core_location = static_cast<RegLocationType>(map_data & 0xf); |
| 3502 | if (p->core_location == kLocPhysReg) { |
| 3503 | RecordCorePromotion(cu, p->core_reg, i); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3504 | } |
| 3505 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3506 | if (cu->verbose) { |
| 3507 | DumpPromotionMap(cu); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 3508 | } |
| 3509 | } |
| 3510 | break; |
| 3511 | } |
| 3512 | } |
| 3513 | } |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 3514 | cg->AdjustSpillMask(cu); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3515 | cu->frame_size = ComputeFrameSize(cu); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3516 | |
| 3517 | // Create RegLocations for arguments |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3518 | llvm::Function::arg_iterator it(cu->func->arg_begin()); |
| 3519 | llvm::Function::arg_iterator it_end(cu->func->arg_end()); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3520 | for (; it != it_end; ++it) { |
| 3521 | llvm::Value* val = it; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3522 | CreateLocFromValue(cu, val); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3523 | } |
| 3524 | // Create RegLocations for all non-argument defintions |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 3525 | for (llvm::inst_iterator i = llvm::inst_begin(func), e = llvm::inst_end(func); i != e; ++i) { |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3526 | llvm::Value* val = &*i; |
| 3527 | if (val->hasName() && (val->getName().str().c_str()[0] == 'v')) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3528 | CreateLocFromValue(cu, val); |
buzbee | ad8f15e | 2012-06-18 14:49:45 -0700 | [diff] [blame] | 3529 | } |
| 3530 | } |
| 3531 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3532 | // Walk the blocks, generating code. |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 3533 | for (llvm::Function::iterator i = cu->func->begin(), e = cu->func->end(); i != e; ++i) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3534 | BitcodeBlockCodeGen(cu, static_cast<llvm::BasicBlock*>(i)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 3537 | cg->HandleSuspendLaunchPads(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3538 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 3539 | cg->HandleThrowLaunchPads(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3540 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 3541 | cg->HandleIntrinsicLaunchPads(cu); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3542 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 3543 | cu->func->eraseFromParent(); |
| 3544 | cu->func = NULL; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | |
| 3548 | } // namespace art |