From 9a7afae4927c5a379631b538116c3796f402a970 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Fri, 9 Jul 2021 10:28:50 -0700 Subject: [PATCH] [OpaquePtr][InferAddrSpace] Use PointerType::getWithSamePointeeType() --- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp index c48a0e7..63b8425 100644 --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -508,8 +508,8 @@ static Value *operandWithNewAddressSpaceOrCreateUndef( SmallVectorImpl *UndefUsesToFix) { Value *Operand = OperandUse.get(); - Type *NewPtrTy = - Operand->getType()->getPointerElementType()->getPointerTo(NewAddrSpace); + Type *NewPtrTy = PointerType::getWithSamePointeeType( + cast(Operand->getType()), NewAddrSpace); if (Constant *C = dyn_cast(Operand)) return ConstantExpr::getAddrSpaceCast(C, NewPtrTy); @@ -537,8 +537,8 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace( Instruction *I, unsigned NewAddrSpace, const ValueToValueMapTy &ValueWithNewAddrSpace, SmallVectorImpl *UndefUsesToFix) const { - Type *NewPtrType = - I->getType()->getPointerElementType()->getPointerTo(NewAddrSpace); + Type *NewPtrType = PointerType::getWithSamePointeeType( + cast(I->getType()), NewAddrSpace); if (I->getOpcode() == Instruction::AddrSpaceCast) { Value *Src = I->getOperand(0); @@ -572,7 +572,8 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace( if (AS != UninitializedAddressSpace) { // For the assumed address space, insert an `addrspacecast` to make that // explicit. - auto *NewPtrTy = I->getType()->getPointerElementType()->getPointerTo(AS); + Type *NewPtrTy = PointerType::getWithSamePointeeType( + cast(I->getType()), AS); auto *NewI = new AddrSpaceCastInst(I, NewPtrTy); NewI->insertAfter(I); return NewI; @@ -634,8 +635,8 @@ static Value *cloneConstantExprWithNewAddressSpace( ConstantExpr *CE, unsigned NewAddrSpace, const ValueToValueMapTy &ValueWithNewAddrSpace, const DataLayout *DL, const TargetTransformInfo *TTI) { - Type *TargetType = - CE->getType()->getPointerElementType()->getPointerTo(NewAddrSpace); + Type *TargetType = PointerType::getWithSamePointeeType( + cast(CE->getType()), NewAddrSpace); if (CE->getOpcode() == Instruction::AddrSpaceCast) { // Because CE is flat, the source address space must be specific. -- 2.7.4