@@ -1964,26 +1964,10 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
1964
1964
Value *Src = Visit (const_cast <Expr*>(E));
1965
1965
llvm::Type *SrcTy = Src->getType ();
1966
1966
llvm::Type *DstTy = ConvertType (DestTy);
1967
- bool NeedAddrspaceCast = false ;
1968
1967
if (SrcTy->isPtrOrPtrVectorTy () && DstTy->isPtrOrPtrVectorTy () &&
1969
1968
SrcTy->getPointerAddressSpace () != DstTy->getPointerAddressSpace ()) {
1970
- // If we have the same address space in AST, which is then codegen'ed to
1971
- // different address spaces in IR, then an address space cast should be
1972
- // valid.
1973
- //
1974
- // This is the case for SYCL, where both types have Default address space
1975
- // in AST, but in IR one of them may be in opencl_private, and another in
1976
- // opencl_generic address space:
1977
- //
1978
- // int arr[5]; // automatic variable, default AS in AST,
1979
- // // private AS in IR
1980
- //
1981
- // char* p = arr; // default AS in AST, generic AS in IR
1982
- //
1983
- if (E->getType ().getAddressSpace () != DestTy.getAddressSpace ())
1984
- llvm_unreachable (" wrong cast for pointers in different address spaces"
1985
- " (must be an address space cast)!" );
1986
- NeedAddrspaceCast = true ;
1969
+ llvm_unreachable (" wrong cast for pointers in different address spaces"
1970
+ " (must be an address space cast)!" );
1987
1971
}
1988
1972
1989
1973
if (CGF.SanOpts .has (SanitizerKind::CFIUnrelatedCast)) {
@@ -2022,14 +2006,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
2022
2006
}
2023
2007
}
2024
2008
2025
- if (NeedAddrspaceCast) {
2026
- llvm::Type *SrcPointeeTy = Src->getType ()->getPointerElementType ();
2027
- llvm::Type *SrcNewAS = llvm::PointerType::get (
2028
- SrcPointeeTy, cast<llvm::PointerType>(DstTy)->getAddressSpace ());
2029
-
2030
- Src = Builder.CreateAddrSpaceCast (Src, SrcNewAS);
2031
- }
2032
-
2033
2009
// If Src is a fixed vector and Dst is a scalable vector, and both have the
2034
2010
// same element type, use the llvm.experimental.vector.insert intrinsic to
2035
2011
// perform the bitcast.
@@ -2966,53 +2942,6 @@ Value *ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *E) {
2966
2942
// Binary Operators
2967
2943
// ===----------------------------------------------------------------------===//
2968
2944
2969
- static Value *insertAddressSpaceCast (Value *V, unsigned NewAS) {
2970
- auto *VTy = cast<llvm::PointerType>(V->getType ());
2971
- if (VTy->getAddressSpace () == NewAS)
2972
- return V;
2973
-
2974
- llvm::PointerType *VTyNewAS =
2975
- llvm::PointerType::get (VTy->getElementType (), NewAS);
2976
-
2977
- if (auto *Constant = dyn_cast<llvm::Constant>(V))
2978
- return llvm::ConstantExpr::getAddrSpaceCast (Constant, VTyNewAS);
2979
-
2980
- llvm::Instruction *NewV =
2981
- new llvm::AddrSpaceCastInst (V, VTyNewAS, V->getName () + " .ascast" );
2982
- NewV->insertAfter (cast<llvm::Instruction>(V));
2983
- return NewV;
2984
- }
2985
-
2986
- static void ensureSameAddrSpace (Value *&RHS, Value *&LHS,
2987
- bool CanInsertAddrspaceCast,
2988
- const LangOptions &Opts,
2989
- const ASTContext &Context) {
2990
- if (RHS->getType () == LHS->getType ())
2991
- return ;
2992
-
2993
- auto *RHSTy = dyn_cast<llvm::PointerType>(RHS->getType ());
2994
- auto *LHSTy = dyn_cast<llvm::PointerType>(LHS->getType ());
2995
- if (!RHSTy || !LHSTy || RHSTy->getAddressSpace () == LHSTy->getAddressSpace ())
2996
- return ;
2997
-
2998
- if (!CanInsertAddrspaceCast)
2999
- // Pointers have different address spaces and we cannot do anything with
3000
- // this.
3001
- llvm_unreachable (" Pointers are expected to have the same address space." );
3002
-
3003
- // Language rules define if it is legal to cast from one address space to
3004
- // another, and which address space we should use as a "common
3005
- // denominator". In SYCL, generic address space overlaps with all other
3006
- // address spaces.
3007
- if (Opts.SYCLIsDevice ) {
3008
- unsigned GenericAS = Context.getTargetAddressSpace (LangAS::opencl_generic);
3009
- RHS = insertAddressSpaceCast (RHS, GenericAS);
3010
- LHS = insertAddressSpaceCast (LHS, GenericAS);
3011
- } else
3012
- llvm_unreachable (" Unable to find a common address space for "
3013
- " two pointers." );
3014
- }
3015
-
3016
2945
BinOpInfo ScalarExprEmitter::EmitBinOps (const BinaryOperator *E) {
3017
2946
TestAndClearIgnoreResultAssign ();
3018
2947
BinOpInfo Result;
@@ -4134,14 +4063,6 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,
4134
4063
RHS = Builder.CreateStripInvariantGroup (RHS);
4135
4064
}
4136
4065
4137
- // Expression operands may have the same addrspace in AST, but different
4138
- // addrspaces in LLVM IR, in which case an addrspacecast should be valid.
4139
- bool CanInsertAddrspaceCast =
4140
- LHSTy.getAddressSpace () == RHSTy.getAddressSpace ();
4141
-
4142
- ensureSameAddrSpace (RHS, LHS, CanInsertAddrspaceCast, CGF.getLangOpts (),
4143
- CGF.getContext ());
4144
-
4145
4066
Result = Builder.CreateICmp (UICmpOpc, LHS, RHS, " cmp" );
4146
4067
}
4147
4068
@@ -4513,6 +4434,7 @@ static bool isCheapEnoughToEvaluateUnconditionally(const Expr *E,
4513
4434
// exist in the source-level program.
4514
4435
}
4515
4436
4437
+
4516
4438
Value *ScalarExprEmitter::
4517
4439
VisitAbstractConditionalOperator (const AbstractConditionalOperator *E) {
4518
4440
TestAndClearIgnoreResultAssign ();
@@ -4621,15 +4543,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
4621
4543
assert (!RHS && " LHS and RHS types must match" );
4622
4544
return nullptr ;
4623
4545
}
4624
-
4625
- // Expressions may have the same addrspace in AST, but different address
4626
- // space in LLVM IR, in which case an addrspacecast should be valid.
4627
- bool CanInsertAddrspaceCast = rhsExpr->getType ().getAddressSpace () ==
4628
- lhsExpr->getType ().getAddressSpace ();
4629
-
4630
- ensureSameAddrSpace (RHS, LHS, CanInsertAddrspaceCast, CGF.getLangOpts (),
4631
- CGF.getContext ());
4632
-
4633
4546
return Builder.CreateSelect (CondV, LHS, RHS, " cond" );
4634
4547
}
4635
4548
@@ -4664,14 +4577,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
4664
4577
if (!RHS)
4665
4578
return LHS;
4666
4579
4667
- // Expressions may have the same addrspace in AST, but different address
4668
- // space in LLVM IR, in which case an addrspacecast should be valid.
4669
- bool CanInsertAddrspaceCast = rhsExpr->getType ().getAddressSpace () ==
4670
- lhsExpr->getType ().getAddressSpace ();
4671
-
4672
- ensureSameAddrSpace (RHS, LHS, CanInsertAddrspaceCast, CGF.getLangOpts (),
4673
- CGF.getContext ());
4674
-
4675
4580
// Create a PHI node for the real part.
4676
4581
llvm::PHINode *PN = Builder.CreatePHI (LHS->getType (), 2 , " cond" );
4677
4582
PN->addIncoming (LHS, LHSBlock);
0 commit comments