[Patch][pr19848] Produce explicit comdats in clang

Reid Kleckner rnk at google.com
Fri Dec 19 15:41:11 PST 2014


On Fri, Dec 19, 2014 at 2:39 PM, Reid Kleckner <rnk at google.com> wrote:
>
> Are we sure we want to go this way? MachO can't even represent generalized
> comdats. If we want to fix the conflation of weak linkage and implicit
> single-member comdat groups, it might be nice to have a lighter weight more
> memory efficient way of representing this.
>
> Right now every C++ inline function gets linkonce_odr, a linkage enum
> packed into a bitfield to say that it needs a comdat. With this change, we
> will copy the long C++ mangled name into a separate symbol table for not
> much gain.
>
> Maybe we should turn linkage into a flags enum? Something like ODR,
> Discardable, Weak, ImplicitComdat.
>

Crazy idea: let's make Comdat a value type which wraps either a GlobalValue
(basic single symbol selectany case) or a ComdatGroup (advanced, funky
selection or multi-symbol case). Then GlobalValue::getComdat() can check a
few bits and return a little single-pointer wrapper depending on what kind
of thing it is, and IR passes can treat it uniformly.

The IR for the simple inline function case would be something like:
define void @f() comdat { ; no $f sigil
  ret void
}

I'm not sure how we would write the global variable case. Today we write:
$v = comdat any
@v = global i32 0, comdat $v

I don't think we can write this due to ambiguity:
@v = global i32 0, comdat
$v = ...

Maybe we could pretend it's linkage and write this?
@v = comdat global i32 0

Maybe functions should look like this?
define comdat void @f() { ret void }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141219/f04b9d64/attachment.html>


More information about the cfe-commits mailing list