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

Markus Lavin via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 5 00:42:30 PDT 2021


Author: Markus Lavin
Date: 2021-11-05T08:41:39+01:00
New Revision: 7e34d5ead17563a2aa734b8adcc0fcff5373aebb

URL: https://github.com/llvm/llvm-project/commit/7e34d5ead17563a2aa734b8adcc0fcff5373aebb
DIFF: https://github.com/llvm/llvm-project/commit/7e34d5ead17563a2aa734b8adcc0fcff5373aebb.diff

LOG: [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

Added: 
    

Modified: 
    llvm/utils/reduce_pipeline.py
    llvm/utils/reduce_pipeline_test/fake_opt.py
    llvm/utils/reduce_pipeline_test/test.py

Removed: 
    


################################################################################
diff  --git a/llvm/utils/reduce_pipeline.py b/llvm/utils/reduce_pipeline.py
index 7779bb805e132..baf6b2f6930d2 100755
--- a/llvm/utils/reduce_pipeline.py
+++ b/llvm/utils/reduce_pipeline.py
@@ -57,7 +57,6 @@
     extra_opt_args))
 
 lst = pipeline.fromStr(args.passes)
-passes = '-passes={}'.format(pipeline.toStr(lst))
 ll_input = args.input
 
 # Step #-1
@@ -67,7 +66,8 @@
 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 @@
         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 @@
     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 @@
     [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 @@
         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,

diff  --git a/llvm/utils/reduce_pipeline_test/fake_opt.py b/llvm/utils/reduce_pipeline_test/fake_opt.py
index 225b6ee814329..ca661995c17fb 100755
--- a/llvm/utils/reduce_pipeline_test/fake_opt.py
+++ b/llvm/utils/reduce_pipeline_test/fake_opt.py
@@ -23,9 +23,12 @@
 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'.

diff  --git a/llvm/utils/reduce_pipeline_test/test.py b/llvm/utils/reduce_pipeline_test/test.py
index 03616fd17bdbe..170b2d4e8c6a3 100755
--- a/llvm/utils/reduce_pipeline_test/test.py
+++ b/llvm/utils/reduce_pipeline_test/test.py
@@ -45,19 +45,32 @@ def test_1(self):
         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."""


        


More information about the llvm-commits mailing list