X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=utils%2Ffindmisopt;h=88f991a634c044c63b71b499b1c860d69cac8d7a;hp=80b8006178e98390b8469459b7d8b018eb7d55a8;hb=cb6684b63b3c4c5a90e194c5719bc82690180f30;hpb=024409995684ed37250a0d6dec4956316368a42a diff --git a/utils/findmisopt b/utils/findmisopt index 80b8006178e..88f991a634c 100755 --- a/utils/findmisopt +++ b/utils/findmisopt @@ -7,24 +7,28 @@ # it from finding a problem unless the set of failing optimizations are # known and given to it on the command line. # -# Given a bytecode file that produces correct output (or return code), +# Given a bitcode file that produces correct output (or return code), # this script will run through all the optimizations passes that gccas # uses (in the same order) and will narrow down which optimizations # cause the program either generate different output or return a # different result code. When the passes have been narrowed down, -# bugpoint is invoked to further refine the problem to its origin. +# bugpoint is invoked to further refine the problem to its origin. If a +# release version of bugpoint is available it will be used, otherwise +# debug. # # Usage: # findmisopt bcfile outdir progargs [match] # # Where: # bcfile -# is the bytecode file input (the unoptimized working case) +# is the bitcode file input (the unoptimized working case) # outdir # is a directory into which intermediate results are placed # progargs # is a single argument containing all the arguments the program needs -# match +# proginput +# is a file name from which stdin should be directed +# match # if specified to any value causes the result code of the program to # be used to determine success/fail. If not specified success/fail is # determined by diffing the program's output with the non-optimized @@ -35,10 +39,24 @@ if [ "$#" -lt 3 ] ; then exit 1 fi +dir="${0%%/utils/findmisopt}" +if [ -x "$dir/Release/bin/bugpoint" ] ; then + bugpoint="$dir/Release/bin/bugpoint" +elif [ -x "$dir/Debug/bin/bugpoint" ] ; then + bugpoint="$dir/Debug/bin/bugpoint" +else + echo "findmisopt: bugpoint not found" + exit 1 +fi + bcfile="$1" outdir="$2" args="$3" -match="$4" +input="$4" +if [ ! -f "$input" ] ; then + input="/dev/null" +fi +match="$5" name=`basename $bcfile .bc` ll="$outdir/${name}.ll" s="$outdir/${name}.s" @@ -49,11 +67,18 @@ optll="$outdir/${name}.opt.ll" opts="$outdir/${name}.opt.s" optprog="$outdir/${name}.opt" optout="$outdir/${name}.opt.out" +ldflags="-lstdc++ -lm -ldl -lc" echo "Test Name: $name" echo "Unoptimized program: $prog" echo " Optimized program: $optprog" +# Define the list of optimizations to run. This comprises the same set of +# optimizations that opt -std-compile-opts and gccld run, in the same order. +opt_switches=`llvm-as < /dev/null -o - | opt -std-compile-opts -disable-output -debug-pass=Arguments 2>&1 | sed 's/Pass Arguments: //'` +all_switches="$opt_switches" +echo "Passes : $all_switches" + # Create output directory if it doesn't exist if [ -f "$outdir" ] ; then echo "$outdir is not a directory" @@ -67,12 +92,11 @@ fi # Generate the disassembly llvm-dis "$bcfile" -o "$ll" -f || exit 1 -# Generate the non-optimized program +# Generate the non-optimized program and its output llc "$bcfile" -o "$s" -f || exit 1 -gcc "$s" -o "$prog" -lstdc++ -lc -lm || exit 1 - -# Define the list of optimizations to run -all_switches="-verify -lowersetjmp -funcresolve -raiseallocs -simplifycfg -mem2reg -globalopt -globaldce -ipconstprop -deadargelim -instcombine -simplifycfg -prune-eh -inline -simplify-libcalls -argpromotion -raise -tailduplicate -simplifycfg -scalarrepl -instcombine -predsimplify -condprop -tailcallelim -simplifycfg -reassociate -licm -loop-unswitch -instcombine -indvars -loop-unroll -instcombine -load-vn -gcse -sccp -instcombine -condprop -dse -dce -simplifycfg -deadtypeelim -constmerge" +gcc "$s" -o "$prog" $ldflags || exit 1 +"$prog" $args > "$out" 2>&1 <$input +ex1=$? # Current set of switches is empty function tryit { @@ -80,10 +104,8 @@ function tryit { opt $switches_to_use "$bcfile" -o "$optbc" -f || exit llvm-dis "$optbc" -o "$optll" -f || exit llc "$optbc" -o "$opts" -f || exit - gcc "$opts" -o "$optprog" -lstdc++ -lc -lm || exit - "$prog" $args > "$out" 2>&1 - ex1=$? - "$optprog" $args > "$optout" 2>&1 + gcc "$opts" -o "$optprog" $ldflags || exit + "$optprog" $args > "$optout" 2>&1 <"$input" ex2=$? if [ -n "$match" ] ; then @@ -100,7 +122,7 @@ function tryit { echo "Diff fails with these switches:" echo $switches echo "Differences:" - diff "$out" "$optout" + diff "$out" "$optout" | head return 0; fi fi @@ -116,6 +138,15 @@ for sw in $all_switches ; do fi done +# Terminate the previous output with a newline +echo "" + +# Determine if we're done because none of the optimizations broke the program +if [ "$switches" == " $all_switches" ] ; then + echo "The program did not miscompile" + exit 0 +fi + final="" while [ ! -z "$switches" ] ; do trimmed=`echo "$switches" | sed -e 's/^ *\(-[^ ]*\).*/\1/'` @@ -138,7 +169,8 @@ if [ "$final" == " $all_switches" ] ; then exit 0 fi echo "Smallest Optimization list=$final" -bpcmd="bugpoint -run-llc --output "$out" --input /dev/null $bcfile $final --args $args" + +bpcmd="$bugpoint -run-llc -disable-loop-extraction --output "$out" --input /dev/null $bcfile $final --args $args" echo "Running: $bpcmd" $bpcmd