38#define DEBUG_TYPE "internalize"
40STATISTIC(NumAliases,
"Number of aliases internalized");
41STATISTIC(NumFunctions,
"Number of functions internalized");
42STATISTIC(NumGlobals,
"Number of global vars internalized");
48 cl::desc(
"A file containing list of symbol names to preserve"));
58class PreserveAPIList {
79 errs() <<
"WARNING: when loading pattern: '"
80 <<
toString(GlobOrErr.takeError()) <<
"' ignoring";
91 errs() <<
"WARNING: Internalize couldn't load file '" <<
Filename
92 <<
"'! Continuing as if it's empty.\n";
95 Buf = std::move(*BufOrErr);
100 std::shared_ptr<MemoryBuffer> Buf;
104bool InternalizePass::shouldPreserveGV(
const GlobalValue &GV) {
119 if (
const auto *
G = dyn_cast<GlobalVariable>(&GV))
120 if (
G->isExternallyInitialized())
131 return MustPreserveGV(GV);
134bool InternalizePass::maybeInternalize(
140 if (ComdatMap.
lookup(
C).External)
143 if (
auto *GO = dyn_cast<GlobalObject>(&GV)) {
150 ComdatInfo &
Info = ComdatMap.
find(
C)->second;
152 GO->setComdat(
nullptr);
163 if (shouldPreserveGV(GV))
174void InternalizePass::checkComdat(
182 if (shouldPreserveGV(GV))
183 Info.External =
true;
187 bool Changed =
false;
194 if (!M.getComdatSymbolTable().empty()) {
196 checkComdat(
F, ComdatMap);
198 checkComdat(GV, ComdatMap);
200 checkComdat(GA, ComdatMap);
213 AlwaysPreserved.
insert(V->getName());
219 AlwaysPreserved.
insert(
"llvm.used");
220 AlwaysPreserved.
insert(
"llvm.compiler.used");
224 AlwaysPreserved.
insert(
"llvm.global_ctors");
225 AlwaysPreserved.
insert(
"llvm.global_dtors");
226 AlwaysPreserved.
insert(
"llvm.global.annotations");
231 AlwaysPreserved.
insert(
"__stack_chk_fail");
233 AlwaysPreserved.
insert(
"__ssp_canary_word");
235 AlwaysPreserved.
insert(
"__stack_chk_guard");
240 if (!maybeInternalize(
I, ComdatMap))
250 for (
auto &GV : M.globals()) {
251 if (!maybeInternalize(GV, ComdatMap))
260 for (
auto &GA : M.aliases()) {
261 if (!maybeInternalize(GA, ComdatMap))
266 LLVM_DEBUG(
dbgs() <<
"Internalized alias " << GA.getName() <<
"\n");
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Analysis containing CSE Info
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
static cl::list< std::string > APIList("internalize-public-api-list", cl::value_desc("list"), cl::desc("A list of symbol names to preserve"), cl::CommaSeparated)
static cl::opt< std::string > APIFile("internalize-public-api-file", cl::value_desc("filename"), cl::desc("A file containing list of symbol names to preserve"))
Module.h This file contains the declarations for the Module class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
StringSet - A set-like wrapper for the StringMap.
A container for analyses that lazily runs them and caches their results.
@ NoDeduplicate
No deduplication is performed.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
Represents either an error or a value T.
bool match(StringRef S) const
static Expected< GlobPattern > create(StringRef Pat)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool hasLocalLinkage() const
const Comdat * getComdat() const
void setLinkage(LinkageTypes LT)
bool hasDLLExportStorageClass() const
@ DefaultVisibility
The GV is visible.
void setVisibility(VisibilityTypes V)
bool hasAvailableExternallyLinkage() const
@ InternalLinkage
Rename collisions when linking (static functions).
bool internalizeModule(Module &TheModule)
Run the internalizer on TheModule, returns true if any changes was made.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
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.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
StringRef - Represent a constant reference to a string, i.e.
std::pair< typename Base::iterator, bool > insert(StringRef key)
Triple - Helper class for working with autoconf configuration names.
bool isOSBinFormatWasm() const
Tests whether the OS uses the Wasm binary format.
bool isOSAIX() const
Tests whether the OS is AIX.
StringRef getName() const
Return a constant reference to the value's name.
A forward iterator which reads text lines from a buffer.
@ C
The default llvm calling convention, compatible with C.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...