diff options
author | Mehdi Amini <joker.eph@gmail.com> | 2024-11-22 19:48:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-22 19:48:34 +0100 |
commit | a04b0d587a8d260063fe1d50f6fecdc585d75ff4 (patch) | |
tree | 1ca80cb42bd8061fe8fa26b75c71b72feb040aec /llvm/lib/IR/Module.cpp | |
parent | f170f5fa80f244ccac51e9867de3ad823512a2d4 (diff) | |
download | llvm-a04b0d587a8d260063fe1d50f6fecdc585d75ff4.zip llvm-a04b0d587a8d260063fe1d50f6fecdc585d75ff4.tar.gz llvm-a04b0d587a8d260063fe1d50f6fecdc585d75ff4.tar.bz2 |
Implement Move-assignment for llvm::Module (NFC) (#117270)
Move-assignment is quite convenient in various situation, and
work-around having it available is very convoluted.
Diffstat (limited to 'llvm/lib/IR/Module.cpp')
-rw-r--r-- | llvm/lib/IR/Module.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp index 7f5c015..c7b9f87 100644 --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -77,6 +77,41 @@ Module::Module(StringRef MID, LLVMContext &C) Context.addModule(this); } +Module &Module::operator=(Module &&Other) { + assert(&Context == &Other.Context && "Module must be in the same Context"); + + dropAllReferences(); + + ModuleID = std::move(Other.ModuleID); + SourceFileName = std::move(Other.SourceFileName); + IsNewDbgInfoFormat = std::move(Other.IsNewDbgInfoFormat); + + GlobalList.clear(); + GlobalList.splice(GlobalList.begin(), Other.GlobalList); + + FunctionList.clear(); + FunctionList.splice(FunctionList.begin(), Other.FunctionList); + + AliasList.clear(); + AliasList.splice(AliasList.begin(), Other.AliasList); + + IFuncList.clear(); + IFuncList.splice(IFuncList.begin(), Other.IFuncList); + + NamedMDList.clear(); + NamedMDList.splice(NamedMDList.begin(), Other.NamedMDList); + GlobalScopeAsm = std::move(Other.GlobalScopeAsm); + OwnedMemoryBuffer = std::move(Other.OwnedMemoryBuffer); + Materializer = std::move(Other.Materializer); + TargetTriple = std::move(Other.TargetTriple); + DL = std::move(Other.DL); + CurrentIntrinsicIds = std::move(Other.CurrentIntrinsicIds); + UniquedIntrinsicNames = std::move(Other.UniquedIntrinsicNames); + ModuleFlags = std::move(Other.ModuleFlags); + Context.addModule(this); + return *this; +} + Module::~Module() { Context.removeModule(this); dropAllReferences(); |