[PATCH] D35918: [GVNHoist] Factor out reachability to search for anticipable instructions quickly

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 15:59:00 PDT 2017


dberlin added a comment.

In https://reviews.llvm.org/D35918#823285, @hiraditya wrote:

> In https://reviews.llvm.org/D35918#822192, @dberlin wrote:
>
> > In https://reviews.llvm.org/D35918#822168, @hiraditya wrote:
> >
> > > In https://reviews.llvm.org/D35918#822143, @dberlin wrote:
> > >
> > > > FYI: IDFCalculator can compute the PostDominanceFrontier in linear time.
> > >
> > >
> > > I was unable to find how to pass the root node of inverse graph, because there might be more than one root.
> > >  Thanks,
> >
> >
> > No.
> >  The graph always has one root, virtual or not.
> >  Once kuba's latest patch is committed, it will *always* be virtual, actually.
> >
> > But i'm not sure why that would stop you one way or the other?
> >  The IDF calculator only asks for the defining blocks, not the root.
> >  You can hand it all CFG blocks and it should work fine.
>
>
> What I understand is that the API of IDFCalculator::calculate, populates a vector with all the dominance frontiers of the  defining blocks (AFAICT from the usage in ADCE.cpp).
>  How can I create a mapping of a basic block vs. its (post) dominance frontier. For this pass I would need to have such a mapping. I guess I'm having difficulty understanding the code. THanks for the help.


Such a mapping is by definition n^2 space, and i'm having trouble seeing why it is necessary.

Here is what you are doing:
For each instruction with the same VN:

  find the post-dominance frontier of the block of the instruction
  Insert a chi there, with certain arguments.

This is unnecessarily wasteful (you may compute the same pdf again and again).

Here is what SSUPRE (and you), should do:

Collect all the blocks of the instructions with the same VN into defining blocks.
Compute the PDF using IDFCalculator.
Place empty chis in the PDF.

At this point, you have two options:

  Walk post-dominator tree top-down and use a stack to store the last value you see.
  When you hit a chi from a given edge, the value to use as the argument is at the top of the stack.

This is O(Basic Blocks)

The O(instructions+chis) way to do it is:

Make a vector of instructions and chi argument uses.  Each should be given the DFS in/out number  from the post dominator tree node for the basic block they come from, and a local DFS number (IE order in block) in the case of instructions
A "chi argument use" is created for each incoming edge to the chi, but is empty/fake.  These should assume the basic block from the other side of the edge (IE not the chi block, but the edge to the chi block).
Sort by dfs in/out, then local number

  Walk vector with a stack.
  At each element of vector:
    while( !top of stack is empty && DFS in/out  of current thing in vector is not inside of DFS number of top of stack)
     pop stack
  If element you are staring at is a chi use:
    if stack is empty, chi has null operand
    if stack is not, set chi argument for the edge to top of stack
  else: // must be an instruction
      if stack is empty, push onto stack
     If stack is not empty, the thing on the stack post-dominates you and you are redundant :)

The forwards version of this algorithm is used by predicateinfo to do SSA renaming.
Your algorithm is the same on the reverse graph, except the chi arguments are virtual :)


https://reviews.llvm.org/D35918





More information about the llvm-commits mailing list