[DirectX] Remove uses of isOpaquePointerTy(). NFC
authorJustin Bogner <mail@justinbogner.com>
Wed, 19 Jul 2023 19:04:38 +0000 (12:04 -0700)
committerJustin Bogner <mail@justinbogner.com>
Wed, 19 Jul 2023 21:28:05 +0000 (14:28 -0700)
isOpaquePointerTy now returns true for all pointers, so we can replace
these with isPointerTy().

llvm/lib/Target/DirectX/DXILPrepare.cpp
llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
llvm/lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp

index d339430..660ca41 100644 (file)
@@ -127,9 +127,6 @@ public:
             I.eraseFromParent();
             continue;
           }
-          // Only insert bitcasts if the IR is using opaque pointers.
-          if (M.getContext().supportsTypedPointers())
-            continue;
 
           // Emtting NoOp bitcast instructions allows the ValueEnumerator to be
           // unmodified as it reserves instruction IDs during contruction.
index 328bea5..2c321f4 100644 (file)
@@ -513,7 +513,7 @@ unsigned DXILBitcodeWriter::getEncodedBinaryOpcode(unsigned Opcode) {
 }
 
 unsigned DXILBitcodeWriter::getTypeID(Type *T, const Value *V) {
-  if (!T->isOpaquePointerTy() &&
+  if (!T->isPointerTy() &&
       // For Constant, always check PointerMap to make sure OpaquePointer in
       // things like constant struct/array works.
       (!V || !isa<Constant>(V)))
@@ -1070,24 +1070,14 @@ void DXILBitcodeWriter::writeTypeTable() {
       break;
     }
     case Type::PointerTyID: {
-      PointerType *PTy = cast<PointerType>(T);
       // POINTER: [pointee type, address space]
-      Code = bitc::TYPE_CODE_POINTER;
-      // Emitting an empty struct type for the opaque pointer's type allows
-      // this to be order-independent. Non-struct types must be emitted in
-      // bitcode before they can be referenced.
-      if (PTy->isOpaquePointerTy()) {
-        TypeVals.push_back(false);
-        Code = bitc::TYPE_CODE_OPAQUE;
-        writeStringRecord(Stream, bitc::TYPE_CODE_STRUCT_NAME,
-                          "dxilOpaquePtrReservedName", StructNameAbbrev);
-      } else {
-        TypeVals.push_back(getTypeID(PTy->getNonOpaquePointerElementType()));
-        unsigned AddressSpace = PTy->getAddressSpace();
-        TypeVals.push_back(AddressSpace);
-        if (AddressSpace == 0)
-          AbbrevToUse = PtrAbbrev;
-      }
+      // Emitting an empty struct type for the pointer's type allows this to be
+      // order-independent. Non-struct types must be emitted in bitcode before
+      // they can be referenced.
+      TypeVals.push_back(false);
+      Code = bitc::TYPE_CODE_OPAQUE;
+      writeStringRecord(Stream, bitc::TYPE_CODE_STRUCT_NAME,
+                        "dxilOpaquePtrReservedName", StructNameAbbrev);
       break;
     }
     case Type::FunctionTyID: {
index eea8994..97b7a41 100644 (file)
@@ -22,15 +22,15 @@ namespace {
 // Classifies the type of the value passed in by walking the value's users to
 // find a typed instruction to materialize a type from.
 Type *classifyPointerType(const Value *V, PointerTypeMap &Map) {
-  assert(V->getType()->isOpaquePointerTy() &&
-         "classifyPointerType called with non-opaque pointer");
+  assert(V->getType()->isPointerTy() &&
+         "classifyPointerType called with non-pointer");
   auto It = Map.find(V);
   if (It != Map.end())
     return It->second;
 
   Type *PointeeTy = nullptr;
   if (auto *Inst = dyn_cast<GetElementPtrInst>(V)) {
-    if (!Inst->getResultElementType()->isOpaquePointerTy())
+    if (!Inst->getResultElementType()->isPointerTy())
       PointeeTy = Inst->getResultElementType();
   } else if (auto *Inst = dyn_cast<AllocaInst>(V)) {
     PointeeTy = Inst->getAllocatedType();
@@ -45,7 +45,7 @@ Type *classifyPointerType(const Value *V, PointerTypeMap &Map) {
     } else if (const auto *Inst = dyn_cast<StoreInst>(User)) {
       NewPointeeTy = Inst->getValueOperand()->getType();
       // When store value is ptr type, cannot get more type info.
-      if (NewPointeeTy->isOpaquePointerTy())
+      if (NewPointeeTy->isPointerTy())
         continue;
     } else if (const auto *Inst = dyn_cast<GetElementPtrInst>(User)) {
       NewPointeeTy = Inst->getSourceElementType();
@@ -54,7 +54,7 @@ Type *classifyPointerType(const Value *V, PointerTypeMap &Map) {
       // HLSL doesn't support pointers, so it is unlikely to get more than one
       // or two levels of indirection in the IR. Because of this, recursion is
       // pretty safe.
-      if (NewPointeeTy->isOpaquePointerTy()) {
+      if (NewPointeeTy->isPointerTy()) {
         PointeeTy = classifyPointerType(User, Map);
         break;
       }
@@ -85,7 +85,7 @@ Type *classifyFunctionType(const Function &F, PointerTypeMap &Map) {
   SmallVector<Type *, 8> NewArgs;
   Type *RetTy = F.getReturnType();
   LLVMContext &Ctx = F.getContext();
-  if (RetTy->isOpaquePointerTy()) {
+  if (RetTy->isPointerTy()) {
     RetTy = nullptr;
     for (const auto &B : F) {
       const auto *RetInst = dyn_cast_or_null<ReturnInst>(B.getTerminator());
@@ -106,7 +106,7 @@ Type *classifyFunctionType(const Function &F, PointerTypeMap &Map) {
   }
   for (auto &A : F.args()) {
     Type *ArgTy = A.getType();
-    if (ArgTy->isOpaquePointerTy())
+    if (ArgTy->isPointerTy())
       ArgTy = classifyPointerType(&A, Map);
     NewArgs.push_back(ArgTy);
   }
@@ -189,7 +189,7 @@ static void classifyGlobalCtorPointerType(const GlobalVariable &GV,
 PointerTypeMap PointerTypeAnalysis::run(const Module &M) {
   PointerTypeMap Map;
   for (auto &G : M.globals()) {
-    if (G.getType()->isOpaquePointerTy())
+    if (G.getType()->isPointerTy())
       classifyPointerType(&G, Map);
     if (G.getName() == "llvm.global_ctors")
       classifyGlobalCtorPointerType(G, Map);
@@ -200,7 +200,7 @@ PointerTypeMap PointerTypeAnalysis::run(const Module &M) {
 
     for (const auto &B : F) {
       for (const auto &I : B) {
-        if (I.getType()->isOpaquePointerTy())
+        if (I.getType()->isPointerTy())
           classifyPointerType(&I, Map);
       }
     }