[llvm-branch-commits] [clang] [CIR] Implement Direct+canFlatten in CallConvLowering (PR #201719)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jun 12 09:05:26 PDT 2026
================
@@ -419,6 +458,63 @@ void insertArgCoercion(FunctionOpInterface funcOp,
BlockArgument blockArg = entry.getArgument(blockArgIdx);
+ if (auto flatTy = getFlattenedCoercedType(ac)) {
+ // Direct + canFlatten: the coerced type is a struct whose fields become
+ // individual wire arguments. The reconstruction mirrors the Expand path
+ // — replace the single block arg with N scalar block args, store them
+ // into an alloca of the coerced struct type, reload — but then applies
+ // an additional coercion from the coerced struct type to the original
+ // argument type if the two differ in layout.
+ unsigned numFields = flatTy.getNumElements();
+ assert(numFields >= 2 && "getFlattenedCoercedType guarantees >1 fields");
+ Type origTy = blockArg.getType();
+ Location loc = funcOp.getLoc();
+
+ // Change slot 0 to field 0's type; insert slots 1..N-1 after it.
+ blockArg.setType(flatTy.getElementType(0));
+ for (unsigned f = 1; f < numFields; ++f)
+ entry.insertArgument(blockArgIdx + f, flatTy.getElementType(f), loc);
+
+ // setInsertionPointToStart: see comment in the Expand arm above.
+ rewriter.setInsertionPointToStart(&entry);
+ auto flatPtrTy = cir::PointerType::get(flatTy);
+ uint64_t flatAlign = dl.getTypeABIAlignment(flatTy);
+ auto flatSlot = cir::AllocaOp::create(
+ rewriter, loc, flatPtrTy, flatTy, rewriter.getStringAttr("coerce"),
+ rewriter.getI64IntegerAttr(flatAlign));
+ SmallPtrSet<Operation *, 8> flattenOps = {flatSlot};
+ for (unsigned f = 0; f < numFields; ++f) {
----------------
adams381 wrote:
Switched to `llvm::enumerate(flatTy.getMembers())`.
https://github.com/llvm/llvm-project/pull/201719
More information about the llvm-branch-commits
mailing list