[clang] Remove some getPointerElementType() uses

Same cases where the call can be removed in a straightforward way.
This commit is contained in:
Nikita Popov 2022-01-25 12:04:06 +01:00
parent f302e0b5dd
commit 99adacbcb7
6 changed files with 25 additions and 23 deletions

View File

@ -351,12 +351,12 @@ bool AtomicInfo::requiresMemSetZero(llvm::Type *type) const {
bool AtomicInfo::emitMemSetZeroIfNecessary() const {
assert(LVal.isSimple());
llvm::Value *addr = LVal.getPointer(CGF);
if (!requiresMemSetZero(addr->getType()->getPointerElementType()))
Address addr = LVal.getAddress(CGF);
if (!requiresMemSetZero(addr.getElementType()))
return false;
CGF.Builder.CreateMemSet(
addr, llvm::ConstantInt::get(CGF.Int8Ty, 0),
addr.getPointer(), llvm::ConstantInt::get(CGF.Int8Ty, 0),
CGF.getContext().toCharUnitsFromBits(AtomicSizeInBits).getQuantity(),
LVal.getAlignment().getAsAlign());
return true;
@ -1522,7 +1522,7 @@ RValue AtomicInfo::ConvertIntToValueOrAtomic(llvm::Value *IntVal,
!AsValue)) {
auto *ValTy = AsValue
? CGF.ConvertTypeForMem(ValueTy)
: getAtomicAddress().getType()->getPointerElementType();
: getAtomicAddress().getElementType();
if (ValTy->isIntegerTy()) {
assert(IntVal->getType() == ValTy && "Different integer types.");
return RValue::get(CGF.EmitFromMemory(IntVal, ValueTy));

View File

@ -112,7 +112,8 @@ public:
assert(functionPtr && "configuring callee without function pointer");
assert(functionPtr->getType()->isPointerTy());
assert(functionPtr->getType()->isOpaquePointerTy() ||
functionPtr->getType()->getPointerElementType()->isFunctionTy());
functionPtr->getType()->getNonOpaquePointerElementType()
->isFunctionTy());
}
static CGCallee forBuiltin(unsigned builtinID,

View File

@ -1613,8 +1613,9 @@ ScalarExprEmitter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
if (GlobalConstStr->getType()->getPointerAddressSpace() == ExprAS)
return GlobalConstStr;
llvm::Type *EltTy = GlobalConstStr->getType()->getPointerElementType();
llvm::PointerType *NewPtrTy = llvm::PointerType::get(EltTy, ExprAS);
llvm::PointerType *PtrTy = cast<llvm::PointerType>(GlobalConstStr->getType());
llvm::PointerType *NewPtrTy =
llvm::PointerType::getWithSamePointeeType(PtrTy, ExprAS);
return Builder.CreateAddrSpaceCast(GlobalConstStr, NewPtrTy, "usn_addr_cast");
}

View File

@ -837,10 +837,7 @@ void ReductionCodeGen::emitAggregateType(CodeGenFunction &CGF, unsigned N) {
}
llvm::Value *Size;
llvm::Value *SizeInChars;
auto *ElemType = OrigAddresses[N]
.first.getPointer(CGF)
->getType()
->getPointerElementType();
auto *ElemType = OrigAddresses[N].first.getAddress(CGF).getElementType();
auto *ElemSizeOf = llvm::ConstantExpr::getSizeOf(ElemType);
if (AsArraySection) {
Size = CGF.Builder.CreatePtrDiff(OrigAddresses[N].second.getPointer(CGF),

View File

@ -3401,12 +3401,13 @@ CGOpenMPRuntimeGPU::getParameterAddress(CodeGenFunction &CGF,
LocalAddr, /*Volatile=*/false, TargetTy, SourceLocation());
// First cast to generic.
TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
TargetAddr, TargetAddr->getType()->getPointerElementType()->getPointerTo(
/*AddrSpace=*/0));
TargetAddr, llvm::PointerType::getWithSamePointeeType(
cast<llvm::PointerType>(TargetAddr->getType()), /*AddrSpace=*/0));
// Cast from generic to native address space.
TargetAddr = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
TargetAddr, TargetAddr->getType()->getPointerElementType()->getPointerTo(
NativePointeeAddrSpace));
TargetAddr, llvm::PointerType::getWithSamePointeeType(
cast<llvm::PointerType>(TargetAddr->getType()),
NativePointeeAddrSpace));
Address NativeParamAddr = CGF.CreateMemTemp(NativeParamType);
CGF.EmitStoreOfScalar(TargetAddr, NativeParamAddr, /*Volatile=*/false,
NativeParamType);
@ -3431,8 +3432,8 @@ void CGOpenMPRuntimeGPU::emitOutlinedFunctionCall(
continue;
}
llvm::Value *TargetArg = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
NativeArg,
NativeArg->getType()->getPointerElementType()->getPointerTo());
NativeArg, llvm::PointerType::getWithSamePointeeType(
cast<llvm::PointerType>(NativeArg->getType()), /*AddrSpace*/ 0));
TargetArgs.emplace_back(
CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(TargetArg, TargetType));
}

View File

@ -8936,8 +8936,9 @@ private:
llvm::Type *coerceKernelArgumentType(llvm::Type *Ty, unsigned FromAS,
unsigned ToAS) const {
// Single value types.
if (Ty->isPointerTy() && Ty->getPointerAddressSpace() == FromAS)
return llvm::PointerType::get(Ty->getPointerElementType(), ToAS);
auto *PtrTy = llvm::dyn_cast<llvm::PointerType>(Ty);
if (PtrTy && PtrTy->getAddressSpace() == FromAS)
return llvm::PointerType::getWithSamePointeeType(PtrTy, ToAS);
return Ty;
}
@ -9333,8 +9334,8 @@ llvm::Constant *AMDGPUTargetCodeGenInfo::getNullPointer(
return llvm::ConstantPointerNull::get(PT);
auto &Ctx = CGM.getContext();
auto NPT = llvm::PointerType::get(PT->getPointerElementType(),
Ctx.getTargetAddressSpace(LangAS::opencl_generic));
auto NPT = llvm::PointerType::getWithSamePointeeType(
PT, Ctx.getTargetAddressSpace(LangAS::opencl_generic));
return llvm::ConstantExpr::getAddrSpaceCast(
llvm::ConstantPointerNull::get(NPT), PT);
}
@ -10269,8 +10270,9 @@ ABIArgInfo SPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
llvm::Type *LTy = CGT.ConvertType(Ty);
auto DefaultAS = getContext().getTargetAddressSpace(LangAS::Default);
auto GlobalAS = getContext().getTargetAddressSpace(LangAS::cuda_device);
if (LTy->isPointerTy() && LTy->getPointerAddressSpace() == DefaultAS) {
LTy = llvm::PointerType::get(LTy->getPointerElementType(), GlobalAS);
auto *PtrTy = llvm::dyn_cast<llvm::PointerType>(LTy);
if (PtrTy && PtrTy->getAddressSpace() == DefaultAS) {
LTy = llvm::PointerType::getWithSamePointeeType(PtrTy, GlobalAS);
return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
}
}