Skip to content

Commit 6561460

Browse files
[SPIR-V] Ensure that DuplicatesTracker is working with TypedPointers pointee types (llvm#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.
1 parent c6d85ba commit 6561460

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "MCTargetDesc/SPIRVBaseInfo.h"
1818
#include "MCTargetDesc/SPIRVMCTargetDesc.h"
19+
#include "SPIRVUtils.h"
1920
#include "llvm/ADT/DenseMap.h"
2021
#include "llvm/ADT/MapVector.h"
2122
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
@@ -285,10 +286,13 @@ class SPIRVGeneralDuplicatesTracker {
285286
TT.add(Ty, MF, R);
286287
}
287288

288-
void add(const Type *PointerElementType, unsigned AddressSpace,
289+
void add(const Type *PointeeTy, unsigned AddressSpace,
289290
const MachineFunction *MF, Register R) {
290-
ST.add(SPIRV::PointerTypeDescriptor(PointerElementType, AddressSpace), MF,
291-
R);
291+
if (isUntypedPointerTy(PointeeTy))
292+
PointeeTy =
293+
TypedPointerType::get(IntegerType::getInt8Ty(PointeeTy->getContext()),
294+
getPointerAddressSpace(PointeeTy));
295+
ST.add(SPIRV::PointerTypeDescriptor(PointeeTy, AddressSpace), MF, R);
292296
}
293297

294298
void add(const Constant *C, const MachineFunction *MF, Register R) {
@@ -320,10 +324,13 @@ class SPIRVGeneralDuplicatesTracker {
320324
return TT.find(const_cast<Type *>(Ty), MF);
321325
}
322326

323-
Register find(const Type *PointerElementType, unsigned AddressSpace,
327+
Register find(const Type *PointeeTy, unsigned AddressSpace,
324328
const MachineFunction *MF) {
325-
return ST.find(
326-
SPIRV::PointerTypeDescriptor(PointerElementType, AddressSpace), MF);
329+
if (isUntypedPointerTy(PointeeTy))
330+
PointeeTy =
331+
TypedPointerType::get(IntegerType::getInt8Ty(PointeeTy->getContext()),
332+
getPointerAddressSpace(PointeeTy));
333+
return ST.find(SPIRV::PointerTypeDescriptor(PointeeTy, AddressSpace), MF);
327334
}
328335

329336
Register find(const Constant *C, const MachineFunction *MF) {

0 commit comments

Comments
 (0)