[llvm] [DirectX] Teach MemIntrinsics about structs and nested arrays (PR #173078)

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 22 10:53:52 PST 2025


================
@@ -109,6 +109,24 @@ static Type *getPointeeType(Value *Ptr, const DataLayout &DL) {
   llvm_unreachable("Could not calculate pointee type");
 }
 
+static size_t flattenTypes(Type *ContainerTy, const DataLayout &DL,
+                           SmallVectorImpl<std::pair<Type *, size_t>> &FlatTys,
+                           size_t NextOffset = 0) {
+  if (auto *AT = dyn_cast<ArrayType>(ContainerTy)) {
+    for (uint64_t I = 0, E = AT->getNumElements(); I != E; ++I)
+      NextOffset = flattenTypes(AT->getElementType(), DL, FlatTys, NextOffset);
+    return NextOffset;
----------------
bogner wrote:

When we iterate over the elements (of the array here and of the struct in the other recursive case below), we're passing the new value of NextOffset along each time (note the `NextOffset = f(..., NextOffset)` pattern). This tracks where we are in the overall flattened layout of the type.

Is there a way to write this that would be clearer?

https://github.com/llvm/llvm-project/pull/173078


More information about the llvm-commits mailing list