[llvm] [DirectX] Implement `memcpy` in DXIL CBuffer Access pass (PR #144436)
Deric C. via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 19 16:59:11 PDT 2025
================
@@ -195,6 +195,82 @@ static void replaceLoad(LoadInst *LI, CBufferResource &CBR,
DeadInsts.push_back(LI);
}
+/// Replace memcpy from a cbuffer global with a memcpy from the cbuffer handle
+/// itself. Assumes the cbuffer global is an array, and the length of bytes to
+/// copy is divisible by array element allocation size.
+/// The memcpy source must also be a direct cbuffer global reference, not a GEP.
+static void replaceMemCpy(MemCpyInst *MCI, CBufferResource &CBR,
+ SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
+
+ ArrayType *ArrTy = dyn_cast<ArrayType>(CBR.getValueType());
+ assert(ArrTy && "MemCpy lowering is only supported for array types");
+
+ // This assumption vastly simplifies the implementation
+ if (MCI->getSource() != CBR.Member)
+ reportFatalUsageError(
+ "Expected MemCpy source to be a cbuffer global variable");
----------------
Icohedron wrote:
If `MCI->getSource()` is not the handle of a cbuffer global resource member then it must be a GEP because this function is only called on MCIs that are users of a cbuffer global resource member or users of a GEP that index into a cbuffer global resource member. (See the [`replaceAccessesWithHandle`](https://github.com/llvm/llvm-project/blob/f1988f43da9b901d40ce6cee8c34ae6bbd8b47af/llvm/lib/Target/DirectX/DXILCBufferAccess.cpp#L151-L175) function)
https://github.com/llvm/llvm-project/pull/144436
More information about the llvm-commits
mailing list