<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 12, 2014, at 1:22 AM, Artyom Skrobov <<a href="mailto:Artyom.Skrobov@arm.com" class="">Artyom.Skrobov@arm.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">It is true that this inverts the order, but I don't think this<br class="">definition of po_iterator is used anywhere except the constructor<br class="">for PostOrderInverseCFGView.<br class=""></blockquote><br class="">You're right, it's not; but equally the definition of<br class="">PostOrderCFGView::po_iterator isn't used anywhere except the<br class="">constructor for PostOrderCFGView: it's declared privately,<br class="">and it's not used by any PostOrderCFGView consumers.<br class=""></blockquote><br class="">Ok, that makes sense now, but it makes me feel the APIs themselves<br class="">are a bit misleading/confusing.  (see below)<br class=""></blockquote><br class="">Would it help make things a bit clearer if we move this private typedef out<br class="">of PostOrderCFGView declaration, into PostOrderCFGView constructor body?<br class="">(And the same for the new PostOrderInverseCFGView)<br class=""></div></blockquote><div><br class=""></div><div>It's actually a lot clearer to me now.  But there may be some benefits in making this implementation detail truly private, especially if it is used in only one place.  That would remove some stuff from the header file, cleaning up the interface.</div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><blockquote type="cite" class="">There is no virtual definition of the 'dequeue' method, so<br class="">'dequeue' (which is declared in DataflowWorklistBase) uses<br class="">the po_iterator defined in DataflowWorklistBase, which is<br class="">the wrong definition for reverse analysis.<br class=""></blockquote><br class="">No, dequeue() uses PostOrderCFGView::iterator, which<br class="">iterates over the Blocks vector. So, the only factor<br class="">affecting the order of iteration is how the Blocks vector<br class="">is initialized in the PostOrderInverseCFGView constructor.<br class=""></blockquote><br class="">I see it now.  From an API perspective it is very confusing,<br class="">because the name "PostOrderCFGView" implies the iteration<br class="">always is in that order.<br class=""></blockquote><br class="">Well, that's true: PostOrderCFGView always does it in the "normal" order,<br class="">and PostOrderInverseCFGView always does it in the inverse order.<br class=""></div></blockquote><div><br class=""></div><div>The standard terminology is "forward" and "backwards" analysis.  "Normal" implies a bias, when there really isn't one.</div><div><br class=""></div><div>The names are also not quite right.  A "forward" analysis uses a "reverse postorder", while a "backwards" analysis uses a "postorder" traversal.  Thus the names really should be:</div><div><br class=""></div><div>  PostOrderCFGView (for backwards analysis)</div><div>  ReversePostOrderCFGView (for forwards analysis)</div><div><br class=""></div><div>see:</div><div><br class=""></div><div><a href="http://en.wikipedia.org/wiki/Data-flow_analysis" class="">http://en.wikipedia.org/wiki/Data-flow_analysis</a></div><div><br class=""></div><div>("the order matters")</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><br class=""><br class=""><blockquote type="cite" class="">Also the comment is very misleading if we are doing a reverse<br class="">analysis:<br class=""><br class=""> // Next dequeue from the initial reverse post order.  This is the<br class=""> // theoretical ideal in the presence of no back edges.<br class=""><br class="">Technically we'd be doing the opposite thing if this was a<br class="">reverse analysis.  The comment if anything is what hung me<br class="">up on thinking it was doing the wrong thing.<br class=""></blockquote><br class="">The terminology here is a bit muddy, but I took it that "reverse" means<br class="">"back to forward", in the sense of using Blocks.rbegin() for the iteration<br class="">(which still applies to DataflowWorklistInverse); while "inverse" means<br class="">"bottom to top", in the sense of po_iterator visiting predecessors instead<br class="">of successors for each block. Assuming this terminology, DataflowWorklist<br class="">uses "reverse normal order", and DataflowWorklistInverse uses "reverse<br class="">inverse order"; but the comment in question remains valid in both cases.<br class=""><br class="">(I guess I should add the above paragraph into a comment in<br class="">DataflowWorklist.h?)<br class=""></div></blockquote><div><br class=""></div><div>Per my comment above, let's keep with the standard terminology: "forward" and "backwards".</div><div><br class=""></div><div>But I'm wondering about the refactoring here in your patch:</div><div><br class=""></div><div><blockquote type="cite" class=""><div>-  void sortWorklist();</div><div>+class DataflowWorklist : public DataflowWorklistBase {</div><div>+public:</div><div>+  DataflowWorklist(const CFG &cfg, AnalysisDeclContext &Ctx)</div><div>+    : DataflowWorklistBase(cfg, *Ctx.getAnalysis<PostOrderCFGView>()) {}</div><div> };</div><div> </div><div>+class DataflowWorklistInverse : public DataflowWorklistBase {</div><div>+public:</div><div>+  DataflowWorklistInverse(const CFG &cfg, AnalysisDeclContext &Ctx)</div><div>+    : DataflowWorklistBase(cfg, *Ctx.getAnalysis<PostOrderInverseCFGView>()) {}</div><div>+};</div><div>+</div><div> } // end clang namespace</div><div> </div></blockquote><br class=""></div><div>We're getting specialized behavior via subclassing, but I'm wondering if we can make this simpler.  What if we just have a "DataflowWorklist" class with one constructor that takes an enum indicating a forward or backward analysis.  Based on the enum we construct a PostOrderCFGView or a ReverseOrderCFGView.  Both of those could subclass some common class, say DataflowCFGView, that provides the iterator.  There is thus no need to duplicate DataflowWorklist.</div><div><br class=""></div><div>Honestly, we may not need two classes for the CFG view either, especially if all we are doing is putting the order in the Blocks vector.  That seems like we just need a "CFGView" class that initializes the Blocks vector based on the order specified when the CFGView object is constructed.</div><div><br class=""></div><div>The nice thing about this is that we don't get an expansion of classes and concepts.  All we have is a worklist that consults a CFG ordering.</div></div></body></html>