I'm working on it..

Moderator: Hoernchen

I'm working on it..

Postby Hoernchen » Fri Mar 15, 2013 3:18 pm

I just thought I'd let you know that I've been working on a epiphany llvm backend for the past month or so, it's not quite ready yet, but I'll release it as soon as it is.
I did not plan to announce anything before releasing it, but with talk about a llvm backend as a gsoc project popping up tnt suggested that it might be a good idea to mention it now because duplicating that work would probably be a waste of time.
Hoernchen
 
Posts: 41
Joined: Mon Dec 17, 2012 3:22 am

Re: I'm working on it..

Postby 9600 » Fri Mar 15, 2013 4:31 pm

Hoernchen wrote:I just thought I'd let you know that I've been working on a epiphany llvm backend for the past month or so, it's not quite ready yet, but I'll release it as soon as it is.
I did not plan to announce anything before releasing it, but with talk about a llvm backend as a gsoc project popping up tnt suggested that it might be a good idea to mention it now because duplicating that work would probably be a waste of time.


It would be a terrible waste of time if this work was duplicated, thanks for letting us know and it really is fantastic news to hear that you're working on this!

Do you have access to prototype hardware, and if not would network access to a board now or some time in the near future be useful? If so I'm sure we could arrange this.

Cheers,

Andrew
Andrew Back (a.k.a. 9600 / carrierdetect)
Parallella Community Manager
User avatar
9600
 
Posts: 717
Joined: Mon Dec 17, 2012 3:25 am

Re: I'm working on it..

Postby glasspelican » Fri Mar 15, 2013 5:05 pm

If your up for it I'm interested in collaborating.
I have been doing research trying to figure out how to get started.
glasspelican
 
Posts: 23
Joined: Mon Dec 17, 2012 3:21 am
Location: Canada, Ontario

Re: I'm working on it..

Postby grubbymits » Fri Mar 15, 2013 6:08 pm

I was thinking about this myself, so this is good news! I'd be very willing to help out, I've been working on a different backend for my phd and would love to be able to use the epiphany instead. Any repo?
grubbymits
 
Posts: 2
Joined: Fri Mar 15, 2013 6:03 pm

Re: I'm working on it..

Postby timpart » Sat Mar 16, 2013 10:10 am

I know nothing about this compiler backend but I have been writing quite a bit of Epiphany assembler recently (mostly integer stuff) If you want to swap ideas for code sequences etc, feel free to get in touch.

Keeping the floating point system occupied with work is quite a challenge as there are noticeable pipeline delays. Ideally you need to be working on two, three or even four different calculations at once, interleaving them. In hand crafted assembler a bit of loop unrolling and interleaving would probably pay dividends (there are lots of registers to make use of).

I also wondered if it would be worthwhile where speed is more important than space to inline floating point functions - that gives more scope for interleaving with other stuff. Also avoids the call return overhead (8 cycles excluding any stack frame formation) Perhaps that is a more advanced topic, need to get basics going first.

Tim
timpart
 
Posts: 283
Joined: Mon Dec 17, 2012 3:25 am
Location: UK

Re: I'm working on it..

Postby glasspelican » Sat Mar 16, 2013 3:09 pm

One of the nice things with llvm is that you can optimize separately from the code generation.

The first stage of the compilation is translating the program code Into the llvm Intermediate Representation (IR). (front end)
IR is a well defined RISC Assembly like language.
The second stage is running the IR through several optimization passes, this could be as simple as rearranging the instructions to take advantage of the pipeline.

the final stage is the optimized IR is feed into the code generator (also called the back-end), this is where the program becomes executable.

because of the disconnected nature of the components, it is entirely possible to have a team working on the code generator, and another working on optimization.
glasspelican
 
Posts: 23
Joined: Mon Dec 17, 2012 3:21 am
Location: Canada, Ontario

Re: I'm working on it..

Postby grubbymits » Sat Mar 16, 2013 3:55 pm

It is also relatively simple to describe target pipeline latencies, and these latencies can be used by a number of, already implemented, schedulers. But as mentioned before, the basic blocks need to have enough instructions in them in the first place - but there is already a loop unroller pass. And I doubt that with computationally heavy code such as OpenCL, which has a lot of explicit data parallelism, there would be a lack of fp operations.
grubbymits
 
Posts: 2
Joined: Fri Mar 15, 2013 6:03 pm

Re: I'm working on it..

Postby Hoernchen » Tue Mar 19, 2013 7:00 pm

While I do appreciate the help offers I'm currently happy doing everything myself - after all I'm doing it for fun in my spare time, not because I get paid for it. There will be plenty of opportunity for other people to contribute as soon as I put it on github.
I do not have a board yet, and while it sure would be nice having one and being able to attach some sdr stuff to it it's not really necessary right now, after all building a backend does not depend on trial and error.
As far as the current progress is concerned, I do have an ASM writer (we already have binutils, so there is no need to mess with outputting binaries for now) and the generated code is pretty much able to match the output of gcc with "-mcmove -mno-soft-cmpsf -mshort-calls -mfp-mode=round-nearest -fomit-frame-pointer -ffast-math -O3", this combination of flags is my current target, since i'll use the backend for some SDR stuff as soon as the Parallela arrives.
Hoernchen
 
Posts: 41
Joined: Mon Dec 17, 2012 3:22 am

Re: I'm working on it..

Postby philtor » Wed May 01, 2013 1:12 am

Hoernchen : do you have a code repo for this LLVM work anywhere? A github perhaps? I'd be very interested in helping out or at least testing it.
philtor
 
Posts: 10
Joined: Mon Dec 17, 2012 3:29 am

Re: I'm working on it..

Postby Hoernchen » Sat May 04, 2013 2:19 pm

If you just want to use the backend come back later when it's finished, at the current stage it's only useful if you plan to work on it.

The good stuff lives here: https://github.com/Hoernchen
Building is pretty much straightforward, clone llvm, checkout epiphany, cd llvm/tools, clone clang, checkout epiphany, cd llvm/lib/Target, clone Epiphany
You need to use cmake, the necessary settings are -DLLVM_TARGETS_TO_BUILD="AArch64;Epiphany" -DCMAKE_BUILD_TYPE=Debug - the build needs a few gigabytes of space, so plan ahead.

I chose to base the backend on AArch64 because it is the newest backend that is "ARM-like", and the actual ARM backend is not really a good example for anything because it supports thumbv1/2, vfpv2/3, neon, and pretty much everything else there is so the code is a bit of a mess. This is why most of the code, including the comments, looks like aarch64 backend code - there is no reason to reinvent the wheel, most problems you're facing when working on a backend are far from unique, so looking at all the other existing backends makes sense.
My primary goal was to match "epiphany-elf-gcc -S -c -o - -mcmove -mno-soft-cmpsf -mshort-calls -mfp-mode=round-nearest -fomit-frame-pointer -ffast-math -O3" because I'm mostly interested in using the epiphany for stuff it is good at, which means dsp stuff involving floats. At the moment I'm still using the aarch64 clang frontend, because it "just works", although in the long run this will obviously require some work.

Using the backend works like this: clang -target aarch64--eabi -emit-llvm foobla.c -c -O3 -ffast-math -fomit-frame-pointer -o - -S -ffp-contract=fast | llc -march=epiphany

So, let's sum up what it does have:
* asm printer that is not immediately compatible with the epiphany binutils (printing of floating point constants, double reg names, ..) because this is my "debug output"
* FMA/FMSUB support
* a pass that removes unnecessary compares
* a pass that tries to combine loads and stores to double loads and stores if the alignment matches, mostly useful for stuff involving the complex floats, manually providing the alignment using __builtin_assume_aligned is necessary for this. This can be enabled with -double-ls. Code to try, provided by tnt: http://pastebin.com/A6xp01R6 and http://pastebin.com/K0RNCgzg

..and what it doesn't have:
* elf writer
* instruction encoding, because there is no elf writer
* support for the secondary integer instructions
* switching of rounding modes for float/fix
* postmodify loads and stores, this might need a pass after the double l/s combine pass
* software float compares, ieee-754 style, for proper inf/nan handling
* support for variadic functions
* a call convention that is rock solid
* -O0 breaks stuff
* target specific scheduling
* R63, because I abuse that reg as destination for compares and for some other stuff
* tail call optimizations (not particularly important)
* pretty code
* probably something else i forgot to mention

In short, expect it to break, fix it, rinse and repeat.
Last edited by Hoernchen on Tue May 14, 2013 4:18 pm, edited 2 times in total.
Hoernchen
 
Posts: 41
Joined: Mon Dec 17, 2012 3:22 am

Next

Return to LLVM Compiler

Who is online

Users browsing this forum: No registered users and 1 guest