Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from Souper IR to WASM #13

Merged
merged 2 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions utils/souper2wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# from Souper IR to WASM

__Souper IR → LLVM IR__
Souper's [souper-check.cpp](https://github.com/google/souper/blob/master/tools/souper-check.cpp) and [souper2llvm.in](https://github.com/google/souper/blob/master/utils/souper2llvm.in)

__LLVM IR → WASM__
`llc -mtriple=wasm32-unknown-unknown` ([blog](https://medium.com/@richardanaya/write-web-assembly-with-llvm-fbee788b2817))

## run demo
```
zsh run.sh
```

## requirements
Python >= 3.6
LLVM >= 8.0

## existing issues
- In some cases (like `demo/negate.opt`), width info can not be identified correctly
11 changes: 11 additions & 0 deletions utils/souper2wasm/demo/infer.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"


define i1 @foo(i1 %x1, i64 %x2) {
entry:
%0 = icmp ult i64 135637824071393761, %x2
%1 = or i1 %x1, %0
%2 = select i1 %1, i64 135637824071393761, i64 %x2
%3 = icmp ult i64 135637824071393761, %2
ret i1 %3
}
Binary file added utils/souper2wasm/demo/infer.o
Binary file not shown.
20 changes: 20 additions & 0 deletions utils/souper2wasm/demo/infer.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; REQUIRES: solver

; RUN: %souper-check %solver -infer-rhs -print-replacement %s > %t1
; RUN: %FileCheck %s -check-prefix=SUCCESS < %t1
; RUN: %parser-test < %t1
; RUN: %souper-check %solver < %t1 | %FileCheck -check-prefix=LGTM %s
; RUN: %souper-check %solver -infer-rhs %s > %t2
; RUN: cat %s %t2 | %souper-check %solver | %FileCheck -check-prefix=LGTM %s

; SUCCESS: RHS inferred successfully
; LGTM: LGTM

%0:i1 = var
%1:i64 = var
%2:i1 = ult 135637824071393761:i64, %1
%3:i1 = or %0, %2
%4:i64 = select %3, 135637824071393761:i64, %1
%5:i1 = ult 135637824071393761:i64, %4
infer %5

19 changes: 19 additions & 0 deletions utils/souper2wasm/demo/negate.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; REQUIRES: solver

; RUN: %souper-check %solver -print-replacement %s > %t1
; RUN: %FileCheck %s < %t1
; RUN: %parser-test < %t1
; RUN: %souper-check %solver %t1 | %FileCheck %s

; RUN: %souper-check %solver -print-replacement-split %s > %t2
; RUN: %FileCheck %s < %t2
; RUN: %parser-test < %t2
; RUN: %souper-check %solver %t2 | %FileCheck %s

; CHECK: LGTM

%0:i64 = var
%1:i64 = xor %0, -1:i64
%2:i64 = add %1, 1:i64
%3:i64 = sub 0:i64, %0
cand %2 %3
7 changes: 7 additions & 0 deletions utils/souper2wasm/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
echo "py ... \c"
python3 souper2llvm.py demo/infer.opt
echo "okay"

echo "llc ... \c"
llc -mtriple=wasm32-unknown-unknown -O3 -filetype=obj demo/infer.ll -o demo/infer.o
echo "okay"
Loading