[llvm] [SPIR-V] Ensure that DuplicatesTracker is working with TypedPointers pointee types (PR #94952)

Vyacheslav Levytskyy via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 03:29:23 PDT 2024


https://github.com/VyacheslavLevytskyy created https://github.com/llvm/llvm-project/pull/94952

This PR is a tweak to ensure that DuplicatesTracker is working with TypedPointers pointee types rather than with original llvm's untyped pointers. This enforces DuplicatesTracker promise to avoid emission of several identical OpTypePointer instructions.

>From 4342cb8fa020940c06fe35a2d0638fd33c3907e3 Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Mon, 10 Jun 2024 03:23:55 -0700
Subject: [PATCH] ensure DuplicatesTracker is working with TypedPointers
 pointee types

---
 .../lib/Target/SPIRV/SPIRVDuplicatesTracker.h | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.h b/llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.h
index 2ec3fb35ca045..3c8405fadd44e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.h
+++ b/llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.h
@@ -16,6 +16,7 @@
 
 #include "MCTargetDesc/SPIRVBaseInfo.h"
 #include "MCTargetDesc/SPIRVMCTargetDesc.h"
+#include "SPIRVUtils.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
@@ -285,10 +286,13 @@ class SPIRVGeneralDuplicatesTracker {
     TT.add(Ty, MF, R);
   }
 
-  void add(const Type *PointerElementType, unsigned AddressSpace,
+  void add(const Type *PointeeTy, unsigned AddressSpace,
            const MachineFunction *MF, Register R) {
-    ST.add(SPIRV::PointerTypeDescriptor(PointerElementType, AddressSpace), MF,
-           R);
+    if (isUntypedPointerTy(PointeeTy))
+      PointeeTy =
+          TypedPointerType::get(IntegerType::getInt8Ty(PointeeTy->getContext()),
+                                getPointerAddressSpace(PointeeTy));
+    ST.add(SPIRV::PointerTypeDescriptor(PointeeTy, AddressSpace), MF, R);
   }
 
   void add(const Constant *C, const MachineFunction *MF, Register R) {
@@ -320,10 +324,13 @@ class SPIRVGeneralDuplicatesTracker {
     return TT.find(const_cast<Type *>(Ty), MF);
   }
 
-  Register find(const Type *PointerElementType, unsigned AddressSpace,
+  Register find(const Type *PointeeTy, unsigned AddressSpace,
                 const MachineFunction *MF) {
-    return ST.find(
-        SPIRV::PointerTypeDescriptor(PointerElementType, AddressSpace), MF);
+    if (isUntypedPointerTy(PointeeTy))
+      PointeeTy =
+          TypedPointerType::get(IntegerType::getInt8Ty(PointeeTy->getContext()),
+                                getPointerAddressSpace(PointeeTy));
+    return ST.find(SPIRV::PointerTypeDescriptor(PointeeTy, AddressSpace), MF);
   }
 
   Register find(const Constant *C, const MachineFunction *MF) {



More information about the llvm-commits mailing list