[LLVMdev] Advice on CFG pre-analysis

Joachim Durchholz jo at durchholz.org
Sat May 24 11:23:22 PDT 2008


Am Samstag, den 24.05.2008, 13:18 -0400 schrieb Gordon Henriksen:
> A way to leverage the type system here might be with 'match'
> statement  
> like ml's. Consider:
> 
> type maybe 'a = None | Some 'a
> 
> let maybe_add x y =
>    match x, y with
>    | Some x, Some y -> x + y
>    | Some n, None | None, Some n -> n
>    | None, None -> None
> 
> Here, the expressions like 'Some x' and 'None' are patterns, which  
> match different variants of the 'maybe int' type. 'Some x' and 'Some  
> y' additionally bind matched subexpressions to names. For the first  
> pattern, I chose to shadow the nullable parameters with the non- 
> nullable matched subexpressions.

At the LLVM level, this is already what Talin wants to do.
The only difference is that Talin's code would need to rename the
variables inside the 'then' block in the frontend:

if x != NULL then
  x1 = cast-to-non-nullable-type (x)
  ... continue with x1 and know it can't be NULL
endif

OCaml's match is a shorthand for the comparison-plus-cast combination.

IIRC there's an OCaml compiler that uses LLVM; Talin should be able to
reuse the technique employed there.

HTH
Jo




More information about the llvm-dev mailing list