From ce0e12f0b4f304ba2d008c4facd302f127d34b2e Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Fri, 9 Jan 2015 00:26:45 +0000 Subject: [PATCH] [REFACTOR] Push logic from MemDepPrinter into getNonLocalPointerDependency Previously, MemDepPrinter handled volatile and unordered accesses without involving MemoryDependencyAnalysis. By making a slight tweak to the documented interface - which is respected by both callers - we can move this responsibility to MDA for the benefit of any future callers. This is basically just cleanup. In the future, we may decide to extend MDA's non local dependency analysis to return useful results for ordered or volatile loads. I believe (but have not really checked in detail) that local dependency analyis does get useful results for ordered, but not volatile, loads. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225483 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/Analysis/MemoryDependenceAnalysis.h | 9 +++-- lib/Analysis/MemDepPrinter.cpp | 24 ++----------- lib/Analysis/MemoryDependenceAnalysis.cpp | 35 +++++++++++-------- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/include/llvm/Analysis/MemoryDependenceAnalysis.h b/include/llvm/Analysis/MemoryDependenceAnalysis.h index 672c839d33b..67fd70a4561 100644 --- a/include/llvm/Analysis/MemoryDependenceAnalysis.h +++ b/include/llvm/Analysis/MemoryDependenceAnalysis.h @@ -366,9 +366,12 @@ namespace llvm { /// getNonLocalPointerDependency - Perform a full dependency query for an - /// access to the QueryInst's specified (non-volatile) memory location, - /// returning the set of instructions that either define or clobber - /// the value. + /// access to the QueryInst's specified memory location, returning the set + /// of instructions that either define or clobber the value. + /// + /// Warning: For a volatile query instruction, the dependencies will be + /// accurate, and thus usable for reordering, but it is never legal to + /// remove the query instruction. /// /// This method assumes the pointer has a "NonLocal" dependency within /// QueryInst's parent basic block. diff --git a/lib/Analysis/MemDepPrinter.cpp b/lib/Analysis/MemDepPrinter.cpp index ed77da02690..ffc9fe64cc5 100644 --- a/lib/Analysis/MemDepPrinter.cpp +++ b/lib/Analysis/MemDepPrinter.cpp @@ -118,27 +118,9 @@ bool MemDepPrinter::runOnFunction(Function &F) { } } else { SmallVector NLDI; - if (LoadInst *LI = dyn_cast(Inst)) { - if (!LI->isUnordered()) { - // FIXME: Handle atomic/volatile loads. - Deps[Inst].insert(std::make_pair(getInstTypePair(nullptr, Unknown), - static_cast(nullptr))); - continue; - } - MDA.getNonLocalPointerDependency(LI, NLDI); - } else if (StoreInst *SI = dyn_cast(Inst)) { - if (!SI->isUnordered()) { - // FIXME: Handle atomic/volatile stores. - Deps[Inst].insert(std::make_pair(getInstTypePair(nullptr, Unknown), - static_cast(nullptr))); - continue; - } - MDA.getNonLocalPointerDependency(SI, NLDI); - } else if (VAArgInst *VI = dyn_cast(Inst)) { - MDA.getNonLocalPointerDependency(VI, NLDI); - } else { - llvm_unreachable("Unknown memory instruction!"); - } + assert( (isa(Inst) || isa(Inst) || + isa(Inst)) && "Unknown memory instruction!"); + MDA.getNonLocalPointerDependency(Inst, NLDI); DepSet &InstDeps = Deps[Inst]; for (SmallVectorImpl::const_iterator diff --git a/lib/Analysis/MemoryDependenceAnalysis.cpp b/lib/Analysis/MemoryDependenceAnalysis.cpp index cc459482b2c..c505aa48817 100644 --- a/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -881,18 +881,23 @@ getNonLocalPointerDependency(Instruction *QueryInst, bool isLoad = isa(QueryInst); BasicBlock *FromBB = QueryInst->getParent(); assert(FromBB); + + assert(Loc.Ptr->getType()->isPointerTy() && + "Can't get pointer deps of a non-pointer!"); + Result.clear(); - // This routine does not expect to deal with volatile instructions. Doing so - // would require piping through the QueryInst all the way through. + // This routine does not expect to deal with volatile instructions. + // Doing so would require piping through the QueryInst all the way through. // TODO: volatiles can't be elided, but they can be reordered with other - // non-volatile accesses. - if (LoadInst *LI = dyn_cast(QueryInst)) { - assert(!LI->isVolatile()); - } else if (StoreInst *SI = dyn_cast(QueryInst)) { - assert(!SI->isVolatile()); - } - - + // non-volatile accesses. + auto isVolatile = [](Instruction *Inst) { + if (LoadInst *LI = dyn_cast(Inst)) { + return LI->isVolatile(); + } else if (StoreInst *SI = dyn_cast(Inst)) { + return SI->isVolatile(); + } + return false; + }; // We currently give up on any instruction which is ordered, but we do handle // atomic instructions which are unordered. // TODO: Handle ordered instructions @@ -904,11 +909,13 @@ getNonLocalPointerDependency(Instruction *QueryInst, } return false; }; - assert(!isOrdered(QueryInst) && "ordered instructions not expected"); + if (isVolatile(QueryInst) || isOrdered(QueryInst)) { + Result.push_back(NonLocalDepResult(FromBB, + MemDepResult::getUnknown(), + const_cast(Loc.Ptr))); + return; + } - assert(Loc.Ptr->getType()->isPointerTy() && - "Can't get pointer deps of a non-pointer!"); - Result.clear(); PHITransAddr Address(const_cast(Loc.Ptr), DL, AC); -- 2.34.1