<div dir="ltr">Hi Jakub,<div><br></div><div>I think this broke one of our jobs on Green Dragon:</div><div><a href="http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-expensive/8568/consoleFull">http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-expensive/8568/consoleFull</a><br></div><div><br></div><div>Could you please take a look?</div><div><br></div><div>Thanks</div><div><br></div><div>Cheers,</div><div>Juergen</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 3, 2017 at 7:33 AM, Jakub Kuderski via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kuhar<br>
Date: Tue Oct 3 07:33:41 2017<br>
New Revision: 314801<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=314801&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=314801&view=rev</a><br>
Log:<br>
[Dominators] Add DFS number verification<br>
<br>
Summary:<br>
This patch teaches the DominatorTree verifier to check DFS In/Out numbers which are used to answer dominance queries.<br>
DFS number verification is done in O(nlogn), so it shouldn't add much overhead on top of the O(n^3) sibling property verification.<br>
This check should detect errors like the one spotted in PR34466 and related bug reports.<br>
<br>
The patch also cleans up the DFS calculation a bit, as all constructed trees should have a single root now.<br>
<br>
I see 2 new test failures when running check-all after this change:<br>
<br>
```<br>
Failing Tests (2):<br>
Polly :: Isl/CodeGen/OpenMP/reference-<wbr>argument-from-non-affine-<wbr>region.ll<br>
Polly :: Isl/CodeGen/OpenMP/two-<wbr>parallel-loops-reference-<wbr>outer-indvar.ll<br>
<br>
```<br>
which seem to happen just after `Create LLVM-IR from SCoPs` -- I XFAILed them in r314800.<br>
<br>
Reviewers: dberlin, grosser, davide, zhendongsu, bollu<br>
<br>
Reviewed By: dberlin<br>
<br>
Subscribers: nandini12396, bollu, Meinersbur, brzycki, llvm-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D38331" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D38331</a><br>
<br>
Modified:<br>
llvm/trunk/include/llvm/<wbr>Support/GenericDomTree.h<br>
llvm/trunk/include/llvm/<wbr>Support/<wbr>GenericDomTreeConstruction.h<br>
<br>
Modified: llvm/trunk/include/llvm/<wbr>Support/GenericDomTree.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GenericDomTree.h?rev=314801&r1=314800&r2=314801&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/Support/GenericDomTree.h?<wbr>rev=314801&r1=314800&r2=<wbr>314801&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/<wbr>Support/GenericDomTree.h (original)<br>
+++ llvm/trunk/include/llvm/<wbr>Support/GenericDomTree.h Tue Oct 3 07:33:41 2017<br>
@@ -702,28 +702,25 @@ public:<br>
return;<br>
}<br>
<br>
- unsigned DFSNum = 0;<br>
-<br>
SmallVector<std::pair<const DomTreeNodeBase<NodeT> *,<br>
typename DomTreeNodeBase<NodeT>::const_<wbr>iterator>,<br>
32> WorkStack;<br>
<br>
const DomTreeNodeBase<NodeT> *ThisRoot = getRootNode();<br>
-<br>
+ assert((!Parent || ThisRoot) && "Empty constructed DomTree");<br>
if (!ThisRoot)<br>
return;<br>
<br>
- // Even in the case of multiple exits that form the post dominator root<br>
- // nodes, do not iterate over all exits, but start from the virtual root<br>
- // node. Otherwise bbs, that are not post dominated by any exit but by the<br>
- // virtual root node, will never be assigned a DFS number.<br>
- WorkStack.push_back(std::make_<wbr>pair(ThisRoot, ThisRoot->begin()));<br>
+ // Both dominators and postdominators have a single root node. In the case<br>
+ // case of PostDominatorTree, this node is a virtual root.<br>
+ WorkStack.push_back({ThisRoot, ThisRoot->begin()});<br>
+<br>
+ unsigned DFSNum = 0;<br>
ThisRoot->DFSNumIn = DFSNum++;<br>
<br>
while (!WorkStack.empty()) {<br>
const DomTreeNodeBase<NodeT> *Node = WorkStack.back().first;<br>
- typename DomTreeNodeBase<NodeT>::const_<wbr>iterator ChildIt =<br>
- WorkStack.back().second;<br>
+ const auto ChildIt = WorkStack.back().second;<br>
<br>
// If we visited all of the children of this node, "recurse" back up the<br>
// stack setting the DFOutNum.<br>
@@ -735,7 +732,7 @@ public:<br>
const DomTreeNodeBase<NodeT> *Child = *ChildIt;<br>
++WorkStack.back().second;<br>
<br>
- WorkStack.push_back(std::make_<wbr>pair(Child, Child->begin()));<br>
+ WorkStack.push_back({Child, Child->begin()});<br>
Child->DFSNumIn = DFSNum++;<br>
}<br>
}<br>
<br>
Modified: llvm/trunk/include/llvm/<wbr>Support/<wbr>GenericDomTreeConstruction.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GenericDomTreeConstruction.h?rev=314801&r1=314800&r2=314801&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/Support/<wbr>GenericDomTreeConstruction.h?<wbr>rev=314801&r1=314800&r2=<wbr>314801&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/<wbr>Support/<wbr>GenericDomTreeConstruction.h (original)<br>
+++ llvm/trunk/include/llvm/<wbr>Support/<wbr>GenericDomTreeConstruction.h Tue Oct 3 07:33:41 2017<br>
@@ -1349,6 +1349,102 @@ struct SemiNCAInfo {<br>
return true;<br>
}<br>
<br>
+ // Check if the computed DFS numbers are correct. Note that DFS info may not<br>
+ // be valid, and when that is the case, we don't verify the numbers.<br>
+ static bool VerifyDFSNumbers(const DomTreeT &DT) {<br>
+ if (!DT.DFSInfoValid || !DT.Parent)<br>
+ return true;<br>
+<br>
+ const NodePtr RootBB = IsPostDom ? nullptr : DT.getRoots()[0];<br>
+ const TreeNodePtr Root = DT.getNode(RootBB);<br>
+<br>
+ auto PrintNodeAndDFSNums = [](const TreeNodePtr TN) {<br>
+ errs() << BlockNamePrinter(TN) << " {" << TN->getDFSNumIn() << ", "<br>
+ << TN->getDFSNumOut() << '}';<br>
+ };<br>
+<br>
+ // Verify the root's DFS In number. Although DFS numbering would also work<br>
+ // if we started from some other value, we assume 0-based numbering.<br>
+ if (Root->getDFSNumIn() != 0) {<br>
+ errs() << "DFSIn number for the tree root is not:\n\t";<br>
+ PrintNodeAndDFSNums(Root);<br>
+ errs() << '\n';<br>
+ errs().flush();<br>
+ return false;<br>
+ }<br>
+<br>
+ // For each tree node verify if children's DFS numbers cover their parent's<br>
+ // DFS numbers with no gaps.<br>
+ for (const auto &NodeToTN : DT.DomTreeNodes) {<br>
+ const TreeNodePtr Node = NodeToTN.second.get();<br>
+<br>
+ // Handle tree leaves.<br>
+ if (Node->getChildren().empty()) {<br>
+ if (Node->getDFSNumIn() + 1 != Node->getDFSNumOut()) {<br>
+ errs() << "Tree leaf should have DFSOut = DFSIn + 1:\n\t";<br>
+ PrintNodeAndDFSNums(Node);<br>
+ errs() << '\n';<br>
+ errs().flush();<br>
+ return false;<br>
+ }<br>
+<br>
+ continue;<br>
+ }<br>
+<br>
+ // Make a copy and sort it such that it is possible to check if there are<br>
+ // no gaps between DFS numbers of adjacent children.<br>
+ SmallVector<TreeNodePtr, 8> Children(Node->begin(), Node->end());<br>
+ std::sort(Children.begin(), Children.end(),<br>
+ [](const TreeNodePtr Ch1, const TreeNodePtr Ch2) {<br>
+ return Ch1->getDFSNumIn() < Ch2->getDFSNumIn();<br>
+ });<br>
+<br>
+ auto PrintChildrenError = [Node, &Children, PrintNodeAndDFSNums](<br>
+ const TreeNodePtr FirstCh, const TreeNodePtr SecondCh = nullptr) {<br>
+ assert(FirstCh);<br>
+<br>
+ errs() << "Incorrect DFS numbers for:\n\tParent ";<br>
+ PrintNodeAndDFSNums(Node);<br>
+<br>
+ errs() << "\n\tChild ";<br>
+ PrintNodeAndDFSNums(FirstCh);<br>
+<br>
+ if (SecondCh) {<br>
+ errs() << "\n\tSecond child ";<br>
+ PrintNodeAndDFSNums(SecondCh);<br>
+ }<br>
+<br>
+ errs() << "\nAll children: ";<br>
+ for (const TreeNodePtr Ch : Children) {<br>
+ PrintNodeAndDFSNums(Ch);<br>
+ errs() << ", ";<br>
+ }<br>
+<br>
+ errs() << '\n';<br>
+ errs().flush();<br>
+ };<br>
+<br>
+ if (Children.front()-><wbr>getDFSNumIn() != Node->getDFSNumIn() + 1) {<br>
+ PrintChildrenError(Children.<wbr>front());<br>
+ return false;<br>
+ }<br>
+<br>
+ if (Children.back()-><wbr>getDFSNumOut() + 1 != Node->getDFSNumOut()) {<br>
+ PrintChildrenError(Children.<wbr>back());<br>
+ return false;<br>
+ }<br>
+<br>
+ for (size_t i = 0, e = Children.size() - 1; i != e; ++i) {<br>
+ if (Children[i]->getDFSNumOut() + 1 != Children[i + 1]->getDFSNumIn()) {<br>
+ PrintChildrenError(Children[i]<wbr>, Children[i + 1]);<br>
+ return false;<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ return true;<br>
+ }<br>
+<br>
// Checks if for every edge From -> To in the graph<br>
// NCD(From, To) == IDom(To) or To.<br>
bool verifyNCD(const DomTreeT &DT) {<br>
@@ -1521,7 +1617,8 @@ bool Verify(const DomTreeT &DT) {<br>
SemiNCAInfo<DomTreeT> SNCA(nullptr);<br>
return SNCA.verifyRoots(DT) && SNCA.verifyReachability(DT) &&<br>
SNCA.VerifyLevels(DT) && SNCA.verifyNCD(DT) &&<br>
- SNCA.verifyParentProperty(DT) && SNCA.verifySiblingProperty(DT)<wbr>;<br>
+ SNCA.verifyParentProperty(DT) && SNCA.verifySiblingProperty(DT) &&<br>
+ SNCA.VerifyDFSNumbers(DT);<br>
}<br>
<br>
} // namespace DomTreeBuilder<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>