4949import vadl .pass .PassResults ;
5050import vadl .template .Renderable ;
5151import vadl .types .BuiltInTable ;
52+ import vadl .viam .ArtificialResource ;
5253import vadl .viam .Definition ;
54+ import vadl .viam .GeneratesRegisterFileName ;
5355import vadl .viam .Instruction ;
5456import vadl .viam .PseudoInstruction ;
5557import vadl .viam .RegisterTensor ;
@@ -95,8 +97,8 @@ protected String getOutputPath() {
9597 * @param destRegisterFile is the register file for the destination register in LLVM.
9698 */
9799 record CopyPhysRegInstruction (Instruction instruction ,
98- RegisterTensor srcRegisterFile ,
99- RegisterTensor destRegisterFile ) {
100+ List < GeneratesRegisterFileName > srcRegisterFile ,
101+ List < GeneratesRegisterFileName > destRegisterFile ) {
100102 }
101103
102104 /**
@@ -121,10 +123,11 @@ record LoadRegSlot(Instruction instruction, RegisterTensor destRegisterFile, int
121123
122124 }
123125
124- private List <CopyPhysRegInstruction > getMovInstructions (
126+ private List <CopyPhysRegInstruction > physInstructions (
127+ Specification viam ,
125128 Map <MachineInstructionLabel , List <Instruction >> isaMatching ) {
126- var addi32 = mapWithInstructionLabel (MachineInstructionLabel .ADDI_32 , isaMatching );
127- var addi64 = mapWithInstructionLabel (MachineInstructionLabel .ADDI_64 , isaMatching );
129+ var addi32 = mapWithInstructionLabel (viam , MachineInstructionLabel .ADDI_32 , isaMatching );
130+ var addi64 = mapWithInstructionLabel (viam , MachineInstructionLabel .ADDI_64 , isaMatching );
128131
129132 return Stream .concat (addi32 .stream (), addi64 .stream ()).toList ();
130133 }
@@ -177,6 +180,7 @@ private List<LoadRegSlot> getLoadMemoryInstructions(
177180 }
178181
179182 private List <CopyPhysRegInstruction > mapWithInstructionLabel (
183+ Specification viam ,
180184 MachineInstructionLabel label ,
181185 Map <MachineInstructionLabel , List <Instruction >> isaMatching ) {
182186 var instructions =
@@ -189,13 +193,34 @@ private List<CopyPhysRegInstruction> mapWithInstructionLabel(
189193 .filter (HasRegisterTensor ::hasRegisterFile )
190194 .findFirst (),
191195 "There must be destination register" ).registerTensor ();
196+
197+ var destAliases = viam .isa ().get ().artificialResources ()
198+ .stream ()
199+ .filter (x -> x .aliasSlice () == null )
200+ .filter (ArtificialResource ::isRegisterFile )
201+ .filter (x -> x .innerResourceRef () == destRegisterFile )
202+ .toList ();
203+
192204 var srcRegisterFile =
193205 ensurePresent (i .behavior ().getNodes (ReadsRegisterTensor .class )
194206 .filter (HasRegisterTensor ::hasRegisterFile )
195207 .findFirst (),
196208 "There must be source register" ).registerTensor ();
197209
198- return new CopyPhysRegInstruction (i , srcRegisterFile , destRegisterFile );
210+ var srcAliases = viam .isa ().get ().artificialResources ()
211+ .stream ()
212+ .filter (x -> x .aliasSlice () == null )
213+ .filter (ArtificialResource ::isRegisterFile )
214+ .filter (x -> x .innerResourceRef () == destRegisterFile )
215+ .toList ();
216+
217+ List <GeneratesRegisterFileName > srcResult = new ArrayList <>(srcAliases );
218+ srcResult .add (srcRegisterFile );
219+
220+ List <GeneratesRegisterFileName > destResult = new ArrayList <>(destAliases );
221+ destResult .add (destRegisterFile );
222+
223+ return new CopyPhysRegInstruction (i , srcResult , destResult );
199224 })
200225 .toList ();
201226 }
@@ -337,7 +362,7 @@ protected Map<String, Object> createVariables(final PassResults passResults,
337362 var map = new HashMap <String , Object >();
338363 map .put (CommonVarNames .NAMESPACE , lcbConfiguration ().targetName ().value ().toLowerCase ());
339364 map .put ("copyPhysInstructions" ,
340- getMovInstructions ( isaMatches ).stream ().map (this ::map ).toList ());
365+ physInstructions ( specification , isaMatches ).stream ().map (this ::map ).toList ());
341366 map .put ("storeStackSlotInstructions" ,
342367 getStoreMemoryInstructions (isaMatches ).stream ().map (this ::map ).toList ());
343368 map .put ("loadStackSlotInstructions" ,
@@ -466,8 +491,10 @@ private static void machineInstructions(
466491
467492 private Map <String , Object > map (CopyPhysRegInstruction obj ) {
468493 return Map .of (
469- "destRegisterFile" , obj .destRegisterFile .simpleName (),
470- "srcRegisterFile" , obj .srcRegisterFile .simpleName (),
494+ "destRegisterFile" ,
495+ obj .destRegisterFile .stream ().map (x -> x .identifier ().simpleName ()).toList (),
496+ "srcRegisterFile" ,
497+ obj .srcRegisterFile .stream ().map (x -> x .identifier ().simpleName ()).toList (),
471498 "instruction" , obj .instruction .simpleName ()
472499 );
473500 }
0 commit comments