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];
+}
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];
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits