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

improve souper2llvm #21

Merged
merged 3 commits into from
Oct 10, 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "binaryen"]
path = binaryen
url = git://github.com/WebAssembly/binaryen.git
[submodule "wasmer"]
path = wasmer
url = https://github.com/wasmerio/wasmer
9 changes: 9 additions & 0 deletions utils/pipeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ cmake ..
cmake --build .
```

__wasmer__

```
cd wasmer
make release-llvm
```

__binaryen__

```
Expand All @@ -77,6 +84,8 @@ Python3 >= 3.6

LLVM >= 8.0

Rust (Nightly)

### Note
1. current solution for __`.opt`__ → __`.ll`__ is not so reliable
2. for reference, my env is `llv=9.0.0`, `gcc=9.2.0`, `cmake=3.15.3`
4 changes: 3 additions & 1 deletion utils/pipeline/bc2opt2ll.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def batch_opt2ll(file_names):
for file_name in file_names:
try:
result = subprocess.run(
f'python3 souper2llvm.py {file_name}.opt > {file_name}.ll',
# the former uses compiled script, the latter uses raw script
# ../../souper/build/souper2llvm ${name}.opt > ${name}.ll
f'python souper2llvm.py {file_name}.opt > {file_name}.ll',
check=True,
shell=True,
stdout=subprocess.PIPE,
Expand Down
59 changes: 38 additions & 21 deletions utils/pipeline/pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,56 @@ ext=$(echo $1 | sed 's/^.*\.//')

# export BINARYEN_DEBUG_SOUPERIFY=0

:<<EOF
if [ "${ext}" == "wast" ]; then
echo "### step1 wast2wasm \c"
../../wabt/bin/wat2wasm ${name}.wast -o ${name}.wasm
echo "### step0 wast2ll \c"
../../wasmer/target/release/wasmer run ${name}.wast --backend=llvm --disable-cache --llvm-pre-opt-ir=${name}.ll
ext='ll'
echo "okay"
fi
EOF

echo "### step2 wasm2opt \c"
../../binaryen/bin/wasm-opt ${name}.wasm --flatten --souperify-single-use > ${name}.opt
if [ "${ext}" == "wast" ]; then
echo "### step1 wast2wasm \c"
../../wabt/bin/wat2wasm ${name}.wast -o ${name}.wasm
# ../../binaryen/bin/wasm-as ${name}.wast > ${name}.wasm
ext='wasm'
echo "okay"
fi

if [ "${ext}" == "wasm" ]; then
echo "### step2 wasm2opt \c"
../../binaryen/bin/wasm-opt ${name}.wasm --flatten --souperify-single-use > ${name}.opt
../../binaryen/bin/wasm-opt ${name}.wasm --flatten --simplify-locals-nonesting --reorder-locals --souperify > ${name}.opt
ext='opt'
echo "okay"
fi

echo "### step3 opt2ll \c"
python souper2llvm.py ${name}.opt > ${name}.ll
# ../../souper/build/souper2llvm ${name}.opt > ${name}.ll # it seems not so good
echo "okay"
if [ "${ext}" == "opt" ]; then
echo "### step3 opt2ll \c"
python souper2llvm.py ${name}.opt > ${name}.ll
# ../../souper/build/souper2llvm ${name}.opt > ${name}.ll
ext='ll'
echo "okay"
fi

echo "### step4 ll2bc \c"
llvm-as ${name}.ll
echo "okay"
if [ "${ext}" == "ll" ]; then
echo "### step4 ll2bc \c"
llvm-as ${name}.ll
ext='bc'
echo "okay"
fi

echo "### step5 bc2opt2ll \c"
sh bc2opt2ll.sh ${name}.bc ../../souper/build/souper
echo "okay"
if [ "${ext}" == "bc" ]; then
echo "### step5 bc2opt2ll \c"
sh bc2opt2ll.sh ${name}.bc ../../souper/build/souper
ext='ll'
echo "okay"
fi

echo "### extra ll2s \c"
llc -march=wasm32 -filetype=asm ${name}.ll
echo "okay"
# echo "### extra ll2s \c"
# llc -march=wasm32 -filetype=asm ${name}.ll
# echo "okay"

echo "### extra ll2o \c"
llc -march=wasm32 -filetype=obj ${name}.ll
echo "okay"
# echo "### extra ll2o \c"
# llc -march=wasm32 -filetype=obj ${name}.ll
# echo "okay"
1 change: 1 addition & 0 deletions wasmer
Submodule wasmer added at 88f126