blob: 2150f925489b2d2324a56c826f9829376f2c1663 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// SPDX-License-Identifier: Apache-2.0
package chiselTests
import chisel3._
import chisel3.experimental.doNotDedup
import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage}
import firrtl.stage.FirrtlCircuitAnnotation
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
class MuchUsedModule extends Module {
val io = IO(new Bundle {
val in = Input(UInt(16.W))
val out = Output(UInt(16.W))
})
io.out := io.in +% 1.U
}
class UsesMuchUsedModule(addAnnos: Boolean) extends Module {
val io = IO(new Bundle {
val in = Input(UInt(16.W))
val out = Output(UInt(16.W))
})
val mod0 = Module(new MuchUsedModule)
val mod1 = Module(new MuchUsedModule)
val mod2 = Module(new MuchUsedModule)
val mod3 = Module(new MuchUsedModule)
mod0.io.in := io.in
mod1.io.in := mod0.io.out
mod2.io.in := mod1.io.out
mod3.io.in := mod2.io.out
io.out := mod3.io.out
if (addAnnos) {
doNotDedup(mod1)
doNotDedup(mod3)
}
}
class AnnotationNoDedup extends AnyFreeSpec with Matchers {
val stage = new ChiselStage
"Firrtl provides transform that reduces identical modules to a single instance" - {
"Annotations can be added which will prevent this deduplication for specific modules instances" in {
val lowFirrtl = stage
.execute(
Array("-X", "low", "--target-dir", "test_run_dir"),
Seq(ChiselGeneratorAnnotation(() => new UsesMuchUsedModule(addAnnos = true)))
)
.collectFirst {
case FirrtlCircuitAnnotation(circuit) => circuit.serialize
}
.getOrElse(fail)
lowFirrtl should include("module MuchUsedModule :")
lowFirrtl should include("module MuchUsedModule_1 :")
lowFirrtl should include("module MuchUsedModule_3 :")
(lowFirrtl should not).include("module MuchUsedModule_2 :")
(lowFirrtl should not).include("module MuchUsedModule_4 :")
}
"Turning off these annotations dedups all the occurrences" in {
val lowFirrtl = stage
.execute(
Array("-X", "low", "--target-dir", "test_run_dir"),
Seq(ChiselGeneratorAnnotation(() => new UsesMuchUsedModule(addAnnos = false)))
)
.collectFirst {
case FirrtlCircuitAnnotation(circuit) => circuit.serialize
}
.getOrElse(fail)
lowFirrtl should include("module MuchUsedModule :")
(lowFirrtl should not).include("module MuchUsedModule_1 :")
(lowFirrtl should not).include("module MuchUsedModule_3 :")
(lowFirrtl should not).include("module MuchUsedModule_2 :")
(lowFirrtl should not).include("module MuchUsedModule_4 :")
}
}
}
|