[LLVMdev] Multimedia IO instructions & partial backend implementations for simple CPUs

Rob Stewart robstewart57 at gmail.com
Tue Nov 5 06:39:12 PST 2013


On 3 November 2013 05:44, Sean Silva <chisophugis at gmail.com> wrote:

> 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.

OK. So to be specific, I am using a Haskell language binding to LLVM,
not C. With my multimedia IO examples, am I correct in thinking I have
a few options:
1. Do IO in my host language, and parse bytestrings in to LLVM data
structures, e.g. vectors. Then, pass these data structures to LLVM
generated code for JIT compilation.
2. Write IO functions in C, and compile with -emit-llvm . Then in my
LLVM code generation, I read this external function from a bitcode
file generated by clang. Here, there is no IO in my host language.
3. Call libc functions within LLVM to parse bytestrings directly in to
structs or vectors. If libc embedded in LLVM even possible?

Is there an LLVM cookbook for interaction with IO runtime systems?

> The state of backend documentation is pretty dire. I brain dumped basically
> all the backend docs I could think of in
> <http://thread.gmane.org/gmane.comp.compilers.llvm.devel/65898>. That thread
> also has some other good pointers for a person interested in writing a
> backend.

That's a great resource, thanks.

One thing I'd really appreciate is a cookbook on LLVM data structures.
I have read the language reference http://llvm.org/docs/LangRef.html ,
and understand the expressivity of aggregate types. What I do not yet
have a good feeling for is when to use them. To give a concrete
example, I'd like to parse a greyscale image in to an LLVM data
structure. At each {x,y} point, there is an Int8 value between 0 and
255. Take a small 4x3 image. I could feed my pixels in to a flat Int8
vector of length 12. I could also feed it in to an array of length 4,
of Int8 arrays of length 3.

Now take 2 simple functions: one does greyscale brightening, the other
does a sobel filter. The first needs only to know the value of 1 pixel
at a time, i.e. to increase its value. For this, the vector option
would be fine, and I assume (naively) that I'd enjoy SIMD performance
over this vector, executing `add x` to each element? However, the
Sobel filter needs information not only about the value of a pixel,
but also the values of its surrounding pixels. In this case, the 2D
array would be more suitable, as the shape of the image is known.
Would I lose SIMD vectorisation, probably? Or as a third option, would
I use a struct with a triple of three elements: a vector, and two Int8
values indicating the X and Y lengths of the image?

What I'm after is a cookbook for LLVM data structures, and how to
apply them. E.g, when to use structs, when to use aggregated types,
and how to hold on to SIMD vectorisation when ever is possible.

--
Rob



More information about the llvm-dev mailing list