[llvm] d62cdfa - [mlgo] fixes for old python versions

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 18:09:13 PST 2023


Author: Mircea Trofin
Date: 2023-02-03T18:08:14-08:00
New Revision: d62cdfadc05436cc4ea0bb6e1875a4c621f33a14

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

LOG: [mlgo] fixes for old python versions

Added: 
    

Modified: 
    llvm/lib/Analysis/models/interactive_host.py
    llvm/lib/Analysis/models/log_reader.py

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/models/interactive_host.py b/llvm/lib/Analysis/models/interactive_host.py
index 5a14c47904e9..7b168e82fb62 100644
--- a/llvm/lib/Analysis/models/interactive_host.py
+++ b/llvm/lib/Analysis/models/interactive_host.py
@@ -63,7 +63,10 @@ def run_interactive(temp_rootname: str,
       with io.BufferedReader(io.FileIO(from_compiler, 'rb')) as fc:
         tensor_specs, _, advice_spec = log_reader.read_header(fc)
         context = None
-        while compiler_proc.poll() is None and (next_event := fc.readline()):
+        while compiler_proc.poll() is None:
+          next_event = fc.readline()
+          if not next_event:
+            break
           last_context, observation_id, features, _ = log_reader.read_one_observation(
               context, next_event, fc, tensor_specs, None)
           if last_context != context:

diff  --git a/llvm/lib/Analysis/models/log_reader.py b/llvm/lib/Analysis/models/log_reader.py
index 7278b1f5e46e..be0f218d4ae7 100644
--- a/llvm/lib/Analysis/models/log_reader.py
+++ b/llvm/lib/Analysis/models/log_reader.py
@@ -76,6 +76,7 @@ def read_tensor(fs: io.BufferedReader, ts: TensorSpec) -> TensorValue:
 def pretty_print_tensor_value(tv: TensorValue):
   print(f'{tv.spec().name}: {",".join([str(v) for v in tv])}')
 
+
 def read_header(f: io.BufferedReader):
   header = json.loads(f.readline())
   tensor_specs = [TensorSpec.from_dict(ts) for ts in header['features']]
@@ -86,10 +87,8 @@ def read_header(f: io.BufferedReader):
   return tensor_specs, score_spec, advice_spec
 
 
-def read_one_observation(context: Optional[str],
-                         event_str: str,
-                         f: io.BufferedReader,
-                         tensor_specs: List[TensorSpec],
+def read_one_observation(context: Optional[str], event_str: str,
+                         f: io.BufferedReader, tensor_specs: List[TensorSpec],
                          score_spec: Optional[TensorSpec]):
   event = json.loads(event_str)
   if 'context' in event:
@@ -113,7 +112,10 @@ def read_stream(fname: str):
   with io.BufferedReader(io.FileIO(fname, 'rb')) as f:
     tensor_specs, score_spec, _ = read_header(f)
     context = None
-    while event_str := f.readline():
+    while True:
+      event_str = f.readline()
+      if not event_str:
+        break
       context, observation_id, features, score = read_one_observation(
           context, event_str, f, tensor_specs, score_spec)
       yield context, observation_id, features, score


        


More information about the llvm-commits mailing list