[firtool] Add option to specify default layer specialization mode

This adds a command line option to specify the default layer
specialization mode.
This commit is contained in:
Andrew Young 2024-07-29 14:28:20 -07:00
parent b4e85d6409
commit 856a4e6c06
4 changed files with 45 additions and 0 deletions

View File

@ -14,7 +14,9 @@
#ifndef CIRCT_DIALECT_FIRRTL_FIRPARSER_H
#define CIRCT_DIALECT_FIRRTL_FIRPARSER_H
#include "circt/Dialect/FIRRTL/FIRRTLAttributes.h"
#include "circt/Support/LLVM.h"
#include <optional>
#include <string>
#include <vector>
@ -53,6 +55,7 @@ struct FIRParserOptions {
bool scalarizeExtModules = false;
std::vector<std::string> enableLayers;
std::vector<std::string> disableLayers;
std::optional<LayerSpecialization> defaultLayerSpecialization;
};
mlir::OwningOpRef<mlir::ModuleOp> importFIRFile(llvm::SourceMgr &sourceMgr,

View File

@ -5605,6 +5605,8 @@ DoneParsing:
circuit.setEnableLayersAttr(enableLayers);
if (auto disableLayers = parseLayers(getConstants().options.disableLayers))
circuit.setDisableLayersAttr(disableLayers);
circuit.setDefaultLayerSpecialization(
getConstants().options.defaultLayerSpecialization);
return success();
}

View File

@ -0,0 +1,15 @@
; RUN: firtool --parse-only %s | FileCheck %s --check-prefixes=COMMON,DEFAULT
; RUN: firtool --parse-only %s --default-layer-specialization=none | FileCheck %s --check-prefixes=COMMON,NONE
; RUN: firtool --parse-only %s --default-layer-specialization=enable | FileCheck %s --check-prefixes=COMMON,ENABLE
; RUN: firtool --parse-only %s --default-layer-specialization=disable | FileCheck %s --check-prefixes=COMMON,DISABLE
; Check that default layer specialization attaches a circuit attribute.
FIRRTL version 4.0.0
; COMMON: firrtl.circuit "LayerSpecialization"
; DEFAULT-NOT: default_layer_specialization
; NONE-NOT: default_layer_specialization
; ENABLE-SAME: default_layer_specialization = #firrtl<layerspecialization enable>
; DISABLE-SAME: default_layer_specialization = #firrtl<layerspecialization disable>
circuit LayerSpecialization:
extmodule LayerSpecialization:

View File

@ -267,6 +267,18 @@ static cl::list<std::string>
cl::value_desc("layer-list"), cl::MiscFlags::CommaSeparated,
cl::cat(mainCategory));
enum class LayerSpecializationOpt { None, Enable, Disable };
static llvm::cl::opt<LayerSpecializationOpt> defaultLayerSpecialization{
"default-layer-specialization",
llvm::cl::desc("The default specialization for layers"),
llvm::cl::values(
clEnumValN(LayerSpecializationOpt::None, "none", "Layers are disabled"),
clEnumValN(LayerSpecializationOpt::Disable, "disable",
"Layers are disabled"),
clEnumValN(LayerSpecializationOpt::Enable, "enable",
"Layers are enabled")),
cl::init(LayerSpecializationOpt::None), cl::cat(mainCategory)};
/// Check output stream before writing bytecode to it.
/// Warn and return true if output is known to be displayed.
static bool checkBytecodeOutputToConsole(raw_ostream &os) {
@ -371,6 +383,19 @@ static LogicalResult processBuffer(
options.scalarizeExtModules = scalarizeExtModules;
options.enableLayers = enableLayers;
options.disableLayers = disableLayers;
switch (defaultLayerSpecialization) {
case LayerSpecializationOpt::None:
options.defaultLayerSpecialization = std::nullopt;
break;
case LayerSpecializationOpt::Enable:
options.defaultLayerSpecialization = firrtl::LayerSpecialization::Enable;
break;
case LayerSpecializationOpt::Disable:
options.defaultLayerSpecialization = firrtl::LayerSpecialization::Disable;
break;
}
module = importFIRFile(sourceMgr, &context, parserTimer, options);
} else {
auto parserTimer = ts.nest("MLIR Parser");