Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// | 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// |
| 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 for (SizeT I = 0; I < NumNodes; ++I) | 327 for (SizeT I = 0; I < NumNodes; ++I) |
| 328 Nodes[I]->advancedPhiLowering(); | 328 Nodes[I]->advancedPhiLowering(); |
| 329 | 329 |
| 330 TimerMarker TT(TimerStack::TT_lowerPhiAssignments, this); | 330 TimerMarker TT(TimerStack::TT_lowerPhiAssignments, this); |
| 331 if (true) { | 331 if (true) { |
| 332 // The following code does an in-place update of liveness and live ranges | 332 // The following code does an in-place update of liveness and live ranges |
| 333 // as a result of adding the new phi edge split nodes. | 333 // as a result of adding the new phi edge split nodes. |
| 334 getLiveness()->initPhiEdgeSplits(Nodes.begin() + NumNodes, | 334 getLiveness()->initPhiEdgeSplits(Nodes.begin() + NumNodes, |
| 335 Variables.begin() + NumVars); | 335 Variables.begin() + NumVars); |
| 336 TimerMarker TTT(TimerStack::TT_liveness, this); | 336 TimerMarker TTT(TimerStack::TT_liveness, this); |
| 337 LivenessBV ScratchBV; | |
| 337 // Iterate over the newly added nodes to add their liveness info. | 338 // Iterate over the newly added nodes to add their liveness info. |
| 338 for (auto I = Nodes.begin() + NumNodes, E = Nodes.end(); I != E; ++I) { | 339 for (auto I = Nodes.begin() + NumNodes, E = Nodes.end(); I != E; ++I) { |
| 339 InstNumberT FirstInstNum = getNextInstNumber(); | 340 InstNumberT FirstInstNum = getNextInstNumber(); |
| 340 (*I)->renumberInstructions(); | 341 (*I)->renumberInstructions(); |
| 341 InstNumberT LastInstNum = getNextInstNumber() - 1; | 342 InstNumberT LastInstNum = getNextInstNumber() - 1; |
| 342 (*I)->liveness(getLiveness()); | 343 (*I)->liveness(getLiveness(), &ScratchBV); |
|
John
2016/02/29 15:12:31
make scratchbv a member of Liveness?
Jim Stichnoth
2016/02/29 22:58:26
Done.
| |
| 343 (*I)->livenessAddIntervals(getLiveness(), FirstInstNum, LastInstNum); | 344 (*I)->livenessAddIntervals(getLiveness(), FirstInstNum, LastInstNum); |
| 344 } | 345 } |
| 345 } else { | 346 } else { |
| 346 // The following code does a brute-force recalculation of live ranges as a | 347 // The following code does a brute-force recalculation of live ranges as a |
| 347 // result of adding the new phi edge split nodes. The liveness calculation | 348 // result of adding the new phi edge split nodes. The liveness calculation |
| 348 // is particularly expensive because the new nodes are not yet in a proper | 349 // is particularly expensive because the new nodes are not yet in a proper |
| 349 // topological order and so convergence is slower. | 350 // topological order and so convergence is slower. |
| 350 // | 351 // |
| 351 // This code is kept here for reference and can be temporarily enabled in | 352 // This code is kept here for reference and can be temporarily enabled in |
| 352 // case the incremental code is under suspicion. | 353 // case the incremental code is under suspicion. |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 813 Node->livenessLightweight(); | 814 Node->livenessLightweight(); |
| 814 } | 815 } |
| 815 | 816 |
| 816 void Cfg::liveness(LivenessMode Mode) { | 817 void Cfg::liveness(LivenessMode Mode) { |
| 817 TimerMarker T(TimerStack::TT_liveness, this); | 818 TimerMarker T(TimerStack::TT_liveness, this); |
| 818 Live.reset(new Liveness(this, Mode)); | 819 Live.reset(new Liveness(this, Mode)); |
| 819 getVMetadata()->init(VMK_Uses); | 820 getVMetadata()->init(VMK_Uses); |
| 820 Live->init(); | 821 Live->init(); |
| 821 // Initialize with all nodes needing to be processed. | 822 // Initialize with all nodes needing to be processed. |
| 822 BitVector NeedToProcess(Nodes.size(), true); | 823 BitVector NeedToProcess(Nodes.size(), true); |
| 824 LivenessBV ScratchBV; | |
| 823 while (NeedToProcess.any()) { | 825 while (NeedToProcess.any()) { |
| 824 // Iterate in reverse topological order to speed up convergence. | 826 // Iterate in reverse topological order to speed up convergence. |
| 825 for (CfgNode *Node : reverse_range(Nodes)) { | 827 for (CfgNode *Node : reverse_range(Nodes)) { |
| 826 if (NeedToProcess[Node->getIndex()]) { | 828 if (NeedToProcess[Node->getIndex()]) { |
| 827 NeedToProcess[Node->getIndex()] = false; | 829 NeedToProcess[Node->getIndex()] = false; |
| 828 bool Changed = Node->liveness(getLiveness()); | 830 bool Changed = Node->liveness(getLiveness(), &ScratchBV); |
| 829 if (Changed) { | 831 if (Changed) { |
| 830 // If the beginning-of-block liveness changed since the last | 832 // If the beginning-of-block liveness changed since the last |
| 831 // iteration, mark all in-edges as needing to be processed. | 833 // iteration, mark all in-edges as needing to be processed. |
| 832 for (CfgNode *Pred : Node->getInEdges()) | 834 for (CfgNode *Pred : Node->getInEdges()) |
| 833 NeedToProcess[Pred->getIndex()] = true; | 835 NeedToProcess[Pred->getIndex()] = true; |
| 834 } | 836 } |
| 835 } | 837 } |
| 836 } | 838 } |
| 837 } | 839 } |
| 838 if (Mode == Liveness_Intervals) { | 840 if (Mode == Liveness_Intervals) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 deleteJumpTableInsts(); | 1071 deleteJumpTableInsts(); |
| 1070 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); | 1072 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
| 1071 for (CfgNode *Node : Nodes) { | 1073 for (CfgNode *Node : Nodes) { |
| 1072 if (NeedSandboxing && Node->needsAlignment()) | 1074 if (NeedSandboxing && Node->needsAlignment()) |
| 1073 getAssembler()->alignCfgNode(); | 1075 getAssembler()->alignCfgNode(); |
| 1074 Node->emitIAS(this); | 1076 Node->emitIAS(this); |
| 1075 } | 1077 } |
| 1076 emitJumpTables(); | 1078 emitJumpTables(); |
| 1077 } | 1079 } |
| 1078 | 1080 |
| 1081 size_t Cfg::getTotalMemoryMB() { | |
| 1082 constexpr size_t OneMB = 1024 * 1024; | |
| 1083 return (CfgLocalAllocator<int>().current()->getTotalMemory() / OneMB); | |
|
John
2016/02/29 15:12:30
Add a comment explaining why int and not something
Jim Stichnoth
2016/02/29 22:58:26
Done.
| |
| 1084 } | |
| 1085 | |
| 1079 // Dumps the IR with an optional introductory message. | 1086 // Dumps the IR with an optional introductory message. |
| 1080 void Cfg::dump(const IceString &Message) { | 1087 void Cfg::dump(const IceString &Message) { |
| 1081 if (!BuildDefs::dump()) | 1088 if (!BuildDefs::dump()) |
| 1082 return; | 1089 return; |
| 1083 if (!isVerbose()) | 1090 if (!isVerbose()) |
| 1084 return; | 1091 return; |
| 1085 OstreamLocker L(Ctx); | 1092 OstreamLocker L(Ctx); |
| 1086 Ostream &Str = Ctx->getStrDump(); | 1093 Ostream &Str = Ctx->getStrDump(); |
| 1087 if (!Message.empty()) | 1094 if (!Message.empty()) |
| 1088 Str << "================ " << Message << " ================\n"; | 1095 Str << "================ " << Message << " ================\n"; |
| 1089 if (isVerbose(IceV_Mem)) { | 1096 if (isVerbose(IceV_Mem)) { |
| 1090 constexpr size_t OneMB = 1024 * 1024; | 1097 Str << "Memory size = " << getTotalMemoryMB() << " MB\n"; |
| 1091 Str << "Memory size = " | |
| 1092 << (CfgLocalAllocator<int>().current()->getTotalMemory() / OneMB) | |
| 1093 << " MB\n"; | |
| 1094 } | 1098 } |
| 1095 setCurrentNode(getEntryNode()); | 1099 setCurrentNode(getEntryNode()); |
| 1096 // Print function name+args | 1100 // Print function name+args |
| 1097 if (isVerbose(IceV_Instructions)) { | 1101 if (isVerbose(IceV_Instructions)) { |
| 1098 Str << "define "; | 1102 Str << "define "; |
| 1099 if (getInternal() && !Ctx->getFlags().getDisableInternal()) | 1103 if (getInternal() && !Ctx->getFlags().getDisableInternal()) |
| 1100 Str << "internal "; | 1104 Str << "internal "; |
| 1101 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; | 1105 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; |
| 1102 for (SizeT i = 0; i < Args.size(); ++i) { | 1106 for (SizeT i = 0; i < Args.size(); ++i) { |
| 1103 if (i > 0) | 1107 if (i > 0) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1140 } | 1144 } |
| 1141 } | 1145 } |
| 1142 // Print each basic block | 1146 // Print each basic block |
| 1143 for (CfgNode *Node : Nodes) | 1147 for (CfgNode *Node : Nodes) |
| 1144 Node->dump(this); | 1148 Node->dump(this); |
| 1145 if (isVerbose(IceV_Instructions)) | 1149 if (isVerbose(IceV_Instructions)) |
| 1146 Str << "}\n"; | 1150 Str << "}\n"; |
| 1147 } | 1151 } |
| 1148 | 1152 |
| 1149 } // end of namespace Ice | 1153 } // end of namespace Ice |
| OLD | NEW |