forked from OSchip/llvm-project
New pass manager for LICM.
Summary: Port LICM to the new pass manager. Reviewers: davidxl, silvas Subscribers: silvas, davide, sanjoy, llvm-commits, mehdi_amini Differential Revision: http://reviews.llvm.org/D21772 llvm-svn: 275118
This commit is contained in:
parent
cbc6ac2afd
commit
7ef5820fa3
|
@ -159,7 +159,7 @@ void initializeInternalizeLegacyPassPass(PassRegistry&);
|
||||||
void initializeIntervalPartitionPass(PassRegistry&);
|
void initializeIntervalPartitionPass(PassRegistry&);
|
||||||
void initializeJumpThreadingPass(PassRegistry&);
|
void initializeJumpThreadingPass(PassRegistry&);
|
||||||
void initializeLCSSAWrapperPassPass(PassRegistry &);
|
void initializeLCSSAWrapperPassPass(PassRegistry &);
|
||||||
void initializeLICMPass(PassRegistry&);
|
void initializeLegacyLICMPassPass(PassRegistry&);
|
||||||
void initializeLazyValueInfoWrapperPassPass(PassRegistry&);
|
void initializeLazyValueInfoWrapperPassPass(PassRegistry&);
|
||||||
void initializeLintPass(PassRegistry&);
|
void initializeLintPass(PassRegistry&);
|
||||||
void initializeLiveDebugValuesPass(PassRegistry&);
|
void initializeLiveDebugValuesPass(PassRegistry&);
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
//===- LICM.h - Loop Invariant Code Motion Pass -------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// The LLVM Compiler Infrastructure
|
||||||
|
//
|
||||||
|
// This file is distributed under the University of Illinois Open Source
|
||||||
|
// License. See LICENSE.TXT for details.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
//
|
||||||
|
// This pass performs loop invariant code motion, attempting to remove as much
|
||||||
|
// code from the body of a loop as possible. It does this by either hoisting
|
||||||
|
// code into the preheader block, or by sinking code to the exit blocks if it is
|
||||||
|
// safe. This pass also promotes must-aliased memory locations in the loop to
|
||||||
|
// live in registers, thus hoisting and sinking "invariant" loads and stores.
|
||||||
|
//
|
||||||
|
// This pass uses alias analysis for two purposes:
|
||||||
|
//
|
||||||
|
// 1. Moving loop invariant loads and calls out of loops. If we can determine
|
||||||
|
// that a load or call inside of a loop never aliases anything stored to,
|
||||||
|
// we can hoist it or sink it like any other instruction.
|
||||||
|
// 2. Scalar Promotion of Memory - If there is a store instruction inside of
|
||||||
|
// the loop, we try to move the store to happen AFTER the loop instead of
|
||||||
|
// inside of the loop. This can only happen if a few conditions are true:
|
||||||
|
// A. The pointer stored through is loop invariant
|
||||||
|
// B. There are no stores or loads in the loop which _may_ alias the
|
||||||
|
// pointer. There are no calls in the loop which mod/ref the pointer.
|
||||||
|
// If these conditions are true, we can promote the loads and stores in the
|
||||||
|
// loop of the pointer to use a temporary alloca'd variable. We then use
|
||||||
|
// the SSAUpdater to construct the appropriate SSA form for the value.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_TRANSFORMS_SCALAR_LICM_H
|
||||||
|
#define LLVM_TRANSFORMS_SCALAR_LICM_H
|
||||||
|
|
||||||
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
|
#include "llvm/IR/PassManager.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
/// Performs Loop Invariant Code Motion Pass.
|
||||||
|
class LICMPass : public PassInfoMixin<LICMPass> {
|
||||||
|
public:
|
||||||
|
PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM);
|
||||||
|
};
|
||||||
|
} // end namespace llvm
|
||||||
|
|
||||||
|
#endif // LLVM_TRANSFORMS_SCALAR_LICM_H
|
|
@ -122,7 +122,7 @@ void LTOCodeGenerator::initializeLTOPasses() {
|
||||||
initializePostOrderFunctionAttrsLegacyPassPass(R);
|
initializePostOrderFunctionAttrsLegacyPassPass(R);
|
||||||
initializeReversePostOrderFunctionAttrsLegacyPassPass(R);
|
initializeReversePostOrderFunctionAttrsLegacyPassPass(R);
|
||||||
initializeGlobalsAAWrapperPassPass(R);
|
initializeGlobalsAAWrapperPassPass(R);
|
||||||
initializeLICMPass(R);
|
initializeLegacyLICMPassPass(R);
|
||||||
initializeMergedLoadStoreMotionLegacyPassPass(R);
|
initializeMergedLoadStoreMotionLegacyPassPass(R);
|
||||||
initializeGVNLegacyPassPass(R);
|
initializeGVNLegacyPassPass(R);
|
||||||
initializeMemCpyOptLegacyPassPass(R);
|
initializeMemCpyOptLegacyPassPass(R);
|
||||||
|
|
|
@ -88,6 +88,7 @@
|
||||||
#include "llvm/Transforms/Scalar/GuardWidening.h"
|
#include "llvm/Transforms/Scalar/GuardWidening.h"
|
||||||
#include "llvm/Transforms/Scalar/IndVarSimplify.h"
|
#include "llvm/Transforms/Scalar/IndVarSimplify.h"
|
||||||
#include "llvm/Transforms/Scalar/JumpThreading.h"
|
#include "llvm/Transforms/Scalar/JumpThreading.h"
|
||||||
|
#include "llvm/Transforms/Scalar/LICM.h"
|
||||||
#include "llvm/Transforms/Scalar/LoopRotation.h"
|
#include "llvm/Transforms/Scalar/LoopRotation.h"
|
||||||
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
|
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
|
||||||
#include "llvm/Transforms/Scalar/LowerAtomic.h"
|
#include "llvm/Transforms/Scalar/LowerAtomic.h"
|
||||||
|
|
|
@ -187,6 +187,7 @@ LOOP_ANALYSIS("access-info", LoopAccessAnalysis())
|
||||||
#define LOOP_PASS(NAME, CREATE_PASS)
|
#define LOOP_PASS(NAME, CREATE_PASS)
|
||||||
#endif
|
#endif
|
||||||
LOOP_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
LOOP_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
||||||
|
LOOP_PASS("licm", LICMPass())
|
||||||
LOOP_PASS("rotate", LoopRotatePass())
|
LOOP_PASS("rotate", LoopRotatePass())
|
||||||
LOOP_PASS("no-op-loop", NoOpLoopPass())
|
LOOP_PASS("no-op-loop", NoOpLoopPass())
|
||||||
LOOP_PASS("print", PrintLoopPass(dbgs()))
|
LOOP_PASS("print", PrintLoopPass(dbgs()))
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/Transforms/Scalar/LICM.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/AliasSetTracker.h"
|
#include "llvm/Analysis/AliasSetTracker.h"
|
||||||
|
@ -40,6 +41,7 @@
|
||||||
#include "llvm/Analysis/Loads.h"
|
#include "llvm/Analysis/Loads.h"
|
||||||
#include "llvm/Analysis/LoopInfo.h"
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
#include "llvm/Analysis/LoopPass.h"
|
#include "llvm/Analysis/LoopPass.h"
|
||||||
|
#include "llvm/Analysis/LoopPassManager.h"
|
||||||
#include "llvm/Analysis/MemoryBuiltins.h"
|
#include "llvm/Analysis/MemoryBuiltins.h"
|
||||||
#include "llvm/Analysis/ScalarEvolution.h"
|
#include "llvm/Analysis/ScalarEvolution.h"
|
||||||
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
||||||
|
@ -104,13 +106,39 @@ static bool canSinkOrHoistInst(Instruction &I, AliasAnalysis *AA,
|
||||||
LoopSafetyInfo *SafetyInfo);
|
LoopSafetyInfo *SafetyInfo);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct LICM : public LoopPass {
|
struct LoopInvariantCodeMotion {
|
||||||
static char ID; // Pass identification, replacement for typeid
|
bool runOnLoop(Loop *L, AliasAnalysis *AA, LoopInfo *LI, DominatorTree *DT,
|
||||||
LICM() : LoopPass(ID) {
|
TargetLibraryInfo *TLI, ScalarEvolution *SE);
|
||||||
initializeLICMPass(*PassRegistry::getPassRegistry());
|
|
||||||
|
DenseMap<Loop *, AliasSetTracker *> &getLoopToAliasSetMap() {
|
||||||
|
return LoopToAliasSetMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool runOnLoop(Loop *L, LPPassManager &LPM) override;
|
private:
|
||||||
|
DenseMap<Loop *, AliasSetTracker *> LoopToAliasSetMap;
|
||||||
|
|
||||||
|
AliasSetTracker *collectAliasInfoForLoop(Loop *L, LoopInfo *LI,
|
||||||
|
AliasAnalysis *AA);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct LegacyLICMPass : public LoopPass {
|
||||||
|
static char ID; // Pass identification, replacement for typeid
|
||||||
|
LegacyLICMPass() : LoopPass(ID) {
|
||||||
|
initializeLegacyLICMPassPass(*PassRegistry::getPassRegistry());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool runOnLoop(Loop *L, LPPassManager &LPM) override {
|
||||||
|
if (skipLoop(L))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto *SE = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
|
||||||
|
return LICM.runOnLoop(L,
|
||||||
|
&getAnalysis<AAResultsWrapperPass>().getAAResults(),
|
||||||
|
&getAnalysis<LoopInfoWrapperPass>().getLoopInfo(),
|
||||||
|
&getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
|
||||||
|
&getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(),
|
||||||
|
SE ? &SE->getSE() : nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
/// This transformation requires natural loop information & requires that
|
/// This transformation requires natural loop information & requires that
|
||||||
/// loop preheaders be inserted into the CFG...
|
/// loop preheaders be inserted into the CFG...
|
||||||
|
@ -124,23 +152,13 @@ struct LICM : public LoopPass {
|
||||||
using llvm::Pass::doFinalization;
|
using llvm::Pass::doFinalization;
|
||||||
|
|
||||||
bool doFinalization() override {
|
bool doFinalization() override {
|
||||||
assert(LoopToAliasSetMap.empty() && "Didn't free loop alias sets");
|
assert(LICM.getLoopToAliasSetMap().empty() &&
|
||||||
|
"Didn't free loop alias sets");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AliasAnalysis *AA; // Current AliasAnalysis information
|
LoopInvariantCodeMotion LICM;
|
||||||
LoopInfo *LI; // Current LoopInfo
|
|
||||||
DominatorTree *DT; // Dominator Tree for the current Loop.
|
|
||||||
|
|
||||||
TargetLibraryInfo *TLI; // TargetLibraryInfo for constant folding.
|
|
||||||
|
|
||||||
// State that is updated as we process loops.
|
|
||||||
bool Changed; // Set to true when we change anything.
|
|
||||||
BasicBlock *Preheader; // The preheader block of the current loop...
|
|
||||||
Loop *CurLoop; // The current loop we are working on...
|
|
||||||
AliasSetTracker *CurAST; // AliasSet information for the current loop...
|
|
||||||
DenseMap<Loop *, AliasSetTracker *> LoopToAliasSetMap;
|
|
||||||
|
|
||||||
/// cloneBasicBlockAnalysis - Simple Analysis hook. Clone alias set info.
|
/// cloneBasicBlockAnalysis - Simple Analysis hook. Clone alias set info.
|
||||||
void cloneBasicBlockAnalysis(BasicBlock *From, BasicBlock *To,
|
void cloneBasicBlockAnalysis(BasicBlock *From, BasicBlock *To,
|
||||||
|
@ -152,48 +170,63 @@ private:
|
||||||
|
|
||||||
/// Simple Analysis hook. Delete loop L from alias set map.
|
/// Simple Analysis hook. Delete loop L from alias set map.
|
||||||
void deleteAnalysisLoop(Loop *L) override;
|
void deleteAnalysisLoop(Loop *L) override;
|
||||||
|
|
||||||
AliasSetTracker *collectAliasInfoForLoop(Loop *L);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
char LICM::ID = 0;
|
PreservedAnalyses LICMPass::run(Loop &L, AnalysisManager<Loop> &AM) {
|
||||||
INITIALIZE_PASS_BEGIN(LICM, "licm", "Loop Invariant Code Motion", false, false)
|
// FIXME: Check if loop should be skipped.
|
||||||
|
|
||||||
|
const auto &FAM =
|
||||||
|
AM.getResult<FunctionAnalysisManagerLoopProxy>(L).getManager();
|
||||||
|
Function *F = L.getHeader()->getParent();
|
||||||
|
|
||||||
|
auto *AA = FAM.getCachedResult<AAManager>(*F);
|
||||||
|
auto *LI = FAM.getCachedResult<LoopAnalysis>(*F);
|
||||||
|
auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
|
||||||
|
auto *TLI = FAM.getCachedResult<TargetLibraryAnalysis>(*F);
|
||||||
|
auto *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
|
||||||
|
assert((AA && LI && DT && TLI && SE) && "Analyses for LICM not available");
|
||||||
|
|
||||||
|
LoopInvariantCodeMotion LICM;
|
||||||
|
|
||||||
|
if (!LICM.runOnLoop(&L, AA, LI, DT, TLI, SE))
|
||||||
|
return PreservedAnalyses::all();
|
||||||
|
|
||||||
|
// FIXME: There is no setPreservesCFG in the new PM. When that becomes
|
||||||
|
// available, it should be used here.
|
||||||
|
return getLoopPassPreservedAnalyses();
|
||||||
|
}
|
||||||
|
|
||||||
|
char LegacyLICMPass::ID = 0;
|
||||||
|
INITIALIZE_PASS_BEGIN(LegacyLICMPass, "licm", "Loop Invariant Code Motion",
|
||||||
|
false, false)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopPass)
|
INITIALIZE_PASS_DEPENDENCY(LoopPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||||
INITIALIZE_PASS_END(LICM, "licm", "Loop Invariant Code Motion", false, false)
|
INITIALIZE_PASS_END(LegacyLICMPass, "licm", "Loop Invariant Code Motion", false,
|
||||||
|
false)
|
||||||
|
|
||||||
Pass *llvm::createLICMPass() { return new LICM(); }
|
Pass *llvm::createLICMPass() { return new LegacyLICMPass(); }
|
||||||
|
|
||||||
/// Hoist expressions out of the specified loop. Note, alias info for inner
|
/// Hoist expressions out of the specified loop. Note, alias info for inner
|
||||||
/// loop is not preserved so it is not a good idea to run LICM multiple
|
/// loop is not preserved so it is not a good idea to run LICM multiple
|
||||||
/// times on one loop.
|
/// times on one loop.
|
||||||
///
|
///
|
||||||
bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AliasAnalysis *AA,
|
||||||
if (skipLoop(L))
|
LoopInfo *LI, DominatorTree *DT,
|
||||||
return false;
|
TargetLibraryInfo *TLI,
|
||||||
|
ScalarEvolution *SE) {
|
||||||
Changed = false;
|
bool Changed = false;
|
||||||
|
|
||||||
// Get our Loop and Alias Analysis information...
|
|
||||||
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
|
||||||
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
|
||||||
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
|
||||||
|
|
||||||
TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
|
||||||
|
|
||||||
assert(L->isLCSSAForm(*DT) && "Loop is not in LCSSA form.");
|
assert(L->isLCSSAForm(*DT) && "Loop is not in LCSSA form.");
|
||||||
|
|
||||||
CurAST = collectAliasInfoForLoop(L);
|
AliasSetTracker *CurAST = collectAliasInfoForLoop(L, LI, AA);
|
||||||
|
|
||||||
CurLoop = L;
|
|
||||||
|
|
||||||
// Get the preheader block to move instructions into...
|
// Get the preheader block to move instructions into...
|
||||||
Preheader = L->getLoopPreheader();
|
BasicBlock *Preheader = L->getLoopPreheader();
|
||||||
|
|
||||||
// Compute loop safety information.
|
// Compute loop safety information.
|
||||||
LoopSafetyInfo SafetyInfo;
|
LoopSafetyInfo SafetyInfo;
|
||||||
computeLoopSafetyInfo(&SafetyInfo, CurLoop);
|
computeLoopSafetyInfo(&SafetyInfo, L);
|
||||||
|
|
||||||
// We want to visit all of the instructions in this loop... that are not parts
|
// We want to visit all of the instructions in this loop... that are not parts
|
||||||
// of our subloops (they have already had their invariants hoisted out of
|
// of our subloops (they have already had their invariants hoisted out of
|
||||||
|
@ -206,11 +239,11 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
// instructions, we perform another pass to hoist them out of the loop.
|
// instructions, we perform another pass to hoist them out of the loop.
|
||||||
//
|
//
|
||||||
if (L->hasDedicatedExits())
|
if (L->hasDedicatedExits())
|
||||||
Changed |= sinkRegion(DT->getNode(L->getHeader()), AA, LI, DT, TLI, CurLoop,
|
Changed |= sinkRegion(DT->getNode(L->getHeader()), AA, LI, DT, TLI, L,
|
||||||
CurAST, &SafetyInfo);
|
CurAST, &SafetyInfo);
|
||||||
if (Preheader)
|
if (Preheader)
|
||||||
Changed |= hoistRegion(DT->getNode(L->getHeader()), AA, LI, DT, TLI,
|
Changed |= hoistRegion(DT->getNode(L->getHeader()), AA, LI, DT, TLI, L,
|
||||||
CurLoop, CurAST, &SafetyInfo);
|
CurAST, &SafetyInfo);
|
||||||
|
|
||||||
// Now that all loop invariants have been removed from the loop, promote any
|
// Now that all loop invariants have been removed from the loop, promote any
|
||||||
// memory references to scalars that we can.
|
// memory references to scalars that we can.
|
||||||
|
@ -221,9 +254,8 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
|
|
||||||
// Loop over all of the alias sets in the tracker object.
|
// Loop over all of the alias sets in the tracker object.
|
||||||
for (AliasSet &AS : *CurAST)
|
for (AliasSet &AS : *CurAST)
|
||||||
Changed |=
|
Changed |= promoteLoopAccessesToScalars(
|
||||||
promoteLoopAccessesToScalars(AS, ExitBlocks, InsertPts, PIC, LI, DT,
|
AS, ExitBlocks, InsertPts, PIC, LI, DT, TLI, L, CurAST, &SafetyInfo);
|
||||||
TLI, CurLoop, CurAST, &SafetyInfo);
|
|
||||||
|
|
||||||
// Once we have promoted values across the loop body we have to recursively
|
// Once we have promoted values across the loop body we have to recursively
|
||||||
// reform LCSSA as any nested loop may now have values defined within the
|
// reform LCSSA as any nested loop may now have values defined within the
|
||||||
|
@ -232,8 +264,7 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
// SSAUpdater strategy during promotion that was LCSSA aware and reformed
|
// SSAUpdater strategy during promotion that was LCSSA aware and reformed
|
||||||
// it as it went.
|
// it as it went.
|
||||||
if (Changed) {
|
if (Changed) {
|
||||||
auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
|
formLCSSARecursively(*L, *DT, LI, SE);
|
||||||
formLCSSARecursively(*L, *DT, LI, SEWP ? &SEWP->getSE() : nullptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,10 +275,6 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
assert((!L->getParentLoop() || L->getParentLoop()->isLCSSAForm(*DT)) &&
|
assert((!L->getParentLoop() || L->getParentLoop()->isLCSSAForm(*DT)) &&
|
||||||
"Parent loop not left in LCSSA form after LICM!");
|
"Parent loop not left in LCSSA form after LICM!");
|
||||||
|
|
||||||
// Clear out loops state information for the next iteration
|
|
||||||
CurLoop = nullptr;
|
|
||||||
Preheader = nullptr;
|
|
||||||
|
|
||||||
// If this loop is nested inside of another one, save the alias information
|
// If this loop is nested inside of another one, save the alias information
|
||||||
// for when we process the outer loop.
|
// for when we process the outer loop.
|
||||||
if (L->getParentLoop())
|
if (L->getParentLoop())
|
||||||
|
@ -255,9 +282,8 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
else
|
else
|
||||||
delete CurAST;
|
delete CurAST;
|
||||||
|
|
||||||
if (Changed)
|
if (Changed && SE)
|
||||||
if (auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>())
|
SE->forgetLoopDispositions(L);
|
||||||
SEWP->getSE().forgetLoopDispositions(L);
|
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +413,8 @@ void llvm::computeLoopSafetyInfo(LoopSafetyInfo *SafetyInfo, Loop *CurLoop) {
|
||||||
// Iterate over header and compute safety info.
|
// Iterate over header and compute safety info.
|
||||||
for (BasicBlock::iterator I = Header->begin(), E = Header->end();
|
for (BasicBlock::iterator I = Header->begin(), E = Header->end();
|
||||||
(I != E) && !SafetyInfo->HeaderMayThrow; ++I)
|
(I != E) && !SafetyInfo->HeaderMayThrow; ++I)
|
||||||
SafetyInfo->HeaderMayThrow |= !isGuaranteedToTransferExecutionToSuccessor(&*I);
|
SafetyInfo->HeaderMayThrow |=
|
||||||
|
!isGuaranteedToTransferExecutionToSuccessor(&*I);
|
||||||
|
|
||||||
SafetyInfo->MayThrow = SafetyInfo->HeaderMayThrow;
|
SafetyInfo->MayThrow = SafetyInfo->HeaderMayThrow;
|
||||||
// Iterate over loop instructions and compute safety info.
|
// Iterate over loop instructions and compute safety info.
|
||||||
|
@ -1042,7 +1069,13 @@ bool llvm::promoteLoopAccessesToScalars(
|
||||||
|
|
||||||
/// Returns an owning pointer to an alias set which incorporates aliasing info
|
/// Returns an owning pointer to an alias set which incorporates aliasing info
|
||||||
/// from L and all subloops of L.
|
/// from L and all subloops of L.
|
||||||
AliasSetTracker *LICM::collectAliasInfoForLoop(Loop *L) {
|
/// FIXME: In new pass manager, there is no helper functions to handle loop
|
||||||
|
/// analysis such as cloneBasicBlockAnalysis. So the AST needs to be recompute
|
||||||
|
/// from scratch for every loop. Hook up with the helper functions when
|
||||||
|
/// available in the new pass manager to avoid redundant computation.
|
||||||
|
AliasSetTracker *
|
||||||
|
LoopInvariantCodeMotion::collectAliasInfoForLoop(Loop *L, LoopInfo *LI,
|
||||||
|
AliasAnalysis *AA) {
|
||||||
AliasSetTracker *CurAST = nullptr;
|
AliasSetTracker *CurAST = nullptr;
|
||||||
SmallVector<Loop *, 4> RecomputeLoops;
|
SmallVector<Loop *, 4> RecomputeLoops;
|
||||||
for (Loop *InnerL : L->getSubLoops()) {
|
for (Loop *InnerL : L->getSubLoops()) {
|
||||||
|
@ -1092,8 +1125,9 @@ AliasSetTracker *LICM::collectAliasInfoForLoop(Loop *L) {
|
||||||
|
|
||||||
/// Simple analysis hook. Clone alias set info.
|
/// Simple analysis hook. Clone alias set info.
|
||||||
///
|
///
|
||||||
void LICM::cloneBasicBlockAnalysis(BasicBlock *From, BasicBlock *To, Loop *L) {
|
void LegacyLICMPass::cloneBasicBlockAnalysis(BasicBlock *From, BasicBlock *To,
|
||||||
AliasSetTracker *AST = LoopToAliasSetMap.lookup(L);
|
Loop *L) {
|
||||||
|
AliasSetTracker *AST = LICM.getLoopToAliasSetMap().lookup(L);
|
||||||
if (!AST)
|
if (!AST)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1102,8 +1136,8 @@ void LICM::cloneBasicBlockAnalysis(BasicBlock *From, BasicBlock *To, Loop *L) {
|
||||||
|
|
||||||
/// Simple Analysis hook. Delete value V from alias set
|
/// Simple Analysis hook. Delete value V from alias set
|
||||||
///
|
///
|
||||||
void LICM::deleteAnalysisValue(Value *V, Loop *L) {
|
void LegacyLICMPass::deleteAnalysisValue(Value *V, Loop *L) {
|
||||||
AliasSetTracker *AST = LoopToAliasSetMap.lookup(L);
|
AliasSetTracker *AST = LICM.getLoopToAliasSetMap().lookup(L);
|
||||||
if (!AST)
|
if (!AST)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1112,13 +1146,13 @@ void LICM::deleteAnalysisValue(Value *V, Loop *L) {
|
||||||
|
|
||||||
/// Simple Analysis hook. Delete value L from alias set map.
|
/// Simple Analysis hook. Delete value L from alias set map.
|
||||||
///
|
///
|
||||||
void LICM::deleteAnalysisLoop(Loop *L) {
|
void LegacyLICMPass::deleteAnalysisLoop(Loop *L) {
|
||||||
AliasSetTracker *AST = LoopToAliasSetMap.lookup(L);
|
AliasSetTracker *AST = LICM.getLoopToAliasSetMap().lookup(L);
|
||||||
if (!AST)
|
if (!AST)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete AST;
|
delete AST;
|
||||||
LoopToAliasSetMap.erase(L);
|
LICM.getLoopToAliasSetMap().erase(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if the body of this loop may store into the memory
|
/// Return true if the body of this loop may store into the memory
|
||||||
|
|
|
@ -48,7 +48,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
||||||
initializeInductiveRangeCheckEliminationPass(Registry);
|
initializeInductiveRangeCheckEliminationPass(Registry);
|
||||||
initializeIndVarSimplifyLegacyPassPass(Registry);
|
initializeIndVarSimplifyLegacyPassPass(Registry);
|
||||||
initializeJumpThreadingPass(Registry);
|
initializeJumpThreadingPass(Registry);
|
||||||
initializeLICMPass(Registry);
|
initializeLegacyLICMPassPass(Registry);
|
||||||
initializeLoopDataPrefetchPass(Registry);
|
initializeLoopDataPrefetchPass(Registry);
|
||||||
initializeLoopDeletionPass(Registry);
|
initializeLoopDeletionPass(Registry);
|
||||||
initializeLoopAccessLegacyAnalysisPass(Registry);
|
initializeLoopAccessLegacyAnalysisPass(Registry);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -basicaa -licm %s | FileCheck %s
|
; RUN: opt -S -basicaa -licm %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
|
||||||
declare i32 @foo() readonly argmemonly nounwind
|
declare i32 @foo() readonly argmemonly nounwind
|
||||||
declare i32 @foo2() readonly nounwind
|
declare i32 @foo2() readonly nounwind
|
||||||
declare i32 @bar(i32* %loc2) readonly argmemonly nounwind
|
declare i32 @bar(i32* %loc2) readonly argmemonly nounwind
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -licm -basicaa < %s -S | FileCheck %s
|
; RUN: opt -licm -basicaa < %s -S | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
|
||||||
|
|
||||||
define void @f_0(i1 %p) nounwind ssp {
|
define void @f_0(i1 %p) nounwind ssp {
|
||||||
; CHECK-LABEL: @f_0(
|
; CHECK-LABEL: @f_0(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -S -basicaa -licm | FileCheck %s
|
; RUN: opt < %s -S -basicaa -licm | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='lcssa,require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
|
||||||
|
|
||||||
; Check that we can hoist unordered loads
|
; Check that we can hoist unordered loads
|
||||||
define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
|
define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -licm | llvm-dis
|
; RUN: opt < %s -licm | llvm-dis
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s | llvm-dis
|
||||||
|
|
||||||
define void @testfunc(i32 %i) {
|
define void @testfunc(i32 %i) {
|
||||||
; <label>:0
|
; <label>:0
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -S -basicaa -licm | FileCheck %s
|
; RUN: opt < %s -S -basicaa -licm | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='lcssa,require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
|
||||||
; This fixes PR22460
|
; This fixes PR22460
|
||||||
|
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -licm -disable-output < %s
|
; RUN: opt -licm -disable-output < %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -disable-output < %s
|
||||||
|
|
||||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
||||||
target triple = "x86_64-apple-darwin10.0.0"
|
target triple = "x86_64-apple-darwin10.0.0"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -licm -basicaa < %s -S | FileCheck %s
|
; RUN: opt -licm -basicaa < %s -S | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
|
||||||
|
|
||||||
define void @dgefa() nounwind ssp {
|
define void @dgefa() nounwind ssp {
|
||||||
entry:
|
entry:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -licm -S | FileCheck %s
|
; RUN: opt < %s -licm -S | FileCheck %s
|
||||||
|
; RUN: opt -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
|
||||||
; PR19835
|
; PR19835
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -licm -S | FileCheck %s
|
; RUN: opt < %s -licm -S | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
|
||||||
|
|
||||||
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
|
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
|
||||||
target triple = "i386-pc-windows-msvc18.0.0"
|
target triple = "i386-pc-windows-msvc18.0.0"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='loop-simplify,require<aa>,require<targetir>,require<scalar-evolution>,loop(simplify-cfg,licm)' -S < %s | FileCheck %s
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='loop-simplify,require<aa>,require<targetir>,require<scalar-evolution>,loop(simplify-cfg,licm)' -S < %s | FileCheck %s
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='lcssa,require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -licm < %s | FileCheck %s
|
; RUN: opt -S -licm < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
|
|
||||||
target datalayout = "E-m:e-p:32:32-i8:8:8-i16:16:16-i64:32:32-f64:32:32-v64:32:32-v128:32:32-a0:0:32-n32"
|
target datalayout = "E-m:e-p:32:32-i8:8:8-i16:16:16-i64:32:32-f64:32:32-v64:32:32-v128:32:32-a0:0:32-n32"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -licm -S | FileCheck %s
|
; RUN: opt < %s -licm -S | FileCheck %s
|
||||||
|
; RUN: opt -lcssa %s | opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S | FileCheck %s
|
||||||
|
|
||||||
@X = global i32 0 ; <i32*> [#uses=1]
|
@X = global i32 0 ; <i32*> [#uses=1]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s| FileCheck %s
|
||||||
;
|
;
|
||||||
; Manually validate LCSSA form is preserved even after SSAUpdater is used to
|
; Manually validate LCSSA form is preserved even after SSAUpdater is used to
|
||||||
; promote things in the loop bodies.
|
; promote things in the loop bodies.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
; Test that LICM works when there is not a loop-preheader
|
; Test that LICM works when there is not a loop-preheader
|
||||||
; RUN: opt < %s -licm | llvm-dis
|
; RUN: opt < %s -licm | llvm-dis
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s | llvm-dis
|
||||||
|
|
||||||
define void @testfunc(i32 %i.s, i1 %ifcond) {
|
define void @testfunc(i32 %i.s, i1 %ifcond) {
|
||||||
br i1 %ifcond, label %Then, label %Else
|
br i1 %ifcond, label %Then, label %Else
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -licm < %s | FileCheck %s
|
; RUN: opt -S -licm < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
|
|
||||||
declare void @use_nothrow(i64 %a) nounwind
|
declare void @use_nothrow(i64 %a) nounwind
|
||||||
declare void @use(i64 %a)
|
declare void @use(i64 %a)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -tbaa -basicaa -licm -S < %s | FileCheck %s
|
; RUN: opt -tbaa -basicaa -licm -S < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=type-based-aa,basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
|
|
||||||
; LICM should keep the stores in their original order when it sinks/promotes them.
|
; LICM should keep the stores in their original order when it sinks/promotes them.
|
||||||
; rdar://12045203
|
; rdar://12045203
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -tbaa -basicaa -licm -S < %s | FileCheck %s
|
; RUN: opt -tbaa -basicaa -licm -S < %s | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=type-based-aa,basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
|
|
||||||
; If we can prove a local is thread local, we can insert stores during
|
; If we can prove a local is thread local, we can insert stores during
|
||||||
; promotion which wouldn't be legal otherwise.
|
; promotion which wouldn't be legal otherwise.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -basicaa -licm -S | FileCheck %s
|
; RUN: opt < %s -basicaa -licm -S | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=type-based-aa,basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
|
|
||||||
; Make sure we don't hoist a conditionally-executed store out of the loop;
|
; Make sure we don't hoist a conditionally-executed store out of the loop;
|
||||||
; it would violate the concurrency memory model
|
; it would violate the concurrency memory model
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -basicaa -licm -S | FileCheck %s
|
; RUN: opt < %s -basicaa -licm -S | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
|
|
||||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -basicaa -tbaa -licm -S | FileCheck %s
|
; RUN: opt < %s -basicaa -tbaa -licm -S | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=type-based-aa,basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
|
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
|
||||||
|
|
||||||
@X = global i32 7 ; <i32*> [#uses=4]
|
@X = global i32 7 ; <i32*> [#uses=4]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -S -licm < %s | FileCheck %s
|
; RUN: opt -S -licm < %s | FileCheck %s
|
||||||
|
; RUN: opt -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
||||||
|
|
||||||
; UDiv is safe to speculate if the denominator is known non-zero.
|
; UDiv is safe to speculate if the denominator is known non-zero.
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -basicaa -sroa -loop-rotate -licm -S < %s | FileCheck %s
|
; RUN: opt -basicaa -sroa -loop-rotate -licm -S < %s | FileCheck %s
|
||||||
|
; RUN: opt -basicaa -sroa -loop-rotate %s | opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S | FileCheck %s
|
||||||
; The objects *p and *q are aliased to each other, but even though *q is
|
; The objects *p and *q are aliased to each other, but even though *q is
|
||||||
; volatile, *p can be considered invariant in the loop. Check if it is moved
|
; volatile, *p can be considered invariant in the loop. Check if it is moved
|
||||||
; out of the loop.
|
; out of the loop.
|
||||||
|
|
Loading…
Reference in New Issue