Bueno, Denis
2010-Apr-09 21:11 UTC
[LLVMdev] Unknown or runtime type in function definition?
Hello all, I'm trying to understand a bit of LLVM IR syntax. I have a function definition which looks like this in IR: define void @foo(%1* ptr) { ... The C code for foo has a definition that looks like: typedef struct bar_struct bar; ... Definition of struct bar_struct ... void foo(bar *ptr) { ... I can't whittle down a convenient test source file just now; but I'm trying to understand what the syntax of the 'define' above means -- specifically, what does it mean for a parameter to have type '%1*'? What is the semantics here? Inside the body of @foo, there is an SSA variable %1 -- is that variable related to the %1 in the type of the parameter? (It doesn't seem to be, which is why I ask.) I looked in the LLVM Language Reference manual but couldn't find any type syntax that corresponded to the type I see for foo's parameter. I'm not sure where else to look, but I'd be happy to hear any pointers. Any help is appreciated. Thanks in advance. -Denis
Eli Friedman
2010-Apr-09 22:11 UTC
[LLVMdev] Unknown or runtime type in function definition?
On Fri, Apr 9, 2010 at 2:11 PM, Bueno, Denis <denbuen at sandia.gov> wrote:> Hello all, > > I'm trying to understand a bit of LLVM IR syntax. I have a function > definition which looks like this in IR: > > define void @foo(%1* ptr) { ... > > The C code for foo has a definition that looks like: > > typedef struct bar_struct bar; > ... Definition of struct bar_struct ... > void foo(bar *ptr) { ... > > I can't whittle down a convenient test source file just now; but I'm trying > to understand what the syntax of the 'define' above means -- specifically, > what does it mean for a parameter to have type '%1*'? What is the semantics > here? Inside the body of @foo, there is an SSA variable %1 -- is that > variable related to the %1 in the type of the parameter? (It doesn't seem > to be, which is why I ask.)In that context, %1 refers to an unnamed struct; whether %1 refers to a type or a value is determined by the context. Short example which should help: %0 = type { i32, float, float, double } define i32 @a(%0*) { entry: getelementptr %0* %0, i32 0, i32 0 load i32* %1 ret i32 %2 } -Eli
Bueno, Denis
2010-Apr-09 22:22 UTC
[LLVMdev] Unknown or runtime type in function definition?
On 4/9/10 4:11 PM, "Eli Friedman" <eli.friedman at gmail.com> wrote:> In that context, %1 refers to an unnamed struct; whether %1 refers to > a type or a value is determined by the context. Short example which > should help: > > %0 = type { i32, float, float, double } > define i32 @a(%0*) { > entry: > getelementptr %0* %0, i32 0, i32 0 > load i32* %1 > ret i32 %2 > }Okay. Looking back over the IR, I see a type %1 defined at the top of the module. Thanks! -Denis
Daniel Dunbar
2010-Apr-10 01:24 UTC
[LLVMdev] Unknown or runtime type in function definition?
On Fri, Apr 9, 2010 at 3:11 PM, Eli Friedman <eli.friedman at gmail.com> wrote:> On Fri, Apr 9, 2010 at 2:11 PM, Bueno, Denis <denbuen at sandia.gov> wrote: >> Hello all, >> >> I'm trying to understand a bit of LLVM IR syntax. I have a function >> definition which looks like this in IR: >> >> define void @foo(%1* ptr) { ... >> >> The C code for foo has a definition that looks like: >> >> typedef struct bar_struct bar; >> ... Definition of struct bar_struct ... >> void foo(bar *ptr) { ... >> >> I can't whittle down a convenient test source file just now; but I'm trying >> to understand what the syntax of the 'define' above means -- specifically, >> what does it mean for a parameter to have type '%1*'? What is the semantics >> here? Inside the body of @foo, there is an SSA variable %1 -- is that >> variable related to the %1 in the type of the parameter? (It doesn't seem >> to be, which is why I ask.) > > In that context, %1 refers to an unnamed struct; whether %1 refers to > a type or a value is determined by the context. Short example which > should help:FWIW, I personally regard this as a bug not a feature. It doesn't make the IR any easier to read. - Daniel> > %0 = type { i32, float, float, double } > define i32 @a(%0*) { > entry: > getelementptr %0* %0, i32 0, i32 0 > load i32* %1 > ret i32 %2 > } > > -Eli > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >