Dmitry N. Mikushin
2011-Nov-21 00:58 UTC
[LLVMdev] A way to pass const char* arg without creating a GlobalVariable
Hi, Is it possible to make up a ConstantArray containing a "const char*" string and pass it directly to the function "char*" argument *without* creating a GlobalVaribable? I looked around and found the usual implementation is array->globalVar->gep. If we omit globalVar & gep, then the argument type would be [ i8 x N ], where N is set to the exact string length, and the expected type is i8* => assertion. In other words, in C we can submit constant value directly to parameter list, e.g. foo("hello"). Is there an equivalent capability in LLVM IR? Our primary targets have limited support for global variables, and it is better to omit them, where possible. Thanks, - Dima.
Gordon Henriksen
2011-Nov-21 01:11 UTC
[LLVMdev] A way to pass const char* arg without creating a GlobalVariable
What memory would the pointer argument point to? ― Gordon On Nov 20, 2011, at 16:58, "Dmitry N. Mikushin" <maemarcus at gmail.com> wrote:> Hi, > > Is it possible to make up a ConstantArray containing a "const char*" > string and pass it directly to the function "char*" argument *without* > creating a GlobalVaribable? > I looked around and found the usual implementation is > array->globalVar->gep. If we omit globalVar & gep, then the argument > type would be [ i8 x N ], where N is set to the exact string length, > and the expected type is i8* => assertion. > In other words, in C we can submit constant value directly to > parameter list, e.g. foo("hello"). Is there an equivalent capability > in LLVM IR? > Our primary targets have limited support for global variables, and it > is better to omit them, where possible. > > Thanks, > - Dima.
Dmitry N. Mikushin
2011-Nov-21 02:37 UTC
[LLVMdev] A way to pass const char* arg without creating a GlobalVariable
Hi Gordon, Yes, logically this is impossible. I'd reformulate the question in the following way: how could we change the argument type to be able to pass arrays of the various lengths without global variables? There is a variable length array type - maybe it can help somehow? Or could we create and initialize an AllocInst instead? So, any replacement for global vars would perfectly suite for our case. - D. ----- Original message -----> What memory would the pointer argument point to? > > ― Gordon > > On Nov 20, 2011, at 16:58, "Dmitry N. Mikushin" <maemarcus at gmail.com> > wrote: > > > Hi, > > > > Is it possible to make up a ConstantArray containing a "const char*" > > string and pass it directly to the function "char*" argument *without* > > creating a GlobalVaribable? > > I looked around and found the usual implementation is > > array->globalVar->gep. If we omit globalVar & gep, then the argument > > type would be [ i8 x N ], where N is set to the exact string length, > > and the expected type is i8* => assertion. > > In other words, in C we can submit constant value directly to > > parameter list, e.g. foo("hello"). Is there an equivalent capability > > in LLVM IR? > > Our primary targets have limited support for global variables, and it > > is better to omit them, where possible. > > > > Thanks, > > - Dima.-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111121/6102dcaa/attachment.html>
Maybe Matching Threads
- [LLVMdev] A way to pass const char* arg without creating a GlobalVariable
- [LLVMdev] Use still stuck around after Def is destroyed:
- [LLVMdev] LICM promoting memory to scalar
- [LLVMdev] Use still stuck around after Def is destroyed:
- [LLVMdev] LICM promoting memory to scalar