mincaml: a simple and efficient compiler for a minimal functional …sumii/pub/fdpe05.pdf · ·...
TRANSCRIPT
![Page 1: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/1.jpg)
MinCaml:A Simple and Efficient Compilerfor a Minimal Functional Language
Eijiro SumiiTohoku University
![Page 2: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/2.jpg)
Highlights
"Simple and efficient compilerfor a minimal functional language"
Only 2000 lines of OCamlEfficiency comparable to OCamlOptand GCC for several applications– Ray tracing, Huffman encoding, etc.Used for undergraduates in Tokyo since 2001
![Page 3: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/3.jpg)
Outline of This Talk
Pedagogical backgroundDesign and implementation of MinCamlEfficiency
![Page 4: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/4.jpg)
Computer Science forUndergraduates in Tokyo
Liberal arts (1.5 yr)– English, German/Chinese/French/Spanish,
mathematics, logic, physics, chemistry, ...– Computer literacy, CS introduction,
Java programming, data structuresCS major (2.5 yr) [~30 students/yr]– Algorithms, OS, architecture, ...– SPARC assembly, C, C++, Scheme, OCaml,
Prolog
![Page 5: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/5.jpg)
Programming Languages forCS Major in Tokyo
PL labs (63 hr)– Mini-Scheme interpreter in Scheme,– Mini-ML interpreter in OCaml,– Othello/Reversi competition in OCaml, etc.Compiler lecture (21 hr)– Parsing, intermediate representations,
register allocation, garbage collection, ...PL theory lectures (42 hr)– λ-calculus, semantics, type theory, ...
![Page 6: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/6.jpg)
CPU/Compiler Labs (126 hr)
CPU lab– Design and implement original CPUs by
using VHDL and FPGACompiler lab– Develop compilers for the original CPUs
MinCaml is used here!
⇒ Compete by the speed of ray tracing(5-6 students per group)
![Page 7: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/7.jpg)
Special thanks to Hiraki laboratory
![Page 8: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/8.jpg)
![Page 9: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/9.jpg)
![Page 10: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/10.jpg)
How is MinCaml Used?
Students are given high-level descriptions of MinCaml– in Japanese and pseudo-codeEach group is required to implement themEvery student is required to solve small exercises– such as hand compilation
![Page 11: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/11.jpg)
Outcome (1/2)
Students liked ML!
Implemented polymorphism(like MLton), garbage collection,inter-procedural register allocation, etc. without being toldStarted a portal site (www.ocaml.jp) with Japanese translations of the OCaml manual without being told
![Page 12: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/12.jpg)
Outcome (2/2)
"Outsiders" are also using MinCaml
Somebody anonymous wrote a comprehensive commentary on MinCamlRuby hackers organized an independent seminar to study MinCamlProf. Asai is using MinCaml in Ochanomizu University
![Page 13: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/13.jpg)
Outline of This Talk
Pedagogical backgroundDesign and implementation of MinCamlEfficiency
![Page 14: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/14.jpg)
Goals
As simple as possible
but
Able to efficiently executenon-trivial applications(such as ray tracing)
![Page 15: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/15.jpg)
MinCaml: The Language
Functional: no destructive update of variables (cf. SSA)Higher-orderCall-by-valueImpure– Input/output– Destructive update of arraysImplicitly typedMonomorphic
![Page 16: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/16.jpg)
Syntax (1/2)
M, N (expressions) ::=cop(M1, ..., Mn)if M then N1 else N2let x = M in Nxlet rec x y1 ... yn = M1 in M2M N1 ... Nn (no partial application)... (cont.)
![Page 17: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/17.jpg)
Syntax (2/2)
M, N (expressions) ::=...(M1, ..., Mn)let (x1, ..., xn) = M in N (cf. #i M)Array.create M NM.(N)M1.(M2) ← M3()
Literally implemented asML data type Syntax.t
![Page 18: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/18.jpg)
Everything else is omitted!
Array boundary checking (easy)Garbage collectionData types and pattern matchingPolymorphismExceptionsObjects etc.
Optional homework(≥ 2 compulsory from this year)
![Page 19: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/19.jpg)
MinCaml: The Compiler
TypingParser AlphaKNormal
ConstFold Inline
Closure
Elim
RegAllocVirtual Emit
Lexer100 168 165 181 46
334634
104 163 262 256
BetaAssoc3818
Simm1342
![Page 20: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/20.jpg)
Lexing and Parsing
Written in OCamlLex and OCamlYaccGiven by the instructer– Algorithms are out of scopeCf. packrat parsing [Ford 2002]
![Page 21: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/21.jpg)
Type Inference
Based on standard unificationusing ML references– Let-polymorphic version is
already taught in PL labFree variables are treated asexternal functions (or arrays)– "Principal typing" [Jim 96] is
automatically inferred
![Page 22: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/22.jpg)
MinCaml: The Compiler
TypingParser AlphaKNormal
ConstFold Inline
Closure
Elim
RegAllocVirtual Emit
Lexer100 168 165 181 46
334634
104 163 262 256
BetaAssoc3818
Simm1342
![Page 23: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/23.jpg)
K-Normalization
a + b + c * d⇓
let tmp1 = a + b inlet tmp2 = c * d intmp1 + tmp2
Nesting is allowedlet x = (let y = M1 in M2) in M3
– Simplifies the normalization and inliningCf. A-normalization by CPS
![Page 24: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/24.jpg)
Syntax of K-Normal Form
M, N ::=cop(x1, ..., xn)if x then M1 else M2let x = M in Nxlet rec x y1 ... yn = M1 in M2x y1 ... yn...
Implemented as KNormal.t
![Page 25: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/25.jpg)
Algorithm of K-Normalization: Pseudo-Code Given to Students
K : Syntax.t → KNormal.tK(c) = cK(op(M1, ..., Mn)) =
let x1 = K(M1) in ... let xn = K(Mn) inop(x1, ..., xn)
K(if op(M1, ..., Mn) then N1 else N2) =let x1 = K(M1) in ... let xn = K(Mn) inif op(x1, ..., xn) then K(N1) else K(N2)
K(let x = M in N) = let x = K(M) in K(N)K(x) = x etc.
![Page 26: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/26.jpg)
α-Conversion (AnotherExample of Pseudo-Code)
α : KNormal.t → Id.t Map.t → KNormal.t
α(c)ρ = cα(op(x1, ..., xn))ρ = op(ρ(x1), ..., ρ(xn))α(if x then N1 else N2)ρ =
if ρ(x) then α(N1)ρ else α(N2)ρα(let x = M in N)ρ = (x' fresh)
let x' = α(M)ρ in α(N)ρ[x→x']α(x)ρ = ρ(x)
etc.
![Page 27: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/27.jpg)
MinCaml: The Compiler
TypingParser AlphaKNormal
ConstFold Inline
Closure
Elim
RegAllocVirtual Emit
Lexer100 168 165 181 46
334634
104 163 262 256
BetaAssoc3818
Simm1342
![Page 28: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/28.jpg)
β-Reduction
let x = y in M ⇒ [y/x]M
Pseudo-code (similar to previous examples) is left as an exercise
![Page 29: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/29.jpg)
Nested "Let" Reduction
let y = (let x = M1 in M2) in M3
⇓let x = M1 in let y = M2 in M3
Resembles A-normalization,but does not expand "if"
C[if M then N1 else N2]⇒ if x then C[N1] else C[N2]
![Page 30: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/30.jpg)
Inlining
Inlines all "small" functions
Includes recursive ones"Small" = less than a constant size– User-specified by "-inline" optionRepeat for a constant number of times– User-specified by "-iter" option
![Page 31: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/31.jpg)
Constant Folding andUnused Variable Elimination
let x = 3 in let y = 7 in x + y⇓
let x = 3 in let y = 7 in 10⇓10
Effective after inlining
![Page 32: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/32.jpg)
MinCaml: The Compiler
TypingParser AlphaKNormal
ConstFold Inline
Closure
Elim
RegAllocVirtual Emit
Lexer100 168 165 181 46
334634
104 163 262 256
BetaAssoc3818
Simm1342
![Page 33: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/33.jpg)
Closure Conversion
Local function definitions (let rec)+ function applications
⇓
Top-level function definitions+
Closure creations (make_closure)Closure applications (apply_closure)Known function calls (apply_direct)
![Page 34: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/34.jpg)
Example 1:Closure Creation/Application
let x = 3 inlet rec f y = x + y inf 7
⇓let rec ftop [x] y = x + y ;;
let x = 3 inmake_closure f = (ftop, [x]) inapply_closure f 7
![Page 35: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/35.jpg)
Example 2: Known Function Call
let rec f x = x + 3 in(f, f 7)
⇓let rec ftop [] x = x + 3 ;;
make_closure f = (ftop, []) in(f, apply_direct f 7)
![Page 36: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/36.jpg)
Example 3:Unused Closure Elimination
let rec f x = x + 3 inf 7
⇓let rec ftop [] x = x + 3 ;;
apply_direct f 7
![Page 37: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/37.jpg)
MinCaml: The Compiler
TypingParser AlphaKNormal
ConstFold Inline
Closure
Elim
RegAllocVirtual Emit
Lexer100 168 165 181 46
334634
104 163 262 256
BetaAssoc3818
Simm1342
![Page 38: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/38.jpg)
Virtual Machine Code Generation
SPARC assembly with:Infinite number of registers/variablesTop-level function definitions and calls (call_closure, call_direct)Conditional expressions (if)
Tuple creations/accessesand closure creations are
expanded to stores and loads
![Page 39: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/39.jpg)
Register Allocation
Greedy algorithm with:Look-ahead for targeting
let x = 3 in let y = 7 in f y x⇒ let r2 = 3 in let r1 = 7 in f r1 r2
Backtracking for "early save"let x = 3 in...; f (); ...; x + 7
⇒ let r1 = 3 insave(r1, x); ...; f (); ...; restore(x, r2); r2 + 7
![Page 40: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/40.jpg)
13-Bit Immediate Optimization
Specific to SPARC“Inlining” or "constant folding"for integers from -4096 to 4095
set 123, %r1add %r1, %r2, %r3
⇓add %r2, 123, %r3
![Page 41: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/41.jpg)
Assembly Generation
Lengthy (256 lines)but easy
Tail call optimizationStack map computationRegister shuffling– Somewhat tricky but short (11 lines)
![Page 42: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/42.jpg)
Outline of This Talk
Pedagogical backgroundDesign and implementation of MinCamlEfficiency
![Page 43: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/43.jpg)
Environment
Machine: Sun Fire V880– 4 Ultra SPARC III 1.2GHz– 8 GB main memory– Solaris 9Compilers:– MinCaml (32 bit, -iter 1000 -inline 100)– OCamlOpt 3.08.3 (32 bit, -unsafe -inline 100)– GCC 4.0.0 20050319 (32 bit and 64 bit, -O3)– GCC 3.4.3 (32 bit "flat model", -O3)
![Page 44: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/44.jpg)
Applications
Functional– Ackermann– Fibonacci– TakeuchiImperative– Ray tracing– Harmonic function– Mandelbrot set– Huffman encoding
![Page 45: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/45.jpg)
Execution Time of Functional Programs(min-caml = 1)
0
1
2
3
4
5
6
7
ack fib tak
min-camlocamloptgcc -m32gcc -m64gcc -m32 -mflat
![Page 46: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/46.jpg)
Execution Time of Imperative Programs(gcc -m32 = 1)
0
0.5
1
1.5
2
2.5
3
3.5
raytrace harmonic mandelbrot huffman
min-camlocamloptgcc -m32gcc -m64gcc -m32 -mflat
![Page 47: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/47.jpg)
Summary
"Simple and efficient compilerfor a minimal functional language"
Future work:Improve the register allocation– By far more complex than other modules– Too slow at compile timeRetarget to IA-32– 2-operand instructions (which are
"destructive" by definition) and FPU stack
![Page 48: MinCaml: A Simple and Efficient Compiler for a Minimal Functional …sumii/pub/FDPE05.pdf · · 2005-10-04A Simple and Efficient Compiler for a Minimal Functional Language ... C++,](https://reader031.vdocuments.mx/reader031/viewer/2022020315/5ab114fd7f8b9a284c8c0404/html5/thumbnails/48.jpg)
http://min-caml.sf.net/