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

Christian Clauss via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 27 14:05:29 PST 2025


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

>From 5c00c6f485f364838797cc5d70fa22e61acb936c 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] [polly] python futurize --stage1 --write

---
 polly/utils/jscop2cloog.py       | 57 ++++++++++++-----------
 polly/utils/pyscop/jscop2iscc.py | 78 ++++++++++++++++----------------
 2 files changed, 69 insertions(+), 66 deletions(-)

diff --git a/polly/utils/jscop2cloog.py b/polly/utils/jscop2cloog.py
index 29383974f26780..177327665d025b 100755
--- a/polly/utils/jscop2cloog.py
+++ b/polly/utils/jscop2cloog.py
@@ -1,33 +1,36 @@
 #!/usr/bin/env python
+from __future__ import print_function
 import argparse, os
 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
 
@@ -47,22 +50,22 @@ 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 42f4cc180f1fb9..c063fe9de3de01 100755
--- a/polly/utils/pyscop/jscop2iscc.py
+++ b/polly/utils/pyscop/jscop2iscc.py
@@ -1,68 +1,68 @@
 #!/usr/bin/env python
+from __future__ import print_function
 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 :=",
-  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 :=",
-  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 :=",
-  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 :=",
-  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__()
-



More information about the llvm-commits mailing list