llvm-project/llvm/lib/Transforms
Duncan P. N. Exon Smith 71480bd0c7 ValueMapper/Enumerator: Clean up code in post-order traversals, NFC
Re-layer the functions in the new (i.e., newly correct) post-order
traversals in ValueEnumerator (r266947) and ValueMapper (r266949).
Instead of adding a node to the worklist in a helper function and
returning a flag to say what happened, return the node itself.  This
makes the code way cleaner: the worklist is local to the main function,
there is no flag for an early loop exit (since we can cleanly bury the
loop), and it's perfectly clear when pointers into the worklist might be
invalidated.

I'm fixing both algorithms in the same commit to avoid repeating the
commit message; if you take the time to understand one the other should
be easy.  The diff itself isn't entirely obvious since the traversals
have some noise (i.e., things to do), but here's the high-level change:

    auto helper = [&WL](T *Op) {     auto helper = [](T **&I, T **E) {
                                 =>    while (I != E) {
      if (shouldVisit(Op)) {             T *Op = *I++;
        WL.push(Op, Op->begin());        if (shouldVisit(Op)) {
        return true;                       return Op;
      }                                }
      return false;                    return nullptr;
    };                               };
                                 =>
    WL.push(S, S->begin());          WL.push(S, S->begin());
    while (!empty()) {               while (!empty()) {
      auto *N = WL.top().N;            auto *N = WL.top().N;
      auto *&I = WL.top().I;           auto *&I = WL.top().I;
      bool DidChange = false;
      while (I != N->end())
        if (helper(*I++)) {      =>    if (T *Op = helper(I, N->end()) {
          DidChange = true;              WL.push(Op, Op->begin());
          break;                         continue;
        }                              }
      if (DidChange)
        continue;

      POT.push(WL.pop());        =>    POT.push(WL.pop());
    }                                }

Thanks to Mehdi for helping me find a better way to layer this.

llvm-svn: 267099
2016-04-22 02:33:06 +00:00
..
Hello Remove autoconf support 2016-01-26 21:29:08 +00:00
IPO Initial implementation of optimization bisect support. 2016-04-21 17:58:54 +00:00
InstCombine NFC: fix copy / paste comment 2016-04-21 19:53:39 +00:00
Instrumentation Fixed flag description 2016-04-21 22:00:13 +00:00
ObjCARC Initial implementation of optimization bisect support. 2016-04-21 17:58:54 +00:00
Scalar Initial implementation of optimization bisect support. 2016-04-21 17:58:54 +00:00
Utils ValueMapper/Enumerator: Clean up code in post-order traversals, NFC 2016-04-22 02:33:06 +00:00
Vectorize Initial implementation of optimization bisect support. 2016-04-21 17:58:54 +00:00
CMakeLists.txt
LLVMBuild.txt