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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // https://developers.google.com/native-client/dev/reference/pnacl-bitcode-abi | 52 // https://developers.google.com/native-client/dev/reference/pnacl-bitcode-abi |
53 // If not, all kinds of assertions may fire. | 53 // If not, all kinds of assertions may fire. |
54 // | 54 // |
55 class LLVM2ICEConverter { | 55 class LLVM2ICEConverter { |
56 public: | 56 public: |
57 LLVM2ICEConverter(Ice::GlobalContext *Ctx, LLVMContext &LLVMContext) | 57 LLVM2ICEConverter(Ice::GlobalContext *Ctx, LLVMContext &LLVMContext) |
58 : Ctx(Ctx), Func(NULL), TypeConverter(LLVMContext) {} | 58 : Ctx(Ctx), Func(NULL), TypeConverter(LLVMContext) {} |
59 | 59 |
60 // Caller is expected to delete the returned Ice::Cfg object. | 60 // Caller is expected to delete the returned Ice::Cfg object. |
61 Ice::Cfg *convertFunction(const Function *F) { | 61 Ice::Cfg *convertFunction(const Function *F) { |
62 static Ice::TimerIdT IDllvmConvert = | |
63 Ice::GlobalContext::getTimerID("llvmConvert"); | |
64 Ice::TimerMarker T(IDllvmConvert, Ctx); | |
65 VarMap.clear(); | 62 VarMap.clear(); |
66 NodeMap.clear(); | 63 NodeMap.clear(); |
67 Func = new Ice::Cfg(Ctx); | 64 Func = new Ice::Cfg(Ctx); |
68 Func->setFunctionName(F->getName()); | 65 Func->setFunctionName(F->getName()); |
69 Func->setReturnType(convertToIceType(F->getReturnType())); | 66 Func->setReturnType(convertToIceType(F->getReturnType())); |
70 Func->setInternal(F->hasInternalLinkage()); | 67 Func->setInternal(F->hasInternalLinkage()); |
| 68 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func); |
71 | 69 |
72 // The initial definition/use of each arg is the entry node. | 70 // The initial definition/use of each arg is the entry node. |
73 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; | 71 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; |
74 ++ArgI) { | 72 ++ArgI) { |
75 Func->addArg(mapValueToIceVar(ArgI)); | 73 Func->addArg(mapValueToIceVar(ArgI)); |
76 } | 74 } |
77 | 75 |
78 // Make an initial pass through the block list just to resolve the | 76 // Make an initial pass through the block list just to resolve the |
79 // blocks in the original linearized order. Otherwise the ICE | 77 // blocks in the original linearized order. Otherwise the ICE |
80 // linearized order will be affected by branch targets in | 78 // linearized order will be affected by branch targets in |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 std::map<const Value *, Ice::Variable *> VarMap; | 608 std::map<const Value *, Ice::Variable *> VarMap; |
611 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; | 609 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; |
612 Ice::TypeConverter TypeConverter; | 610 Ice::TypeConverter TypeConverter; |
613 }; | 611 }; |
614 | 612 |
615 } // end of anonymous namespace | 613 } // end of anonymous namespace |
616 | 614 |
617 namespace Ice { | 615 namespace Ice { |
618 | 616 |
619 void Converter::convertToIce() { | 617 void Converter::convertToIce() { |
620 static TimerIdT IDconvertToIce = GlobalContext::getTimerID("convertToIce"); | 618 TimerMarker T(TimerStack::TT_convertToIce, Ctx); |
621 TimerMarker T(IDconvertToIce, Ctx); | |
622 nameUnnamedGlobalAddresses(Mod); | 619 nameUnnamedGlobalAddresses(Mod); |
623 if (!Ctx->getFlags().DisableGlobals) | 620 if (!Ctx->getFlags().DisableGlobals) |
624 convertGlobals(Mod); | 621 convertGlobals(Mod); |
625 convertFunctions(); | 622 convertFunctions(); |
626 } | 623 } |
627 | 624 |
628 void Converter::convertFunctions() { | 625 void Converter::convertFunctions() { |
| 626 TimerStackIdT StackID = GlobalContext::TSK_Funcs; |
629 for (const Function &I : *Mod) { | 627 for (const Function &I : *Mod) { |
630 if (I.empty()) | 628 if (I.empty()) |
631 continue; | 629 continue; |
| 630 TimerIdT TimerID = 0; |
| 631 if (Ctx->getFlags().TimeEachFunction) { |
| 632 TimerID = Ctx->getTimerID(StackID, I.getName()); |
| 633 Ctx->pushTimer(TimerID, StackID); |
| 634 } |
632 LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext()); | 635 LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext()); |
633 | 636 |
634 Cfg *Fcn = FunctionConverter.convertFunction(&I); | 637 Cfg *Fcn = FunctionConverter.convertFunction(&I); |
635 translateFcn(Fcn); | 638 translateFcn(Fcn); |
| 639 if (Ctx->getFlags().TimeEachFunction) |
| 640 Ctx->popTimer(TimerID, StackID); |
636 } | 641 } |
637 | 642 |
638 emitConstants(); | 643 emitConstants(); |
639 } | 644 } |
640 | 645 |
641 } // end of namespace Ice | 646 } // end of namespace Ice |
OLD | NEW |