[clang] [clang][CGOpenMPRuntime] Avoid Type::getPointerTo() (NFC) (PR #112017)
Youngsuk Kim via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 11 14:43:20 PDT 2024
https://github.com/JOE1994 updated https://github.com/llvm/llvm-project/pull/112017
>From 542112f283387db666c54422c714e901bb898c84 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim <youngsuk.kim at hpe.com>
Date: Fri, 11 Oct 2024 10:06:57 -0500
Subject: [PATCH 1/2] [clang][CGOpenMPRuntime] Avoid Type::getPointerTo() (NFC)
`llvm::Type::getPointerTo()` is to be deprecated & removed soon.
---
clang/lib/CodeGen/CGOpenMPRuntime.cpp | 45 +++++++++------------------
1 file changed, 14 insertions(+), 31 deletions(-)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 8593cb5ffdd97d..7e0ecb31546c5f 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1713,25 +1713,15 @@ llvm::Function *CGOpenMPRuntime::emitThreadPrivateVarDefinition(
if (!Ctor && !Dtor)
return nullptr;
- llvm::Type *CopyCtorTyArgs[] = {CGM.VoidPtrTy, CGM.VoidPtrTy};
- auto *CopyCtorTy = llvm::FunctionType::get(CGM.VoidPtrTy, CopyCtorTyArgs,
- /*isVarArg=*/false)
- ->getPointerTo();
// Copying constructor for the threadprivate variable.
// Must be NULL - reserved by runtime, but currently it requires that this
// parameter is always NULL. Otherwise it fires assertion.
- CopyCtor = llvm::Constant::getNullValue(CopyCtorTy);
+ CopyCtor = llvm::Constant::getNullValue(CGM.VoidPtrTy);
if (Ctor == nullptr) {
- auto *CtorTy = llvm::FunctionType::get(CGM.VoidPtrTy, CGM.VoidPtrTy,
- /*isVarArg=*/false)
- ->getPointerTo();
- Ctor = llvm::Constant::getNullValue(CtorTy);
+ Ctor = llvm::Constant::getNullValue(CGM.VoidPtrTy);
}
if (Dtor == nullptr) {
- auto *DtorTy = llvm::FunctionType::get(CGM.VoidTy, CGM.VoidPtrTy,
- /*isVarArg=*/false)
- ->getPointerTo();
- Dtor = llvm::Constant::getNullValue(DtorTy);
+ Dtor = llvm::Constant::getNullValue(CGM.VoidPtrTy);
}
if (!CGF) {
auto *InitFunctionTy =
@@ -1817,7 +1807,7 @@ Address CGOpenMPRuntime::getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
OMPBuilder.getOrCreateRuntimeFunction(
CGM.getModule(), OMPRTL___kmpc_threadprivate_cached),
Args),
- VarLVType->getPointerTo(/*AddrSpace=*/0)),
+ CGF.Builder.getPtrTy(0)),
VarLVType, CGM.getContext().getTypeAlignInChars(VarType));
}
@@ -2131,10 +2121,7 @@ static Address emitAddrOfVarFromArray(CodeGenFunction &CGF, Address Array,
llvm::Value *Ptr = CGF.Builder.CreateLoad(PtrAddr);
llvm::Type *ElemTy = CGF.ConvertTypeForMem(Var->getType());
- return Address(
- CGF.Builder.CreateBitCast(
- Ptr, ElemTy->getPointerTo(Ptr->getType()->getPointerAddressSpace())),
- ElemTy, CGF.getContext().getDeclAlign(Var));
+ return Address(Ptr, ElemTy, CGF.getContext().getDeclAlign(Var));
}
static llvm::Value *emitCopyprivateCopyFunction(
@@ -2166,11 +2153,11 @@ static llvm::Value *emitCopyprivateCopyFunction(
// Src = (void*[n])(RHSArg);
Address LHS(CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(&LHSArg)),
- ArgsElemType->getPointerTo()),
+ CGF.Builder.getPtrTy(0)),
ArgsElemType, CGF.getPointerAlign());
Address RHS(CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(&RHSArg)),
- ArgsElemType->getPointerTo()),
+ CGF.Builder.getPtrTy(0)),
ArgsElemType, CGF.getPointerAlign());
// *(Type0*)Dst[0] = *(Type0*)Src[0];
// *(Type1*)Dst[1] = *(Type1*)Src[1];
@@ -3681,9 +3668,7 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
QualType KmpTaskTWithPrivatesQTy = C.getRecordType(KmpTaskTWithPrivatesQTyRD);
QualType KmpTaskTWithPrivatesPtrQTy =
C.getPointerType(KmpTaskTWithPrivatesQTy);
- llvm::Type *KmpTaskTWithPrivatesTy = CGF.ConvertType(KmpTaskTWithPrivatesQTy);
- llvm::Type *KmpTaskTWithPrivatesPtrTy =
- KmpTaskTWithPrivatesTy->getPointerTo();
+ llvm::Type *KmpTaskTWithPrivatesPtrTy = CGF.Builder.getPtrTy(0);
llvm::Value *KmpTaskTWithPrivatesTySize =
CGF.getTypeSize(KmpTaskTWithPrivatesQTy);
QualType SharedsPtrTy = C.getPointerType(SharedsTy);
@@ -4399,7 +4384,7 @@ Address CGOpenMPRuntime::emitDepobjDependClause(
Args, ".dep.arr.addr");
llvm::Type *KmpDependInfoLlvmTy = CGF.ConvertTypeForMem(KmpDependInfoTy);
Addr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
- Addr, KmpDependInfoLlvmTy->getPointerTo());
+ Addr, CGF.Builder.getPtrTy(0));
DependenciesArray = Address(Addr, KmpDependInfoLlvmTy, Align);
// Write number of elements in the first element of array for depobj.
LValue Base = CGF.MakeAddrLValue(DependenciesArray, KmpDependInfoTy);
@@ -4841,11 +4826,11 @@ llvm::Function *CGOpenMPRuntime::emitReductionFunction(
// Src = (void*[n])(RHSArg);
Address LHS(CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(&LHSArg)),
- ArgsElemType->getPointerTo()),
+ CGF.Builder.getPtrTy(0)),
ArgsElemType, CGF.getPointerAlign());
Address RHS(CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(&RHSArg)),
- ArgsElemType->getPointerTo()),
+ CGF.Builder.getPtrTy(0)),
ArgsElemType, CGF.getPointerAlign());
// ...
@@ -5277,8 +5262,7 @@ static llvm::Value *emitReduceInitFunction(CodeGenModule &CGM,
CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args, Loc, Loc);
QualType PrivateType = RCG.getPrivateType(N);
Address PrivateAddr = CGF.EmitLoadOfPointer(
- CGF.GetAddrOfLocalVar(&Param).withElementType(
- CGF.ConvertTypeForMem(PrivateType)->getPointerTo()),
+ CGF.GetAddrOfLocalVar(&Param).withElementType(CGF.Builder.getPtrTy(0)),
C.getPointerType(PrivateType)->castAs<PointerType>());
llvm::Value *Size = nullptr;
// If the size of the reduction item is non-constant, load it from global
@@ -5366,15 +5350,14 @@ static llvm::Value *emitReduceCombFunction(CodeGenModule &CGM,
// Pull out the pointer to the variable.
CGF.EmitLoadOfPointer(
CGF.GetAddrOfLocalVar(&ParamInOut)
- .withElementType(
- CGF.ConvertTypeForMem(LHSVD->getType())->getPointerTo()),
+ .withElementType(CGF.Builder.getPtrTy(0)),
C.getPointerType(LHSVD->getType())->castAs<PointerType>()));
PrivateScope.addPrivate(
RHSVD,
// Pull out the pointer to the variable.
CGF.EmitLoadOfPointer(
CGF.GetAddrOfLocalVar(&ParamIn).withElementType(
- CGF.ConvertTypeForMem(RHSVD->getType())->getPointerTo()),
+ CGF.Builder.getPtrTy(0)),
C.getPointerType(RHSVD->getType())->castAs<PointerType>()));
PrivateScope.Privatize();
// Emit the combiner body:
>From 1ca0f4cc1789801cef978f21da930aae1bc18181 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim <youngsuk.kim at hpe.com>
Date: Fri, 11 Oct 2024 16:42:26 -0500
Subject: [PATCH 2/2] Use CGM.UnqualPtrTy instead of CGM.VoidPtrTy
---
clang/lib/CodeGen/CGOpenMPRuntime.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 7e0ecb31546c5f..3747b00d4893ad 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1716,12 +1716,12 @@ llvm::Function *CGOpenMPRuntime::emitThreadPrivateVarDefinition(
// Copying constructor for the threadprivate variable.
// Must be NULL - reserved by runtime, but currently it requires that this
// parameter is always NULL. Otherwise it fires assertion.
- CopyCtor = llvm::Constant::getNullValue(CGM.VoidPtrTy);
+ CopyCtor = llvm::Constant::getNullValue(CGM.UnqualPtrTy);
if (Ctor == nullptr) {
- Ctor = llvm::Constant::getNullValue(CGM.VoidPtrTy);
+ Ctor = llvm::Constant::getNullValue(CGM.UnqualPtrTy);
}
if (Dtor == nullptr) {
- Dtor = llvm::Constant::getNullValue(CGM.VoidPtrTy);
+ Dtor = llvm::Constant::getNullValue(CGM.UnqualPtrTy);
}
if (!CGF) {
auto *InitFunctionTy =
More information about the cfe-commits
mailing list