[clang] [CodeGen] Add conditional to module cloning in bitcode linking (PR #72478)
Jacob Lambert via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 15 22:20:27 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) {
----------------
lamb-j wrote:
Open to suggestions on a cleaner way to do this. Ideally we could do something like the following, instead of duplicating the functionality twice:
```
std::unique_ptr<llvm::Module> LinkMod;
if (ClRelinkBuiltinBitcodePostop)
LinkMod = Clone
else
LinkMod = Original
// Link with LinkMod
```
But due to `llvm::Module` not having a default constructor, I haven't figured out a way to do something like the above. That is, creating a single variable that can represent both the Original and the Clone, and set it depending on the provided boolean.
https://github.com/llvm/llvm-project/pull/72478
More information about the cfe-commits
mailing list