@@ -546,6 +546,33 @@ def addDependency(self,
546546 deps_added += 1
547547 self .addLiveVar (v .name , new_dependency_instr ) # Source and dests variables are now a live-in for new_dependency_instr
548548
549+ def addExtraXStoreDependencies (self , original_instr , xstore_instr , new_var ):
550+ """
551+ Adds instructions using `new_var` as new dependencies of `xstore_instr`.
552+ `new_var` is awaiting `xstore_instr` to get a register free.
553+ Dependency graph and topo sort are updated as appropriate. `xstore_instr` is NOT
554+ added to the topo_sort.
555+ Parameters:
556+ new_var: Variable waiting for eviction to occurr.
557+ xstore_instr: The instruction in charge of eviction.
558+ original_instr: The original instruction awaiting `new_var` to be ready.
559+ """
560+ deps_added = 0
561+ for idx , next_instr_id in new_var .accessed_by_xinsts :
562+ if idx < self .topo_start_idx + 2 * Simulation .INSTRUCTION_WINDOW_SIZE :
563+ # Only add dependencies within the instruction window and next 2 instruction windows
564+ if deps_added > 0 or len (new_var .accessed_by_xinsts ) <= 0 :
565+ # Add, at least, one dependency if needed
566+ break
567+ if next_instr_id != xstore_instr .id and next_instr_id != original_instr .id :
568+ assert next_instr_id in self .dependency_graph
569+ self .dependency_graph .add_edge (xstore_instr .id , next_instr_id ) # Link as dependency to input instruction
570+ if self .dependency_graph .in_degree (next_instr_id ) == 1 :
571+ # We need to add next instruction back to topo sort because it will have a dependency
572+ next_instr = self .dependency_graph .nodes [next_instr_id ]['instruction' ]
573+ self .addXInstrBackIntoPipeline (next_instr )
574+ deps_added += 1
575+
549576 def addLiveVar (self ,
550577 var_name : str ,
551578 instr ):
@@ -2322,6 +2349,10 @@ def prepareInstruction(original_xinstr, simulation: Simulation) -> int:
23222349
23232350 if retval == 2 :
23242351 # XInsts needed to prepare variable
2352+
2353+ # Add extra dependencies in case of XStore
2354+ if isinstance (new_instr_or_reg , xinst .XStore ):
2355+ simulation .addExtraXStoreDependencies (original_xinstr , new_instr_or_reg , src_var )
23252356
23262357 # Moves should always be able to schedule at this point
23272358 assert isinstance (new_instr_or_reg , (xinst .Move , xinst .XStore ))
0 commit comments