Skip to content

Commit 6f6df3b

Browse files
authored
Merge pull request #469 from OpenVADL/bugfix/temp
lcb: Use aliases for register classes
2 parents 184359e + db7305a commit 6f6df3b

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

vadl/main/resources/templates/lcb/llvm/lib/Target/InstrInfo.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,19 @@ static [(${namespace})]CC::CondCode getCondFromBranchOpc(unsigned Opc) {
123123
void [(${namespace})]InstrInfo::copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, MCRegister DestReg, MCRegister SrcReg, bool KillSrc) const
124124
{
125125
[# th:each="r : ${copyPhysInstructions}" ]
126-
if ( [(${namespace})]::[(${r.destRegisterFile})]RegClass.contains( DestReg )
127-
&& [(${namespace})]::[(${r.srcRegisterFile})]RegClass.contains( SrcReg ) )
126+
if ( (
127+
[# th:each="dest,iterStat : ${r.destRegisterFile}" ]
128+
[#th:block th:if="${!iterStat.first}"] || [/th:block]
129+
[(${namespace})]::[(${dest})]RegClass.contains( DestReg )
130+
[/]
131+
)
132+
&&
133+
(
134+
[# th:each="src,iterStat : ${r.srcRegisterFile}" ]
135+
[#th:block th:if="${!iterStat.first}"] || [/th:block]
136+
[(${namespace})]::[(${src})]RegClass.contains( SrcReg )
137+
[/]
138+
))
128139
{
129140
BuildMI( MBB, MBBI, DL, get( [(${namespace})]::[(${r.instruction})] ) )
130141
.addReg( DestReg, RegState::Define )

vadl/main/vadl/lcb/template/lib/Target/EmitInstrInfoCppFilePass.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
import vadl.pass.PassResults;
5050
import vadl.template.Renderable;
5151
import vadl.types.BuiltInTable;
52+
import vadl.viam.ArtificialResource;
5253
import vadl.viam.Definition;
54+
import vadl.viam.GeneratesRegisterFileName;
5355
import vadl.viam.Instruction;
5456
import vadl.viam.PseudoInstruction;
5557
import 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

Comments
 (0)