Chromium Code Reviews| 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 /// \file | 10 /// \file |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 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 (Instr->getKind() == Inst::Switch || Instr->getKind() == Inst::Br) { | |
|
Jim Stichnoth
2016/04/04 23:08:20
I think it would be more "standard" for the code b
Eric Holk
2016/04/04 23:16:07
Done.
| |
| 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 Loading... | |
| 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 // Validate each Phi instruction in the node with respect to control flow. For | 99 // Validate each Phi instruction in the node with respect to control flow. For |
| 88 // every phi argument, its label must appear in the predecessor list. For each | 100 // every phi argument, its label must appear in the predecessor list. For each |
| 89 // predecessor, there must be a phi argument with that label. We don't check | 101 // predecessor, there must be a phi argument with that label. We don't check |
| 90 // that phi arguments with the same label have the same value. | 102 // that phi arguments with the same label have the same value. |
| 91 void CfgNode::validatePhis() { | 103 void CfgNode::validatePhis() { |
| 92 for (Inst &Instr : Phis) { | 104 for (Inst &Instr : Phis) { |
| 93 auto *Phi = llvm::cast<InstPhi>(&Instr); | 105 auto *Phi = llvm::cast<InstPhi>(&Instr); |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 if (I.isDeleted()) | 887 if (I.isDeleted()) |
| 876 continue; | 888 continue; |
| 877 if (I.isUnconditionalBranch()) | 889 if (I.isUnconditionalBranch()) |
| 878 Branch = &I; | 890 Branch = &I; |
| 879 else if (!I.isRedundantAssign()) | 891 else if (!I.isRedundantAssign()) |
| 880 return; | 892 return; |
| 881 } | 893 } |
| 882 // Make sure there is actually a successor to repoint in-edges to. | 894 // Make sure there is actually a successor to repoint in-edges to. |
| 883 if (OutEdges.empty()) | 895 if (OutEdges.empty()) |
| 884 return; | 896 return; |
| 885 assert(OutEdges.size() == 1); | 897 assert(hasSingleOutEdge()); |
| 886 // Don't try to delete a self-loop. | 898 // Don't try to delete a self-loop. |
| 887 if (OutEdges[0] == this) | 899 if (OutEdges[0] == this) |
| 888 return; | 900 return; |
| 889 // Make sure the node actually contains (ends with) an unconditional branch. | 901 // Make sure the node actually contains (ends with) an unconditional branch. |
| 890 if (Branch == nullptr) | 902 if (Branch == nullptr) |
| 891 return; | 903 return; |
| 892 | 904 |
| 893 Branch->setDeleted(); | 905 Branch->setDeleted(); |
| 894 CfgNode *Successor = OutEdges.front(); | 906 CfgNode *Successor = OutEdges.front(); |
| 895 // Repoint all this node's in-edges to this node's successor, unless this | 907 // Repoint all this node's in-edges to this node's successor, unless this |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1456 auto *Instr = InstIntrinsicCall::create( | 1468 auto *Instr = InstIntrinsicCall::create( |
| 1457 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); | 1469 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); |
| 1458 Instr->addArg(AtomicRMWOp); | 1470 Instr->addArg(AtomicRMWOp); |
| 1459 Instr->addArg(Counter); | 1471 Instr->addArg(Counter); |
| 1460 Instr->addArg(One); | 1472 Instr->addArg(One); |
| 1461 Instr->addArg(OrderAcquireRelease); | 1473 Instr->addArg(OrderAcquireRelease); |
| 1462 Insts.push_front(Instr); | 1474 Insts.push_front(Instr); |
| 1463 } | 1475 } |
| 1464 | 1476 |
| 1465 } // end of namespace Ice | 1477 } // end of namespace Ice |
| OLD | NEW |