llvm.org GIT mirror llvm / e44aed7
[PM] Port EliminateAvailableExternally pass to the new pass manager. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268599 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
7 changed file(s) with 72 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
135135 void initializeEfficiencySanitizerPass(PassRegistry&);
136136 void initializeScalarizerPass(PassRegistry&);
137137 void initializeEarlyCSELegacyPassPass(PassRegistry &);
138 void initializeEliminateAvailableExternallyPass(PassRegistry&);
138 void initializeEliminateAvailableExternallyLegacyPassPass(PassRegistry &);
139139 void initializeExpandISelPseudosPass(PassRegistry&);
140140 void initializeForceFunctionAttrsLegacyPassPass(PassRegistry&);
141141 void initializeGCMachineCodeAnalysisPass(PassRegistry&);
0 //===- ElimAvailExtern.h - Optimize Global Variables ------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This transform is designed to eliminate available external global
10 // definitions from the program, turning them into declarations.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TRANSFORMS_IPO_ELIMAVAILEXTERN_H
15 #define LLVM_TRANSFORMS_IPO_ELIMAVAILEXTERN_H
16
17 #include "llvm/IR/Module.h"
18 #include "llvm/IR/PassManager.h"
19
20 namespace llvm {
21
22 /// A pass that transforms external global definitions into declarations.
23 class EliminateAvailableExternallyPass
24 : public PassInfoMixin {
25 public:
26 PreservedAnalyses run(Module &M);
27 };
28 }
29
30 #endif // LLVM_TRANSFORMS_IPO_ELIMAVAILEXTERN_H
4545 #include "llvm/Support/Regex.h"
4646 #include "llvm/Target/TargetMachine.h"
4747 #include "llvm/Transforms/IPO/ConstantMerge.h"
48 #include "llvm/Transforms/IPO/ElimAvailExtern.h"
4849 #include "llvm/Transforms/IPO/ForceFunctionAttrs.h"
4950 #include "llvm/Transforms/IPO/FunctionAttrs.h"
5051 #include "llvm/Transforms/IPO/GlobalDCE.h"
3535 #define MODULE_PASS(NAME, CREATE_PASS)
3636 #endif
3737 MODULE_PASS("constmerge", ConstantMergePass())
38 MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
3839 MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
3940 MODULE_PASS("globaldce", GlobalDCEPass())
4041 MODULE_PASS("globalopt", GlobalOptPass())
1212 //
1313 //===----------------------------------------------------------------------===//
1414
15 #include "llvm/Transforms/IPO.h"
15 #include "llvm/Transforms/IPO/ElimAvailExtern.h"
1616 #include "llvm/ADT/Statistic.h"
1717 #include "llvm/IR/Constants.h"
1818 #include "llvm/IR/Module.h"
19 #include "llvm/Transforms/IPO.h"
1920 #include "llvm/Transforms/Utils/GlobalStatus.h"
2021 #include "llvm/Pass.h"
2122 using namespace llvm;
2526 STATISTIC(NumFunctions, "Number of functions removed");
2627 STATISTIC(NumVariables, "Number of global variables removed");
2728
28 namespace {
29 struct EliminateAvailableExternally : public ModulePass {
30 static char ID; // Pass identification, replacement for typeid
31 EliminateAvailableExternally() : ModulePass(ID) {
32 initializeEliminateAvailableExternallyPass(
33 *PassRegistry::getPassRegistry());
34 }
35
36 // run - Do the EliminateAvailableExternally pass on the specified module,
37 // optionally updating the specified callgraph to reflect the changes.
38 //
39 bool runOnModule(Module &M) override;
40 };
41 }
42
43 char EliminateAvailableExternally::ID = 0;
44 INITIALIZE_PASS(EliminateAvailableExternally, "elim-avail-extern",
45 "Eliminate Available Externally Globals", false, false)
46
47 ModulePass *llvm::createEliminateAvailableExternallyPass() {
48 return new EliminateAvailableExternally();
49 }
50
51 bool EliminateAvailableExternally::runOnModule(Module &M) {
52 if (skipModule(M))
53 return false;
54
29 static bool eliminateAvailableExternally(Module &M) {
5530 bool Changed = false;
5631
5732 // Drop initializers of available externally global variables.
8459
8560 return Changed;
8661 }
62
63 PreservedAnalyses EliminateAvailableExternallyPass::run(Module &M) {
64 if (!eliminateAvailableExternally(M))
65 return PreservedAnalyses::all();
66 return PreservedAnalyses::none();
67 }
68
69 namespace {
70 struct EliminateAvailableExternallyLegacyPass : public ModulePass {
71 static char ID; // Pass identification, replacement for typeid
72 EliminateAvailableExternallyLegacyPass() : ModulePass(ID) {
73 initializeEliminateAvailableExternallyLegacyPassPass(
74 *PassRegistry::getPassRegistry());
75 }
76
77 // run - Do the EliminateAvailableExternally pass on the specified module,
78 // optionally updating the specified callgraph to reflect the changes.
79 //
80 bool runOnModule(Module &M) {
81 if (skipModule(M))
82 return false;
83 return eliminateAvailableExternally(M);
84 }
85 };
86 }
87
88 char EliminateAvailableExternallyLegacyPass::ID = 0;
89 INITIALIZE_PASS(EliminateAvailableExternallyLegacyPass, "elim-avail-extern",
90 "Eliminate Available Externally Globals", false, false)
91
92 ModulePass *llvm::createEliminateAvailableExternallyPass() {
93 return new EliminateAvailableExternallyLegacyPass();
94 }
5050 initializeStripDeadDebugInfoPass(Registry);
5151 initializeStripNonDebugSymbolsPass(Registry);
5252 initializeBarrierNoopPass(Registry);
53 initializeEliminateAvailableExternallyPass(Registry);
53 initializeEliminateAvailableExternallyLegacyPassPass(Registry);
5454 initializeSampleProfileLoaderPass(Registry);
5555 initializeFunctionImportPassPass(Registry);
5656 initializeWholeProgramDevirtPass(Registry);
None ; RUN: opt -elim-avail-extern -S < %s | FileCheck %s
0 ; RUN: opt -passes=elim-avail-extern -S < %s | FileCheck %s
11
22 ; CHECK: declare hidden void @f()
33 define available_externally hidden void @f() {