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 /// \file | 10 /// \file |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 LLVM2ICEFunctionConverter(const LLVM2ICEFunctionConverter &) = delete; | 89 LLVM2ICEFunctionConverter(const LLVM2ICEFunctionConverter &) = delete; |
90 LLVM2ICEFunctionConverter & | 90 LLVM2ICEFunctionConverter & |
91 operator=(const LLVM2ICEFunctionConverter &) = delete; | 91 operator=(const LLVM2ICEFunctionConverter &) = delete; |
92 | 92 |
93 public: | 93 public: |
94 explicit LLVM2ICEFunctionConverter(Ice::Converter &Converter) | 94 explicit LLVM2ICEFunctionConverter(Ice::Converter &Converter) |
95 : LLVM2ICEConverter(Converter), Func(nullptr) {} | 95 : LLVM2ICEConverter(Converter), Func(nullptr) {} |
96 | 96 |
97 void convertFunction(const Function *F) { | 97 void convertFunction(const Function *F) { |
98 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber()); | 98 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber()); |
99 Ice::Cfg::setCurrentCfg(Func.get()); | 99 { |
| 100 Ice::CfgLocalAllocatorScope _(Func.get()); |
100 | 101 |
101 VarMap.clear(); | 102 VarMap.clear(); |
102 NodeMap.clear(); | 103 NodeMap.clear(); |
103 Func->setFunctionName(F->getName()); | 104 Func->setFunctionName(F->getName()); |
104 Func->setReturnType(convertToIceType(F->getReturnType())); | 105 Func->setReturnType(convertToIceType(F->getReturnType())); |
105 Func->setInternal(F->hasInternalLinkage()); | 106 Func->setInternal(F->hasInternalLinkage()); |
106 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func.get()); | 107 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func.get()); |
107 | 108 |
108 // The initial definition/use of each arg is the entry node. | 109 // The initial definition/use of each arg is the entry node. |
109 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; | 110 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; |
110 ++ArgI) { | 111 ++ArgI) { |
111 Func->addArg(mapValueToIceVar(ArgI)); | 112 Func->addArg(mapValueToIceVar(ArgI)); |
| 113 } |
| 114 |
| 115 // Make an initial pass through the block list just to resolve the blocks |
| 116 // in the original linearized order. Otherwise the ICE linearized order |
| 117 // will be affected by branch targets in terminator instructions. |
| 118 for (const BasicBlock &BBI : *F) |
| 119 mapBasicBlockToNode(&BBI); |
| 120 for (const BasicBlock &BBI : *F) |
| 121 convertBasicBlock(&BBI); |
| 122 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock())); |
| 123 Func->computeInOutEdges(); |
112 } | 124 } |
113 | |
114 // Make an initial pass through the block list just to resolve the blocks | |
115 // in the original linearized order. Otherwise the ICE linearized order | |
116 // will be affected by branch targets in terminator instructions. | |
117 for (const BasicBlock &BBI : *F) | |
118 mapBasicBlockToNode(&BBI); | |
119 for (const BasicBlock &BBI : *F) | |
120 convertBasicBlock(&BBI); | |
121 Func->setEntryNode(mapBasicBlockToNode(&F->getEntryBlock())); | |
122 Func->computeInOutEdges(); | |
123 | |
124 Ice::Cfg::setCurrentCfg(nullptr); | |
125 Converter.translateFcn(std::move(Func)); | 125 Converter.translateFcn(std::move(Func)); |
126 } | 126 } |
127 | 127 |
128 // convertConstant() does not use Func or require it to be a valid Ice::Cfg | 128 // convertConstant() does not use Func or require it to be a valid Ice::Cfg |
129 // pointer. As such, it's suitable for e.g. constructing global initializers. | 129 // pointer. As such, it's suitable for e.g. constructing global initializers. |
130 Ice::Constant *convertConstant(const Constant *Const) { | 130 Ice::Constant *convertConstant(const Constant *Const) { |
131 if (const auto GV = dyn_cast<GlobalValue>(Const)) { | 131 if (const auto GV = dyn_cast<GlobalValue>(Const)) { |
132 Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV); | 132 Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV); |
133 bool IsUndefined = false; | 133 bool IsUndefined = false; |
134 if (const auto *Func = llvm::dyn_cast<Ice::FunctionDeclaration>(Decl)) | 134 if (const auto *Func = llvm::dyn_cast<Ice::FunctionDeclaration>(Decl)) |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 Ctx->pushTimer(TimerID, StackID); | 924 Ctx->pushTimer(TimerID, StackID); |
925 } | 925 } |
926 LLVM2ICEFunctionConverter FunctionConverter(*this); | 926 LLVM2ICEFunctionConverter FunctionConverter(*this); |
927 FunctionConverter.convertFunction(&I); | 927 FunctionConverter.convertFunction(&I); |
928 if (TimeThisFunction) | 928 if (TimeThisFunction) |
929 Ctx->popTimer(TimerID, StackID); | 929 Ctx->popTimer(TimerID, StackID); |
930 } | 930 } |
931 } | 931 } |
932 | 932 |
933 } // end of namespace Ice | 933 } // end of namespace Ice |
OLD | NEW |