Skip to content
Snippets Groups Projects
Commit 7e34d5ea authored by Markus Lavin's avatar Markus Lavin
Browse files

[NPM] Fix bug in llvm/utils/reduce_pipeline.py

Last minute changes in https://reviews.llvm.org/D110908 unfortunately
introduced a bug wrt automatic pipeline expansion. This patch fixes that
as well as gets rid of a few redundant variables.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D113177
parent bbc213af
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,6 @@ print('The following extra args will be passed to opt: {}'.format(
extra_opt_args))
lst = pipeline.fromStr(args.passes)
passes = '-passes={}'.format(pipeline.toStr(lst))
ll_input = args.input
# Step #-1
......@@ -67,7 +66,8 @@ ll_input = args.input
if not args.dont_expand_passes:
run_args = [
args.opt_binary, '-disable-symbolication', '-disable-output',
'-print-pipeline-passes', passes, ll_input
'-print-pipeline-passes', '-passes={}'.format(pipeline.toStr(lst)),
ll_input
]
run_args.extend(extra_opt_args)
opt = subprocess.run(run_args,
......@@ -81,15 +81,15 @@ if not args.dont_expand_passes:
exit(1)
stdout = opt.stdout.decode()
stdout = stdout[:stdout.rfind('\n')]
print('Expanded pass sequence: {}'.format(stdout))
passes = '-passes={}'.format(stdout)
lst = pipeline.fromStr(stdout)
print('Expanded pass sequence: {}'.format(pipeline.toStr(lst)))
# Step #0
# Confirm that the given input, passes and options result in failure.
print('---Starting step #0---')
run_args = [
args.opt_binary, '-disable-symbolication', '-disable-output', passes,
ll_input
args.opt_binary, '-disable-symbolication', '-disable-output',
'-passes={}'.format(pipeline.toStr(lst)), ll_input
]
run_args.extend(extra_opt_args)
opt = subprocess.run(run_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
......@@ -121,22 +121,20 @@ for idx in range(pipeline.count(lst)):
if not args.dont_remove_empty_pm:
lstA = pipeline.prune(lstA)
lstB = pipeline.prune(lstB)
passesA = '-passes=' + pipeline.toStr(lstA)
passesB = '-passes=' + pipeline.toStr(lstB)
intermediate = 'intermediate-0.ll' if idx % 2 else 'intermediate-1.ll'
intermediate = tmpd.name + '/' + intermediate
run_args = [
args.opt_binary, '-disable-symbolication', '-S', '-o', intermediate,
passesA, ll_input
'-passes={}'.format(pipeline.toStr(lstA)), ll_input
]
run_args.extend(extra_opt_args)
optA = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
run_args = [
args.opt_binary, '-disable-symbolication', '-disable-output', passesB,
intermediate
args.opt_binary, '-disable-symbolication', '-disable-output',
'-passes={}'.format(pipeline.toStr(lstB)), intermediate
]
run_args.extend(extra_opt_args)
optB = subprocess.run(run_args,
......@@ -161,10 +159,9 @@ for idx in reversed(range(pipeline.count(lst))):
[lstA, lstB] = pipeline.split(lst, idx)
if not args.dont_remove_empty_pm:
lstA = pipeline.prune(lstA)
passesA = '-passes=' + pipeline.toStr(lstA)
run_args = [
args.opt_binary, '-disable-symbolication', '-disable-output', passesA,
ll_input
args.opt_binary, '-disable-symbolication', '-disable-output',
'-passes={}'.format(pipeline.toStr(lstA)), ll_input
]
run_args.extend(extra_opt_args)
optA = subprocess.run(run_args,
......@@ -188,10 +185,9 @@ while True:
candLst = pipeline.remove(lst, idx)
if not args.dont_remove_empty_pm:
candLst = pipeline.prune(candLst)
passes = '-passes=' + pipeline.toStr(candLst)
run_args = [
args.opt_binary, '-disable-symbolication', '-disable-output',
passes, ll_input
'-passes={}'.format(pipeline.toStr(candLst)), ll_input
]
run_args.extend(extra_opt_args)
opt = subprocess.run(run_args,
......
......@@ -23,9 +23,12 @@ parser.add_argument('-o', action='store', dest='output')
parser.add_argument('input')
[args, unknown_args] = parser.parse_known_args()
# Echo pipeline if '-print-pipeline-passes'.
# Expand pipeline if '-print-pipeline-passes'.
if args.print_pipeline_passes:
print(args.passes)
if args.passes == 'EXPAND_a_to_f':
print('a,b,c,d,e,f')
else:
print(args.passes)
exit(0)
# Parse '-crash-seq'.
......
......@@ -45,19 +45,32 @@ class Test(unittest.TestCase):
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="a,i"')
def test_2(self):
"""Test the '--dont-expand-passes' option."""
def test_2_0(self):
"""Test expansion of EXPAND_a_to_f (expands into 'a,b,c,d,e,f')."""
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=a,b,c,A(d,B(e,f),g),h,i',
'-crash-seq=b,d,f', '--dont-expand-passes'
'--input=/dev/null', '--passes=EXPAND_a_to_f', '-crash-seq=b,e'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="b,A(d,B(f))"')
self.assertEqual(getFinalPasses(run), '-passes="b,e"')
def test_2_1(self):
"""Test EXPAND_a_to_f and the '--dont-expand-passes' option."""
run_args = [
'./utils/reduce_pipeline.py',
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
'--input=/dev/null', '--passes=EXPAND_a_to_f',
'-crash-seq=EXPAND_a_to_f', '--dont-expand-passes'
]
run = subprocess.run(run_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.assertEqual(run.returncode, 0)
self.assertEqual(getFinalPasses(run), '-passes="EXPAND_a_to_f"')
def test_3(self):
"""Test that empty pass-managers get removed by default."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment