[llvm] 2ea5aa1 - [IR] Deprecate opaque pointer compatibility APIs

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 01:21:18 PDT 2023


Author: Nikita Popov
Date: 2023-07-19T10:21:10+02:00
New Revision: 2ea5aa1c96cfb15ece9a665f0d59d6c9fa1365f0

URL: https://github.com/llvm/llvm-project/commit/2ea5aa1c96cfb15ece9a665f0d59d6c9fa1365f0
DIFF: https://github.com/llvm/llvm-project/commit/2ea5aa1c96cfb15ece9a665f0d59d6c9fa1365f0.diff

LOG: [IR] Deprecate opaque pointer compatibility APIs

This deprecates various compatibility APIs that have been
introduced as part of the opaque pointer migration.

These will be removed at some point after the LLVM 17 release.

Differential Revision: https://reviews.llvm.org/D155585

Added: 
    

Modified: 
    llvm/include/llvm/IR/DerivedTypes.h
    llvm/include/llvm/IR/LLVMContext.h
    llvm/include/llvm/IR/Type.h
    llvm/lib/IR/Type.cpp
    llvm/unittests/AsmParser/AsmParserTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 4f8c9e65ff9347..f98dcc62650047 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -644,8 +644,6 @@ class PointerType : public Type {
   explicit PointerType(Type *ElType, unsigned AddrSpace);
   explicit PointerType(LLVMContext &C, unsigned AddrSpace);
 
-  Type *PointeeTy;
-
 public:
   PointerType(const PointerType &) = delete;
   PointerType &operator=(const PointerType &) = delete;
@@ -674,14 +672,14 @@ class PointerType : public Type {
   /// given address space. This is only useful during the opaque pointer
   /// transition.
   /// TODO: remove after opaque pointer transition is complete.
+  [[deprecated("Use PointerType::get() with LLVMContext argument instead")]]
   static PointerType *getWithSamePointeeType(PointerType *PT,
                                              unsigned AddressSpace) {
-    if (PT->isOpaque())
-      return get(PT->getContext(), AddressSpace);
-    return get(PT->PointeeTy, AddressSpace);
+    return get(PT->getContext(), AddressSpace);
   }
 
-  bool isOpaque() const { return !PointeeTy; }
+  [[deprecated("Always returns true")]]
+  bool isOpaque() const { return true; }
 
   /// Return true if the specified type is valid as a element type.
   static bool isValidElementType(Type *ElemTy);
@@ -696,16 +694,18 @@ class PointerType : public Type {
   /// type matches Ty. Primarily used for checking if an instruction's pointer
   /// operands are valid types. Will be useless after non-opaque pointers are
   /// removed.
-  bool isOpaqueOrPointeeTypeMatches(Type *Ty) {
-    return isOpaque() || PointeeTy == Ty;
+  [[deprecated("Always returns true")]]
+  bool isOpaqueOrPointeeTypeMatches(Type *) {
+    return true;
   }
 
   /// Return true if both pointer types have the same element type. Two opaque
   /// pointers are considered to have the same element type, while an opaque
   /// and a non-opaque pointer have 
diff erent element types.
   /// TODO: Remove after opaque pointer transition is complete.
+  [[deprecated("Always returns true")]]
   bool hasSameElementTypeAs(PointerType *Other) {
-    return PointeeTy == Other->PointeeTy;
+    return true;
   }
 
   /// Implement support type inquiry through isa, cast, and dyn_cast.

diff  --git a/llvm/include/llvm/IR/LLVMContext.h b/llvm/include/llvm/IR/LLVMContext.h
index 2eedf2b9f77625..e5786afd72214b 100644
--- a/llvm/include/llvm/IR/LLVMContext.h
+++ b/llvm/include/llvm/IR/LLVMContext.h
@@ -316,9 +316,11 @@ class LLVMContext {
   /// times, but only with the same value. Note that creating a pointer type or
   /// otherwise querying the opaque pointer mode performs an implicit set to
   /// the default value.
+  [[deprecated("Opaque pointers are always enabled")]]
   void setOpaquePointers(bool Enable) const;
 
   /// Whether typed pointers are supported. If false, all pointers are opaque.
+  [[deprecated("Always returns false")]]
   bool supportsTypedPointers() const;
 
 private:

diff  --git a/llvm/include/llvm/IR/Type.h b/llvm/include/llvm/IR/Type.h
index 12aaf6cab458b2..fc558e6ee5db64 100644
--- a/llvm/include/llvm/IR/Type.h
+++ b/llvm/include/llvm/IR/Type.h
@@ -256,7 +256,8 @@ class Type {
   bool isPointerTy() const { return getTypeID() == PointerTyID; }
 
   /// True if this is an instance of an opaque PointerType.
-  bool isOpaquePointerTy() const;
+  LLVM_DEPRECATED("Use isPointerTy() instead", "isPointerTy")
+  bool isOpaquePointerTy() const { return isPointerTy(); };
 
   /// Return true if this is a pointer type or a vector of pointer types.
   bool isPtrOrPtrVectorTy() const { return getScalarType()->isPointerTy(); }
@@ -411,11 +412,9 @@ class Type {
   /// Only use this method in code that is not reachable with opaque pointers,
   /// or part of deprecated methods that will be removed as part of the opaque
   /// pointers transition.
+  [[deprecated("Pointers no longer have element types")]]
   Type *getNonOpaquePointerElementType() const {
-    assert(getTypeID() == PointerTyID);
-    assert(NumContainedTys &&
-           "Attempting to get element type of opaque pointer");
-    return ContainedTys[0];
+    llvm_unreachable("Pointers no longer have element types");
   }
 
   /// Given vector type, change the element type,

diff  --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 3515645e7de20a..ba4d0f5dc18db5 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -57,12 +57,6 @@ 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::isScalableTy() const {
   if (const auto *STy = dyn_cast<StructType>(this)) {
     SmallPtrSet<Type *, 4> Visited;
@@ -814,15 +808,8 @@ PointerType *PointerType::get(LLVMContext &C, unsigned AddressSpace) {
   return Entry;
 }
 
-PointerType::PointerType(Type *E, unsigned AddrSpace)
-  : Type(E->getContext(), PointerTyID), PointeeTy(E) {
-  ContainedTys = &PointeeTy;
-  NumContainedTys = 1;
-  setSubclassData(AddrSpace);
-}
-
 PointerType::PointerType(LLVMContext &C, unsigned AddrSpace)
-    : Type(C, PointerTyID), PointeeTy(nullptr) {
+    : Type(C, PointerTyID) {
   setSubclassData(AddrSpace);
 }
 

diff  --git a/llvm/unittests/AsmParser/AsmParserTest.cpp b/llvm/unittests/AsmParser/AsmParserTest.cpp
index ee6cd709cf651a..77dba5bfd4cae8 100644
--- a/llvm/unittests/AsmParser/AsmParserTest.cpp
+++ b/llvm/unittests/AsmParser/AsmParserTest.cpp
@@ -252,9 +252,6 @@ TEST(AsmParserTest, TypeWithSlotMappingParsing) {
   ASSERT_TRUE(Ty);
   ASSERT_TRUE(Ty->isPointerTy());
 
-  PointerType *PT = cast<PointerType>(Ty);
-  ASSERT_TRUE(PT->isOpaque());
-
   // Check that we reject types with garbage.
   Ty = parseType("i32 garbage", Error, M, &Mapping);
   ASSERT_TRUE(!Ty);
@@ -370,9 +367,6 @@ TEST(AsmParserTest, TypeAtBeginningWithSlotMappingParsing) {
   ASSERT_TRUE(Ty->isPointerTy());
   ASSERT_TRUE(Read == 3);
 
-  PointerType *PT = cast<PointerType>(Ty);
-  ASSERT_TRUE(PT->isOpaque());
-
   // Check that we reject types with garbage.
   Ty = parseTypeAtBeginning("i32 garbage", Read, Error, M, &Mapping);
   ASSERT_TRUE(Ty);


        


More information about the llvm-commits mailing list