Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// | 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file implements the LLVM to ICE converter. | 10 // This file implements the LLVM to ICE converter. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 // valid PNaCl bitcode. Otherwise, the behavior is undefined. | 72 // valid PNaCl bitcode. Otherwise, the behavior is undefined. |
| 73 class LLVM2ICEFunctionConverter : LLVM2ICEConverter { | 73 class LLVM2ICEFunctionConverter : LLVM2ICEConverter { |
| 74 LLVM2ICEFunctionConverter(const LLVM2ICEFunctionConverter &) = delete; | 74 LLVM2ICEFunctionConverter(const LLVM2ICEFunctionConverter &) = delete; |
| 75 LLVM2ICEFunctionConverter & | 75 LLVM2ICEFunctionConverter & |
| 76 operator=(const LLVM2ICEFunctionConverter &) = delete; | 76 operator=(const LLVM2ICEFunctionConverter &) = delete; |
| 77 | 77 |
| 78 public: | 78 public: |
| 79 LLVM2ICEFunctionConverter(Ice::Converter &Converter) | 79 LLVM2ICEFunctionConverter(Ice::Converter &Converter) |
| 80 : LLVM2ICEConverter(Converter), Func(nullptr) {} | 80 : LLVM2ICEConverter(Converter), Func(nullptr) {} |
| 81 | 81 |
| 82 // Caller is expected to delete the returned Ice::Cfg object. | 82 void convertFunction(const Function *F) { |
| 83 Ice::Cfg *convertFunction(const Function *F) { | |
| 84 VarMap.clear(); | 83 VarMap.clear(); |
| 85 NodeMap.clear(); | 84 NodeMap.clear(); |
| 86 Func = Ice::Cfg::create(Ctx); | 85 Func = Ice::Cfg::create(Ctx); |
| 87 Func->setFunctionName(F->getName()); | 86 Func->setFunctionName(F->getName()); |
| 88 Func->setReturnType(convertToIceType(F->getReturnType())); | 87 Func->setReturnType(convertToIceType(F->getReturnType())); |
| 89 Func->setInternal(F->hasInternalLinkage()); | 88 Func->setInternal(F->hasInternalLinkage()); |
| 90 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func); | 89 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func.get()); |
| 91 | 90 |
| 92 // The initial definition/use of each arg is the entry node. | 91 // The initial definition/use of each arg is the entry node. |
| 93 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; | 92 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; |
| 94 ++ArgI) { | 93 ++ArgI) { |
| 95 Func->addArg(mapValueToIceVar(ArgI)); | 94 Func->addArg(mapValueToIceVar(ArgI)); |
| 96 } | 95 } |
| 97 | 96 |
| 98 // Make an initial pass through the block list just to resolve the | 97 // Make an initial pass through the block list just to resolve the |
| 99 // blocks in the original linearized order. Otherwise the ICE | 98 // blocks in the original linearized order. Otherwise the ICE |
| 100 // linearized order will be affected by branch targets in | 99 // linearized order will be affected by branch targets in |
| 101 // terminator instructions. | 100 // terminator instructions. |
| 102 for (const BasicBlock &BBI : *F) | 101 for (const BasicBlock &BBI : *F) |
| 103 mapBasicBlockToNode(&BBI); | 102 mapBasicBlockToNode(&BBI); |
| 104 for (const BasicBlock &BBI : *F) | 103 for (const BasicBlock &BBI : *F) |
| 105 convertBasicBlock(&BBI); | 104 convertBasicBlock(&BBI); |
| 106 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock())); | 105 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock())); |
| 107 Func->computePredecessors(); | 106 Func->computePredecessors(); |
| 107 } | |
| 108 | 108 |
| 109 return Func; | 109 std::unique_ptr<Ice::Cfg> release() { return std::move(Func); } |
|
JF
2015/02/02 20:59:19
That's nicer. Could you leave a TODO to fix?
Jim Stichnoth
2015/02/03 00:48:51
Done.
| |
| 110 } | |
| 111 | 110 |
| 112 // convertConstant() does not use Func or require it to be a valid | 111 // convertConstant() does not use Func or require it to be a valid |
| 113 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing | 112 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing |
| 114 // global initializers. | 113 // global initializers. |
| 115 Ice::Constant *convertConstant(const Constant *Const) { | 114 Ice::Constant *convertConstant(const Constant *Const) { |
| 116 if (const auto GV = dyn_cast<GlobalValue>(Const)) { | 115 if (const auto GV = dyn_cast<GlobalValue>(Const)) { |
| 117 Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV); | 116 Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV); |
| 118 const Ice::RelocOffsetT Offset = 0; | 117 const Ice::RelocOffsetT Offset = 0; |
| 119 return Ctx->getConstantSym(Offset, Decl->getName(), | 118 return Ctx->getConstantSym(Offset, Decl->getName(), |
| 120 Decl->getSuppressMangling()); | 119 Decl->getSuppressMangling()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 140 private: | 139 private: |
| 141 // LLVM values (instructions, etc.) are mapped directly to ICE variables. | 140 // LLVM values (instructions, etc.) are mapped directly to ICE variables. |
| 142 // mapValueToIceVar has a version that forces an ICE type on the variable, | 141 // mapValueToIceVar has a version that forces an ICE type on the variable, |
| 143 // and a version that just uses convertToIceType on V. | 142 // and a version that just uses convertToIceType on V. |
| 144 Ice::Variable *mapValueToIceVar(const Value *V, Ice::Type IceTy) { | 143 Ice::Variable *mapValueToIceVar(const Value *V, Ice::Type IceTy) { |
| 145 if (IceTy == Ice::IceType_void) | 144 if (IceTy == Ice::IceType_void) |
| 146 return nullptr; | 145 return nullptr; |
| 147 if (VarMap.find(V) == VarMap.end()) { | 146 if (VarMap.find(V) == VarMap.end()) { |
| 148 VarMap[V] = Func->makeVariable(IceTy); | 147 VarMap[V] = Func->makeVariable(IceTy); |
| 149 if (ALLOW_DUMP) | 148 if (ALLOW_DUMP) |
| 150 VarMap[V]->setName(Func, V->getName()); | 149 VarMap[V]->setName(Func.get(), V->getName()); |
| 151 } | 150 } |
| 152 return VarMap[V]; | 151 return VarMap[V]; |
| 153 } | 152 } |
| 154 | 153 |
| 155 Ice::Variable *mapValueToIceVar(const Value *V) { | 154 Ice::Variable *mapValueToIceVar(const Value *V) { |
| 156 return mapValueToIceVar(V, convertToIceType(V->getType())); | 155 return mapValueToIceVar(V, convertToIceType(V->getType())); |
| 157 } | 156 } |
| 158 | 157 |
| 159 Ice::CfgNode *mapBasicBlockToNode(const BasicBlock *BB) { | 158 Ice::CfgNode *mapBasicBlockToNode(const BasicBlock *BB) { |
| 160 if (NodeMap.find(BB) == NodeMap.end()) { | 159 if (NodeMap.find(BB) == NodeMap.end()) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 LLVMObjectAsString(Inst)); | 296 LLVMObjectAsString(Inst)); |
| 298 } | 297 } |
| 299 | 298 |
| 300 llvm_unreachable("convertInstruction"); | 299 llvm_unreachable("convertInstruction"); |
| 301 return nullptr; | 300 return nullptr; |
| 302 } | 301 } |
| 303 | 302 |
| 304 Ice::Inst *convertLoadInstruction(const LoadInst *Inst) { | 303 Ice::Inst *convertLoadInstruction(const LoadInst *Inst) { |
| 305 Ice::Operand *Src = convertOperand(Inst, 0); | 304 Ice::Operand *Src = convertOperand(Inst, 0); |
| 306 Ice::Variable *Dest = mapValueToIceVar(Inst); | 305 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 307 return Ice::InstLoad::create(Func, Dest, Src); | 306 return Ice::InstLoad::create(Func.get(), Dest, Src); |
| 308 } | 307 } |
| 309 | 308 |
| 310 Ice::Inst *convertStoreInstruction(const StoreInst *Inst) { | 309 Ice::Inst *convertStoreInstruction(const StoreInst *Inst) { |
| 311 Ice::Operand *Addr = convertOperand(Inst, 1); | 310 Ice::Operand *Addr = convertOperand(Inst, 1); |
| 312 Ice::Operand *Val = convertOperand(Inst, 0); | 311 Ice::Operand *Val = convertOperand(Inst, 0); |
| 313 return Ice::InstStore::create(Func, Val, Addr); | 312 return Ice::InstStore::create(Func.get(), Val, Addr); |
| 314 } | 313 } |
| 315 | 314 |
| 316 Ice::Inst *convertArithInstruction(const Instruction *Inst, | 315 Ice::Inst *convertArithInstruction(const Instruction *Inst, |
| 317 Ice::InstArithmetic::OpKind Opcode) { | 316 Ice::InstArithmetic::OpKind Opcode) { |
| 318 const auto BinOp = cast<BinaryOperator>(Inst); | 317 const auto BinOp = cast<BinaryOperator>(Inst); |
| 319 Ice::Operand *Src0 = convertOperand(Inst, 0); | 318 Ice::Operand *Src0 = convertOperand(Inst, 0); |
| 320 Ice::Operand *Src1 = convertOperand(Inst, 1); | 319 Ice::Operand *Src1 = convertOperand(Inst, 1); |
| 321 Ice::Variable *Dest = mapValueToIceVar(BinOp); | 320 Ice::Variable *Dest = mapValueToIceVar(BinOp); |
| 322 return Ice::InstArithmetic::create(Func, Opcode, Dest, Src0, Src1); | 321 return Ice::InstArithmetic::create(Func.get(), Opcode, Dest, Src0, Src1); |
| 323 } | 322 } |
| 324 | 323 |
| 325 Ice::Inst *convertPHINodeInstruction(const PHINode *Inst) { | 324 Ice::Inst *convertPHINodeInstruction(const PHINode *Inst) { |
| 326 unsigned NumValues = Inst->getNumIncomingValues(); | 325 unsigned NumValues = Inst->getNumIncomingValues(); |
| 327 Ice::InstPhi *IcePhi = | 326 Ice::InstPhi *IcePhi = |
| 328 Ice::InstPhi::create(Func, NumValues, mapValueToIceVar(Inst)); | 327 Ice::InstPhi::create(Func.get(), NumValues, mapValueToIceVar(Inst)); |
| 329 for (unsigned N = 0, E = NumValues; N != E; ++N) { | 328 for (unsigned N = 0, E = NumValues; N != E; ++N) { |
| 330 IcePhi->addArgument(convertOperand(Inst, N), | 329 IcePhi->addArgument(convertOperand(Inst, N), |
| 331 mapBasicBlockToNode(Inst->getIncomingBlock(N))); | 330 mapBasicBlockToNode(Inst->getIncomingBlock(N))); |
| 332 } | 331 } |
| 333 return IcePhi; | 332 return IcePhi; |
| 334 } | 333 } |
| 335 | 334 |
| 336 Ice::Inst *convertBrInstruction(const BranchInst *Inst) { | 335 Ice::Inst *convertBrInstruction(const BranchInst *Inst) { |
| 337 if (Inst->isConditional()) { | 336 if (Inst->isConditional()) { |
| 338 Ice::Operand *Src = convertOperand(Inst, 0); | 337 Ice::Operand *Src = convertOperand(Inst, 0); |
| 339 BasicBlock *BBThen = Inst->getSuccessor(0); | 338 BasicBlock *BBThen = Inst->getSuccessor(0); |
| 340 BasicBlock *BBElse = Inst->getSuccessor(1); | 339 BasicBlock *BBElse = Inst->getSuccessor(1); |
| 341 Ice::CfgNode *NodeThen = mapBasicBlockToNode(BBThen); | 340 Ice::CfgNode *NodeThen = mapBasicBlockToNode(BBThen); |
| 342 Ice::CfgNode *NodeElse = mapBasicBlockToNode(BBElse); | 341 Ice::CfgNode *NodeElse = mapBasicBlockToNode(BBElse); |
| 343 return Ice::InstBr::create(Func, Src, NodeThen, NodeElse); | 342 return Ice::InstBr::create(Func.get(), Src, NodeThen, NodeElse); |
| 344 } else { | 343 } else { |
| 345 BasicBlock *BBSucc = Inst->getSuccessor(0); | 344 BasicBlock *BBSucc = Inst->getSuccessor(0); |
| 346 return Ice::InstBr::create(Func, mapBasicBlockToNode(BBSucc)); | 345 return Ice::InstBr::create(Func.get(), mapBasicBlockToNode(BBSucc)); |
| 347 } | 346 } |
| 348 } | 347 } |
| 349 | 348 |
| 350 Ice::Inst *convertIntToPtrInstruction(const IntToPtrInst *Inst) { | 349 Ice::Inst *convertIntToPtrInstruction(const IntToPtrInst *Inst) { |
| 351 Ice::Operand *Src = convertOperand(Inst, 0); | 350 Ice::Operand *Src = convertOperand(Inst, 0); |
| 352 Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType()); | 351 Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType()); |
| 353 return Ice::InstAssign::create(Func, Dest, Src); | 352 return Ice::InstAssign::create(Func.get(), Dest, Src); |
| 354 } | 353 } |
| 355 | 354 |
| 356 Ice::Inst *convertPtrToIntInstruction(const PtrToIntInst *Inst) { | 355 Ice::Inst *convertPtrToIntInstruction(const PtrToIntInst *Inst) { |
| 357 Ice::Operand *Src = convertOperand(Inst, 0); | 356 Ice::Operand *Src = convertOperand(Inst, 0); |
| 358 Ice::Variable *Dest = mapValueToIceVar(Inst); | 357 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 359 return Ice::InstAssign::create(Func, Dest, Src); | 358 return Ice::InstAssign::create(Func.get(), Dest, Src); |
| 360 } | 359 } |
| 361 | 360 |
| 362 Ice::Inst *convertRetInstruction(const ReturnInst *Inst) { | 361 Ice::Inst *convertRetInstruction(const ReturnInst *Inst) { |
| 363 Ice::Operand *RetOperand = convertOperand(Inst, 0); | 362 Ice::Operand *RetOperand = convertOperand(Inst, 0); |
| 364 if (RetOperand) { | 363 if (RetOperand) { |
| 365 return Ice::InstRet::create(Func, RetOperand); | 364 return Ice::InstRet::create(Func.get(), RetOperand); |
| 366 } else { | 365 } else { |
| 367 return Ice::InstRet::create(Func); | 366 return Ice::InstRet::create(Func.get()); |
| 368 } | 367 } |
| 369 } | 368 } |
| 370 | 369 |
| 371 Ice::Inst *convertCastInstruction(const Instruction *Inst, | 370 Ice::Inst *convertCastInstruction(const Instruction *Inst, |
| 372 Ice::InstCast::OpKind CastKind) { | 371 Ice::InstCast::OpKind CastKind) { |
| 373 Ice::Operand *Src = convertOperand(Inst, 0); | 372 Ice::Operand *Src = convertOperand(Inst, 0); |
| 374 Ice::Variable *Dest = mapValueToIceVar(Inst); | 373 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 375 return Ice::InstCast::create(Func, CastKind, Dest, Src); | 374 return Ice::InstCast::create(Func.get(), CastKind, Dest, Src); |
| 376 } | 375 } |
| 377 | 376 |
| 378 Ice::Inst *convertICmpInstruction(const ICmpInst *Inst) { | 377 Ice::Inst *convertICmpInstruction(const ICmpInst *Inst) { |
| 379 Ice::Operand *Src0 = convertOperand(Inst, 0); | 378 Ice::Operand *Src0 = convertOperand(Inst, 0); |
| 380 Ice::Operand *Src1 = convertOperand(Inst, 1); | 379 Ice::Operand *Src1 = convertOperand(Inst, 1); |
| 381 Ice::Variable *Dest = mapValueToIceVar(Inst); | 380 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 382 | 381 |
| 383 Ice::InstIcmp::ICond Cond; | 382 Ice::InstIcmp::ICond Cond; |
| 384 switch (Inst->getPredicate()) { | 383 switch (Inst->getPredicate()) { |
| 385 default: | 384 default: |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 409 Cond = Ice::InstIcmp::Sge; | 408 Cond = Ice::InstIcmp::Sge; |
| 410 break; | 409 break; |
| 411 case CmpInst::ICMP_SLT: | 410 case CmpInst::ICMP_SLT: |
| 412 Cond = Ice::InstIcmp::Slt; | 411 Cond = Ice::InstIcmp::Slt; |
| 413 break; | 412 break; |
| 414 case CmpInst::ICMP_SLE: | 413 case CmpInst::ICMP_SLE: |
| 415 Cond = Ice::InstIcmp::Sle; | 414 Cond = Ice::InstIcmp::Sle; |
| 416 break; | 415 break; |
| 417 } | 416 } |
| 418 | 417 |
| 419 return Ice::InstIcmp::create(Func, Cond, Dest, Src0, Src1); | 418 return Ice::InstIcmp::create(Func.get(), Cond, Dest, Src0, Src1); |
| 420 } | 419 } |
| 421 | 420 |
| 422 Ice::Inst *convertFCmpInstruction(const FCmpInst *Inst) { | 421 Ice::Inst *convertFCmpInstruction(const FCmpInst *Inst) { |
| 423 Ice::Operand *Src0 = convertOperand(Inst, 0); | 422 Ice::Operand *Src0 = convertOperand(Inst, 0); |
| 424 Ice::Operand *Src1 = convertOperand(Inst, 1); | 423 Ice::Operand *Src1 = convertOperand(Inst, 1); |
| 425 Ice::Variable *Dest = mapValueToIceVar(Inst); | 424 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 426 | 425 |
| 427 Ice::InstFcmp::FCond Cond; | 426 Ice::InstFcmp::FCond Cond; |
| 428 switch (Inst->getPredicate()) { | 427 switch (Inst->getPredicate()) { |
| 429 | 428 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 Cond = Ice::InstFcmp::Une; | 472 Cond = Ice::InstFcmp::Une; |
| 474 break; | 473 break; |
| 475 case CmpInst::FCMP_UNO: | 474 case CmpInst::FCMP_UNO: |
| 476 Cond = Ice::InstFcmp::Uno; | 475 Cond = Ice::InstFcmp::Uno; |
| 477 break; | 476 break; |
| 478 case CmpInst::FCMP_TRUE: | 477 case CmpInst::FCMP_TRUE: |
| 479 Cond = Ice::InstFcmp::True; | 478 Cond = Ice::InstFcmp::True; |
| 480 break; | 479 break; |
| 481 } | 480 } |
| 482 | 481 |
| 483 return Ice::InstFcmp::create(Func, Cond, Dest, Src0, Src1); | 482 return Ice::InstFcmp::create(Func.get(), Cond, Dest, Src0, Src1); |
| 484 } | 483 } |
| 485 | 484 |
| 486 Ice::Inst *convertExtractElementInstruction(const ExtractElementInst *Inst) { | 485 Ice::Inst *convertExtractElementInstruction(const ExtractElementInst *Inst) { |
| 487 Ice::Variable *Dest = mapValueToIceVar(Inst); | 486 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 488 Ice::Operand *Source1 = convertValue(Inst->getOperand(0)); | 487 Ice::Operand *Source1 = convertValue(Inst->getOperand(0)); |
| 489 Ice::Operand *Source2 = convertValue(Inst->getOperand(1)); | 488 Ice::Operand *Source2 = convertValue(Inst->getOperand(1)); |
| 490 return Ice::InstExtractElement::create(Func, Dest, Source1, Source2); | 489 return Ice::InstExtractElement::create(Func.get(), Dest, Source1, Source2); |
| 491 } | 490 } |
| 492 | 491 |
| 493 Ice::Inst *convertInsertElementInstruction(const InsertElementInst *Inst) { | 492 Ice::Inst *convertInsertElementInstruction(const InsertElementInst *Inst) { |
| 494 Ice::Variable *Dest = mapValueToIceVar(Inst); | 493 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 495 Ice::Operand *Source1 = convertValue(Inst->getOperand(0)); | 494 Ice::Operand *Source1 = convertValue(Inst->getOperand(0)); |
| 496 Ice::Operand *Source2 = convertValue(Inst->getOperand(1)); | 495 Ice::Operand *Source2 = convertValue(Inst->getOperand(1)); |
| 497 Ice::Operand *Source3 = convertValue(Inst->getOperand(2)); | 496 Ice::Operand *Source3 = convertValue(Inst->getOperand(2)); |
| 498 return Ice::InstInsertElement::create(Func, Dest, Source1, Source2, | 497 return Ice::InstInsertElement::create(Func.get(), Dest, Source1, Source2, |
| 499 Source3); | 498 Source3); |
| 500 } | 499 } |
| 501 | 500 |
| 502 Ice::Inst *convertSelectInstruction(const SelectInst *Inst) { | 501 Ice::Inst *convertSelectInstruction(const SelectInst *Inst) { |
| 503 Ice::Variable *Dest = mapValueToIceVar(Inst); | 502 Ice::Variable *Dest = mapValueToIceVar(Inst); |
| 504 Ice::Operand *Cond = convertValue(Inst->getCondition()); | 503 Ice::Operand *Cond = convertValue(Inst->getCondition()); |
| 505 Ice::Operand *Source1 = convertValue(Inst->getTrueValue()); | 504 Ice::Operand *Source1 = convertValue(Inst->getTrueValue()); |
| 506 Ice::Operand *Source2 = convertValue(Inst->getFalseValue()); | 505 Ice::Operand *Source2 = convertValue(Inst->getFalseValue()); |
| 507 return Ice::InstSelect::create(Func, Dest, Cond, Source1, Source2); | 506 return Ice::InstSelect::create(Func.get(), Dest, Cond, Source1, Source2); |
| 508 } | 507 } |
| 509 | 508 |
| 510 Ice::Inst *convertSwitchInstruction(const SwitchInst *Inst) { | 509 Ice::Inst *convertSwitchInstruction(const SwitchInst *Inst) { |
| 511 Ice::Operand *Source = convertValue(Inst->getCondition()); | 510 Ice::Operand *Source = convertValue(Inst->getCondition()); |
| 512 Ice::CfgNode *LabelDefault = mapBasicBlockToNode(Inst->getDefaultDest()); | 511 Ice::CfgNode *LabelDefault = mapBasicBlockToNode(Inst->getDefaultDest()); |
| 513 unsigned NumCases = Inst->getNumCases(); | 512 unsigned NumCases = Inst->getNumCases(); |
| 514 Ice::InstSwitch *Switch = | 513 Ice::InstSwitch *Switch = |
| 515 Ice::InstSwitch::create(Func, NumCases, Source, LabelDefault); | 514 Ice::InstSwitch::create(Func.get(), NumCases, Source, LabelDefault); |
| 516 unsigned CurrentCase = 0; | 515 unsigned CurrentCase = 0; |
| 517 for (SwitchInst::ConstCaseIt I = Inst->case_begin(), E = Inst->case_end(); | 516 for (SwitchInst::ConstCaseIt I = Inst->case_begin(), E = Inst->case_end(); |
| 518 I != E; ++I, ++CurrentCase) { | 517 I != E; ++I, ++CurrentCase) { |
| 519 uint64_t CaseValue = I.getCaseValue()->getSExtValue(); | 518 uint64_t CaseValue = I.getCaseValue()->getSExtValue(); |
| 520 Ice::CfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor()); | 519 Ice::CfgNode *CaseSuccessor = mapBasicBlockToNode(I.getCaseSuccessor()); |
| 521 Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor); | 520 Switch->addBranch(CurrentCase, CaseValue, CaseSuccessor); |
| 522 } | 521 } |
| 523 return Switch; | 522 return Switch; |
| 524 } | 523 } |
| 525 | 524 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 537 static const char LLVMPrefix[] = "llvm."; | 536 static const char LLVMPrefix[] = "llvm."; |
| 538 const size_t LLVMPrefixLen = strlen(LLVMPrefix); | 537 const size_t LLVMPrefixLen = strlen(LLVMPrefix); |
| 539 Ice::IceString Name = Target->getName(); | 538 Ice::IceString Name = Target->getName(); |
| 540 if (Name.substr(0, LLVMPrefixLen) == LLVMPrefix) { | 539 if (Name.substr(0, LLVMPrefixLen) == LLVMPrefix) { |
| 541 Ice::IceString NameSuffix = Name.substr(LLVMPrefixLen); | 540 Ice::IceString NameSuffix = Name.substr(LLVMPrefixLen); |
| 542 Info = Ctx->getIntrinsicsInfo().find(NameSuffix); | 541 Info = Ctx->getIntrinsicsInfo().find(NameSuffix); |
| 543 if (!Info) { | 542 if (!Info) { |
| 544 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") + | 543 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") + |
| 545 LLVMObjectAsString(Inst)); | 544 LLVMObjectAsString(Inst)); |
| 546 } | 545 } |
| 547 NewInst = Ice::InstIntrinsicCall::create(Func, NumArgs, Dest, | 546 NewInst = Ice::InstIntrinsicCall::create(Func.get(), NumArgs, Dest, |
| 548 CallTarget, Info->Info); | 547 CallTarget, Info->Info); |
| 549 } | 548 } |
| 550 } | 549 } |
| 551 | 550 |
| 552 // Not an intrinsic call. | 551 // Not an intrinsic call. |
| 553 if (NewInst == nullptr) { | 552 if (NewInst == nullptr) { |
| 554 NewInst = Ice::InstCall::create(Func, NumArgs, Dest, CallTarget, | 553 NewInst = Ice::InstCall::create(Func.get(), NumArgs, Dest, CallTarget, |
| 555 Inst->isTailCall()); | 554 Inst->isTailCall()); |
| 556 } | 555 } |
| 557 for (unsigned i = 0; i < NumArgs; ++i) { | 556 for (unsigned i = 0; i < NumArgs; ++i) { |
| 558 NewInst->addArg(convertOperand(Inst, i)); | 557 NewInst->addArg(convertOperand(Inst, i)); |
| 559 } | 558 } |
| 560 if (Info) { | 559 if (Info) { |
| 561 validateIntrinsicCall(NewInst, Info); | 560 validateIntrinsicCall(NewInst, Info); |
| 562 } | 561 } |
| 563 return NewInst; | 562 return NewInst; |
| 564 } | 563 } |
| 565 | 564 |
| 566 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) { | 565 Ice::Inst *convertAllocaInstruction(const AllocaInst *Inst) { |
| 567 // PNaCl bitcode only contains allocas of byte-granular objects. | 566 // PNaCl bitcode only contains allocas of byte-granular objects. |
| 568 Ice::Operand *ByteCount = convertValue(Inst->getArraySize()); | 567 Ice::Operand *ByteCount = convertValue(Inst->getArraySize()); |
| 569 uint32_t Align = Inst->getAlignment(); | 568 uint32_t Align = Inst->getAlignment(); |
| 570 Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType()); | 569 Ice::Variable *Dest = mapValueToIceVar(Inst, Ice::getPointerType()); |
| 571 | 570 |
| 572 return Ice::InstAlloca::create(Func, ByteCount, Align, Dest); | 571 return Ice::InstAlloca::create(Func.get(), ByteCount, Align, Dest); |
| 573 } | 572 } |
| 574 | 573 |
| 575 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Inst*/) { | 574 Ice::Inst *convertUnreachableInstruction(const UnreachableInst * /*Inst*/) { |
| 576 return Ice::InstUnreachable::create(Func); | 575 return Ice::InstUnreachable::create(Func.get()); |
| 577 } | 576 } |
| 578 | 577 |
| 579 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) { | 578 Ice::CfgNode *convertBasicBlock(const BasicBlock *BB) { |
| 580 Ice::CfgNode *Node = mapBasicBlockToNode(BB); | 579 Ice::CfgNode *Node = mapBasicBlockToNode(BB); |
| 581 for (const Instruction &II : *BB) { | 580 for (const Instruction &II : *BB) { |
| 582 Ice::Inst *Inst = convertInstruction(&II); | 581 Ice::Inst *Inst = convertInstruction(&II); |
| 583 Node->appendInst(Inst); | 582 Node->appendInst(Inst); |
| 584 } | 583 } |
| 585 return Node; | 584 return Node; |
| 586 } | 585 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 614 << I->getArgType(ArgIndex) | 613 << I->getArgType(ArgIndex) |
| 615 << ". Found: " << Call->getArg(ArgIndex)->getType(); | 614 << ". Found: " << Call->getArg(ArgIndex)->getType(); |
| 616 report_fatal_error(StrBuf.str()); | 615 report_fatal_error(StrBuf.str()); |
| 617 break; | 616 break; |
| 618 } | 617 } |
| 619 } | 618 } |
| 620 } | 619 } |
| 621 | 620 |
| 622 private: | 621 private: |
| 623 // Data | 622 // Data |
| 624 Ice::Cfg *Func; | 623 std::unique_ptr<Ice::Cfg> Func; |
| 625 std::map<const Value *, Ice::Variable *> VarMap; | 624 std::map<const Value *, Ice::Variable *> VarMap; |
| 626 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; | 625 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; |
| 627 }; | 626 }; |
| 628 | 627 |
| 629 // Converter from LLVM global variables to ICE. The entry point is the | 628 // Converter from LLVM global variables to ICE. The entry point is the |
| 630 // convertGlobalsToIce method. | 629 // convertGlobalsToIce method. |
| 631 // | 630 // |
| 632 // Note: this currently assumes that the given IR was verified to be | 631 // Note: this currently assumes that the given IR was verified to be |
| 633 // valid PNaCl bitcode. Othewise, the behavior is undefined. | 632 // valid PNaCl bitcode. Othewise, the behavior is undefined. |
| 634 class LLVM2ICEGlobalsConverter : public LLVM2ICEConverter { | 633 class LLVM2ICEGlobalsConverter : public LLVM2ICEConverter { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 lowerGlobals(VariableDeclarations); | 870 lowerGlobals(VariableDeclarations); |
| 872 } | 871 } |
| 873 | 872 |
| 874 void Converter::convertFunctions() { | 873 void Converter::convertFunctions() { |
| 875 TimerStackIdT StackID = GlobalContext::TSK_Funcs; | 874 TimerStackIdT StackID = GlobalContext::TSK_Funcs; |
| 876 for (const Function &I : *Mod) { | 875 for (const Function &I : *Mod) { |
| 877 if (I.empty()) | 876 if (I.empty()) |
| 878 continue; | 877 continue; |
| 879 | 878 |
| 880 TimerIdT TimerID = 0; | 879 TimerIdT TimerID = 0; |
| 881 if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction) { | 880 const bool TimeThisFunction = |
| 881 ALLOW_DUMP && Ctx->getFlags().TimeEachFunction; | |
| 882 if (TimeThisFunction) { | |
| 882 TimerID = Ctx->getTimerID(StackID, I.getName()); | 883 TimerID = Ctx->getTimerID(StackID, I.getName()); |
| 883 Ctx->pushTimer(TimerID, StackID); | 884 Ctx->pushTimer(TimerID, StackID); |
| 884 } | 885 } |
| 885 LLVM2ICEFunctionConverter FunctionConverter(*this); | 886 LLVM2ICEFunctionConverter FunctionConverter(*this); |
| 886 | 887 FunctionConverter.convertFunction(&I); |
| 887 Cfg *Fcn = FunctionConverter.convertFunction(&I); | 888 translateFcn(FunctionConverter.release()); |
| 888 translateFcn(Fcn); | 889 if (TimeThisFunction) |
| 889 if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction) | |
| 890 Ctx->popTimer(TimerID, StackID); | 890 Ctx->popTimer(TimerID, StackID); |
| 891 } | 891 } |
| 892 } | 892 } |
| 893 | 893 |
| 894 } // end of namespace Ice | 894 } // end of namespace Ice |
| OLD | NEW |