[LLVMdev] Complex constant expressions?

Talin viridia at gmail.com
Tue Jan 22 21:24:01 PST 2008

Chris Lattner wrote:
> It's really up to you, and it may be up to your language spec.  One 
> approach would be to generate a series of llvm::ConstantExpr::get* method 
> calls, which implicitly constant fold expressions where possible.  For 
> example, if you ask for "add 3+7" you'll get 10.  If you ask for "div 15, 
> 0" you'll get an unfolded constant expr back.
Thanks, that is exactly what I needed.
> However, if you treat type checking separately from code generation, your 
> language may require that you diagnose these sorts of things, and that 
> would mean that you have to implement the constant folding logic in  your 
> frontend.  This is what clang does, for example.
Since my AST nodes wrap the LLVM Constant nodes, I have the choice of 
mapping from my language types to LLVM types or the reverse, when 
needed. So I can use whatever is appropriate at any given point.

More information about the llvm-dev mailing list