Skip to content

Commit

Permalink
[Continuations] - Add helper for getWithSamePointeeType
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasilvanus committed Dec 8, 2023
1 parent 285131f commit fd11332
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions shared/continuations/lib/ContinuationsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 5 additions & 6 deletions shared/continuations/lib/RegisterBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ Value *RegisterBufferPass::computeMemAddr(IRBuilder<> &Builder,
Value *MemSrc = computeMemAddr(Builder, Src);
New = Builder.CreateCast(
Inst->getOpcode(), MemSrc,
PointerType::getWithSamePointeeType(
cast<PointerType>(Inst->getDestTy()), Data.Addrspace));
getWithSamePointeeType(cast<PointerType>(Inst->getDestTy()),
Data.Addrspace));
} else if (auto *Inst = dyn_cast<ConstantExpr>(Address)) {
if (Inst->isCast()) {
auto *Src = Inst->getOperand(0);
Value *MemSrc = computeMemAddr(Builder, Src);
New = Builder.CreateCast(
static_cast<Instruction::CastOps>(Inst->getOpcode()), MemSrc,
PointerType::getWithSamePointeeType(
cast<PointerType>(Inst->getType()), Data.Addrspace));
getWithSamePointeeType(cast<PointerType>(Inst->getType()),
Data.Addrspace));
} else {
LLVM_DEBUG(Address->dump());
llvm_unreachable(
Expand Down Expand Up @@ -242,8 +242,7 @@ Value *RegisterBufferPass::handleSingleLoadStore(
// Change load/store to use addrspace(20)
auto *AddressType = cast<PointerType>(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)
Expand Down

0 comments on commit fd11332

Please sign in to comment.