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