Re-land [openmp] Fix warnings when building on Windows with latest MSVC or Clang...
[llvm-project.git] / llvm / test / Other / opt-bisect-helper.py
blob86c0851272e2c0cd58e6df0f7a8c9b56cb1e22ab
1 #!/usr/bin/env python
3 from __future__ import print_function
5 import os
6 import sys
7 import argparse
8 import subprocess
10 parser = argparse.ArgumentParser()
12 parser.add_argument("--start", type=int, default=0)
13 parser.add_argument("--end", type=int, default=(1 << 32))
14 parser.add_argument("--optcmd", default=("opt"))
15 parser.add_argument("--filecheckcmd", default=("FileCheck"))
16 parser.add_argument("--prefix", default=("CHECK-BISECT"))
17 parser.add_argument("--test", default=(""))
19 args = parser.parse_args()
21 start = args.start
22 end = args.end
24 opt_command = [args.optcmd, "-O2", "-opt-bisect-limit=%(count)s", "-S", args.test]
25 check_command = [args.filecheckcmd, args.test, "--check-prefix=%s" % args.prefix]
26 last = None
27 while start != end and start != end - 1:
28 count = int(round(start + (end - start) / 2))
29 cmd = [x % {"count": count} for x in opt_command]
30 print("opt: " + str(cmd))
31 opt_result = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
32 filecheck_result = subprocess.Popen(check_command, stdin=opt_result.stdout)
33 opt_result.stdout.close()
34 opt_result.stderr.close()
35 filecheck_result.wait()
36 if filecheck_result.returncode == 0:
37 start = count
38 else:
39 end = count
41 print("Last good count: %d" % start)