LLVM: lib/Transforms/IPO/ElimAvailExtern.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
28
29using namespace llvm;
30
31#define DEBUG_TYPE "elim-avail-extern"
32
35 cl::desc("Convert available_externally into locals, renaming them "
36 "to avoid link-time clashes."));
37
38STATISTIC(NumRemovals, "Number of functions removed");
39STATISTIC(NumConversions, "Number of functions converted");
40STATISTIC(NumVariables, "Number of global variables removed");
41
43
44 F.deleteBody();
45 ++NumRemovals;
46}
47
48
49
50
51
52
53
54
55
57 assert(F.hasAvailableExternallyLinkage());
58 assert(.isDeclaration());
59
61 return isa(U.getUser());
62 }))
64
65 auto OrigName = F.getName().str();
66
67
68
69
70
72 F.setName(NewName);
73 if (auto *SP = F.getSubprogram())
74 SP->replaceLinkageName(MDString::get(F.getParent()->getContext(), NewName));
75
77
78
79
80
81
82
83 auto *Decl =
85 F.getAddressSpace(), OrigName, F.getParent());
86 F.replaceUsesWithIf(Decl,
87 [&](Use &U) { return !isa(U.getUser()); });
88 ++NumConversions;
89}
90
92 bool Changed = false;
93
94
96 if (!GV.hasAvailableExternallyLinkage())
97 continue;
98 if (GV.hasInitializer()) {
100 GV.setInitializer(nullptr);
102 Init->destroyConstant();
103 }
104 GV.removeDeadConstantUsers();
106 ++NumVariables;
107 Changed = true;
108 }
109
110
112 if (F.isDeclaration() || .hasAvailableExternallyLinkage())
113 continue;
114
117 else
119
120 F.removeDeadConstantUsers();
121 Changed = true;
122 }
123
124 return Changed;
125}
126
130
131
132
133
134
135
139}
static void convertToLocalCopy(Module &M, Function &F)
Create a copy of the thinlto import, mark it local, and redirect direct calls to the copy.
cl::opt< bool > ConvertToLocal("avail-extern-to-local", cl::Hidden, cl::desc("Convert available_externally into locals, renaming them " "to avoid link-time clashes."))
void deleteFunction(Function &F)
static bool eliminateAvailableExternally(Module &M, bool Convert)
Module.h This file contains the declarations for the Module class.
ModuleAnalysisManager MAM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A container for analyses that lazily runs them and caches their results.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
This is an important base class in LLVM.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
@ InternalLinkage
Rename collisions when linking (static functions).
@ ExternalLinkage
Externally visible function.
static MDString * get(LLVMContext &Context, StringRef Str)
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A Use represents the edge between a Value definition and its users.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool isSafeToDestroyConstant(const Constant *C)
It is safe to destroy a constant iff it is only used by constants itself.
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.