[llvm] 5a201a7 - [LLVMContextImpl] Separate out opaque pointers

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 27 14:13:14 PST 2023


Author: Arthur Eubanks
Date: 2023-02-27T14:13:03-08:00
New Revision: 5a201a730539eef4ea6f6e6cd5976bc38565dc99

URL: https://github.com/llvm/llvm-project/commit/5a201a730539eef4ea6f6e6cd5976bc38565dc99
DIFF: https://github.com/llvm/llvm-project/commit/5a201a730539eef4ea6f6e6cd5976bc38565dc99.diff

LOG: [LLVMContextImpl] Separate out opaque pointers

To make the map lookups simpler for opaque pointers and to simplify future typed pointer code removal. No significant compile time wins though.

While we're here, remove the address space 0 optimization for typed pointers.

Reviewed By: nikic

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

Added: 
    

Modified: 
    llvm/lib/IR/LLVMContextImpl.h
    llvm/lib/IR/Type.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h
index 7d6c65ab2a21..3e7e3426aba7 100644
--- a/llvm/lib/IR/LLVMContextImpl.h
+++ b/llvm/lib/IR/LLVMContextImpl.h
@@ -1535,8 +1535,9 @@ class LLVMContextImpl {
 
   DenseMap<std::pair<Type *, uint64_t>, ArrayType *> ArrayTypes;
   DenseMap<std::pair<Type *, ElementCount>, VectorType *> VectorTypes;
-  DenseMap<Type *, PointerType *> PointerTypes; // Pointers in AddrSpace = 0
-  DenseMap<std::pair<Type *, unsigned>, PointerType *> ASPointerTypes;
+  PointerType *AS0PointerType = nullptr; // AddrSpace = 0
+  DenseMap<unsigned, PointerType *> PointerTypes;
+  DenseMap<std::pair<Type *, unsigned>, PointerType *> LegacyPointerTypes;
   DenseMap<std::pair<Type *, unsigned>, TypedPointerType *> ASTypedPointerTypes;
 
   /// ValueHandles - This map keeps track of all of the value handles that are

diff  --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 8c77e9862df0..182ae0663cbe 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -748,9 +748,8 @@ PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
   if (CImpl->getOpaquePointers())
     return get(EltTy->getContext(), AddressSpace);
 
-  // Since AddressSpace #0 is the common case, we special case it.
-  PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy]
-     : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)];
+  PointerType *&Entry =
+      CImpl->LegacyPointerTypes[std::make_pair(EltTy, AddressSpace)];
 
   if (!Entry)
     Entry = new (CImpl->Alloc) PointerType(EltTy, AddressSpace);
@@ -763,10 +762,8 @@ PointerType *PointerType::get(LLVMContext &C, unsigned AddressSpace) {
          "Can only create opaque pointers in opaque pointer mode");
 
   // Since AddressSpace #0 is the common case, we special case it.
-  PointerType *&Entry =
-      AddressSpace == 0
-          ? CImpl->PointerTypes[nullptr]
-          : CImpl->ASPointerTypes[std::make_pair(nullptr, AddressSpace)];
+  PointerType *&Entry = AddressSpace == 0 ? CImpl->AS0PointerType
+                                          : CImpl->PointerTypes[AddressSpace];
 
   if (!Entry)
     Entry = new (CImpl->Alloc) PointerType(C, AddressSpace);


        


More information about the llvm-commits mailing list