1 package edu.berkeley.fleet.ir;
2 import edu.berkeley.fleet.loops.*;
6 * How do we know when a stream is done? In the case of Equalize?
10 public static final int NUM_LANES = 3;
11 public static final int FIFO_SHIP_CAPACITY = 8;
14 * A block is a set of statements which may be dispatched
15 * concurrently; no memory may be both read from and written to
16 * within a Block, each block may have at most one ReadBack, and
17 * each Block will completely finish before starting the next
20 public static class Block {
22 private int var_idx = 0;
24 public Statement[] statements;
25 public String toString() {
26 StringBuffer sb = new StringBuffer();
27 sb.append("block {\n");
28 for(int i=0; i<statements.length; i++) {
30 sb.append(statements[i].toString());
38 * Each variable is single-assignment, single-use. When
39 * compiling, each Var maps to an outbox at which the values
40 * in question will be made available.
43 private Statement assigner;
44 private Statement user;
45 public final int lane;
47 public Var() { this(0); }
48 public Var(int lane) { this.lane = lane; this.idx = var_idx++; }
49 public String toString() { return "v"+idx; }
50 public Statement getAssigner() { return assigner; }
51 public void setAssigner(Statement assigner) {
52 if (this.assigner!=null) throw new RuntimeException();
53 this.assigner = assigner;
55 public Statement getUser() { return user; }
56 public void setUser(Statement user) {
57 if (this.user!=null) throw new RuntimeException();
62 // Statements //////////////////////////////////////////////////////////////////////////////
64 public class Statement {
67 public class Literal extends Statement {
70 public Literal(Var dest, long[] vals) {
73 dest.setAssigner(this);
76 public void emitSetupInstructions() {
77 if (vals.length > FIFO_SHIP_CAPACITY) throw new RuntimeException();
78 Ship fifo = allocateShip("Fifo");
79 Dock fifo_in = fifo.getDock("in");
80 for(int i=0; i<vals.length; i++) {
83 dest.setOutbox(fifo.getDock("out"));
85 public void emitTeardownInstructions() {
91 public class ReadBack extends Statement {
93 public ReadBack(Var values) {
99 public class Fanout extends Statement {
100 public final Var[] dests;
101 public final Var source;
102 public Fanout(Var[] dests, Var source) {
104 this.source = source;
108 /** mainly used to relocate a value from one lane to another */
109 public class Move extends Statement {
110 public Move(Var dest, Var source) {
115 * Repeat the first item from val enough times to match the
116 * length of mimic. [val] MUST be a single-element stream.
118 public class Equalize extends Statement {
119 public Equalize(Var dest, Var val, Var mimic) { }
122 // technically we could "fan out" tokens instead of fanning out counts, but...
123 /** Like VRep, but for the single-column case */
124 public class Replicate extends Statement {
125 public Replicate(Var dest, Var counts, Var vals) { }
128 public class Alu extends Statement {
129 public Alu(Var dest, Var opcodes, Var in1, Var in2) { }
132 public class Lut extends Statement {
133 public Lut(Var dest, Var table, Var in1, Var in2) { }
136 public class ReadMem extends Statement {
137 public ReadMem(Var dest, long whichMem, Var addresses) { }
140 public class WriteMem extends Statement {
141 public WriteMem(long whichMem, Var addresses, Var values) { }