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

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri May 27 14:35:32 PDT 2016


On Fri, May 27, 2016 at 2:21 PM, Justin Bogner <mail at justinbogner.com> wrote:
> Davide Italiano via llvm-commits <llvm-commits at lists.llvm.org> writes:
>> Author: davide
>> Date: Wed May 18 10:18:25 2016
>> New Revision: 269937
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=269937&view=rev
>> Log:
>> [PM] Port per-function SCCP to the new pass manager.
>>
>> Added:
>>     llvm/trunk/include/llvm/Transforms/Scalar/SCCP.h
>> Modified:
>>     llvm/trunk/include/llvm/InitializePasses.h
>>     llvm/trunk/lib/Passes/PassBuilder.cpp
>>     llvm/trunk/lib/Passes/PassRegistry.def
>>     llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
>>     llvm/trunk/lib/Transforms/Scalar/Scalar.cpp
>>     llvm/trunk/test/Transforms/SCCP/global-alias-constprop.ll
>>
>> Modified: llvm/trunk/include/llvm/InitializePasses.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=269937&r1=269936&r2=269937&view=diff
>> ==============================================================================
>> --- llvm/trunk/include/llvm/InitializePasses.h (original)
>> +++ llvm/trunk/include/llvm/InitializePasses.h Wed May 18 10:18:25 2016
>> @@ -267,7 +267,7 @@ void initializeRegionViewerPass(PassRegi
>>  void initializeReversePostOrderFunctionAttrsPass(PassRegistry&);
>>  void initializeRewriteStatepointsForGCPass(PassRegistry&);
>>  void initializeSafeStackPass(PassRegistry&);
>> -void initializeSCCPPass(PassRegistry&);
>> +void initializeSCCPLegacyPassPass(PassRegistry &);
>>  void initializeSROALegacyPassPass(PassRegistry&);
>>  void initializeSROA_DTPass(PassRegistry&);
>>  void initializeSROA_SSAUpPass(PassRegistry&);
>>
>> Added: llvm/trunk/include/llvm/Transforms/Scalar/SCCP.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/SCCP.h?rev=269937&view=auto
>> ==============================================================================
>> --- llvm/trunk/include/llvm/Transforms/Scalar/SCCP.h (added)
>> +++ llvm/trunk/include/llvm/Transforms/Scalar/SCCP.h Wed May 18 10:18:25 2016
>> @@ -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
>>
>> Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=269937&r1=269936&r2=269937&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
>> +++ llvm/trunk/lib/Passes/PassBuilder.cpp Wed May 18 10:18:25 2016
>> @@ -72,6 +72,7 @@
>>  #include "llvm/Transforms/Scalar/LowerAtomic.h"
>>  #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
>>  #include "llvm/Transforms/Scalar/Reassociate.h"
>> +#include "llvm/Transforms/Scalar/SCCP.h"
>>  #include "llvm/Transforms/Scalar/SROA.h"
>>  #include "llvm/Transforms/Scalar/SimplifyCFG.h"
>>  #include "llvm/Transforms/Scalar/Sink.h"
>>
>> Modified: llvm/trunk/lib/Passes/PassRegistry.def
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=269937&r1=269936&r2=269937&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Passes/PassRegistry.def (original)
>> +++ llvm/trunk/lib/Passes/PassRegistry.def Wed May 18 10:18:25 2016
>> @@ -131,6 +131,7 @@ FUNCTION_PASS("print<loops>", LoopPrinte
>>  FUNCTION_PASS("print<regions>", RegionInfoPrinterPass(dbgs()))
>>  FUNCTION_PASS("print<scalar-evolution>", ScalarEvolutionPrinterPass(dbgs()))
>>  FUNCTION_PASS("reassociate", ReassociatePass())
>> +FUNCTION_PASS("sccp", SCCPPass())
>>  FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())
>>  FUNCTION_PASS("sink", SinkingPass())
>>  FUNCTION_PASS("sroa", SROA())
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=269937&r1=269936&r2=269937&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Wed May 18 10:18:25 2016
>> @@ -39,6 +39,7 @@
>>  #include "llvm/Support/raw_ostream.h"
>>  #include "llvm/Transforms/IPO.h"
>>  #include "llvm/Transforms/Scalar.h"
>> +#include "llvm/Transforms/Scalar/SCCP.h"
>>  #include "llvm/Transforms/Utils/Local.h"
>>  #include <algorithm>
>>  using namespace llvm;
>> @@ -1548,53 +1549,12 @@ bool SCCPSolver::ResolvedUndefsIn(Functi
>>    return false;
>>  }
>>
>> -
>> -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,
>> +// runSCCP() - Run the Sparse Conditional Constant Propagation algorithm,
>>  // and return true if the function was modified.
>>  //
>> -bool SCCP::runOnFunction(Function &F) {
>> -  if (skipFunction(F))
>> -    return false;
>> -
>> +static bool runSCCP(Function &F, const DataLayout &DL,
>> +                    const TargetLibraryInfo *TLI) {
>>    DEBUG(dbgs() << "SCCP on function '" << F.getName() << "'\n");
>> -  const DataLayout &DL = F.getParent()->getDataLayout();
>> -  const TargetLibraryInfo *TLI =
>> -      &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
>>    SCCPSolver Solver(DL, TLI);
>>
>>    // Mark the first block of the function as being executable.
>> @@ -1664,6 +1624,54 @@ bool SCCP::runOnFunction(Function &F) {
>>    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();
>
> Should this preserve GlobalsAA like the legacy pass does?
>

Hmm, probably. Should we do the same in Reassociate? It has a similar
problem from what I can see (unless I misread the code).

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list