forked from OSchip/llvm-project
[PM] Port LCSSA to the new PM.
Differential Revision: http://reviews.llvm.org/D21090 llvm-svn: 272294
This commit is contained in:
parent
6437eb9d5f
commit
e12c487b8c
|
@ -163,7 +163,7 @@ void initializeInternalizeLegacyPassPass(PassRegistry&);
|
||||||
void initializeIntervalPartitionPass(PassRegistry&);
|
void initializeIntervalPartitionPass(PassRegistry&);
|
||||||
void initializeIRTranslatorPass(PassRegistry &);
|
void initializeIRTranslatorPass(PassRegistry &);
|
||||||
void initializeJumpThreadingPass(PassRegistry&);
|
void initializeJumpThreadingPass(PassRegistry&);
|
||||||
void initializeLCSSAPass(PassRegistry&);
|
void initializeLCSSAWrapperPassPass(PassRegistry &);
|
||||||
void initializeLICMPass(PassRegistry&);
|
void initializeLICMPass(PassRegistry&);
|
||||||
void initializeLazyValueInfoPass(PassRegistry&);
|
void initializeLazyValueInfoPass(PassRegistry&);
|
||||||
void initializeLintPass(PassRegistry&);
|
void initializeLintPass(PassRegistry&);
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
//===- LCSSA.h - Loop-closed SSA transform 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 transforms loops by placing phi nodes at the end of the loops for
|
||||||
|
// all values that are live across the loop boundary. For example, it turns
|
||||||
|
// the left into the right code:
|
||||||
|
//
|
||||||
|
// for (...) for (...)
|
||||||
|
// if (c) if (c)
|
||||||
|
// X1 = ... X1 = ...
|
||||||
|
// else else
|
||||||
|
// X2 = ... X2 = ...
|
||||||
|
// X3 = phi(X1, X2) X3 = phi(X1, X2)
|
||||||
|
// ... = X3 + 4 X4 = phi(X3)
|
||||||
|
// ... = X4 + 4
|
||||||
|
//
|
||||||
|
// This is still valid LLVM; the extra phi nodes are purely redundant, and will
|
||||||
|
// be trivially eliminated by InstCombine. The major benefit of this
|
||||||
|
// transformation is that it makes many other loop optimizations, such as
|
||||||
|
// LoopUnswitching, simpler.
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_TRANSFORMS_UTILS_LCSSA_H
|
||||||
|
#define LLVM_TRANSFORMS_UTILS_LCSSA_H
|
||||||
|
|
||||||
|
#include "llvm/IR/PassManager.h"
|
||||||
|
|
||||||
|
namespace llvm {
|
||||||
|
|
||||||
|
/// Converts loops into loop-closed SSA form.
|
||||||
|
class LCSSAPass : public PassInfoMixin<LCSSAPass> {
|
||||||
|
public:
|
||||||
|
PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
|
||||||
|
};
|
||||||
|
} // end namespace llvm
|
||||||
|
|
||||||
|
#endif // LLVM_TRANSFORMS_UTILS_LCSSA_H
|
|
@ -83,6 +83,7 @@
|
||||||
#include "llvm/Transforms/Scalar/SROA.h"
|
#include "llvm/Transforms/Scalar/SROA.h"
|
||||||
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
|
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
|
||||||
#include "llvm/Transforms/Scalar/Sink.h"
|
#include "llvm/Transforms/Scalar/Sink.h"
|
||||||
|
#include "llvm/Transforms/Utils/LCSSA.h"
|
||||||
#include "llvm/Transforms/Utils/MemorySSA.h"
|
#include "llvm/Transforms/Utils/MemorySSA.h"
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,7 @@ FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
|
||||||
FUNCTION_PASS("guard-widening", GuardWideningPass())
|
FUNCTION_PASS("guard-widening", GuardWideningPass())
|
||||||
FUNCTION_PASS("gvn", GVN())
|
FUNCTION_PASS("gvn", GVN())
|
||||||
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())
|
FUNCTION_PASS("partially-inline-libcalls", PartiallyInlineLibCallsPass())
|
||||||
|
FUNCTION_PASS("lcssa", LCSSAPass())
|
||||||
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
|
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
|
||||||
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))
|
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))
|
||||||
FUNCTION_PASS("print<block-freq>", BlockFrequencyPrinterPass(dbgs()))
|
FUNCTION_PASS("print<block-freq>", BlockFrequencyPrinterPass(dbgs()))
|
||||||
|
|
|
@ -1300,7 +1300,7 @@ INITIALIZE_PASS_DEPENDENCY(DependenceAnalysisWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||||
|
|
||||||
INITIALIZE_PASS_END(LoopInterchange, "loop-interchange",
|
INITIALIZE_PASS_END(LoopInterchange, "loop-interchange",
|
||||||
|
|
|
@ -585,7 +585,7 @@ INITIALIZE_PASS_BEGIN(LoopVersioningLICM, "loop-versioning-licm",
|
||||||
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis)
|
INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Utils/LCSSA.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
|
@ -42,6 +42,7 @@
|
||||||
#include "llvm/IR/Instructions.h"
|
#include "llvm/IR/Instructions.h"
|
||||||
#include "llvm/IR/PredIteratorCache.h"
|
#include "llvm/IR/PredIteratorCache.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Transforms/Utils/LoopUtils.h"
|
#include "llvm/Transforms/Utils/LoopUtils.h"
|
||||||
#include "llvm/Transforms/Utils/SSAUpdater.h"
|
#include "llvm/Transforms/Utils/SSAUpdater.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -270,11 +271,20 @@ bool llvm::formLCSSARecursively(Loop &L, DominatorTree &DT, LoopInfo *LI,
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Process all loops in the function, inner-most out.
|
||||||
|
static bool formLCSSAOnAllLoops(LoopInfo *LI, DominatorTree &DT,
|
||||||
|
ScalarEvolution *SE) {
|
||||||
|
bool Changed = false;
|
||||||
|
for (auto &L : *LI)
|
||||||
|
Changed |= formLCSSARecursively(*L, DT, LI, SE);
|
||||||
|
return Changed;
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct LCSSA : public FunctionPass {
|
struct LCSSAWrapperPass : public FunctionPass {
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
LCSSA() : FunctionPass(ID) {
|
LCSSAWrapperPass() : FunctionPass(ID) {
|
||||||
initializeLCSSAPass(*PassRegistry::getPassRegistry());
|
initializeLCSSAWrapperPassPass(*PassRegistry::getPassRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cached analysis information for the current function.
|
// Cached analysis information for the current function.
|
||||||
|
@ -302,28 +312,40 @@ struct LCSSA : public FunctionPass {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
char LCSSA::ID = 0;
|
char LCSSAWrapperPass::ID = 0;
|
||||||
INITIALIZE_PASS_BEGIN(LCSSA, "lcssa", "Loop-Closed SSA Form Pass", false, false)
|
INITIALIZE_PASS_BEGIN(LCSSAWrapperPass, "lcssa", "Loop-Closed SSA Form Pass",
|
||||||
|
false, false)
|
||||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||||
INITIALIZE_PASS_END(LCSSA, "lcssa", "Loop-Closed SSA Form Pass", false, false)
|
INITIALIZE_PASS_END(LCSSAWrapperPass, "lcssa", "Loop-Closed SSA Form Pass",
|
||||||
|
false, false)
|
||||||
|
|
||||||
Pass *llvm::createLCSSAPass() { return new LCSSA(); }
|
Pass *llvm::createLCSSAPass() { return new LCSSAWrapperPass(); }
|
||||||
char &llvm::LCSSAID = LCSSA::ID;
|
char &llvm::LCSSAID = LCSSAWrapperPass::ID;
|
||||||
|
|
||||||
|
/// Transform \p F into loop-closed SSA form.
|
||||||
/// Process all loops in the function, inner-most out.
|
bool LCSSAWrapperPass::runOnFunction(Function &F) {
|
||||||
bool LCSSA::runOnFunction(Function &F) {
|
|
||||||
bool Changed = false;
|
|
||||||
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||||
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||||
auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
|
auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
|
||||||
SE = SEWP ? &SEWP->getSE() : nullptr;
|
SE = SEWP ? &SEWP->getSE() : nullptr;
|
||||||
|
|
||||||
// Simplify each loop nest in the function.
|
return formLCSSAOnAllLoops(LI, *DT, SE);
|
||||||
for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
|
|
||||||
Changed |= formLCSSARecursively(**I, *DT, LI, SE);
|
|
||||||
|
|
||||||
return Changed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PreservedAnalyses LCSSAPass::run(Function &F, AnalysisManager<Function> &AM) {
|
||||||
|
auto &LI = AM.getResult<LoopAnalysis>(F);
|
||||||
|
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
||||||
|
auto *SE = AM.getCachedResult<ScalarEvolutionAnalysis>(F);
|
||||||
|
if (!formLCSSAOnAllLoops(&LI, DT, SE))
|
||||||
|
return PreservedAnalyses::all();
|
||||||
|
|
||||||
|
// FIXME: There is no setPreservesCFG in the new PM. When that becomes
|
||||||
|
// available, it should be used here.
|
||||||
|
PreservedAnalyses PA;
|
||||||
|
PA.preserve<BasicAA>();
|
||||||
|
PA.preserve<GlobalsAA>();
|
||||||
|
PA.preserve<SCEVAA>();
|
||||||
|
PA.preserve<ScalarEvolutionAnalysis>();
|
||||||
|
return PA;
|
||||||
|
}
|
||||||
|
|
|
@ -880,7 +880,7 @@ void llvm::initializeLoopPassPass(PassRegistry &Registry) {
|
||||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(BasicAAWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(BasicAAWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
|
||||||
|
|
|
@ -24,7 +24,7 @@ void llvm::initializeTransformUtils(PassRegistry &Registry) {
|
||||||
initializeAddDiscriminatorsPass(Registry);
|
initializeAddDiscriminatorsPass(Registry);
|
||||||
initializeBreakCriticalEdgesPass(Registry);
|
initializeBreakCriticalEdgesPass(Registry);
|
||||||
initializeInstNamerPass(Registry);
|
initializeInstNamerPass(Registry);
|
||||||
initializeLCSSAPass(Registry);
|
initializeLCSSAWrapperPassPass(Registry);
|
||||||
initializeLoopSimplifyPass(Registry);
|
initializeLoopSimplifyPass(Registry);
|
||||||
initializeLowerInvokePass(Registry);
|
initializeLowerInvokePass(Registry);
|
||||||
initializeLowerSwitchPass(Registry);
|
initializeLowerSwitchPass(Registry);
|
||||||
|
|
|
@ -6193,7 +6193,7 @@ INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
|
||||||
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis)
|
INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -lcssa -S | FileCheck %s
|
; RUN: opt < %s -lcssa -S | FileCheck %s
|
||||||
|
; RUN: opt < %s -passes=lcssa -S | FileCheck %s
|
||||||
|
|
||||||
declare i1 @c1()
|
declare i1 @c1()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -lcssa
|
; RUN: opt < %s -lcssa
|
||||||
|
; RUN: opt < %s -passes=lcssa
|
||||||
|
|
||||||
%struct.SetJmpMapEntry = type { i8*, i32, %struct.SetJmpMapEntry* }
|
%struct.SetJmpMapEntry = type { i8*, i32, %struct.SetJmpMapEntry* }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -lcssa -disable-output
|
; RUN: opt < %s -lcssa -disable-output
|
||||||
|
; RUN: opt < %s -passes=lcssa -disable-output
|
||||||
; PR977
|
; PR977
|
||||||
; END.
|
; END.
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -lcssa -S | FileCheck %s
|
; RUN: opt < %s -lcssa -S | FileCheck %s
|
||||||
|
; RUN: opt < %s -passes=lcssa -S | FileCheck %s
|
||||||
|
|
||||||
define void @lcssa(i1 %S2) {
|
define void @lcssa(i1 %S2) {
|
||||||
; CHECK-LABEL: @lcssa
|
; CHECK-LABEL: @lcssa
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -lcssa
|
; RUN: opt < %s -lcssa
|
||||||
|
; RUN: opt < %s -passes=lcssa
|
||||||
|
|
||||||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
|
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt -lcssa -S < %s | FileCheck %s
|
; RUN: opt -lcssa -S < %s | FileCheck %s
|
||||||
|
; RUN: opt -passes=lcssa -S < %s | FileCheck %s
|
||||||
|
|
||||||
; This test is based on the following C++ code:
|
; This test is based on the following C++ code:
|
||||||
;
|
;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
; RUN: opt < %s -lcssa -S | FileCheck %s
|
; RUN: opt < %s -lcssa -S | FileCheck %s
|
||||||
|
; RUN: opt < %s -passes=lcssa -S | FileCheck %s
|
||||||
; CHECK: exit1:
|
; CHECK: exit1:
|
||||||
; CHECK: .lcssa =
|
; CHECK: .lcssa =
|
||||||
; CHECK: exit2:
|
; CHECK: exit2:
|
||||||
|
|
Loading…
Reference in New Issue