Skip to content

Commit 5ae2aed

Browse files
authored
clang: Remove dest LangAS argument from performAddrSpaceCast (#138866)
It isn't used and is redundant with the result pointer type argument. A more reasonable API would only have LangAS parameters, or IR parameters, not both. Not all values have a meaningful value for this. I'm also not sure why we have this at all, it's not overridden by any targets and further simplification is possible.
1 parent c64c64d commit 5ae2aed

13 files changed

+39
-51
lines changed

clang/lib/CodeGen/CGAtomic.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
10841084
auto DestAS = getContext().getTargetAddressSpace(LangAS::opencl_generic);
10851085
auto *DestType = llvm::PointerType::get(getLLVMContext(), DestAS);
10861086

1087-
return getTargetHooks().performAddrSpaceCast(
1088-
*this, V, AS, LangAS::opencl_generic, DestType, false);
1087+
return getTargetHooks().performAddrSpaceCast(*this, V, AS, DestType,
1088+
false);
10891089
};
10901090

10911091
Args.add(RValue::get(CastToGenericAddrSpace(Ptr.emitRawPointer(*this),

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4081,8 +4081,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
40814081
LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
40824082
if (AAS != EAS) {
40834083
llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
4084-
return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
4085-
EAS, Ty));
4084+
return RValue::get(
4085+
getTargetHooks().performAddrSpaceCast(*this, AI, AAS, Ty));
40864086
}
40874087
return RValue::get(AI);
40884088
}
@@ -4103,8 +4103,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
41034103
LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
41044104
if (AAS != EAS) {
41054105
llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
4106-
return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
4107-
EAS, Ty));
4106+
return RValue::get(
4107+
getTargetHooks().performAddrSpaceCast(*this, AI, AAS, Ty));
41084108
}
41094109
return RValue::get(AI);
41104110
}

clang/lib/CodeGen/CGCall.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5245,12 +5245,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
52455245
if (SRetPtr.getAddressSpace() != RetAI.getIndirectAddrSpace()) {
52465246
llvm::Value *V = SRetPtr.getBasePointer();
52475247
LangAS SAS = getLangASFromTargetAS(SRetPtr.getAddressSpace());
5248-
LangAS DAS = getLangASFromTargetAS(RetAI.getIndirectAddrSpace());
52495248
llvm::Type *Ty = llvm::PointerType::get(getLLVMContext(),
52505249
RetAI.getIndirectAddrSpace());
52515250

52525251
SRetPtr = SRetPtr.withPointer(
5253-
getTargetHooks().performAddrSpaceCast(*this, V, SAS, DAS, Ty, true),
5252+
getTargetHooks().performAddrSpaceCast(*this, V, SAS, Ty, true),
52545253
SRetPtr.isKnownNonNull());
52555254
}
52565255
IRCallArgs[IRFunctionArgs.getSRetArgNo()] =
@@ -5395,8 +5394,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
53955394
// we can look through a cast to a compatible address space value,
53965395
// otherwise emit a copy.
53975396
llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
5398-
*this, V, I->Ty.getAddressSpace(), CGM.getASTAllocaAddressSpace(),
5399-
T, true);
5397+
*this, V, I->Ty.getAddressSpace(), T, true);
54005398
if (ArgHasMaybeUndefAttr)
54015399
Val = Builder.CreateFreeze(Val);
54025400
IRCallArgs[FirstIRArg] = Val;
@@ -5485,12 +5483,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
54855483
if (FirstIRArg < IRFuncTy->getNumParams() &&
54865484
V->getType() != IRFuncTy->getParamType(FirstIRArg)) {
54875485
assert(V->getType()->isPointerTy() && "Only pointers can mismatch!");
5488-
auto FormalAS = CallInfo.arguments()[ArgNo]
5489-
.type.getQualifiers()
5490-
.getAddressSpace();
54915486
auto ActualAS = I->Ty.getAddressSpace();
54925487
V = getTargetHooks().performAddrSpaceCast(
5493-
*this, V, ActualAS, FormalAS, IRFuncTy->getParamType(FirstIRArg));
5488+
*this, V, ActualAS, IRFuncTy->getParamType(FirstIRArg));
54945489
}
54955490

54965491
if (ArgHasMaybeUndefAttr)

clang/lib/CodeGen/CGClass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,8 +2132,8 @@ void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
21322132
unsigned TargetThisAS = getContext().getTargetAddressSpace(ThisAS);
21332133
llvm::Type *NewType =
21342134
llvm::PointerType::get(getLLVMContext(), TargetThisAS);
2135-
ThisPtr = getTargetHooks().performAddrSpaceCast(*this, ThisPtr, ThisAS,
2136-
SlotAS, NewType);
2135+
ThisPtr =
2136+
getTargetHooks().performAddrSpaceCast(*this, ThisPtr, ThisAS, NewType);
21372137
}
21382138

21392139
// Push the this ptr.

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl(
299299
llvm::Constant *Addr = GV;
300300
if (AS != ExpectedAS) {
301301
Addr = getTargetCodeGenInfo().performAddrSpaceCast(
302-
*this, GV, AS, ExpectedAS,
302+
*this, GV, AS,
303303
llvm::PointerType::get(getLLVMContext(),
304304
getContext().getTargetAddressSpace(ExpectedAS)));
305305
}
@@ -2705,10 +2705,9 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
27052705
CGM.getDataLayout().getAllocaAddrSpace());
27062706
auto DestAS = getContext().getTargetAddressSpace(DestLangAS);
27072707
auto *T = llvm::PointerType::get(getLLVMContext(), DestAS);
2708-
DeclPtr =
2709-
DeclPtr.withPointer(getTargetHooks().performAddrSpaceCast(
2710-
*this, V, SrcLangAS, DestLangAS, T, true),
2711-
DeclPtr.isKnownNonNull());
2708+
DeclPtr = DeclPtr.withPointer(
2709+
getTargetHooks().performAddrSpaceCast(*this, V, SrcLangAS, T, true),
2710+
DeclPtr.isKnownNonNull());
27122711
}
27132712

27142713
// Push a destructor cleanup for this parameter if the ABI requires it.

clang/lib/CodeGen/CGException.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,8 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
11561156
assert(typeValue && "fell into catch-all case!");
11571157
// With opaque ptrs, only the address space can be a mismatch.
11581158
if (typeValue->getType() != argTy)
1159-
typeValue =
1160-
CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue, globAS,
1161-
LangAS::Default, argTy);
1159+
typeValue = CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue,
1160+
globAS, argTy);
11621161

11631162
// Figure out the next block.
11641163
bool nextIsEnd;

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, LangAS DestLangAS,
122122
if (!ArraySize)
123123
Builder.SetInsertPoint(getPostAllocaInsertPoint());
124124
V = getTargetHooks().performAddrSpaceCast(
125-
*this, V, getASTAllocaAddressSpace(), DestLangAS,
126-
Builder.getPtrTy(DestAddrSpace), /*IsNonNull=*/true);
125+
*this, V, getASTAllocaAddressSpace(), Builder.getPtrTy(DestAddrSpace),
126+
/*IsNonNull=*/true);
127127
}
128128

129129
return RawAddress(V, Ty, Align, KnownNonNull);
@@ -466,7 +466,7 @@ static RawAddress createReferenceTemporary(CodeGenFunction &CGF,
466466
llvm::Constant *C = GV;
467467
if (AS != LangAS::Default)
468468
C = TCG.performAddrSpaceCast(
469-
CGF.CGM, GV, AS, LangAS::Default,
469+
CGF.CGM, GV, AS,
470470
llvm::PointerType::get(
471471
CGF.getLLVMContext(),
472472
CGF.getContext().getTargetAddressSpace(LangAS::Default)));
@@ -3296,8 +3296,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
32963296
if (AS != T.getAddressSpace()) {
32973297
auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace());
32983298
auto PtrTy = llvm::PointerType::get(CGM.getLLVMContext(), TargetAS);
3299-
auto ASC = getTargetHooks().performAddrSpaceCast(
3300-
CGM, ATPO.getPointer(), AS, T.getAddressSpace(), PtrTy);
3299+
auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(),
3300+
AS, PtrTy);
33013301
ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());
33023302
}
33033303

@@ -5565,8 +5565,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
55655565
QualType DestTy = getContext().getPointerType(E->getType());
55665566
llvm::Value *V = getTargetHooks().performAddrSpaceCast(
55675567
*this, LV.getPointer(*this),
5568-
E->getSubExpr()->getType().getAddressSpace(),
5569-
E->getType().getAddressSpace(), ConvertType(DestTy));
5568+
E->getSubExpr()->getType().getAddressSpace(), ConvertType(DestTy));
55705569
return MakeAddrLValue(Address(V, ConvertTypeForMem(E->getType()),
55715570
LV.getAddress().getAlignment()),
55725571
E->getType(), LV.getBaseInfo(), LV.getTBAAInfo());

clang/lib/CodeGen/CGExprCXX.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ RValue CodeGenFunction::EmitCXXDestructorCall(
113113
if (SrcAS != DstAS) {
114114
QualType DstTy = DtorDecl->getThisType();
115115
llvm::Type *NewType = CGM.getTypes().ConvertType(DstTy);
116-
This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, DstAS,
117-
NewType);
116+
This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, NewType);
118117
}
119118

120119
CallArgList Args;
@@ -2231,8 +2230,7 @@ llvm::Value *CodeGenFunction::EmitCXXTypeidExpr(const CXXTypeidExpr *E) {
22312230
auto MaybeASCast = [=](auto &&TypeInfo) {
22322231
if (GlobAS == LangAS::Default)
22332232
return TypeInfo;
2234-
return getTargetHooks().performAddrSpaceCast(CGM,TypeInfo, GlobAS,
2235-
LangAS::Default, PtrTy);
2233+
return getTargetHooks().performAddrSpaceCast(CGM, TypeInfo, GlobAS, PtrTy);
22362234
};
22372235

22382236
if (E->isTypeOperand()) {

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,12 +1226,12 @@ class ConstExprEmitter
12261226

12271227
case CK_AddressSpaceConversion: {
12281228
auto C = Emitter.tryEmitPrivate(subExpr, subExpr->getType());
1229-
if (!C) return nullptr;
1230-
LangAS destAS = E->getType()->getPointeeType().getAddressSpace();
1229+
if (!C)
1230+
return nullptr;
12311231
LangAS srcAS = subExpr->getType()->getPointeeType().getAddressSpace();
12321232
llvm::Type *destTy = ConvertType(E->getType());
12331233
return CGM.getTargetCodeGenInfo().performAddrSpaceCast(CGM, C, srcAS,
1234-
destAS, destTy);
1234+
destTy);
12351235
}
12361236

12371237
case CK_LValueToRValue: {

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,8 +2434,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
24342434
// expects. It is desirable to remove this iff a better solution is found.
24352435
if (auto A = dyn_cast<llvm::Argument>(Src); A && A->hasStructRetAttr())
24362436
return CGF.CGM.getTargetCodeGenInfo().performAddrSpaceCast(
2437-
CGF, Src, E->getType().getAddressSpace(), DestTy.getAddressSpace(),
2438-
DstTy);
2437+
CGF, Src, E->getType().getAddressSpace(), DstTy);
24392438

24402439
assert(
24412440
(!SrcTy->isPtrOrPtrVectorTy() || !DstTy->isPtrOrPtrVectorTy() ||
@@ -2568,7 +2567,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
25682567
// space, an address space conversion may end up as a bitcast.
25692568
return CGF.CGM.getTargetCodeGenInfo().performAddrSpaceCast(
25702569
CGF, Visit(E), E->getType()->getPointeeType().getAddressSpace(),
2571-
DestTy->getPointeeType().getAddressSpace(), ConvertType(DestTy));
2570+
ConvertType(DestTy));
25722571
}
25732572
case CK_AtomicToNonAtomic:
25742573
case CK_NonAtomicToAtomic:

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5251,7 +5251,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
52515251
assert(getContext().getTargetAddressSpace(ExpectedAS) == TargetAS);
52525252
if (DAddrSpace != ExpectedAS) {
52535253
return getTargetCodeGenInfo().performAddrSpaceCast(
5254-
*this, GV, DAddrSpace, ExpectedAS,
5254+
*this, GV, DAddrSpace,
52555255
llvm::PointerType::get(getLLVMContext(), TargetAS));
52565256
}
52575257

@@ -5486,7 +5486,7 @@ castStringLiteralToDefaultAddressSpace(CodeGenModule &CGM,
54865486
auto AS = CGM.GetGlobalConstantAddressSpace();
54875487
if (AS != LangAS::Default)
54885488
Cast = CGM.getTargetCodeGenInfo().performAddrSpaceCast(
5489-
CGM, GV, AS, LangAS::Default,
5489+
CGM, GV, AS,
54905490
llvm::PointerType::get(
54915491
CGM.getLLVMContext(),
54925492
CGM.getContext().getTargetAddressSpace(LangAS::Default)));
@@ -6886,7 +6886,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
68866886
llvm::Constant *CV = GV;
68876887
if (AddrSpace != LangAS::Default)
68886888
CV = getTargetCodeGenInfo().performAddrSpaceCast(
6889-
*this, GV, AddrSpace, LangAS::Default,
6889+
*this, GV, AddrSpace,
68906890
llvm::PointerType::get(
68916891
getLLVMContext(),
68926892
getContext().getTargetAddressSpace(LangAS::Default)));

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ LangAS TargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
138138

139139
llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
140140
CodeGen::CodeGenFunction &CGF, llvm::Value *Src, LangAS SrcAddr,
141-
LangAS DestAddr, llvm::Type *DestTy, bool isNonNull) const {
141+
llvm::Type *DestTy, bool isNonNull) const {
142142
// Since target may map different address spaces in AST to the same address
143143
// space, an address space conversion may end up as a bitcast.
144144
if (auto *C = dyn_cast<llvm::Constant>(Src))
145-
return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
145+
return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestTy);
146146
// Try to preserve the source's name to make IR more readable.
147147
return CGF.Builder.CreateAddrSpaceCast(
148148
Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
149149
}
150150

151151
llvm::Constant *
152152
TargetCodeGenInfo::performAddrSpaceCast(CodeGenModule &CGM, llvm::Constant *Src,
153-
LangAS SrcAddr, LangAS DestAddr,
153+
LangAS SrcAddr,
154154
llvm::Type *DestTy) const {
155155
// Since target may map different address spaces in AST to the same address
156156
// space, an address space conversion may end up as a bitcast.

clang/lib/CodeGen/TargetInfo.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ class TargetCodeGenInfo {
316316
virtual LangAS getASTAllocaAddressSpace() const { return LangAS::Default; }
317317

318318
Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr,
319-
LangAS SrcAddr, LangAS DestAddr,
320-
llvm::Type *DestTy,
319+
LangAS SrcAddr, llvm::Type *DestTy,
321320
bool IsNonNull = false) const;
322321

323322
/// Perform address space cast of an expression of pointer type.
@@ -328,7 +327,7 @@ class TargetCodeGenInfo {
328327
/// \param IsNonNull is the flag indicating \p V is known to be non null.
329328
virtual llvm::Value *performAddrSpaceCast(CodeGen::CodeGenFunction &CGF,
330329
llvm::Value *V, LangAS SrcAddr,
331-
LangAS DestAddr, llvm::Type *DestTy,
330+
llvm::Type *DestTy,
332331
bool IsNonNull = false) const;
333332

334333
/// Perform address space cast of a constant expression of pointer type.
@@ -338,7 +337,7 @@ class TargetCodeGenInfo {
338337
/// \param DestTy is the destination LLVM pointer type.
339338
virtual llvm::Constant *performAddrSpaceCast(CodeGenModule &CGM,
340339
llvm::Constant *V,
341-
LangAS SrcAddr, LangAS DestAddr,
340+
LangAS SrcAddr,
342341
llvm::Type *DestTy) const;
343342

344343
/// Get address space of pointer parameter for __cxa_atexit.

0 commit comments

Comments
 (0)