1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[IR] Add Type::isOpaquePointerTy() helper (NFC)

Shortcut to check for opaque pointers without a cast to PointerType.
This commit is contained in:
Nikita Popov 2021-06-25 20:55:09 +02:00
parent 20d5a26896
commit 33e01a9045
3 changed files with 11 additions and 3 deletions

View File

@ -227,6 +227,9 @@ public:
/// True if this is an instance of PointerType.
bool isPointerTy() const { return getTypeID() == PointerTyID; }
/// True if this is an instance of an opaque PointerType.
bool isOpaquePointerTy() const;
/// Return true if this is a pointer type or a vector of pointer types.
bool isPtrOrPtrVectorTy() const { return getScalarType()->isPointerTy(); }

View File

@ -2575,7 +2575,7 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) {
}
}
if (Result->isPointerTy() && cast<PointerType>(Result)->isOpaque()) {
if (Result->isOpaquePointerTy()) {
unsigned AddrSpace;
if (parseOptionalAddrSpace(AddrSpace))
return true;

View File

@ -60,6 +60,12 @@ bool Type::isIntegerTy(unsigned Bitwidth) const {
return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
}
bool Type::isOpaquePointerTy() const {
if (auto *PTy = dyn_cast<PointerType>(this))
return PTy->isOpaque();
return false;
}
bool Type::canLosslesslyBitCastTo(Type *Ty) const {
// Identity cast means no change so return true
if (this == Ty)
@ -691,8 +697,7 @@ PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
// Create opaque pointer for pointer to opaque pointer.
if (CImpl->ForceOpaquePointers ||
(isa<PointerType>(EltTy) && cast<PointerType>(EltTy)->isOpaque()))
if (CImpl->ForceOpaquePointers || EltTy->isOpaquePointerTy())
return get(EltTy->getContext(), AddressSpace);
// Since AddressSpace #0 is the common case, we special case it.