[PATCH] D18252: Drop comdats from the dst module if they are not selected

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 20:53:08 PDT 2016


joker.eph added inline comments.

================
Comment at: llvm/lib/Linker/LinkModules.cpp:476
@@ -472,1 +475,3 @@
 
+void ModuleLinker::dropReplacedComdat(
+    GlobalValue &GV, const DenseSet<const Comdat *> &ReplacedDstComdats) {
----------------
doc

================
Comment at: llvm/lib/Linker/LinkModules.cpp:503
@@ +502,3 @@
+  if (Declaration->use_empty())
+    Declaration->eraseFromParent();
+}
----------------
What's happening here is not super nice in the alias case, since you're creating a new GlobalVariable to trash it right after.
Can't this be done before the if with an early return like below?

```
if (!ReplacedDstComdats.count(C))
    return;
if (Declaration->use_empty()) {
    Declaration->eraseFromParent();
    return;
}
  if (auto *F = dyn_cast<Function>(&GV))
    F->deleteBody();
 else if (auto *Var = dyn_cast<GlobalVariable>(&GV)) 
    Var->setInitializer(nullptr);
 else { // alias case
       auto &Alias = cast<GlobalAlias>(GV);
    Module &M = *Alias.getParent();
    PointerType &Ty = *cast<PointerType>(Alias.getType());
    GlobalValue::LinkageTypes L = Alias.getLinkage();
    auto Declaration =
        new GlobalVariable(M, Ty.getElementType(), /*isConstant*/ false, L,
                           /*Initializer*/ nullptr);
    Declaration->takeName(&Alias);
    Alias.replaceAllUsesWith(Declaration);
    Alias.eraseFromParent();
}
```


http://reviews.llvm.org/D18252





More information about the llvm-commits mailing list