blob: 4908384e4334ef68dec84aed18efe3982a2d2c0e [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DragonEgg</title>
</head>
<body>
<div>
<img src="dragoneggsmall.png" alt="DragonEgg logo" width="136" height="136" align="left" hspace="30">
<!--*********************************************************************-->
<h1>DragonEgg - Using LLVM as a GCC backend</h1>
<!--*********************************************************************-->
<p><a href="http://dragonegg.llvm.org/">DragonEgg</a> is a gcc plugin
<tt>dragonegg.so</tt> that replaces gcc's optimizers and code generators with
those from the <a href="http://llvm.org">LLVM project</a>.</p>
<p>It is a reimplementation of
<a href="http://llvm.org/docs/CommandGuide/">llvm-gcc</a>
that works with <a href="http://gcc.gnu.org">gcc-4.5</a> or later.</p>
<br clear="all">
<!--=====================================================================-->
<h2>Goals</h2>
<!--=====================================================================-->
<ul>
<li>Work with unmodified gcc</li>
<li>Support all gcc languages</li>
</ul>
<!--=====================================================================-->
<h2>Current Status</h2>
<!--=====================================================================-->
<ul>
<li>C works well, for example you can build a working gcc using it</li>
<li>C++ works fairly well, for example you can build LLVM, clang and boost
with it (the resulting LLVM and clang work correctly; I did not test whether
boost actually works)</li>
<li>A lot of Fortran compiles, but the compiled code has not been tested for
correctness</li>
<li>It can compile quite a lot of Ada, but the compiled code may not work
right</li>
<li>It can compile a small amount of Obj-C and Obj-C++</li>
<li>It fails to compile any Java</li>
<li>Exception handling does not work</li>
<li>Limited debug info</li>
<li>Requires one gcc patch</li>
<li>Only supports x86-32 and x86-64</li>
<li>Only supports linux and darwin (darwin hasn't been tested recently though)</li>
</ul>
<p><a href="http://dragonegg.llvm.org/">DragonEgg</a> is under heavy
development and is not mature - it may crash or produce wrong code. It works
with <a href="http://gcc.gnu.org">gcc-4.5</a> which is nowhere near being
released yet and is changing rapidly. This is an additional source of
instability, and means that
<a href="http://dragonegg.llvm.org/">DragonEgg</a> may fail to build from
time-to-time if it has not caught up with the latest gcc changes.
<a href="http://dragonegg.llvm.org/">DragonEgg</a> uses the development
version of <a href="http://llvm.org">LLVM</a> which creates similar problems.</p>
<!--=====================================================================-->
<h2>DragonEgg in action</h2>
<!--=====================================================================-->
<p>Here is the result of compiling a simple "hello world" program with gcc-4.5.</p>
<pre>
$ gcc hello.c -S -O1 -o -
.file "hello.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello world!"
.text
.globl main
.type main, @function
main:
subq $8, %rsp
movl $.LC0, %edi
call puts
movl $0, %eax
addq $8, %rsp
ret
.size main, .-main
.ident "GCC: (GNU) 4.5.0 20090928 (experimental)"
.section .note.GNU-stack,"",@progbits
</pre>
<p>Adding <tt>-fplugin=path/dragonegg.so</tt> to the gcc command line causes
the program to be optimized and codegened by LLVM instead.</p>
<pre>
$ gcc hello.c -S -O1 -o - -fplugin=./dragonegg.so
.file "hello.c"
# Start of file scope inline assembly
.ident "GCC: (GNU) 4.5.0 20090928 (experimental) LLVM: 82450:82981"
# End of file scope inline assembly
.text
.align 16
.globl main
.type main,@function
main:
subq $8, %rsp
movl $.L.str, %edi
call puts
xorl %eax, %eax
addq $8, %rsp
ret
.size main, .-main
.type .L.str,@object
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "Hello world!"
.size .L.str, 13
.section .note.GNU-stack,"",@progbits
</pre>
<p>Adding <tt>-fplugin-arg-dragonegg-emit-ir</tt> causes LLVM IR to be output.</p>
<pre>
$ gcc hello.c -S -O1 -o - -fplugin=./dragonegg.so -fplugin-arg-dragonegg-emit-ir
; ModuleID = 'hello.c'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
target triple = "x86_64-unknown-linux-gnu"
module asm "\09.ident\09\22GCC: (GNU) 4.5.0 20090928 (experimental) LLVM: 82450:82981\22"
@.str = private constant [13 x i8] c"Hello world!\00", align 1 ; &lt;[13 x i8]*&gt; [#uses=1]
define i32 @main() nounwind {
entry:
%0 = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @.str, i64 0, i64 0)) nounwind ; &lt;i32&gt; [#uses=0]
ret i32 0
}
declare i32 @puts(i8* nocapture) nounwind
</pre>
<!--=====================================================================-->
<h2>Getting it</h2>
<!--=====================================================================-->
<p>Get <a href="http://dragonegg.llvm.org/">DragonEgg</a>:</p>
<pre> svn co http://llvm.org/svn/llvm-project/dragonegg/trunk dragonegg</pre>
<p>Get the development version of <a href="http://llvm.org">LLVM</a>:</p>
<pre> svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm</pre>
<p>Build <a href="http://llvm.org">LLVM</a> in the usual way.
You do not need to install it.</p>
<p>Get the development version of <a href="http://gcc.gnu.org">gcc</a>:</p>
<pre> svn co http://gcc.gnu.org/svn/gcc/trunk gcc</pre>
<p>Apply all of the patches in <tt>dragonegg/gcc-patches/</tt>, if any, to
<a href="http://gcc.gnu.org">gcc</a>.
You need to pass the <tt>-p1</tt> option to <tt>patch</tt>.
Build and install <a href="http://gcc.gnu.org">gcc</a> in the usual way.</p>
<p>Doing</p>
<pre> GCC=path_to_just_installed_gcc make</pre>
<p>in the <tt>dragonegg</tt> directory should then build <tt>dragonegg.so</tt>.
See the <tt>README</tt> file for more details.</p>
<p>To use <tt>dragonegg.so</tt>, compile something with your just-installed
version of <tt>gcc</tt>, adding <tt>-fplugin=path_to_dragonegg/dragonegg.so</tt>
to the command line. See the <tt>README</tt> file for more details and useful
command line options.</p>
<!--=====================================================================-->
<h2>It doesn't work!</h2>
<!--=====================================================================-->
<p>Sorry about that! Please report bugs and problems to the LLVM developers'
<a href="http://llvm.org/docs/#maillist">mailing list</a>, or using LLVM's
<a href="http://llvm.org/bugs/">bugzilla</a>.</p>
<p>Suggestions for improvement are welcome. Patches are even more welcome!</p>
<!--=====================================================================-->
<h2>More information</h2>
<!--=====================================================================-->
There was a talk "Reimplementing llvm-gcc as a gcc plugin" about
<a href="http://dragonegg.llvm.org/">DragonEgg</a> at the
<a href="http://llvm.org/devmtg/2009-10/">2009 llvm developers meeting</a>.
At that time, <a href="http://dragonegg.llvm.org/">DragonEgg</a> was known as
"the gcc plugin".
<p>[<a href="http://llvm.org/devmtg/2009-10/Sands_LLVMGCCPlugin.pdf">Slides</a>]</p>
<p>[<a href="http://llvm.org/devmtg/2009-10/Sands_LLVMGCCPlugin-700kbps.mov">Video</a>]&nbsp;<font size="-1">(Computer)</font></p>
<p>[<a href="http://llvm.org/devmtg/2009-10/Sands_LLVMGCCPlugin-mobile.m4v">Video</a>]&nbsp;<font size="-1">(Mobile)</font></p>
</div>
</body>
</html>