[PM] Port per-function SCCP to the new pass manager.

llvm-svn: 269937
This commit is contained in:
Davide Italiano 2016-05-18 15:18:25 +00:00
parent da5b1131de
commit 98f7e0e790
7 changed files with 92 additions and 46 deletions

View File

@ -267,7 +267,7 @@ void initializeRegionViewerPass(PassRegistry&);
void initializeReversePostOrderFunctionAttrsPass(PassRegistry&); void initializeReversePostOrderFunctionAttrsPass(PassRegistry&);
void initializeRewriteStatepointsForGCPass(PassRegistry&); void initializeRewriteStatepointsForGCPass(PassRegistry&);
void initializeSafeStackPass(PassRegistry&); void initializeSafeStackPass(PassRegistry&);
void initializeSCCPPass(PassRegistry&); void initializeSCCPLegacyPassPass(PassRegistry &);
void initializeSROALegacyPassPass(PassRegistry&); void initializeSROALegacyPassPass(PassRegistry&);
void initializeSROA_DTPass(PassRegistry&); void initializeSROA_DTPass(PassRegistry&);
void initializeSROA_SSAUpPass(PassRegistry&); void initializeSROA_SSAUpPass(PassRegistry&);

View File

@ -0,0 +1,35 @@
//===- SCCP.cpp - Sparse Conditional Constant Propagation -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
// This file implements sparse conditional constant propagation and merging:
//
// Specifically, this:
// * Assumes values are constant unless proven otherwise
// * Assumes BasicBlocks are dead unless proven otherwise
// * Proves values to be constant, and replaces them with constants
// * Proves conditional branches to be unconditional
//
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_SCALAR_SCCP_H
#define LLVM_TRANSFORMS_SCALAR_SCCP_H
#include "llvm/IR/Function.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
/// This pass performs function-level constant propagation and merging.
struct SCCPPass : PassInfoMixin<SCCPPass> {
PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
};
}
#endif // LLVM_TRANSFORMS_SCALAR_SCCP_H

View File

@ -72,6 +72,7 @@
#include "llvm/Transforms/Scalar/LowerAtomic.h" #include "llvm/Transforms/Scalar/LowerAtomic.h"
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h" #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
#include "llvm/Transforms/Scalar/Reassociate.h" #include "llvm/Transforms/Scalar/Reassociate.h"
#include "llvm/Transforms/Scalar/SCCP.h"
#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"

View File

@ -131,6 +131,7 @@ FUNCTION_PASS("print<loops>", LoopPrinterPass(dbgs()))
FUNCTION_PASS("print<regions>", RegionInfoPrinterPass(dbgs())) FUNCTION_PASS("print<regions>", RegionInfoPrinterPass(dbgs()))
FUNCTION_PASS("print<scalar-evolution>", ScalarEvolutionPrinterPass(dbgs())) FUNCTION_PASS("print<scalar-evolution>", ScalarEvolutionPrinterPass(dbgs()))
FUNCTION_PASS("reassociate", ReassociatePass()) FUNCTION_PASS("reassociate", ReassociatePass())
FUNCTION_PASS("sccp", SCCPPass())
FUNCTION_PASS("simplify-cfg", SimplifyCFGPass()) FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())
FUNCTION_PASS("sink", SinkingPass()) FUNCTION_PASS("sink", SinkingPass())
FUNCTION_PASS("sroa", SROA()) FUNCTION_PASS("sroa", SROA())

View File

@ -39,6 +39,7 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/SCCP.h"
#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/Local.h"
#include <algorithm> #include <algorithm>
using namespace llvm; using namespace llvm;
@ -1548,53 +1549,12 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
return false; return false;
} }
// runSCCP() - Run the Sparse Conditional Constant Propagation algorithm,
namespace {
//===--------------------------------------------------------------------===//
//
/// SCCP Class - This class uses the SCCPSolver to implement a per-function
/// Sparse Conditional Constant Propagator.
///
struct SCCP : public FunctionPass {
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.addPreserved<GlobalsAAWrapperPass>();
}
static char ID; // Pass identification, replacement for typeid
SCCP() : FunctionPass(ID) {
initializeSCCPPass(*PassRegistry::getPassRegistry());
}
// runOnFunction - Run the Sparse Conditional Constant Propagation
// algorithm, and return true if the function was modified.
//
bool runOnFunction(Function &F) override;
};
} // end anonymous namespace
char SCCP::ID = 0;
INITIALIZE_PASS_BEGIN(SCCP, "sccp",
"Sparse Conditional Constant Propagation", false, false)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_END(SCCP, "sccp",
"Sparse Conditional Constant Propagation", false, false)
// createSCCPPass - This is the public interface to this file.
FunctionPass *llvm::createSCCPPass() {
return new SCCP();
}
// runOnFunction() - Run the Sparse Conditional Constant Propagation algorithm,
// and return true if the function was modified. // and return true if the function was modified.
// //
bool SCCP::runOnFunction(Function &F) { static bool runSCCP(Function &F, const DataLayout &DL,
if (skipFunction(F)) const TargetLibraryInfo *TLI) {
return false;
DEBUG(dbgs() << "SCCP on function '" << F.getName() << "'\n"); DEBUG(dbgs() << "SCCP on function '" << F.getName() << "'\n");
const DataLayout &DL = F.getParent()->getDataLayout();
const TargetLibraryInfo *TLI =
&getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
SCCPSolver Solver(DL, TLI); SCCPSolver Solver(DL, TLI);
// Mark the first block of the function as being executable. // Mark the first block of the function as being executable.
@ -1664,6 +1624,54 @@ bool SCCP::runOnFunction(Function &F) {
return MadeChanges; return MadeChanges;
} }
PreservedAnalyses SCCPPass::run(Function &F, AnalysisManager<Function> &AM) {
const DataLayout &DL = F.getParent()->getDataLayout();
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
if (!runSCCP(F, DL, &TLI))
return PreservedAnalyses::all();
return PreservedAnalyses::none();
}
namespace {
//===--------------------------------------------------------------------===//
//
/// SCCP Class - This class uses the SCCPSolver to implement a per-function
/// Sparse Conditional Constant Propagator.
///
struct SCCPLegacyPass : public FunctionPass {
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<TargetLibraryInfoWrapperPass>();
AU.addPreserved<GlobalsAAWrapperPass>();
}
static char ID; // Pass identification, replacement for typeid
SCCPLegacyPass() : FunctionPass(ID) {
initializeSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
}
// runOnFunction - Run the Sparse Conditional Constant Propagation
// algorithm, and return true if the function was modified.
//
bool runOnFunction(Function &F) override {
if (skipFunction(F))
return false;
const DataLayout &DL = F.getParent()->getDataLayout();
const TargetLibraryInfo *TLI =
&getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
return runSCCP(F, DL, TLI);
}
};
} // end anonymous namespace
char SCCPLegacyPass::ID = 0;
INITIALIZE_PASS_BEGIN(SCCPLegacyPass, "sccp",
"Sparse Conditional Constant Propagation", false, false)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
INITIALIZE_PASS_END(SCCPLegacyPass, "sccp",
"Sparse Conditional Constant Propagation", false, false)
// createSCCPPass - This is the public interface to this file.
FunctionPass *llvm::createSCCPPass() { return new SCCPLegacyPass(); }
static bool AddressIsTaken(const GlobalValue *GV) { static bool AddressIsTaken(const GlobalValue *GV) {
// Delete any dead constantexpr klingons. // Delete any dead constantexpr klingons.
GV->removeDeadConstantUsers(); GV->removeDeadConstantUsers();

View File

@ -70,7 +70,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
initializeReassociateLegacyPassPass(Registry); initializeReassociateLegacyPassPass(Registry);
initializeRegToMemPass(Registry); initializeRegToMemPass(Registry);
initializeRewriteStatepointsForGCPass(Registry); initializeRewriteStatepointsForGCPass(Registry);
initializeSCCPPass(Registry); initializeSCCPLegacyPassPass(Registry);
initializeIPSCCPLegacyPassPass(Registry); initializeIPSCCPLegacyPassPass(Registry);
initializeSROALegacyPassPass(Registry); initializeSROALegacyPassPass(Registry);
initializeSROA_DTPass(Registry); initializeSROA_DTPass(Registry);

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -sccp -S | FileCheck %s ; RUN: opt < %s -sccp -S | FileCheck %s
; RUN: opt < %s -passes=sccp -S | FileCheck %s
@0 = private unnamed_addr constant [2 x i32] [i32 -1, i32 1] @0 = private unnamed_addr constant [2 x i32] [i32 -1, i32 1]
@"\01??_7A@@6B@" = unnamed_addr alias i32, getelementptr inbounds ([2 x i32], [2 x i32]* @0, i32 0, i32 1) @"\01??_7A@@6B@" = unnamed_addr alias i32, getelementptr inbounds ([2 x i32], [2 x i32]* @0, i32 0, i32 1)