Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate generator behavior into phases #2274

Merged
merged 19 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefrag
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ endif
MODEL ?= TestHarness
PROJECT ?= freechips.rocketchip.system
CFG_PROJECT ?= $(PROJECT)
CONFIG ?= DefaultConfig
CONFIG ?= $(CFG_PROJECT).DefaultConfig
# TODO: For now must match rocketchip.Generator
long_name = $(PROJECT).$(CONFIG)
comma := ,
space := $() $()
splitConfigs := $(subst $(comma), ,$(CONFIG))
configBases := $(foreach config,$(splitConfigs),$(lastword $(subst ., ,$(config))))
CONFIG_STR := $(subst $(space),_,$(configBases))
long_name = $(PROJECT).$(CONFIG_STR)

VLSI_MEM_GEN ?= $(base_dir)/scripts/vlsi_mem_gen

Expand Down
4 changes: 2 additions & 2 deletions emulator/Makefrag-verilator
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ verilog = \

$(generated_dir)/%.fir $(generated_dir)/%.d: $(FIRRTL_JAR) $(chisel_srcs) $(bootrom_img)
mkdir -p $(dir $@)
cd $(base_dir) && $(SBT) "runMain $(PROJECT).Generator $(generated_dir) $(PROJECT) $(MODEL) $(CFG_PROJECT) $(CONFIG)"
cd $(base_dir) && $(SBT) "runMain $(PROJECT).Generator -td $(generated_dir) -T $(PROJECT).$(MODEL) -C $(CONFIG)"

%.v %.conf: %.fir $(FIRRTL_JAR)
mkdir -p $(dir $@)
Expand Down Expand Up @@ -69,7 +69,7 @@ VERILATOR_FLAGS := --top-module $(MODEL) \
--threads $(VERILATOR_THREADS) -Wno-UNOPTTHREADS \
-Wno-STMTDLY --x-assign unique \
-I$(vsrc) \
-O3 -CFLAGS "$(CXXFLAGS) -DVERILATOR -DTEST_HARNESS=V$(MODEL) -include $(csrc)/verilator.h -include $(generated_dir)/$(PROJECT).$(CONFIG).plusArgs"
-O3 -CFLAGS "$(CXXFLAGS) -DVERILATOR -DTEST_HARNESS=V$(MODEL) -include $(csrc)/verilator.h -include $(generated_dir)/$(long_name).plusArgs"
cppfiles = $(addprefix $(csrc)/, $(addsuffix .cc, $(CXXSRCS)))
headers = $(wildcard $(csrc)/*.h)

Expand Down
40 changes: 20 additions & 20 deletions regression/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,36 @@ endif

ifeq ($(SUITE),RocketSuiteA)
PROJECT=freechips.rocketchip.system
CONFIGS=DefaultConfig
CONFIGS=$(PROJECT).DefaultConfig
endif

ifeq ($(SUITE),RocketSuiteB)
PROJECT=freechips.rocketchip.system
CONFIGS=DefaultBufferlessConfig
CONFIGS=$(PROJECT).DefaultBufferlessConfig
endif

ifeq ($(SUITE),RocketSuiteC)
PROJECT=freechips.rocketchip.system
CONFIGS=TinyConfig
CONFIGS=$(PROJECT).TinyConfig
endif

ifeq ($(SUITE),UnittestSuite)
PROJECT=freechips.rocketchip.unittest
CONFIGS=AMBAUnitTestConfig TLSimpleUnitTestConfig TLWidthUnitTestConfig
CONFIGS=$(PROJECT).AMBAUnitTestConfig $(PROJECT).TLSimpleUnitTestConfig $(PROJECT).TLWidthUnitTestConfig
endif

ifeq ($(SUITE), JtagDtmSuite)
PROJECT=freechips.rocketchip.system

export JTAG_DTM_ENABLE_SBA ?= off
ifeq ($(JTAG_DTM_ENABLE_SBA), off)
CONFIGS_32=WithJtagDTMSystem_DefaultRV32Config
CONFIGS_64=WithJtagDTMSystem_DefaultConfig
CONFIGS_32=$(PROJECT).WithJtagDTMSystem,$(PROJECT).DefaultRV32Config
CONFIGS_64=$(PROJECT).WithJtagDTMSystem,$(PROJECT).DefaultConfig
endif

ifeq ($(JTAG_DTM_ENABLE_SBA), on)
CONFIGS_32=WithJtagDTMSystem_WithDebugSBASystem_DefaultRV32Config
CONFIGS_64=WithJtagDTMSystem_WithDebugSBASystem_DefaultConfig
CONFIGS_32=$(PROJECT).WithJtagDTMSystem,$(PROJECT).WithDebugSBASystem,$(PROJECT).DefaultRV32Config
CONFIGS_64=$(PROJECT).WithJtagDTMSystem,$(PROJECT).WithDebugSBASystem,$(PROJECT).DefaultConfig
endif

CONFIGS += $(CONFIGS_32)
Expand All @@ -89,18 +89,18 @@ endif
ifeq ($(SUITE), Miscellaneous)
PROJECT=freechips.rocketchip.system
CONFIGS=\
DefaultSmallConfig \
DualBankConfig \
DualChannelConfig \
DualChannelDualBankConfig \
RoccExampleConfig \
Edge128BitConfig \
Edge32BitConfig \
QuadChannelBenchmarkConfig \
EightChannelConfig \
DualCoreConfig \
MemPortOnlyConfig \
MMIOPortOnlyConfig
$(PROJECT).DefaultSmallConfig \
$(PROJECT).DualBankConfig \
$(PROJECT).DualChannelConfig \
$(PROJECT).DualChannelDualBankConfig \
$(PROJECT).RoccExampleConfig \
$(PROJECT).Edge128BitConfig \
$(PROJECT).Edge32BitConfig \
$(PROJECT).QuadChannelBenchmarkConfig \
$(PROJECT).EightChannelConfig \
$(PROJECT).DualCoreConfig \
$(PROJECT).MemPortOnlyConfig \
$(PROJECT).MMIOPortOnlyConfig
endif

# These are the named regression targets. While it's expected you run them in
Expand Down
10 changes: 3 additions & 7 deletions src/main/scala/groundtest/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

package freechips.rocketchip.groundtest

import freechips.rocketchip.util.GeneratorApp
import firrtl.options.StageMain
import freechips.rocketchip.system.RocketChipStage

object Generator extends GeneratorApp {
generateFirrtl
generateAnno
generateTestSuiteMakefrags // TODO: Needed only for legacy make targets
generateArtefacts
}
object Generator extends StageMain(new RocketChipStage)
49 changes: 49 additions & 0 deletions src/main/scala/stage/RocketChipAnnotations.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip.stage

import chisel3.experimental.BaseModule
import firrtl.annotations.{Annotation, NoTargetAnnotation}
import firrtl.options.{HasShellOptions, ShellOption, Unserializable}

sealed trait RocketChipOption extends Unserializable { this: Annotation => }

/* required options */

case class TopModuleAnnotation(clazz: Class[_ <: Any]) extends NoTargetAnnotation with RocketChipOption
private[stage] object TopModuleAnnotation extends HasShellOptions {
override val options = Seq(
new ShellOption[String](
longOption = "top-module",
toAnnotationSeq = a => Seq(TopModuleAnnotation(Class.forName(a).asInstanceOf[Class[_ <: BaseModule]])),
helpText = "<top module>",
shortOption = Some("T")
)
)
}

case class ConfigsAnnotation(configNames: Seq[String]) extends NoTargetAnnotation with RocketChipOption
private[stage] object ConfigsAnnotation extends HasShellOptions {
override val options = Seq(
new ShellOption[Seq[String]](
longOption = "configs",
toAnnotationSeq = a => Seq(ConfigsAnnotation(a)),
helpText = "<comma-delimited configs>",
shortOption = Some("C")
)
)
}

/* optional options */

case class OutputBaseNameAnnotation(outputBaseName: String) extends NoTargetAnnotation with RocketChipOption
private[stage] object OutputBaseNameAnnotation extends HasShellOptions {
override val options = Seq(
new ShellOption[String](
longOption = "name",
toAnnotationSeq = a => Seq(OutputBaseNameAnnotation(a)),
helpText = "<base name of output files>",
shortOption = Some("n")
)
)
}
17 changes: 17 additions & 0 deletions src/main/scala/stage/RocketChipCli.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip.stage

import firrtl.options.Shell

trait RocketChipCli { this: Shell =>

parser.note("Rocket Chip Compiler Options")
Seq(
TopModuleAnnotation,
ConfigsAnnotation,
OutputBaseNameAnnotation,
)
.foreach(_.addOptions(parser))

}
37 changes: 37 additions & 0 deletions src/main/scala/stage/RocketChipOptions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip.stage

class RocketChipOptions private[stage] (
val topModule: Option[Class[_ <: Any]] = None,
val configNames: Option[Seq[String]] = None,
val outputBaseName: Option[String] = None) {

private[stage] def copy(
topModule: Option[Class[_ <: Any]] = topModule,
configNames: Option[Seq[String]] = configNames,
outputBaseName: Option[String] = outputBaseName,
): RocketChipOptions = {

new RocketChipOptions(
topModule=topModule,
configNames=configNames,
outputBaseName=outputBaseName,
)
}

lazy val topPackage: Option[String] = topModule match {
case Some(a) => Some(a.getPackage.getName)
case _ => None
}

lazy val configClass: Option[String] = configNames match {
case Some(names) =>
val classNames = names.map{ n => n.split('.').last }
Some(classNames.mkString("_"))
case _ => None
}

lazy val longName: String = outputBaseName.getOrElse(s"${topPackage.get}.${configClass.get}")
debs-sifive marked this conversation as resolved.
Show resolved Hide resolved
}

24 changes: 24 additions & 0 deletions src/main/scala/stage/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip

import firrtl.AnnotationSeq
import firrtl.options.OptionsView

package object stage {

implicit object RocketChipOptionsView extends OptionsView[RocketChipOptions] {

def view(annotations: AnnotationSeq): RocketChipOptions = annotations
.collect { case a: RocketChipOption => a }
.foldLeft(new RocketChipOptions()){ (c, x) =>
x match {
case TopModuleAnnotation(a) => c.copy(topModule = Some(a))
case ConfigsAnnotation(a) => c.copy(configNames = Some(a))
case OutputBaseNameAnnotation(a) => c.copy(outputBaseName = Some(a))
}
}

}

}
140 changes: 140 additions & 0 deletions src/main/scala/stage/phases/AddDefaultTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// See LICENSE.SiFive for license details.

package freechips.rocketchip.stage.phases


import chipsalliance.rocketchip.config.Parameters
import chisel3.stage.phases.Elaborate
import firrtl.AnnotationSeq
import firrtl.annotations.NoTargetAnnotation
import firrtl.options.{Phase, PreservesAll}
import firrtl.options.Viewer.view
import freechips.rocketchip.stage.RocketChipOptions
import freechips.rocketchip.subsystem.RocketTilesKey
import freechips.rocketchip.system.{DefaultTestSuites, RegressionTestSuite, RocketTestSuite, TestGeneration}
import freechips.rocketchip.tile.XLen
import freechips.rocketchip.util.HasRocketChipStageUtils
import freechips.rocketchip.system.DefaultTestSuites._

import scala.collection.mutable

/** Annotation that contains a list of [[RocketTestSuite]]s to run */
case class RocketTestSuiteAnnotation(tests: Seq[RocketTestSuite]) extends NoTargetAnnotation

/** Generates [[RocketTestSuiteAnnotation]] depending on whether the top-module project is part of
* [[freechips.rocketchip.system]] or not (e.g. for unit tests).
*/
class AddDefaultTests extends Phase with PreservesAll[Phase] with HasRocketChipStageUtils {

override val prerequisites = Seq(classOf[Checks], classOf[Elaborate])
override val dependents = Seq(classOf[GenerateTestSuiteMakefrags])

def GenerateDefaultTestSuites(): List[RocketTestSuite] = {
List(DefaultTestSuites.groundtest64("p"), DefaultTestSuites.emptyBmarks, DefaultTestSuites.singleRegression)
}

def GenerateSystemTestSuites(annotations: AnnotationSeq): scala.collection.mutable.Buffer[RocketTestSuite] = {
val params: Parameters = getConfig(view[RocketChipOptions](annotations).configNames.get).toInstance
val xlen = params(XLen)
val tests = scala.collection.mutable.Buffer[RocketTestSuite]()

val regressionTests = mutable.LinkedHashSet(
"rv64ud-v-fcvt",
"rv64ud-p-fdiv",
"rv64ud-v-fadd",
"rv64uf-v-fadd",
"rv64um-v-mul",
"rv64mi-p-breakpoint",
"rv64uc-v-rvc",
"rv64ud-v-structural",
"rv64si-p-wfi",
"rv64um-v-divw",
"rv64ua-v-lrsc",
"rv64ui-v-fence_i",
"rv64ud-v-fcvt_w",
"rv64uf-v-fmin",
"rv64ui-v-sb",
"rv64ua-v-amomax_d",
"rv64ud-v-move",
"rv64ud-v-fclass",
"rv64ua-v-amoand_d",
"rv64ua-v-amoxor_d",
"rv64si-p-sbreak",
"rv64ud-v-fmadd",
"rv64uf-v-ldst",
"rv64um-v-mulh",
"rv64si-p-dirty",
"rv32mi-p-ma_addr",
"rv32mi-p-csr",
"rv32ui-p-sh",
"rv32ui-p-lh",
"rv32uc-p-rvc",
"rv32mi-p-sbreak",
"rv32ui-p-sll")

// TODO: for now only generate tests for the first core in the first subsystem
params(RocketTilesKey).headOption.map { tileParams =>
val coreParams = tileParams.core
val vm = coreParams.useVM
val env = if (vm) List("p", "v") else List("p")
coreParams.fpu foreach { case cfg =>
if (xlen == 32) {
tests ++= env.map(rv32uf)
if (cfg.fLen >= 64)
tests ++= env.map(rv32ud)
} else {
tests += rv32udBenchmarks
tests ++= env.map(rv64uf)
if (cfg.fLen >= 64)
tests ++= env.map(rv64ud)
}
}
if (coreParams.useAtomics) {
if (tileParams.dcache.flatMap(_.scratch).isEmpty)
tests ++= env.map(if (xlen == 64) rv64ua else rv32ua)
else
tests ++= env.map(if (xlen == 64) rv64uaSansLRSC else rv32uaSansLRSC)
}
if (coreParams.useCompressed) tests ++= env.map(if (xlen == 64) rv64uc else rv32uc)
val (rvi, rvu) =
if (xlen == 64) ((if (vm) rv64i else rv64pi), rv64u)
else ((if (vm) rv32i else rv32pi), rv32u)

tests ++= rvi.map(_ ("p"))
tests ++= (if (vm) List("v") else List()).flatMap(env => rvu.map(_ (env)))
tests += benchmarks

/* Filter the regression tests based on what the Rocket Chip configuration supports */
val extensions = {
val fd = coreParams.fpu.map {
case cfg if cfg.fLen >= 64 => "fd"
case _ => "f"
}
val m = coreParams.mulDiv.map { case _ => "m" }
fd ++ m ++ Seq(if (coreParams.useRVE) Some("e") else Some("i"),
if (coreParams.useAtomics) Some("a") else None,
if (coreParams.useCompressed) Some("c") else None)
.flatten
.mkString("")
}
val re = s"""^rv$xlen[usm][$extensions].+""".r
regressionTests.retain {
case re() => true
case _ => false
}
tests += new RegressionTestSuite(regressionTests)
}
tests
}

override def transform(annotations: AnnotationSeq): AnnotationSeq = {
val ropts = view[RocketChipOptions](annotations)
val tests = ropts.topPackage.get match {
case "freechips.rocketchip.system" => GenerateSystemTestSuites(annotations)
case _ => GenerateDefaultTestSuites()
}

RocketTestSuiteAnnotation(tests) +: annotations
}

}
Loading