mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-14 03:50:48 +00:00

After D45330, Dominators are required for IPSCCP and can be preserved. This patch preserves DominatorTreeAnalysis in the new pass manager. AFAIK the legacy pass manager cannot preserve function analysis required by a module analysis. Reviewers: davide, dberlin, chandlerc, efriedma, kuhar, NutshellySima Reviewed By: chandlerc, kuhar, NutshellySima Differential Revision: https://reviews.llvm.org/D47259 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346486 91177308-0d34-0410-b5e6-96231b3b80d8
88 lines
2.9 KiB
C++
88 lines
2.9 KiB
C++
#include "llvm/Transforms/IPO/SCCP.h"
|
|
#include "llvm/Analysis/AssumptionCache.h"
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
|
#include "llvm/Transforms/IPO.h"
|
|
#include "llvm/Transforms/Scalar/SCCP.h"
|
|
|
|
using namespace llvm;
|
|
|
|
PreservedAnalyses IPSCCPPass::run(Module &M, ModuleAnalysisManager &AM) {
|
|
const DataLayout &DL = M.getDataLayout();
|
|
auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
|
|
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
|
|
auto getAnalysis = [&FAM](Function &F) -> AnalysisResultsForFn {
|
|
DominatorTree &DT = FAM.getResult<DominatorTreeAnalysis>(F);
|
|
return {
|
|
make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)),
|
|
&DT};
|
|
};
|
|
|
|
if (!runIPSCCP(M, DL, &TLI, getAnalysis))
|
|
return PreservedAnalyses::all();
|
|
|
|
PreservedAnalyses PA;
|
|
PA.preserve<DominatorTreeAnalysis>();
|
|
PA.preserve<FunctionAnalysisManagerModuleProxy>();
|
|
return PA;
|
|
}
|
|
|
|
namespace {
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
//
|
|
/// IPSCCP Class - This class implements interprocedural Sparse Conditional
|
|
/// Constant Propagation.
|
|
///
|
|
class IPSCCPLegacyPass : public ModulePass {
|
|
public:
|
|
static char ID;
|
|
|
|
IPSCCPLegacyPass() : ModulePass(ID) {
|
|
initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
|
|
}
|
|
|
|
bool runOnModule(Module &M) override {
|
|
if (skipModule(M))
|
|
return false;
|
|
const DataLayout &DL = M.getDataLayout();
|
|
const TargetLibraryInfo *TLI =
|
|
&getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
|
|
|
auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn {
|
|
DominatorTree &DT =
|
|
this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
|
|
return {
|
|
make_unique<PredicateInfo>(
|
|
F, DT,
|
|
this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
|
|
F)),
|
|
nullptr}; // We cannot preserve the DT with the legacy pass manager,
|
|
// so so set it to nullptr.
|
|
};
|
|
|
|
return runIPSCCP(M, DL, TLI, getAnalysis);
|
|
}
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
AU.addRequired<AssumptionCacheTracker>();
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
|
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
|
}
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
char IPSCCPLegacyPass::ID = 0;
|
|
|
|
INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp",
|
|
"Interprocedural Sparse Conditional Constant Propagation",
|
|
false, false)
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
|
INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp",
|
|
"Interprocedural Sparse Conditional Constant Propagation",
|
|
false, false)
|
|
|
|
// createIPSCCPPass - This is the public interface to this file.
|
|
ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }
|