[PM] Port LoopUnroll.

We just set PreserveLCSSA to always true since we don't have an
analogous method `mustPreserveAnalysisID(LCSSA)`.

Also port LoopInfo verifier pass to test LoopUnrollPass.

llvm-svn: 276063
This commit is contained in:
Sean Silva 2016-07-19 23:54:23 +00:00
parent 9e52c064c2
commit e3c18a5ae8
7 changed files with 77 additions and 0 deletions

View File

@ -791,6 +791,11 @@ public:
PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
};
/// \brief Verifier pass for the \c LoopAnalysis results.
struct LoopVerifierPass : public PassInfoMixin<LoopVerifierPass> {
PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
};
/// \brief The legacy pass manager's analysis pass to compute loop information.
class LoopInfoWrapperPass : public FunctionPass {
LoopInfo LI;

View File

@ -0,0 +1,28 @@
//===- LoopUnrollPass.h -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
#define LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
struct LoopUnrollPass : public PassInfoMixin<LoopUnrollPass> {
Optional<unsigned> ProvidedCount;
Optional<unsigned> ProvidedThreshold;
Optional<bool> ProvidedAllowPartial;
Optional<bool> ProvidedRuntime;
PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM);
};
} // end namespace llvm
#endif // LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H

View File

@ -715,6 +715,13 @@ void LoopInfoWrapperPass::print(raw_ostream &OS, const Module *) const {
LI.print(OS);
}
PreservedAnalyses LoopVerifierPass::run(Function &F,
AnalysisManager<Function> &AM) {
LoopInfo &LI = AM.getResult<LoopAnalysis>(F);
LI.verify();
return PreservedAnalyses::all();
}
//===----------------------------------------------------------------------===//
// LoopBlocksDFS implementation
//

View File

@ -99,6 +99,7 @@
#include "llvm/Transforms/Scalar/LoopRotation.h"
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
#include "llvm/Transforms/Scalar/LoopStrengthReduce.h"
#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
#include "llvm/Transforms/Scalar/LowerAtomic.h"
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
#include "llvm/Transforms/Scalar/MemCpyOptimizer.h"

View File

@ -176,6 +176,7 @@ FUNCTION_PASS("tailcallelim", TailCallElimPass())
FUNCTION_PASS("unreachableblockelim", UnreachableBlockElimPass())
FUNCTION_PASS("verify", VerifierPass())
FUNCTION_PASS("verify<domtree>", DominatorTreeVerifierPass())
FUNCTION_PASS("verify<loops>", LoopVerifierPass())
FUNCTION_PASS("verify<memoryssa>", MemorySSAVerifierPass())
FUNCTION_PASS("verify<regions>", RegionInfoVerifierPass())
#undef FUNCTION_PASS
@ -202,6 +203,7 @@ LOOP_PASS("loop-deletion", LoopDeletionPass())
LOOP_PASS("simplify-cfg", LoopSimplifyCFGPass())
LOOP_PASS("strength-reduce", LoopStrengthReducePass())
LOOP_PASS("indvars", IndVarSimplifyPass())
LOOP_PASS("unroll", LoopUnrollPass())
LOOP_PASS("print-access-info", LoopAccessInfoPrinterPass(dbgs()))
LOOP_PASS("print<ivusers>", IVUsersPrinterPass(dbgs()))
#undef LOOP_PASS

View File

@ -12,12 +12,14 @@
// counts of loops easily.
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Scalar/LoopUnrollPass.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/LoopPassManager.h"
#include "llvm/Analysis/LoopUnrollAnalyzer.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
@ -1054,3 +1056,34 @@ Pass *llvm::createLoopUnrollPass(int Threshold, int Count, int AllowPartial,
Pass *llvm::createSimpleLoopUnrollPass() {
return llvm::createLoopUnrollPass(-1, -1, 0, 0);
}
PreservedAnalyses LoopUnrollPass::run(Loop &L, AnalysisManager<Loop> &AM) {
const auto &FAM =
AM.getResult<FunctionAnalysisManagerLoopProxy>(L).getManager();
Function *F = L.getHeader()->getParent();
DominatorTree *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
LoopInfo *LI = FAM.getCachedResult<LoopAnalysis>(*F);
ScalarEvolution *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
auto *TTI = FAM.getCachedResult<TargetIRAnalysis>(*F);
auto *AC = FAM.getCachedResult<AssumptionAnalysis>(*F);
if (!DT)
report_fatal_error("LoopUnrollPass: DominatorTreeAnalysis not cached at a higher level");
if (!LI)
report_fatal_error("LoopUnrollPass: LoopAnalysis not cached at a higher level");
if (!SE)
report_fatal_error("LoopUnrollPass: ScalarEvolutionAnalysis not cached at a higher level");
if (!TTI)
report_fatal_error("LoopUnrollPass: TargetIRAnalysis not cached at a higher level");
if (!AC)
report_fatal_error("LoopUnrollPass: AssumptionAnalysis not cached at a higher level");
bool Changed = tryToUnrollLoop(
&L, *DT, LI, SE, *TTI, *AC, /*PreserveLCSSA*/ true, ProvidedCount,
ProvidedThreshold, ProvidedAllowPartial, ProvidedRuntime);
if (!Changed)
return PreservedAnalyses::all();
return getLoopPassPreservedAnalyses();
}

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -S -loop-unroll -verify-loop-info | FileCheck %s
; RUN: opt < %s -S -passes='function(require<scalar-evolution>,require<targetir>,loop(unroll),verify<loops>)' | FileCheck %s
;
; Unit tests for LoopInfo::markAsRemoved.