mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-12 05:40:30 +00:00
PM: Port GlobalOpt to the new pass manager
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267499 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
183519d6d0
commit
1a9ed3005a
@ -141,7 +141,7 @@ void initializeGCMachineCodeAnalysisPass(PassRegistry&);
|
||||
void initializeGCModuleInfoPass(PassRegistry&);
|
||||
void initializeGVNLegacyPassPass(PassRegistry&);
|
||||
void initializeGlobalDCEPass(PassRegistry&);
|
||||
void initializeGlobalOptPass(PassRegistry&);
|
||||
void initializeGlobalOptLegacyPassPass(PassRegistry&);
|
||||
void initializeGlobalsAAWrapperPassPass(PassRegistry&);
|
||||
void initializeIPCPPass(PassRegistry&);
|
||||
void initializeIPSCCPPass(PassRegistry&);
|
||||
|
32
include/llvm/Transforms/IPO/GlobalOpt.h
Normal file
32
include/llvm/Transforms/IPO/GlobalOpt.h
Normal file
@ -0,0 +1,32 @@
|
||||
//===- GlobalOpt.h - Optimize Global Variables ------------------*- 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 simple global variables that never have their address
|
||||
// taken. If obviously true, it marks read/write globals as constant, deletes
|
||||
// variables only stored to, etc.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_IPO_GLOBALOPT_H
|
||||
#define LLVM_TRANSFORMS_IPO_GLOBALOPT_H
|
||||
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// Optimize globals that never have their address taken.
|
||||
class GlobalOptPass : public PassInfoMixin<GlobalOptPass> {
|
||||
public:
|
||||
PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LLVM_TRANSFORMS_IPO_GLOBALOPT_H
|
@ -98,7 +98,7 @@ void LTOCodeGenerator::initializeLTOPasses() {
|
||||
|
||||
initializeInternalizePassPass(R);
|
||||
initializeIPSCCPPass(R);
|
||||
initializeGlobalOptPass(R);
|
||||
initializeGlobalOptLegacyPassPass(R);
|
||||
initializeConstantMergePass(R);
|
||||
initializeDAHPass(R);
|
||||
initializeInstructionCombiningPassPass(R);
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
|
||||
#include "llvm/Transforms/IPO/FunctionAttrs.h"
|
||||
#include "llvm/Transforms/IPO/GlobalOpt.h"
|
||||
#include "llvm/Transforms/IPO/InferFunctionAttrs.h"
|
||||
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
|
||||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||
|
@ -36,6 +36,7 @@ MODULE_ALIAS_ANALYSIS("globals-aa", GlobalsAA())
|
||||
#define MODULE_PASS(NAME, CREATE_PASS)
|
||||
#endif
|
||||
MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
|
||||
MODULE_PASS("globalopt", GlobalOptPass())
|
||||
MODULE_PASS("inferattrs", InferFunctionAttrsPass())
|
||||
MODULE_PASS("instrprof", InstrProfiling())
|
||||
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
||||
|
@ -13,7 +13,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
#include "llvm/Transforms/IPO/GlobalOpt.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
@ -40,6 +40,7 @@
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
#include "llvm/Transforms/Utils/CtorUtils.h"
|
||||
#include "llvm/Transforms/Utils/Evaluator.h"
|
||||
#include "llvm/Transforms/Utils/GlobalStatus.h"
|
||||
@ -64,31 +65,6 @@ STATISTIC(NumAliasesResolved, "Number of global aliases resolved");
|
||||
STATISTIC(NumAliasesRemoved, "Number of global aliases eliminated");
|
||||
STATISTIC(NumCXXDtorsRemoved, "Number of global C++ destructors removed");
|
||||
|
||||
namespace {
|
||||
struct GlobalOpt : public ModulePass {
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
}
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
GlobalOpt() : ModulePass(ID) {
|
||||
initializeGlobalOptPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnModule(Module &M) override;
|
||||
};
|
||||
}
|
||||
|
||||
char GlobalOpt::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(GlobalOpt, "globalopt",
|
||||
"Global Variable Optimizer", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_END(GlobalOpt, "globalopt",
|
||||
"Global Variable Optimizer", false, false)
|
||||
|
||||
ModulePass *llvm::createGlobalOptimizerPass() { return new GlobalOpt(); }
|
||||
|
||||
/// Is this global variable possibly used by a leak checker as a root? If so,
|
||||
/// we might not really want to eliminate the stores to it.
|
||||
static bool isLeakCheckerRoot(GlobalVariable *GV) {
|
||||
@ -2530,19 +2506,11 @@ static bool OptimizeEmptyGlobalCXXDtors(Function *CXAAtExitFn) {
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool GlobalOpt::runOnModule(Module &M) {
|
||||
if (skipModule(M))
|
||||
return false;
|
||||
|
||||
bool Changed = false;
|
||||
|
||||
auto &DL = M.getDataLayout();
|
||||
auto *TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
||||
auto LookupDomTree = [this](Function &F) -> DominatorTree & {
|
||||
return this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
|
||||
};
|
||||
|
||||
static bool optimizeGlobalsInModule(
|
||||
Module &M, const DataLayout &DL, TargetLibraryInfo *TLI,
|
||||
function_ref<DominatorTree &(Function &)> LookupDomTree) {
|
||||
SmallSet<const Comdat *, 8> NotDiscardableComdats;
|
||||
bool Changed = false;
|
||||
bool LocalChange = true;
|
||||
while (LocalChange) {
|
||||
LocalChange = false;
|
||||
@ -2591,3 +2559,54 @@ bool GlobalOpt::runOnModule(Module &M) {
|
||||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
PreservedAnalyses GlobalOptPass::run(Module &M, AnalysisManager<Module> &AM) {
|
||||
auto &DL = M.getDataLayout();
|
||||
auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
|
||||
auto &FAM =
|
||||
AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
|
||||
auto LookupDomTree = [&FAM](Function &F) -> DominatorTree &{
|
||||
return FAM.getResult<DominatorTreeAnalysis>(F);
|
||||
};
|
||||
if (!optimizeGlobalsInModule(M, DL, &TLI, LookupDomTree))
|
||||
return PreservedAnalyses::all();
|
||||
return PreservedAnalyses::none();
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct GlobalOptLegacyPass : public ModulePass {
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
GlobalOptLegacyPass() : ModulePass(ID) {
|
||||
initializeGlobalOptLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnModule(Module &M) override {
|
||||
if (skipModule(M))
|
||||
return false;
|
||||
|
||||
auto &DL = M.getDataLayout();
|
||||
auto *TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
|
||||
auto LookupDomTree = [this](Function &F) -> DominatorTree & {
|
||||
return this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
|
||||
};
|
||||
return optimizeGlobalsInModule(M, DL, TLI, LookupDomTree);
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char GlobalOptLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(GlobalOptLegacyPass, "globalopt",
|
||||
"Global Variable Optimizer", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_END(GlobalOptLegacyPass, "globalopt",
|
||||
"Global Variable Optimizer", false, false)
|
||||
|
||||
ModulePass *llvm::createGlobalOptimizerPass() {
|
||||
return new GlobalOptLegacyPass();
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
|
||||
initializeDAHPass(Registry);
|
||||
initializeForceFunctionAttrsLegacyPassPass(Registry);
|
||||
initializeGlobalDCEPass(Registry);
|
||||
initializeGlobalOptPass(Registry);
|
||||
initializeGlobalOptLegacyPassPass(Registry);
|
||||
initializeIPCPPass(Registry);
|
||||
initializeAlwaysInlinerPass(Registry);
|
||||
initializeSimpleInlinerPass(Registry);
|
||||
|
@ -1,4 +1,5 @@
|
||||
; RUN: opt < %s -globalopt -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=globalopt -S | FileCheck %s
|
||||
|
||||
; CHECK-NOT: global
|
||||
@X = internal global i32 4 ; <i32*> [#uses=1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user