[llvm] r271706 - SDAG: Update ChainNodesMatched as nodes are deleted
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 3 11:50:12 PDT 2016
Author: bogner
Date: Fri Jun 3 13:50:11 2016
New Revision: 271706
URL: http://llvm.org/viewvc/llvm-project?rev=271706&view=rev
Log:
SDAG: Update ChainNodesMatched as nodes are deleted
Avoid relying on UB by looking into deleted nodes for a marker value.
Instead, update the list of chain nodes as we go.
Modified:
llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAG.h?rev=271706&r1=271705&r2=271706&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAG.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAG.h Fri Jun 3 13:50:11 2016
@@ -249,6 +249,14 @@ public:
virtual void NodeUpdated(SDNode *N);
};
+ struct DAGNodeDeletedListener : public DAGUpdateListener {
+ std::function<void(SDNode *, SDNode *)> Callback;
+ DAGNodeDeletedListener(SelectionDAG &DAG,
+ std::function<void(SDNode *, SDNode *)> Callback)
+ : DAGUpdateListener(DAG), Callback(Callback) {}
+ void NodeDeleted(SDNode *N, SDNode *E) override { Callback(N, E); }
+ };
+
/// When true, additional steps are taken to
/// ensure that getConstant() and similar functions return DAG nodes that
/// have legal types. This is important after type legalization since
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=271706&r1=271705&r2=271706&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Fri Jun 3 13:50:11 2016
@@ -2163,10 +2163,8 @@ void SelectionDAGISel::UpdateChains(
// Replace all the chain results with the final chain we ended up with.
for (unsigned i = 0, e = ChainNodesMatched.size(); i != e; ++i) {
SDNode *ChainNode = ChainNodesMatched[i];
-
- // If this node was already deleted, don't look at it.
- if (ChainNode->getOpcode() == ISD::DELETED_NODE)
- continue;
+ assert(ChainNode->getOpcode() != ISD::DELETED_NODE &&
+ "Deleted node left in chain");
// Don't replace the results of the root node if we're doing a
// MorphNodeTo.
@@ -3368,6 +3366,13 @@ void SelectionDAGISel::SelectCodeCommon(
} else {
assert(NodeToMatch->getOpcode() != ISD::DELETED_NODE &&
"NodeToMatch was removed partway through selection");
+ SelectionDAG::DAGNodeDeletedListener NDL(*CurDAG, [&](SDNode *N,
+ SDNode *E) {
+ assert(!E && "Unexpected node replacement in MorphNode");
+ ChainNodesMatched.erase(std::remove(ChainNodesMatched.begin(),
+ ChainNodesMatched.end(), N),
+ ChainNodesMatched.end());
+ });
Res = MorphNode(NodeToMatch, TargetOpc, VTList, Ops, EmitNodeInfo);
}
More information about the llvm-commits
mailing list