mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-17 03:24:34 +00:00
[LPM] Conclude my immediate work by making the LoopVectorizer
a FunctionPass. With this change the loop vectorizer no longer is a loop pass and can readily depend on function analyses. In particular, with this change we no longer have to form a loop pass manager to run the loop vectorizer which simplifies the entire pass management of LLVM. The next step here is to teach the loop vectorizer to leverage profile information through the profile information providing analysis passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200074 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -930,13 +930,21 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void addInnerLoop(Loop *L, SmallVectorImpl<Loop *> &V) {
|
||||||
|
if (L->empty())
|
||||||
|
return V.push_back(L);
|
||||||
|
|
||||||
|
for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
|
||||||
|
addInnerLoop(*I, V);
|
||||||
|
}
|
||||||
|
|
||||||
/// The LoopVectorize Pass.
|
/// The LoopVectorize Pass.
|
||||||
struct LoopVectorize : public LoopPass {
|
struct LoopVectorize : public FunctionPass {
|
||||||
/// Pass identification, replacement for typeid
|
/// Pass identification, replacement for typeid
|
||||||
static char ID;
|
static char ID;
|
||||||
|
|
||||||
explicit LoopVectorize(bool NoUnrolling = false, bool AlwaysVectorize = true)
|
explicit LoopVectorize(bool NoUnrolling = false, bool AlwaysVectorize = true)
|
||||||
: LoopPass(ID),
|
: FunctionPass(ID),
|
||||||
DisableUnrolling(NoUnrolling),
|
DisableUnrolling(NoUnrolling),
|
||||||
AlwaysVectorize(AlwaysVectorize) {
|
AlwaysVectorize(AlwaysVectorize) {
|
||||||
initializeLoopVectorizePass(*PassRegistry::getPassRegistry());
|
initializeLoopVectorizePass(*PassRegistry::getPassRegistry());
|
||||||
@@ -951,11 +959,7 @@ struct LoopVectorize : public LoopPass {
|
|||||||
bool DisableUnrolling;
|
bool DisableUnrolling;
|
||||||
bool AlwaysVectorize;
|
bool AlwaysVectorize;
|
||||||
|
|
||||||
virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
|
virtual bool runOnFunction(Function &F) {
|
||||||
// We only vectorize innermost loops.
|
|
||||||
if (!L->empty())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SE = &getAnalysis<ScalarEvolution>();
|
SE = &getAnalysis<ScalarEvolution>();
|
||||||
DL = getAnalysisIfAvailable<DataLayout>();
|
DL = getAnalysisIfAvailable<DataLayout>();
|
||||||
LI = &getAnalysis<LoopInfo>();
|
LI = &getAnalysis<LoopInfo>();
|
||||||
@@ -973,6 +977,32 @@ struct LoopVectorize : public LoopPass {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build up a worklist of inner-loops to vectorize. This is necessary as
|
||||||
|
// the act of vectorizing or partially unrolling a loop creates new loops
|
||||||
|
// and can invalidate iterators across the loops.
|
||||||
|
SmallVector<Loop *, 8> Worklist;
|
||||||
|
|
||||||
|
for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
|
||||||
|
addInnerLoop(*I, Worklist);
|
||||||
|
|
||||||
|
// Now walk the identified inner loops.
|
||||||
|
bool Changed = false;
|
||||||
|
while (!Worklist.empty())
|
||||||
|
Changed |= processLoop(Worklist.pop_back_val());
|
||||||
|
|
||||||
|
// Process each loop nest in the function.
|
||||||
|
return Changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool processLoop(Loop *L) {
|
||||||
|
// We only handle inner loops, so if there are children just recurse.
|
||||||
|
if (!L->empty()) {
|
||||||
|
bool Changed = false;
|
||||||
|
for (Loop::iterator I = L->begin(), E = L->begin(); I != E; ++I)
|
||||||
|
Changed |= processLoop(*I);
|
||||||
|
return Changed;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG(dbgs() << "LV: Checking a loop in \"" <<
|
DEBUG(dbgs() << "LV: Checking a loop in \"" <<
|
||||||
L->getHeader()->getParent()->getName() << "\"\n");
|
L->getHeader()->getParent()->getName() << "\"\n");
|
||||||
|
|
||||||
@@ -1052,7 +1082,6 @@ struct LoopVectorize : public LoopPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
LoopPass::getAnalysisUsage(AU);
|
|
||||||
AU.addRequiredID(LoopSimplifyID);
|
AU.addRequiredID(LoopSimplifyID);
|
||||||
AU.addRequiredID(LCSSAID);
|
AU.addRequiredID(LCSSAID);
|
||||||
AU.addRequired<DominatorTreeWrapperPass>();
|
AU.addRequired<DominatorTreeWrapperPass>();
|
||||||
|
Reference in New Issue
Block a user