Chromium Code Reviews| 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()); | |
|
JF
2014/04/16 01:27:32
snprintf
Jim Stichnoth
2014/04/21 20:26:40
Done.
| |
| 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(IceCfg *Cfg) const { | |
| 65 Cfg->setCurrentNode(this); | |
| 66 IceOstream &Str = Cfg->getContext()->StrDump; | |
| 67 if (Cfg->getContext()->isVerbose(IceV_Instructions)) { | |
| 68 Str << getName() << ":\n"; | |
| 69 } | |
| 70 // Dump list of predecessor nodes. | |
| 71 if (Cfg->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) { | |
| 72 Str << " // preds = "; | |
| 73 for (IceNodeList::const_iterator I = InEdges.begin(), E = InEdges.end(); | |
| 74 I != E; ++I) { | |
| 75 if (I != InEdges.begin()) | |
| 76 Str << ", "; | |
| 77 Str << "%" << (*I)->getName(); | |
| 78 } | |
| 79 Str << "\n"; | |
| 80 } | |
| 81 // Dump each instruction. | |
| 82 if (Cfg->getContext()->isVerbose(IceV_Instructions)) { | |
| 83 for (IcePhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; | |
| 84 ++I) { | |
| 85 const IceInst *Inst = *I; | |
| 86 Inst->dumpDecorated(Cfg); | |
| 87 } | |
| 88 IceInstList::const_iterator I = Insts.begin(), E = Insts.end(); | |
| 89 while (I != E) { | |
| 90 IceInst *Inst = *I++; | |
| 91 Inst->dumpDecorated(Cfg); | |
| 92 } | |
| 93 } | |
| 94 // Dump list of successor nodes. | |
| 95 if (Cfg->getContext()->isVerbose(IceV_Succs)) { | |
| 96 Str << " // succs = "; | |
| 97 for (IceNodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); | |
| 98 I != E; ++I) { | |
| 99 if (I != OutEdges.begin()) | |
| 100 Str << ", "; | |
| 101 Str << "%" << (*I)->getName(); | |
| 102 } | |
| 103 Str << "\n"; | |
| 104 } | |
| 105 } | |
| OLD | NEW |