From ac66a11c196d19146f6d38846d8208c423005ef3 Mon Sep 17 00:00:00 2001 From: Jannik Silvanus Date: Thu, 7 Dec 2023 15:54:57 +0100 Subject: [PATCH 1/2] [Continuations] - Remove uses of isOpaqueOrPointeeTypeMatches This function was long deprecated and now has been removed upstream. These were only used in asserts, and these asserts are going to turn into no-ops with opaque pointers, so we can just remove them now without replacement. --- shared/continuations/lib/LowerRaytracingPipeline.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/shared/continuations/lib/LowerRaytracingPipeline.cpp b/shared/continuations/lib/LowerRaytracingPipeline.cpp index 137c6e4fbf..bc603f0dab 100644 --- a/shared/continuations/lib/LowerRaytracingPipeline.cpp +++ b/shared/continuations/lib/LowerRaytracingPipeline.cpp @@ -129,8 +129,6 @@ struct PayloadCopyHelper { // Pointer to the node field in the local payload auto *LocalFieldPtr = B.CreateInBoundsGEP(&PayloadTy, LocalPayload, PayloadIdxList); - assert(cast(LocalFieldPtr->getType()) - ->isOpaqueOrPointeeTypeMatches(FieldTy)); // If the field is serialized in multiple intervals in the global, // we perform a manual bytewise copy using i32 and i8. @@ -953,11 +951,6 @@ void LowerRaytracingPipelinePassImpl::copyPayload( Payload, Layout.SerializationTy->getPointerTo(Payload->getAddressSpace())); - assert(cast(PayloadSerialization->getType()) - ->isOpaqueOrPointeeTypeMatches(Layout.SerializationTy)); - assert(cast(LocalPayload->getType()) - ->isOpaqueOrPointeeTypeMatches(&PayloadTy)); - PayloadCopyHelper Helper{ *Mod, B, From 45a3cb4914254ae8a4bfdf8e1967dffcf0d50be1 Mon Sep 17 00:00:00 2001 From: Jannik Silvanus Date: Thu, 7 Dec 2023 15:56:50 +0100 Subject: [PATCH 2/2] [Continuations] - Add helper for getWithSamePointeeType PointerType::getWithSamePointeeType was removed in upstream LLVM, but we rely on it in typed pointer mode. Add a helper function that calls the LLVM function for old LLVM, and returns an untyped pointer for new LLVM. This helper can be removed once typed pointer support is no longer needed. --- .../include/continuations/ContinuationsUtil.h | 5 +++++ shared/continuations/lib/ContinuationsUtil.cpp | 11 +++++++++++ shared/continuations/lib/RegisterBuffer.cpp | 11 +++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/shared/continuations/include/continuations/ContinuationsUtil.h b/shared/continuations/include/continuations/ContinuationsUtil.h index 2dc5396423..35645848f8 100644 --- a/shared/continuations/include/continuations/ContinuationsUtil.h +++ b/shared/continuations/include/continuations/ContinuationsUtil.h @@ -637,6 +637,11 @@ findIntrImplEntryByIntrinsicCall(CallInst *Call); // during DXILContPostProcess, so we cannot remove all unused declarations right // at the end of LowerRaytracingPipeline. bool removeUnusedFunctionDecls(Module *Mod, bool OnlyIntrinsics = true); + +// Replacement for PointerType::getWithSamePointeeType that works with new LLVM. +// Returns a typed pointer type if the pointer type is typed. +PointerType *getWithSamePointeeType(PointerType *PtrTy, unsigned AddressSpace); + } // namespace llvm #endif diff --git a/shared/continuations/lib/ContinuationsUtil.cpp b/shared/continuations/lib/ContinuationsUtil.cpp index 419b710a53..bda3dc83ff 100644 --- a/shared/continuations/lib/ContinuationsUtil.cpp +++ b/shared/continuations/lib/ContinuationsUtil.cpp @@ -110,3 +110,14 @@ bool llvm::removeUnusedFunctionDecls(Module *Mod, bool OnlyIntrinsics) { return DidChange; } + +PointerType *llvm::getWithSamePointeeType(PointerType *PtrTy, + unsigned AddressSpace) { +#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 482880 + return PointerType::getWithSamePointeeType(PtrTy, AddressSpace); +#else + // New version of the code (also handles unknown version, which we treat as + // latest) + return PointerType::get(PtrTy->getContext(), AddressSpace); +#endif +} diff --git a/shared/continuations/lib/RegisterBuffer.cpp b/shared/continuations/lib/RegisterBuffer.cpp index 614bf405e0..960a05b1b2 100644 --- a/shared/continuations/lib/RegisterBuffer.cpp +++ b/shared/continuations/lib/RegisterBuffer.cpp @@ -194,16 +194,16 @@ Value *RegisterBufferPass::computeMemAddr(IRBuilder<> &Builder, Value *MemSrc = computeMemAddr(Builder, Src); New = Builder.CreateCast( Inst->getOpcode(), MemSrc, - PointerType::getWithSamePointeeType( - cast(Inst->getDestTy()), Data.Addrspace)); + getWithSamePointeeType(cast(Inst->getDestTy()), + Data.Addrspace)); } else if (auto *Inst = dyn_cast(Address)) { if (Inst->isCast()) { auto *Src = Inst->getOperand(0); Value *MemSrc = computeMemAddr(Builder, Src); New = Builder.CreateCast( static_cast(Inst->getOpcode()), MemSrc, - PointerType::getWithSamePointeeType( - cast(Inst->getType()), Data.Addrspace)); + getWithSamePointeeType(cast(Inst->getType()), + Data.Addrspace)); } else { LLVM_DEBUG(Address->dump()); llvm_unreachable( @@ -242,8 +242,7 @@ Value *RegisterBufferPass::handleSingleLoadStore( // Change load/store to use addrspace(20) auto *AddressType = cast(Address->getType()); Address = Builder.CreateAddrSpaceCast( - Address, PointerType::getWithSamePointeeType(AddressType, - GlobalRegisterAddrspace)); + Address, getWithSamePointeeType(AddressType, GlobalRegisterAddrspace)); // If only registers are accessed, emit a simple load/store if (TotalElementCount <= Data.RegisterCount)