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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") + | 530 report_fatal_error(std::string("Invalid PNaCl intrinsic call: ") + |
531 LLVMObjectAsString(Inst)); | 531 LLVMObjectAsString(Inst)); |
532 } | 532 } |
533 NewInst = Ice::InstIntrinsicCall::create(Func, NumArgs, Dest, | 533 NewInst = Ice::InstIntrinsicCall::create(Func, NumArgs, Dest, |
534 CallTarget, Info->Info); | 534 CallTarget, Info->Info); |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 // Not an intrinsic call. | 538 // Not an intrinsic call. |
539 if (NewInst == NULL) { | 539 if (NewInst == NULL) { |
540 NewInst = Ice::InstCall::create(Func, NumArgs, Dest, CallTarget); | 540 NewInst = Ice::InstCall::create(Func, NumArgs, Dest, CallTarget, |
| 541 Inst->isTailCall()); |
541 } | 542 } |
542 for (unsigned i = 0; i < NumArgs; ++i) { | 543 for (unsigned i = 0; i < NumArgs; ++i) { |
543 NewInst->addArg(convertOperand(Inst, i)); | 544 NewInst->addArg(convertOperand(Inst, i)); |
544 } | 545 } |
545 if (Info) { | 546 if (Info) { |
546 validateIntrinsicCall(NewInst, Info); | 547 validateIntrinsicCall(NewInst, Info); |
547 } | 548 } |
548 return NewInst; | 549 return NewInst; |
549 } | 550 } |
550 | 551 |
(...skipping 16 matching lines...) Expand all Loading... |
567 for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end(); | 568 for (BasicBlock::const_iterator II = BB->begin(), II_e = BB->end(); |
568 II != II_e; ++II) { | 569 II != II_e; ++II) { |
569 Ice::Inst *Inst = convertInstruction(II); | 570 Ice::Inst *Inst = convertInstruction(II); |
570 Node->appendInst(Inst); | 571 Node->appendInst(Inst); |
571 } | 572 } |
572 return Node; | 573 return Node; |
573 } | 574 } |
574 | 575 |
575 void validateIntrinsicCall(const Ice::InstCall *Call, | 576 void validateIntrinsicCall(const Ice::InstCall *Call, |
576 const Ice::Intrinsics::FullIntrinsicInfo *I) { | 577 const Ice::Intrinsics::FullIntrinsicInfo *I) { |
577 assert(I->NumTypes >= 1); | 578 Ice::SizeT ArgIndex = 0; |
578 if (I->Signature[0] == Ice::IceType_void) { | 579 switch (I->validateCall(Call, ArgIndex)) { |
579 if (Call->getDest() != NULL) { | 580 default: |
580 report_fatal_error( | 581 report_fatal_error("Unknown validation error for intrinsic call"); |
581 "Return value for intrinsic func w/ void return type."); | 582 break; |
582 } | 583 case Ice::Intrinsics::IsValidCall: |
583 } else { | 584 break; |
584 if (I->Signature[0] != Call->getDest()->getType()) { | 585 case Ice::Intrinsics::BadReturnType: { |
585 report_fatal_error("Mismatched return types."); | 586 std::string Buffer; |
586 } | 587 raw_string_ostream StrBuf(Buffer); |
| 588 StrBuf << "Intrinsic call expects return type " << I->getReturnType() |
| 589 << ". Found: " << Call->getReturnType(); |
| 590 report_fatal_error(StrBuf.str()); |
| 591 break; |
587 } | 592 } |
588 if (Call->getNumArgs() + 1 != I->NumTypes) { | 593 case Ice::Intrinsics::WrongNumOfArgs: { |
589 std::cerr << "Call->getNumArgs() " << (int)Call->getNumArgs() | 594 std::string Buffer; |
590 << " I->NumTypes " << (int)I->NumTypes << "\n"; | 595 raw_string_ostream StrBuf(Buffer); |
591 report_fatal_error("Mismatched # of args."); | 596 StrBuf << "Intrinsic call expects " << I->getNumArgs() |
| 597 << ". Found: " << Call->getNumArgs(); |
| 598 report_fatal_error(StrBuf.str()); |
| 599 break; |
592 } | 600 } |
593 for (size_t i = 1; i < I->NumTypes; ++i) { | 601 case Ice::Intrinsics::WrongCallArgType: { |
594 if (Call->getArg(i - 1)->getType() != I->Signature[i]) { | 602 std::string Buffer; |
595 report_fatal_error("Mismatched argument type."); | 603 raw_string_ostream StrBuf(Buffer); |
596 } | 604 StrBuf << "Intrinsic call argument " << ArgIndex << " expects type " |
| 605 << I->getArgType(ArgIndex) |
| 606 << ". Found: " << Call->getArg(ArgIndex)->getType(); |
| 607 report_fatal_error(StrBuf.str()); |
| 608 break; |
| 609 } |
597 } | 610 } |
598 } | 611 } |
599 | 612 |
600 private: | 613 private: |
601 // Data | 614 // Data |
602 Ice::GlobalContext *Ctx; | 615 Ice::GlobalContext *Ctx; |
603 Ice::Cfg *Func; | 616 Ice::Cfg *Func; |
604 Ice::CfgNode *CurrentNode; | 617 Ice::CfgNode *CurrentNode; |
605 std::map<const Value *, Ice::Variable *> VarMap; | 618 std::map<const Value *, Ice::Variable *> VarMap; |
606 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; | 619 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
674 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec() | 687 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec() |
675 << " sec\n"; | 688 << " sec\n"; |
676 } | 689 } |
677 translateFcn(Fcn); | 690 translateFcn(Fcn); |
678 } | 691 } |
679 | 692 |
680 emitConstants(); | 693 emitConstants(); |
681 } | 694 } |
682 | 695 |
683 } // end of namespace Ice | 696 } // end of namespace Ice |
OLD | NEW |