28 #define DEBUG_TYPE "elim-avail-extern" 30 STATISTIC(NumFunctions,
"Number of functions removed");
31 STATISTIC(NumVariables,
"Number of global variables removed");
38 if (!GV.hasAvailableExternallyLinkage())
40 if (GV.hasInitializer()) {
42 GV.setInitializer(
nullptr);
46 GV.removeDeadConstantUsers();
54 if (!
F.hasAvailableExternallyLinkage())
56 if (!
F.isDeclaration())
59 F.removeDeadConstantUsers();
76 struct EliminateAvailableExternallyLegacyPass :
public ModulePass {
79 EliminateAvailableExternallyLegacyPass() :
ModulePass(ID) {
86 bool runOnModule(
Module &M)
override {
98 "Eliminate Available Externally Globals",
false,
false)
101 return new EliminateAvailableExternallyLegacyPass();
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
Externally visible function.
STATISTIC(NumFunctions, "Total number of functions")
ModulePass * createEliminateAvailableExternallyPass()
This transform is designed to eliminate available external globals (functions or global variables) ...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static bool eliminateAvailableExternally(Module &M)
A set of analyses that are preserved following a run of a transformation pass.
void initializeEliminateAvailableExternallyLegacyPassPass(PassRegistry &)
This is an important base class in LLVM.
bool isSafeToDestroyConstant(const Constant *C)
It is safe to destroy a constant iff it is only used by constants itself.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Module.h This file contains the declarations for the Module class.
INITIALIZE_PASS(EliminateAvailableExternallyLegacyPass, "elim-avail-extern", "Eliminate Available Externally Globals", false, false) ModulePass *llvm
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
void destroyConstant()
Called if some element of this constant is no longer valid.
iterator_range< global_iterator > globals()
A container for analyses that lazily runs them and caches their results.