39 if (!ExportGV.hasLocalLinkage())
42 auto Name = ExportGV.getName();
44 if ((!ImportGV || ImportGV->
use_empty()) && !PromoteExtra.
count(&ExportGV))
47 std::string NewName = (
Name + ModuleId).str();
49 if (
const auto *
C = ExportGV.getComdat())
50 if (
C->getName() ==
Name)
53 ExportGV.setName(NewName);
63 if (!RenamedComdats.
empty())
65 if (
auto *
C = GO.getComdat()) {
66 auto Replacement = RenamedComdats.
find(
C);
67 if (Replacement != RenamedComdats.
end())
68 GO.setComdat(Replacement->second);
79 auto ExternalizeTypeId = [&](
CallInst *CI,
unsigned ArgNo) {
81 cast<MetadataAsValue>(CI->
getArgOperand(ArgNo))->getMetadata();
83 if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
84 Metadata *&GlobalMD = LocalToGlobal[MD];
98 for (
const Use &U : TypeTestFunc->
uses()) {
99 auto CI = cast<CallInst>(U.getUser());
100 ExternalizeTypeId(CI, 1);
106 for (
const Use &U : TypeCheckedLoadFunc->
uses()) {
107 auto CI = cast<CallInst>(U.getUser());
108 ExternalizeTypeId(CI, 2);
117 for (
auto MD : MDs) {
118 auto I = LocalToGlobal.
find(MD->getOperand(1));
119 if (
I == LocalToGlobal.
end()) {
133 void simplifyExternals(
Module &M) {
169 if (ShouldKeepDefinition(GA))
179 nullptr,
"",
nullptr,
187 if (ShouldKeepDefinition(&F))
196 if (ShouldKeepDefinition(&GV))
207 if (
auto *F = dyn_cast<Function>(C))
209 if (isa<GlobalValue>(C))
212 forEachVirtualFunction(cast<Constant>(
Op), Fn);
218 void splitAndWriteThinLTOBitcode(
222 if (ModuleId.empty()) {
233 promoteTypeIds(M, ModuleId);
256 std::set<const Function *> EligibleVirtualFns;
261 if (HasTypeMetadata(&GV)) {
266 if (!RT || RT->getBitWidth() > 64 || F->
arg_empty() ||
271 if (!ArgT || ArgT->getBitWidth() > 64)
276 EligibleVirtualFns.insert(F);
281 std::unique_ptr<Module> MergedM(
284 if (MergedMComdats.
count(C))
286 if (
auto *F = dyn_cast<Function>(GV))
287 return EligibleVirtualFns.
count(F);
288 if (
auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->
getBaseObject()))
289 return HasTypeMetadata(GVar);
311 if (
auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->
getBaseObject()))
312 if (HasTypeMetadata(GVar))
315 if (MergedMComdats.
count(C))
320 promoteInternals(*MergedM, M, ModuleId, CfiFunctions);
321 promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
324 for (
auto V : CfiFunctions) {
341 for (
auto Type : Types)
346 if(!CfiFunctionMDs.
empty()) {
347 NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata(
"cfi.functions");
348 for (
auto MD : CfiFunctionMDs)
352 simplifyExternals(*MergedM);
371 W.writeModule(&M,
false, &Index,
373 W.writeModule(MergedM.get(),
false,
386 W2.writeModule(&M,
false, &Index,
388 W2.writeModule(MergedM.get(),
false,
392 *ThinLinkOS << Buffer;
397 bool requiresSplit(
Module &M) {
412 if (requiresSplit(M))
413 return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
433 class WriteThinLTOBitcode :
public ModulePass {
450 StringRef getPassName()
const override {
return "ThinLTO Bitcode Writer"; }
452 bool runOnModule(
Module &M)
override {
454 &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex());
469 "Write ThinLTO Bitcode",
false,
true)
478 return new WriteThinLTOBitcode(Str, ThinLinkOS);
485 writeThinLTOBitcode(OS, ThinLinkOS,
void setVisibility(VisibilityTypes V)
void push_back(const T &Elt)
ModulePass * createWriteThinLTOBitcodePass(raw_ostream &Str, raw_ostream *ThinLinkOS=nullptr)
Write ThinLTO-ready bitcode to Str.
iterator_range< use_iterator > uses()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
VisibilityTypes getVisibility() const
A Module instance is used to store all the information related to an LLVM module. ...
static MDString * get(LLVMContext &Context, StringRef Str)
This is the interface to build a ModuleSummaryIndex for a module.
Implements a dense probed hash-table based set.
Available for inspection, not emission.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Analysis providing profile information.
Type * getValueType() const
void addOperand(MDNode *M)
This class represents a function call, abstracting a target machine's calling convention.
An immutable pass that tracks lazily created AssumptionCache objects.
An efficient, type-erasing, non-owning reference to a callable.
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
Externally visible function.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
const Comdat * getComdat() const
Analysis pass to provide the ModuleSummaryIndex object.
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI)
Direct function to compute a ModuleSummaryIndex from a given module.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
StringRef getName() const
Return a constant reference to the value's name.
iterator_range< global_object_iterator > global_objects()
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
A Use represents the edge between a Value definition and its users.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class is a functor to be used in legacy module or SCC passes for computing AA results for a func...
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
const GlobalObject * getBaseObject() const
void setName(const Twine &Name)
Change the name of the value.
LLVM_NODISCARD bool empty() const
global_iterator global_begin()
Class to represent function types.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
bool insert(const value_type &X)
Insert a new element into the SetVector.
void setComdat(Comdat *C)
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
iterator find(const_arg_type_t< KeyT > Val)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
void WriteBitcodeToFile(const Module *M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
Type * getReturnType() const
Returns the type of the ret val.
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
A set of analyses that are preserved following a run of a transformation pass.
alias_iterator alias_end()
write thinlto Write ThinLTO Bitcode
The instances of the Type class are immutable: once they are created, they are never changed...
FunctionType * getFunctionType() const
Returns the FunctionType for me.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
const Comdat * getComdat() const
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
A manager for alias analyses.
std::pair< iterator, bool > insert(const ValueT &V)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
Class to represent integer types.
std::unique_ptr< Module > CloneModule(const Module *M)
Return an exact copy of the specified module.
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...
static void write(bool isBE, void *P, T V)
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
global_iterator global_end()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
void initializeWriteThinLTOBitcodePass(PassRegistry &)
bool isFunctionTy() const
True if this is an instance of FunctionType.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
alias_iterator alias_begin()
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
void setLinkage(LinkageTypes LT)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
void setPreservesAll()
Set by analyses that do not transform their input at all.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
ThreadLocalMode getThreadLocalMode() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
PointerType * getType() const
Global values are always pointers.
bool hasAddressTaken(const User **=nullptr) const
hasAddressTaken - returns true if there are any uses of this function other than direct calls or invo...
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
void setArgOperand(unsigned i, Value *v)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Provides passes for computing function attributes based on interprocedural analyses.
LLVMContext & getContext() const
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
bool hasLocalLinkage() const
LLVM_NODISCARD bool empty() const
const std::string to_string(const T &Value)
write thinlto Write ThinLTO false
LLVM Value Representation.
A vector that has set insertion semantics.
This class implements an extremely fast bulk output stream that can only output to a stream...
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
This is the interface for LLVM's primary stateless and local alias analysis.
A container for analyses that lazily runs them and caches their results.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
This header defines various interfaces for pass management in LLVM.
iterator_range< global_value_iterator > global_values()
bool isDeclarationForLinker() const
static IntegerType * getInt8Ty(LLVMContext &C)
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode,"write-thinlto-bitcode","Write ThinLTO Bitcode", false, true) INITIALIZE_PASS_END(WriteThinLTOBitcode
LLVMContext & getContext() const
Get the global data context.
Legacy wrapper pass to provide the ModuleSummaryIndex object.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...