Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1468)

Unified Diff: src/IceCfgNode.cpp

Issue 205613002: Initial skeleton of Subzero. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Introduce IceGlobalContext, and rearrange other things around that Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceCfgNode.cpp
diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5794d28928272fe0a8d6cfd17205f887495295cf
--- /dev/null
+++ b/src/IceCfgNode.cpp
@@ -0,0 +1,105 @@
+//===- 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 IceCfgNode class, including the
+// complexities of instruction insertion and in-edge calculation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "IceCfg.h"
+#include "IceCfgNode.h"
+#include "IceInst.h"
+#include "IceOperand.h"
+
+IceCfgNode::IceCfgNode(IceCfg *Cfg, uint32_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 IceCfgNode::getName() const {
+ if (Name != "")
+ return Name;
+ char buf[30];
+ sprintf(buf, "__%u", getIndex());
JF 2014/04/16 01:27:32 snprintf
Jim Stichnoth 2014/04/21 20:26:40 Done.
+ 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 IceCfgNode::appendInst(IceInst *Inst) {
+ if (IceInstPhi *Phi = llvm::dyn_cast<IceInstPhi>(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 registerEdges() pass finalizes it by creating the
+// InEdges list.
+void IceCfgNode::registerEdges() {
+ OutEdges = (*Insts.rbegin())->getTerminatorEdges();
+ for (IceNodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end();
+ I != E; ++I) {
+ IceCfgNode *Node = *I;
+ Node->InEdges.push_back(this);
+ }
+}
+
+// ======================== Dump routines ======================== //
+
+void IceCfgNode::dump(IceCfg *Cfg) const {
+ Cfg->setCurrentNode(this);
+ IceOstream &Str = Cfg->getContext()->StrDump;
+ 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 (IceNodeList::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 (IcePhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E;
+ ++I) {
+ const IceInst *Inst = *I;
+ Inst->dumpDecorated(Cfg);
+ }
+ IceInstList::const_iterator I = Insts.begin(), E = Insts.end();
+ while (I != E) {
+ IceInst *Inst = *I++;
+ Inst->dumpDecorated(Cfg);
+ }
+ }
+ // Dump list of successor nodes.
+ if (Cfg->getContext()->isVerbose(IceV_Succs)) {
+ Str << " // succs = ";
+ for (IceNodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end();
+ I != E; ++I) {
+ if (I != OutEdges.begin())
+ Str << ", ";
+ Str << "%" << (*I)->getName();
+ }
+ Str << "\n";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698