on type annotations of LLVM IR

Hi,

I am curious to know the design decision on why operands of LLVM IR instructions are type annotated.

Why wasn’t the C style of explicit declaration of variables (or values in LLVM context) followed by their uses model not adopted here?

or may be even annotate the value (result of the Instruction) with type rather than annotating each operands on the Instruction?

Just felt that by annotating each operand with types may make the Instruction ‘complex’ to understand. May be I am wrong.

Thanks for any explanation,

Why wasn't the C style of explicit declaration of variables (or values in LLVM context) followed by their uses model not adopted here?

For the simple reason that there are no variables in LLVM IR. The SSA form means that every value is declared and initialised exactly once. Some values, such as constant integers, are created (in the text serialisation) inline in their use so there is no point where they are declared.

or may be even annotate the value (result of the Instruction) with type rather than annotating each operands on the Instruction?

Just felt that by annotating each operand with types may make the Instruction 'complex' to understand. May be I am wrong.

You will find it much easier to read when you are debugging. The IR is not intended to be read or written by humans, the text serialisation is there as a debugging aid when something has gone wrong. It is *very* useful to be able to look at a single instruction and see all of the types, without having to chase through a load of other parts of the code to find where things were declared.

David

Hi,

Thank you David.

My question was from a machine independent code analyzer/optimizer perspective where types are of less importance. Hence I felt difficult to understand the IR with the types.

Rekha

I'm not sure why you think that types are of less importance there - that's where they're most used. When you get to the back end, a lot of the type information is throw away, as back ends have a far more restricted set of legal types.

David

Hi,

Currently i am doing an analysis which uses type info in conversion instructions only. Hence the question.

Rekha