Permalink
Browse files

Merge pull request #62 from MatthewFluet/llvm

Merge LLVM Codegen
  • Loading branch information...
MatthewFluet committed Jul 1, 2014
2 parents be122ad + e15d00b commit bf36a151a4b0cc366ba32b5ebea5d8ce25239a0b
@@ -1,4 +1,4 @@
(* Copyright (C) 2010-2011 Matthew Fluet.
(* Copyright (C) 2010-2011,2013-2014 Matthew Fluet.
* Copyright (C) 1999-2009 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
@@ -62,19 +62,20 @@ structure CallStack =
structure Codegen =
struct
datatype t = amd64 | C | x86
datatype t = AMD64 | C | LLVM | X86
val codegen =
case _build_const "MLton_Codegen_codegen": Int32.int; of
0 => C
| 1 => x86
| 2 => amd64
| 1 => X86
| 2 => AMD64
| 3 => LLVM
| _ => raise Primitive.Exn.Fail8 "MLton_Codegen_codegen"
val isC = codegen = C
val isX86 = codegen = x86
val isAmd64 = codegen = amd64
(* val isNative = isX86 orelse isAmd64 *)
val isAMD64 = codegen = AMD64
val isLLVM = codegen = LLVM
val isX86 = codegen = X86
end
structure Exn =
@@ -1,4 +1,4 @@
(* Copyright (C) 2011-2013 Matthew Fluet.
(* Copyright (C) 2011-2014 Matthew Fluet.
* Copyright (C) 2003-2007 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
*
@@ -180,7 +180,7 @@ functor Real (structure W: WORD_EXTRA
fun isNormal r = class r = NORMAL
val op ?= =
if MLton.Codegen.isX86 orelse MLton.Codegen.isAmd64
if MLton.Codegen.isAMD64 orelse MLton.Codegen.isLLVM orelse MLton.Codegen.isX86
then R.?=
else
fn (x, y) =>
View
@@ -100,6 +100,8 @@ doit "$lib" \
-cc-opt '-O1 -fno-common' \
-cc-opt '-fno-strict-aliasing -fomit-frame-pointer -w' \
-link-opt '-lm -lgmp' \
-llvm-llc-opt '-O2' \
-llvm-opt-opt '-mem2reg -O2' \
-mlb-path-map "$lib/mlb-path-map" \
-target-as-opt amd64 '-m64' \
-target-as-opt x86 '-m32' \
View
@@ -1,4 +1,11 @@
Here are the changes from version 2010608 to version 20130715.
Here are the changes from version 20130715 to version YYYYMMDD.
* 2014-07-01
- Merged Brian Leibig's llvm code generator.
--------------------------------------------------------------------------------
Here are the changes from version 20100608 to version 20130715.
Summary:
+ Compiler.
@@ -0,0 +1,15 @@
CCodegen
========
The <:CCodegen:> is a <:Codegen:code generator> that translates the
<:Machine:> <:IntermediateLanguage:> to C, which is further optimized
and compiled to native object code by `gcc` (or another C compiler).
== Implementation ==
* <!ViewGitFile(mlton,master,mlton/codegen/c-codegen/c-codegen.sig)>
* <!ViewGitFile(mlton,master,mlton/codegen/c-codegen/c-codegen.fun)>
== Details and Notes ==
The <:CCodegen:> is the original <:Codegen:code generator> for MLton.
@@ -17,4 +17,4 @@ program into disjoint sets, referred to as chunks.
== Details and Notes ==
Breaking large <:RSSA:> functions into chunks is necessary for
reasonable `gcc` compile times with the <:CCodegen:>.
reasonable compile times with the <:CCodegen:> and the <:LLVMCodegen:>.
View
@@ -0,0 +1,19 @@
Codegen
=======
<:Codegen:> is a translation pass from the <:Machine:>
<:IntermediateLanguage:> to one or more compilation units that can be
compiled to native object code by an external tool.
== Implementation ==
* <!ViewGitDir(mlton,master,mlton/codegen)>
== Details and Notes ==
The following <:Codegen:codegens> are implemented:
* <:AMD64Codegen:>
* <:CCodegen:>
* <:LLVMCodegen:>
* <:X86Codegen:>
@@ -33,11 +33,12 @@ pass an option to the assembler, you must use `gcc`'s `-Wa,` syntax.
+
Pass _option_ to `gcc` when compiling C code.
* ++-codegen {native|x86|amd64|c}++
* ++-codegen {native|amd64|c|llvm|x86}++
+
Generate native code or C code. With `-codegen native`
(`-codegen x86` or `-codegen amd64`), MLton typically compiles more
quickly and generates better code.
Generate native object code via amd64 assembly, C code, LLVM code, or
x86 code or C code. With `-codegen native` (`-codegen amd64` or
`-codegen x86`), MLton typically compiles more quickly and generates
better code.
* ++-const __name__ __value__++
+
@@ -89,7 +90,7 @@ Write C prototypes to _file_ for all of the functions in the program
* ++-ieee-fp {false|true}++
+
Cause the native code generator to be pedantic about following the
Cause the x86 native code generator to be pedantic about following the
IEEE floating point standard. By default, it is not, because of the
performance cost. This only has an effect with `-codegen x86`.
@@ -106,7 +107,7 @@ the output file is saved.
+
[cols="^25%,<75%"]
|====
| `g` | generated `.c` and `.s` files passed to `gcc`
| `g` | generated `.c` and `.s` files passed to `gcc` and generated `.ll` files passed to `llvm-as`
| `o` | object (`.o`) files
|====
@@ -119,6 +120,18 @@ e.g. `-link-opt '-Lpath -lfoo'`. If you wish to pass an option to the
linker, you must use `gcc`'s `-Wl,` syntax, e.g.,
`-link-opt '-Wl,--export-dynamic'`.
* ++-llvm-as-opt __option__++
+
Pass _option_ to `llvm-as` when assembling (`.ll` to `.bc`) LLVM code.
* ++-llvm-llc-opt __option__++
+
Pass _option_ to `llc` when compiling (`.bc` to `.o`) LLVM code.
* ++-llvm-opt-opt __option__++
+
Pass _option_ to `opt` when optimizing (`.bc` to `.bc`) LLVM code.
* ++-mlb-path-map __file__++
+
Use _file_ as an <:MLBasisPathMap:ML Basis path map> to define
@@ -67,6 +67,8 @@ list.
* Ville Laurikari ported MLton to IA64/HPUX, HPPA/HPUX, PowerPC/AIX, PowerPC64/AIX.
* Brian Leibig implemented the <:LLVMCodegen:>.
* Geoffrey Mainland helped with FreeBSD packaging.
* Eric McCorkle ported MLton to Intel Mac.
@@ -43,10 +43,10 @@ the profiler uses the `Enter`/`Leave` statements to infer the "local"
portion of the control stack at each program point. The profiler then
removes the ++Enter++s/++Leave++s and inserts different information
depending on which kind of profiling is happening. For time profiling
(with the native codegen), the profiler inserts labels that cover the
(with the <:AMD64Codegen:> and <:X86Codegen:>), the profiler inserts labels that cover the
code (i.e. each statement has a unique label in its basic block that
prefixes it) and associates each label with the local control stack.
For time profiling (with the C and bytecode codegens), the profiler
For time profiling (with the <:CCodegen:> and <:LLVMCodegen:>), the profiler
inserts code that sets a global field that records the local control
stack. For allocation profiling, the profiler inserts calls to a C
function that will maintain byte counts. With stack profiling, the
@@ -0,0 +1,17 @@
LLVMCodegen
===========
The <:LLVMCodegen:> is a <:Codegen:code generator> that translates the
<:Machine:> <:IntermediateLanguage:> to <:LLVM:> assembly, which is
further optimized and compiled to native object code by the <:LLVM:>
toolchain.
== Implementation ==
* <!ViewGitFile(mlton,master,mlton/codegen/llvm-codegen/llvm-codegen.sig)>
* <!ViewGitFile(mlton,master,mlton/codegen/llvm-codegen/llvm-codegen.fun)>
== Details and Notes ==
The <:LLVMCodegen:> was initially developed by Brian Leibig (see
<!Cite(Leibig13,An LLVM Back-end for MLton)>).
View
@@ -1,18 +1,11 @@
LLVM
====
http://www.llvm.org/[LLVM] (Low Level Virtual Machine) is an abstract
machine, optimizer, and code generator. It might make a nice backend
for MLton, and there has been some discussion about this on the MLton
list.
The http://www.llvm.org/[LLVM Project] is a collection of modular and
reusable compiler and toolchain technologies.
* http://www.mlton.org/pipermail/mlton/2005-November/028263.html
The latest is that LLVM's `gcc` variant has been used in place of
`gcc`, and so there has been no work toward changing MLton to target
LLVM's IL directly.
* http://www.mlton.org/pipermail/mlton/2006-August/029021.html
MLton supports code generation via LLVM (`-codegen llvm`); see
<:LLVMCodegen:>.
== Also see ==
@@ -438,6 +438,15 @@ ____
Ken Larsen and Henning Niss.
USENIX Annual Technical Conference, 2004.
* <!Anchor(Leibig13)>
http://www.cs.rit.edu/~bal6053/msproject/[An LLVM Back-end for MLton].
Brian Leibig.
MS Project Report, 2013.
+
____
Describes MLton's <:LLVMCodegen:>.
____
* <!Anchor(Leroy90)>
http://pauillac.inria.fr/~xleroy/bibrefs/Leroy-ZINC.html[The ZINC Experiment: an Economical Implementation of the ML Language].
Xavier Leroy.
@@ -17,8 +17,8 @@ It uses <:AllocateRegisters:>, <:Chunkify:>, and <:ParallelMove:>.
== Details and Notes ==
Because the MLton runtime system is shared by all codegens, it is most
convenient to decide on stack layout _before_ any codegen takes over.
Because the MLton runtime system is shared by all <:Codegen:codegens>, it is most
convenient to decide on stack layout _before_ any <:Codegen:codegen> takes over.
In particular, we compute all the stack frame info for each <:RSSA:>
function, including stack size, <:GarbageCollection:garbage collector>
masks for each frame, etc. To do so, the <:Machine:>
View
@@ -54,10 +54,11 @@ wish to pass an option to the assembler, you must use \fBgcc\fP's
Pass \fIoption\fP to \fBgcc\fP when compiling C code.
.TP
\fB\-codegen \fI{\fBnative\fP|\fBx86\fP|\fBamd64\fP|\fBc\fP}\fP\fR
Generate native code or C code. With \fB\-codegen
native\fP (\fB\-codegen x86\fP or \fB\-codegen amd64\fP), \fBMLton\fP
typically compiles more quickly and generates better code.
\fB\-codegen \fI{\fBnative\fP|\fBx86\fP|\fBamd64\fP|\fBc\fP|\fBllvm\fP}\fP\fR
Generate native object code via amd64 assembly, C code, LLVM code, or
x86 assembly. With \fB\-codegen native\fP (\fB\-codegen amd64\fP or
\fB\-codegen x86\fP), \fBMLton\fP typically compiles more quickly and
generates better code.
.TP
\fB\-const '\fIname value\fP'\fR
@@ -120,11 +121,23 @@ approximate measure of code size of a procedure. The default is 320.
Save intermediate files. If no \fB\-keep\fP argument is given, then
only the output file is saved.
.in +.5i
\fBg\fP generated \fB.c\fP and \fB.s\fP files passed to \fBgcc\fP
\fBg\fP generated \fB.c\fP and \fB.s\fP files passed to \fBgcc\fP and generated \fB.ll\fP files passed to \fBllvm-as\fP
.br
\fBo\fP object (\fB.o\fP) files
.in -.5i
.TP
\fB\-llvm\-as\-opt \fIoption\fP\fR
Pass \fIoption\fP to \fBllvm-as\fP when assembling (\fB.ll\fP to \fB.bc\fP) LLVM code.
.TP
\fB\-llvm\-llc\-opt \fIoption\fP\fR
Pass \fIoption\fP to \fBllc\fP when compiling (\fB.bc\fP to \fB.o\fP) LLVM code.
.TP
\fB\-llvm\-opt\-opt \fIoption\fP\fR
Pass \fIoption\fP to \fBopt\fP when optimizing (\fB.bc\fP to \fB.bc\fP) LLVM code.
.TP
\fB\-link\-opt \fIoption\fP\fR
Pass \fIoption\fP to \fBgcc\fP when linking. You can use this to
@@ -328,6 +328,7 @@ let
* end of the backend.
*)
if !Control.codegen = Control.CCodegen
orelse !Control.codegen = Control.LLVMCodegen
orelse !Control.profile <> Control.ProfileNone
then new ()
else
Oops, something went wrong.

0 comments on commit bf36a15

Please sign in to comment.