diff --git a/.buildbot.sh b/.buildbot.sh index eeedea7c8..4b3f6e70f 100644 --- a/.buildbot.sh +++ b/.buildbot.sh @@ -10,6 +10,7 @@ TRACERS="hwt swt" # - `yk-config` must be in PATH. # - YK_BUILD_TYPE must be set. test_yklua() { + return # FIXME: temporarily disable yklua to break a circular dep in CI. if [ ! -e "yklua" ]; then git clone https://github.com/ykjit/yklua fi diff --git a/bin/yk-config b/bin/yk-config index 3d0d4f7b1..8a83f602d 100755 --- a/bin/yk-config +++ b/bin/yk-config @@ -10,59 +10,16 @@ if [ ! -d "${DIR}/../ykrt" ]; then exit 1 fi -set_aot_pipeline() { - level=$1 - # env var always takes precident. - if [ ! -z "${YKB_AOT_OPTLEVEL}" ]; then - level=${YKB_AOT_OPTLEVEL} - fi - case ${level} in - 0) - POSTLINK_PASSES=${POSTLINK_PASSES_AO0} - PRELINK_PASSES=${PRELINK_PASSES_AO0} - ;; - 1) - POSTLINK_PASSES=${POSTLINK_PASSES_AO1} - PRELINK_PASSES=${PRELINK_PASSES_AO1} - ;; - *) - echo "error: invalid yk AOT optimisation level '${level}'" >&2 - exit 1 - ;; - esac -} - -# Canned pipelines. -# -# Ideally we'd detect the optimisation level from the CFLAGS env var, but it's -# not easy to reliably parse that info out of CFLAGS. So for now we allow `--ao -# ` to yk-config (or set YKB_AOT_OPTLEVEL in the env) to specify the AOT -# optimisation level. -# -# Note that clang is still passed -O0 regardless. We just add our own pipeline -# specification on top. -PRELINK_PASSES_AO0="" -POSTLINK_PASSES_AO0="instcombine" -PRELINK_PASSES_AO1="" -# The whole -O1 pipeline, as reported by `opt -O1 -print-pipeline-passes -# /dev/null`. -POSTLINK_PASSES_AO1="annotation2metadata,forceattrs,inferattrs,coro-early,function(lower-expect,simplifycfg,sroa,early-cse<>),openmp-opt,ipsccp,called-value-propagation,globalopt,function(mem2reg,instcombine,simplifycfg),require,function(invalidate),require,cgscc(devirt<4>(inline,inline,function-attrs,function(sroa,early-cse,simplifycfg,instcombine,libcalls-shrinkwrap,simplifycfg,reassociate,loop-mssa(loop-instsimplify,loop-simplifycfg,licm,loop-rotate,licm,simple-loop-unswitch),simplifycfg,instcombine,loop(loop-idiom,indvars,loop-deletion,loop-unroll-full),sroa,memcpyopt,sccp,bdce,instcombine,coro-elide,adce,simplifycfg,instcombine),function-attrs,function(require),coro-split)),deadargelim,coro-cleanup,globalopt,globaldce,elim-avail-extern,rpo-function-attrs,recompute-globalsaa,function(float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,infer-alignment,loop-load-elim,instcombine,simplifycfg,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg),globaldce,constmerge,cg-profile,rel-lookup-table-converter,function(annotation-remarks),verify" -# Initialise the AOT pipeline to level 0 unless YKB_AOT_OPTLEVEL is set. -set_aot_pipeline 0 - OUTPUT="" usage() { echo "Generate C compiler flags for building against the yk JIT.\n" echo "Usage:" - echo " yk-config [--ao <0|1>] \\" + echo " yk-config \\" echo " <--cc|--cxx|--ar|--ranlib|--cppflags|--cflags|--ldflags>\n" echo " Where is a Rust cargo profile starting with either 'debug' or 'release'.\n" echo " --cc, --cxx, --ar, --ranlib, --cppflags, --cflags and --ldflags specify " - echo " what flags to output.\n" - echo " --ao specifies the yk-specific AOT optimisation pipeline to use for flags " - echo " that follow. Defaults to 0, but (if set) the YKB_AOT_OPTLEVEL environment " - echo " variable always takes precedent." + echo " what flags to output.\n\n" } handle_arg() { @@ -77,32 +34,18 @@ handle_arg() { fi case $1 in - --ao) set_aot_pipeline $2;; --cc) OUTPUT="${ykllvm_bin_dir}/clang" ;; --cxx) OUTPUT="${ykllvm_bin_dir}/clang++" ;; --ar) OUTPUT="${ykllvm_bin_dir}/llvm-ar" ;; --ranlib) OUTPUT="${ykllvm_bin_dir}/llvm-ranlib" ;; --cflags) - # FIXME: we can only do -O0 for now. - OUTPUT="${OUTPUT} -O0" # Enable LTO. OUTPUT="${OUTPUT} -flto" # Outline functions containing loops during AOT compilation. Needed # for `yk_unroll_safe`. OUTPUT="${OUTPUT} -fyk-noinline-funcs-with-loops" - # Required so that our curated set of optimisation passes can run. - # Without this, clang will slap `optnone` attributes on every - # function, causing optimisations to skip them. - OUTPUT="${OUTPUT} -Xclang -disable-O0-optnone" - # Run these "prelink" optimisation passes. - # - # These are run on the individual pre-LTO-merged LLVM modules. - if [ ! -z "${PRELINK_PASSES}" ]; then - OUTPUT="${OUTPUT} -mllvm --newpm-passes=${PRELINK_PASSES}" - fi - case $profile in - debug*) OUTPUT="$OUTPUT -g" ;; - esac + # Don't optimise functions by changing their calling convention. + OUTPUT="${OUTPUT} -mllvm -yk-dont-opt-func-abi" ;; --cppflags) # Path to yk.h @@ -167,18 +110,11 @@ handle_arg() { if [ "${YKB_TRACER}" = "swt" ]; then OUTPUT="${OUTPUT} -Wl,--mllvm=--yk-basicblock-tracer" fi - # Add known yk-friendly optimisations. - # - # This pairs with `-Xclang -disable-O0-optnone`. See above. + # Disable backend optimisations that Yk can't handle by adding the + # `optnone` attribute onto every function after high-level IR + # optimisations have finished. OUTPUT="${OUTPUT} -Wl,--mllvm=--yk-optnone-after-ir-passes" - # Run these post-link passes. - # - # These are run on the merged LTO LLVM module. - if [ ! -z "${POSTLINK_PASSES}" ]; then - OUTPUT="${OUTPUT} -Xlinker --lto-newpm-passes=${POSTLINK_PASSES}" - fi - # Emit a basic block map section. Used for block mapping. OUTPUT="${OUTPUT} -Wl,--lto-basic-block-sections=labels" diff --git a/tests/c/aot_debuginfo.c b/tests/c/aot_debuginfo.c index 202da49c2..84723207d 100644 --- a/tests/c/aot_debuginfo.c +++ b/tests/c/aot_debuginfo.c @@ -1,4 +1,5 @@ -// ignore-if: test $YK_CARGO_PROFILE != "debug" +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 -g // Run-time: // env-var: YKD_LOG_IR=-:aot // env-var: YKD_SERIALISE_COMPILATION=1 @@ -16,6 +17,7 @@ // %{{_}}: i64 = call yk_location_new() // ... // # aot_debuginfo.c:{{_}}: int i = 4; +// ... // *%{{_}} = 4i32 // ... // # aot_debuginfo.c:{{_}}: while (i > 0) { diff --git a/tests/c/arithmetic.c b/tests/c/arithmetic.c index 20d8e9586..2bddd9460 100644 --- a/tests/c/arithmetic.c +++ b/tests/c/arithmetic.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt,jit-post-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/ashr_exact.c b/tests/c/ashr_exact.c index 2701f039a..f1eb3dd46 100644 --- a/tests/c/ashr_exact.c +++ b/tests/c/ashr_exact.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/bf.c b/tests/c/bf.c index 3c4ddf306..3bdf39b98 100644 --- a/tests/c/bf.c +++ b/tests/c/bf.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_SERIALISE_COMPILATION=1 // env-var: YK_LOG=4 diff --git a/tests/c/call_ext_simple.c b/tests/c/call_ext_simple.c index 7cb002f08..102166a3c 100644 --- a/tests/c/call_ext_simple.c +++ b/tests/c/call_ext_simple.c @@ -1,10 +1,11 @@ // Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 // stderr: // ... -// func_decl putchar (i32) -> i32 +// func_decl putc (i32, ptr) -> i32 // ... // %{{6}}: i32 = call @putc... // ... diff --git a/tests/c/double.c b/tests/c/double.c index 855493590..ef19a0a3d 100644 --- a/tests/c/double.c +++ b/tests/c/double.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/doubleinline.c b/tests/c/doubleinline.c index fd32537d7..9300d7786 100644 --- a/tests/c/doubleinline.c +++ b/tests/c/doubleinline.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/dyn_ptradd_mixed.c b/tests/c/dyn_ptradd_mixed.c index ff3781e17..aad04bab4 100644 --- a/tests/c/dyn_ptradd_mixed.c +++ b/tests/c/dyn_ptradd_mixed.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/dyn_ptradd_multidim.c b/tests/c/dyn_ptradd_multidim.c index da81060eb..a803e8473 100644 --- a/tests/c/dyn_ptradd_multidim.c +++ b/tests/c/dyn_ptradd_multidim.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 @@ -51,8 +53,8 @@ int main(int argc, char **argv) { int i = 0; NOOPT_VAL(loc); - NOOPT_VAL(i); NOOPT_VAL(array); + NOOPT_VAL(i); while (i < 4) { yk_mt_control_point(mt, &loc); fprintf(stderr, "i=%d, elem=%03d\n", i, array[i][i][i]); diff --git a/tests/c/float.c b/tests/c/float.c index 7a265f926..794d71c11 100644 --- a/tests/c/float.c +++ b/tests/c/float.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/float_binop.c b/tests/c/float_binop.c index 2fd1e934f..8e863b58b 100644 --- a/tests/c/float_binop.c +++ b/tests/c/float_binop.c @@ -1,4 +1,5 @@ -// ## yk-config-env: YKB_AOT_OPTLEVEL=1 +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/float_div.c b/tests/c/float_div.c index c424f0311..ef3ba6788 100644 --- a/tests/c/float_div.c +++ b/tests/c/float_div.c @@ -1,4 +1,5 @@ -// ## yk-config-env: YKB_AOT_OPTLEVEL=1 +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/float_mul.c b/tests/c/float_mul.c index 1c92e344c..e35bf41bb 100644 --- a/tests/c/float_mul.c +++ b/tests/c/float_mul.c @@ -1,4 +1,5 @@ -// ## yk-config-env: YKB_AOT_OPTLEVEL=1 +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/floats.c b/tests/c/floats.c index bf6896f85..2bad2b158 100644 --- a/tests/c/floats.c +++ b/tests/c/floats.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_SERIALISE_COMPILATION=1 // status: success diff --git a/tests/c/floats_return.c b/tests/c/floats_return.c index 03de13650..68aedb68e 100644 --- a/tests/c/floats_return.c +++ b/tests/c/floats_return.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/inline_const.c b/tests/c/inline_const.c index f27c1307a..ccd38f2b7 100644 --- a/tests/c/inline_const.c +++ b/tests/c/inline_const.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/inst_type_depends_global.c b/tests/c/inst_type_depends_global.c index a3fe71f11..84bfc6627 100644 --- a/tests/c/inst_type_depends_global.c +++ b/tests/c/inst_type_depends_global.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:aot // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/intrinsics.c b/tests/c/intrinsics.c index 2da761ad4..649f04af2 100644 --- a/tests/c/intrinsics.c +++ b/tests/c/intrinsics.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/phi1.c b/tests/c/phi1.c index 90378c2fd..c7376ccbb 100644 --- a/tests/c/phi1.c +++ b/tests/c/phi1.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YK_LOG=4 diff --git a/tests/c/phi2.c b/tests/c/phi2.c index 779027518..1998262d4 100644 --- a/tests/c/phi2.c +++ b/tests/c/phi2.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YK_LOG=4 diff --git a/tests/c/phi3.c b/tests/c/phi3.c index 3c7c8010a..4a38a4c11 100644 --- a/tests/c/phi3.c +++ b/tests/c/phi3.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YK_LOG=4 diff --git a/tests/c/ptradd.c b/tests/c/ptradd.c index 4a9eff589..034bff233 100644 --- a/tests/c/ptradd.c +++ b/tests/c/ptradd.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O0 -Xclang -disable-O0-optnone -Xlinker --lto-newpm-passes=instcombine // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YK_LOG=4 diff --git a/tests/c/sdiv.c b/tests/c/sdiv.c index d086c4a63..ce4cf77b7 100644 --- a/tests/c/sdiv.c +++ b/tests/c/sdiv.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/simple_inline.c b/tests/c/simple_inline.c index 6487b2f78..32c53b115 100644 --- a/tests/c/simple_inline.c +++ b/tests/c/simple_inline.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/simplecall.c b/tests/c/simplecall.c index 14e168aee..5028be923 100644 --- a/tests/c/simplecall.c +++ b/tests/c/simplecall.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot,jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 @@ -25,8 +27,8 @@ // 2 // foo // 1 -// yk-jit-event: deoptimise // bar +// yk-jit-event: deoptimise // 0 // exit diff --git a/tests/c/udiv.c b/tests/c/udiv.c index 47b260434..b65c2d8e1 100644 --- a/tests/c/udiv.c +++ b/tests/c/udiv.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:jit-pre-opt // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/tests/c/unintptr_t_to_ptr.c b/tests/c/unintptr_t_to_ptr.c index 2f5a5c9f0..8a69aa245 100644 --- a/tests/c/unintptr_t_to_ptr.c +++ b/tests/c/unintptr_t_to_ptr.c @@ -1,3 +1,5 @@ +// Compiler: +// env-var: YKB_EXTRA_CC_FLAGS=-O1 // Run-time: // env-var: YKD_LOG_IR=-:aot // env-var: YKD_SERIALISE_COMPILATION=1 diff --git a/ykbuild/completion-wrapper b/ykbuild/completion-wrapper index 0a8fb06be..365144ac7 100755 --- a/ykbuild/completion-wrapper +++ b/ykbuild/completion-wrapper @@ -2,8 +2,11 @@ # This wrapper script is used to record compiler invocations in sub-builds. # That information can then be used for e.g. code completion purposes. +# +# It is also used to allow tests to insert extra flags into the compiler +# invocation. set -e -echo "${YK_COMPILER_PATH} $@" > $(mktemp -p ${YK_COMPILER_TEMPDIR}) -${YK_COMPILER_PATH} $@ +echo "${YK_COMPILER_PATH} ${YKB_EXTRA_CC_FLAGS} $@" > $(mktemp -p ${YK_COMPILER_TEMPDIR}) +${YK_COMPILER_PATH} ${YKB_EXTRA_CC_FLAGS} $@ diff --git a/ykllvm b/ykllvm index 269ef87a0..1056ba1ca 160000 --- a/ykllvm +++ b/ykllvm @@ -1 +1 @@ -Subproject commit 269ef87a0577234e6ada8e645b3eea7404dad249 +Subproject commit 1056ba1caab5a4c49e67d7d33865c653772966e5