[LLVMdev] Generating code for Sequence expression

Tim Northover t.p.northover at gmail.com
Wed Nov 14 14:00:22 PST 2012


Hi José,

>   ( e1; e2; ... ; en )
>
> To evaluate the sequence expression, each expression ei in the list is
> evaluated in the order they appear, and the last one en gives the final
> result.
>
> How can the sequence expression be translated to the llvm IR?

Your language probably only cares about the visible effects of the
evaluation order. For example, ordering of volatile loads/stores and
the sequence of function calls involved (and even that, only to a
certain extent).

If so, you just need to generate code for the expressions one after
the other and let LLVM take care of which optimisations it can perform
that preserve the semantics.

> After translating each expression ei from the sequence, how would the
> resulting values be combined to evaluate in sequence?

The "combination" would be not even bothering to record the value of
the first expressions (e1, ... e_{n-1}), but returning the value of
the last expression as the final result.

Tim.




More information about the llvm-dev mailing list