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