Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a VHDL backend for LLVM?

Tags:

LLVM is very modular and allows you to fairly easily define new backends. However most of the documentation/tutorials on creating an LLVM backend focus on adding a new processor instruction set and registers. I'm wondering what it would take to create a VHDL backend for LLVM? Are there examples of using LLVM to go from one higher level language to another?

Just to clarify: are there examples of translating LLVM IR to a higher level language instead of to an assembly language? For example: you could read in C with Clang, use LLVM to do some optimization and then write out code in another language like Java or maybe Fortran.

like image 263
aneccodeal Avatar asked Sep 08 '10 04:09

aneccodeal


People also ask

What is the backend of LLVM?

The backend of LLVM features a target-independent code generator that may create output for several types of target CPUs — including X86, PowerPC, ARM, and SPARC. The backend may also be used to generate code targeted at SPUs of the Cell processor or GPUs to support the execution of compute kernels.

What is target code in LLVM?

Code intended for a specific machine can take the form of either assembly code or binary code (usable for a JIT compiler). The backend of LLVM features a target-independent code generator that may create output for several types of target CPUs — including X86, PowerPC, ARM, and SPARC.

What is LLVM Language Reference Manual?

LLVM Language Reference Manual — a reference manual for the LLVM assembly language. The LLVM Target-Independent Code Generator — a guide to the components (classes and code generation algorithms) for translating the LLVM internal representation into machine code for a specified target.

Does LLVM work with older versions of C?

Bear in mind that LLVM changes very quickly, so some of the code shown here will not work in older/newer versions. However, the principles should roughly be the same. LLVM uses CMake to generate the build files for the build system. There are a few possible target build systems: Ninja, Makefiles, Visual Studio and XCode.


2 Answers

Yes !

There are many LLVM back-end targeting VHDL/Verilog around :

  • (open source) Legup paper
  • (commercial) Xilinx HLS
  • (online) C-to-verilog

And I know there are many others...

The interesting thing about such low-level representations as LLVM or GIMPLE (also called RTL by the the way) is that they expose static-single assignments (SSA) forms : this can be translated to hardware quite directly, as SSA can be seen as a tree of multiplexers...

like image 188
JCLL Avatar answered Nov 13 '22 18:11

JCLL


There's nothing really special about the LLVM IR. It's a standard DAG with variable arity. Decompiling LLVM IR is a lot like decompiling machine language.

You might be able to leverage some frontend optimizations such as constant folding, but that sounds pretty minor compared to the whole task.

My only experience with LLVM was writing a binary translator for a class project, from a toy CISC to a custom RISC.

I'd say, since it's the closest thing to a standard IR (well, GCC GIMPLE is a close second), see if it fits with your algorithms and style and evaluate it as one alternative.

Note that GCC also started out prioritizing portability above all, and has also accomplished a lot.

like image 26
Potatoswatter Avatar answered Nov 13 '22 20:11

Potatoswatter