[llvm-commits] [llvm] r154631 - in /llvm/trunk: include/llvm/Analysis/Dominators.h lib/VMCore/Dominators.cpp

Eli Friedman eli.friedman at gmail.com
Thu Apr 12 16:39:41 PDT 2012


On Thu, Apr 12, 2012 at 4:31 PM, Dan Gohman <gohman at apple.com> wrote:
> Author: djg
> Date: Thu Apr 12 18:31:46 2012
> New Revision: 154631
>
> URL: http://llvm.org/viewvc/llvm-project?rev=154631&view=rev
> Log:
> Add forms of dominates and isReachableFromEntry that accept a Use
> directly instead of a user Instruction. This allows them to test
> whether a def dominates a particular operand if the user instruction
> is a PHI.
>
> Modified:
>    llvm/trunk/include/llvm/Analysis/Dominators.h
>    llvm/trunk/lib/VMCore/Dominators.cpp
>
> Modified: llvm/trunk/include/llvm/Analysis/Dominators.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/Dominators.h?rev=154631&r1=154630&r2=154631&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/Dominators.h (original)
> +++ llvm/trunk/include/llvm/Analysis/Dominators.h Thu Apr 12 18:31:46 2012
> @@ -775,6 +775,7 @@
>   // dominates - Return true if Def dominates a use in User. This performs
>   // the special checks necessary if Def and User are in the same basic block.
>   // Note that Def doesn't dominate a use in Def itself!
> +  bool dominates(const Instruction *Def, const Use &U) const;
>   bool dominates(const Instruction *Def, const Instruction *User) const;
>   bool dominates(const Instruction *Def, const BasicBlock *BB) const;
>
> @@ -843,6 +844,8 @@
>     return DT->isReachableFromEntry(A);
>   }
>
> +  bool isReachableFromEntry(const Use &U) const;
> +
>
>   virtual void releaseMemory() {
>     DT->releaseMemory();
>
> Modified: llvm/trunk/lib/VMCore/Dominators.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Dominators.cpp?rev=154631&r1=154630&r2=154631&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/Dominators.cpp (original)
> +++ llvm/trunk/lib/VMCore/Dominators.cpp Thu Apr 12 18:31:46 2012
> @@ -184,3 +184,84 @@
>   }
>   return true;
>  }
> +
> +bool DominatorTree::dominates(const Instruction *Def,
> +                              const Use &U) const {
> +  Instruction *UserInst = dyn_cast<Instruction>(U.getUser());
> +
> +  // All non-instructions conceptually dominate everything. Instructions do
> +  // not dominate non-instructions.
> +  if (!UserInst)
> +    return !isa<Instruction>(Def);

isa<Instruction> can't fail on an Instruction*.

-Eli




More information about the llvm-commits mailing list