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 21 matching lines...) Expand all Loading... | |
| 32 // Returns the name the node was created with. If no name was given, it | 32 // Returns the name the node was created with. If no name was given, it |
| 33 // synthesizes a (hopefully) unique name. | 33 // synthesizes a (hopefully) unique name. |
| 34 IceString CfgNode::getName() const { | 34 IceString CfgNode::getName() const { |
| 35 if (NameIndex >= 0) | 35 if (NameIndex >= 0) |
| 36 return Func->getIdentifierName(NameIndex); | 36 return Func->getIdentifierName(NameIndex); |
| 37 return "__" + std::to_string(LabelNumber); | 37 return "__" + std::to_string(LabelNumber); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Adds an instruction to either the Phi list or the regular instruction list. | 40 // Adds an instruction to either the Phi list or the regular instruction list. |
| 41 // Validates that all Phis are added before all regular instructions. | 41 // Validates that all Phis are added before all regular instructions. |
| 42 void CfgNode::appendInst(Inst *Instr) { | 42 void CfgNode::appendInst(Inst *Instr, bool AllowPhisAnywhere) { |
| 43 ++InstCountEstimate; | 43 ++InstCountEstimate; |
| 44 | |
| 45 if (auto Dest = Instr->getDest()) { | |
|
Jim Stichnoth
2016/03/29 17:49:57
auto *
here and below
Eric Holk
2016/03/29 22:58:07
Done.
| |
| 46 Dest->setDefNode(this); | |
| 47 } | |
| 48 | |
| 49 if (auto Br = llvm::dyn_cast<InstBr>(Instr)) { | |
| 50 if (auto N = Br->getTargetTrue()) { | |
| 51 N->addInEdge(this); | |
| 52 addOutEdge(N); | |
| 53 } | |
| 54 if (auto N = Br->getTargetFalse()) { | |
| 55 N->addInEdge(this); | |
| 56 addOutEdge(N); | |
| 57 } | |
| 58 } | |
| 59 | |
| 44 if (auto *Phi = llvm::dyn_cast<InstPhi>(Instr)) { | 60 if (auto *Phi = llvm::dyn_cast<InstPhi>(Instr)) { |
| 45 if (!Insts.empty()) { | 61 if (!AllowPhisAnywhere && !Insts.empty()) { |
| 46 Func->setError("Phi instruction added to the middle of a block"); | 62 Func->setError("Phi instruction added to the middle of a block"); |
| 63 assert(false); | |
|
JF
2016/03/28 18:17:13
llvm_unreachable
Jim Stichnoth
2016/03/29 17:49:57
actually just remove the assert.
Eric Holk
2016/03/29 19:54:08
Actually, I didn't mean to keep this assert here a
| |
| 47 return; | 64 return; |
| 48 } | 65 } |
| 49 Phis.push_back(Phi); | 66 Phis.push_back(Phi); |
| 50 } else { | 67 } else { |
| 51 Insts.push_back(Instr); | 68 Insts.push_back(Instr); |
| 52 } | 69 } |
| 70 Instr->setCfgNode(this); | |
| 53 } | 71 } |
| 54 | 72 |
| 55 namespace { | 73 namespace { |
| 56 template <typename List> void removeDeletedAndRenumber(List *L, Cfg *Func) { | 74 template <typename List> void removeDeletedAndRenumber(List *L, Cfg *Func) { |
| 57 const bool DoDelete = | 75 const bool DoDelete = |
| 58 BuildDefs::minimal() || !GlobalContext::getFlags().getKeepDeletedInsts(); | 76 BuildDefs::minimal() || !GlobalContext::getFlags().getKeepDeletedInsts(); |
| 59 auto I = L->begin(), E = L->end(), Next = I; | 77 auto I = L->begin(), E = L->end(), Next = I; |
| 60 for (++Next; I != E; I = Next++) { | 78 for (++Next; I != E; I = Next++) { |
| 61 if (DoDelete && I->isDeleted()) { | 79 if (DoDelete && I->isDeleted()) { |
| 62 L->erase(I); | 80 L->erase(I); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 76 | 94 |
| 77 // When a node is created, the OutEdges are immediately known, but the InEdges | 95 // When a node is created, the OutEdges are immediately known, but the InEdges |
| 78 // have to be built up incrementally. After the CFG has been constructed, the | 96 // have to be built up incrementally. After the CFG has been constructed, the |
| 79 // computePredecessors() pass finalizes it by creating the InEdges list. | 97 // computePredecessors() pass finalizes it by creating the InEdges list. |
| 80 void CfgNode::computePredecessors() { | 98 void CfgNode::computePredecessors() { |
| 81 for (CfgNode *Succ : OutEdges) | 99 for (CfgNode *Succ : OutEdges) |
| 82 Succ->InEdges.push_back(this); | 100 Succ->InEdges.push_back(this); |
| 83 } | 101 } |
| 84 | 102 |
| 85 void CfgNode::computeSuccessors() { | 103 void CfgNode::computeSuccessors() { |
| 104 OutEdges.clear(); | |
| 105 InEdges.clear(); | |
| 86 OutEdges = Insts.rbegin()->getTerminatorEdges(); | 106 OutEdges = Insts.rbegin()->getTerminatorEdges(); |
| 87 } | 107 } |
| 88 | 108 |
| 89 // Validate each Phi instruction in the node with respect to control flow. For | 109 // Validate each Phi instruction in the node with respect to control flow. For |
| 90 // every phi argument, its label must appear in the predecessor list. For each | 110 // every phi argument, its label must appear in the predecessor list. For each |
| 91 // predecessor, there must be a phi argument with that label. We don't check | 111 // predecessor, there must be a phi argument with that label. We don't check |
| 92 // that phi arguments with the same label have the same value. | 112 // that phi arguments with the same label have the same value. |
| 93 void CfgNode::validatePhis() { | 113 void CfgNode::validatePhis() { |
| 94 for (Inst &Instr : Phis) { | 114 for (Inst &Instr : Phis) { |
| 95 auto *Phi = llvm::cast<InstPhi>(&Instr); | 115 auto *Phi = llvm::cast<InstPhi>(&Instr); |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 if (I.isDeleted()) | 887 if (I.isDeleted()) |
| 868 continue; | 888 continue; |
| 869 if (I.isUnconditionalBranch()) | 889 if (I.isUnconditionalBranch()) |
| 870 Branch = &I; | 890 Branch = &I; |
| 871 else if (!I.isRedundantAssign()) | 891 else if (!I.isRedundantAssign()) |
| 872 return; | 892 return; |
| 873 } | 893 } |
| 874 // 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. |
| 875 if (OutEdges.empty()) | 895 if (OutEdges.empty()) |
| 876 return; | 896 return; |
| 877 assert(OutEdges.size() == 1); | 897 assert(OutEdges.size() == 1 || OutEdges[0] == OutEdges[1]); |
| 878 // Don't try to delete a self-loop. | 898 // Don't try to delete a self-loop. |
| 879 if (OutEdges[0] == this) | 899 if (OutEdges[0] == this) |
| 880 return; | 900 return; |
| 881 // Make sure the node actually contains (ends with) an unconditional branch. | 901 // Make sure the node actually contains (ends with) an unconditional branch. |
| 882 if (Branch == nullptr) | 902 if (Branch == nullptr) |
| 883 return; | 903 return; |
| 884 | 904 |
| 885 Branch->setDeleted(); | 905 Branch->setDeleted(); |
| 886 CfgNode *Successor = OutEdges.front(); | 906 CfgNode *Successor = OutEdges.front(); |
| 887 // 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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1449 auto *Instr = InstIntrinsicCall::create( | 1469 auto *Instr = InstIntrinsicCall::create( |
| 1450 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); | 1470 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); |
| 1451 Instr->addArg(AtomicRMWOp); | 1471 Instr->addArg(AtomicRMWOp); |
| 1452 Instr->addArg(Counter); | 1472 Instr->addArg(Counter); |
| 1453 Instr->addArg(One); | 1473 Instr->addArg(One); |
| 1454 Instr->addArg(OrderAcquireRelease); | 1474 Instr->addArg(OrderAcquireRelease); |
| 1455 Insts.push_front(Instr); | 1475 Insts.push_front(Instr); |
| 1456 } | 1476 } |
| 1457 | 1477 |
| 1458 } // end of namespace Ice | 1478 } // end of namespace Ice |
| OLD | NEW |