26 const Comdat *SC = Src->getComdat();
29 Comdat *DC = Dst->getParent()->getOrInsertComdat(SC->
getName());
56 assert(M.isMaterialized() &&
"Module must be materialized before cloning!");
59 std::unique_ptr<Module> New =
60 std::make_unique<Module>(M.getModuleIdentifier(), M.getContext());
61 New->setSourceFileName(M.getSourceFileName());
62 New->setDataLayout(M.getDataLayout());
63 New->setTargetTriple(M.getTargetTriple());
64 New->setModuleInlineAsm(M.getModuleInlineAsm());
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);
132 if (
I.isDeclaration()) {
136 I.getAllMetadata(MDs);
138 F->addMetadata(MD.first, *
MapMetadata(MD.second, VMap));
142 if (!ShouldCloneDefinition(&
I)) {
146 F->setPersonalityFn(
nullptr);
153 VMap[&J] = &*DestI++;
160 if (
I.hasPersonalityFn())
161 F->setPersonalityFn(
MapValue(
I.getPersonalityFn(), VMap));
169 if (!ShouldCloneDefinition(&
I))
183 for (
const NamedMDNode &NMD : M.named_metadata()) {
184 NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
185 for (
const MDNode *
N : NMD.operands())
197 G.getAllMetadata(MDs);
201 if (
G.isDeclaration())
204 if (!ShouldCloneDefinition(&
G)) {
209 if (
G.hasInitializer())
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void copyComdat(GlobalObject *Dst, const GlobalObject *Src)
Module.h This file contains the declarations for the Module class.
This class represents an incoming formal argument to a Function.
LLVM_ABI StringRef getName() const
void setSelectionKind(SelectionKind Val)
SelectionKind getSelectionKind() const
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 ...
LLVM_ABI void setAliasee(Constant *Aliasee)
These methods retrieve and set alias target.
static LLVM_ABI 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 LLVM_ABI 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.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
void setLinkage(LinkageTypes LT)
@ ExternalLinkage
Externally visible function.
LLVM_ABI void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
LLVM_ABI 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.
LLVM_ABI 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.
LLVM_ABI 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.
Attribute unwrap(LLVMAttributeRef Attr)
LLVM_ABI 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.
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Look up or compute a value in the value map.
LLVMAttributeRef wrap(Attribute Attr)
LLVM_ABI std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Lookup or compute a mapping for a piece of metadata.