From 7be7f232699fcca3f7631722db2f4b5ba48f8566 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 18 Jul 2023 12:04:36 +0200 Subject: [PATCH] [llvm] Remove uses of getWithSamePointeeType() (NFC) --- llvm/lib/Analysis/ConstantFolding.cpp | 10 ++++------ llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp | 16 +++++----------- llvm/lib/Target/AMDGPU/AMDGPUPromoteKernelArguments.cpp | 2 +- llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 10 +++------- llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp | 7 ++----- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 5 ++--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 5 +---- .../InstCombine/InstCombineLoadStoreAlloca.cpp | 5 ++--- llvm/unittests/IR/TypesTest.cpp | 13 ------------- 9 files changed, 20 insertions(+), 53 deletions(-) diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 514d449..facd972 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -861,18 +861,16 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef Ops, } /// Strip the pointer casts, but preserve the address space information. -Constant *StripPtrCastKeepAS(Constant *Ptr) { +// TODO: This probably doesn't make sense with opaque pointers. +static Constant *StripPtrCastKeepAS(Constant *Ptr) { assert(Ptr->getType()->isPointerTy() && "Not a pointer type"); auto *OldPtrTy = cast(Ptr->getType()); Ptr = cast(Ptr->stripPointerCasts()); auto *NewPtrTy = cast(Ptr->getType()); // Preserve the address space number of the pointer. - if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) { - Ptr = ConstantExpr::getPointerCast( - Ptr, PointerType::getWithSamePointeeType(NewPtrTy, - OldPtrTy->getAddressSpace())); - } + if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) + Ptr = ConstantExpr::getPointerCast(Ptr, OldPtrTy); return Ptr; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp index 733fdae..0b57e13 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp @@ -1093,10 +1093,8 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I, Value *TID = Builder.CreateAdd(Tmp0, Tmp1); TID = Builder.CreateAdd(TID, TIdZ); - Value *Indices[] = { - Constant::getNullValue(Type::getInt32Ty(Mod->getContext())), - TID - }; + LLVMContext &Context = Mod->getContext(); + Value *Indices[] = {Constant::getNullValue(Type::getInt32Ty(Context)), TID}; Value *Offset = Builder.CreateInBoundsGEP(GVTy, GV, Indices); I.mutateType(Offset->getType()); @@ -1109,9 +1107,7 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I, CallInst *Call = dyn_cast(V); if (!Call) { if (ICmpInst *CI = dyn_cast(V)) { - Value *Src0 = CI->getOperand(0); - PointerType *NewTy = PointerType::getWithSamePointeeType( - cast(Src0->getType()), AMDGPUAS::LOCAL_ADDRESS); + PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS); if (isa(CI->getOperand(0))) CI->setOperand(0, ConstantPointerNull::get(NewTy)); @@ -1127,8 +1123,7 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I, if (isa(V)) continue; - PointerType *NewTy = PointerType::getWithSamePointeeType( - cast(V->getType()), AMDGPUAS::LOCAL_ADDRESS); + PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS); // FIXME: It doesn't really make sense to try to do this for all // instructions. @@ -1188,8 +1183,7 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I, Function *ObjectSize = Intrinsic::getDeclaration( Mod, Intrinsic::objectsize, {Intr->getType(), - PointerType::getWithSamePointeeType( - cast(Src->getType()), AMDGPUAS::LOCAL_ADDRESS)}); + PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS)}); CallInst *NewCall = Builder.CreateCall( ObjectSize, diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteKernelArguments.cpp index ed450f5..9b654a2 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteKernelArguments.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteKernelArguments.cpp @@ -116,7 +116,7 @@ bool AMDGPUPromoteKernelArguments::promotePointer(Value *Ptr) { // Cast pointer to global address space and back to flat and let // Infer Address Spaces pass to do all necessary rewriting. PointerType *NewPT = - PointerType::getWithSamePointeeType(PT, AMDGPUAS::GLOBAL_ADDRESS); + PointerType::get(PT->getContext(), AMDGPUAS::GLOBAL_ADDRESS); Value *Cast = B.CreateAddrSpaceCast(Ptr, NewPT, Twine(Ptr->getName(), ".global")); Value *CastBack = diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp index 34bca13..fe20b83 100644 --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -14204,7 +14204,6 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const { Value *Val = AI->getValOperand(); Type *ValTy = Val->getType(); Value *Addr = AI->getPointerOperand(); - PointerType *PtrTy = cast(Addr->getType()); auto CreateNewAtomicRMW = [AI](IRBuilder<> &Builder, Value *Addr, Value *Val) -> Value * { @@ -14229,8 +14228,7 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const { Builder.SetInsertPoint(SharedBB); Value *CastToLocal = Builder.CreateAddrSpaceCast( - Addr, - PointerType::getWithSamePointeeType(PtrTy, AMDGPUAS::LOCAL_ADDRESS)); + Addr, PointerType::get(Ctx, AMDGPUAS::LOCAL_ADDRESS)); Value *LoadedShared = CreateNewAtomicRMW(Builder, CastToLocal, Val); Builder.CreateBr(PhiBB); @@ -14241,8 +14239,7 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const { Builder.SetInsertPoint(PrivateBB); Value *CastToPrivate = Builder.CreateAddrSpaceCast( - Addr, - PointerType::getWithSamePointeeType(PtrTy, AMDGPUAS::PRIVATE_ADDRESS)); + Addr, PointerType::get(Ctx, AMDGPUAS::PRIVATE_ADDRESS)); Value *LoadedPrivate = Builder.CreateLoad(ValTy, CastToPrivate, "loaded.private"); Value *NewVal = Builder.CreateFAdd(LoadedPrivate, Val, "val.new"); @@ -14251,8 +14248,7 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const { Builder.SetInsertPoint(GlobalBB); Value *CastToGlobal = Builder.CreateAddrSpaceCast( - Addr, - PointerType::getWithSamePointeeType(PtrTy, AMDGPUAS::GLOBAL_ADDRESS)); + Addr, PointerType::get(Ctx, AMDGPUAS::GLOBAL_ADDRESS)); Value *LoadedGlobal = CreateNewAtomicRMW(Builder, CastToGlobal, Val); Builder.CreateBr(PhiBB); diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp index 05ea7a8..5cd41cc 100644 --- a/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp @@ -190,8 +190,7 @@ static void convertToParamAS(Value *OldUser, Value *Param) { return NewGEP; } if (auto *BC = dyn_cast(I.OldInstruction)) { - auto *NewBCType = PointerType::getWithSamePointeeType( - cast(BC->getType()), ADDRESS_SPACE_PARAM); + auto *NewBCType = PointerType::get(BC->getContext(), ADDRESS_SPACE_PARAM); return BitCastInst::Create(BC->getOpcode(), I.NewParam, NewBCType, BC->getName(), BC); } @@ -407,9 +406,7 @@ void NVPTXLowerArgs::markPointerAsGlobal(Value *Ptr) { } Instruction *PtrInGlobal = new AddrSpaceCastInst( - Ptr, - PointerType::getWithSamePointeeType(cast(Ptr->getType()), - ADDRESS_SPACE_GLOBAL), + Ptr, PointerType::get(Ptr->getContext(), ADDRESS_SPACE_GLOBAL), Ptr->getName(), &*InsertPt); Value *PtrInGeneric = new AddrSpaceCastInst(PtrInGlobal, Ptr->getType(), Ptr->getName(), &*InsertPt); diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 95d2bf9..89f39f8 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -11928,9 +11928,8 @@ struct AAAddressSpaceImpl : public AAAddressSpace { getAssociatedType()->getPointerAddressSpace()) return ChangeStatus::UNCHANGED; - Type *NewPtrTy = PointerType::getWithSamePointeeType( - cast(getAssociatedType()), - static_cast(getAddressSpace())); + Type *NewPtrTy = PointerType::get(getAssociatedType()->getContext(), + static_cast(getAddressSpace())); bool UseOriginalValue = OriginalValue->getType()->getPointerAddressSpace() == static_cast(getAddressSpace()); diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp index ddff766..6aba57d 100644 --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -4317,10 +4317,7 @@ struct AAKernelInfoFunction : AAKernelInfo { if (WorkFnAI->getType()->getPointerAddressSpace() != (unsigned int)AddressSpace::Generic) { WorkFnAI = new AddrSpaceCastInst( - WorkFnAI, - PointerType::getWithSamePointeeType( - cast(WorkFnAI->getType()), - (unsigned int)AddressSpace::Generic), + WorkFnAI, PointerType::get(Ctx, (unsigned int)AddressSpace::Generic), WorkFnAI->getName() + ".generic", StateMachineBeginBB); WorkFnAI->setDebugLoc(DLoc); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 29568b7..6aa20ee 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -404,9 +404,8 @@ void PointerReplacer::replace(Instruction *I) { } else if (auto *BC = dyn_cast(I)) { auto *V = getReplacement(BC->getOperand(0)); assert(V && "Operand not replaced"); - auto *NewT = PointerType::getWithSamePointeeType( - cast(BC->getType()), - V->getType()->getPointerAddressSpace()); + auto *NewT = PointerType::get(BC->getType()->getContext(), + V->getType()->getPointerAddressSpace()); auto *NewI = new BitCastInst(V, NewT); IC.InsertNewInstWith(NewI, *BC); NewI->takeName(BC); diff --git a/llvm/unittests/IR/TypesTest.cpp b/llvm/unittests/IR/TypesTest.cpp index eba808a..855262f 100644 --- a/llvm/unittests/IR/TypesTest.cpp +++ b/llvm/unittests/IR/TypesTest.cpp @@ -35,19 +35,6 @@ TEST(TypesTest, LayoutIdenticalEmptyStructs) { EXPECT_TRUE(Foo->isLayoutIdentical(Bar)); } -TEST(TypesTest, CopyPointerType) { - LLVMContext C; - - PointerType *P1 = PointerType::get(C, 1); - EXPECT_TRUE(P1->isOpaque()); - PointerType *P1C = PointerType::getWithSamePointeeType(P1, 1); - EXPECT_EQ(P1, P1C); - EXPECT_TRUE(P1C->isOpaque()); - PointerType *P1C0 = PointerType::getWithSamePointeeType(P1, 0); - EXPECT_NE(P1, P1C0); - EXPECT_TRUE(P1C0->isOpaque()); -} - TEST(TypesTest, TargetExtType) { LLVMContext Context; Type *A = TargetExtType::get(Context, "typea"); -- 2.7.4