OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // This file implements the IceCfgNode class, including the |
| 11 // complexities of instruction insertion and in-edge calculation. |
| 12 // |
| 13 //===----------------------------------------------------------------------===// |
| 14 |
| 15 #include "IceCfg.h" |
| 16 #include "IceCfgNode.h" |
| 17 #include "IceInst.h" |
| 18 #include "IceOperand.h" |
| 19 |
| 20 IceCfgNode::IceCfgNode(IceCfg *Cfg, uint32_t LabelNumber, IceString Name) |
| 21 : Cfg(Cfg), Number(LabelNumber), Name(Name) {} |
| 22 |
| 23 // Returns the name the node was created with. If no name was given, |
| 24 // it synthesizes a (hopefully) unique name. |
| 25 IceString IceCfgNode::getName() const { |
| 26 if (Name != "") |
| 27 return Name; |
| 28 char buf[30]; |
| 29 sprintf(buf, "__%u", getIndex()); |
| 30 return buf; |
| 31 } |
| 32 |
| 33 // Adds an instruction to either the Phi list or the regular |
| 34 // instruction list. Validates that all Phis are added before all |
| 35 // regular instructions. |
| 36 void IceCfgNode::appendInst(IceInst *Inst) { |
| 37 if (IceInstPhi *Phi = llvm::dyn_cast<IceInstPhi>(Inst)) { |
| 38 if (!Insts.empty()) { |
| 39 Cfg->setError("Phi instruction added to the middle of a block"); |
| 40 return; |
| 41 } |
| 42 Phis.push_back(Phi); |
| 43 } else { |
| 44 Insts.push_back(Inst); |
| 45 } |
| 46 Inst->updateVars(this); |
| 47 } |
| 48 |
| 49 // When a node is created, the OutEdges are immediately knows, but the |
| 50 // InEdges have to be built up incrementally. After the CFG has been |
| 51 // constructed, the registerEdges() pass finalizes it by creating the |
| 52 // InEdges list. |
| 53 void IceCfgNode::registerEdges() { |
| 54 OutEdges = (*Insts.rbegin())->getTerminatorEdges(); |
| 55 for (IceNodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); |
| 56 I != E; ++I) { |
| 57 IceCfgNode *Node = *I; |
| 58 Node->InEdges.push_back(this); |
| 59 } |
| 60 } |
| 61 |
| 62 // ======================== Dump routines ======================== // |
| 63 |
| 64 void IceCfgNode::dump(IceOstream &Str) const { |
| 65 Str.setCurrentNode(this); |
| 66 if (Str.isVerbose(IceV_Instructions)) { |
| 67 Str << getName() << ":\n"; |
| 68 } |
| 69 // Dump list of predecessor nodes. |
| 70 if (Str.isVerbose(IceV_Preds) && !InEdges.empty()) { |
| 71 Str << " // preds = "; |
| 72 for (IceNodeList::const_iterator I = InEdges.begin(), E = InEdges.end(); |
| 73 I != E; ++I) { |
| 74 if (I != InEdges.begin()) |
| 75 Str << ", "; |
| 76 Str << "%" << (*I)->getName(); |
| 77 } |
| 78 Str << "\n"; |
| 79 } |
| 80 // Dump each instruction. |
| 81 if (Str.isVerbose(IceV_Instructions)) { |
| 82 for (IcePhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; |
| 83 ++I) { |
| 84 Str << (*I); |
| 85 } |
| 86 IceInstList::const_iterator I = Insts.begin(), E = Insts.end(); |
| 87 while (I != E) { |
| 88 IceInst *Inst = *I++; |
| 89 Str << Inst; |
| 90 } |
| 91 } |
| 92 // Dump list of successor nodes. |
| 93 if (Str.isVerbose(IceV_Succs)) { |
| 94 Str << " // succs = "; |
| 95 for (IceNodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); |
| 96 I != E; ++I) { |
| 97 if (I != OutEdges.begin()) |
| 98 Str << ", "; |
| 99 Str << "%" << (*I)->getName(); |
| 100 } |
| 101 Str << "\n"; |
| 102 } |
| 103 } |
OLD | NEW |