xref: /llvm-project-15.0.7/llvm/utils/bisect (revision a2e270fa)
1#!/usr/bin/env python
2#
3# The way you use this is you create a script that takes in as its first
4# argument a count. The script passes into LLVM the count via a command
5# line flag that disables a pass after LLVM has run after the pass has
6# run for count number of times. Then the script invokes a test of some
7# sort and indicates whether LLVM successfully compiled the test via the
8# scripts exit status. Then you invoke bisect as follows:
9#
10# bisect --start=<start_num> --end=<end_num> ./script.sh "%(count)s"
11#
12# And bisect will continually call ./script.sh with various counts using
13# the exit status to determine success and failure.
14#
15import os
16import sys
17import argparse
18import subprocess
19
20parser = argparse.ArgumentParser()
21
22parser.add_argument('--start', type=int, default=0)
23parser.add_argument('--end', type=int, default=(1 << 32))
24parser.add_argument('command', nargs='+')
25
26args = parser.parse_args()
27
28start = args.start
29end = args.end
30
31print("Bisect Starting!")
32print("Start: %d" % start)
33print("End: %d" % end)
34
35last = None
36while start != end and start != end-1:
37    count = start + (end - start)/2
38    print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end))
39    cmd = [x % {'count':count} for x in args.command]
40    print cmd
41    result = subprocess.call(cmd)
42    if result == 0:
43        print("    PASSES! Setting start to count")
44        start = count
45    else:
46        print("    FAILS! Setting end to count")
47        end = count
48
49print("Last good count: %d" % start)
50