forked from OSchip/llvm-project
[LoopReroll][NewPM] Port -loop-reroll to NPM
Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D87957
This commit is contained in:
parent
137597d4f4
commit
d3f6972abb
|
@ -245,7 +245,7 @@ void initializeLoopInterchangePass(PassRegistry&);
|
|||
void initializeLoopLoadEliminationPass(PassRegistry&);
|
||||
void initializeLoopPassPass(PassRegistry&);
|
||||
void initializeLoopPredicationLegacyPassPass(PassRegistry&);
|
||||
void initializeLoopRerollPass(PassRegistry&);
|
||||
void initializeLoopRerollLegacyPassPass(PassRegistry &);
|
||||
void initializeLoopRotateLegacyPassPass(PassRegistry&);
|
||||
void initializeLoopSimplifyCFGLegacyPassPass(PassRegistry&);
|
||||
void initializeLoopSimplifyPass(PassRegistry&);
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
//===- LoopReroll.h - Loop rerolling pass ---------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_SCALAR_LOOPREROLL_H
|
||||
#define LLVM_TRANSFORMS_SCALAR_LOOPREROLL_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/Transforms/Scalar/LoopPassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class Function;
|
||||
|
||||
class LoopRerollPass : public PassInfoMixin<LoopRerollPass> {
|
||||
public:
|
||||
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
|
||||
LoopStandardAnalysisResults &AR, LPMUpdater &U);
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_TRANSFORMS_SCALAR_LOOPREROLL_H
|
|
@ -154,6 +154,7 @@
|
|||
#include "llvm/Transforms/Scalar/LoopLoadElimination.h"
|
||||
#include "llvm/Transforms/Scalar/LoopPassManager.h"
|
||||
#include "llvm/Transforms/Scalar/LoopPredication.h"
|
||||
#include "llvm/Transforms/Scalar/LoopReroll.h"
|
||||
#include "llvm/Transforms/Scalar/LoopRotation.h"
|
||||
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
|
||||
#include "llvm/Transforms/Scalar/LoopSink.h"
|
||||
|
|
|
@ -369,6 +369,7 @@ LOOP_PASS("print<loop-cache-cost>", LoopCachePrinterPass(dbgs()))
|
|||
LOOP_PASS("loop-predication", LoopPredicationPass())
|
||||
LOOP_PASS("guard-widening", GuardWideningPass())
|
||||
LOOP_PASS("simple-loop-unswitch", SimpleLoopUnswitchPass())
|
||||
LOOP_PASS("loop-reroll", LoopRerollPass())
|
||||
#undef LOOP_PASS
|
||||
|
||||
#ifndef LOOP_PASS_WITH_PARAMS
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Scalar/LoopReroll.h"
|
||||
#include "llvm/Transforms/Utils.h"
|
||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||
#include "llvm/Transforms/Utils/Local.h"
|
||||
|
@ -161,12 +162,12 @@ namespace {
|
|||
IL_End
|
||||
};
|
||||
|
||||
class LoopReroll : public LoopPass {
|
||||
class LoopRerollLegacyPass : public LoopPass {
|
||||
public:
|
||||
static char ID; // Pass ID, replacement for typeid
|
||||
|
||||
LoopReroll() : LoopPass(ID) {
|
||||
initializeLoopRerollPass(*PassRegistry::getPassRegistry());
|
||||
LoopRerollLegacyPass() : LoopPass(ID) {
|
||||
initializeLoopRerollLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnLoop(Loop *L, LPPassManager &LPM) override;
|
||||
|
@ -175,6 +176,15 @@ namespace {
|
|||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||
getLoopAnalysisUsage(AU);
|
||||
}
|
||||
};
|
||||
|
||||
class LoopReroll {
|
||||
public:
|
||||
LoopReroll(AliasAnalysis *AA, LoopInfo *LI, ScalarEvolution *SE,
|
||||
TargetLibraryInfo *TLI, DominatorTree *DT, bool PreserveLCSSA)
|
||||
: AA(AA), LI(LI), SE(SE), TLI(TLI), DT(DT),
|
||||
PreserveLCSSA(PreserveLCSSA) {}
|
||||
bool runOnLoop(Loop *L);
|
||||
|
||||
protected:
|
||||
AliasAnalysis *AA;
|
||||
|
@ -484,16 +494,16 @@ namespace {
|
|||
|
||||
} // end anonymous namespace
|
||||
|
||||
char LoopReroll::ID = 0;
|
||||
char LoopRerollLegacyPass::ID = 0;
|
||||
|
||||
INITIALIZE_PASS_BEGIN(LoopReroll, "loop-reroll", "Reroll loops", false, false)
|
||||
INITIALIZE_PASS_BEGIN(LoopRerollLegacyPass, "loop-reroll", "Reroll loops",
|
||||
false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||
INITIALIZE_PASS_END(LoopReroll, "loop-reroll", "Reroll loops", false, false)
|
||||
INITIALIZE_PASS_END(LoopRerollLegacyPass, "loop-reroll", "Reroll loops", false,
|
||||
false)
|
||||
|
||||
Pass *llvm::createLoopRerollPass() {
|
||||
return new LoopReroll;
|
||||
}
|
||||
Pass *llvm::createLoopRerollPass() { return new LoopRerollLegacyPass; }
|
||||
|
||||
// Returns true if the provided instruction is used outside the given loop.
|
||||
// This operates like Instruction::isUsedOutsideOfBlock, but considers PHIs in
|
||||
|
@ -1644,18 +1654,7 @@ bool LoopReroll::reroll(Instruction *IV, Loop *L, BasicBlock *Header,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool LoopReroll::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||
if (skipLoop(L))
|
||||
return false;
|
||||
|
||||
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
||||
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
||||
TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
|
||||
*L->getHeader()->getParent());
|
||||
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
PreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
|
||||
|
||||
bool LoopReroll::runOnLoop(Loop *L) {
|
||||
BasicBlock *Header = L->getHeader();
|
||||
LLVM_DEBUG(dbgs() << "LRR: F[" << Header->getParent()->getName() << "] Loop %"
|
||||
<< Header->getName() << " (" << L->getNumBlocks()
|
||||
|
@ -1704,3 +1703,26 @@ bool LoopReroll::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool LoopRerollLegacyPass::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||
if (skipLoop(L))
|
||||
return false;
|
||||
|
||||
auto *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
||||
auto *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||
auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
||||
auto *TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
|
||||
*L->getHeader()->getParent());
|
||||
auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
bool PreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
|
||||
|
||||
return LoopReroll(AA, LI, SE, TLI, DT, PreserveLCSSA).runOnLoop(L);
|
||||
}
|
||||
|
||||
PreservedAnalyses LoopRerollPass::run(Loop &L, LoopAnalysisManager &AM,
|
||||
LoopStandardAnalysisResults &AR,
|
||||
LPMUpdater &U) {
|
||||
return LoopReroll(&AR.AA, &AR.LI, &AR.SE, &AR.TLI, &AR.DT, true).runOnLoop(&L)
|
||||
? getLoopPassPreservedAnalyses()
|
||||
: PreservedAnalyses::all();
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
|||
initializeLoopPredicationLegacyPassPass(Registry);
|
||||
initializeLoopRotateLegacyPassPass(Registry);
|
||||
initializeLoopStrengthReducePass(Registry);
|
||||
initializeLoopRerollPass(Registry);
|
||||
initializeLoopRerollLegacyPassPass(Registry);
|
||||
initializeLoopUnrollPass(Registry);
|
||||
initializeLoopUnrollAndJamPass(Registry);
|
||||
initializeLoopUnswitchPass(Registry);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -loop-reroll -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=loop-reroll -S | FileCheck %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-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
|
|
Loading…
Reference in New Issue