[polly] [polly] python futurize --stage1 --write (PR #124580)

Christian Clauss via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 27 09:53:32 PST 2025


https://github.com/cclauss updated https://github.com/llvm/llvm-project/pull/124580

>From 026a717ee4b97ab7d0d6cbe45026a963e436d9ca Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss at me.com>
Date: Mon, 27 Jan 2025 17:09:58 +0100
Subject: [PATCH 1/3] [polly] python futurize --stage1 --write

---
 .../imath/tests/gmp-compat-test/gendata.py    |  3 ++-
 .../External/isl/imath/tools/findthreshold.py |  9 ++++---
 polly/lib/External/isl/libisl-gdb.py          |  1 +
 polly/test/update_check.py                    |  1 +
 polly/utils/jscop2cloog.py                    |  3 ++-
 polly/utils/pyscop/jscop2iscc.py              | 25 ++++++++++---------
 6 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/polly/lib/External/isl/imath/tests/gmp-compat-test/gendata.py b/polly/lib/External/isl/imath/tests/gmp-compat-test/gendata.py
index 3ca17ff359d912..f2ff6cec380912 100644
--- a/polly/lib/External/isl/imath/tests/gmp-compat-test/gendata.py
+++ b/polly/lib/External/isl/imath/tests/gmp-compat-test/gendata.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import print_function
 import random
 import gmpapi
 
@@ -42,7 +43,7 @@ def apply(fun, lst):
 mm_all = mm_slong + mm_ulong + mm_sint + mm_uint + mm_sshort + mm_ushort
 zero_one_all = mzero_one + zero_one
 
-mpz_std_list = zero_one_all + mm_all + apply(plus1, mm_all) + apply(minus1, mm_all)
+mpz_std_list = zero_one_all + mm_all + plus1(*mm_all) + minus1(*mm_all)
 si_std_list = (
     zero_one + mm_slong + mm_sint + mm_sshort + mm_slong1 + mm_sint1 + mm_sshort1
 )
diff --git a/polly/lib/External/isl/imath/tools/findthreshold.py b/polly/lib/External/isl/imath/tools/findthreshold.py
index fbb325e1da916a..8a5b2f22646f13 100644
--- a/polly/lib/External/isl/imath/tools/findthreshold.py
+++ b/polly/lib/External/isl/imath/tools/findthreshold.py
@@ -21,6 +21,7 @@
 ## call mp_int_multiply_threshold(n) during program initialization, to
 ## establish a satisfactory result.
 ##
+from __future__ import print_function
 import math, os, random, sys, time
 
 
@@ -62,7 +63,7 @@ def compute_stats():
     check_binary('imtimer')
     seed = int(time.time())
 
-    print >> sys.stderr, "Computing timer statistics (this may take a while)"
+    print("Computing timer statistics (this may take a while)", file=sys.stderr)
     stats = {}
     for prec in (32, 40, 64, 80, 128, 150, 256, 384, 512, 600, 768, 1024):
         sys.stderr.write('%-4d ' % prec)
@@ -86,9 +87,9 @@ def compute_stats():
     stats = compute_stats()
     stats.sort(key=lambda s: s[3] / s[2])
     for prec, thresh, trec, tnorm in stats:
-        print "%d\t%d\t%.3f\t%.3f\t%.4f" % (prec, thresh, trec, tnorm,
-                                            tnorm / trec)
+        print("%d\t%d\t%.3f\t%.3f\t%.4f" % (prec, thresh, trec, tnorm,
+                                            tnorm / trec))
 
-    print
+    print()
 
 # Here there be dragons
diff --git a/polly/lib/External/isl/libisl-gdb.py b/polly/lib/External/isl/libisl-gdb.py
index bf01bc583d15d8..a3e0045364f7e0 100644
--- a/polly/lib/External/isl/libisl-gdb.py
+++ b/polly/lib/External/isl/libisl-gdb.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
 import gdb
 import re
 
diff --git a/polly/test/update_check.py b/polly/test/update_check.py
index a973c72ff4e78e..0ee10fd6f04930 100644
--- a/polly/test/update_check.py
+++ b/polly/test/update_check.py
@@ -4,6 +4,7 @@
 # Polly/LLVM update_check.py
 # Update lit FileCheck files by replacing the 'CHECK:' lines by the actual output of the 'RUN:' command.
 
+from __future__ import print_function
 import argparse
 import os
 import subprocess
diff --git a/polly/utils/jscop2cloog.py b/polly/utils/jscop2cloog.py
index 29383974f26780..10a27d5f0d2968 100755
--- a/polly/utils/jscop2cloog.py
+++ b/polly/utils/jscop2cloog.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import print_function
 import argparse, os
 import json
 
@@ -50,7 +51,7 @@ def writeCloog(scop):
   context = scop['context']
   domains = getDomains(scop)
   schedules = getSchedules(scop)
-  print template % (context, domains, schedules)
+  print(template % (context, domains, schedules))
 
 def __main__():
   description = 'Translate JSCoP into iscc input'
diff --git a/polly/utils/pyscop/jscop2iscc.py b/polly/utils/pyscop/jscop2iscc.py
index 42f4cc180f1fb9..efa481b455ce76 100755
--- a/polly/utils/pyscop/jscop2iscc.py
+++ b/polly/utils/pyscop/jscop2iscc.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+from __future__ import print_function
 import argparse, isl, os
 import json
 
@@ -9,8 +10,8 @@ def printDomain(scop):
   for statement in scop['statements']:
     domain = domain.union(isl.USet(statement['domain']))
 
-  print "D :=",
-  print str(domain) + ";"
+  print("D :=", end=' ')
+  print(str(domain) + ";")
 
 def printAccesses(scop):
 
@@ -21,8 +22,8 @@ def printAccesses(scop):
       if access['kind'] == 'read':
         read = read.union(isl.UMap(access['relation']))
 
-  print "R :=",
-  print str(read) + ";"
+  print("R :=", end=' ')
+  print(str(read) + ";")
 
   write = isl.UMap('{}')
 
@@ -31,8 +32,8 @@ def printAccesses(scop):
       if access['kind'] == 'write':
         write = write.union(isl.UMap(access['relation']))
 
-  print "W :=",
-  print str(write) + ";"
+  print("W :=", end=' ')
+  print(str(write) + ";")
 
 def printSchedule(scop):
 
@@ -41,8 +42,8 @@ def printSchedule(scop):
   for statement in scop['statements']:
     schedule = schedule.union(isl.UMap(statement['schedule']))
 
-  print "S :=",
-  print str(schedule) + ";"
+  print("S :=", end=' ')
+  print(str(schedule) + ";")
 
 def __main__():
   description = 'Translate JSCoP into iscc input'
@@ -58,10 +59,10 @@ def __main__():
   printAccesses(scop)
   printSchedule(scop)
 
-  print 'R := R * D;'
-  print 'W := W * D;'
-  print 'Dep := (last W before R under S)[0];'
-  print 'schedule D respecting Dep minimizing Dep;'
+  print('R := R * D;')
+  print('W := W * D;')
+  print('Dep := (last W before R under S)[0];')
+  print('schedule D respecting Dep minimizing Dep;')
 
 
 __main__()

>From 9a5fded179f0a51e0a07186450089564c259c402 Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss at me.com>
Date: Mon, 27 Jan 2025 18:46:13 +0100
Subject: [PATCH 2/3] Format Python code with Darker

---
 .../External/isl/imath/tools/findthreshold.py |  3 +-
 polly/utils/jscop2cloog.py                    | 53 +++++++------
 polly/utils/pyscop/jscop2iscc.py              | 77 +++++++++----------
 3 files changed, 65 insertions(+), 68 deletions(-)

diff --git a/polly/lib/External/isl/imath/tools/findthreshold.py b/polly/lib/External/isl/imath/tools/findthreshold.py
index 8a5b2f22646f13..bc08eb78c0403c 100644
--- a/polly/lib/External/isl/imath/tools/findthreshold.py
+++ b/polly/lib/External/isl/imath/tools/findthreshold.py
@@ -87,8 +87,7 @@ def compute_stats():
     stats = compute_stats()
     stats.sort(key=lambda s: s[3] / s[2])
     for prec, thresh, trec, tnorm in stats:
-        print("%d\t%d\t%.3f\t%.3f\t%.4f" % (prec, thresh, trec, tnorm,
-                                            tnorm / trec))
+        print("%d\t%d\t%.3f\t%.3f\t%.4f" % (prec, thresh, trec, tnorm, tnorm / trec))
 
     print()
 
diff --git a/polly/utils/jscop2cloog.py b/polly/utils/jscop2cloog.py
index 10a27d5f0d2968..8bdaa6b957729e 100755
--- a/polly/utils/jscop2cloog.py
+++ b/polly/utils/jscop2cloog.py
@@ -4,31 +4,31 @@
 import json
 
 def getDomains(scop):
-  statements = scop['statements'];
-  numStatements = len(statements)
+    statements = scop['statements'];
+    numStatements = len(statements)
 
-  output = "%s\n\n" % str(numStatements)
+    output = "%s\n\n" % str(numStatements)
 
-  for statement in scop['statements']:
-    output += "%s\n\n" % statement['domain']
-    output += "0  0  0               # for future options\n\n"
+    for statement in scop['statements']:
+      output += "%s\n\n" % statement['domain']
+      output += "0  0  0               # for future options\n\n"
 
+    return output
 
-  return output
 
 def getSchedules(scop):
-  statements = scop['statements'];
-  numStatements = len(statements)
+    statements = scop['statements'];
+    numStatements = len(statements)
 
-  output = "%s\n\n" % str(numStatements)
+    output = "%s\n\n" % str(numStatements)
 
-  for statement in scop['statements']:
-    output += "%s\n\n" % statement['schedule']
+    for statement in scop['statements']:
+        output += "%s\n\n" % statement['schedule']
 
-  return output
+    return output
 
 def writeCloog(scop):
-  template = """
+    template = """
 # ---------------------- CONTEXT ----------------------
 c # language is C
 
@@ -48,22 +48,21 @@ def writeCloog(scop):
 0 # We do not want to set manually the schedule dimension names
 """
 
-  context = scop['context']
-  domains = getDomains(scop)
-  schedules = getSchedules(scop)
-  print(template % (context, domains, schedules))
+    context = scop['context']
+    domains = getDomains(scop)
+    schedules = getSchedules(scop)
+    print(template % (context, domains, schedules))
 
 def __main__():
-  description = 'Translate JSCoP into iscc input'
-  parser = argparse.ArgumentParser(description)
-  parser.add_argument('inputFile', metavar='N', type=file,
-                      help='The JSCoP file')
+    description = 'Translate JSCoP into iscc input'
+    parser = argparse.ArgumentParser(description)
+    parser.add_argument('inputFile', metavar='N', type=file, help='The JSCoP file')
 
-  args = parser.parse_args()
-  inputFile = args.inputFile
-  scop = json.load(inputFile)
+    args = parser.parse_args()
+    inputFile = args.inputFile
+    scop = json.load(inputFile)
 
-  writeCloog(scop)
+    writeCloog(scop)
 
-__main__()
 
+__main__()
diff --git a/polly/utils/pyscop/jscop2iscc.py b/polly/utils/pyscop/jscop2iscc.py
index efa481b455ce76..c063fe9de3de01 100755
--- a/polly/utils/pyscop/jscop2iscc.py
+++ b/polly/utils/pyscop/jscop2iscc.py
@@ -3,67 +3,66 @@
 import argparse, isl, os
 import json
 
+
 def printDomain(scop):
+    domain = isl.USet("{}")
 
-  domain = isl.USet('{}')
+    for statement in scop["statements"]:
+        domain = domain.union(isl.USet(statement["domain"]))
 
-  for statement in scop['statements']:
-    domain = domain.union(isl.USet(statement['domain']))
+    print("D :=", end=" ")
+    print(str(domain) + ";")
 
-  print("D :=", end=' ')
-  print(str(domain) + ";")
 
 def printAccesses(scop):
+    read = isl.UMap("{}")
 
-  read = isl.UMap('{}')
+    for statement in scop["statements"]:
+        for access in statement["accesses"]:
+            if access["kind"] == "read":
+                read = read.union(isl.UMap(access["relation"]))
 
-  for statement in scop['statements']:
-    for access in statement['accesses']:
-      if access['kind'] == 'read':
-        read = read.union(isl.UMap(access['relation']))
+    print("R :=", end=" ")
+    print(str(read) + ";")
 
-  print("R :=", end=' ')
-  print(str(read) + ";")
+    write = isl.UMap("{}")
 
-  write = isl.UMap('{}')
+    for statement in scop["statements"]:
+        for access in statement["accesses"]:
+            if access["kind"] == "write":
+                write = write.union(isl.UMap(access["relation"]))
 
-  for statement in scop['statements']:
-    for access in statement['accesses']:
-      if access['kind'] == 'write':
-        write = write.union(isl.UMap(access['relation']))
+    print("W :=", end=" ")
+    print(str(write) + ";")
 
-  print("W :=", end=' ')
-  print(str(write) + ";")
 
 def printSchedule(scop):
+    schedule = isl.UMap("{}")
 
-  schedule = isl.UMap('{}')
+    for statement in scop["statements"]:
+        schedule = schedule.union(isl.UMap(statement["schedule"]))
 
-  for statement in scop['statements']:
-    schedule = schedule.union(isl.UMap(statement['schedule']))
+    print("S :=", end=" ")
+    print(str(schedule) + ";")
 
-  print("S :=", end=' ')
-  print(str(schedule) + ";")
 
 def __main__():
-  description = 'Translate JSCoP into iscc input'
-  parser = argparse.ArgumentParser(description)
-  parser.add_argument('inputFile', metavar='N', type=file,
-                      help='The JSCoP file')
+    description = "Translate JSCoP into iscc input"
+    parser = argparse.ArgumentParser(description)
+    parser.add_argument("inputFile", metavar="N", type=file, help="The JSCoP file")
 
-  args = parser.parse_args()
-  inputFile = args.inputFile
-  scop = json.load(inputFile)
+    args = parser.parse_args()
+    inputFile = args.inputFile
+    scop = json.load(inputFile)
 
-  printDomain(scop)
-  printAccesses(scop)
-  printSchedule(scop)
+    printDomain(scop)
+    printAccesses(scop)
+    printSchedule(scop)
 
-  print('R := R * D;')
-  print('W := W * D;')
-  print('Dep := (last W before R under S)[0];')
-  print('schedule D respecting Dep minimizing Dep;')
+    print("R := R * D;")
+    print("W := W * D;")
+    print("Dep := (last W before R under S)[0];")
+    print("schedule D respecting Dep minimizing Dep;")
 
 
 __main__()
-

>From e4acc5b56b2266e4028b07d4d21a5fed59d8015b Mon Sep 17 00:00:00 2001
From: Christian Clauss <cclauss at me.com>
Date: Mon, 27 Jan 2025 18:53:15 +0100
Subject: [PATCH 3/3] ruff format polly/utils/jscop2cloog.py

---
 polly/utils/jscop2cloog.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/polly/utils/jscop2cloog.py b/polly/utils/jscop2cloog.py
index 8bdaa6b957729e..177327665d025b 100755
--- a/polly/utils/jscop2cloog.py
+++ b/polly/utils/jscop2cloog.py
@@ -3,30 +3,32 @@
 import argparse, os
 import json
 
+
 def getDomains(scop):
-    statements = scop['statements'];
+    statements = scop["statements"]
     numStatements = len(statements)
 
     output = "%s\n\n" % str(numStatements)
 
-    for statement in scop['statements']:
-      output += "%s\n\n" % statement['domain']
-      output += "0  0  0               # for future options\n\n"
+    for statement in scop["statements"]:
+        output += "%s\n\n" % statement["domain"]
+        output += "0  0  0               # for future options\n\n"
 
     return output
 
 
 def getSchedules(scop):
-    statements = scop['statements'];
+    statements = scop["statements"]
     numStatements = len(statements)
 
     output = "%s\n\n" % str(numStatements)
 
-    for statement in scop['statements']:
-        output += "%s\n\n" % statement['schedule']
+    for statement in scop["statements"]:
+        output += "%s\n\n" % statement["schedule"]
 
     return output
 
+
 def writeCloog(scop):
     template = """
 # ---------------------- CONTEXT ----------------------
@@ -48,15 +50,16 @@ def writeCloog(scop):
 0 # We do not want to set manually the schedule dimension names
 """
 
-    context = scop['context']
+    context = scop["context"]
     domains = getDomains(scop)
     schedules = getSchedules(scop)
     print(template % (context, domains, schedules))
 
+
 def __main__():
-    description = 'Translate JSCoP into iscc input'
+    description = "Translate JSCoP into iscc input"
     parser = argparse.ArgumentParser(description)
-    parser.add_argument('inputFile', metavar='N', type=file, help='The JSCoP file')
+    parser.add_argument("inputFile", metavar="N", type=file, help="The JSCoP file")
 
     args = parser.parse_args()
     inputFile = args.inputFile



More information about the llvm-commits mailing list