Skip to content

Commit 4dbcde3

Browse files
committed
initial commit
1 parent a223ec2 commit 4dbcde3

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,13 @@ mlir::Value createCoercedValue(mlir::Value Src, mlir::Type Ty,
336336
return CGF.buildAggregateBitcast(Src, Ty);
337337
}
338338

339-
cir_cconv_unreachable("NYI");
339+
auto &bld = CGF.getRewriter();
340+
auto alloca = bld.create<AllocaOp>(
341+
Src.getLoc(), bld.getType<PointerType>(Ty), Ty,
342+
/*name=*/llvm::StringRef(""), /*alignment=*/bld.getI64IntegerAttr(4));
343+
Src = findAlloca(Src.getDefiningOp());
344+
createMemCpy(CGF, alloca, Src, SrcSize.getFixedValue());
345+
return bld.create<LoadOp>(Src.getLoc(), alloca.getResult());
340346
}
341347

342348
mlir::Value emitAddressAtOffset(LowerFunction &LF, mlir::Value addr,

clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,52 @@ S_PAD ret_s_pad() {
234234
S_PAD s;
235235
return s;
236236
}
237+
238+
typedef struct {
239+
int a;
240+
int b;
241+
short c;
242+
} GT_64_LT_128;
243+
244+
// CHECK: @pass_gt_64_lt_128(%arg0: !cir.array<!u64i x 2>
245+
// CHECK: %[[#V0:]] = cir.alloca !ty_GT_64_LT_128_, !cir.ptr<!ty_GT_64_LT_128_>, [""] {alignment = 4 : i64}
246+
// CHECK: %[[#V1:]] = cir.alloca !cir.array<!u64i x 2>, !cir.ptr<!cir.array<!u64i x 2>>, ["tmp"] {alignment = 8 : i64}
247+
// CHECK: cir.store %arg0, %[[#V1]] : !cir.array<!u64i x 2>, !cir.ptr<!cir.array<!u64i x 2>>
248+
// CHECK: %[[#V2:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr<!cir.array<!u64i x 2>>), !cir.ptr<!void>
249+
// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_GT_64_LT_128_>), !cir.ptr<!void>
250+
// CHECK: %[[#V4:]] = cir.const #cir.int<12> : !u64i
251+
// CHECK: cir.libc.memcpy %[[#V4]] bytes from %[[#V2]] to %[[#V3]] : !u64i, !cir.ptr<!void> -> !cir.ptr<!void>
252+
// CHECK: cir.return
253+
254+
// LLVM: @pass_gt_64_lt_128([2 x i64] %[[#V0:]])
255+
// LLVM: %[[#V2:]] = alloca %struct.GT_64_LT_128, i64 1, align 4
256+
// LLVM: %[[#V3:]] = alloca [2 x i64], i64 1, align 8
257+
// LLVM: store [2 x i64] %[[#V0]], ptr %[[#V3]], align 8
258+
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr %[[#V2]], ptr %[[#V3]], i64 12, i1 false)
259+
// LLVM: ret void
260+
void pass_gt_64_lt_128(GT_64_LT_128 s) {}
261+
262+
// CHECK: @call_gt_64_lt_128()
263+
// CHECK: %[[#V0:]] = cir.alloca !ty_GT_64_LT_128_, !cir.ptr<!ty_GT_64_LT_128_>, ["s"] {alignment = 4 : i64}
264+
// CHECK: %[[#V1:]] = cir.load %[[#V0]] : !cir.ptr<!ty_GT_64_LT_128_>, !ty_GT_64_LT_128_
265+
// CHECK: %[[#V2:]] = cir.alloca !cir.array<!u64i x 2>, !cir.ptr<!cir.array<!u64i x 2>>, [""] {alignment = 4 : i64}
266+
// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_GT_64_LT_128_>), !cir.ptr<!void>
267+
// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V2]] : !cir.ptr<!cir.array<!u64i x 2>>), !cir.ptr<!void>
268+
// CHECK: %[[#V5:]] = cir.const #cir.int<12> : !u64i
269+
// CHECK: cir.libc.memcpy %[[#V5]] bytes from %[[#V3]] to %[[#V4]] : !u64i, !cir.ptr<!void> -> !cir.ptr<!void>
270+
// CHECK: %[[#V6:]] = cir.load %[[#V2]] : !cir.ptr<!cir.array<!u64i x 2>>, !cir.array<!u64i x 2>
271+
// CHECK: cir.call @pass_gt_64_lt_128(%[[#V6]]) : (!cir.array<!u64i x 2>) -> ()
272+
// CHECK: cir.return
273+
274+
// LLVM: @call_gt_64_lt_128()
275+
// LLVM: %[[#V1:]] = alloca %struct.GT_64_LT_128, i64 1, align 4
276+
// LLVM: %[[#V2:]] = load %struct.GT_64_LT_128, ptr %[[#V1]], align 4
277+
// LLVM: %[[#V3:]] = alloca [2 x i64], i64 1, align 4
278+
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr %[[#V3]], ptr %[[#V1]], i64 12, i1 false)
279+
// LLVM: %[[#V4:]] = load [2 x i64], ptr %[[#V3]], align 8
280+
// LLVM: call void @pass_gt_64_lt_128([2 x i64] %[[#V4]])
281+
// LLVM: ret void
282+
void call_gt_64_lt_128() {
283+
GT_64_LT_128 s;
284+
pass_gt_64_lt_128(s);
285+
}

0 commit comments

Comments
 (0)