| 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. |
| 11 // | 11 // |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 #include "IceConverter.h" | 14 #include "IceConverter.h" |
| 15 | 15 |
| 16 #include "IceCfg.h" | 16 #include "IceCfg.h" |
| 17 #include "IceCfgNode.h" | 17 #include "IceCfgNode.h" |
| 18 #include "IceClFlags.h" |
| 18 #include "IceDefs.h" | 19 #include "IceDefs.h" |
| 19 #include "IceGlobalContext.h" | 20 #include "IceGlobalContext.h" |
| 20 #include "IceInst.h" | 21 #include "IceInst.h" |
| 21 #include "IceOperand.h" | 22 #include "IceOperand.h" |
| 22 #include "IceTargetLowering.h" | |
| 23 #include "IceTypes.h" | 23 #include "IceTypes.h" |
| 24 | 24 |
| 25 #include "llvm/IR/Constant.h" | 25 #include "llvm/IR/Constant.h" |
| 26 #include "llvm/IR/Constants.h" | 26 #include "llvm/IR/Constants.h" |
| 27 #include "llvm/IR/DataLayout.h" | 27 #include "llvm/IR/DataLayout.h" |
| 28 #include "llvm/IR/Instruction.h" | 28 #include "llvm/IR/Instruction.h" |
| 29 #include "llvm/IR/Instructions.h" | 29 #include "llvm/IR/Instructions.h" |
| 30 #include "llvm/IR/LLVMContext.h" | 30 #include "llvm/IR/LLVMContext.h" |
| 31 #include "llvm/IR/Module.h" | 31 #include "llvm/IR/Module.h" |
| 32 | 32 |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 | 608 |
| 609 private: | 609 private: |
| 610 // Data | 610 // Data |
| 611 Ice::GlobalContext *Ctx; | 611 Ice::GlobalContext *Ctx; |
| 612 Ice::Cfg *Func; | 612 Ice::Cfg *Func; |
| 613 Ice::CfgNode *CurrentNode; | 613 Ice::CfgNode *CurrentNode; |
| 614 Ice::Type SubzeroPointerType; | 614 Ice::Type SubzeroPointerType; |
| 615 std::map<const Value *, Ice::Variable *> VarMap; | 615 std::map<const Value *, Ice::Variable *> VarMap; |
| 616 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; | 616 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; |
| 617 }; | 617 }; |
| 618 | |
| 619 } | 618 } |
| 620 | 619 |
| 621 int Ice::Converter::convertToIce(llvm::Module *Mod) { | 620 int Ice::Converter::convertToIce(llvm::Module *Mod) { |
| 622 int ExitStatus = 0; | |
| 623 | |
| 624 // Ideally, Func would be declared inside the loop and its object | |
| 625 // would be automatically deleted at the end of the loop iteration. | |
| 626 // However, emitting the constant pool requires a valid Cfg object, | |
| 627 // so we need to defer deleting the last non-empty Cfg object until | |
| 628 // outside the loop and after emitting the constant pool. TODO: | |
| 629 // Since all constants are globally pooled in the Ice::GlobalContext | |
| 630 // object, change all Ice::Constant related functions to use | |
| 631 // GlobalContext instead of Cfg, and then clean up this loop. | |
| 632 OwningPtr<Ice::Cfg> Func; | |
| 633 | |
| 634 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { | 621 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { |
| 635 if (I->empty()) | 622 if (I->empty()) |
| 636 continue; | 623 continue; |
| 637 LLVM2ICEConverter FunctionConverter(Ctx); | 624 LLVM2ICEConverter FunctionConverter(Ctx); |
| 638 | 625 |
| 639 Ice::Timer TConvert; | 626 Ice::Timer TConvert; |
| 640 Func.reset(FunctionConverter.convertFunction(I)); | 627 Ice::Cfg *Fcn = FunctionConverter.convertFunction(I); |
| 641 if (DisableInternal) | 628 if (Flags.SubzeroTimingEnabled) { |
| 642 Func->setInternal(false); | |
| 643 | |
| 644 if (SubzeroTimingEnabled) { | |
| 645 std::cerr << "[Subzero timing] Convert function " | 629 std::cerr << "[Subzero timing] Convert function " |
| 646 << Func->getFunctionName() << ": " << TConvert.getElapsedSec() | 630 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec() |
| 647 << " sec\n"; | 631 << " sec\n"; |
| 648 } | 632 } |
| 649 | 633 translateFcn(Fcn); |
| 650 if (DisableTranslation) { | |
| 651 Func->dump(); | |
| 652 } else { | |
| 653 Ice::Timer TTranslate; | |
| 654 Func->translate(); | |
| 655 if (SubzeroTimingEnabled) { | |
| 656 std::cerr << "[Subzero timing] Translate function " | |
| 657 << Func->getFunctionName() << ": " | |
| 658 << TTranslate.getElapsedSec() << " sec\n"; | |
| 659 } | |
| 660 if (Func->hasError()) { | |
| 661 errs() << "ICE translation error: " << Func->getError() << "\n"; | |
| 662 ExitStatus = 1; | |
| 663 } | |
| 664 | |
| 665 Ice::Timer TEmit; | |
| 666 Func->emit(); | |
| 667 if (SubzeroTimingEnabled) { | |
| 668 std::cerr << "[Subzero timing] Emit function " | |
| 669 << Func->getFunctionName() << ": " << TEmit.getElapsedSec() | |
| 670 << " sec\n"; | |
| 671 } | |
| 672 } | |
| 673 } | 634 } |
| 674 | 635 |
| 675 if (!DisableTranslation && Func) | 636 emitConstants(); |
| 676 Func->getTarget()->emitConstants(); | |
| 677 | |
| 678 return ExitStatus; | 637 return ExitStatus; |
| 679 } | 638 } |
| OLD | NEW |