mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
Revert r343308: [LoopInterchange] Turn into a loop pass.
llvm-svn: 343310
This commit is contained in:
parent
6e2559695c
commit
bdb732a3d8
@ -375,9 +375,11 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
|
||||
addExtensionsToPM(EP_LateLoopOptimizations, MPM);
|
||||
MPM.add(createLoopDeletionPass()); // Delete dead loops
|
||||
|
||||
if (EnableLoopInterchange)
|
||||
if (EnableLoopInterchange) {
|
||||
// FIXME: These are function passes and break the loop pass pipeline.
|
||||
MPM.add(createLoopInterchangePass()); // Interchange loops
|
||||
|
||||
MPM.add(createCFGSimplificationPass());
|
||||
}
|
||||
if (!DisableUnrollLoops)
|
||||
MPM.add(createSimpleLoopUnrollPass(OptLevel)); // Unroll small loops
|
||||
addExtensionsToPM(EP_LoopOptimizerEnd, MPM);
|
||||
|
@ -17,9 +17,9 @@
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Analysis/AliasAnalysis.h"
|
||||
#include "llvm/Analysis/DependenceAnalysis.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/Analysis/LoopPass.h"
|
||||
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
|
||||
#include "llvm/Analysis/ScalarEvolution.h"
|
||||
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
|
||||
@ -271,7 +271,7 @@ static bool isLegalToInterChangeLoops(CharMatrix &DepMatrix,
|
||||
return true;
|
||||
}
|
||||
|
||||
static LoopVector populateWorklist(Loop &L) {
|
||||
static void populateWorklist(Loop &L, SmallVector<LoopVector, 8> &V) {
|
||||
LLVM_DEBUG(dbgs() << "Calling populateWorklist on Func: "
|
||||
<< L.getHeader()->getParent()->getName() << " Loop: %"
|
||||
<< L.getHeader()->getName() << '\n');
|
||||
@ -282,15 +282,16 @@ static LoopVector populateWorklist(Loop &L) {
|
||||
// The current loop has multiple subloops in it hence it is not tightly
|
||||
// nested.
|
||||
// Discard all loops above it added into Worklist.
|
||||
if (Vec->size() != 1)
|
||||
return {};
|
||||
|
||||
if (Vec->size() != 1) {
|
||||
LoopList.clear();
|
||||
return;
|
||||
}
|
||||
LoopList.push_back(CurrentLoop);
|
||||
CurrentLoop = Vec->front();
|
||||
Vec = &CurrentLoop->getSubLoops();
|
||||
}
|
||||
LoopList.push_back(CurrentLoop);
|
||||
return LoopList;
|
||||
V.push_back(std::move(LoopList));
|
||||
}
|
||||
|
||||
static PHINode *getInductionVariable(Loop *L, ScalarEvolution *SE) {
|
||||
@ -424,7 +425,7 @@ private:
|
||||
};
|
||||
|
||||
// Main LoopInterchange Pass.
|
||||
struct LoopInterchange : public LoopPass {
|
||||
struct LoopInterchange : public FunctionPass {
|
||||
static char ID;
|
||||
ScalarEvolution *SE = nullptr;
|
||||
LoopInfo *LI = nullptr;
|
||||
@ -435,27 +436,50 @@ struct LoopInterchange : public LoopPass {
|
||||
/// Interface to emit optimization remarks.
|
||||
OptimizationRemarkEmitter *ORE;
|
||||
|
||||
LoopInterchange() : LoopPass(ID) {
|
||||
LoopInterchange() : FunctionPass(ID) {
|
||||
initializeLoopInterchangePass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<ScalarEvolutionWrapperPass>();
|
||||
AU.addRequired<AAResultsWrapperPass>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<LoopInfoWrapperPass>();
|
||||
AU.addRequired<DependenceAnalysisWrapperPass>();
|
||||
AU.addRequiredID(LoopSimplifyID);
|
||||
AU.addRequiredID(LCSSAID);
|
||||
AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
|
||||
|
||||
getLoopAnalysisUsage(AU);
|
||||
AU.addPreserved<DominatorTreeWrapperPass>();
|
||||
AU.addPreserved<LoopInfoWrapperPass>();
|
||||
AU.addPreserved<ScalarEvolutionWrapperPass>();
|
||||
AU.addPreservedID(LCSSAID);
|
||||
}
|
||||
|
||||
bool runOnLoop(Loop *L, LPPassManager &LPM) override {
|
||||
if (skipLoop(L) || L->getParentLoop())
|
||||
bool runOnFunction(Function &F) override {
|
||||
if (skipFunction(F))
|
||||
return false;
|
||||
|
||||
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
||||
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||
DI = &getAnalysis<DependenceAnalysisWrapperPass>().getDI();
|
||||
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
|
||||
PreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
|
||||
|
||||
return processLoopList(populateWorklist(*L));
|
||||
// Build up a worklist of loop pairs to analyze.
|
||||
SmallVector<LoopVector, 8> Worklist;
|
||||
|
||||
for (Loop *L : *LI)
|
||||
populateWorklist(*L, Worklist);
|
||||
|
||||
LLVM_DEBUG(dbgs() << "Worklist size = " << Worklist.size() << "\n");
|
||||
bool Changed = true;
|
||||
while (!Worklist.empty()) {
|
||||
LoopVector LoopList = Worklist.pop_back_val();
|
||||
Changed = processLoopList(LoopList, F);
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool isComputableLoopNest(LoopVector LoopList) {
|
||||
@ -483,7 +507,7 @@ struct LoopInterchange : public LoopPass {
|
||||
return LoopList.size() - 1;
|
||||
}
|
||||
|
||||
bool processLoopList(LoopVector LoopList) {
|
||||
bool processLoopList(LoopVector LoopList, Function &F) {
|
||||
bool Changed = false;
|
||||
unsigned LoopNestDepth = LoopList.size();
|
||||
if (LoopNestDepth < 2) {
|
||||
@ -1518,8 +1542,13 @@ char LoopInterchange::ID = 0;
|
||||
|
||||
INITIALIZE_PASS_BEGIN(LoopInterchange, "loop-interchange",
|
||||
"Interchanges loops for cache reuse", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DependenceAnalysisWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||
INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
|
||||
|
||||
INITIALIZE_PASS_END(LoopInterchange, "loop-interchange",
|
||||
|
Loading…
Reference in New Issue
Block a user