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