Skip to content

Commit 6f4e9de

Browse files
committed
lowering: Add micro architecture lowering
1 parent 1b4371c commit 6f4e9de

File tree

12 files changed

+96
-49
lines changed

12 files changed

+96
-49
lines changed

.idea/misc.xml

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vadl/main/vadl/ast/Definition.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4365,15 +4365,16 @@ enum ProcessKind {
43654365

43664366
class MicroArchitectureDefinition extends Definition implements IdentifiableNode {
43674367
Identifier id;
4368-
IsId processor;
4368+
@Child
4369+
IsId isa;
43694370
@Child
43704371
List<Definition> definitions;
43714372
SourceLocation loc;
43724373

4373-
MicroArchitectureDefinition(Identifier id, IsId processor, List<Definition> definitions,
4374+
MicroArchitectureDefinition(Identifier id, IsId isa, List<Definition> definitions,
43744375
SourceLocation loc) {
43754376
this.id = id;
4376-
this.processor = processor;
4377+
this.isa = isa;
43774378
this.definitions = definitions;
43784379
this.loc = loc;
43794380
}
@@ -4404,7 +4405,7 @@ void prettyPrint(int indent, StringBuilder builder) {
44044405
builder.append("micro architecture ");
44054406
id.prettyPrint(0, builder);
44064407
builder.append(" implements ");
4407-
processor.prettyPrint(0, builder);
4408+
isa.prettyPrint(0, builder);
44084409
builder.append(" = {\n");
44094410
prettyPrintDefinitions(indent + 1, builder, definitions);
44104411
builder.append(prettyIndentString(indent)).append("}\n");
@@ -4420,13 +4421,13 @@ public boolean equals(Object o) {
44204421
}
44214422
MicroArchitectureDefinition that = (MicroArchitectureDefinition) o;
44224423
return Objects.equals(id, that.id)
4423-
&& Objects.equals(processor, that.processor)
4424+
&& Objects.equals(isa, that.isa)
44244425
&& Objects.equals(definitions, that.definitions);
44254426
}
44264427

44274428
@Override
44284429
public int hashCode() {
4429-
return Objects.hash(id, processor, definitions);
4430+
return Objects.hash(id, isa, definitions);
44304431
}
44314432

44324433
}

vadl/main/vadl/ast/MacroExpander.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ public Definition visit(CpuProcessDefinition definition) {
895895

896896
@Override
897897
public Definition visit(MicroArchitectureDefinition definition) {
898-
return new MicroArchitectureDefinition(definition.id, definition.processor,
898+
return new MicroArchitectureDefinition(definition.id, definition.isa,
899899
expandDefinitions(definition.definitions), copyLoc(definition.loc)
900900
).withAnnotations(expandAnnotations(definition.annotations));
901901
}

vadl/main/vadl/ast/TypeChecker.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,12 @@ public Void visit(CpuProcessDefinition definition) {
21842184

21852185
@Override
21862186
public Void visit(MicroArchitectureDefinition definition) {
2187-
throwUnimplemented(definition);
2187+
if (!(definition.isa.target() instanceof InstructionSetDefinition)) {
2188+
throw error("ISA required", definition.isa)
2189+
.locationDescription(definition.isa, "A MIA implements an ISA but this points to a %s",
2190+
requireNonNull(definition.isa.target()).getClass().getSimpleName()).build();
2191+
}
2192+
definition.definitions.forEach(this::check);
21882193
return null;
21892194
}
21902195

vadl/main/vadl/ast/ViamLowering.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,20 @@
6969
import vadl.viam.Function;
7070
import vadl.viam.Instruction;
7171
import vadl.viam.InstructionSetArchitecture;
72+
import vadl.viam.Logic;
7273
import vadl.viam.Memory;
7374
import vadl.viam.MemoryRegion;
75+
import vadl.viam.MicroArchitecture;
7476
import vadl.viam.PrintableInstruction;
7577
import vadl.viam.Procedure;
7678
import vadl.viam.Processor;
7779
import vadl.viam.PseudoInstruction;
7880
import vadl.viam.RegisterResource;
7981
import vadl.viam.RegisterTensor;
8082
import vadl.viam.Relocation;
83+
import vadl.viam.Signal;
8184
import vadl.viam.Specification;
85+
import vadl.viam.Stage;
8286
import vadl.viam.annotations.AlignmentAnnotation;
8387
import vadl.viam.asm.AsmDirectiveMapping;
8488
import vadl.viam.asm.AsmModifier;
@@ -1464,8 +1468,30 @@ public Optional<vadl.viam.Definition> visit(MemoryDefinition definition) {
14641468

14651469
@Override
14661470
public Optional<vadl.viam.Definition> visit(MicroArchitectureDefinition definition) {
1467-
throw new RuntimeException("The ViamGenerator does not support `%s` yet".formatted(
1468-
definition.getClass().getSimpleName()));
1471+
var identifier = generateIdentifier(definition.viamId, definition.identifier());
1472+
var isa = visitIsa(
1473+
(InstructionSetDefinition) requireNonNull(definition.isa.target()));
1474+
1475+
var children = definition.definitions.stream().map(this::fetch).filter(Optional::isPresent)
1476+
.map(Optional::orElseThrow).toList();
1477+
var stages = filterAndCastToInstance(children, Stage.class);
1478+
var logic = filterAndCastToInstance(children, Logic.class);
1479+
var signals = filterAndCastToInstance(children, Signal.class);
1480+
var registers = filterAndCastToInstance(children, RegisterTensor.class);
1481+
var memories = filterAndCastToInstance(children, Memory.class);
1482+
var functions = filterAndCastToInstance(children, Function.class);
1483+
1484+
return Optional.of(new MicroArchitecture(
1485+
identifier,
1486+
isa,
1487+
stages,
1488+
logic,
1489+
signals,
1490+
registers,
1491+
memories,
1492+
functions
1493+
)
1494+
);
14691495
}
14701496

14711497
@Override

vadl/main/vadl/dump/infoEnrichers/RtlEnricherCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class RtlEnricherCollection {
6565
forType(DefinitionEntity.class, (defEntity, passResults) -> {
6666
if (defEntity.origin() instanceof MicroArchitecture mia) {
6767
var mappingExt = mia.extension(MiaMapping.class);
68-
var isaExt = mia.processor().isa().extension(InstructionProgressGraphExtension.class);
68+
var isaExt = mia.isa().extension(InstructionProgressGraphExtension.class);
6969
if (mappingExt != null && isaExt != null) {
7070
var info = InfoUtils.createGraphModal(isaExt.ipg().name, isaExt.ipg().name,
7171
viz(isaExt.ipg(), mappingExt));

vadl/main/vadl/viam/MicroArchitecture.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class MicroArchitecture extends Definition {
2828

29-
private final Processor processor;
29+
private final InstructionSetArchitecture instructionSetArchitecture;
3030

3131
// Stages and Logic elements
3232
private final List<Stage> stages;
@@ -42,34 +42,39 @@ public class MicroArchitecture extends Definition {
4242
/**
4343
* Create a micro architecture definition.
4444
*
45-
* @param identifier identifier
46-
* @param processor processor definition
47-
* @param stages list of stages
48-
* @param logic list of logic elements
45+
* @param identifier identifier
46+
* @param instructionSetArchitecture processor definition
47+
* @param stages list of stages
48+
* @param logic list of logic elements
4949
*/
50-
public MicroArchitecture(Identifier identifier, Processor processor, List<Stage> stages,
50+
public MicroArchitecture(Identifier identifier,
51+
InstructionSetArchitecture instructionSetArchitecture,
52+
List<Stage> stages,
5153
List<Logic> logic) {
52-
this(identifier, processor, stages, logic, new ArrayList<>(), new ArrayList<>(),
54+
this(identifier, instructionSetArchitecture, stages, logic, new ArrayList<>(),
55+
new ArrayList<>(),
5356
new ArrayList<>(), new ArrayList<>());
5457
}
5558

5659
/**
5760
* Create a micro architecture definition.
5861
*
59-
* @param identifier identifier
60-
* @param processor processor definition
61-
* @param stages list of stages
62-
* @param logic list of logic elements
63-
* @param signals list of signals
64-
* @param registers list of registers (tensors)
65-
* @param memories list of memories
66-
* @param functions list of functions
62+
* @param identifier identifier
63+
* @param instructionSetArchitecture processor definition
64+
* @param stages list of stages
65+
* @param logic list of logic elements
66+
* @param signals list of signals
67+
* @param registers list of registers (tensors)
68+
* @param memories list of memories
69+
* @param functions list of functions
6770
*/
68-
public MicroArchitecture(Identifier identifier, Processor processor, List<Stage> stages,
71+
public MicroArchitecture(Identifier identifier,
72+
InstructionSetArchitecture instructionSetArchitecture,
73+
List<Stage> stages,
6974
List<Logic> logic, List<Signal> signals, List<RegisterTensor> registers,
7075
List<Memory> memories, List<Function> functions) {
7176
super(identifier);
72-
this.processor = processor;
77+
this.instructionSetArchitecture = instructionSetArchitecture;
7378
this.stages = stages;
7479
this.logic = logic;
7580
this.signals = signals;
@@ -85,8 +90,8 @@ public MicroArchitecture(Identifier identifier, Processor processor, List<Stage>
8590
}
8691
}
8792

88-
public Processor processor() {
89-
return processor;
93+
public InstructionSetArchitecture isa() {
94+
return instructionSetArchitecture;
9095
}
9196

9297
public List<Stage> stages() {

vadl/main/vadl/viam/passes/dummyPasses/DummyMiaPass.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public PassName getName() {
5151
return null;
5252
}
5353

54-
var mip = viam.processor().orElse(null);
54+
var isa = viam.isa().orElse(null);
5555

56-
if (mip == null) {
56+
if (isa == null) {
5757
// if there is no mip, we just do nothing
5858
return null;
5959
}
@@ -65,9 +65,9 @@ public PassName getName() {
6565

6666
viam.add(
6767
switch (dummyMia) {
68-
case single -> SingleStageDummyMia.mia(mip);
69-
case three -> ThreeStageDummyMia.mia(viam, mip);
70-
case five -> FiveStageDummyMia.mia(viam, mip);
68+
case single -> SingleStageDummyMia.mia(isa);
69+
case three -> ThreeStageDummyMia.mia(viam, isa);
70+
case five -> FiveStageDummyMia.mia(viam, isa);
7171
}
7272
);
7373

vadl/main/vadl/viam/passes/dummyPasses/FiveStageDummyMia.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import vadl.types.MicroArchitectureType;
2525
import vadl.types.Type;
2626
import vadl.viam.Identifier;
27+
import vadl.viam.InstructionSetArchitecture;
2728
import vadl.viam.Logic;
2829
import vadl.viam.Memory;
2930
import vadl.viam.MicroArchitecture;
30-
import vadl.viam.Processor;
3131
import vadl.viam.RegisterTensor;
3232
import vadl.viam.Resource;
3333
import vadl.viam.Specification;
@@ -47,12 +47,12 @@
4747
*/
4848
class FiveStageDummyMia {
4949

50-
public static MicroArchitecture mia(Specification viam, Processor mip) {
50+
public static MicroArchitecture mia(Specification viam, InstructionSetArchitecture isa) {
5151
var regFile = viam.isa().orElseThrow().registerTensors()
5252
.stream().filter(RegisterTensor::isRegisterFile).findFirst().get();
5353
var mem = viam.isa().orElseThrow().ownMemories().get(0);
54-
var pc = Objects.requireNonNull(mip.isa().pc()).registerTensor();
55-
var csr = mip.isa().registerTensors().stream()
54+
var pc = Objects.requireNonNull(isa.pc()).registerTensor();
55+
var csr = isa.registerTensors().stream()
5656
.filter(reg -> reg.simpleName().equals("CSR")).findAny().orElse(null);
5757

5858
var ident = Identifier.noLocation("MiA");
@@ -68,7 +68,7 @@ public static MicroArchitecture mia(Specification viam, Processor mip) {
6868

6969
return new MicroArchitecture(
7070
ident,
71-
mip,
71+
isa,
7272
new ArrayList<>(List.of(fetch, decode, execute, memory, writeBack)),
7373
new ArrayList<>(List.of(bypass, predict))
7474
);

vadl/main/vadl/viam/passes/dummyPasses/SingleStageDummyMia.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import vadl.types.MicroArchitectureType;
2323
import vadl.types.Type;
2424
import vadl.viam.Identifier;
25+
import vadl.viam.InstructionSetArchitecture;
2526
import vadl.viam.MicroArchitecture;
26-
import vadl.viam.Processor;
27-
import vadl.viam.Specification;
2827
import vadl.viam.Stage;
2928
import vadl.viam.StageOutput;
3029
import vadl.viam.graph.Graph;
@@ -41,14 +40,14 @@
4140
*/
4241
class SingleStageDummyMia {
4342

44-
public static MicroArchitecture mia(Processor mip) {
43+
public static MicroArchitecture mia(InstructionSetArchitecture isa) {
4544
var ident = Identifier.noLocation("MiA");
4645

4746
var issStage = iss(ident.append("ISS"));
4847

4948
return new MicroArchitecture(
5049
ident,
51-
mip,
50+
isa,
5251
new ArrayList<>(List.of(issStage)),
5352
new ArrayList<>()
5453
);

0 commit comments

Comments
 (0)