Skip to content

Instantly share code, notes, and snippets.

@nihalpasham
Last active November 2, 2024 02:28
Show Gist options
  • Save nihalpasham/8301c865df690f5f293d93643f2efe8b to your computer and use it in GitHub Desktop.
Save nihalpasham/8301c865df690f5f293d93643f2efe8b to your computer and use it in GitHub Desktop.
Plan for Building a Backend in Cranelift

Plan for Building a Backend in Cranelift

Steps to Add a New Backend:

  1. Create a Folder for the Backend
    • Place the new backend directory under /cranelift/codegen/src/isa, where each backend resides.
  2. Define Backend and Implement Required Traits
    • Ensure the backend implements these essential traits:
      • TargetIsa: Specifies the target architecture’s interface.
      • LowerBackend: Manages instruction lowering for the architecture.
  3. Add Core ISLE Files to the Backend Folder
    • inst.isle: Define ISA-specific instructions, encodings and registers for the target architecture using ISLE (Instruction Selection or Lowering Expressions).
    • lower.isle: Specify instruction selection and CLIF (Cranelift Intermediate Representation) to MachInst (Machine Instructions) lowering rules.
  4. Implement an ABI for the Target Architecture
    • Place the ABI implementation in the appropriate folder within the backend directory.
  5. Add ISA-Specific Settings
    • Define any required ISA-specific settings in cranelift-codegen-meta, located at:
      • /cranelift/codegen/meta/src/isa/<arch>
  6. Include Filetests for Basic Functionality
    • Add initial filetests to verify the backend’s basic functionality in:
      • /cranelift/filetests/filetests/isa/<arch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment