From b2f5dae767d78c11d9c96c30b6fd83475c02ef2d Mon Sep 17 00:00:00 2001 From: "Rojas Chaves, Jose" Date: Mon, 26 May 2025 16:21:15 +0000 Subject: [PATCH] Fix suggested bank error --- .../assembler/stages/asm_scheduler.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/assembler_tools/hec-assembler-tools/assembler/stages/asm_scheduler.py b/assembler_tools/hec-assembler-tools/assembler/stages/asm_scheduler.py index 29e38374..2f737308 100644 --- a/assembler_tools/hec-assembler-tools/assembler/stages/asm_scheduler.py +++ b/assembler_tools/hec-assembler-tools/assembler/stages/asm_scheduler.py @@ -543,6 +543,33 @@ def addDependency(self, deps_added += 1 self.addLiveVar(v.name, new_dependency_instr) # Source and dests variables are now a live-in for new_dependency_instr + def addExtraXStoreDependencies(self, original_instr, xstore_instr, new_var): + """ + Adds instructions using `new_var` as new dependencies of `xstore_instr`. + `new_var` is awaiting `xstore_instr` to get a register free. + Dependency graph and topo sort are updated as appropriate. `xstore_instr` is NOT + added to the topo_sort. + Parameters: + new_var: Variable waiting for eviction to occurr. + xstore_instr: The instruction in charge of eviction. + original_instr: The original instruction awaiting `new_var` to be ready. + """ + deps_added = 0 + for idx, next_instr_id in new_var.accessed_by_xinsts: + if idx < self.topo_start_idx + 2 * Simulation.INSTRUCTION_WINDOW_SIZE: + # Only add dependencies within the instruction window and next 2 instruction windows + if deps_added > 0 or len(new_var.accessed_by_xinsts) <= 0: + # Add, at least, one dependency if needed + break + if next_instr_id != xstore_instr.id and next_instr_id != original_instr.id: + assert next_instr_id in self.dependency_graph + self.dependency_graph.add_edge(xstore_instr.id, next_instr_id) # Link as dependency to input instruction + if self.dependency_graph.in_degree(next_instr_id) == 1: + # We need to add next instruction back to topo sort because it will have a dependency + next_instr = self.dependency_graph.nodes[next_instr_id]['instruction'] + self.addXInstrBackIntoPipeline(next_instr) + deps_added += 1 + def addLiveVar(self, var_name: str, instr): @@ -2319,6 +2346,10 @@ def prepareInstruction(original_xinstr, simulation: Simulation) -> int: if retval == 2: # XInsts needed to prepare variable + + # Add extra dependencies in case of XStore + if isinstance(new_instr_or_reg, xinst.XStore): + simulation.addExtraXStoreDependencies(original_xinstr, new_instr_or_reg, src_var) # Moves should always be able to schedule at this point assert isinstance(new_instr_or_reg, (xinst.Move, xinst.XStore))