Converting a Constant GEP to a POD integer?

Working on my garbage collector…I need to be able to convert a ConstantExpr to a plain int at link time.

At compile time, I use ContactExpr::getOffsetOf() to calculate the offsets for pointer fields to be traced by the collector. Since the target machine has not yet been selected at this point, we don’t yet know what the exact offset will be, so the expression cannot be flattened into a simple integer. That’s OK, however, because most of the time we’re assembling constant static data structures, so having a Constant is OK.

The problem arises, however, when that offset expression is used as part of the metadata argument to llvm.gcroot(). Because of the way that the GC lowering pass works, the output of the GC strategy has to be emitted via an asm printer, which as far as I can tell, doesn’t accept llvm::Constant as an argument. (Even if it did, it would be no good, since I need to sort the field offsets in ascending order, and you can’t sort an array of Constant*).

This is all happening at link time, which means that the target machine is fully known by this point. So it ought to be possible to convert the field offset expression (including the constant GEP) into a plain integer. Any idea how to do this?

Hi Talin,

This is all happening at link time, which means that the target machine is fully
known by this point. So it ought to be possible to convert the field offset
expression (including the constant GEP) into a plain integer. Any idea how to do
this?

probably you can just run the constant folder on it (passing the target data to
the constant folder).

Ciao,

Duncan.

Hi Talin,

This is all happening at link time, which means that the target machine is fully
known by this point. So it ought to be possible to convert the field offset
expression (including the constant GEP) into a plain integer. Any idea how to do
this?

probably you can just run the constant folder on it (passing the target data to
the constant folder).

Ah, that worked. Thanks!