microsoft / knossos-ksc

Compiler with automatic differentiation
Other
45 stars 10 forks source link

Prune unused defs #1020

Closed toelli-msft closed 2 years ago

toelli-msft commented 2 years ago

For example, the following only emits defs which are needed (transitively) by main () (you can also provide multiple roots):

ksc --compile-and-run \
    --ks-source-file src/runtime/prelude.ks \
    --ks-source-file test/ksc/$SOURCE.ks \
    --ks-output-file obj/test/ksc/$SOURCE.kso \
    --cpp-include prelude.h \
    --cpp-output-file obj/test/ksc/$SOURCE.cpp \
    --remove-unused --used '[main (Tuple)]' \
    --c++ g++ \
    --exe-output-file obj/test/ksc/$SOURCE.exe 2>&1 | tee /tmp/out

To get the old behaviour use all-defs

ksc --compile-and-run \
    --ks-source-file src/runtime/prelude.ks \
    --ks-source-file test/ksc/$SOURCE.ks \
    --ks-output-file obj/test/ksc/$SOURCE.kso \
    --cpp-include prelude.h \
    --cpp-output-file obj/test/ksc/$SOURCE.cpp \
    --all-defs \
    --c++ g++ \
    --exe-output-file obj/test/ksc/$SOURCE.exe 2>&1 | tee /tmp/out
toelli-msft commented 2 years ago

gmm.cpp goes from 4817 lines to 3093 lines. ex0.cpp goes from 1588 lines to 18 lines!