mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-14 05:20:30 +00:00
[PM] Port LoopIdiomRecognize Pass to new PM
Summary: Port LoopIdiomRecognize Pass to new PM Reviewers: davidxl Subscribers: davide, sanjoy, mzolotukhin, llvm-commits Differential Revision: http://reviews.llvm.org/D22250 llvm-svn: 275202
This commit is contained in:
parent
76806b1edc
commit
c181c867aa
@ -177,7 +177,7 @@ void initializeLoopDataPrefetchPass(PassRegistry&);
|
|||||||
void initializeLoopDeletionPass(PassRegistry&);
|
void initializeLoopDeletionPass(PassRegistry&);
|
||||||
void initializeLoopDistributePass(PassRegistry&);
|
void initializeLoopDistributePass(PassRegistry&);
|
||||||
void initializeLoopExtractorPass(PassRegistry&);
|
void initializeLoopExtractorPass(PassRegistry&);
|
||||||
void initializeLoopIdiomRecognizePass(PassRegistry&);
|
void initializeLoopIdiomRecognizeLegacyPassPass(PassRegistry&);
|
||||||
void initializeLoopInfoWrapperPassPass(PassRegistry&);
|
void initializeLoopInfoWrapperPassPass(PassRegistry&);
|
||||||
void initializeLoopInstSimplifyPass(PassRegistry&);
|
void initializeLoopInstSimplifyPass(PassRegistry&);
|
||||||
void initializeLoopInterchangePass(PassRegistry &);
|
void initializeLoopInterchangePass(PassRegistry &);
|
||||||
|
31
include/llvm/Transforms/Scalar/LoopIdiomRecognize.h
Normal file
31
include/llvm/Transforms/Scalar/LoopIdiomRecognize.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
//===- LoopIdiomRecognize.h - Loop Idiom Recognize 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 implements an idiom recognizer that transforms simple loops into a
|
||||||
|
// non-loop form. In cases that this kicks in, it can be a significant
|
||||||
|
// performance win.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_TRANSFORMS_SCALAR_LOOPIDIOMRECOGNIZE_H
|
||||||
|
#define LLVM_TRANSFORMS_SCALAR_LOOPIDIOMRECOGNIZE_H
|
||||||
|
|
||||||
|
#include "llvm/Analysis/LoopInfo.h"
|
||||||
|
#include "llvm/IR/PassManager.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
/// Performs Loop Idiom Recognize Pass.
|
||||||
|
class LoopIdiomRecognizePass : public PassInfoMixin<LoopIdiomRecognizePass> {
|
||||||
|
public:
|
||||||
|
PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM);
|
||||||
|
};
|
||||||
|
} // end namespace llvm
|
||||||
|
|
||||||
|
#endif // LLVM_TRANSFORMS_SCALAR_LOOPIDIOMRECOGNIZE_H
|
@ -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/LoopIdiomRecognize.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("loop-idiom", LoopIdiomRecognizePass())
|
||||||
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()))
|
||||||
|
@ -31,15 +31,16 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"
|
||||||
#include "llvm/ADT/MapVector.h"
|
#include "llvm/ADT/MapVector.h"
|
||||||
#include "llvm/ADT/SetVector.h"
|
#include "llvm/ADT/SetVector.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
||||||
#include "llvm/Analysis/GlobalsModRef.h"
|
#include "llvm/Analysis/GlobalsModRef.h"
|
||||||
#include "llvm/Analysis/LoopPass.h"
|
|
||||||
#include "llvm/Analysis/LoopAccessAnalysis.h"
|
#include "llvm/Analysis/LoopAccessAnalysis.h"
|
||||||
|
#include "llvm/Analysis/LoopPass.h"
|
||||||
|
#include "llvm/Analysis/LoopPassManager.h"
|
||||||
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
|
||||||
#include "llvm/Analysis/ScalarEvolutionExpander.h"
|
#include "llvm/Analysis/ScalarEvolutionExpander.h"
|
||||||
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
|
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
|
||||||
@ -53,6 +54,7 @@
|
|||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Transforms/Utils/BuildLibCalls.h"
|
#include "llvm/Transforms/Utils/BuildLibCalls.h"
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include "llvm/Transforms/Utils/LoopUtils.h"
|
#include "llvm/Transforms/Utils/LoopUtils.h"
|
||||||
@ -65,7 +67,7 @@ STATISTIC(NumMemCpy, "Number of memcpy's formed from loop load+stores");
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class LoopIdiomRecognize : public LoopPass {
|
class LoopIdiomRecognize {
|
||||||
Loop *CurLoop;
|
Loop *CurLoop;
|
||||||
AliasAnalysis *AA;
|
AliasAnalysis *AA;
|
||||||
DominatorTree *DT;
|
DominatorTree *DT;
|
||||||
@ -76,21 +78,15 @@ class LoopIdiomRecognize : public LoopPass {
|
|||||||
const DataLayout *DL;
|
const DataLayout *DL;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
explicit LoopIdiomRecognize(AliasAnalysis *AA, DominatorTree *DT,
|
||||||
explicit LoopIdiomRecognize() : LoopPass(ID) {
|
LoopInfo *LI, ScalarEvolution *SE,
|
||||||
initializeLoopIdiomRecognizePass(*PassRegistry::getPassRegistry());
|
TargetLibraryInfo *TLI,
|
||||||
}
|
const TargetTransformInfo *TTI,
|
||||||
|
const DataLayout *DL)
|
||||||
|
: CurLoop(nullptr), AA(AA), DT(DT), LI(LI), SE(SE), TLI(TLI), TTI(TTI),
|
||||||
|
DL(DL) {}
|
||||||
|
|
||||||
bool runOnLoop(Loop *L, LPPassManager &LPM) override;
|
bool runOnLoop(Loop *L);
|
||||||
|
|
||||||
/// This transformation requires natural loop information & requires that
|
|
||||||
/// loop preheaders be inserted into the CFG.
|
|
||||||
///
|
|
||||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
||||||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
|
||||||
AU.addRequired<TargetTransformInfoWrapperPass>();
|
|
||||||
getLoopAnalysisUsage(AU);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef SmallVector<StoreInst *, 8> StoreList;
|
typedef SmallVector<StoreInst *, 8> StoreList;
|
||||||
@ -137,18 +133,78 @@ private:
|
|||||||
/// @}
|
/// @}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LoopIdiomRecognizeLegacyPass : public LoopPass {
|
||||||
|
public:
|
||||||
|
static char ID;
|
||||||
|
explicit LoopIdiomRecognizeLegacyPass() : LoopPass(ID) {
|
||||||
|
initializeLoopIdiomRecognizeLegacyPassPass(
|
||||||
|
*PassRegistry::getPassRegistry());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool runOnLoop(Loop *L, LPPassManager &LPM) override {
|
||||||
|
if (skipLoop(L))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
||||||
|
DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||||
|
LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||||
|
ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
||||||
|
TargetLibraryInfo *TLI =
|
||||||
|
&getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
||||||
|
const TargetTransformInfo *TTI =
|
||||||
|
&getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
|
||||||
|
*L->getHeader()->getParent());
|
||||||
|
const DataLayout *DL = &L->getHeader()->getModule()->getDataLayout();
|
||||||
|
|
||||||
|
LoopIdiomRecognize LIR(AA, DT, LI, SE, TLI, TTI, DL);
|
||||||
|
return LIR.runOnLoop(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This transformation requires natural loop information & requires that
|
||||||
|
/// loop preheaders be inserted into the CFG.
|
||||||
|
///
|
||||||
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||||
|
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||||
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
||||||
|
getLoopAnalysisUsage(AU);
|
||||||
|
}
|
||||||
|
};
|
||||||
} // End anonymous namespace.
|
} // End anonymous namespace.
|
||||||
|
|
||||||
char LoopIdiomRecognize::ID = 0;
|
PreservedAnalyses LoopIdiomRecognizePass::run(Loop &L,
|
||||||
INITIALIZE_PASS_BEGIN(LoopIdiomRecognize, "loop-idiom", "Recognize loop idioms",
|
AnalysisManager<Loop> &AM) {
|
||||||
false, false)
|
const auto &FAM =
|
||||||
|
AM.getResult<FunctionAnalysisManagerLoopProxy>(L).getManager();
|
||||||
|
Function *F = L.getHeader()->getParent();
|
||||||
|
|
||||||
|
// Use getCachedResult because Loop pass cannot trigger a function analysis.
|
||||||
|
auto *AA = FAM.getCachedResult<AAManager>(*F);
|
||||||
|
auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
|
||||||
|
auto *LI = FAM.getCachedResult<LoopAnalysis>(*F);
|
||||||
|
auto *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
|
||||||
|
auto *TLI = FAM.getCachedResult<TargetLibraryAnalysis>(*F);
|
||||||
|
const auto *TTI = FAM.getCachedResult<TargetIRAnalysis>(*F);
|
||||||
|
const auto *DL = &L.getHeader()->getModule()->getDataLayout();
|
||||||
|
assert((AA && DT && LI && SE && TLI && TTI && DL) &&
|
||||||
|
"Analyses for Loop Idiom Recognition not available");
|
||||||
|
|
||||||
|
LoopIdiomRecognize LIR(AA, DT, LI, SE, TLI, TTI, DL);
|
||||||
|
if (!LIR.runOnLoop(&L))
|
||||||
|
return PreservedAnalyses::all();
|
||||||
|
|
||||||
|
return getLoopPassPreservedAnalyses();
|
||||||
|
}
|
||||||
|
|
||||||
|
char LoopIdiomRecognizeLegacyPass::ID = 0;
|
||||||
|
INITIALIZE_PASS_BEGIN(LoopIdiomRecognizeLegacyPass, "loop-idiom",
|
||||||
|
"Recognize loop idioms", false, false)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopPass)
|
INITIALIZE_PASS_DEPENDENCY(LoopPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
||||||
INITIALIZE_PASS_END(LoopIdiomRecognize, "loop-idiom", "Recognize loop idioms",
|
INITIALIZE_PASS_END(LoopIdiomRecognizeLegacyPass, "loop-idiom",
|
||||||
false, false)
|
"Recognize loop idioms", false, false)
|
||||||
|
|
||||||
Pass *llvm::createLoopIdiomPass() { return new LoopIdiomRecognize(); }
|
Pass *llvm::createLoopIdiomPass() { return new LoopIdiomRecognizeLegacyPass(); }
|
||||||
|
|
||||||
static void deleteDeadInstruction(Instruction *I) {
|
static void deleteDeadInstruction(Instruction *I) {
|
||||||
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
I->replaceAllUsesWith(UndefValue::get(I->getType()));
|
||||||
@ -161,10 +217,7 @@ static void deleteDeadInstruction(Instruction *I) {
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
bool LoopIdiomRecognize::runOnLoop(Loop *L, LPPassManager &LPM) {
|
bool LoopIdiomRecognize::runOnLoop(Loop *L) {
|
||||||
if (skipLoop(L))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
CurLoop = L;
|
CurLoop = L;
|
||||||
// If the loop could not be converted to canonical form, it must have an
|
// If the loop could not be converted to canonical form, it must have an
|
||||||
// indirectbr in it, just give up.
|
// indirectbr in it, just give up.
|
||||||
@ -176,15 +229,6 @@ bool LoopIdiomRecognize::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
if (Name == "memset" || Name == "memcpy")
|
if (Name == "memset" || Name == "memcpy")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
|
|
||||||
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
|
||||||
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
|
||||||
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
|
||||||
TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
|
||||||
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
|
|
||||||
*CurLoop->getHeader()->getParent());
|
|
||||||
DL = &CurLoop->getHeader()->getModule()->getDataLayout();
|
|
||||||
|
|
||||||
HasMemset = TLI->has(LibFunc::memset);
|
HasMemset = TLI->has(LibFunc::memset);
|
||||||
HasMemsetPattern = TLI->has(LibFunc::memset_pattern16);
|
HasMemsetPattern = TLI->has(LibFunc::memset_pattern16);
|
||||||
HasMemcpy = TLI->has(LibFunc::memcpy);
|
HasMemcpy = TLI->has(LibFunc::memcpy);
|
||||||
|
@ -60,7 +60,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
|||||||
initializeLoopUnrollPass(Registry);
|
initializeLoopUnrollPass(Registry);
|
||||||
initializeLoopUnswitchPass(Registry);
|
initializeLoopUnswitchPass(Registry);
|
||||||
initializeLoopVersioningLICMPass(Registry);
|
initializeLoopVersioningLICMPass(Registry);
|
||||||
initializeLoopIdiomRecognizePass(Registry);
|
initializeLoopIdiomRecognizeLegacyPassPass(Registry);
|
||||||
initializeLowerAtomicLegacyPassPass(Registry);
|
initializeLowerAtomicLegacyPassPass(Registry);
|
||||||
initializeLowerExpectIntrinsicPass(Registry);
|
initializeLowerExpectIntrinsicPass(Registry);
|
||||||
initializeLowerGuardIntrinsicPass(Registry);
|
initializeLowerGuardIntrinsicPass(Registry);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
; RUN: opt -loop-idiom < %s -S | FileCheck %s
|
; RUN: opt -loop-idiom < %s -S | FileCheck %s
|
||||||
|
; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(loop-idiom)' < %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"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user