Index: src/IceCfgNode.cpp |
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..63917e09131c5776ccd782e5427de8d519b5ab60 |
--- /dev/null |
+++ b/src/IceCfgNode.cpp |
@@ -0,0 +1,110 @@ |
+//===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// |
+// |
+// The Subzero Code Generator |
+// |
+// This file is distributed under the University of Illinois Open Source |
+// License. See LICENSE.TXT for details. |
+// |
+//===----------------------------------------------------------------------===// |
+// |
+// This file implements the CfgNode class, including the |
+// complexities of instruction insertion and in-edge calculation. |
+// |
+//===----------------------------------------------------------------------===// |
+ |
+#include "IceCfg.h" |
+#include "IceCfgNode.h" |
+#include "IceInst.h" |
+#include "IceOperand.h" |
+ |
+namespace Ice { |
+ |
+CfgNode::CfgNode(IceCfg *Cfg, IceSize_t LabelNumber, IceString Name) |
+ : Cfg(Cfg), Number(LabelNumber), Name(Name) {} |
+ |
+// Returns the name the node was created with. If no name was given, |
+// it synthesizes a (hopefully) unique name. |
+IceString CfgNode::getName() const { |
+ 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).
|
+ return Name; |
+ 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
|
+ char buf[BufLen]; |
+ snprintf(buf, BufLen, "__%u", getIndex()); |
+ return buf; |
+} |
+ |
+// Adds an instruction to either the Phi list or the regular |
+// instruction list. Validates that all Phis are added before all |
+// regular instructions. |
+void CfgNode::appendInst(Inst *Inst) { |
+ if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) { |
+ if (!Insts.empty()) { |
+ Cfg->setError("Phi instruction added to the middle of a block"); |
+ return; |
+ } |
+ Phis.push_back(Phi); |
+ } else { |
+ Insts.push_back(Inst); |
+ } |
+ Inst->updateVars(this); |
+} |
+ |
+// When a node is created, the OutEdges are immediately knows, but the |
+// InEdges have to be built up incrementally. After the CFG has been |
+// constructed, the computePredecessors() pass finalizes it by |
+// creating the InEdges list. |
+void CfgNode::computePredecessors() { |
+ OutEdges = (*Insts.rbegin())->getTerminatorEdges(); |
+ for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); |
+ I != E; ++I) { |
+ CfgNode *Node = *I; |
+ Node->InEdges.push_back(this); |
+ } |
+} |
+ |
+// ======================== Dump routines ======================== // |
+ |
+void CfgNode::dump(IceCfg *Cfg) const { |
+ Cfg->setCurrentNode(this); |
+ IceOstream &Str = Cfg->getContext()->getStrDump(); |
+ if (Cfg->getContext()->isVerbose(IceV_Instructions)) { |
+ Str << getName() << ":\n"; |
+ } |
+ // Dump list of predecessor nodes. |
+ if (Cfg->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) { |
+ Str << " // preds = "; |
+ for (NodeList::const_iterator I = InEdges.begin(), E = InEdges.end(); |
+ I != E; ++I) { |
+ if (I != InEdges.begin()) |
+ Str << ", "; |
+ Str << "%" << (*I)->getName(); |
+ } |
+ Str << "\n"; |
+ } |
+ // Dump each instruction. |
+ if (Cfg->getContext()->isVerbose(IceV_Instructions)) { |
+ for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; |
+ ++I) { |
+ const Inst *Inst = *I; |
+ Inst->dumpDecorated(Cfg); |
+ } |
+ InstList::const_iterator I = Insts.begin(), E = Insts.end(); |
+ while (I != E) { |
+ Inst *Inst = *I++; |
+ Inst->dumpDecorated(Cfg); |
+ } |
+ } |
+ // Dump list of successor nodes. |
+ if (Cfg->getContext()->isVerbose(IceV_Succs)) { |
+ Str << " // succs = "; |
+ for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end(); |
+ I != E; ++I) { |
+ if (I != OutEdges.begin()) |
+ Str << ", "; |
+ Str << "%" << (*I)->getName(); |
+ } |
+ Str << "\n"; |
+ } |
+} |
+ |
+} // end of namespace Ice |