The above C code is converted to the following IR code. The string
literal "Hello World!" is defined as an unnamed global constant.
Does the IR language support the declaration of local values to store
the string literal? I don't this is supported as I am reading the
manual. But I would like to double check. Thanks.
If you want a pointer to a value, it has to be located somewhere in memory. There are basically three places memory can be allocated in a program: on the stack (alloca), on the heap (malloc), or in program memory (a global variable/constant).
If you want a pointer to a value, it has to be located somewhere in
memory. There are basically three places memory can be allocated in a
program: on the stack (alloca),
Even I can alloca a chuck of memory, there is not a way to put the
string constant to it? Sounds likely there is not way to avoid the
initialization of the global variables. Is it?
Globals, especially ones as simple as strings, tend to be
"initialized" just by being mapped into memory by the kernel from the
executable file. It's the best possible initialization (no
computation, no explicit instructions, it's all just an mmap); all the
global variable is doing is giving you a handle to this string that
you've requested should be available.