Home | History | Annotate | Download | only in Other
      1 #!/usr/bin/env python
      2 
      3 import os
      4 import sys
      5 import argparse
      6 import subprocess
      7 
      8 parser = argparse.ArgumentParser()
      9 
     10 parser.add_argument('--start', type=int, default=0)
     11 parser.add_argument('--end', type=int, default=(1 << 32))
     12 parser.add_argument('--optcmd', default=("opt"))
     13 parser.add_argument('--filecheckcmd', default=("FileCheck"))
     14 parser.add_argument('--prefix', default=("CHECK-BISECT"))
     15 parser.add_argument('--test', default=(""))
     16 
     17 args = parser.parse_args()
     18 
     19 start = args.start
     20 end = args.end
     21 
     22 opt_command = [args.optcmd, "-O2", "-opt-bisect-limit=%(count)s", "-S", args.test]
     23 check_command = [args.filecheckcmd, args.test, "--check-prefix=%s" % args.prefix]
     24 last = None
     25 while start != end and start != end-1:
     26     count = int(round(start + (end - start)/2))
     27     cmd = [x % {'count':count} for x in opt_command]
     28     print("opt: " + str(cmd))
     29     opt_result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     30     filecheck_result = subprocess.Popen(check_command, stdin=opt_result.stdout)
     31     opt_result.stdout.close()
     32     opt_result.stderr.close()
     33     filecheck_result.wait()
     34     if filecheck_result.returncode == 0:
     35         start = count
     36     else:
     37         end = count
     38 
     39 print("Last good count: %d" % start)
     40