}
/// 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<PointerType>(Ptr->getType());
Ptr = cast<Constant>(Ptr->stripPointerCasts());
auto *NewPtrTy = cast<PointerType>(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;
}
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());
CallInst *Call = dyn_cast<CallInst>(V);
if (!Call) {
if (ICmpInst *CI = dyn_cast<ICmpInst>(V)) {
- Value *Src0 = CI->getOperand(0);
- PointerType *NewTy = PointerType::getWithSamePointeeType(
- cast<PointerType>(Src0->getType()), AMDGPUAS::LOCAL_ADDRESS);
+ PointerType *NewTy = PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS);
if (isa<ConstantPointerNull>(CI->getOperand(0)))
CI->setOperand(0, ConstantPointerNull::get(NewTy));
if (isa<AddrSpaceCastInst>(V))
continue;
- PointerType *NewTy = PointerType::getWithSamePointeeType(
- cast<PointerType>(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.
Function *ObjectSize = Intrinsic::getDeclaration(
Mod, Intrinsic::objectsize,
{Intr->getType(),
- PointerType::getWithSamePointeeType(
- cast<PointerType>(Src->getType()), AMDGPUAS::LOCAL_ADDRESS)});
+ PointerType::get(Context, AMDGPUAS::LOCAL_ADDRESS)});
CallInst *NewCall = Builder.CreateCall(
ObjectSize,
// 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 =
Value *Val = AI->getValOperand();
Type *ValTy = Val->getType();
Value *Addr = AI->getPointerOperand();
- PointerType *PtrTy = cast<PointerType>(Addr->getType());
auto CreateNewAtomicRMW = [AI](IRBuilder<> &Builder, Value *Addr,
Value *Val) -> Value * {
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);
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");
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);
return NewGEP;
}
if (auto *BC = dyn_cast<BitCastInst>(I.OldInstruction)) {
- auto *NewBCType = PointerType::getWithSamePointeeType(
- cast<PointerType>(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);
}
}
Instruction *PtrInGlobal = new AddrSpaceCastInst(
- Ptr,
- PointerType::getWithSamePointeeType(cast<PointerType>(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);
getAssociatedType()->getPointerAddressSpace())
return ChangeStatus::UNCHANGED;
- Type *NewPtrTy = PointerType::getWithSamePointeeType(
- cast<PointerType>(getAssociatedType()),
- static_cast<uint32_t>(getAddressSpace()));
+ Type *NewPtrTy = PointerType::get(getAssociatedType()->getContext(),
+ static_cast<uint32_t>(getAddressSpace()));
bool UseOriginalValue =
OriginalValue->getType()->getPointerAddressSpace() ==
static_cast<uint32_t>(getAddressSpace());
if (WorkFnAI->getType()->getPointerAddressSpace() !=
(unsigned int)AddressSpace::Generic) {
WorkFnAI = new AddrSpaceCastInst(
- WorkFnAI,
- PointerType::getWithSamePointeeType(
- cast<PointerType>(WorkFnAI->getType()),
- (unsigned int)AddressSpace::Generic),
+ WorkFnAI, PointerType::get(Ctx, (unsigned int)AddressSpace::Generic),
WorkFnAI->getName() + ".generic", StateMachineBeginBB);
WorkFnAI->setDebugLoc(DLoc);
}
} else if (auto *BC = dyn_cast<BitCastInst>(I)) {
auto *V = getReplacement(BC->getOperand(0));
assert(V && "Operand not replaced");
- auto *NewT = PointerType::getWithSamePointeeType(
- cast<PointerType>(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);
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");