[llvm-branch-commits] [cfe-branch] r209029 - Merging r197036:
Tom Stellard
thomas.stellard at amd.com
Fri May 16 14:05:39 PDT 2014
Author: tstellar
Date: Fri May 16 16:05:39 2014
New Revision: 209029
URL: http://llvm.org/viewvc/llvm-project?rev=209029&view=rev
Log:
Merging r197036:
------------------------------------------------------------------------
r197036 | david.tweed | 2013-12-11 08:39:46 -0500 (Wed, 11 Dec 2013) | 8 lines
Add front-end infrastructure now address space casts are in LLVM IR.
With the introduction of explicit address space casts into LLVM, there's
a need to provide a new cast kind the front-end can create for C/OpenCL/CUDA
and code to produce address space casts from those kinds when appropriate.
Patch by Michele Scandale!
------------------------------------------------------------------------
Modified:
cfe/branches/release_34/include/clang/AST/OperationKinds.h
cfe/branches/release_34/lib/AST/Expr.cpp
cfe/branches/release_34/lib/AST/ExprConstant.cpp
cfe/branches/release_34/lib/CodeGen/CGExpr.cpp
cfe/branches/release_34/lib/CodeGen/CGExprAgg.cpp
cfe/branches/release_34/lib/CodeGen/CGExprComplex.cpp
cfe/branches/release_34/lib/CodeGen/CGExprConstant.cpp
cfe/branches/release_34/lib/CodeGen/CGExprScalar.cpp
cfe/branches/release_34/lib/Edit/RewriteObjCFoundationAPI.cpp
cfe/branches/release_34/lib/Sema/SemaExpr.cpp
cfe/branches/release_34/lib/StaticAnalyzer/Core/ExprEngineC.cpp
Modified: cfe/branches/release_34/include/clang/AST/OperationKinds.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/include/clang/AST/OperationKinds.h?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/include/clang/AST/OperationKinds.h (original)
+++ cfe/branches/release_34/include/clang/AST/OperationKinds.h Fri May 16 16:05:39 2014
@@ -295,7 +295,10 @@ enum CastKind {
CK_BuiltinFnToFnPtr,
// Convert a zero value for OpenCL event_t initialization.
- CK_ZeroToOCLEvent
+ CK_ZeroToOCLEvent,
+
+ // Convert a pointer to a different address space.
+ CK_AddressSpaceConversion
};
static const CastKind CK_Invalid = static_cast<CastKind>(-1);
Modified: cfe/branches/release_34/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/AST/Expr.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/AST/Expr.cpp (original)
+++ cfe/branches/release_34/lib/AST/Expr.cpp Fri May 16 16:05:39 2014
@@ -1474,6 +1474,11 @@ void CastExpr::CheckCastConsistency() co
assert(getSubExpr()->getType()->isFunctionType());
goto CheckNoBasePath;
+ case CK_AddressSpaceConversion:
+ assert(getType()->isPointerType());
+ assert(getSubExpr()->getType()->isPointerType());
+ assert(getType()->getPointeeType().getAddressSpace() !=
+ getSubExpr()->getType()->getPointeeType().getAddressSpace());
// These should not have an inheritance path.
case CK_Dynamic:
case CK_ToUnion:
@@ -1636,6 +1641,8 @@ const char *CastExpr::getCastKindName()
return "BuiltinFnToFnPtr";
case CK_ZeroToOCLEvent:
return "ZeroToOCLEvent";
+ case CK_AddressSpaceConversion:
+ return "AddressSpaceConversion";
}
llvm_unreachable("Unhandled cast kind!");
Modified: cfe/branches/release_34/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/AST/ExprConstant.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/AST/ExprConstant.cpp (original)
+++ cfe/branches/release_34/lib/AST/ExprConstant.cpp Fri May 16 16:05:39 2014
@@ -7109,6 +7109,7 @@ bool IntExprEvaluator::VisitCastExpr(con
case CK_BuiltinFnToFnPtr:
case CK_ZeroToOCLEvent:
case CK_NonAtomicToAtomic:
+ case CK_AddressSpaceConversion:
llvm_unreachable("invalid cast kind for integral value");
case CK_BitCast:
@@ -7581,6 +7582,7 @@ bool ComplexExprEvaluator::VisitCastExpr
case CK_BuiltinFnToFnPtr:
case CK_ZeroToOCLEvent:
case CK_NonAtomicToAtomic:
+ case CK_AddressSpaceConversion:
llvm_unreachable("invalid cast kind for complex value");
case CK_LValueToRValue:
Modified: cfe/branches/release_34/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/CGExpr.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/CGExpr.cpp Fri May 16 16:05:39 2014
@@ -2744,6 +2744,7 @@ LValue CodeGenFunction::EmitCastLValue(c
case CK_ARCReclaimReturnedObject:
case CK_ARCExtendBlockObject:
case CK_CopyAndAutoreleaseBlockObject:
+ case CK_AddressSpaceConversion:
return EmitUnsupportedLValue(E, "unexpected cast lvalue");
case CK_Dependent:
Modified: cfe/branches/release_34/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/CGExprAgg.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/CGExprAgg.cpp Fri May 16 16:05:39 2014
@@ -713,6 +713,7 @@ void AggExprEmitter::VisitCastExpr(CastE
case CK_CopyAndAutoreleaseBlockObject:
case CK_BuiltinFnToFnPtr:
case CK_ZeroToOCLEvent:
+ case CK_AddressSpaceConversion:
llvm_unreachable("cast kind invalid for aggregate types");
}
}
Modified: cfe/branches/release_34/lib/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/CGExprComplex.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/CGExprComplex.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/CGExprComplex.cpp Fri May 16 16:05:39 2014
@@ -475,6 +475,7 @@ ComplexPairTy ComplexExprEmitter::EmitCa
case CK_CopyAndAutoreleaseBlockObject:
case CK_BuiltinFnToFnPtr:
case CK_ZeroToOCLEvent:
+ case CK_AddressSpaceConversion:
llvm_unreachable("invalid cast kind for complex value");
case CK_FloatingRealToComplex:
Modified: cfe/branches/release_34/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/CGExprConstant.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/CGExprConstant.cpp Fri May 16 16:05:39 2014
@@ -633,6 +633,9 @@ public:
return llvm::ConstantStruct::get(STy, Elts);
}
+ case CK_AddressSpaceConversion:
+ return llvm::ConstantExpr::getAddrSpaceCast(C, destType);
+
case CK_LValueToRValue:
case CK_AtomicToNonAtomic:
case CK_NonAtomicToAtomic:
@@ -1062,13 +1065,13 @@ llvm::Constant *CodeGenModule::EmitConst
if (!Offset->isNullValue()) {
llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, Int8PtrTy);
Casted = llvm::ConstantExpr::getGetElementPtr(Casted, Offset);
- C = llvm::ConstantExpr::getBitCast(Casted, C->getType());
+ C = llvm::ConstantExpr::getPointerCast(Casted, C->getType());
}
// Convert to the appropriate type; this could be an lvalue for
// an integer.
if (isa<llvm::PointerType>(DestTy))
- return llvm::ConstantExpr::getBitCast(C, DestTy);
+ return llvm::ConstantExpr::getPointerCast(C, DestTy);
return llvm::ConstantExpr::getPtrToInt(C, DestTy);
} else {
Modified: cfe/branches/release_34/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/CodeGen/CGExprScalar.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/branches/release_34/lib/CodeGen/CGExprScalar.cpp Fri May 16 16:05:39 2014
@@ -1299,7 +1299,18 @@ Value *ScalarExprEmitter::VisitCastExpr(
case CK_AnyPointerToBlockPointerCast:
case CK_BitCast: {
Value *Src = Visit(const_cast<Expr*>(E));
- return Builder.CreateBitCast(Src, ConvertType(DestTy));
+ llvm::Type *SrcTy = Src->getType();
+ llvm::Type *DstTy = ConvertType(DestTy);
+ if (SrcTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() &&
+ SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace()) {
+ llvm::Type *MidTy = CGF.CGM.getDataLayout().getIntPtrType(SrcTy);
+ return Builder.CreateIntToPtr(Builder.CreatePtrToInt(Src, MidTy), DstTy);
+ }
+ return Builder.CreateBitCast(Src, DstTy);
+ }
+ case CK_AddressSpaceConversion: {
+ Value *Src = Visit(const_cast<Expr*>(E));
+ return Builder.CreateAddrSpaceCast(Src, ConvertType(DestTy));
}
case CK_AtomicToNonAtomic:
case CK_NonAtomicToAtomic:
@@ -1360,7 +1371,7 @@ Value *ScalarExprEmitter::VisitCastExpr(
// Make sure the array decay ends up being the right type. This matters if
// the array type was of an incomplete type.
- return CGF.Builder.CreateBitCast(V, ConvertType(CE->getType()));
+ return CGF.Builder.CreatePointerCast(V, ConvertType(CE->getType()));
}
case CK_FunctionToPointerDecay:
return EmitLValue(E).getAddress();
Modified: cfe/branches/release_34/lib/Edit/RewriteObjCFoundationAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/Edit/RewriteObjCFoundationAPI.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/Edit/RewriteObjCFoundationAPI.cpp (original)
+++ cfe/branches/release_34/lib/Edit/RewriteObjCFoundationAPI.cpp Fri May 16 16:05:39 2014
@@ -1033,6 +1033,7 @@ static bool rewriteToNumericBoxedExpress
case CK_IntegralComplexToReal:
case CK_IntegralComplexToBoolean:
case CK_AtomicToNonAtomic:
+ case CK_AddressSpaceConversion:
needsCast = true;
break;
Modified: cfe/branches/release_34/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/Sema/SemaExpr.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/release_34/lib/Sema/SemaExpr.cpp Fri May 16 16:05:39 2014
@@ -4876,8 +4876,13 @@ CastKind Sema::PrepareScalarCast(ExprRes
case Type::STK_BlockPointer:
case Type::STK_ObjCObjectPointer:
switch (DestTy->getScalarTypeKind()) {
- case Type::STK_CPointer:
+ case Type::STK_CPointer: {
+ unsigned SrcAS = SrcTy->getPointeeType().getAddressSpace();
+ unsigned DestAS = DestTy->getPointeeType().getAddressSpace();
+ if (SrcAS != DestAS)
+ return CK_AddressSpaceConversion;
return CK_BitCast;
+ }
case Type::STK_BlockPointer:
return (SrcKind == Type::STK_BlockPointer
? CK_BitCast : CK_AnyPointerToBlockPointerCast);
@@ -7830,10 +7835,14 @@ QualType Sema::CheckCompareOperands(Expr
diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, /*isError*/false);
}
if (LCanPointeeTy != RCanPointeeTy) {
+ unsigned AddrSpaceL = LCanPointeeTy.getAddressSpace();
+ unsigned AddrSpaceR = RCanPointeeTy.getAddressSpace();
+ CastKind Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion
+ : CK_BitCast;
if (LHSIsNull && !RHSIsNull)
- LHS = ImpCastExprToType(LHS.take(), RHSType, CK_BitCast);
+ LHS = ImpCastExprToType(LHS.take(), RHSType, Kind);
else
- RHS = ImpCastExprToType(RHS.take(), LHSType, CK_BitCast);
+ RHS = ImpCastExprToType(RHS.take(), LHSType, Kind);
}
return ResultTy;
}
Modified: cfe/branches/release_34/lib/StaticAnalyzer/Core/ExprEngineC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/StaticAnalyzer/Core/ExprEngineC.cpp?rev=209029&r1=209028&r2=209029&view=diff
==============================================================================
--- cfe/branches/release_34/lib/StaticAnalyzer/Core/ExprEngineC.cpp (original)
+++ cfe/branches/release_34/lib/StaticAnalyzer/Core/ExprEngineC.cpp Fri May 16 16:05:39 2014
@@ -286,6 +286,7 @@ void ExprEngine::VisitCast(const CastExp
case CK_Dependent:
case CK_ArrayToPointerDecay:
case CK_BitCast:
+ case CK_AddressSpaceConversion:
case CK_IntegralCast:
case CK_NullToPointer:
case CK_IntegralToPointer:
More information about the llvm-branch-commits
mailing list