Reputation: 5
I would like to do some analysis on each function in LLVM IR. However, when I generate LLVM IR code from my example c code, I found that in some case, the argument number of a function is different from my example c code. For example:
my example c code is as below:
struct outer_s{
int a;
int b;
int c;
};
void func_a(struct outer_s z){
// nothing
}
however, the generated LLVM IR code is as below:
%struct.outer_s = type { i32, i32, i32 }
; Function Attrs: noinline nounwind optnone uwtable
define dso_local void @func_a(i64, i32) #0 {
%3 = alloca %struct.outer_s, align 4
%4 = alloca { i64, i32 }, align 4
%5 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %4, i32 0, i32 0
store i64 %0, i64* %5, align 4
%6 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %4, i32 0, i32 1
store i32 %1, i32* %6, align 4
%7 = bitcast %struct.outer_s* %3 to i8*
%8 = bitcast { i64, i32 }* %4 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %7, i8* align 4 %8, i64 12, i1 false)
ret void
}
As we have seen above, the "struct outer_s z" argument is split in two parts. If I use API to get function arguments, the argument number that I get is also 2.
As my analysis is start from function arguments and wrong argument num will cause wrong result. So I’m wondering if there is any LLVM Pass or clang argument that I can use to avoid those "split" case?
Upvotes: 0
Views: 792
Reputation: 9324
Short answer: no, you need to deal with it.
Long answer: no, you need to deal with it. Even worse, the IR here is very target-dependent as the argument passing rules are defined by platform ABI. Here are many complications as that they are often declared in terms of a source language. So, we need to find a way to model these rules via LLVM IR which is usually much low level as compared to the original. Often this is quite a non-trivial process (e.g. for passing struct by value, vectors, homogeneous aggregates, etc.) and the process might be in some sense "destructive" to the original sources and the mapping is not one-to-one. You cannot "switch off" this process, as this is correctness thing.
Upvotes: 1