OLD | NEW |
1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// | 1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file implements the CfgNode class, including the complexities | 10 // This file implements the CfgNode class, including the complexities |
11 // of instruction insertion and in-edge calculation. | 11 // of instruction insertion and in-edge calculation. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "assembler.h" | 15 #include "assembler.h" |
16 #include "IceCfg.h" | 16 #include "IceCfg.h" |
17 #include "IceCfgNode.h" | 17 #include "IceCfgNode.h" |
18 #include "IceInst.h" | 18 #include "IceInst.h" |
19 #include "IceLiveness.h" | 19 #include "IceLiveness.h" |
20 #include "IceOperand.h" | 20 #include "IceOperand.h" |
21 #include "IceTargetLowering.h" | 21 #include "IceTargetLowering.h" |
22 | 22 |
23 namespace Ice { | 23 namespace Ice { |
24 | 24 |
25 CfgNode::CfgNode(Cfg *Func, SizeT LabelNumber, IceString Name) | 25 CfgNode::CfgNode(Cfg *Func, SizeT LabelNumber) |
26 : Func(Func), Number(LabelNumber), Name(Name), HasReturn(false), | 26 : Func(Func), Number(LabelNumber), NameIndex(-1), HasReturn(false), |
27 NeedsPlacement(false), InstCountEstimate(0) {} | 27 NeedsPlacement(false), InstCountEstimate(0) {} |
28 | 28 |
29 // Returns the name the node was created with. If no name was given, | 29 // Returns the name the node was created with. If no name was given, |
30 // it synthesizes a (hopefully) unique name. | 30 // it synthesizes a (hopefully) unique name. |
31 IceString CfgNode::getName() const { | 31 IceString CfgNode::getName() const { |
32 if (!Name.empty()) | 32 if (NameIndex >= 0) |
33 return Name; | 33 return Func->getNodeName(NameIndex); |
34 return "__" + std::to_string(getIndex()); | 34 return "__" + std::to_string(getIndex()); |
35 } | 35 } |
36 | 36 |
37 // Adds an instruction to either the Phi list or the regular | 37 // Adds an instruction to either the Phi list or the regular |
38 // instruction list. Validates that all Phis are added before all | 38 // instruction list. Validates that all Phis are added before all |
39 // regular instructions. | 39 // regular instructions. |
40 void CfgNode::appendInst(Inst *Inst) { | 40 void CfgNode::appendInst(Inst *Inst) { |
41 ++InstCountEstimate; | 41 ++InstCountEstimate; |
42 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) { | 42 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) { |
43 if (!Insts.empty()) { | 43 if (!Insts.empty()) { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // terminator instruction. If there are multiple edges from Pred to | 212 // terminator instruction. If there are multiple edges from Pred to |
213 // this node, only one edge is split, and the particular choice of | 213 // this node, only one edge is split, and the particular choice of |
214 // edge is undefined. This could happen with a switch instruction, or | 214 // edge is undefined. This could happen with a switch instruction, or |
215 // a conditional branch that weirdly has both branches to the same | 215 // a conditional branch that weirdly has both branches to the same |
216 // place. TODO(stichnot,kschimpf): Figure out whether this is legal | 216 // place. TODO(stichnot,kschimpf): Figure out whether this is legal |
217 // in the LLVM IR or the PNaCl bitcode, and if so, we need to | 217 // in the LLVM IR or the PNaCl bitcode, and if so, we need to |
218 // establish a strong relationship among the ordering of Pred's | 218 // establish a strong relationship among the ordering of Pred's |
219 // out-edge list, this node's in-edge list, and the Phi instruction's | 219 // out-edge list, this node's in-edge list, and the Phi instruction's |
220 // operand list. | 220 // operand list. |
221 CfgNode *CfgNode::splitIncomingEdge(CfgNode *Pred, SizeT EdgeIndex) { | 221 CfgNode *CfgNode::splitIncomingEdge(CfgNode *Pred, SizeT EdgeIndex) { |
222 CfgNode *NewNode = | 222 CfgNode *NewNode = Func->makeNode(); |
223 Func->makeNode("split_" + Pred->getName() + "_" + getName() + "_" + | 223 if (ALLOW_DUMP) |
| 224 NewNode->setName("split_" + Pred->getName() + "_" + getName() + "_" + |
224 std::to_string(EdgeIndex)); | 225 std::to_string(EdgeIndex)); |
225 // The new node is added to the end of the node list, and will later | 226 // The new node is added to the end of the node list, and will later |
226 // need to be sorted into a reasonable topological order. | 227 // need to be sorted into a reasonable topological order. |
227 NewNode->setNeedsPlacement(true); | 228 NewNode->setNeedsPlacement(true); |
228 // Repoint Pred's out-edge. | 229 // Repoint Pred's out-edge. |
229 bool Found = false; | 230 bool Found = false; |
230 for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); | 231 for (auto I = Pred->OutEdges.begin(), E = Pred->OutEdges.end(); |
231 !Found && I != E; ++I) { | 232 !Found && I != E; ++I) { |
232 if (*I == this) { | 233 if (*I == this) { |
233 *I = NewNode; | 234 *I = NewNode; |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 if (!First) | 1008 if (!First) |
1008 Str << ", "; | 1009 Str << ", "; |
1009 First = false; | 1010 First = false; |
1010 Str << "%" << I->getName(); | 1011 Str << "%" << I->getName(); |
1011 } | 1012 } |
1012 Str << "\n"; | 1013 Str << "\n"; |
1013 } | 1014 } |
1014 } | 1015 } |
1015 | 1016 |
1016 } // end of namespace Ice | 1017 } // end of namespace Ice |
OLD | NEW |