Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

VyacheslavLevytskyy
Copy link
Contributor

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.

@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2024

@llvm/pr-subscribers-backend-spir-v

Author: Vyacheslav Levytskyy (VyacheslavLevytskyy)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/94952.diff

1 Files Affected:

  • (modified) llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.h (+13-6)
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) {

@VyacheslavLevytskyy VyacheslavLevytskyy merged commit 6561460 into llvm:main Jun 11, 2024
10 checks passed
VyacheslavLevytskyy added a commit that referenced this pull request Jun 19, 2024
…95958)

This PR continues #94952,
managing FunctionType in the same way as a pointee types in
#94952 (that is working with
TypedPointers pointee types rather than with original llvm's untyped
pointers).

This PR also fully reworks the base type for the duplicates tracker's
storage to conform with and reuse DenseMapInfo. Previous implementation
didn't store enough info to differ between key values (see isEqual()
implemented as equality of derived from arguments hash values). This, in
turn, led to random crashes in very rare occasions when hash value of an
actual key matched hash values of empty and tombstone instances. In this
PR we use std::tuple instead of a tailor-made class hierarchy, both
reusing DenseMapInfo templates and getting rid of the crash condition.
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
…lvm#95958)

This PR continues llvm#94952,
managing FunctionType in the same way as a pointee types in
llvm#94952 (that is working with
TypedPointers pointee types rather than with original llvm's untyped
pointers).

This PR also fully reworks the base type for the duplicates tracker's
storage to conform with and reuse DenseMapInfo. Previous implementation
didn't store enough info to differ between key values (see isEqual()
implemented as equality of derived from arguments hash values). This, in
turn, led to random crashes in very rare occasions when hash value of an
actual key matched hash values of empty and tombstone instances. In this
PR we use std::tuple instead of a tailor-made class hierarchy, both
reusing DenseMapInfo templates and getting rid of the crash condition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants