Skip to content

Commit

Permalink
[FIRRTL] Copy Memory Annotations in BlackBoxMemory
Browse files Browse the repository at this point in the history
Fix BlackBoxMemory to copy annotations from the memory to the external
memory (and not the wrapper if doing wrapping).

Note: this DOES NOT copy annotations associated with the memory ports.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
  • Loading branch information
seldridge committed Oct 22, 2021
1 parent 70c361b commit f239be4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/Dialect/FIRRTL/Transforms/BlackBoxMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ static FModuleOp createWrapperModule(MemOp op,

// Create the module
builder.setInsertionPointToStart(moduleOp.getBody());
auto instanceOp =
builder.create<InstanceOp>(op.getLoc(), extModuleOp, op.name());
auto instanceOp = builder.create<InstanceOp>(
op.getLoc(), extModuleOp, op.name(), AnnotationSet(op).getArray());

// Connect the ports between the memory module and the instance of the black
// box memory module. The outer module has a single bundle representing each
Expand Down Expand Up @@ -361,7 +361,8 @@ replaceMemWithExtModule(DenseMap<MemOp, FExtModuleOp, MemOpInfo> &knownMems,

// Create an instance of the black box module
auto instanceOp =
builder.create<InstanceOp>(memOp.getLoc(), extModuleOp, memOp.name());
builder.create<InstanceOp>(memOp.getLoc(), extModuleOp, memOp.name(),
AnnotationSet(memOp).getArray());

// Create a wire for every memory port
SmallVector<Value, 2> results;
Expand Down
22 changes: 22 additions & 0 deletions test/Dialect/FIRRTL/blackbox-memory.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,25 @@ firrtl.circuit "Duplicate" {
// INLINE-NEXT: firrtl.connect %WriteMemory2_W0_mask, %32 : !firrtl.uint<1>, !firrtl.uint<1>
// INLINE-NEXT: }
// INLINE-NEXT: }

// Check that the annotation assocaited with the memory gets copied to the
// external memory. Ensure that this works correctly for both the wrapper and
// inline variants. (Specifically that the wrapper variant only copies the
// annotation onto the external memory and not the wrapper module.)
firrtl.circuit "AnnotationsMove" {
firrtl.module @AnnotationsMove() {
%r0 = firrtl.mem Undefined {
annotations = [{class = "a"}],
depth = 16 : i64,
name = "ReadMemory",
portNames = ["read0"],
readLatency = 1 : i32,
writeLatency = 1 : i32} :
!firrtl.bundle<addr: uint<4>, en: uint<1>, clk: clock, data flip: sint<8>>
}
}

// CHECK-LABEL: "AnnotationsMove"
// WRAPPER: firrtl.instance ReadMemory {annotations = [{class = "a"}]} @ReadMemory_ext
// INLINE: firrtl.instance ReadMemory {annotations = [{class = "a"}]} @ReadMemory
// CHECK-NOT: {class = "a"}

0 comments on commit f239be4

Please sign in to comment.