[PATCH] Support for address space casting in order to map these on the new 'addrspacecast' IR instruction
Michele Scandale
michele.scandale at gmail.com
Thu Nov 21 15:42:15 PST 2013
I don't know if it's fine (and correct) to introduce the concept of address space casting at semantic level.
So as alternative solution I propose also this non-intrusive alternative patch: here I've just fixed the code generation of scalar bitcast. Still there is an incoherence, because a semantic *bitcast* is translated in an operation that may not correspond to a bitcast in the LLVM IR (addrspacecast is assumed to represent whatever kind of conversion that may imply value and size changes).
What do you think?
Hi rjmccall, rsmith,
http://llvm-reviews.chandlerc.com/D2241
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2241?vs=5708&id=5723#toc
Files:
lib/CodeGen/CGExprScalar.cpp
test/CodeGenOpenCL/address-spaces-cast.cl
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -1299,6 +1299,8 @@
case CK_AnyPointerToBlockPointerCast:
case CK_BitCast: {
Value *Src = Visit(const_cast<Expr*>(E));
+ if (E->getType()->isPointerType() && DestTy->isPointerType())
+ return Builder.CreatePointerCast(Src, ConvertType(DestTy));
return Builder.CreateBitCast(Src, ConvertType(DestTy));
}
case CK_AtomicToNonAtomic:
Index: test/CodeGenOpenCL/address-spaces-cast.cl
===================================================================
--- test/CodeGenOpenCL/address-spaces-cast.cl
+++ test/CodeGenOpenCL/address-spaces-cast.cl
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -ffake-address-space-map -emit-llvm -o - | FileCheck %s
+
+#define NULL ((void*)0)
+
+void explicit_cast_between_address_space(int i, __local int *A) {
+// CHECK: explicit_cast_between_address_space
+ __global int *b;
+
+ b = i > 42 ? (__global int *)A : NULL;
+//CHECK: addrspacecast
+
+ if (b)
+ A[0] = b[5];
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2241.2.patch
Type: text/x-patch
Size: 1097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131121/d6db88dc/attachment.bin>
More information about the cfe-commits
mailing list