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

Side by Side Diff: src/IceCfgNode.cpp

Issue 1837663002: Initial Subzero WASM prototype. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review feedback and merging master Created 4 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/IceClFlags.def » ('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 /// \file 10 /// \file
(...skipping 19 matching lines...) Expand all
30 if (BuildDefs::dump()) { 30 if (BuildDefs::dump()) {
31 Name = 31 Name =
32 NodeString::createWithString(Func, "__" + std::to_string(getIndex())); 32 NodeString::createWithString(Func, "__" + std::to_string(getIndex()));
33 } else { 33 } else {
34 Name = NodeString::createWithoutString(Func); 34 Name = NodeString::createWithoutString(Func);
35 } 35 }
36 } 36 }
37 37
38 // Adds an instruction to either the Phi list or the regular instruction list. 38 // Adds an instruction to either the Phi list or the regular instruction list.
39 // Validates that all Phis are added before all regular instructions. 39 // Validates that all Phis are added before all regular instructions.
40 void CfgNode::appendInst(Inst *Instr) { 40 void CfgNode::appendInst(Inst *Instr, bool AllowPhisAnywhere) {
41 ++InstCountEstimate; 41 ++InstCountEstimate;
42
43 if (BuildDefs::wasm()) {
44 if (llvm::isa<InstSwitch>(Instr) || llvm::isa<InstBr>(Instr)) {
45 for (auto *N : Instr->getTerminatorEdges()) {
46 N->addInEdge(this);
47 addOutEdge(N);
48 }
49 }
50 }
51
42 if (auto *Phi = llvm::dyn_cast<InstPhi>(Instr)) { 52 if (auto *Phi = llvm::dyn_cast<InstPhi>(Instr)) {
43 if (!Insts.empty()) { 53 if (!AllowPhisAnywhere && !Insts.empty()) {
44 Func->setError("Phi instruction added to the middle of a block"); 54 Func->setError("Phi instruction added to the middle of a block");
45 return; 55 return;
46 } 56 }
47 Phis.push_back(Phi); 57 Phis.push_back(Phi);
48 } else { 58 } else {
49 Insts.push_back(Instr); 59 Insts.push_back(Instr);
50 } 60 }
51 } 61 }
52 62
53 namespace { 63 namespace {
(...skipping 20 matching lines...) Expand all
74 84
75 // When a node is created, the OutEdges are immediately known, but the InEdges 85 // When a node is created, the OutEdges are immediately known, but the InEdges
76 // have to be built up incrementally. After the CFG has been constructed, the 86 // have to be built up incrementally. After the CFG has been constructed, the
77 // computePredecessors() pass finalizes it by creating the InEdges list. 87 // computePredecessors() pass finalizes it by creating the InEdges list.
78 void CfgNode::computePredecessors() { 88 void CfgNode::computePredecessors() {
79 for (CfgNode *Succ : OutEdges) 89 for (CfgNode *Succ : OutEdges)
80 Succ->InEdges.push_back(this); 90 Succ->InEdges.push_back(this);
81 } 91 }
82 92
83 void CfgNode::computeSuccessors() { 93 void CfgNode::computeSuccessors() {
94 OutEdges.clear();
95 InEdges.clear();
84 OutEdges = Insts.rbegin()->getTerminatorEdges(); 96 OutEdges = Insts.rbegin()->getTerminatorEdges();
85 } 97 }
86 98
87 // Ensure each Phi instruction in the node is consistent with respect to control 99 // Ensure each Phi instruction in the node is consistent with respect to control
88 // flow. For each predecessor, there must be a phi argument with that label. 100 // flow. For each predecessor, there must be a phi argument with that label.
89 // If a phi argument's label doesn't appear in the predecessor list (which can 101 // If a phi argument's label doesn't appear in the predecessor list (which can
90 // happen as a result of e.g. unreachable node elimination), its value is 102 // happen as a result of e.g. unreachable node elimination), its value is
91 // modified to be zero, to maintain consistency in liveness analysis. This 103 // modified to be zero, to maintain consistency in liveness analysis. This
92 // allows us to remove some dead control flow without a major rework of the phi 104 // allows us to remove some dead control flow without a major rework of the phi
93 // instructions. We don't check that phi arguments with the same label have the 105 // instructions. We don't check that phi arguments with the same label have the
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 if (I.isDeleted()) 894 if (I.isDeleted())
883 continue; 895 continue;
884 if (I.isUnconditionalBranch()) 896 if (I.isUnconditionalBranch())
885 Branch = &I; 897 Branch = &I;
886 else if (!I.isRedundantAssign()) 898 else if (!I.isRedundantAssign())
887 return; 899 return;
888 } 900 }
889 // Make sure there is actually a successor to repoint in-edges to. 901 // Make sure there is actually a successor to repoint in-edges to.
890 if (OutEdges.empty()) 902 if (OutEdges.empty())
891 return; 903 return;
892 assert(OutEdges.size() == 1); 904 assert(hasSingleOutEdge());
893 // Don't try to delete a self-loop. 905 // Don't try to delete a self-loop.
894 if (OutEdges[0] == this) 906 if (OutEdges[0] == this)
895 return; 907 return;
896 // Make sure the node actually contains (ends with) an unconditional branch. 908 // Make sure the node actually contains (ends with) an unconditional branch.
897 if (Branch == nullptr) 909 if (Branch == nullptr)
898 return; 910 return;
899 911
900 Branch->setDeleted(); 912 Branch->setDeleted();
901 CfgNode *Successor = OutEdges.front(); 913 CfgNode *Successor = OutEdges.front();
902 // Repoint all this node's in-edges to this node's successor, unless this 914 // Repoint all this node's in-edges to this node's successor, unless this
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 auto *Instr = InstIntrinsicCall::create( 1474 auto *Instr = InstIntrinsicCall::create(
1463 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); 1475 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info);
1464 Instr->addArg(AtomicRMWOp); 1476 Instr->addArg(AtomicRMWOp);
1465 Instr->addArg(Counter); 1477 Instr->addArg(Counter);
1466 Instr->addArg(One); 1478 Instr->addArg(One);
1467 Instr->addArg(OrderAcquireRelease); 1479 Instr->addArg(OrderAcquireRelease);
1468 Insts.push_front(Instr); 1480 Insts.push_front(Instr);
1469 } 1481 }
1470 1482
1471 } // end of namespace Ice 1483 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfgNode.h ('k') | src/IceClFlags.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698