Skip to content

Commit 7e34d5e

Browse files
committed
[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
1 parent bbc213a commit 7e34d5e

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

llvm/utils/reduce_pipeline.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
extra_opt_args))
5858

5959
lst = pipeline.fromStr(args.passes)
60-
passes = '-passes={}'.format(pipeline.toStr(lst))
6160
ll_input = args.input
6261

6362
# Step #-1
@@ -67,7 +66,8 @@
6766
if not args.dont_expand_passes:
6867
run_args = [
6968
args.opt_binary, '-disable-symbolication', '-disable-output',
70-
'-print-pipeline-passes', passes, ll_input
69+
'-print-pipeline-passes', '-passes={}'.format(pipeline.toStr(lst)),
70+
ll_input
7171
]
7272
run_args.extend(extra_opt_args)
7373
opt = subprocess.run(run_args,
@@ -81,15 +81,15 @@
8181
exit(1)
8282
stdout = opt.stdout.decode()
8383
stdout = stdout[:stdout.rfind('\n')]
84-
print('Expanded pass sequence: {}'.format(stdout))
85-
passes = '-passes={}'.format(stdout)
84+
lst = pipeline.fromStr(stdout)
85+
print('Expanded pass sequence: {}'.format(pipeline.toStr(lst)))
8686

8787
# Step #0
8888
# Confirm that the given input, passes and options result in failure.
8989
print('---Starting step #0---')
9090
run_args = [
91-
args.opt_binary, '-disable-symbolication', '-disable-output', passes,
92-
ll_input
91+
args.opt_binary, '-disable-symbolication', '-disable-output',
92+
'-passes={}'.format(pipeline.toStr(lst)), ll_input
9393
]
9494
run_args.extend(extra_opt_args)
9595
opt = subprocess.run(run_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -121,22 +121,20 @@
121121
if not args.dont_remove_empty_pm:
122122
lstA = pipeline.prune(lstA)
123123
lstB = pipeline.prune(lstB)
124-
passesA = '-passes=' + pipeline.toStr(lstA)
125-
passesB = '-passes=' + pipeline.toStr(lstB)
126124

127125
intermediate = 'intermediate-0.ll' if idx % 2 else 'intermediate-1.ll'
128126
intermediate = tmpd.name + '/' + intermediate
129127
run_args = [
130128
args.opt_binary, '-disable-symbolication', '-S', '-o', intermediate,
131-
passesA, ll_input
129+
'-passes={}'.format(pipeline.toStr(lstA)), ll_input
132130
]
133131
run_args.extend(extra_opt_args)
134132
optA = subprocess.run(run_args,
135133
stdout=subprocess.PIPE,
136134
stderr=subprocess.PIPE)
137135
run_args = [
138-
args.opt_binary, '-disable-symbolication', '-disable-output', passesB,
139-
intermediate
136+
args.opt_binary, '-disable-symbolication', '-disable-output',
137+
'-passes={}'.format(pipeline.toStr(lstB)), intermediate
140138
]
141139
run_args.extend(extra_opt_args)
142140
optB = subprocess.run(run_args,
@@ -161,10 +159,9 @@
161159
[lstA, lstB] = pipeline.split(lst, idx)
162160
if not args.dont_remove_empty_pm:
163161
lstA = pipeline.prune(lstA)
164-
passesA = '-passes=' + pipeline.toStr(lstA)
165162
run_args = [
166-
args.opt_binary, '-disable-symbolication', '-disable-output', passesA,
167-
ll_input
163+
args.opt_binary, '-disable-symbolication', '-disable-output',
164+
'-passes={}'.format(pipeline.toStr(lstA)), ll_input
168165
]
169166
run_args.extend(extra_opt_args)
170167
optA = subprocess.run(run_args,
@@ -188,10 +185,9 @@
188185
candLst = pipeline.remove(lst, idx)
189186
if not args.dont_remove_empty_pm:
190187
candLst = pipeline.prune(candLst)
191-
passes = '-passes=' + pipeline.toStr(candLst)
192188
run_args = [
193189
args.opt_binary, '-disable-symbolication', '-disable-output',
194-
passes, ll_input
190+
'-passes={}'.format(pipeline.toStr(candLst)), ll_input
195191
]
196192
run_args.extend(extra_opt_args)
197193
opt = subprocess.run(run_args,

llvm/utils/reduce_pipeline_test/fake_opt.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
parser.add_argument('input')
2424
[args, unknown_args] = parser.parse_known_args()
2525

26-
# Echo pipeline if '-print-pipeline-passes'.
26+
# Expand pipeline if '-print-pipeline-passes'.
2727
if args.print_pipeline_passes:
28-
print(args.passes)
28+
if args.passes == 'EXPAND_a_to_f':
29+
print('a,b,c,d,e,f')
30+
else:
31+
print(args.passes)
2932
exit(0)
3033

3134
# Parse '-crash-seq'.

llvm/utils/reduce_pipeline_test/test.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,32 @@ def test_1(self):
4545
self.assertEqual(run.returncode, 0)
4646
self.assertEqual(getFinalPasses(run), '-passes="a,i"')
4747

48-
def test_2(self):
49-
"""Test the '--dont-expand-passes' option."""
48+
def test_2_0(self):
49+
"""Test expansion of EXPAND_a_to_f (expands into 'a,b,c,d,e,f')."""
5050
run_args = [
5151
'./utils/reduce_pipeline.py',
5252
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
53-
'--input=/dev/null', '--passes=a,b,c,A(d,B(e,f),g),h,i',
54-
'-crash-seq=b,d,f', '--dont-expand-passes'
53+
'--input=/dev/null', '--passes=EXPAND_a_to_f', '-crash-seq=b,e'
5554
]
5655
run = subprocess.run(run_args,
5756
stdout=subprocess.PIPE,
5857
stderr=subprocess.PIPE)
5958
self.assertEqual(run.returncode, 0)
60-
self.assertEqual(getFinalPasses(run), '-passes="b,A(d,B(f))"')
59+
self.assertEqual(getFinalPasses(run), '-passes="b,e"')
60+
61+
def test_2_1(self):
62+
"""Test EXPAND_a_to_f and the '--dont-expand-passes' option."""
63+
run_args = [
64+
'./utils/reduce_pipeline.py',
65+
'--opt-binary=./utils/reduce_pipeline_test/fake_opt.py',
66+
'--input=/dev/null', '--passes=EXPAND_a_to_f',
67+
'-crash-seq=EXPAND_a_to_f', '--dont-expand-passes'
68+
]
69+
run = subprocess.run(run_args,
70+
stdout=subprocess.PIPE,
71+
stderr=subprocess.PIPE)
72+
self.assertEqual(run.returncode, 0)
73+
self.assertEqual(getFinalPasses(run), '-passes="EXPAND_a_to_f"')
6174

6275
def test_3(self):
6376
"""Test that empty pass-managers get removed by default."""

0 commit comments

Comments
 (0)