Git Product home page Git Product logo

llvm2yul's Introduction

LLVM IR to Yul

Convertor from LLVM to Yul

Standard Library

If you want to build using LLVM frontend, please use corresponding language standard library.

Build

Install llvm

Many platfrom can't get prebuilt binary library for LLVM. So we suggested compile LLVM manually. Please refer llvm-sys documentation to build it.

Compile

export LLVM_SYS_170_PREFIX=<path-to-llvm-directory>
cargo build

Usage and Test

Use rust example. Follow these instructions to build testable LLVM IR file.

  1. Clone patine repo
git clone https://github.com/tiannian/patine
  1. Build store example
RUSTFLAGS="--emit=llvm-ir" cargo build --release --example=store
  1. Link llvm
llvm-link target/release/deps/patine_core-*.ll \
          target/release/deps/patine_std-*.ll \
          target/release/examples/store-*.ll \
          -o store.dc
llvm-dis store.dc
  1. Copy store.dc.ll to llvm2yul directory.

  2. Compile this repo.

export LLVM_SYS_170_PREFIX=<path-to-llvm-directory>
RUST_LOG=llvm2yul=debug cargo r --example=compiler

Passes Design

Compile Object

  1. Iterate object's all function.
  2. Compile function
    1. Compile Header
    2. Compile Block.
    3. Compile Termiantor
    4. Compile Body

Compile Function Header

In this step, llvm2yul will flat struct.

Compile Block

  • Compile phi instruction
  • Compile call instruction. struct will be flatten
  • Compile load
  • Compile store
  • Compile select

Compile Termiantor

  • Compile Ret
  • Compile Br
  • Compile CondBr
  • Compile Switch
  • Compile Unreachable

Compile builtin call

Replace function call into builtin

Features and TODOs

  • 64 / 32 bit with 256 align as primitive type. Primitive type use parameter and return value directly.
  • Map LLVM IR instruction to yul
    1. ExtractValue
    2. InsertValue
    3. Alloca
    4. Load
    5. Store
    6. GetElementPtr
    7. PtrToInt
    8. IntToPtr
    9. Phi
    10. Select
    11. Call
  • Map LLVM IR Type to yul
    1. Void
    2. Integer
    3. Pointer
    4. Array
    5. Struct
    6. NamedStruct
  • Map LLVM IR Constant to yul
    1. Int
    2. Null
    3. AggregateZero
    4. Struct
    5. Array
    6. GlobalReference
    7. Poison
    8. Ptr2Int
    9. Int2Ptr
  • Flatten LLVM IR Struct or Array
  • Map LLVM IR function call to yul.
    • Use FFI function to map yul builtin function.
    • allocate function as builtin function
  • Map block termiantor to control flow.
    • Ret (leave)
    • Br
    • CondBr
    • Switch (switch)
    • Unreachable (invaild)
  • Map LLVM IR funtion to yul
    • Primitive parameter type
    • Primitive return type
    • Nested struct parameter and return support.
  • Make unsupported display clearily

llvm2yul's People

Contributors

tiannian avatar

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.