llvm-project/clang/test/CodeGen/bpf-union-argument.c
Yonghong Song 481d67d310 [Clang][BPF] Support record argument with direct values
Currently, record arguments are always passed by reference by allocating
space for record values in the caller. This is less efficient for
small records which may take one or two registers. For example,
for x86_64 and aarch64, for a record size up to 16 bytes, the record
values can be passed by values directly on the registers.

This patch added BPF support of record argument with direct values
for up to 16 byte record size. If record size is 0, that record
will not take any register, which is the same behavior for x86_64
and aarch64. If the record size is greater than 16 bytes, the
record argument will be passed by reference.

Differential Revision: https://reviews.llvm.org/D132144
2022-08-18 19:11:50 -07:00

45 lines
903 B
C

// REQUIRES: bpf-registered-target
// RUN: %clang_cc1 -triple bpf -O2 -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
union t1 {};
union t2 {
int a;
long b;
};
union t3 {
struct {
int a;
long b;
};
long c;
};
union t4 {
struct {
long a;
long b;
long c;
};
long d;
};
int foo1(union t1 arg1, union t2 arg2) {
// CHECK: define dso_local i32 @foo1(i64 %arg2.coerce)
return arg2.a;
}
int foo2(union t3 arg1, union t4 arg2) {
// CHECK: define dso_local i32 @foo2([2 x i64] %arg1.coerce, ptr noundef byval(%union.t4) align 8 %arg2)
return arg1.a + arg2.a;
}
int foo3(void) {
union t1 tmp1 = {};
union t2 tmp2 = {};
union t3 tmp3 = {};
union t4 tmp4 = {};
return foo1(tmp1, tmp2) + foo2(tmp3, tmp4);
// CHECK: call i32 @foo1(i64 %{{[a-zA-Z0-9]+}})
// CHECK: call i32 @foo2([2 x i64] %{{[a-zA-Z0-9]+}}, ptr noundef byval(%union.t4) align 8 %tmp4)
}