llvm / clangir

A new (MLIR based) high-level IR for clang.
https://clangir.org
Other
382 stars 100 forks source link

[ABI][CallingConvention] Functional call with `byval` #798

Open SchrodingerZhu opened 2 months ago

SchrodingerZhu commented 2 months ago

For the following code, clangir seems to generate code that departures from existing CodeGen:

struct T {
    struct {
        long a[16];
        long b;
    };
    int c;
};
void opaque(T*);

void foo(T t) {
    opaque(&t);
}

Expected:

%struct.T = type { %struct.anon, i32 }
%struct.anon = type { [20 x i64], i64 }

define dso_local void @foo(T)(ptr noundef byval(%struct.T) align 8 %t) {
entry:
  call void @opaque(T*)(ptr noundef %t)
  ret void
}

declare void @opaque(T*)(ptr noundef) #1

Actual

%struct.T = type { %struct.anon.1, i32 }
%struct.anon.1 = type { [20 x i64], i64 }

declare void @_Z6opaqueP1T(ptr)

define void @_Z3foo1T(%struct.T %0) {
  %2 = alloca %struct.T, i64 1, align 8
  store %struct.T %0, ptr %2, align 8
  call void @_Z6opaqueP1T(ptr %2)
  ret void
}
bcardosolopes commented 2 months ago

We need to honour byval!

bcardosolopes commented 1 month ago

@sitio-couto recent work on target lowering is the right place to implement this