[PATCH] D28114: [StructurizeCfg] Update dominator info.
Serge Pavlov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 25 23:44:12 PST 2016
sepavloff created this revision.
sepavloff added reviewers: arsenm, chandlerc.
sepavloff added a subscriber: llvm-commits.
Herald added a subscriber: wdng.
In some cases StructurizeCfg updates root node, but dominator info
remains unchanges, it causes crash when expensive checks are enabled.
This change fixes PR27488.
https://reviews.llvm.org/D28114
Files:
include/llvm/Support/GenericDomTree.h
lib/Transforms/Scalar/StructurizeCFG.cpp
test/Transforms/StructurizeCFG/no-branch-to-entry.ll
Index: test/Transforms/StructurizeCFG/no-branch-to-entry.ll
===================================================================
--- test/Transforms/StructurizeCFG/no-branch-to-entry.ll
+++ test/Transforms/StructurizeCFG/no-branch-to-entry.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -o - -structurizecfg < %s | FileCheck %s
+; RUN: opt -S -o - -structurizecfg -verify-dom-info < %s | FileCheck %s
; CHECK-LABEL: @no_branch_to_entry_undef(
; CHECK: entry:
Index: lib/Transforms/Scalar/StructurizeCFG.cpp
===================================================================
--- lib/Transforms/Scalar/StructurizeCFG.cpp
+++ lib/Transforms/Scalar/StructurizeCFG.cpp
@@ -792,6 +792,7 @@
LoopFunc,
LoopStart);
BranchInst::Create(LoopStart, NewEntry);
+ DT->addNewBlock(NewEntry, nullptr);
}
// Create an extra loop end node
Index: include/llvm/Support/GenericDomTree.h
===================================================================
--- include/llvm/Support/GenericDomTree.h
+++ include/llvm/Support/GenericDomTree.h
@@ -571,16 +571,37 @@
// API to update (Post)DominatorTree information based on modifications to
// the CFG...
- /// addNewBlock - Add a new node to the dominator tree information. This
- /// creates a new node as a child of DomBB dominator node,linking it into
- /// the children list of the immediate dominator.
+ /// Add a new node to the dominator tree information.
+ ///
+ /// This creates a new node as a child of DomBB dominator node, linking it
+ /// into the children list of the immediate dominator.
+ ///
+ /// \param BB New node in CFG.
+ /// \param DomBB CFG node that is dominator for BB, nullptr if the new CFG
+ /// node becomes a new root.
+ /// \returns New dominator tree node that represents new CFG node.
+ ///
DomTreeNodeBase<NodeT> *addNewBlock(NodeT *BB, NodeT *DomBB) {
assert(getNode(BB) == nullptr && "Block already in dominator tree!");
- DomTreeNodeBase<NodeT> *IDomNode = getNode(DomBB);
- assert(IDomNode && "Not immediate dominator specified for block!");
DFSInfoValid = false;
- return (DomTreeNodes[BB] = IDomNode->addChild(
+ if (DomTreeNodeBase<NodeT> *IDomNode = getNode(DomBB)) {
+ return (DomTreeNodes[BB] = IDomNode->addChild(
llvm::make_unique<DomTreeNodeBase<NodeT>>(BB, IDomNode))).get();
+ }
+ // The new node becomes a tree root.
+ auto &Roots = DominatorBase<NodeT>::Roots;
+ DomTreeNodeBase<NodeT> *NewNode = (DomTreeNodes[BB] =
+ llvm::make_unique<DomTreeNodeBase<NodeT>>(BB, nullptr)).get();
+ if (Roots.empty()) {
+ addRoot(BB);
+ } else {
+ assert(Roots.size() == 1);
+ NodeT *OldRoot = Roots.front();
+ DomTreeNodes[OldRoot] =
+ NewNode->addChild(std::move(DomTreeNodes[OldRoot]));
+ Roots[0] = BB;
+ }
+ return RootNode = NewNode;
}
/// changeImmediateDominator - This method is used to update the dominator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28114.82492.patch
Type: text/x-patch
Size: 3002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161226/4ff35436/attachment.bin>
More information about the llvm-commits
mailing list