From a09d0289bcceb483dd239118cf3a257db372b47c Mon Sep 17 00:00:00 2001 From: Mats Jun Larsen Date: Tue, 28 Jan 2025 23:27:22 +0900 Subject: [PATCH 1/3] [IR][SPIR-V] Replace of PointerType::get(Type) with opaque version (NFC) Follow-up to https://github.com/llvm/llvm-project/issues/123569 I must've missed these when I was going through uses last week. --- llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 3 +-- llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp index b52c793e57e96..d24fa8aafae9a 100644 --- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp @@ -2181,9 +2181,8 @@ getOrCreateSPIRVDeviceEventPointer(MachineIRBuilder &MIRBuilder, OpaqueType = StructType::getTypeByName(Context, "opencl.clk_event_t"); if (!OpaqueType) OpaqueType = StructType::create(Context, "spirv.DeviceEvent"); - unsigned SC0 = storageClassToAddressSpace(SPIRV::StorageClass::Function); unsigned SC1 = storageClassToAddressSpace(SPIRV::StorageClass::Generic); - Type *PtrType = PointerType::get(PointerType::get(OpaqueType, SC0), SC1); + Type *PtrType = PointerType::get(Context, SC1); return GR->getOrCreateSPIRVType(PtrType, MIRBuilder); } diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp index 874894ae98726..57442e38c71a3 100644 --- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp @@ -629,7 +629,7 @@ SPIRVGlobalRegistry::getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, unsigned AddressSpace = typeToAddressSpace(LLVMTy); // Find a constant in DT or build a new one. Constant *CP = ConstantPointerNull::get( - PointerType::get(::getPointeeType(LLVMTy), AddressSpace)); + PointerType::get(::getPointeeType(LLVMTy)->getContext(), AddressSpace)); Register Res = DT.find(CP, CurMF); if (!Res.isValid()) { LLT LLTy = LLT::pointer(AddressSpace, PointerSize); From 0b2358e55c8de69c899856bc01b80d06688458c1 Mon Sep 17 00:00:00 2001 From: Mats Jun Larsen Date: Tue, 28 Jan 2025 23:32:57 +0900 Subject: [PATCH 2/3] Remove leftover unused variables --- llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp index d24fa8aafae9a..95fa7bc3894fd 100644 --- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp @@ -2176,11 +2176,6 @@ static SPIRVType * getOrCreateSPIRVDeviceEventPointer(MachineIRBuilder &MIRBuilder, SPIRVGlobalRegistry *GR) { LLVMContext &Context = MIRBuilder.getMF().getFunction().getContext(); - Type *OpaqueType = StructType::getTypeByName(Context, "spirv.DeviceEvent"); - if (!OpaqueType) - OpaqueType = StructType::getTypeByName(Context, "opencl.clk_event_t"); - if (!OpaqueType) - OpaqueType = StructType::create(Context, "spirv.DeviceEvent"); unsigned SC1 = storageClassToAddressSpace(SPIRV::StorageClass::Generic); Type *PtrType = PointerType::get(Context, SC1); return GR->getOrCreateSPIRVType(PtrType, MIRBuilder); From e0f92e6a28f94064db1a182abd46a1fd984a5803 Mon Sep 17 00:00:00 2001 From: Mats Jun Larsen Date: Tue, 28 Jan 2025 23:41:57 +0900 Subject: [PATCH 3/3] Don't go through getPointeeType --- llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp index 57442e38c71a3..e2f1b211caa5c 100644 --- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp @@ -629,7 +629,7 @@ SPIRVGlobalRegistry::getOrCreateConstNullPtr(MachineIRBuilder &MIRBuilder, unsigned AddressSpace = typeToAddressSpace(LLVMTy); // Find a constant in DT or build a new one. Constant *CP = ConstantPointerNull::get( - PointerType::get(::getPointeeType(LLVMTy)->getContext(), AddressSpace)); + PointerType::get(LLVMTy->getContext(), AddressSpace)); Register Res = DT.find(CP, CurMF); if (!Res.isValid()) { LLT LLTy = LLT::pointer(AddressSpace, PointerSize);