[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 07:31:28 PST 2023


================
@@ -251,32 +255,50 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool ShouldLinkFiles) {
       }
 
     CurLinkModule = LM.Module.get();
-
-    // TODO: If CloneModule() is updated to support cloning of unmaterialized
-    // modules, we can remove this
     bool Err;
-    if (Error E = CurLinkModule->materializeAll())
-      return false;
 
     // Create a Clone to move to the linker, which preserves the original
     // linking modules, allowing them to be linked again in the future
-    // TODO: Add a ShouldCleanup option to make Cloning optional. When
-    // set, we can pass the original modules to the linker for cleanup
-    std::unique_ptr<llvm::Module> Clone = llvm::CloneModule(*LM.Module);
+    if (ClRelinkBuiltinBitcodePostop) {
----------------
yxsamliu wrote:

you could define a lambda

`auto DoLink = [&](auto& Mod) {
      if (LM.Internalize) {
        Err = Linker::linkModules(
            *M, std::move(Mod), LM.LinkFlags,
            [](llvm::Module &M, const llvm::StringSet<> &GVS) {
              internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
                return !GV.hasName() || (GVS.count(GV.getName()) == 0);
              });
            });
      } else
        Err = Linker::linkModules(*M, std::move(Mod), LM.LinkFlags);
};`

then call this lambda 

https://github.com/llvm/llvm-project/pull/72478


More information about the cfe-commits mailing list