Transpiler Question

I want to use LLVM as the main component in my compilation process. In doing so, I know I need to convert a high-level language to another language (python or a custom syntax.)

The architecture I’m targeting is non-traditional hardware: microfluidic devices. Microfluidic devices are a specific class of reconfigurable computing; which don’t necessarily adhere to a traditional Von-Neuamann architecture. What I’m aiming to do is to take my high level language and convert it a language that is accepted by one of the synthesizers we have (in python or a custom syntax) which will then simulate/execute the given program.

The workflow I have is as such:
High level language → parsed and converted to C++ → LLVM → machine code (python or custom syntax.)

I’m not 100% sure if I should write a full backend for python and our custom syntax. The documentation here: https://llvm.org/docs/WritingAnLLVMBackend.html discusses various hardware targets but nothing on software targets.

My questions are as such:

  • Is my case the correct use of LLVM?
  • Should I be writing an LLVM backend to transpile? (if not would a pass suffice?)
  • Is there any documentation that I have missed trying to target a software architecture?

Thanks.

I want to use LLVM as the main component in my compilation process. In doing so, I know I need to convert a high-level language to another language (python or a custom syntax.)

The architecture I'm targeting is non-traditional hardware: microfluidic devices. Microfluidic devices are a specific class of reconfigurable computing; which don't necessarily adhere to a traditional Von-Neuamann architecture. What I'm aiming to do is to take my high level language and convert it a language that is accepted by one of the synthesizers we have (in python or a custom syntax) which will then simulate/execute the given program.

The workflow I have is as such:
High level language -> parsed and converted to C++ -> LLVM -> machine code (python or custom syntax.)

I'm not 100% sure if I should write a full backend for python and our custom syntax. The documentation here: https://llvm.org/docs/WritingAnLLVMBackend.html discusses various hardware targets but nothing on software targets.

My questions are as such:
- Is my case the correct use of LLVM?

"Virtual" targets, which don't target any physical hardware, are pretty common. In-tree, we have WebAssembly, NVPTX, and BPF. It's hard to say more without knowing more about your target.

- Should I be writing an LLVM backend to transpile? (if not would a pass suffice?)

Using the LLVM backend infrastructure gives you a bunch of useful code like handling for types and operations which aren't natively supported by your target, calling convention handling, a register allocator (including PHI elimination), and stack frame layout. So writing a backend is probably the easiest approach unless your target IR is very similar to LLVM IR.

- Is there any documentation that I have missed trying to target a software architecture?

In practice, the "virtual" targets look pretty similar to normal hardware targets. What specifically are you looking for documentation on?

-Eli

Hello, Eli,

Thanks for the response. I did end up finding the CBackendTarget from LLVM 3.1.

Most of my uncertainity about the documentation is that I’ve read:
https://llvm.org/docs/CommandGuide/llc.html

https://llvm.org/docs/CodeGenerator.htm

https://llvm.org/docs/WritingAnLLVMBackend.html

From those, I’m still not sure if llc is as modular as opt – can I just develop off branch and run llc to load my .so and run my backend that way or do I have to develop on branch? (Effectively, I’m asking if I can develop my targets like one would develop passes.)
It only references physical targets, hence my uncertainty if LLVM was able to support the virtual targets (my intuition said yes, but there isn only one line int he “Writing an LLVM Backend” documentation that references a support for a “software target” so I wanted to make sure.) Thanks for clearing that up.

Thanks, for pointing to WebAssmebly. I briefly looked through that, but it looked as though it had all of the definitions of the Sparc or X86 targets, so I assumed it was overkill and discovered the CBackend.

Hi Jason,

I’m part of a team building a C to Rust transpiler (www.c2rust.com has a demo, links to sources, etc.) These slides cover our transpiler design: https://www.ics.uci.edu/~perl/talk/rustconf18/. The goals you describe sound somewhat different from ours, so I’m not sure how relevant our approach is to your problem but it might provide food for thought nonetheless.

Cheers,
Per