-
Notifications
You must be signed in to change notification settings - Fork 13.5k
clang: Remove dest LangAS argument from performAddrSpaceCast #138866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clang: Remove dest LangAS argument from performAddrSpaceCast #138866
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Matt Arsenault (arsenm) ChangesIt isn't used and is redundant with the result pointer type argument. Full diff: https://github.com/llvm/llvm-project/pull/138866.diff 13 Files Affected:
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 0af3cd07b13a0..51f0799a792fd 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -1084,8 +1084,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
auto DestAS = getContext().getTargetAddressSpace(LangAS::opencl_generic);
auto *DestType = llvm::PointerType::get(getLLVMContext(), DestAS);
- return getTargetHooks().performAddrSpaceCast(
- *this, V, AS, LangAS::opencl_generic, DestType, false);
+ return getTargetHooks().performAddrSpaceCast(*this, V, AS, DestType,
+ false);
};
Args.add(RValue::get(CastToGenericAddrSpace(Ptr.emitRawPointer(*this),
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e6816736412b8..45e0f69c46902 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4081,8 +4081,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
if (AAS != EAS) {
llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
- return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
- EAS, Ty));
+ return RValue::get(
+ getTargetHooks().performAddrSpaceCast(*this, AI, AAS, Ty));
}
return RValue::get(AI);
}
@@ -4103,8 +4103,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
LangAS EAS = E->getType()->getPointeeType().getAddressSpace();
if (AAS != EAS) {
llvm::Type *Ty = CGM.getTypes().ConvertType(E->getType());
- return RValue::get(getTargetHooks().performAddrSpaceCast(*this, AI, AAS,
- EAS, Ty));
+ return RValue::get(
+ getTargetHooks().performAddrSpaceCast(*this, AI, AAS, Ty));
}
return RValue::get(AI);
}
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index db8820a8c517e..dd892bada0433 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5242,12 +5242,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
if (SRetPtr.getAddressSpace() != RetAI.getIndirectAddrSpace()) {
llvm::Value *V = SRetPtr.getBasePointer();
LangAS SAS = getLangASFromTargetAS(SRetPtr.getAddressSpace());
- LangAS DAS = getLangASFromTargetAS(RetAI.getIndirectAddrSpace());
llvm::Type *Ty = llvm::PointerType::get(getLLVMContext(),
RetAI.getIndirectAddrSpace());
SRetPtr = SRetPtr.withPointer(
- getTargetHooks().performAddrSpaceCast(*this, V, SAS, DAS, Ty, true),
+ getTargetHooks().performAddrSpaceCast(*this, V, SAS, Ty, true),
SRetPtr.isKnownNonNull());
}
IRCallArgs[IRFunctionArgs.getSRetArgNo()] =
@@ -5392,8 +5391,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
// we can look through a cast to a compatible address space value,
// otherwise emit a copy.
llvm::Value *Val = getTargetHooks().performAddrSpaceCast(
- *this, V, I->Ty.getAddressSpace(), CGM.getASTAllocaAddressSpace(),
- T, true);
+ *this, V, I->Ty.getAddressSpace(), T, true);
if (ArgHasMaybeUndefAttr)
Val = Builder.CreateFreeze(Val);
IRCallArgs[FirstIRArg] = Val;
@@ -5482,12 +5480,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
if (FirstIRArg < IRFuncTy->getNumParams() &&
V->getType() != IRFuncTy->getParamType(FirstIRArg)) {
assert(V->getType()->isPointerTy() && "Only pointers can mismatch!");
- auto FormalAS = CallInfo.arguments()[ArgNo]
- .type.getQualifiers()
- .getAddressSpace();
auto ActualAS = I->Ty.getAddressSpace();
V = getTargetHooks().performAddrSpaceCast(
- *this, V, ActualAS, FormalAS, IRFuncTy->getParamType(FirstIRArg));
+ *this, V, ActualAS, IRFuncTy->getParamType(FirstIRArg));
}
if (ArgHasMaybeUndefAttr)
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index a8c48237977c2..befbfc64a680c 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2132,8 +2132,8 @@ void CodeGenFunction::EmitCXXConstructorCall(const CXXConstructorDecl *D,
unsigned TargetThisAS = getContext().getTargetAddressSpace(ThisAS);
llvm::Type *NewType =
llvm::PointerType::get(getLLVMContext(), TargetThisAS);
- ThisPtr = getTargetHooks().performAddrSpaceCast(*this, ThisPtr, ThisAS,
- SlotAS, NewType);
+ ThisPtr =
+ getTargetHooks().performAddrSpaceCast(*this, ThisPtr, ThisAS, NewType);
}
// Push the this ptr.
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 1e54e55c5abbb..fe8c3cb20add3 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -299,7 +299,7 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl(
llvm::Constant *Addr = GV;
if (AS != ExpectedAS) {
Addr = getTargetCodeGenInfo().performAddrSpaceCast(
- *this, GV, AS, ExpectedAS,
+ *this, GV, AS,
llvm::PointerType::get(getLLVMContext(),
getContext().getTargetAddressSpace(ExpectedAS)));
}
@@ -2705,10 +2705,9 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
CGM.getDataLayout().getAllocaAddrSpace());
auto DestAS = getContext().getTargetAddressSpace(DestLangAS);
auto *T = llvm::PointerType::get(getLLVMContext(), DestAS);
- DeclPtr =
- DeclPtr.withPointer(getTargetHooks().performAddrSpaceCast(
- *this, V, SrcLangAS, DestLangAS, T, true),
- DeclPtr.isKnownNonNull());
+ DeclPtr = DeclPtr.withPointer(
+ getTargetHooks().performAddrSpaceCast(*this, V, SrcLangAS, T, true),
+ DeclPtr.isKnownNonNull());
}
// Push a destructor cleanup for this parameter if the ABI requires it.
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index ebecb3aa5241d..e0367282355cf 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1156,9 +1156,8 @@ static void emitCatchDispatchBlock(CodeGenFunction &CGF,
assert(typeValue && "fell into catch-all case!");
// With opaque ptrs, only the address space can be a mismatch.
if (typeValue->getType() != argTy)
- typeValue =
- CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue, globAS,
- LangAS::Default, argTy);
+ typeValue = CGF.getTargetHooks().performAddrSpaceCast(CGF, typeValue,
+ globAS, argTy);
// Figure out the next block.
bool nextIsEnd;
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 7f1308719a71e..d104f6cac18d9 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -122,8 +122,8 @@ RawAddress CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, LangAS DestLangAS,
if (!ArraySize)
Builder.SetInsertPoint(getPostAllocaInsertPoint());
V = getTargetHooks().performAddrSpaceCast(
- *this, V, getASTAllocaAddressSpace(), DestLangAS,
- Builder.getPtrTy(DestAddrSpace), /*IsNonNull=*/true);
+ *this, V, getASTAllocaAddressSpace(), Builder.getPtrTy(DestAddrSpace),
+ /*IsNonNull=*/true);
}
return RawAddress(V, Ty, Align, KnownNonNull);
@@ -466,7 +466,7 @@ static RawAddress createReferenceTemporary(CodeGenFunction &CGF,
llvm::Constant *C = GV;
if (AS != LangAS::Default)
C = TCG.performAddrSpaceCast(
- CGF.CGM, GV, AS, LangAS::Default,
+ CGF.CGM, GV, AS,
llvm::PointerType::get(
CGF.getLLVMContext(),
CGF.getContext().getTargetAddressSpace(LangAS::Default)));
@@ -3292,8 +3292,8 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
if (AS != T.getAddressSpace()) {
auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace());
auto PtrTy = llvm::PointerType::get(CGM.getLLVMContext(), TargetAS);
- auto ASC = getTargetHooks().performAddrSpaceCast(
- CGM, ATPO.getPointer(), AS, T.getAddressSpace(), PtrTy);
+ auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(),
+ AS, PtrTy);
ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());
}
@@ -5561,8 +5561,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
QualType DestTy = getContext().getPointerType(E->getType());
llvm::Value *V = getTargetHooks().performAddrSpaceCast(
*this, LV.getPointer(*this),
- E->getSubExpr()->getType().getAddressSpace(),
- E->getType().getAddressSpace(), ConvertType(DestTy));
+ E->getSubExpr()->getType().getAddressSpace(), ConvertType(DestTy));
return MakeAddrLValue(Address(V, ConvertTypeForMem(E->getType()),
LV.getAddress().getAlignment()),
E->getType(), LV.getBaseInfo(), LV.getTBAAInfo());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 3e8c42d5a6f4b..024254b0affe4 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -113,8 +113,7 @@ RValue CodeGenFunction::EmitCXXDestructorCall(
if (SrcAS != DstAS) {
QualType DstTy = DtorDecl->getThisType();
llvm::Type *NewType = CGM.getTypes().ConvertType(DstTy);
- This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, DstAS,
- NewType);
+ This = getTargetHooks().performAddrSpaceCast(*this, This, SrcAS, NewType);
}
CallArgList Args;
@@ -2231,8 +2230,7 @@ llvm::Value *CodeGenFunction::EmitCXXTypeidExpr(const CXXTypeidExpr *E) {
auto MaybeASCast = [=](auto &&TypeInfo) {
if (GlobAS == LangAS::Default)
return TypeInfo;
- return getTargetHooks().performAddrSpaceCast(CGM,TypeInfo, GlobAS,
- LangAS::Default, PtrTy);
+ return getTargetHooks().performAddrSpaceCast(CGM, TypeInfo, GlobAS, PtrTy);
};
if (E->isTypeOperand()) {
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index b21ebeee4bed1..fe564aaf3e59c 100644
--- a/clang/lib/CodeGen/CGExprConstant.cpp
+++ b/clang/lib/CodeGen/CGExprConstant.cpp
@@ -1226,12 +1226,12 @@ class ConstExprEmitter
case CK_AddressSpaceConversion: {
auto C = Emitter.tryEmitPrivate(subExpr, subExpr->getType());
- if (!C) return nullptr;
- LangAS destAS = E->getType()->getPointeeType().getAddressSpace();
+ if (!C)
+ return nullptr;
LangAS srcAS = subExpr->getType()->getPointeeType().getAddressSpace();
llvm::Type *destTy = ConvertType(E->getType());
return CGM.getTargetCodeGenInfo().performAddrSpaceCast(CGM, C, srcAS,
- destAS, destTy);
+ destTy);
}
case CK_LValueToRValue: {
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index f639a87e3ad0b..ae444612d5b18 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2434,8 +2434,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
// expects. It is desirable to remove this iff a better solution is found.
if (auto A = dyn_cast<llvm::Argument>(Src); A && A->hasStructRetAttr())
return CGF.CGM.getTargetCodeGenInfo().performAddrSpaceCast(
- CGF, Src, E->getType().getAddressSpace(), DestTy.getAddressSpace(),
- DstTy);
+ CGF, Src, E->getType().getAddressSpace(), DstTy);
assert(
(!SrcTy->isPtrOrPtrVectorTy() || !DstTy->isPtrOrPtrVectorTy() ||
@@ -2568,7 +2567,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
// space, an address space conversion may end up as a bitcast.
return CGF.CGM.getTargetCodeGenInfo().performAddrSpaceCast(
CGF, Visit(E), E->getType()->getPointeeType().getAddressSpace(),
- DestTy->getPointeeType().getAddressSpace(), ConvertType(DestTy));
+ ConvertType(DestTy));
}
case CK_AtomicToNonAtomic:
case CK_NonAtomicToAtomic:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c27817604f6ca..85f81484e7c01 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5251,7 +5251,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
assert(getContext().getTargetAddressSpace(ExpectedAS) == TargetAS);
if (DAddrSpace != ExpectedAS) {
return getTargetCodeGenInfo().performAddrSpaceCast(
- *this, GV, DAddrSpace, ExpectedAS,
+ *this, GV, DAddrSpace,
llvm::PointerType::get(getLLVMContext(), TargetAS));
}
@@ -5486,7 +5486,7 @@ castStringLiteralToDefaultAddressSpace(CodeGenModule &CGM,
auto AS = CGM.GetGlobalConstantAddressSpace();
if (AS != LangAS::Default)
Cast = CGM.getTargetCodeGenInfo().performAddrSpaceCast(
- CGM, GV, AS, LangAS::Default,
+ CGM, GV, AS,
llvm::PointerType::get(
CGM.getLLVMContext(),
CGM.getContext().getTargetAddressSpace(LangAS::Default)));
@@ -6886,7 +6886,7 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
llvm::Constant *CV = GV;
if (AddrSpace != LangAS::Default)
CV = getTargetCodeGenInfo().performAddrSpaceCast(
- *this, GV, AddrSpace, LangAS::Default,
+ *this, GV, AddrSpace,
llvm::PointerType::get(
getLLVMContext(),
getContext().getTargetAddressSpace(LangAS::Default)));
diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp
index 981488eb4dc37..75a7d3c7c73f0 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -138,11 +138,11 @@ LangAS TargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
CodeGen::CodeGenFunction &CGF, llvm::Value *Src, LangAS SrcAddr,
- LangAS DestAddr, llvm::Type *DestTy, bool isNonNull) const {
+ llvm::Type *DestTy, bool isNonNull) const {
// Since target may map different address spaces in AST to the same address
// space, an address space conversion may end up as a bitcast.
if (auto *C = dyn_cast<llvm::Constant>(Src))
- return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestAddr, DestTy);
+ return performAddrSpaceCast(CGF.CGM, C, SrcAddr, DestTy);
// Try to preserve the source's name to make IR more readable.
return CGF.Builder.CreateAddrSpaceCast(
Src, DestTy, Src->hasName() ? Src->getName() + ".ascast" : "");
@@ -150,7 +150,7 @@ llvm::Value *TargetCodeGenInfo::performAddrSpaceCast(
llvm::Constant *
TargetCodeGenInfo::performAddrSpaceCast(CodeGenModule &CGM, llvm::Constant *Src,
- LangAS SrcAddr, LangAS DestAddr,
+ LangAS SrcAddr,
llvm::Type *DestTy) const {
// Since target may map different address spaces in AST to the same address
// space, an address space conversion may end up as a bitcast.
diff --git a/clang/lib/CodeGen/TargetInfo.h b/clang/lib/CodeGen/TargetInfo.h
index ef4e500f7a38c..dd5dc0c32bd71 100644
--- a/clang/lib/CodeGen/TargetInfo.h
+++ b/clang/lib/CodeGen/TargetInfo.h
@@ -316,8 +316,7 @@ class TargetCodeGenInfo {
virtual LangAS getASTAllocaAddressSpace() const { return LangAS::Default; }
Address performAddrSpaceCast(CodeGen::CodeGenFunction &CGF, Address Addr,
- LangAS SrcAddr, LangAS DestAddr,
- llvm::Type *DestTy,
+ LangAS SrcAddr, llvm::Type *DestTy,
bool IsNonNull = false) const;
/// Perform address space cast of an expression of pointer type.
@@ -328,7 +327,7 @@ class TargetCodeGenInfo {
/// \param IsNonNull is the flag indicating \p V is known to be non null.
virtual llvm::Value *performAddrSpaceCast(CodeGen::CodeGenFunction &CGF,
llvm::Value *V, LangAS SrcAddr,
- LangAS DestAddr, llvm::Type *DestTy,
+ llvm::Type *DestTy,
bool IsNonNull = false) const;
/// Perform address space cast of a constant expression of pointer type.
@@ -338,7 +337,7 @@ class TargetCodeGenInfo {
/// \param DestTy is the destination LLVM pointer type.
virtual llvm::Constant *performAddrSpaceCast(CodeGenModule &CGM,
llvm::Constant *V,
- LangAS SrcAddr, LangAS DestAddr,
+ LangAS SrcAddr,
llvm::Type *DestTy) const;
/// Get address space of pointer parameter for __cxa_atexit.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM.
69ac264
to
abb68b8
Compare
d1a11ed
to
4a1cda9
Compare
abb68b8
to
5605195
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention was to make the interface more flexible in cases that a target may want to do some arithmetic directly based on target address space instead of an addrspacecast inst. However, so many years have passed and no target was doing that. I think we could remove it.
I would like to continue to traffic in LangAS, if for no other reason than that it promotes better habits within CodeGen. Otherwise, I think we will end up with a lot of code that immediately lowers address spaces, and that will make it very difficult to treat address spaces as a frontend abstraction if we ever do have a need for that, which I continue to believe is a likely future development. I don't have a problem with removing the argument in this case if it is actually redundant with a different argument, however. |
Merge activity
|
4a1cda9
to
d7d6cf5
Compare
5605195
to
f231cbc
Compare
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.
f231cbc
to
49a77b9
Compare
I don't think this PR should be merged. Since John is the code owner of clang codegen. |
Merging this was fine because it was just removing the redundant LangAS argument, not removing the abstract handling of address-space conversions in IRGen. I just wanted to note my opposition to the idea of taking that second step, since it had come up in the review. |
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.