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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // target. | 238 // target. |
239 getTarget()->translate(); | 239 getTarget()->translate(); |
240 | 240 |
241 dump("Final output"); | 241 dump("Final output"); |
242 if (getFocusedTiming()) { | 242 if (getFocusedTiming()) { |
243 getContext()->mergeTimersFromTLS(); | 243 getContext()->mergeTimersFromTLS(); |
244 getContext()->dumpTimers(); | 244 getContext()->dumpTimers(); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
| 248 void Cfg::fixPhiNodes() { |
| 249 for (auto *Node : Nodes) { |
| 250 // Fix all the phi edges since WASM can't tell how to make them correctly at |
| 251 // the beginning. |
| 252 assert(Node); |
| 253 const auto &InEdges = Node->getInEdges(); |
| 254 for (auto &Instr : Node->getPhis()) { |
| 255 auto *Phi = llvm::cast<InstPhi>(&Instr); |
| 256 assert(Phi); |
| 257 for (SizeT i = 0; i < InEdges.size(); ++i) { |
| 258 Phi->setLabel(i, InEdges[i]); |
| 259 } |
| 260 } |
| 261 } |
| 262 } |
| 263 |
248 void Cfg::computeInOutEdges() { | 264 void Cfg::computeInOutEdges() { |
249 // Compute the out-edges. | 265 // Compute the out-edges. |
250 for (CfgNode *Node : Nodes) | 266 for (CfgNode *Node : Nodes) |
251 Node->computeSuccessors(); | 267 Node->computeSuccessors(); |
252 | 268 |
253 // Prune any unreachable nodes before computing in-edges. | 269 // Prune any unreachable nodes before computing in-edges. |
254 SizeT NumNodes = getNumNodes(); | 270 SizeT NumNodes = getNumNodes(); |
255 BitVector Reachable(NumNodes); | 271 BitVector Reachable(NumNodes); |
256 BitVector Pending(NumNodes); | 272 BitVector Pending(NumNodes); |
257 Pending.set(getEntryNode()->getIndex()); | 273 Pending.set(getEntryNode()->getIndex()); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 Placed.push_back(Node); | 411 Placed.push_back(Node); |
396 PlaceIndex[Node->getIndex()] = Placed.end(); | 412 PlaceIndex[Node->getIndex()] = Placed.end(); |
397 continue; | 413 continue; |
398 } | 414 } |
399 Node->setNeedsPlacement(false); | 415 Node->setNeedsPlacement(false); |
400 // Assume for now that the unplaced node is from edge-splitting and | 416 // Assume for now that the unplaced node is from edge-splitting and |
401 // therefore has 1 in-edge and 1 out-edge (actually, possibly more than 1 | 417 // therefore has 1 in-edge and 1 out-edge (actually, possibly more than 1 |
402 // in-edge if the predecessor node was contracted). If this changes in | 418 // in-edge if the predecessor node was contracted). If this changes in |
403 // the future, rethink the strategy. | 419 // the future, rethink the strategy. |
404 assert(Node->getInEdges().size() >= 1); | 420 assert(Node->getInEdges().size() >= 1); |
405 assert(Node->getOutEdges().size() == 1); | 421 assert(Node->hasSingleOutEdge()); |
406 | 422 |
407 // If it's a (non-critical) edge where the successor has a single | 423 // If it's a (non-critical) edge where the successor has a single |
408 // in-edge, then place it before the successor. | 424 // in-edge, then place it before the successor. |
409 CfgNode *Succ = Node->getOutEdges().front(); | 425 CfgNode *Succ = Node->getOutEdges().front(); |
410 if (Succ->getInEdges().size() == 1 && | 426 if (Succ->getInEdges().size() == 1 && |
411 PlaceIndex[Succ->getIndex()] != NoPlace) { | 427 PlaceIndex[Succ->getIndex()] != NoPlace) { |
412 Placed.insert(PlaceIndex[Succ->getIndex()], Node); | 428 Placed.insert(PlaceIndex[Succ->getIndex()], Node); |
413 PlaceIndex[Node->getIndex()] = PlaceIndex[Succ->getIndex()]; | 429 PlaceIndex[Node->getIndex()] = PlaceIndex[Succ->getIndex()]; |
414 continue; | 430 continue; |
415 } | 431 } |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 } | 1181 } |
1166 } | 1182 } |
1167 // Print each basic block | 1183 // Print each basic block |
1168 for (CfgNode *Node : Nodes) | 1184 for (CfgNode *Node : Nodes) |
1169 Node->dump(this); | 1185 Node->dump(this); |
1170 if (isVerbose(IceV_Instructions)) | 1186 if (isVerbose(IceV_Instructions)) |
1171 Str << "}\n"; | 1187 Str << "}\n"; |
1172 } | 1188 } |
1173 | 1189 |
1174 } // end of namespace Ice | 1190 } // end of namespace Ice |
OLD | NEW |