OpenCL address space and mangling
eli.friedman at gmail.com
Fri Aug 2 15:57:03 PDT 2013
On Thu, Aug 1, 2013 at 10:45 AM, Tanya Lattner <tonic at nondot.org> wrote:
> On Jul 24, 2013, at 7:49 AM, Michele Scandale <michele.scandale at gmail.com>
> On 07/23/2013 11:36 PM, Tanya Lattner wrote:
> However, I actually should have looked at this closer as it actually doesn't
> to what I want it to. I want it to be the following:
> 1, // opencl_global
> 3, // opencl_local
> 2, // opencl_constant
> and when there is no address space then it maps to nothing.
> So, I don't think your patch is going to work unless the order is changed in
> enum. Because this is not clearly defined in the spec and is implementation
> specific and TARGET specific.. then changing that enum is probably not
> going to
> be the right approach either.
> I see the point but still we need to preserve the source language difference
> with the mangling.
> So, I'm going back to my original statement to keep it to be Target
> For your library, are these functions actually implemented differently?
> they be exactly the same when there is no address space? In our
> we have an address space map defined for X86 and then the names get mangled
> "correctly" for all targets. But, all the functionality is the same since
> address spaces don't impact codegen for X86.
> I'd argue that the fact that address spaces do not impact codegen for X86 is
> merely incidental: the issue goes beyond X86 and impacts all targets --
> including future ones.
> By choosing to use a fake address space map (instead of the one fitting the
> target description), we introduce in the IR a potential for breaking future
> implementations, even though the current X86 target is not affected.
> Moreover, by introducing the fake address map we would violate the semantics
> of the LLVM IR addrspace modifier.
> Even binary compatibility with libraries already distributed can be easily
> This patch (see attachment) aims at preserving the mangling that were
> generated by using the target address space map for those targets that
> override it, while introducing in the mangling the distinction of
> opencl/cuda address spaces for those targets that do not have a non trivial
> target address space map.
> By the way, looking beyond the scope of the current issue of mangling, it
> would be IMO interesting to start a public discussion on the mailing list
> about a way to represent logical address space information different from
> target-specific address space (the case for OpenCL and CUDA) in order to
> allow the implementation of custom language specific analysis and/or
> As a temporary solution, if one needed the logical address space information
> in the IR too for specific purpose (like OpenCL specific optimization), can
> still override the address space map of the target.
> This discussion probably should be moved to the cfe-dev mailing list. I
> think that its better for Clang to have one consistent way of mangling
> address spaces regardless of language. I’ve been thinking about this more
> and another problem I have with not using the Target address space map for
> mangling is that when you have this:
> void __attribute__((__overloadable__)) foo(global int *x)
> You get this:
> define void @_Z3fooPU10AS16776960b(i8* %x)
> The address space on the argument is gone (or zero), but yet you have it in
> the mangled name. So its not consistent.
> I can agree that its right to mangle the names differently from the language
> perspective, but what you mangle them to is really target specific. If you
> want to remove this notion from Clang, then maybe all target specific
> address space maps should go away and a default one for all is used. Then
> each LLVM backend can interpret it as they wish.
> It would be great if some Code owners could weigh in here.
The mangling of a symbol shouldn't depend on its machine
representation. For example, in C++, "long*" and "long long*" have a
different mangling, and that mangling is consistent across platforms
regardless of the actual width in bits of "long" and "long long".
This is required to properly represent overloading. The same concept
applies to "__global int *" and "__local int *"
That said, using numbers here is a terrible idea. Strawman
suggestion: the mangling for __global should be "CLglobal".
More information about the cfe-commits