Skip to content

Commit 7be7f23

Browse files
committed
[llvm] Remove uses of getWithSamePointeeType() (NFC)
1 parent 68746a8 commit 7be7f23

File tree

9 files changed

+20
-53
lines changed

9 files changed

+20
-53
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -861,18 +861,16 @@ Constant *CastGEPIndices(Type *SrcElemTy, ArrayRef<Constant *> Ops,
861861
}
862862

863863
/// Strip the pointer casts, but preserve the address space information.
864-
Constant *StripPtrCastKeepAS(Constant *Ptr) {
864+
// TODO: This probably doesn't make sense with opaque pointers.
865+
static Constant *StripPtrCastKeepAS(Constant *Ptr) {
865866
assert(Ptr->getType()->isPointerTy() && "Not a pointer type");
866867
auto *OldPtrTy = cast<PointerType>(Ptr->getType());
867868
Ptr = cast<Constant>(Ptr->stripPointerCasts());
868869
auto *NewPtrTy = cast<PointerType>(Ptr->getType());
869870

870871
// Preserve the address space number of the pointer.
871-
if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) {
872-
Ptr = ConstantExpr::getPointerCast(
873-
Ptr, PointerType::getWithSamePointeeType(NewPtrTy,
874-
OldPtrTy->getAddressSpace()));
875-
}
872+
if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace())
873+
Ptr = ConstantExpr::getPointerCast(Ptr, OldPtrTy);
876874
return Ptr;
877875
}
878876

llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,10 +1093,8 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
10931093
Value *TID = Builder.CreateAdd(Tmp0, Tmp1);
10941094
TID = Builder.CreateAdd(TID, TIdZ);
10951095

1096-
Value *Indices[] = {
1097-
Constant::getNullValue(Type::getInt32Ty(Mod->getContext())),
1098-
TID
1099-
};
1096+
LLVMContext &Context = Mod->getContext();
1097+
Value *Indices[] = {Constant::getNullValue(Type::getInt32Ty(Context)), TID};
11001098

11011099
Value *Offset = Builder.CreateInBoundsGEP(GVTy, GV, Indices);
11021100
I.mutateType(Offset->getType());
@@ -1109,9 +1107,7 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
11091107
CallInst *Call = dyn_cast<CallInst>(V);
11101108
if (!Call) {
11111109
if (ICmpInst *CI = dyn_cast<ICmpInst>(V)) {
1112-
Value *Src0 = CI->getOperand(0);
1113-
PointerType *NewTy = PointerType::getWithSamePointeeType(
1114-
cast<PointerType>(Src0->getType()), AMDGPUAS::LOCAL_ADDRESS);
1110+
PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
11151111

11161112
if (isa<ConstantPointerNull>(CI->getOperand(0)))
11171113
CI->setOperand(0, ConstantPointerNull::get(NewTy));
@@ -1127,8 +1123,7 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
11271123
if (isa<AddrSpaceCastInst>(V))
11281124
continue;
11291125

1130-
PointerType *NewTy = PointerType::getWithSamePointeeType(
1131-
cast<PointerType>(V->getType()), AMDGPUAS::LOCAL_ADDRESS);
1126+
PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
11321127

11331128
// FIXME: It doesn't really make sense to try to do this for all
11341129
// instructions.
@@ -1188,8 +1183,7 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(AllocaInst &I,
11881183
Function *ObjectSize = Intrinsic::getDeclaration(
11891184
Mod, Intrinsic::objectsize,
11901185
{Intr->getType(),
1191-
PointerType::getWithSamePointeeType(
1192-
cast<PointerType>(Src->getType()), AMDGPUAS::LOCAL_ADDRESS)});
1186+
PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS)});
11931187

11941188
CallInst *NewCall = Builder.CreateCall(
11951189
ObjectSize,

llvm/lib/Target/AMDGPU/AMDGPUPromoteKernelArguments.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool AMDGPUPromoteKernelArguments::promotePointer(Value *Ptr) {
116116
// Cast pointer to global address space and back to flat and let
117117
// Infer Address Spaces pass to do all necessary rewriting.
118118
PointerType *NewPT =
119-
PointerType::getWithSamePointeeType(PT, AMDGPUAS::GLOBAL_ADDRESS);
119+
PointerType::get(PT->getContext(), AMDGPUAS::GLOBAL_ADDRESS);
120120
Value *Cast =
121121
B.CreateAddrSpaceCast(Ptr, NewPT, Twine(Ptr->getName(), ".global"));
122122
Value *CastBack =

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14204,7 +14204,6 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const {
1420414204
Value *Val = AI->getValOperand();
1420514205
Type *ValTy = Val->getType();
1420614206
Value *Addr = AI->getPointerOperand();
14207-
PointerType *PtrTy = cast<PointerType>(Addr->getType());
1420814207

1420914208
auto CreateNewAtomicRMW = [AI](IRBuilder<> &Builder, Value *Addr,
1421014209
Value *Val) -> Value * {
@@ -14229,8 +14228,7 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const {
1422914228

1423014229
Builder.SetInsertPoint(SharedBB);
1423114230
Value *CastToLocal = Builder.CreateAddrSpaceCast(
14232-
Addr,
14233-
PointerType::getWithSamePointeeType(PtrTy, AMDGPUAS::LOCAL_ADDRESS));
14231+
Addr, PointerType::get(Ctx, AMDGPUAS::LOCAL_ADDRESS));
1423414232
Value *LoadedShared = CreateNewAtomicRMW(Builder, CastToLocal, Val);
1423514233
Builder.CreateBr(PhiBB);
1423614234

@@ -14241,8 +14239,7 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const {
1424114239

1424214240
Builder.SetInsertPoint(PrivateBB);
1424314241
Value *CastToPrivate = Builder.CreateAddrSpaceCast(
14244-
Addr,
14245-
PointerType::getWithSamePointeeType(PtrTy, AMDGPUAS::PRIVATE_ADDRESS));
14242+
Addr, PointerType::get(Ctx, AMDGPUAS::PRIVATE_ADDRESS));
1424614243
Value *LoadedPrivate =
1424714244
Builder.CreateLoad(ValTy, CastToPrivate, "loaded.private");
1424814245
Value *NewVal = Builder.CreateFAdd(LoadedPrivate, Val, "val.new");
@@ -14251,8 +14248,7 @@ void SITargetLowering::emitExpandAtomicRMW(AtomicRMWInst *AI) const {
1425114248

1425214249
Builder.SetInsertPoint(GlobalBB);
1425314250
Value *CastToGlobal = Builder.CreateAddrSpaceCast(
14254-
Addr,
14255-
PointerType::getWithSamePointeeType(PtrTy, AMDGPUAS::GLOBAL_ADDRESS));
14251+
Addr, PointerType::get(Ctx, AMDGPUAS::GLOBAL_ADDRESS));
1425614252
Value *LoadedGlobal = CreateNewAtomicRMW(Builder, CastToGlobal, Val);
1425714253
Builder.CreateBr(PhiBB);
1425814254

llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ static void convertToParamAS(Value *OldUser, Value *Param) {
190190
return NewGEP;
191191
}
192192
if (auto *BC = dyn_cast<BitCastInst>(I.OldInstruction)) {
193-
auto *NewBCType = PointerType::getWithSamePointeeType(
194-
cast<PointerType>(BC->getType()), ADDRESS_SPACE_PARAM);
193+
auto *NewBCType = PointerType::get(BC->getContext(), ADDRESS_SPACE_PARAM);
195194
return BitCastInst::Create(BC->getOpcode(), I.NewParam, NewBCType,
196195
BC->getName(), BC);
197196
}
@@ -407,9 +406,7 @@ void NVPTXLowerArgs::markPointerAsGlobal(Value *Ptr) {
407406
}
408407

409408
Instruction *PtrInGlobal = new AddrSpaceCastInst(
410-
Ptr,
411-
PointerType::getWithSamePointeeType(cast<PointerType>(Ptr->getType()),
412-
ADDRESS_SPACE_GLOBAL),
409+
Ptr, PointerType::get(Ptr->getContext(), ADDRESS_SPACE_GLOBAL),
413410
Ptr->getName(), &*InsertPt);
414411
Value *PtrInGeneric = new AddrSpaceCastInst(PtrInGlobal, Ptr->getType(),
415412
Ptr->getName(), &*InsertPt);

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11928,9 +11928,8 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
1192811928
getAssociatedType()->getPointerAddressSpace())
1192911929
return ChangeStatus::UNCHANGED;
1193011930

11931-
Type *NewPtrTy = PointerType::getWithSamePointeeType(
11932-
cast<PointerType>(getAssociatedType()),
11933-
static_cast<uint32_t>(getAddressSpace()));
11931+
Type *NewPtrTy = PointerType::get(getAssociatedType()->getContext(),
11932+
static_cast<uint32_t>(getAddressSpace()));
1193411933
bool UseOriginalValue =
1193511934
OriginalValue->getType()->getPointerAddressSpace() ==
1193611935
static_cast<uint32_t>(getAddressSpace());

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4317,10 +4317,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
43174317
if (WorkFnAI->getType()->getPointerAddressSpace() !=
43184318
(unsigned int)AddressSpace::Generic) {
43194319
WorkFnAI = new AddrSpaceCastInst(
4320-
WorkFnAI,
4321-
PointerType::getWithSamePointeeType(
4322-
cast<PointerType>(WorkFnAI->getType()),
4323-
(unsigned int)AddressSpace::Generic),
4320+
WorkFnAI, PointerType::get(Ctx, (unsigned int)AddressSpace::Generic),
43244321
WorkFnAI->getName() + ".generic", StateMachineBeginBB);
43254322
WorkFnAI->setDebugLoc(DLoc);
43264323
}

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,8 @@ void PointerReplacer::replace(Instruction *I) {
404404
} else if (auto *BC = dyn_cast<BitCastInst>(I)) {
405405
auto *V = getReplacement(BC->getOperand(0));
406406
assert(V && "Operand not replaced");
407-
auto *NewT = PointerType::getWithSamePointeeType(
408-
cast<PointerType>(BC->getType()),
409-
V->getType()->getPointerAddressSpace());
407+
auto *NewT = PointerType::get(BC->getType()->getContext(),
408+
V->getType()->getPointerAddressSpace());
410409
auto *NewI = new BitCastInst(V, NewT);
411410
IC.InsertNewInstWith(NewI, *BC);
412411
NewI->takeName(BC);

llvm/unittests/IR/TypesTest.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ TEST(TypesTest, LayoutIdenticalEmptyStructs) {
3535
EXPECT_TRUE(Foo->isLayoutIdentical(Bar));
3636
}
3737

38-
TEST(TypesTest, CopyPointerType) {
39-
LLVMContext C;
40-
41-
PointerType *P1 = PointerType::get(C, 1);
42-
EXPECT_TRUE(P1->isOpaque());
43-
PointerType *P1C = PointerType::getWithSamePointeeType(P1, 1);
44-
EXPECT_EQ(P1, P1C);
45-
EXPECT_TRUE(P1C->isOpaque());
46-
PointerType *P1C0 = PointerType::getWithSamePointeeType(P1, 0);
47-
EXPECT_NE(P1, P1C0);
48-
EXPECT_TRUE(P1C0->isOpaque());
49-
}
50-
5138
TEST(TypesTest, TargetExtType) {
5239
LLVMContext Context;
5340
Type *A = TargetExtType::get(Context, "typea");

0 commit comments

Comments
 (0)