Giter VIP home page Giter VIP logo

yair's Introduction

๐Ÿฆœ yair

Actions Status Crates.io API Docs

Yet Another Intermediate Representation (pronounced Yarrrr! (like a pirate!)) is a compiler intermediate representation written entirely in Rust. Key design decisions make the representation unique:

  • Single Static Assignment representation [1].
  • No ฮฆ (phi) nodes, basic blocks take arguments instead [2].
  • Target agnostic representation for de-coupling of components.
  • Strong seperation between library components (you don't need to build, link, or use components you don't need).

TODOs

  • Core:
    • Add per-domain functions and function multi-versioning.
  • Verifier:
    • When we have per-domain functions (CPU-only for instance) check for:
      • Recursion.
      • Calling a function in a conflicting domain (call GPU from CPU).
    • Maybe restrict variables to non-any non-gpu?
      • At the least we should have some form of thread_local (shared) variables, and cpu globals too. But any else doesn't really make sense I think?
    • Check for casts to the same type as the value.
    • Check for pointers in invalid domains being inside pointers of other domains (like stack pointer being stored into CPU memory).
    • Check that blocks have correct terminating instructions (ret/br/etc).
  • Add a cranelift code generation library.
  • Add an optimizer!
  • Explain the syntax of the IR:
    • Globals and structs both use %name to differentiate them from other symbols.
  • Verify that all statements in a block are reachable from the tree of blocks above.
  • Verify that a block doesn't have any instructions after a terminator.
  • Verify that names are all valid.

Features

The following features are present in the yair crate.

io

The 'io' feature is a default feature of the yair crate. It lets you consume and produce binary or textual intermediate representation files from yair. This allows for inspection, testing, and serialization to the intermediate representation.

When this feature is enabled, two additional binaries are produced alongside the library crate - yair-as and yair-dis, allowing for assembling and disassembling of the intermediate representation between the human readable textual form, and the binary form.

Additionally, there is a yair::io module that lets users read/write the textual or binary representation into a yair Library that they can work with.

.yail Files

The human readable representation of yair are .yail files. An example file is:

mod "๐Ÿ˜€" {
  fn foo(a : i64, b : i64) : i64 {
    bar(a : i64, b : i64):
      r = or a, b
      ret r
  }
}

Constants in .yail files are slightly strange - constants as used in the Library object are unique per the value and type combination for that given constant. But in the intermediate representation, constants are treated like any other value within the body of a basic block:

mod "๐Ÿ˜€" {
  fn foo(a : i64) : i64 {
    bar(a : i64):
      b = const i64 4
      r = or a, b
      ret r
  }
}

This means that constants behave like regular SSA notes for the purposes of the intermediate representation.

References

References 1

Static single assignment form.

References 2

This approach is similar in some ways to the Swift Intermediate Language approach - Swift's High-Level IR: A Case Study of Complementing LLVM IR with Language-Specific Optimization.

yair's People

Contributors

sheredom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

5l1v3r1

yair's Issues

Function arguments provided from an array or iterator.

At the moment the FunctionBuilder only allows args to be added via with_arg(). In the io::Assembler::parse_fn() it's using a for-loop to pump args in one at a time, which feels a bit clumsy. Adding a .with_args() would be good IMO, taking a slice of pairs, or even an iterator.

I've also used the following to fold the builder, which felt more functional than a for-loop, but is still fairly inelegant:

    let func = args
        .iter()
        .fold(
            module
                .create_function(context)
                .with_attributes(attrs)
                .with_name(name)
                .with_return_type(ret_type),
            |bldr, &arg: &(&str, Type)| bldr.with_arg(arg.0, arg.1),
        )
        .build();

Library That Could Be Useful for Designing the Optimizer

Hey there! I just found this and thought it was interesting because I've been thinking about what it would look like to build essentially an LLVM replacement in Rust, not that I have the time or any compiler experience to do so. :)

Still, I found this library called egg that could be used for creating the optimizer using equality saturation. After walking through the tutorial I was so amazed by how well it seemed like it could work that I wanted to write a compiler just so I could test out the possibilities for optimization using egg.

Anyway, this is probably way pre-mature being that it doesn't look like you have code generation yet ( Edit: Oh, wait maybe you do have LLVM codegen ). Take it or leave it, but I thought the idea might be useful. ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.