[llvm-dev] Access the Post Dominator tree

Momchil Velikov via llvm-dev llvm-dev at lists.llvm.org
Wed Oct 16 11:18:05 PDT 2019


On Wed, Oct 16, 2019 at 6:43 PM Kaarthik Alagapan via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> I’m trying to access the (post) dominator tree at the SelectionDAG phase
> to get the immediate post dominator block of a branch block. Would the post
> dominator tree be built at before that stage or does it occur after
> building the DAG? If it is, how can I get the post dominator tree of the
> specific block? I’m not able to find a specific function that returns the
> tree other than getNode but that works on a dominator tree.
>
> Regards,
> Kaarthik A.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
I'm assuming at SelectionDAG phase you're looking at LLVM IR post-dominator
tree (i.e. not machine one).

There are a few options.
You can state that post-dominace analysis is a prerequisite pass to your
pass in `getAnalysisUsage` and
later obtain it via `auto &PDT =
getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();`

If it's not a hard requirement, you can check if it's already available
with `getAnalysisIfAvailable`.

Or you can construct it directly with `auto PDT = std::make_unique<
PostDominatorTree>(*F);`

Once you have the post-dominator tree, you use the `dominates` member
function(s), they'll
return the post-dominance relation, despite the name.

Mind you, a number of convenience functions are not implemented for
post-dominator tree, look into
`lib/IR/Dominators.cpp` for inspiration how to implement them.

~chill

--
Compiler scrub, Arm.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191016/281b57c3/attachment.html>


More information about the llvm-dev mailing list