type information about instruction


I would like to keep info about size and type info of all instructions ( and Values at the same time). I can do this by extracting type of the Values, but if I have still some unused instructions , I can’t keep track on them. I try to convert them to Value and get the type or simply get the type of instruction, but have the following error:

Assertion `Ty->isSized() && “Cannot getTypeInfo() on a type that is unsized!”’ failed.

This is second or instruction:
%1 = or i32 10, 20
%2 = or i32 %1, 10
ret i32 %1

What can be done in this case?

You've got two issues you need to take account of here.

First is that the Type of an instruction is the type of the Value it
produces, which isn't necessarily what you want. Some instructions
("ret" in your case, but also other branches, and "store") produce no
actual value that can be used later so their type is "void" which has
no size. What you probably want is the type of one of the operands
(RetI->getOperand(0)->getType() for example would be "i32" in your

The other thing you're likely to hit is that aggregate types can have
sizes that depend on the DataLayout. For example {i32, i64} might have
size 96 or 128 depending on the ABI. So you should be using
DataLayout::getTypeSizeInBits if you need to cover these cases instead
of Type's own accessor.



Thank you for the answer. So, as I understood, to get the type of the “or” instruction (which I cannot access further as Value , because it is actually a dead instruction), I should get the type of one of its’ operands, yes? because the example with ret is quite understandable, but it seems really strange that such instructions as add, and , which define the actual values can have their Types be accessed only from the operands.

The Type of the "or" instruction should be fine without messing around
with operands, whether it's dead or not.

First, make sure you're looking at the Instruction you think you are
(sounds obvious, but I'm frequently not) by calling dump: "I->dump()"
either in the actual C++ or in a debugger. You can also dump the Type
itself to make sure it's i32. The more sanity checks the better!

Other than that, what function are you using to get the size?



You are totally right:) Silly faults with confusing the instructions. Thank you again!