Jaymie Strecker
2013-Jan-15 01:50 UTC
[LLVMdev] Struct parameters being converted to other types
In a project I'm working on, functions are being read in from LLVM bitcode, and then LLVM is being used to generate code that calls those functions. This is easy for ints, floats, and pointers. But not for structs. When a function with a struct parameter or return type is compiled with `clang -O0 -emit-llvm`, the resulting bitcode varies greatly depending on the type of struct. For example, LLVM may turn a struct parameter into... - a "byval" pointer (for a struct with several different members) - a vector (for a struct with a few float members) - two doubles (for a struct with two double members) - an i64 (for a struct with two i32 members) ... and possibly more variations. When calling a function that takes a struct argument, I'm having to convert the argument value (the original struct type) to match the parameter type (which could be any of the above variations). Is there a unified way to work with all these variations? Or is there a way to avoid generating them in the first place? --- Jaymie Strecker jstrecker at kosada.com
Anton Korobeynikov
2013-Jan-15 06:41 UTC
[LLVMdev] Struct parameters being converted to other types
> When a function with a struct parameter or return type is compiled with `clang -O0 -emit-llvm`, the resulting bitcode varies greatly depending on the type of struct.This mostly the question for cfe-dev, not llvm-dev, since you're talking about clang, not LLVM itself. However, the answer is easy. The struct is lowered to something which corresponds to C/C++ ABI on your platform for passing the struct in proper way. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University