sampsyo / cs6120

advanced compilers
https://www.cs.cornell.edu/courses/cs6120/2023fa/
MIT License
709 stars 157 forks source link

Proposal: BRIL to RISC-V Lowering System #407

Closed jdroob closed 7 months ago

jdroob commented 9 months ago

What will you do?

We will develop a system for lowering Bril programs to RISC-V assembly code, enabling the execution of Bril programs in a RISC-V environment. We will also focus on verifying the accuracy and correctness of this lowering system.

How will you do it?

To achieve this goal, we will do the following:

  1. Familiarization: We will better acquaint ourselves with both the Bril language and the RISC-V architecture. One team member is actively working on implementing a RISC-V processor in Verilog for another course, and we feel as though we have a solid foundation in Bril. However, we will dive deeper into both before we begin implementation.

  2. Lowering Design: We will design a system for lowering Bril instructions into RISC-V assembly code. Initially, our focus will be on creating a minimum viable implementation. In this phase, we will use a 1-to-N approach, where one Bril instruction corresponds to multiple RISC-V instructions. This basic version will serve as our foundation.

  3. Optimization (Stretch Goal): If time permits, we will explore an M-to-N approach. This strategy will involve optimizing the translation by recognizing dependencies between multiple Bril instructions and generating a more efficient sequence of RISC-V instructions.

How will you empirically measure success?

We will evaluate the success of our project by assessing two key criteria:

  1. Semantic Equivalence: We will verify the correctness of our project by ensuring that the translated RISC-V code is semantically equivalent to the source Bril code. We will utilize Cranelift's ISLE domain-specific language to specify our translation rules and use Crocus to verify the correctness of these rules. It's imperative that the RISC-V code generated by our system matches that produced by Cranelift. This will be tested using rigorous benchmarks.

  2. Performance Improvement: We will assess the improvement in performance from interpreted Bril code to compiled RISC-V code in terms of execution time. We are currently researching tools to accurately measure wall clock time for comparing the two execution modes.

Team members: @20ashah

sampsyo commented 9 months ago

OK, cool! This sounds ambitious, but I think you can make it work. :smiley:

Here are a few questions I think will be important for this project's eval:

Please try to answer these questions within, say, ~1 week so we can agree on how to approach stuff here. I'm particularly interested in knowing that y'all have a RISC-V emulator up and running that you think will work for your purposes.

jdroob commented 8 months ago
sampsyo commented 8 months ago

OK, sounds good!

To be clear, if you want to try to reuse LLVM's register allocator, this has profound implications for the project: namely, you will not be generating RISC-V assembly. Your options include generating LLVM IR (which would be completely target-agnostic and not specific to RISC-V at all) or generating the LLVM MachineInstr IR (which sounds interesting but I have no idea what it would entail). I can't see a way to reuse LLVM's register allocator without reusing its code generator.

jdroob commented 7 months ago

Including a link to the project repo