31#define DEBUG_TYPE "elim-avail-extern"
35 cl::desc(
"Convert available_externally into locals, renaming them "
36 "to avoid link-time clashes."));
38STATISTIC(NumRemovals,
"Number of functions removed");
39STATISTIC(NumConversions,
"Number of functions converted");
40STATISTIC(NumVariables,
"Number of global variables removed");
57 assert(
F.hasAvailableExternallyLinkage());
61 return isa<CallBase>(U.getUser());
65 auto OrigName =
F.getName().str();
73 if (
auto *SP =
F.getSubprogram())
74 SP->replaceLinkageName(
MDString::get(
F.getParent()->getContext(), NewName));
85 F.getAddressSpace(), OrigName,
F.getParent());
86 F.replaceUsesWithIf(Decl,
87 [&](
Use &U) {
return !isa<CallBase>(U.getUser()); });
96 if (!GV.hasAvailableExternallyLinkage())
98 if (GV.hasInitializer()) {
100 GV.setInitializer(
nullptr);
102 Init->destroyConstant();
104 GV.removeDeadConstantUsers();
112 if (
F.isDeclaration() || !
F.hasAvailableExternallyLinkage())
120 F.removeDeadConstantUsers();
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.