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 CfgNode 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 namespace Ice { | |
| 21 | |
| 22 CfgNode::CfgNode(IceCfg *Cfg, IceSize_t LabelNumber, IceString Name) | |
| 23 : Cfg(Cfg), Number(LabelNumber), Name(Name) {} | |
| 24 | |
| 25 // Returns the name the node was created with. If no name was given, | |
| 26 // it synthesizes a (hopefully) unique name. | |
| 27 IceString CfgNode::getName() const { | |
| 28 if (Name != "") | |
|
JF
2014/04/23 03:51:28
!Name.empty()
Jim Stichnoth
2014/04/26 15:02:11
Done (here and 2 other places).
| |
| 29 return Name; | |
| 30 const static size_t BufLen = 30; | |
|
JF
2014/04/23 03:51:28
Here and other places: LLVM has array_lengthof wit
Jim Stichnoth
2014/04/26 15:02:11
Done. I couldn't make this work in IceGlobalConte
| |
| 31 char buf[BufLen]; | |
| 32 snprintf(buf, BufLen, "__%u", getIndex()); | |
| 33 return buf; | |
| 34 } | |
| 35 | |
| 36 // Adds an instruction to either the Phi list or the regular | |
| 37 // instruction list. Validates that all Phis are added before all | |
| 38 // regular instructions. | |
| 39 void CfgNode::appendInst(Inst *Inst) { | |
| 40 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) { | |
| 41 if (!Insts.empty()) { | |
| 42 Cfg->setError("Phi instruction added to the middle of a block"); | |
| 43 return; | |
| 44 } | |
| 45 Phis.push_back(Phi); | |
| 46 } else { | |
| 47 Insts.push_back(Inst); | |
| 48 } | |
| 49 Inst->updateVars(this); | |
| 50 } | |
| 51 | |
| 52 // When a node is created, the OutEdges are immediately knows, but the | |
| 53 // InEdges have to be built up incrementally. After the CFG has been | |
| 54 // constructed, the computePredecessors() pass finalizes it by | |
| 55 // creating the InEdges list. | |
| 56 void CfgNode::computePredecessors() { | |
| 57 OutEdges = (*Insts.rbegin())->getTerminatorEdges(); | |
| 58 for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); | |
| 59 I != E; ++I) { | |
| 60 CfgNode *Node = *I; | |
| 61 Node->InEdges.push_back(this); | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 // ======================== Dump routines ======================== // | |
| 66 | |
| 67 void CfgNode::dump(IceCfg *Cfg) const { | |
| 68 Cfg->setCurrentNode(this); | |
| 69 IceOstream &Str = Cfg->getContext()->getStrDump(); | |
| 70 if (Cfg->getContext()->isVerbose(IceV_Instructions)) { | |
| 71 Str << getName() << ":\n"; | |
| 72 } | |
| 73 // Dump list of predecessor nodes. | |
| 74 if (Cfg->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) { | |
| 75 Str << " // preds = "; | |
| 76 for (NodeList::const_iterator I = InEdges.begin(), E = InEdges.end(); | |
| 77 I != E; ++I) { | |
| 78 if (I != InEdges.begin()) | |
| 79 Str << ", "; | |
| 80 Str << "%" << (*I)->getName(); | |
| 81 } | |
| 82 Str << "\n"; | |
| 83 } | |
| 84 // Dump each instruction. | |
| 85 if (Cfg->getContext()->isVerbose(IceV_Instructions)) { | |
| 86 for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; | |
| 87 ++I) { | |
| 88 const Inst *Inst = *I; | |
| 89 Inst->dumpDecorated(Cfg); | |
| 90 } | |
| 91 InstList::const_iterator I = Insts.begin(), E = Insts.end(); | |
| 92 while (I != E) { | |
| 93 Inst *Inst = *I++; | |
| 94 Inst->dumpDecorated(Cfg); | |
| 95 } | |
| 96 } | |
| 97 // Dump list of successor nodes. | |
| 98 if (Cfg->getContext()->isVerbose(IceV_Succs)) { | |
| 99 Str << " // succs = "; | |
| 100 for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); | |
| 101 I != E; ++I) { | |
| 102 if (I != OutEdges.begin()) | |
| 103 Str << ", "; | |
| 104 Str << "%" << (*I)->getName(); | |
| 105 } | |
| 106 Str << "\n"; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 } // end of namespace Ice | |
| OLD | NEW |