[PATCH] D120716: [Dexter] Collate penalties of the same type into a single line for each

Stephen Tozer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 09:02:15 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1c8366f9f2aa: [Dexter] Collate penalties of the same type into a single line for each (authored by StephenTozer).

Changed prior to commit:
  https://reviews.llvm.org/D120716?vs=412064&id=421943#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120716/new/

https://reviews.llvm.org/D120716

Files:
  cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
  cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp


Index: cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp
===================================================================
--- cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp
+++ cross-project-tests/debuginfo-tests/dexter/feature_tests/subtools/test/address_printing.cpp
@@ -30,8 +30,8 @@
 // CHECK-NEXT: address 'x_2' (0x[[X2_VAL]])
 // CHECK-NEXT: address 'y' (0x[[Y_VAL]])
 // CHECK: misordered result:
-// CHECK-NEXT: step 4 (0x[[Y_VAL]])
-// CHECK-NEXT: step 5 (0x[[X2_VAL]])
+// CHECK-NEXT: (0x[[Y_VAL]]): step 4
+// CHECK-NEXT: (0x[[X2_VAL]]): step 5
 
 int main() {
     int *x = new int(5);
Index: cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
===================================================================
--- cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
+++ cross-project-tests/debuginfo-tests/dexter/dex/heuristic/Heuristic.py
@@ -98,6 +98,32 @@
         metavar='<int>')
 
 
+class PenaltyLineRanges:
+    def __init__(self, first_step, penalty):
+        self.ranges = [(first_step, first_step)]
+        self.penalty = penalty
+
+    def add_step(self, next_step, penalty):
+        last_range = self.ranges[-1]
+        last_step = last_range[1]
+        if (next_step == last_step + 1):
+            self.ranges[-1] = (last_range[0], next_step)
+        else:
+            self.ranges.append((next_step, next_step))
+        self.penalty += penalty
+
+    def __str__(self):
+        range_to_str = lambda r: str(r[0]) if r[0] == r[1] else f'{r[0]}-{r[1]}'
+        if self.ranges[0][0] == self.ranges[-1][1]:
+            text = f'step {self.ranges[0][0]}'
+        else:
+            step_list = ', '.join([range_to_str(r) for r in self.ranges])
+            text = f'steps [{step_list}]'
+        if self.penalty:
+            text += ' <r>[-{}]</>'.format(self.penalty)
+        return text
+
+
 class Heuristic(object):
     def __init__(self, context, steps):
         self.context = context
@@ -456,11 +482,23 @@
             for category in sorted(pen_cmd.pen_dict):
                 lines.append('    <r>{}</>:\n'.format(category))
 
+                step_value_results = {}
+                for result, penalty in pen_cmd.pen_dict[category]:
+                    if not isinstance(result, StepValueInfo):
+                        continue
+                    if result.expected_value not in step_value_results:
+                        step_value_results[result.expected_value] = PenaltyLineRanges(result.step_index, penalty)
+                    else:
+                        step_value_results[result.expected_value].add_step(result.step_index, penalty)
+
+                for value, penalty_line_range in step_value_results.items():
+                    text = f'({value}): {penalty_line_range}'
+                    total_penalty += penalty_line_range.penalty
+                    lines.append('      {}\n'.format(text))
+
                 for result, penalty in pen_cmd.pen_dict[category]:
                     if isinstance(result, StepValueInfo):
-                        text = 'step {}'.format(result.step_index)
-                        if result.expected_value:
-                            text += ' ({})'.format(result.expected_value)
+                        continue
                     else:
                         text = str(result)
                     if penalty:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120716.421943.patch
Type: text/x-patch
Size: 3457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220411/c0515a18/attachment.bin>


More information about the llvm-commits mailing list