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