[LLVMdev] An array of instructions?
Jakob Stoklund Olesen
stoklund at 2pi.dk
Tue Jul 14 05:46:06 PDT 2009
On 14/07/2009, at 14.04, Harel Cain wrote:
> Another question today: an array of string literals in my C program
> was transformed to independent global variables, each holding one
> string, and another array of getelementptr's to them, here it is:
>
> @words= global [5 x i8*] [ i8* getelementptr ([10 x i8]* @.str11, i32
> 0, i32 0), i8* getelementptr ([6 x i8]* @.str12, i32 0, i32 0), i8*
> getelementptr ([7 x i8]* @.str13, i32 0, i32 0), i8* getelementptr ([6
> x i8]* @.str14, i32 0, i32 0), i8* getelementptr ([11 x i8]* @.str15,
> i32 0, i32 0) ] ; <[5 x i8*]*> [#uses=1]
>
> Does this make sense?
Yes, consider the difference between
const char *const words[2] = { "foo", "bar" };
and
const char words[2][4] = { "foo", "bar" };
The first one is an array of pointers, the second is a two-dimensional
array. Your code is a correct translation of the first one.
> Are the elements of this array indeed regular
> GetElementPtrInst's, which is a kind of Instruction? How can an
> instruction live outside of a BasicBlock and a Function?
I am not an LLVM language lawyer, but these GEPs are constant
expressions which is allowed, see http://llvm.org/docs/LangRef.html#constantexprs
Regards,
/jakob
More information about the llvm-dev
mailing list