[LLVMdev] Struct parameters being converted to other types

Jaymie Strecker jstrecker at kosada.com
Mon Jan 14 17:50:04 PST 2013


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





More information about the llvm-dev mailing list