Hello, I am writing a pass which must insert calls to an external library. One of the parameters to functions in this library is a very large, complex structure (let's call it Foo). Foo has many fields, strange target-dependent alignment requirements, and is likely to change many times in the future. The internal representation of Foo is important to this library, but the code my pass generates will only deal with Foo-pointers. For these reasons, I do not want my pass to emit a definition for struct Foo. However, to add an external reference to the library functions, I must supply function signatures that include this structure type. Casting to/from void pointers works, but ultimately generates suboptimal code. Is there any way to refer to this structure by name, instead of specifying its contents? Is this a place where I should use OpaqueType? Could anyone provide examples please? Thank you, -- Nick Johnson
On 2009-04-29, at 10:53, Nick Johnson wrote:> I am writing a pass which must insert calls to an external library. > One of the parameters to functions in this library is a very large, > complex structure (let's call it Foo). [...] The internal > representation of Foo is important to this library, but the code my > pass generates will only deal with Foo-pointers. > > For these reasons, I do not want my pass to emit a definition for > struct Foo. However, to add an external reference to the library > functions, I must supply function signatures that include this > structure type. Casting to/from void pointers works, but ultimately > generates suboptimal code.When your pass inserts calls, try declaring the function declarations to take i8* or %Foo* (where type %Foo = opaque). LLVM will unify the declaration's type when linking with the module that defines the symbol. — Gordon
Thanks, that works. And, I might as well provide a code snippet for google to find: module->addTypeName("foo", OpaqueType::get() ); const Type *struct_foo = module->getTypeByName("foo"); It's really that easy. Nick On Wed, Apr 29, 2009 at 11:17 AM, Gordon Henriksen <gordonhenriksen at me.com> wrote:> On 2009-04-29, at 10:53, Nick Johnson wrote: > >> I am writing a pass which must insert calls to an external library. >> One of the parameters to functions in this library is a very large, >> complex structure (let's call it Foo). [...] The internal >> representation of Foo is important to this library, but the code my >> pass generates will only deal with Foo-pointers. >> >> For these reasons, I do not want my pass to emit a definition for >> struct Foo. However, to add an external reference to the library >> functions, I must supply function signatures that include this >> structure type. Casting to/from void pointers works, but ultimately >> generates suboptimal code. > > When your pass inserts calls, try declaring the function declarations > to take i8* or %Foo* (where type %Foo = opaque). LLVM will unify the > declaration's type when linking with the module that defines the symbol. > > — Gordon > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Nick Johnson