<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
Thanks Garrison.  I just read up a little on Clang - the website seems to indicate that the source is simple and easy to modify for this purpose.  Have any of you used TinyCC (<A href="http://bellard.org/tcc/">http://bellard.org/tcc/</A>) before?  It seems to do exactly what I would like, *but* 1) I haven't heard of it's use in industry as much as I have of LLVM and 2) I don't know how well supported it is.  Thanks again.<BR>
 <BR>
- Shasank<BR> <BR>
<HR id=stopSpelling>
Subject: Re: [LLVMdev] Using LLVM to generate x86 dynamically in memory<BR>From: gvenn.cfe.dev@gmail.com<BR>Date: Tue, 2 Feb 2010 20:00:32 -0500<BR>CC: grosbach@apple.com; llvmdev@cs.uiuc.edu<BR>To: shanko_chavano@hotmail.com<BR><BR><BASE>This can be done. Last year I took clang (v. 2.5) and hacked the compiler driver into a library which would JIT C source to memory.
<DIV>I then created a Zend extension which utilized the library. No external frameworks were used in these hacks, and were fairly simple</DIV>
<DIV>to implement once one knew how to use the Clang/LLVM libraries.</DIV>
<DIV><BR></DIV>
<DIV>I cannot speak to your dll requirement, as the work was done for Linux. In addition I never measured the overhead in terms of a final </DIV>
<DIV>accumulated library size (size of all necessary libraries). No other measurements were taken either.</DIV>
<DIV><BR></DIV>
<DIV>Garrison</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>
<DIV>On Feb 2, 2010, at 19:39, Shasank Chavan wrote:</DIV><BR class=ecxApple-interchange-newline>
<BLOCKQUOTE><SPAN class=ecxApple-style-span style="WORD-SPACING: 0px; FONT: medium Helvetica; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; WHITE-SPACE: normal; LETTER-SPACING: normal; BORDER-COLLAPSE: separate">
<DIV class=ecxhmmessage style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">Hi Jim.  Thanks for your speedy response.  I'm not entirely sure if a JIT is what I'm looking for.  I'm basically looking for a dll with an interface that takes a C program as input and compiles and optimizes it to native x86 instructions in an in-memory buffer.  I don't want the dll the execute it, and I don't particularly want to translate our expressions into LLVM bitcode (although I can if the rest of the pieces are there).  Also, I briefly read up on lli.  This looks like a separate process will have to be spawned to invoke the JIT to execute programs in LLVM bytecode.  This will definitely incur an overhead penalty that we wouldn't want to pay.  Thanks in advance for your response.<BR> <BR>- Shasank<BR> <BR>BTW - I was doing some google searching just now on the topic again, and i was surprised to see how fast google had already found the log of this previous conversation recorded at uiuc. ;).<BR> <BR> <BR> <BR><BR> <BR>> Subject: Re: [LLVMdev] Using LLVM to generate x86 dynamically in memory<BR>> From:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:grosbach@apple.com">grosbach@apple.com</A><BR>> Date: Tue, 2 Feb 2010 15:24:23 -0800<BR>> CC:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:shanko_chavano@hotmail.com">shanko_chavano@hotmail.com</A><BR>> To:<SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</A><BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> On Feb 2, 2010, at 3:05 PM, Shasank Chavan wrote:<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> > Hi. I'm very new to LLVM, and have read some of the documentation online. Before I invest too much time, however, in learning about LLVM, I'd like to know if it can be used for my purpose. We currently have a critical runtime component that evaluates expressions via interpretation. The bytecode that we generate goes through various optimization phases similarly to that of optimizing language compilers (although definitely not as complete) before being evaluated at runtime. For quite some time now we have been thinking about getting away from interpretation all-together and generating native code directly.<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><BR>> > What I'd like to know is:<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><BR>> > 1) Is there an LLVM backend library that can take either a) a C source program in memory or b) an LLVM program in memory, as input and generate x86 instructions in memory?<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> LLVM does support a Just-In-Time (JIT) compiler interface, which is what it sounds like you're looking for. I would suggest looking more deeply into the llvm documentation at<SPAN class=ecxApple-converted-space> </SPAN><A href="http://llvm.org/">llvm.org</A>, paying particular attention to JIT references and the lli utility.<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> ><SPAN class=ecxApple-converted-space> </SPAN><BR>> > 2) HOw "light-weight" would a mechanism like this be? I suppose that depends on what optimizations we decided to apply during this code-gen phase.<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> It does indeed vary quite a bit. I suspect your best bet will be to create some test programs, or just use some of the examples from the llvm source tree, and look at the footprint and compare to what your needs are.<BR>><SPAN class=ecxApple-converted-space> </SPAN><BR>> > What we plan to do is invoke this in-memory compiler to generate the x86 instructions, and then ship them at runtime to our new expression evaluation engine that will simply set a function pointer to it and execute.<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><BR>> > I heard of a compiler called TinyCC that basically has a library (libtcc) that can be invoked at runtime to generate x86 instructions directly from a C program stored in memory. That's what I would like, but with the aggressive opts provided in the LLVM infrastructure. Thanks so much for your time...<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><BR>> > - Shasank<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><BR>> > Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up now._______________________________________________<BR>> > LLVM Developers mailing list<BR>> ><SPAN class=ecxApple-converted-space> </SPAN><A href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</A><SPAN class=ecxApple-converted-space> </SPAN><A href="http://llvm.cs.uiuc.edu/">http://llvm.cs.uiuc.edu/</A><BR>> ><SPAN class=ecxApple-converted-space> </SPAN><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</A><BR>><SPAN class=ecxApple-converted-space> </SPAN><BR><BR>
<HR>
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.<SPAN class=ecxApple-converted-space> </SPAN><A href="http://clk.atdmt.com/GBL/go/201469226/direct/01/">Sign up now.</A><SPAN class=ecxApple-converted-space> </SPAN>_______________________________________________<BR>LLVM Developers mailing list<BR><A href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</A><SPAN class=ecxApple-converted-space> </SPAN>        <A href="http://llvm.cs.uiuc.edu/">http://llvm.cs.uiuc.edu/</A><BR><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</A><BR></DIV></SPAN></BLOCKQUOTE></DIV><BR></DIV>                                       <br /><hr />Hotmail: Free, trusted and rich email service. <a href='http://clk.atdmt.com/GBL/go/201469228/direct/01/' target='_new'>Get it now.</a></body>
</html>