[LLVMdev] Fibonacci example in OCaml
jon at ffconsultancy.com
Tue Nov 27 00:32:11 PST 2007
On Tuesday 27 November 2007 04:02, Gordon Henriksen wrote:
> On 2007-11-26, at 21:12, Jon Harrop wrote:
> > Use phantom types to track the type of each llvalue:
> > type 'a llvalue
> This does not cover the full generality of the IR.
> The first argument
> to a call instruction need not be a Function. Rather, the type of the
> value must be pointer to function.
> Still, those phantom types may be a solution for binding the Value
> hierarchy without introducing gratuitous static casts. (The argument
> to set_visibility must be a GlobalValue, for instance.) Can you
> represent multiple-level inheritance? Value -> GlobalValue ->
> GlobalVariable, say.
You may be able to by enumerating the members of GlobalValue in
a "global_value" type:
type global_value = [ `GlobalVariable | `GlobalConstant | ... ]
and then saying that "set_visibility" accepts some subset of those
val set_visibility : [< global_value ] -> ...
I haven't checked that this works though.
> > I would use polymorphic variants more, particularly for enums and
> > types that are only used once (e.g. "linkage" and "visibility"). So
> > types would be `i32 rather than i32_type
> Types are not enums, they're first-class objects.
> > and int_predicate and real_predicate would become overlapping sum
> > types, e.g. `ugt is valid for both.
> These variant types were set up to have a 1:1 correspondence with the C
> ++ enums, and I'd prefer to keep that. There's also no overlap for
> integer and FP predicates (unsigned greater than is not unordered
> greater than).
That's fine then.
> > Perhaps such optimizations would be better done at a higher-level,
> > above the level of the GC? So that would be ideal for a higher-level
> > VM on top of LLVM.
> Escape analysis is perfectly practical on the LLVM representation.
> Reorganizing data structures is probably best done by the language
> front end. A functional language is the ideal host for such
> experiments. The closest LLVM does is SROA.
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
More information about the llvm-dev