Skip to content

Commit

Permalink
[CIR][ABI][AArch64][Lowering] Support structures with padding (llvm#1118
Browse files Browse the repository at this point in the history
)

The title describes the purpose of the PR. It adds initial support for
structures with padding to the call convention lowering for AArch64.

I have also _initial support_ for the missing feature
[FinishLayout](https://github.com/llvm/clangir/blob/5c5d58402bebdb1e851fb055f746662d4e7eb586/clang/lib/AST/RecordLayoutBuilder.cpp#L786)
for records, and the logic is gotten from the original codegen.

Finally, I added a test for verification.
  • Loading branch information
bruteforceboy committed Nov 25, 2024
1 parent 5d47b2a commit b270c72
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,32 @@ void callS() {
S s;
passS(s);
}

typedef struct {
uint8_t a;
uint16_t b;
uint8_t c;
} S_PAD;

// CHECK: cir.func {{.*@ret_s_pad}}() -> !u48i
// CHECK: %[[#V0:]] = cir.alloca !ty_S_PAD, !cir.ptr<!ty_S_PAD>, ["__retval"] {alignment = 2 : i64}
// CHECK: %[[#V1:]] = cir.load %[[#V0]] : !cir.ptr<!ty_S_PAD>, !ty_S_PAD
// CHECK: %[[#V2:]] = cir.alloca !u48i, !cir.ptr<!u48i>, [""] {alignment = 2 : i64}
// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr<!ty_S_PAD>)
// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V2:]] : !cir.ptr<!u48i>), !cir.ptr<!void>
// CHECK: %[[#V5:]] = cir.const #cir.int<6> : !u64i
// CHECK: cir.libc.memcpy %[[#V5]] bytes from %[[#V3]] to %[[#V4]] : !u64i, !cir.ptr<!void>
// CHECK: %[[#V6:]] = cir.load %[[#V2]] : !cir.ptr<!u48i>
// CHECK: cir.return %[[#V6]]

// LLVM: i48 @ret_s_pad()
// LLVM: %[[#V1:]] = alloca %struct.S_PAD, i64 1, align 2
// LLVM: %[[#V2:]] = load %struct.S_PAD, ptr %[[#V1]], align 2
// LLVM: %[[#V3:]] = alloca i48, i64 1, align 2
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr %[[#V3]], ptr %[[#V1]], i64 6, i1 false)
// LLVM: %[[#V4:]] = load i48, ptr %[[#V3]]
// LLVM: ret i48 %[[#V4]]
S_PAD ret_s_pad() {
S_PAD s;
return s;
}

0 comments on commit b270c72

Please sign in to comment.