This directory contains a script called bug_reducer. It is a reimplementation of llvm's bugpoint using a python script + high level IR utilities. This will enable bugpoint to easily be ported to newer IRs.
An example invocation would be:
./swift/utils/bug-reducer/bug_reducer.py \ opt \ --sdk=$(xcrun --sdk macosx --toolchain default --show-sdk-path) \ --module-name=${MODULE_NAME} \ --work-dir=${PWD}/bug_reducer \ --module-cache=${PWD}/bug_reducer/module-cache \ ${SWIFT_BUILD_DIR} \ ${SIB_FILE}
This is still very alpha and needs a lot of work including tests, so please do not expect it to work at all until tests are available. Once testing is available, please only use this if you are willing to tolerate bugs (and hopefully help fix them/add tests).
Imagine that I have a test case foo.swift that causes the optimizer to assert in the normal performance pipeline. I decide I want to use the bug_reducer to reduce the passes and or size of the test case. First I emit a SIB file with the performance optimizations disabled:
${SWIFTC_CMDLINE} -emit-sib -Xllvm -disable-sil-optzns -O -o ${OUTPUT}.sib
Then I invoke the bug reducer as follows:
./swift/utils/bug-reducer/bug_reducer.py \ opt \ --sdk=$(xcrun --sdk macosx --toolchain default --show-sdk-path) \ --module-name=${MODULE_NAME} \ --work-dir=${PWD}/bug_reducer \ --module-cache=${PWD}/bug_reducer/module-cache \ --reduce-sil \ ${SWIFT_BUILD_DIR} \ ${OUTPUT_SIB}
Then the bug_reducer will first attempt to reduce the passes. Then, it will attempt to reduce the test case by splitting the module and only optimizing part of it. The output will look something like:
*** Successfully Reduced file! *** Final File: ${FINAL_SIB_FILE} *** Final Functions: ${FINAL_SET_OF_FUNCTIONS} *** Repro command line: ${FULL_FINAL_REPRO_CMDLINE} *** Final Passes: ${FINAL_PASSES}
Some notes:
The final sib file produced may be different than the sib file that you inputted. This is because the bug_reducer may have:
a. Created an intermediate optimized sib file with some of the passes applied (this ensures that a module with only one pass can be provided)
b. (In a future version) Split the module into optimized and unoptimized parts to reduce the code even further.
Repro command line will be the actual final full command line used to reproduce the crasher. You should be able to copy/paste the command line directly into LLDB to reproduce. No further work is required.