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

Side by Side Diff: src/IceCfgNode.cpp

Issue 589003002: Subzero: Refactor tracking of Defs and block-local Variables. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: "Mark args as being used in the entry node" was unnecessary. Created 6 years, 3 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/IceCfg.cpp ('k') | src/IceConverter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 29 matching lines...) Expand all
40 void CfgNode::appendInst(Inst *Inst) { 40 void CfgNode::appendInst(Inst *Inst) {
41 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) { 41 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) {
42 if (!Insts.empty()) { 42 if (!Insts.empty()) {
43 Func->setError("Phi instruction added to the middle of a block"); 43 Func->setError("Phi instruction added to the middle of a block");
44 return; 44 return;
45 } 45 }
46 Phis.push_back(Phi); 46 Phis.push_back(Phi);
47 } else { 47 } else {
48 Insts.push_back(Inst); 48 Insts.push_back(Inst);
49 } 49 }
50 Inst->updateVars(this);
51 } 50 }
52 51
53 // Renumbers the non-deleted instructions in the node. This needs to 52 // Renumbers the non-deleted instructions in the node. This needs to
54 // be done in preparation for live range analysis. The instruction 53 // be done in preparation for live range analysis. The instruction
55 // numbers in a block must be monotonically increasing. The range of 54 // numbers in a block must be monotonically increasing. The range of
56 // instruction numbers in a block, from lowest to highest, must not 55 // instruction numbers in a block, from lowest to highest, must not
57 // overlap with the range of any other block. 56 // overlap with the range of any other block.
58 void CfgNode::renumberInstructions() { 57 void CfgNode::renumberInstructions() {
59 for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { 58 for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) {
60 (*I)->renumber(Func); 59 (*I)->renumber(Func);
(...skipping 24 matching lines...) Expand all
85 // the new dest. For example, 84 // the new dest. For example,
86 // a=phi(...) 85 // a=phi(...)
87 // changes to 86 // changes to
88 // "a_phi=phi(...); a=a_phi". 87 // "a_phi=phi(...); a=a_phi".
89 // 88 //
90 // This is in preparation for part 2 which deletes the Phi 89 // This is in preparation for part 2 which deletes the Phi
91 // instructions and appends assignment instructions to predecessor 90 // instructions and appends assignment instructions to predecessor
92 // blocks. Note that this transformation preserves SSA form. 91 // blocks. Note that this transformation preserves SSA form.
93 void CfgNode::placePhiLoads() { 92 void CfgNode::placePhiLoads() {
94 for (PhiList::iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { 93 for (PhiList::iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) {
95 Inst *Inst = (*I)->lower(Func, this); 94 Inst *Inst = (*I)->lower(Func);
96 Insts.insert(Insts.begin(), Inst); 95 Insts.insert(Insts.begin(), Inst);
97 Inst->updateVars(this);
98 } 96 }
99 } 97 }
100 98
101 // This does part 2 of Phi lowering. For each Phi instruction at each 99 // This does part 2 of Phi lowering. For each Phi instruction at each
102 // out-edge, create a corresponding assignment instruction, and add 100 // out-edge, create a corresponding assignment instruction, and add
103 // all the assignments near the end of this block. They need to be 101 // all the assignments near the end of this block. They need to be
104 // added before any branch instruction, and also if the block ends 102 // added before any branch instruction, and also if the block ends
105 // with a compare instruction followed by a branch instruction that we 103 // with a compare instruction followed by a branch instruction that we
106 // may want to fuse, it's better to insert the new assignments before 104 // may want to fuse, it's better to insert the new assignments before
107 // the compare instruction. The tryOptimizedCmpxchgCmpBr() method 105 // the compare instruction. The tryOptimizedCmpxchgCmpBr() method
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // prefer each other for register allocation. 204 // prefer each other for register allocation.
207 if (Variable *Src = llvm::dyn_cast<Variable>(Operand)) { 205 if (Variable *Src = llvm::dyn_cast<Variable>(Operand)) {
208 bool AllowOverlap = false; 206 bool AllowOverlap = false;
209 Dest->setPreferredRegister(Src, AllowOverlap); 207 Dest->setPreferredRegister(Src, AllowOverlap);
210 Src->setPreferredRegister(Dest, AllowOverlap); 208 Src->setPreferredRegister(Dest, AllowOverlap);
211 } 209 }
212 if (CmpInstDest == Operand) 210 if (CmpInstDest == Operand)
213 Insts.insert(SafeInsertionPoint, NewInst); 211 Insts.insert(SafeInsertionPoint, NewInst);
214 else 212 else
215 Insts.insert(InsertionPoint, NewInst); 213 Insts.insert(InsertionPoint, NewInst);
216 NewInst->updateVars(this);
217 } 214 }
218 } 215 }
219 } 216 }
220 217
221 // Deletes the phi instructions after the loads and stores are placed. 218 // Deletes the phi instructions after the loads and stores are placed.
222 void CfgNode::deletePhis() { 219 void CfgNode::deletePhis() {
223 for (PhiList::iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { 220 for (PhiList::iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) {
224 (*I)->setDeleted(); 221 (*I)->setDeleted();
225 } 222 }
226 } 223 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 271 }
275 272
276 void CfgNode::livenessLightweight() { 273 void CfgNode::livenessLightweight() {
277 SizeT NumVars = Func->getNumVariables(); 274 SizeT NumVars = Func->getNumVariables();
278 llvm::BitVector Live(NumVars); 275 llvm::BitVector Live(NumVars);
279 // Process regular instructions in reverse order. 276 // Process regular instructions in reverse order.
280 for (InstList::const_reverse_iterator I = Insts.rbegin(), E = Insts.rend(); 277 for (InstList::const_reverse_iterator I = Insts.rbegin(), E = Insts.rend();
281 I != E; ++I) { 278 I != E; ++I) {
282 if ((*I)->isDeleted()) 279 if ((*I)->isDeleted())
283 continue; 280 continue;
284 (*I)->livenessLightweight(Live); 281 (*I)->livenessLightweight(Func, Live);
285 } 282 }
286 for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) { 283 for (PhiList::const_iterator I = Phis.begin(), E = Phis.end(); I != E; ++I) {
287 if ((*I)->isDeleted()) 284 if ((*I)->isDeleted())
288 continue; 285 continue;
289 (*I)->livenessLightweight(Live); 286 (*I)->livenessLightweight(Func, Live);
290 } 287 }
291 } 288 }
292 289
293 // Performs liveness analysis on the block. Returns true if the 290 // Performs liveness analysis on the block. Returns true if the
294 // incoming liveness changed from before, false if it stayed the same. 291 // incoming liveness changed from before, false if it stayed the same.
295 // (If it changes, the node's predecessors need to be processed 292 // (If it changes, the node's predecessors need to be processed
296 // again.) 293 // again.)
297 bool CfgNode::liveness(Liveness *Liveness) { 294 bool CfgNode::liveness(Liveness *Liveness) {
298 SizeT NumVars = Liveness->getNumVarsInNode(this); 295 SizeT NumVars = Liveness->getNumVarsInNode(this);
299 llvm::BitVector Live(NumVars); 296 llvm::BitVector Live(NumVars);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 I != E; ++I) { 575 I != E; ++I) {
579 if (I != OutEdges.begin()) 576 if (I != OutEdges.begin())
580 Str << ", "; 577 Str << ", ";
581 Str << "%" << (*I)->getName(); 578 Str << "%" << (*I)->getName();
582 } 579 }
583 Str << "\n"; 580 Str << "\n";
584 } 581 }
585 } 582 }
586 583
587 } // end of namespace Ice 584 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.cpp ('k') | src/IceConverter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698