Skip to content

Commit

Permalink
Use getPointerAddressSpace instead of cast<PointerType>.getAddressSpace.
Browse files Browse the repository at this point in the history
The former also handles vectors of pointers, which can occur after vectorization:

```
#5  0x00007f5bfe94de5e in llvm::cast<llvm::PointerType, llvm::Type> (Val=<optimized out>) at llvm/Support/Casting.h:578
578	  assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");

(rr) up
#6  GCInvariantVerifier::visitAddrSpaceCastInst (this=this@entry=0x7ffd022fbf56, I=...) at julia/src/llvm-gc-invariant-verifier.cpp:66
66	    unsigned ToAS = cast<PointerType>(I.getDestTy())->getAddressSpace();

(rr) call I.dump()
%23 = addrspacecast <4 x ptr addrspace(10)> %wide.load to <4 x ptr addrspace(11)>, !dbg !43
```
  • Loading branch information
maleadt committed Apr 18, 2024
1 parent c741bd3 commit da0c190
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static Value *maybe_decay_untracked(jl_codectx_t &ctx, Value *V)
static Value *decay_derived(jl_codectx_t &ctx, Value *V)
{
Type *T = V->getType();
if (cast<PointerType>(T)->getAddressSpace() == AddressSpace::Derived)
if (T->getPointerAddressSpace() == AddressSpace::Derived)
return V;
// Once llvm deletes pointer element types, we won't need it here any more either.
Type *NewT = PointerType::getWithSamePointeeType(cast<PointerType>(T), AddressSpace::Derived);
Expand All @@ -68,7 +68,7 @@ static Value *decay_derived(jl_codectx_t &ctx, Value *V)
static Value *maybe_decay_tracked(jl_codectx_t &ctx, Value *V)
{
Type *T = V->getType();
if (cast<PointerType>(T)->getAddressSpace() != AddressSpace::Tracked)
if (T->getPointerAddressSpace() != AddressSpace::Tracked)
return V;
Type *NewT = PointerType::getWithSamePointeeType(cast<PointerType>(T), AddressSpace::Derived);
return ctx.builder.CreateAddrSpaceCast(V, NewT);
Expand Down Expand Up @@ -295,7 +295,7 @@ void jl_debugcache_t::initialize(Module *m) {

static Value *emit_pointer_from_objref(jl_codectx_t &ctx, Value *V)
{
unsigned AS = cast<PointerType>(V->getType())->getAddressSpace();
unsigned AS = V->getType()->getPointerAddressSpace();
if (AS != AddressSpace::Tracked && AS != AddressSpace::Derived)
return V;
V = decay_derived(ctx, V);
Expand Down
5 changes: 3 additions & 2 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,11 @@ void Optimizer::splitOnStack(CallInst *orig_inst)
store_ty = T_pjlvalue;
}
else {
store_ty = PointerType::getWithSamePointeeType(T_pjlvalue, cast<PointerType>(store_ty)->getAddressSpace());
store_ty = PointerType::getWithSamePointeeType(
T_pjlvalue, store_ty->getPointerAddressSpace());
store_val = builder.CreateBitCast(store_val, store_ty);
}
if (cast<PointerType>(store_ty)->getAddressSpace() != AddressSpace::Tracked)
if (store_ty->getPointerAddressSpace() != AddressSpace::Tracked)
store_val = builder.CreateAddrSpaceCast(store_val, pass.T_prjlvalue);
newstore = builder.CreateStore(store_val, slot.slot);
}
Expand Down
19 changes: 10 additions & 9 deletions src/llvm-gc-invariant-verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ struct GCInvariantVerifier : public InstVisitor<GCInvariantVerifier> {
};

void GCInvariantVerifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
unsigned FromAS = cast<PointerType>(I.getSrcTy())->getAddressSpace();
unsigned ToAS = cast<PointerType>(I.getDestTy())->getAddressSpace();
unsigned FromAS = I.getSrcTy()->getPointerAddressSpace();
unsigned ToAS = I.getDestTy()->getPointerAddressSpace();
if (FromAS == 0)
return;
Check(ToAS != AddressSpace::Loaded && FromAS != AddressSpace::Loaded,
Expand All @@ -81,7 +81,7 @@ void GCInvariantVerifier::checkStoreInst(Type *VTy, unsigned AS, Value &SI) {
if (VTy->isPointerTy()) {
/* We currently don't obey this for arguments. That's ok - they're
externally rooted. */
unsigned AS = cast<PointerType>(VTy)->getAddressSpace();
unsigned AS = VTy->getPointerAddressSpace();
Check(AS != AddressSpace::CalleeRooted &&
AS != AddressSpace::Derived,
"Illegal store of decayed value", &SI);
Expand All @@ -108,14 +108,14 @@ void GCInvariantVerifier::visitAtomicCmpXchgInst(AtomicCmpXchgInst &SI) {
void GCInvariantVerifier::visitLoadInst(LoadInst &LI) {
Type *Ty = LI.getType();
if (Ty->isPointerTy()) {
unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
unsigned AS = Ty->getPointerAddressSpace();
Check(AS != AddressSpace::CalleeRooted &&
AS != AddressSpace::Derived,
"Illegal load of gc relevant value", &LI);
}
Ty = LI.getPointerOperand()->getType();
if (Ty->isPointerTy()) {
unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
unsigned AS = Ty->getPointerAddressSpace();
Check(AS != AddressSpace::CalleeRooted,
"Illegal load of callee rooted value", &LI);
}
Expand All @@ -131,7 +131,7 @@ void GCInvariantVerifier::visitReturnInst(ReturnInst &RI) {
Type *RTy = RI.getReturnValue()->getType();
if (!RTy->isPointerTy())
return;
unsigned AS = cast<PointerType>(RTy)->getAddressSpace();
unsigned AS = RTy->getPointerAddressSpace();
Check(!isSpecialAS(AS) || AS == AddressSpace::Tracked,
"Only gc tracked values may be directly returned", &RI);
}
Expand All @@ -140,7 +140,7 @@ void GCInvariantVerifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
Type *Ty = GEP.getType();
if (!Ty->isPointerTy())
return;
unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
unsigned AS = Ty->getPointerAddressSpace();
if (!isSpecialAS(AS))
return;
/* We're actually ok with GEPs here, as long as they don't feed into any
Expand Down Expand Up @@ -170,8 +170,9 @@ void GCInvariantVerifier::visitCallInst(CallInst &CI) {
continue;
}
Type *Ty = Arg->getType();
Check(Ty->isPointerTy() && cast<PointerType>(Ty)->getAddressSpace() == AddressSpace::Tracked,
"Invalid derived pointer in jlcall", &CI);
Check(Ty->isPointerTy() &&
Ty->getPointerAddressSpace() == AddressSpace::Tracked,
"Invalid derived pointer in jlcall", &CI);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-propagate-addrspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct PropagateJuliaAddrspacesVisitor : public InstVisitor<PropagateJuliaAddrsp
};

static unsigned getValueAddrSpace(Value *V) {
return cast<PointerType>(V->getType())->getAddressSpace();
return V->getType()->getPointerAddressSpace();
}

static bool isSpecialAS(unsigned AS) {
Expand Down

0 comments on commit da0c190

Please sign in to comment.