<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 2, 2013 at 2:48 PM, Rob Stewart <span dir="ltr"><<a href="mailto:robstewart57@gmail.com" target="_blank">robstewart57@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi, I'm getting started with LLVM, with the intention of writing a DSL<br>

that compiles to LLVM IR, to target a new CPU instruction set. I have<br>
two questions:<br>
<br>
1. Multimedia IO in LLVM<br>
<br>
In the paper "The LLVM Instruction Set and Compilation Strategy" [1],<br>
there is talk about a possible multimedia instruction set in a future<br>
LLVM release:<br>
<br>
"Note that LLVM is a virtual instruction set: it does not define<br>
runtime and operating system functions such as I/O, memory management<br>
(in particular, garbage collection), signals, and many others. Some<br>
issues that do belong in the instruction set and may be added in the<br>
future include support for multimedia instructions (e.g., packed<br>
operations),<br>
predicated instructions, and explicit parallelism."<br></blockquote><div><br></div><div>We have vectors. No predicated instructions in the LLVM IR (only in the MI layer). I'm not sure what you mean by "explicit parallelism" (do you mean something like Cilk?) but I don't think LLVM supports that (those things usually have a nontrivial runtime component).</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
My question is a very basic one: how do I use LLVM IR code to do file<br>
IO? As a simple example, take a file with 3 tab-separated integers.<br>
How would I read this file in to an LLVM vector <3 x i32> ? Now take a<br>
more complicated example: decoding a file to an LLVM vector<br>
representation. To use the multimedia instruction set described above<br>
(though I guess not implemented yet), how do I: A) read a greyscale<br>
3x3 pixel image file, B) translate this to an LLVM vector <9 x i8> ?<br></blockquote><div><br></div><div>LLVM doesn't provide a runtime or "VM". You basically do these things the same way that you do them in C. Yes, this unfortunately requires knowing your target platform's system libraries and how to link to them and such; LLVM doesn't paper over this.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<br>
2. Implementing an LLVM backend subset.<br>
<br>
I have not yet delved deeply in to the requirements of implementing<br>
LLVM backends to target new hardware instruction sets. Given a<br>
constrained hardware implementation, is it acceptable to implement a<br>
backend subset, and throwing "Not Supported" exceptions where ever<br>
appropriate. To give a concrete example, take a simple CPU<br>
architecture that does not support floating point arithmetic, but does<br>
support simple integer arithmetic. If my LLVM frontend produces only<br>
i32 values, then `llc -march=my_new_arch` doesn't complain. If,<br>
however, my frontend produces float values, then `llc<br>
-marc=my_new_arch` would complain with the "Type 'float' Not Supported<br>
by architecture my_new_arch".<br>
<br>
Is this the philosophy of LLVM backend implementation? Must the new<br>
target architecture support all LLVM instructions, or am I able to<br>
develop an LLVM backend for an architecture that lacks features like<br>
floating point arithmetic? Any related resources would be appreciated.<br></blockquote><div><br></div><div>If you don't want to merge this with trunk, then you can do whatever you want; typically when starting out you will only implement a subset of instructions (you can't implement them all simultaneously, now can you?). The state of backend documentation is pretty dire. I brain dumped basically all the backend docs I could think of in <<a href="http://thread.gmane.org/gmane.comp.compilers.llvm.devel/65898">http://thread.gmane.org/gmane.comp.compilers.llvm.devel/65898</a>>. That thread also has some other good pointers for a person interested in writing a backend. </div>
<div><br></div><div>Getting a backend intro trunk generally speaking is a large long-term commitment. I'm not sure what the exact requirements are for getting a backend into trunk (I don't think anybody really does at a deep level, other than "some critical subset of experienced LLVM developers think it looks good enough to be committed"), but the biggest hurdle (generally) with getting a backend into LLVM trunk is that it requires a demonstrated ability to work with the community and a clear investment in maintaining the backend from now into the foreseeable future (to put it bluntly, this generally will mean at least 1 or 2 people with a paycheck tied to maintaining the backend and contributing to the community, and these being people that have a history of submitting good patches and that are familiar with the community expectations). (The reason for these requirements is purely experience with other backends, which have been a maintainability nightmare without active developers responsible for maintaining them and compensating for the increase in general codebase complexity (e.g. each new backend makes refactoring the target-independent backend parts more difficult)).</div>
<div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
[1] - <a href="http://goo.gl/HA5AXU" target="_blank">http://goo.gl/HA5AXU</a><br>
<br>
--<br>
Rob<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div></div>