From a04b0d587a8d260063fe1d50f6fecdc585d75ff4 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 22 Nov 2024 19:48:34 +0100 Subject: 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. --- llvm/lib/IR/Module.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'llvm/lib/IR/Module.cpp') 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(); -- cgit v1.1