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)) { | |
|
Jim Stichnoth
2016/04/04 21:26:51
You may also want to do the same for switch instru
Eric Holk
2016/04/04 22:23:22
Done.
| |
| 44 if (auto *N = Br->getTargetTrue()) { | |
| 45 N->addInEdge(this); | |
| 46 addOutEdge(N); | |
| 47 } | |
| 48 if (auto *N = Br->getTargetFalse()) { | |
| 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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 875 if (I.isDeleted()) | 889 if (I.isDeleted()) |
| 876 continue; | 890 continue; |
| 877 if (I.isUnconditionalBranch()) | 891 if (I.isUnconditionalBranch()) |
| 878 Branch = &I; | 892 Branch = &I; |
| 879 else if (!I.isRedundantAssign()) | 893 else if (!I.isRedundantAssign()) |
| 880 return; | 894 return; |
| 881 } | 895 } |
| 882 // Make sure there is actually a successor to repoint in-edges to. | 896 // Make sure there is actually a successor to repoint in-edges to. |
| 883 if (OutEdges.empty()) | 897 if (OutEdges.empty()) |
| 884 return; | 898 return; |
| 885 assert(OutEdges.size() == 1); | 899 assert(hasSingleOutEdge()); |
| 886 // Don't try to delete a self-loop. | 900 // Don't try to delete a self-loop. |
| 887 if (OutEdges[0] == this) | 901 if (OutEdges[0] == this) |
| 888 return; | 902 return; |
| 889 // Make sure the node actually contains (ends with) an unconditional branch. | 903 // Make sure the node actually contains (ends with) an unconditional branch. |
| 890 if (Branch == nullptr) | 904 if (Branch == nullptr) |
| 891 return; | 905 return; |
| 892 | 906 |
| 893 Branch->setDeleted(); | 907 Branch->setDeleted(); |
| 894 CfgNode *Successor = OutEdges.front(); | 908 CfgNode *Successor = OutEdges.front(); |
| 895 // Repoint all this node's in-edges to this node's successor, unless this | 909 // 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( | 1470 auto *Instr = InstIntrinsicCall::create( |
| 1457 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); | 1471 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); |
| 1458 Instr->addArg(AtomicRMWOp); | 1472 Instr->addArg(AtomicRMWOp); |
| 1459 Instr->addArg(Counter); | 1473 Instr->addArg(Counter); |
| 1460 Instr->addArg(One); | 1474 Instr->addArg(One); |
| 1461 Instr->addArg(OrderAcquireRelease); | 1475 Instr->addArg(OrderAcquireRelease); |
| 1462 Insts.push_front(Instr); | 1476 Insts.push_front(Instr); |
| 1463 } | 1477 } |
| 1464 | 1478 |
| 1465 } // end of namespace Ice | 1479 } // end of namespace Ice |
| OLD | NEW |