27class PreserveLibCallsAndAsmUsed {
29 PreserveLibCallsAndAsmUsed(
const StringSet<> &AsmUndefinedRefs,
30 const TargetMachine &TM,
31 std::vector<GlobalValue *> &LLVMUsed)
32 : AsmUndefinedRefs(AsmUndefinedRefs), TM(TM), LLVMUsed(LLVMUsed) {}
34 void findInModule(
Module &TheModule) {
36 for (Function &
F : TheModule)
37 findLibCallsAndAsm(
F);
38 for (GlobalVariable &GV : TheModule.globals())
39 findLibCallsAndAsm(GV);
40 for (GlobalAlias &GA : TheModule.aliases())
41 findLibCallsAndAsm(GA);
46 const StringSet<> &AsmUndefinedRefs;
47 const TargetMachine &TM;
50 llvm::Mangler Mangler;
54 std::vector<GlobalValue *> &LLVMUsed;
60 TargetLibraryInfoImpl TLII(TM.getTargetTriple());
61 TargetLibraryInfo TLI(TLII);
65 for (
unsigned I = 0,
E =
static_cast<unsigned>(LibFunc::NumLibFuncs);
69 Libcalls.insert(TLI.getName(
F));
72 SmallPtrSet<const TargetLowering *, 1> TLSet;
74 for (
const Function &
F : TheModule) {
76 TM.getSubtargetImpl(
F)->getTargetLowering();
81 for (
unsigned I = 0,
E =
static_cast<unsigned>(RTLIB::UNKNOWN_LIBCALL);
83 if (
const char *Name =
84 Lowering->getLibcallName(
static_cast<RTLIB::Libcall
>(
I)))
85 Libcalls.insert(Name);
89 void findLibCallsAndAsm(GlobalValue &GV) {
104 GlobalValue *FuncAliasee =
nullptr;
110 LLVMUsed.push_back(&GV);
114 SmallString<64> Buffer;
115 TM.getNameWithPrefix(Buffer, &GV, Mangler);
116 if (AsmUndefinedRefs.count(Buffer))
117 LLVMUsed.push_back(&GV);
125 std::vector<GlobalValue *> UsedValues;
126 PreserveLibCallsAndAsmUsed(AsmUndefinedRefs, TM, UsedValues)
127 .findInModule(TheModule);
129 if (UsedValues.empty())
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
This file describes how to lower LLVM code to machine code.
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool hasPrivateLinkage() const
A Module instance is used to store all the information related to an LLVM module.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
StringSet - A wrapper for StringMap that provides set-like functionality.
Primary interface to the complete machine description for the target machine.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void updateCompilerUsed(Module &TheModule, const TargetMachine &TM, const StringSet<> &AsmUndefinedRefs)
Find all globals in TheModule that are referenced in AsmUndefinedRefs, as well as the user-supplied f...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.