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

Side by Side 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: Use non-anonymous structs so that array_lengthof works 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 unified diff | Download patch
« no previous file with comments | « src/IceCfgNode.h ('k') | src/IceDefs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(Cfg *Func, SizeT LabelNumber, IceString Name)
23 : Func(Func), 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.empty())
29 return Name;
30 char buf[30];
31 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex());
32 return buf;
33 }
34
35 // Adds an instruction to either the Phi list or the regular
36 // instruction list. Validates that all Phis are added before all
37 // regular instructions.
38 void CfgNode::appendInst(Inst *Inst) {
39 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) {
40 if (!Insts.empty()) {
41 Func->setError("Phi instruction added to the middle of a block");
42 return;
43 }
44 Phis.push_back(Phi);
45 } else {
46 Insts.push_back(Inst);
47 }
48 Inst->updateVars(this);
49 }
50
51 // When a node is created, the OutEdges are immediately knows, but the
52 // InEdges have to be built up incrementally. After the CFG has been
53 // constructed, the computePredecessors() pass finalizes it by
54 // creating the InEdges list.
55 void CfgNode::computePredecessors() {
56 OutEdges = (*Insts.rbegin())->getTerminatorEdges();
57 for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end();
58 I != E; ++I) {
59 CfgNode *Node = *I;
60 Node->InEdges.push_back(this);
61 }
62 }
63
64 // ======================== Dump routines ======================== //
65
66 void CfgNode::dump(Cfg *Func) const {
67 Func->setCurrentNode(this);
68 Ostream &Str = Func->getContext()->getStrDump();
69 if (Func->getContext()->isVerbose(IceV_Instructions)) {
70 Str << getName() << ":\n";
71 }
72 // Dump list of predecessor nodes.
73 if (Func->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) {
74 Str << " // preds = ";
75 for (NodeList::const_iterator I = InEdges.begin(), E = InEdges.end();
76 I != E; ++I) {
77 if (I != InEdges.begin())
78 Str << ", ";
79 Str << "%" << (*I)->getName();
80 }
81 Str << "\n";
82 }
83 // Dump each instruction.
84 if (Func->getContext()->isVerbose(IceV_Instructions)) {
85 for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E;
86 ++I) {
87 const Inst *Inst = *I;
88 Inst->dumpDecorated(Func);
89 }
90 InstList::const_iterator I = Insts.begin(), E = Insts.end();
91 while (I != E) {
92 Inst *Inst = *I++;
93 Inst->dumpDecorated(Func);
94 }
95 }
96 // Dump list of successor nodes.
97 if (Func->getContext()->isVerbose(IceV_Succs)) {
98 Str << " // succs = ";
99 for (NodeList::const_iterator I = OutEdges.begin(), E = OutEdges.end();
100 I != E; ++I) {
101 if (I != OutEdges.begin())
102 Str << ", ";
103 Str << "%" << (*I)->getName();
104 }
105 Str << "\n";
106 }
107 }
108
109 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfgNode.h ('k') | src/IceDefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698