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 (auto *Br = llvm::dyn_cast<InstBr>(Instr)) { | |
| 44 if (auto *N = Br->getTargetTrue()) { | |
| 45 N->addInEdge(this); | |
| 46 addOutEdge(N); | |
| 47 } | |
| 48 if (auto N = Br->getTargetFalse()) { | |
|
Jim Stichnoth
2016/04/01 01:46:43
auto *N
Eric Holk
2016/04/01 19:15:01
Done.
| |
| 49 N->addInEdge(this); | |
| 50 addOutEdge(N); | |
| 51 } | |
| 52 } | |
| 53 | |
| 42 if (auto *Phi = llvm::dyn_cast<InstPhi>(Instr)) { | 54 if (auto *Phi = llvm::dyn_cast<InstPhi>(Instr)) { |
| 43 if (!Insts.empty()) { | 55 if (!AllowPhisAnywhere && !Insts.empty()) { |
| 44 Func->setError("Phi instruction added to the middle of a block"); | 56 Func->setError("Phi instruction added to the middle of a block"); |
| 45 return; | 57 return; |
| 46 } | 58 } |
| 47 Phis.push_back(Phi); | 59 Phis.push_back(Phi); |
| 48 } else { | 60 } else { |
| 49 Insts.push_back(Instr); | 61 Insts.push_back(Instr); |
| 50 } | 62 } |
| 51 } | 63 } |
| 52 | 64 |
| 53 namespace { | 65 namespace { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 74 | 86 |
| 75 // When a node is created, the OutEdges are immediately known, but the InEdges | 87 // 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 | 88 // have to be built up incrementally. After the CFG has been constructed, the |
| 77 // computePredecessors() pass finalizes it by creating the InEdges list. | 89 // computePredecessors() pass finalizes it by creating the InEdges list. |
| 78 void CfgNode::computePredecessors() { | 90 void CfgNode::computePredecessors() { |
| 79 for (CfgNode *Succ : OutEdges) | 91 for (CfgNode *Succ : OutEdges) |
| 80 Succ->InEdges.push_back(this); | 92 Succ->InEdges.push_back(this); |
| 81 } | 93 } |
| 82 | 94 |
| 83 void CfgNode::computeSuccessors() { | 95 void CfgNode::computeSuccessors() { |
| 96 OutEdges.clear(); | |
| 97 InEdges.clear(); | |
| 84 OutEdges = Insts.rbegin()->getTerminatorEdges(); | 98 OutEdges = Insts.rbegin()->getTerminatorEdges(); |
| 85 } | 99 } |
| 86 | 100 |
| 87 // Validate each Phi instruction in the node with respect to control flow. For | 101 // 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 | 102 // 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 | 103 // 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. | 104 // that phi arguments with the same label have the same value. |
| 91 void CfgNode::validatePhis() { | 105 void CfgNode::validatePhis() { |
| 92 for (Inst &Instr : Phis) { | 106 for (Inst &Instr : Phis) { |
| 93 auto *Phi = llvm::cast<InstPhi>(&Instr); | 107 auto *Phi = llvm::cast<InstPhi>(&Instr); |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 if (I.isDeleted()) | 879 if (I.isDeleted()) |
| 866 continue; | 880 continue; |
| 867 if (I.isUnconditionalBranch()) | 881 if (I.isUnconditionalBranch()) |
| 868 Branch = &I; | 882 Branch = &I; |
| 869 else if (!I.isRedundantAssign()) | 883 else if (!I.isRedundantAssign()) |
| 870 return; | 884 return; |
| 871 } | 885 } |
| 872 // Make sure there is actually a successor to repoint in-edges to. | 886 // Make sure there is actually a successor to repoint in-edges to. |
| 873 if (OutEdges.empty()) | 887 if (OutEdges.empty()) |
| 874 return; | 888 return; |
| 875 assert(OutEdges.size() == 1); | 889 assert(OutEdges.size() == 1 || OutEdges[0] == OutEdges[1]); |
| 876 // Don't try to delete a self-loop. | 890 // Don't try to delete a self-loop. |
| 877 if (OutEdges[0] == this) | 891 if (OutEdges[0] == this) |
| 878 return; | 892 return; |
| 879 // Make sure the node actually contains (ends with) an unconditional branch. | 893 // Make sure the node actually contains (ends with) an unconditional branch. |
| 880 if (Branch == nullptr) | 894 if (Branch == nullptr) |
| 881 return; | 895 return; |
| 882 | 896 |
| 883 Branch->setDeleted(); | 897 Branch->setDeleted(); |
| 884 CfgNode *Successor = OutEdges.front(); | 898 CfgNode *Successor = OutEdges.front(); |
| 885 // Repoint all this node's in-edges to this node's successor, unless this | 899 // 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... | |
| 1446 auto *Instr = InstIntrinsicCall::create( | 1460 auto *Instr = InstIntrinsicCall::create( |
| 1447 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); | 1461 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); |
| 1448 Instr->addArg(AtomicRMWOp); | 1462 Instr->addArg(AtomicRMWOp); |
| 1449 Instr->addArg(Counter); | 1463 Instr->addArg(Counter); |
| 1450 Instr->addArg(One); | 1464 Instr->addArg(One); |
| 1451 Instr->addArg(OrderAcquireRelease); | 1465 Instr->addArg(OrderAcquireRelease); |
| 1452 Insts.push_front(Instr); | 1466 Insts.push_front(Instr); |
| 1453 } | 1467 } |
| 1454 | 1468 |
| 1455 } // end of namespace Ice | 1469 } // end of namespace Ice |
| OLD | NEW |