Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/FluxML/IRTools.jl
Mike's Little Intermediate Representation
https://github.com/FluxML/IRTools.jl
Last synced: 3 months ago
JSON representation
Mike's Little Intermediate Representation
- Host: GitHub
- URL: https://github.com/FluxML/IRTools.jl
- Owner: FluxML
- License: mit
- Created: 2018-08-25T08:44:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-08T05:06:53.000Z (6 months ago)
- Last Synced: 2024-06-11T19:18:48.117Z (5 months ago)
- Language: Julia
- Homepage:
- Size: 538 KB
- Stars: 109
- Watchers: 9
- Forks: 33
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- Vulkan-Guide - IRTools.jl
README
# IRTools
[![Build Status](https://travis-ci.org/FluxML/IRTools.jl.svg?branch=master)](https://travis-ci.org/FluxML/IRTools.jl)
[![Dev Docs](https://img.shields.io/badge/docs-dev-blue.svg)](https://fluxml.github.io/IRTools.jl/latest/)
[![Coverage](https://codecov.io/gh/FluxML/IRTools.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/FluxML/IRTools.jl)IRTools aims to provide a simple and flexible IR format, expressive enough to work with both lowered and typed Julia code, as well as external IRs. It can be used with Julia metaprogramming tools such as [Cassette](https://github.com/jrevels/Cassette.jl).
```julia
julia> using IRToolsjulia> function pow(x, n) # A simple Julia function
r = 1
while n > 0
n -= 1
r *= x
end
return r
endjulia> ir = @code_ir pow(1, 1) # Get its IR
1: (%1, %2, %3)
br 2 (%3, 1)
2: (%4, %5)
%6 = %4 > 0
br 4 unless %6
br 3
3:
%7 = %4 - 1
%8 = %5 * %2
br 2 (%7, %8)
4:
return %5julia> using IRTools: var, xcall
julia> ir[var(8)] = xcall(:+, var(5), var(2)) # Tweak it
:(%5 + %2)julia> ir
1: (%1, %2, %3)
br 2 (%3, 1)
2: (%4, %5)
%6 = %4 > 0
br 4 unless %6
br 3
3:
%7 = %4 - 1
%8 = %5 + %2
br 2 (%7, %8)
4:
return %5julia> f = IRTools.func(ir); # Turn the new IR into a lambda
julia> f(nothing, 10, 5)
51julia> @code_llvm f(nothing, 10, 5)
define i64 @"julia_##399_17438"(i64, i64) {
top:
%2 = icmp slt i64 %1, 1
%3 = mul i64 %1, %0
%4 = add i64 %3, 1
%value_phi1.lcssa = select i1 %2, i64 1, i64 %4
ret i64 %value_phi1.lcssa
}
```