Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
polly/trunk/lib/Support/ScopHelper.cpp
Show All 11 Lines | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "polly/Support/ScopHelper.h" | #include "polly/Support/ScopHelper.h" | ||||
#include "polly/Options.h" | #include "polly/Options.h" | ||||
#include "polly/ScopInfo.h" | #include "polly/ScopInfo.h" | ||||
#include "polly/Support/SCEVValidator.h" | #include "polly/Support/SCEVValidator.h" | ||||
#include "llvm/Analysis/LoopInfo.h" | #include "llvm/Analysis/LoopInfo.h" | ||||
#include "llvm/Analysis/RegionInfo.h" | #include "llvm/Analysis/RegionInfo.h" | ||||
#include "llvm/Analysis/RegionInfoImpl.h" | |||||
#include "llvm/Analysis/ScalarEvolution.h" | #include "llvm/Analysis/ScalarEvolution.h" | ||||
#include "llvm/Analysis/ScalarEvolutionExpander.h" | #include "llvm/Analysis/ScalarEvolutionExpander.h" | ||||
#include "llvm/Analysis/ScalarEvolutionExpressions.h" | #include "llvm/Analysis/ScalarEvolutionExpressions.h" | ||||
#include "llvm/IR/CFG.h" | #include "llvm/IR/CFG.h" | ||||
#include "llvm/IR/IntrinsicInst.h" | #include "llvm/IR/IntrinsicInst.h" | ||||
#include "llvm/Support/Debug.h" | #include "llvm/Support/Debug.h" | ||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h" | #include "llvm/Transforms/Utils/BasicBlockUtils.h" | ||||
▲ Show 20 Lines • Show All 420 Lines • ▼ Show 20 Lines | Value *polly::getConditionFromTerminator(TerminatorInst *TI) { | ||||
} | } | ||||
if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) | if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) | ||||
return SI->getCondition(); | return SI->getCondition(); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
static bool hasVariantIndex(GetElementPtrInst *Gep, Loop *L, Region &R, | |||||
ScalarEvolution &SE) { | |||||
for (const Use &Val : llvm::drop_begin(Gep->operands(), 1)) { | |||||
const SCEV *PtrSCEV = SE.getSCEVAtScope(Val, L); | |||||
Loop *OuterLoop = R.outermostLoopInRegion(L); | |||||
if (!SE.isLoopInvariant(PtrSCEV, OuterLoop)) | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
bool polly::isHoistableLoad(LoadInst *LInst, Region &R, LoopInfo &LI, | bool polly::isHoistableLoad(LoadInst *LInst, Region &R, LoopInfo &LI, | ||||
ScalarEvolution &SE, const DominatorTree &DT) { | ScalarEvolution &SE, const DominatorTree &DT, | ||||
const InvariantLoadsSetTy &KnownInvariantLoads) { | |||||
Loop *L = LI.getLoopFor(LInst->getParent()); | Loop *L = LI.getLoopFor(LInst->getParent()); | ||||
auto *Ptr = LInst->getPointerOperand(); | auto *Ptr = LInst->getPointerOperand(); | ||||
// A LoadInst is hoistable if the address it is loading from is also | |||||
// invariant; in this case: another invariant load (whether that address | |||||
// is also not written to has to be checked separately) | |||||
// TODO: This only checks for a LoadInst->GetElementPtrInst->LoadInst | |||||
// pattern generated by the Chapel frontend, but generally this applies | |||||
// for any chain of instruction that does not also depend on any | |||||
// induction variable | |||||
if (auto *GepInst = dyn_cast<GetElementPtrInst>(Ptr)) { | |||||
if (!hasVariantIndex(GepInst, L, R, SE)) { | |||||
if (auto *DecidingLoad = | |||||
dyn_cast<LoadInst>(GepInst->getPointerOperand())) { | |||||
if (KnownInvariantLoads.count(DecidingLoad)) | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
const SCEV *PtrSCEV = SE.getSCEVAtScope(Ptr, L); | const SCEV *PtrSCEV = SE.getSCEVAtScope(Ptr, L); | ||||
while (L && R.contains(L)) { | while (L && R.contains(L)) { | ||||
if (!SE.isLoopInvariant(PtrSCEV, L)) | if (!SE.isLoopInvariant(PtrSCEV, L)) | ||||
return false; | return false; | ||||
L = L->getParentLoop(); | L = L->getParentLoop(); | ||||
} | } | ||||
for (auto *User : Ptr->users()) { | for (auto *User : Ptr->users()) { | ||||
▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines |