[LLVMdev] constant expression as initial value to global

edA-qa mort-ora-y eda-qa at disemia.com
Sat Nov 17 09:10:12 PST 2012


How can I go about evaluating constant expressions and providing them as
the initial value to globals?  I allow my globals to be initialized by
an expression. In C syntax this looks like:
	int const global_val = const_expr( 1, 2, 3 );

I use the "const_expr" to indicate construction-time constant folding
will not be possible. The IR optimizers however will likely reduce this
to a single value.

My first approach is to simply call a startup function which assigns the
values (which is also kind of necessary if I don't use the optimization
passes). Beyond this I see that I could somehow JIT the const_expr
results and then stick in the resulting value as the initial value.

Is there an easier way to go about doing this type of initialization? Or
could somebody explain how the C++11 constexpr support works (since it'd
be about the same I think).


-- 
edA-qa mort-ora-y
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Sign: Please digitally sign your emails.
Encrypt: I'm also happy to receive encrypted mail.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121117/04442db5/attachment.sig>


More information about the llvm-dev mailing list