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" | |
15 | |
16 #include "IceCfg.h" | 14 #include "IceCfg.h" |
17 #include "IceCfgNode.h" | 15 #include "IceCfgNode.h" |
18 #include "IceClFlags.h" | 16 #include "IceClFlags.h" |
| 17 #include "IceConverter.h" |
19 #include "IceDefs.h" | 18 #include "IceDefs.h" |
20 #include "IceGlobalContext.h" | 19 #include "IceGlobalContext.h" |
21 #include "IceInst.h" | 20 #include "IceInst.h" |
22 #include "IceOperand.h" | 21 #include "IceOperand.h" |
23 #include "IceTargetLowering.h" | 22 #include "IceTargetLowering.h" |
24 #include "IceTypes.h" | 23 #include "IceTypes.h" |
25 #include "IceTypeConverter.h" | 24 #include "IceTypeConverter.h" |
26 | 25 |
27 #include "llvm/IR/Constant.h" | 26 #include "llvm/IR/Constant.h" |
28 #include "llvm/IR/Constants.h" | 27 #include "llvm/IR/Constants.h" |
(...skipping 24 matching lines...) Expand all Loading... |
53 // https://developers.google.com/native-client/dev/reference/pnacl-bitcode-abi | 52 // https://developers.google.com/native-client/dev/reference/pnacl-bitcode-abi |
54 // If not, all kinds of assertions may fire. | 53 // If not, all kinds of assertions may fire. |
55 // | 54 // |
56 class LLVM2ICEConverter { | 55 class LLVM2ICEConverter { |
57 public: | 56 public: |
58 LLVM2ICEConverter(Ice::GlobalContext *Ctx, LLVMContext &LLVMContext) | 57 LLVM2ICEConverter(Ice::GlobalContext *Ctx, LLVMContext &LLVMContext) |
59 : Ctx(Ctx), Func(NULL), TypeConverter(LLVMContext) {} | 58 : Ctx(Ctx), Func(NULL), TypeConverter(LLVMContext) {} |
60 | 59 |
61 // Caller is expected to delete the returned Ice::Cfg object. | 60 // Caller is expected to delete the returned Ice::Cfg object. |
62 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); |
63 VarMap.clear(); | 65 VarMap.clear(); |
64 NodeMap.clear(); | 66 NodeMap.clear(); |
65 Func = new Ice::Cfg(Ctx); | 67 Func = new Ice::Cfg(Ctx); |
66 Func->setFunctionName(F->getName()); | 68 Func->setFunctionName(F->getName()); |
67 Func->setReturnType(convertToIceType(F->getReturnType())); | 69 Func->setReturnType(convertToIceType(F->getReturnType())); |
68 Func->setInternal(F->hasInternalLinkage()); | 70 Func->setInternal(F->hasInternalLinkage()); |
69 | 71 |
70 // The initial definition/use of each arg is the entry node. | 72 // The initial definition/use of each arg is the entry node. |
71 for (Function::const_arg_iterator ArgI = F->arg_begin(), | 73 for (Function::const_arg_iterator ArgI = F->arg_begin(), |
72 ArgE = F->arg_end(); | 74 ArgE = F->arg_end(); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 std::map<const Value *, Ice::Variable *> VarMap; | 616 std::map<const Value *, Ice::Variable *> VarMap; |
615 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; | 617 std::map<const BasicBlock *, Ice::CfgNode *> NodeMap; |
616 Ice::TypeConverter TypeConverter; | 618 Ice::TypeConverter TypeConverter; |
617 }; | 619 }; |
618 | 620 |
619 } // end of anonymous namespace | 621 } // end of anonymous namespace |
620 | 622 |
621 namespace Ice { | 623 namespace Ice { |
622 | 624 |
623 void Converter::convertToIce() { | 625 void Converter::convertToIce() { |
| 626 static TimerIdT IDconvertToIce = GlobalContext::getTimerID("convertToIce"); |
| 627 TimerMarker T(IDconvertToIce, Ctx); |
624 nameUnnamedGlobalAddresses(Mod); | 628 nameUnnamedGlobalAddresses(Mod); |
625 if (!Ctx->getFlags().DisableGlobals) | 629 if (!Ctx->getFlags().DisableGlobals) |
626 convertGlobals(Mod); | 630 convertGlobals(Mod); |
627 convertFunctions(); | 631 convertFunctions(); |
628 } | 632 } |
629 | 633 |
630 void Converter::convertFunctions() { | 634 void Converter::convertFunctions() { |
631 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { | 635 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { |
632 if (I->empty()) | 636 if (I->empty()) |
633 continue; | 637 continue; |
634 LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext()); | 638 LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext()); |
635 | 639 |
636 Timer TConvert; | 640 Timer TConvert; |
637 Cfg *Fcn = FunctionConverter.convertFunction(I); | 641 Cfg *Fcn = FunctionConverter.convertFunction(I); |
638 if (Ctx->getFlags().SubzeroTimingEnabled) { | |
639 std::cerr << "[Subzero timing] Convert function " | |
640 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec() | |
641 << " sec\n"; | |
642 } | |
643 translateFcn(Fcn); | 642 translateFcn(Fcn); |
644 } | 643 } |
645 | 644 |
646 emitConstants(); | 645 emitConstants(); |
647 } | 646 } |
648 | 647 |
649 } // end of namespace Ice | 648 } // end of namespace Ice |
OLD | NEW |