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

Side by Side Diff: src/IceCfgNode.cpp

Issue 673783002: Subzero: Improve debugging controls, plus minor refactoring. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 6 years, 2 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/IceClFlags.h » ('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 12 matching lines...) Expand all
23 23
24 CfgNode::CfgNode(Cfg *Func, SizeT LabelNumber, IceString Name) 24 CfgNode::CfgNode(Cfg *Func, SizeT LabelNumber, IceString Name)
25 : Func(Func), Number(LabelNumber), Name(Name), HasReturn(false), 25 : Func(Func), Number(LabelNumber), Name(Name), HasReturn(false),
26 InstCountEstimate(0) {} 26 InstCountEstimate(0) {}
27 27
28 // Returns the name the node was created with. If no name was given, 28 // Returns the name the node was created with. If no name was given,
29 // it synthesizes a (hopefully) unique name. 29 // it synthesizes a (hopefully) unique name.
30 IceString CfgNode::getName() const { 30 IceString CfgNode::getName() const {
31 if (!Name.empty()) 31 if (!Name.empty())
32 return Name; 32 return Name;
33 char buf[30]; 33 return "__" + std::to_string(getIndex());
34 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex());
35 return buf;
36 } 34 }
37 35
38 // Adds an instruction to either the Phi list or the regular 36 // Adds an instruction to either the Phi list or the regular
39 // instruction list. Validates that all Phis are added before all 37 // instruction list. Validates that all Phis are added before all
40 // regular instructions. 38 // regular instructions.
41 void CfgNode::appendInst(Inst *Inst) { 39 void CfgNode::appendInst(Inst *Inst) {
42 ++InstCountEstimate; 40 ++InstCountEstimate;
43 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) { 41 if (InstPhi *Phi = llvm::dyn_cast<InstPhi>(Inst)) {
44 if (!Insts.empty()) { 42 if (!Insts.empty()) {
45 Func->setError("Phi instruction added to the middle of a block"); 43 Func->setError("Phi instruction added to the middle of a block");
(...skipping 12 matching lines...) Expand all
58 // overlap with the range of any other block. 56 // overlap with the range of any other block.
59 void CfgNode::renumberInstructions() { 57 void CfgNode::renumberInstructions() {
60 InstNumberT FirstNumber = Func->getNextInstNumber(); 58 InstNumberT FirstNumber = Func->getNextInstNumber();
61 for (InstPhi *I : Phis) 59 for (InstPhi *I : Phis)
62 I->renumber(Func); 60 I->renumber(Func);
63 for (Inst *I : Insts) 61 for (Inst *I : Insts)
64 I->renumber(Func); 62 I->renumber(Func);
65 InstCountEstimate = Func->getNextInstNumber() - FirstNumber; 63 InstCountEstimate = Func->getNextInstNumber() - FirstNumber;
66 } 64 }
67 65
68 // When a node is created, the OutEdges are immediately knows, but the 66 // When a node is created, the OutEdges are immediately known, but the
69 // InEdges have to be built up incrementally. After the CFG has been 67 // InEdges have to be built up incrementally. After the CFG has been
70 // constructed, the computePredecessors() pass finalizes it by 68 // constructed, the computePredecessors() pass finalizes it by
71 // creating the InEdges list. 69 // creating the InEdges list.
72 void CfgNode::computePredecessors() { 70 void CfgNode::computePredecessors() {
73 OutEdges = (*Insts.rbegin())->getTerminatorEdges(); 71 OutEdges = (*Insts.rbegin())->getTerminatorEdges();
74 for (CfgNode *Succ : OutEdges) 72 for (CfgNode *Succ : OutEdges)
75 Succ->InEdges.push_back(this); 73 Succ->InEdges.push_back(this);
76 } 74 }
77 75
78 // This does part 1 of Phi lowering, by creating a new dest variable 76 // This does part 1 of Phi lowering, by creating a new dest variable
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 Str << "\n"; 548 Str << "\n";
551 } 549 }
552 // Dump the live-in variables. 550 // Dump the live-in variables.
553 LivenessBV LiveIn; 551 LivenessBV LiveIn;
554 if (Liveness) 552 if (Liveness)
555 LiveIn = Liveness->getLiveIn(this); 553 LiveIn = Liveness->getLiveIn(this);
556 if (Func->getContext()->isVerbose(IceV_Liveness) && !LiveIn.empty()) { 554 if (Func->getContext()->isVerbose(IceV_Liveness) && !LiveIn.empty()) {
557 Str << " // LiveIn:"; 555 Str << " // LiveIn:";
558 for (SizeT i = 0; i < LiveIn.size(); ++i) { 556 for (SizeT i = 0; i < LiveIn.size(); ++i) {
559 if (LiveIn[i]) { 557 if (LiveIn[i]) {
560 Str << " %" << Liveness->getVariable(i, this)->getName(); 558 Variable *Var = Liveness->getVariable(i, this);
559 Str << " %" << Var->getName();
560 if (Func->getContext()->isVerbose(IceV_RegOrigins) && Var->hasReg()) {
561 Str << ":" << Func->getTarget()->getRegName(Var->getRegNum(),
562 Var->getType());
563 }
561 } 564 }
562 } 565 }
563 Str << "\n"; 566 Str << "\n";
564 } 567 }
565 // Dump each instruction. 568 // Dump each instruction.
566 if (Func->getContext()->isVerbose(IceV_Instructions)) { 569 if (Func->getContext()->isVerbose(IceV_Instructions)) {
567 for (InstPhi *I : Phis) 570 for (InstPhi *I : Phis)
568 I->dumpDecorated(Func); 571 I->dumpDecorated(Func);
569 for (Inst *I : Insts) 572 for (Inst *I : Insts)
570 I->dumpDecorated(Func); 573 I->dumpDecorated(Func);
571 } 574 }
572 // Dump the live-out variables. 575 // Dump the live-out variables.
573 LivenessBV LiveOut; 576 LivenessBV LiveOut;
574 if (Liveness) 577 if (Liveness)
575 LiveOut = Liveness->getLiveOut(this); 578 LiveOut = Liveness->getLiveOut(this);
576 if (Func->getContext()->isVerbose(IceV_Liveness) && !LiveOut.empty()) { 579 if (Func->getContext()->isVerbose(IceV_Liveness) && !LiveOut.empty()) {
577 Str << " // LiveOut:"; 580 Str << " // LiveOut:";
578 for (SizeT i = 0; i < LiveOut.size(); ++i) { 581 for (SizeT i = 0; i < LiveOut.size(); ++i) {
579 if (LiveOut[i]) { 582 if (LiveOut[i]) {
580 Str << " %" << Liveness->getVariable(i, this)->getName(); 583 Variable *Var = Liveness->getVariable(i, this);
584 Str << " %" << Var->getName();
585 if (Func->getContext()->isVerbose(IceV_RegOrigins) && Var->hasReg()) {
586 Str << ":" << Func->getTarget()->getRegName(Var->getRegNum(),
587 Var->getType());
588 }
581 } 589 }
582 } 590 }
583 Str << "\n"; 591 Str << "\n";
584 } 592 }
585 // Dump list of successor nodes. 593 // Dump list of successor nodes.
586 if (Func->getContext()->isVerbose(IceV_Succs)) { 594 if (Func->getContext()->isVerbose(IceV_Succs)) {
587 Str << " // succs = "; 595 Str << " // succs = ";
588 bool First = true; 596 bool First = true;
589 for (CfgNode *I : OutEdges) { 597 for (CfgNode *I : OutEdges) {
590 if (!First) 598 if (!First)
591 Str << ", "; 599 Str << ", ";
592 First = false; 600 First = false;
593 Str << "%" << I->getName(); 601 Str << "%" << I->getName();
594 } 602 }
595 Str << "\n"; 603 Str << "\n";
596 } 604 }
597 } 605 }
598 606
599 } // end of namespace Ice 607 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.cpp ('k') | src/IceClFlags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698