[llvm] ad4bb82 - [IR] Add Type::isOpaquePointerTy() helper (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 25 11:57:09 PDT 2021
Author: Nikita Popov
Date: 2021-06-25T20:56:59+02:00
New Revision: ad4bb8280952c2cacf497e30560ee94c119b36e0
URL: https://github.com/llvm/llvm-project/commit/ad4bb8280952c2cacf497e30560ee94c119b36e0
DIFF: https://github.com/llvm/llvm-project/commit/ad4bb8280952c2cacf497e30560ee94c119b36e0.diff
LOG: [IR] Add Type::isOpaquePointerTy() helper (NFC)
Shortcut to check for opaque pointers without a cast to PointerType.
Added:
Modified:
llvm/include/llvm/IR/Type.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/Type.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h
index 1cf4db5990820..430bc34a47e70 100644
--- a/llvm/include/llvm/IR/Type.h
+++ b/llvm/include/llvm/IR/Type.h
@@ -227,6 +227,9 @@ class Type {
/// 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(); }
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index be3b7358270eb..bcdf51c47f964 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -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;
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index a7be01415fbf9..a21998976066c 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -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.
More information about the llvm-commits
mailing list