<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Aug 7, 2013, at 6:16 PM, Pete Cooper <<a href="mailto:peter_cooper@apple.com">peter_cooper@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br>On Aug 7, 2013, at 5:12 PM, Michele Scandale <<a href="mailto:michele.scandale@gmail.com">michele.scandale@gmail.com</a>> wrote:<br><br><blockquote type="cite">On 08/08/2013 02:02 AM, Justin Holewinski wrote:<br><blockquote type="cite">This worries me a bit. This would introduce language-specific<br>processing into SelectionDAG. OpenCL maps address spaces one way, other<br>languages map them in other ways. Currently, it is the job of the<br>front-end to map pointers into the correct address space for the target<br>(hence the address space map in clang). With (my understanding of) this<br>proposal, there would be a pre-defined set of language-specific address<br>spaces that the target would need to know about. IMO it should be the<br>job of the front-end to do this mapping.<br></blockquote><br>The begin of the discussion was about possible way to represent high level address space information in the IR different from target address spaces (to have the information orthogonally respect the mapping so to handle also those targets that have the trivial mapping).<br><br>My interpretation of the solution proposed by Pete is that the frontend emits metadata that describe address spaces (overlapping information and mapping target specific). The instruction selection simply applis the mapping encoded in the metadata. So there is no pre-defined set, but there is only a mapping algorithm implemented in the instruction selection phase "table driven", the table is encoded as metadata.<br></blockquote>I think its fair to have this be dealt with by targets instead of the front-end. That way the optimizer can remain generic and use only the metadata. CPU targets will just map every address space to 0 as they have only a single physical memory space. GPU targets such as PTX and R600 can map to the actual HW spaces they want.<br><br>This way you have the target specific information in the backend where I believe it should be, and the front-end can target agnostic (note, I know, its not really agnostic and already contains target specific information, but I just don’t want to add more unless its really needed)<br><br>On the casting between address spaces topic "you can cast between the generic address space and global/local/private, so there's also that to consider.”. This terrifies me. I don’t know how to generate code for this on a system which has disjoint physical memory without branching on every memory access to that address space.<br></div></blockquote>Thinking about this more… </div><div><br></div><div>If you do implement something like alias analysis for address spaces, then casting between address spaces will be unsafe.</div><div><br></div><div>Lets say we have 3 address spaces: local, global, all. Local and global are disjoint, all is the union of the two.</div><div><br></div><div>If you cast local to all, or global to all, then alias analysis will be ok as an ‘all’ pointer already aliased local or global. However, if you cast local to all to global, then you now don’t know if other local pointers alias that so called global pointer or not. This is analogous to casting int* to float* in C++. Its undefined behavior according to the spec, and the compiler will optimize it as such.</div><div><br></div><div>Personally i’d treat it as undefined behavior and implement your code as such, but i’m no CL/CUDA expert so others may disagree.<br><blockquote type="cite" dir="auto"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite">_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span> <a href="http://llvm.cs.uiuc.edu/">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote><br><br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span> <a href="http://llvm.cs.uiuc.edu/">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div></blockquote></div><br></body></html>