diff options
author | Tom Stellard <thomas.stellard@amd.com> | 2014-05-16 21:05:39 +0000 |
---|---|---|
committer | Tom Stellard <thomas.stellard@amd.com> | 2014-05-16 21:05:39 +0000 |
commit | 3aee3bf490502caa2a75e9c6feb5649e3099befb (patch) | |
tree | b11b21dcafe502bd4dba456fe063f05c7cab3b9d | |
parent | b358fb9d3263c0ba45ca6d5e10fbe1452da8c37c (diff) | |
download | llvm-3aee3bf490502caa2a75e9c6feb5649e3099befb.zip llvm-3aee3bf490502caa2a75e9c6feb5649e3099befb.tar.gz llvm-3aee3bf490502caa2a75e9c6feb5649e3099befb.tar.bz2 |
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!
------------------------------------------------------------------------
llvm-svn: 209029
-rw-r--r-- | clang/include/clang/AST/OperationKinds.h | 5 | ||||
-rw-r--r-- | clang/lib/AST/Expr.cpp | 7 | ||||
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExprAgg.cpp | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExprComplex.cpp | 1 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 7 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Edit/RewriteObjCFoundationAPI.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 15 | ||||
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp | 1 |
11 files changed, 48 insertions, 8 deletions
diff --git a/clang/include/clang/AST/OperationKinds.h b/clang/include/clang/AST/OperationKinds.h index 5e41d95..aba88d6 100644 --- a/clang/include/clang/AST/OperationKinds.h +++ b/clang/include/clang/AST/OperationKinds.h @@ -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); diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 9055dda..6307f4c 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1474,6 +1474,11 @@ void CastExpr::CheckCastConsistency() const { 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() const { return "BuiltinFnToFnPtr"; case CK_ZeroToOCLEvent: return "ZeroToOCLEvent"; + case CK_AddressSpaceConversion: + return "AddressSpaceConversion"; } llvm_unreachable("Unhandled cast kind!"); diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 4cac4fa..a0ae5b6 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -7109,6 +7109,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) { 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(const CastExpr *E) { case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: case CK_NonAtomicToAtomic: + case CK_AddressSpaceConversion: llvm_unreachable("invalid cast kind for complex value"); case CK_LValueToRValue: diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index cb990b2..92966d0 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -2744,6 +2744,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { case CK_ARCReclaimReturnedObject: case CK_ARCExtendBlockObject: case CK_CopyAndAutoreleaseBlockObject: + case CK_AddressSpaceConversion: return EmitUnsupportedLValue(E, "unexpected cast lvalue"); case CK_Dependent: diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 9d0f3a9..35e6988 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -713,6 +713,7 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: + case CK_AddressSpaceConversion: llvm_unreachable("cast kind invalid for aggregate types"); } } diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index 73d5bcb..74a2579 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -475,6 +475,7 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastExpr::CastKind CK, Expr *Op, case CK_CopyAndAutoreleaseBlockObject: case CK_BuiltinFnToFnPtr: case CK_ZeroToOCLEvent: + case CK_AddressSpaceConversion: llvm_unreachable("invalid cast kind for complex value"); case CK_FloatingRealToComplex: diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index f4d6861..ad3e1fc 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -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::EmitConstantValue(const APValue &Value, 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 { diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index f3a5387..26e327a 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1299,7 +1299,18 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { 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(CastExpr *CE) { // 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(); diff --git a/clang/lib/Edit/RewriteObjCFoundationAPI.cpp b/clang/lib/Edit/RewriteObjCFoundationAPI.cpp index f4206fb..879c17a 100644 --- a/clang/lib/Edit/RewriteObjCFoundationAPI.cpp +++ b/clang/lib/Edit/RewriteObjCFoundationAPI.cpp @@ -1033,6 +1033,7 @@ static bool rewriteToNumericBoxedExpression(const ObjCMessageExpr *Msg, case CK_IntegralComplexToReal: case CK_IntegralComplexToBoolean: case CK_AtomicToNonAtomic: + case CK_AddressSpaceConversion: needsCast = true; break; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index e1f65f4..992e66a 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4876,8 +4876,13 @@ CastKind Sema::PrepareScalarCast(ExprResult &Src, QualType DestTy) { 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(ExprResult &LHS, ExprResult &RHS, 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; } diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp index 983fda0..9ba086c 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -286,6 +286,7 @@ void ExprEngine::VisitCast(const CastExpr *CastE, const Expr *Ex, case CK_Dependent: case CK_ArrayToPointerDecay: case CK_BitCast: + case CK_AddressSpaceConversion: case CK_IntegralCast: case CK_NullToPointer: case CK_IntegralToPointer: |