[llvm] r234813 - Common some code from MemoryDependenceAnalysis that will be used in MemorySSA

David Blaikie dblaikie at gmail.com
Mon Apr 13 16:27:11 PDT 2015


On Mon, Apr 13, 2015 at 4:20 PM, Daniel Berlin <dberlin at dberlin.org> wrote:

> Author: dannyb
> Date: Mon Apr 13 18:20:13 2015
> New Revision: 234813
>
> URL: http://llvm.org/viewvc/llvm-project?rev=234813&view=rev
> Log:
> Common some code from MemoryDependenceAnalysis that will be used in
> MemorySSA
>
> Modified:
>     llvm/trunk/include/llvm/Analysis/AliasAnalysis.h
>     llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
>
> Modified: llvm/trunk/include/llvm/Analysis/AliasAnalysis.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/AliasAnalysis.h?rev=234813&r1=234812&r2=234813&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/AliasAnalysis.h (original)
> +++ llvm/trunk/include/llvm/Analysis/AliasAnalysis.h Mon Apr 13 18:20:13
> 2015
> @@ -145,6 +145,19 @@ public:
>    Location getLocation(const AtomicRMWInst *RMWI);
>    static Location getLocationForSource(const MemTransferInst *MTI);
>    static Location getLocationForDest(const MemIntrinsic *MI);
> +  Location getLocation(const Instruction *Inst) {
> +    if (auto *I = dyn_cast<LoadInst>(Inst))
> +      return getLocation(I);
> +    else if (auto *I = dyn_cast<StoreInst>(Inst))
>

Drop the elses after returns?


> +      return getLocation(I);
> +    else if (auto *I = dyn_cast<VAArgInst>(Inst))
> +      return getLocation(I);
> +    else if (auto *I = dyn_cast<AtomicCmpXchgInst>(Inst))
> +      return getLocation(I);
> +    else if (auto *I = dyn_cast<AtomicRMWInst>(Inst))
> +      return getLocation(I);
> +    llvm_unreachable("unsupported memory instruction");
>

& that last one can just be "return getLocation(cast<...>(Inst))"
(branching to unreachable is generally avoided in favor of an assertion -
but we do sometimes make tradeoffs for consistency in cases like this)

& sometimes code like this is phrased using a switch over the instruction
kind enum instead, for speed & such.

- David


> +  }
>
>    /// Alias analysis result - Either we know for sure that it does not
> alias, we
>    /// know for sure it must alias, or we don't know anything: The two
> pointers
>
> Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=234813&r1=234812&r2=234813&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
> +++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Mon Apr 13
> 18:20:13 2015
> @@ -874,23 +874,7 @@ MemoryDependenceAnalysis::getNonLocalCal
>  void MemoryDependenceAnalysis::
>  getNonLocalPointerDependency(Instruction *QueryInst,
>                               SmallVectorImpl<NonLocalDepResult> &Result) {
> -
> -  auto getLocation = [](AliasAnalysis *AA, Instruction *Inst) {
> -    if (auto *I = dyn_cast<LoadInst>(Inst))
> -      return AA->getLocation(I);
> -    else if (auto *I = dyn_cast<StoreInst>(Inst))
> -      return AA->getLocation(I);
> -    else if (auto *I = dyn_cast<VAArgInst>(Inst))
> -      return AA->getLocation(I);
> -    else if (auto *I = dyn_cast<AtomicCmpXchgInst>(Inst))
> -      return AA->getLocation(I);
> -    else if (auto *I = dyn_cast<AtomicRMWInst>(Inst))
> -      return AA->getLocation(I);
> -    else
> -      llvm_unreachable("unsupported memory instruction");
> -  };
> -
> -  const AliasAnalysis::Location Loc = getLocation(AA, QueryInst);
> +  const AliasAnalysis::Location Loc = AA->getLocation(QueryInst);
>    bool isLoad = isa<LoadInst>(QueryInst);
>    BasicBlock *FromBB = QueryInst->getParent();
>    assert(FromBB);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150413/11311ed4/attachment.html>


More information about the llvm-commits mailing list