[PATCH] Add CreatePointerBitCastOrAddrSpaceCast to IRBuilder and co.
Quentin Colombet
qcolombet at apple.com
Thu Mar 6 15:16:48 PST 2014
Let me be more specific on the proposal.
I think CastInst::CreatePointerCast can call CastInst::CreatePointerBitCastOrAddrSpaceCast as soon as we handled the PtrToInt part.
I.e.,
CastInst *CastInst::CreatePointerCast(Value *S, Type *Ty,
const Twine &Name,
BasicBlock *InsertAtEnd) {
assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast");
assert((Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) &&
"Invalid cast");
assert(Ty->isVectorTy() == S->getType()->isVectorTy() && "Invalid cast");
assert((!Ty->isVectorTy() ||
Ty->getVectorNumElements() == S->getType()->getVectorNumElements()) &&
"Invalid cast");
if (Ty->isIntOrIntVectorTy())
return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
/* ==== Call Your New method instead ==== */
Type *STy = S->getType();
if (STy->getPointerAddressSpace() != Ty->getPointerAddressSpace())
return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertAtEnd);
return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
/* ====== */
}
Same thing for the instruction version.
Moreover, we should do the same for Constant *ConstantExpr::getPointerCast(Constant *S, Type *Ty).
Again maybe I am missing something, but at first glance, it seems at those points in the code path of XXXPointerCast we have the same restriction, isn’t it?
Thanks,
-Quentin
http://llvm-reviews.chandlerc.com/D2598
More information about the llvm-commits
mailing list