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