From 4b33f034c3f41945967e373673d44dfca63e2928 Mon Sep 17 00:00:00 2001 From: "Matthias J. Kannwischer" Date: Wed, 18 Dec 2024 15:24:02 +0800 Subject: [PATCH] Add BranchLoop type --- slothy/core/slothy.py | 13 +++- slothy/targets/arm_v7m/arch_v7m.py | 99 ++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/slothy/core/slothy.py b/slothy/core/slothy.py index d2880ded..5023ae4a 100644 --- a/slothy/core/slothy.py +++ b/slothy/core/slothy.py @@ -450,7 +450,12 @@ def fusion_loop(self, loop_lbl, forced_loop_type=None, **kwargs): pre , body, post, _, other_data, loop = \ self.arch.Loop.extract(self.source, loop_lbl, forced_loop_type=forced_loop_type) - loop_cnt = other_data['cnt'] + + if hasattr(other_data, 'cnt'): + loop_cnt = other_data['cnt'] + else: + loop_cnt = None + indentation = AsmHelper.find_indentation(body) body_ssa = SourceLine.read_multiline(loop.start(loop_cnt)) + \ @@ -472,7 +477,11 @@ def optimize_loop(self, loop_lbl, postamble_label=None, forced_loop_type=None): early, body, late, _, other_data, loop = \ self.arch.Loop.extract(self.source, loop_lbl, forced_loop_type=forced_loop_type) - loop_cnt = other_data['cnt'] + + if hasattr(other_data, 'cnt'): + loop_cnt = other_data['cnt'] + else: + loop_cnt = None # Check if the body has a dominant indentation indentation = AsmHelper.find_indentation(body) diff --git a/slothy/targets/arm_v7m/arch_v7m.py b/slothy/targets/arm_v7m/arch_v7m.py index abac28ac..56e1f4ed 100644 --- a/slothy/targets/arm_v7m/arch_v7m.py +++ b/slothy/targets/arm_v7m/arch_v7m.py @@ -297,6 +297,105 @@ def end(self, other, indentation=0): yield f'{indent}cmp {other["cnt"]}, {other["end"]}' yield f'{indent}bne {lbl_start}' + +class BranchLoop(Loop): + """ + More general loop type that just considers the branch instruction as part of the boundary. + This can help to improve performance as the instructions that belong to handling the loop can be considered by SLOTHY aswell. + + Note: This loop type is still rather experimental. It has a lot of logics inside as it needs to be able to "understand" a variety of different ways to express loops, e.g., how counters get incremented, how registers marking the end of the loop need to be modified in case of software pipelining etc. Currently, this type covers the three other types we offer above, namely `SubsLoop`, `CmpLoop`, and `VmovCmpLoop`. + + For examples, we refer to the classes `SubsLoop`, `CmpLoop`, and `VmovCmpLoop`. + """ + def __init__(self, lbl="lbl", lbl_start="1", lbl_end="2", loop_init="lr") -> None: + super().__init__(lbl_start=lbl_start, lbl_end=lbl_end, loop_init=loop_init) + self.lbl = lbl + self.lbl_regex = r"^\s*(?P