25 const Comdat *SC = Src->getComdat();
28 Comdat *DC = Dst->getParent()->getOrInsertComdat(SC->getName());
55 assert(M.isMaterialized() &&
"Module must be materialized before cloning!");
58 std::unique_ptr<Module> New =
59 std::make_unique<Module>(M.getModuleIdentifier(), M.getContext());
60 New->setSourceFileName(M.getSourceFileName());
61 New->setDataLayout(M.getDataLayout());
62 New->setTargetTriple(M.getTargetTriple());
63 New->setModuleInlineAsm(M.getModuleInlineAsm());
64 New->IsNewDbgInfoFormat = M.IsNewDbgInfoFormat;
72 *New,
I.getValueType(),
I.isConstant(),
I.getLinkage(),
74 I.getThreadLocalMode(),
I.getType()->getAddressSpace());
83 I.getAddressSpace(),
I.getName(), New.get());
90 if (!ShouldCloneDefinition(&
I)) {
96 if (
I.getValueType()->isFunctionTy())
99 I.getName(), New.get());
103 I.getName(),
nullptr,
I.getThreadLocalMode(),
104 I.getType()->getAddressSpace());
112 I.getType()->getPointerAddressSpace(),
113 I.getLinkage(),
I.getName(), New.get());
114 GA->copyAttributesFrom(&
I);
122 I.getLinkage(),
I.getName(),
nullptr, New.get());
123 GI->copyAttributesFrom(&
I);
135 G.getAllMetadata(MDs);
139 if (
G.isDeclaration())
142 if (!ShouldCloneDefinition(&
G)) {
147 if (
G.hasInitializer())
158 if (
I.isDeclaration()) {
162 I.getAllMetadata(MDs);
164 F->addMetadata(MD.first, *
MapMetadata(MD.second, VMap));
168 if (!ShouldCloneDefinition(&
I)) {
172 F->setPersonalityFn(
nullptr);
179 VMap[&J] = &*DestI++;
186 if (
I.hasPersonalityFn())
187 F->setPersonalityFn(
MapValue(
I.getPersonalityFn(), VMap));
195 if (!ShouldCloneDefinition(&
I))
209 for (
const NamedMDNode &NMD : M.named_metadata()) {
210 NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
211 for (
const MDNode *
N : NMD.operands())
static void copyComdat(GlobalObject *Dst, const GlobalObject *Src)
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents an incoming formal argument to a Function.
void setSelectionKind(SelectionKind Val)
This is an important base class in LLVM.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
static GlobalIFunc * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Resolver, Module *Parent)
If a parent module is specified, the ifunc is automatically inserted into the end of the specified mo...
void setResolver(Constant *Resolver)
These methods retrieve and set ifunc resolver function.
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
void setLinkage(LinkageTypes LT)
@ ExternalLinkage
Externally visible function.
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
A Module instance is used to store all the information related to an LLVM module.
void addOperand(MDNode *M)
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void setName(const Twine &Name)
Change the name of the value.
An efficient, type-erasing, non-owning reference to a callable.
LLVMModuleRef LLVMCloneModule(LLVMModuleRef M)
Return an exact copy of the specified module.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Lookup or compute a mapping for a piece of metadata.
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Look up or compute a value in the value map.
Attribute unwrap(LLVMAttributeRef Attr)
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, CloneFunctionChangeType Changes, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values.
LLVMAttributeRef wrap(Attribute Attr)
std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.