[clang] [CIR] Forward caller storage for byref call arguments (PR #216499)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 24 12:20:34 PDT 2026


================
@@ -410,44 +408,67 @@ void insertReturnCoercion(mlir::FunctionOpInterface funcOp,
   }
 }
 
+/// If \p recordVal is a plain load of an alloca, return that alloca and the
+/// load.  Return nulls otherwise: a volatile or atomic load has to keep its
+/// ordering, and a call result or a load of a member of a larger record has no
+/// alloca of its own.
+static std::pair<cir::AllocaOp, cir::LoadOp>
+getWholeRecordSource(mlir::Value recordVal) {
+  cir::LoadOp load = recordVal.getDefiningOp<cir::LoadOp>();
+  if (!load || load.getIsVolatile() || load.getMemOrder())
+    return {};
+  auto alloca = load.getAddr().getDefiningOp<cir::AllocaOp>();
----------------
andykaylor wrote:

This should probably be trying to look through address space casts. See getUnderlyingAllocaOp() in Address.h. We can't call that here, but we could add a similar helper function at the dialect level. This won't matter until we get into offload targets, so you can just add a TODO comment for now.

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


More information about the cfe-commits mailing list