Skip to content

Commit

Permalink
[FIRRTL] Remove all traces of OMIR JSON support. (#7907)
Browse files Browse the repository at this point in the history
This legacy system for representing an object model has been replaced
by FIRRTL classes, objects, and properties. This removes the old
system completely.

The main change is removing the EmitOMIR pass completely, but there
are several other things related to OMIR JSON to clean up. This
includes command line options and annotations for specifying input and
output OMIR JSON, as well as support for parsing the JSON and
scattering OMIR tracker annotations. Any tests related to the above
were also removed.

The only remaining legacy OMIR feature is the OMIRTracker annotation,
which is currently used in some canBeDeleted logic on annotations in
folders, IMDCE, etc. This is being separated, and removed in this PR:
#7908.
  • Loading branch information
mikeurbach authored Nov 26, 2024
1 parent 8e62f65 commit af4b15a
Show file tree
Hide file tree
Showing 28 changed files with 10 additions and 3,454 deletions.
98 changes: 0 additions & 98 deletions docs/Dialects/FIRRTL/FIRRTLAnnotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -731,104 +731,6 @@ Example:
}
```

### OMIRFileAnnotation

| Property | Type | Description |
| ---------- | ------ | ------------- |
| class | string | `freechips.rocketchip.objectmodel.OMIRFileAnnotation` |
| filename | string | Output file to emit OMIR to |

This annotation defines the output file to write the JSON-serialized OMIR to after compilation.

Example:
```json
{
"class": "freechips.rocketchip.objectmodel.OMIRFileAnnotation",
"filename": "path/to/omir.json"
}
```

### OMIRAnnotation

| Property | Type | Description |
| ---------- | ------ | ------------- |
| class | string | `freechips.rocketchip.objectmodel.OMIRAnnotation` |
| nodes | array | A list of OMIR nodes |

This annotation specifies a piece of Object Model 2.0 IR. The `nodes` field
is an array of individual OMIR nodes (Scala class `OMNode`), which have the
following form:
```json
{
"info": "@[FileA line:col FileB line:col ...]",
"id": "OMID:42",
"fields": [/*...*/]
}
```
The `fields` entry is an array of individual OMIR fields (Scala class `OMField`), which have the following form:
```json
{
"info": "@[FileA line:col FileB line:col ...]",
"name": "foo",
"value": /*...*/
}
```
The `value` field can be a JSON array or dictionary (corresponding to the `OMArray` and `OMMap` Scala classes, respectively), or any of the string-encoded OMIR classes:

- `OMMap:<fields>`
- `OMArray:<elements>`
- `OMReference:<id>`
- `OMBigInt:<value>`
- `OMInt:<value>`
- `OMLong:<value>`
- `OMString:<value>`
- `OMBoolean:<value>`
- `OMDouble:<value>`
- `OMBigDecimal:<value>`
- `OMFrozenTarget:<omir>`
- `OMDeleted`
- `OMReferenceTarget:<target>`
- `OMMemberReferenceTarget:<target>`
- `OMMemberInstanceTarget:<target>`
- `OMInstanceTarget:<target>`
- `OMDontTouchedReferenceTarget:<target>`

Example:
```json
{
"class": "freechips.rocketchip.objectmodel.OMIRAnnotation",
"nodes": [
{
"info": "",
"id": "OMID:0",
"fields": [
{"info": "", "name": "a", "value": "OMReference:0"},
{"info": "", "name": "b", "value": "OMBigInt:42"},
{"info": "", "name": "c", "value": "OMLong:ff"},
{"info": "", "name": "d", "value": "OMString:hello"},
{"info": "", "name": "f", "value": "OMBigDecimal:10.5"},
{"info": "", "name": "g", "value": "OMDeleted:"},
{"info": "", "name": "i", "value": 42},
{"info": "", "name": "j", "value": true},
{"info": "", "name": "k", "value": 3.14}
]
},
{
"info": "",
"id": "OMID:1",
"fields": [
{"info": "", "name": "a", "value": "OMReferenceTarget:~Foo|Foo"},
{"info": "", "name": "b", "value": "OMInstanceTarget:~Foo|Foo"},
{"info": "", "name": "c", "value": "OMMemberReferenceTarget:~Foo|Foo"},
{"info": "", "name": "d", "value": "OMMemberInstanceTarget:~Foo|Foo"},
{"info": "", "name": "e", "value": "OMDontTouchedReferenceTarget:~Foo|Foo"},
{"info": "", "name": "f", "value": "OMReferenceTarget:~Foo|Bar"}
]
}
]
}
```

### RetimeModuleAnnotation

| Property | Type | Description |
Expand Down
7 changes: 0 additions & 7 deletions include/circt-c/Firtool/Firtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,6 @@ circtFirtoolOptionsSetCompanionMode(CirctFirtoolFirtoolOptions options,
MLIR_CAPI_EXPORTED void circtFirtoolOptionsSetDisableAggressiveMergeConnections(
CirctFirtoolFirtoolOptions options, bool value);

MLIR_CAPI_EXPORTED void
circtFirtoolOptionsSetEmitOmir(CirctFirtoolFirtoolOptions options, bool value);

MLIR_CAPI_EXPORTED void
circtFirtoolOptionsSetOmirOutFile(CirctFirtoolFirtoolOptions options,
MlirStringRef value);

MLIR_CAPI_EXPORTED void
circtFirtoolOptionsSetLowerMemories(CirctFirtoolFirtoolOptions options,
bool value);
Expand Down
4 changes: 0 additions & 4 deletions include/circt/Dialect/FIRRTL/AnnotationDetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ constexpr const char *traceNameAnnoClass =
constexpr const char *traceAnnoClass =
"chisel3.experimental.Trace$TraceAnnotation";

constexpr const char *omirAnnoClass =
"freechips.rocketchip.objectmodel.OMIRAnnotation";
constexpr const char *omirFileAnnoClass =
"freechips.rocketchip.objectmodel.OMIRFileAnnotation";
constexpr const char *omirTrackerAnnoClass =
"freechips.rocketchip.objectmodel.OMIRTracker";

Expand Down
3 changes: 1 addition & 2 deletions include/circt/Dialect/FIRRTL/FIRParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ struct FIRParserOptions {
InfoLocHandling infoLocatorHandling = InfoLocHandling::PreferInfo;

/// The number of annotation files that were specified on the command line.
/// This, along with numOMIRFiles provides structure to the buffers in the
/// source manager.
/// This, provides structure to the buffers in the source manager.
unsigned numAnnotationFiles;
bool scalarizePublicModules = false;
bool scalarizeInternalModules = false;
Expand Down
3 changes: 0 additions & 3 deletions include/circt/Dialect/FIRRTL/FIRRTLAnnotationHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,6 @@ LogicalResult applyGCTDataTaps(const AnnoPathValue &target, DictionaryAttr anno,
LogicalResult applyGCTMemTaps(const AnnoPathValue &target, DictionaryAttr anno,
ApplyState &state);

LogicalResult applyOMIR(const AnnoPathValue &target, DictionaryAttr anno,
ApplyState &state);

LogicalResult applyTraceName(const AnnoPathValue &target, DictionaryAttr anno,
ApplyState &state);

Expand Down
4 changes: 0 additions & 4 deletions include/circt/Dialect/FIRRTL/FIRRTLAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ inline ArrayAttr getAnnotationsIfPresent(Operation *op) {
return op->getAttrOfType<ArrayAttr>(getAnnotationAttrName());
}

/// Check if an OMIR type is a string-encoded value that the FIRRTL dialect
/// simply passes through as a string without any decoding.
bool isOMIRStringEncodedPassthrough(StringRef type);

/// This class provides a read-only projection of an annotation.
class Annotation {
public:
Expand Down
3 changes: 0 additions & 3 deletions include/circt/Dialect/FIRRTL/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ std::unique_ptr<mlir::Pass> createDedupPass();

std::unique_ptr<mlir::Pass> createEliminateWiresPass();

std::unique_ptr<mlir::Pass>
createEmitOMIRPass(mlir::StringRef outputFilename = "");

std::unique_ptr<mlir::Pass> createLowerMatchesPass();

std::unique_ptr<mlir::Pass> createLowerSignaturesPass();
Expand Down
17 changes: 0 additions & 17 deletions include/circt/Dialect/FIRRTL/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -291,23 +291,6 @@ def EliminateWires : Pass<"firrtl-eliminate-wires", "firrtl::FModuleOp"> {
let constructor = "circt::firrtl::createEliminateWiresPass()";
}

def EmitOMIR : Pass<"firrtl-emit-omir", "firrtl::CircuitOp"> {
let summary = "Emit OMIR annotations";
let description = [{
This pass gathers the `OMIRAnnotation`s in the design, updates the contained
targets with the trackers that were scattered throughout the design upon
reading the OMIR, and serializes the resulting data into a JSON file.
}];
let constructor = "circt::firrtl::createEmitOMIRPass()";
let options = [Option<"outputFilename", "file", "std::string", "",
"Output file for the JSON-serialized OMIR data">];
let dependentDialects = [
"emit::EmitDialect",
"sv::SVDialect",
"hw::HWDialect"
];
}

def LowerMatches : Pass<"firrtl-lower-matches", "firrtl::FModuleOp"> {
let summary = "Remove all matchs conditional blocks";
let description = [{
Expand Down
14 changes: 0 additions & 14 deletions include/circt/Firtool/Firtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class FirtoolOptions {
}

StringRef getOutputFilename() const { return outputFilename; }
StringRef getOmirOutputFile() const { return omirOutFile; }
StringRef getBlackBoxRootPath() const { return blackBoxRootPath; }
StringRef getChiselInterfaceOutputDirectory() const {
return chiselInterfaceOutDirectory;
Expand Down Expand Up @@ -103,7 +102,6 @@ class FirtoolOptions {
bool shouldDedup() const { return !noDedup; }
bool shouldEnableDebugInfo() const { return enableDebugInfo; }
bool shouldIgnoreReadEnableMemories() const { return ignoreReadEnableMem; }
bool shouldEmitOMIR() const { return emitOMIR; }
bool shouldExportChiselInterface() const { return exportChiselInterface; }
bool shouldConvertVecOfBundle() const { return vbToBV; }
bool shouldEtcDisableInstanceExtraction() const {
Expand Down Expand Up @@ -222,16 +220,6 @@ class FirtoolOptions {
return *this;
}

FirtoolOptions &setEmitOMIR(bool value) {
emitOMIR = value;
return *this;
}

FirtoolOptions &setOmirOutFile(StringRef value) {
omirOutFile = value;
return *this;
}

FirtoolOptions &setAdvancedLayerSink(bool value) {
advancedLayerSink = value;
return *this;
Expand Down Expand Up @@ -386,8 +374,6 @@ class FirtoolOptions {
bool noDedup;
firrtl::CompanionMode companionMode;
bool disableAggressiveMergeConnections;
bool emitOMIR;
std::string omirOutFile;
bool advancedLayerSink;
bool lowerMemories;
std::string blackBoxRootPath;
Expand Down
10 changes: 0 additions & 10 deletions lib/CAPI/Firtool/Firtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,6 @@ void circtFirtoolOptionsSetDisableAggressiveMergeConnections(
unwrap(options)->setDisableAggressiveMergeConnections(value);
}

void circtFirtoolOptionsSetEmitOmir(CirctFirtoolFirtoolOptions options,
bool value) {
unwrap(options)->setEmitOMIR(value);
}

void circtFirtoolOptionsSetOmirOutFile(CirctFirtoolFirtoolOptions options,
MlirStringRef value) {
unwrap(options)->setOmirOutFile(unwrap(value));
}

void circtFirtoolOptionsSetLowerMemories(CirctFirtoolFirtoolOptions options,
bool value) {
unwrap(options)->setLowerMemories(value);
Expand Down
12 changes: 0 additions & 12 deletions lib/Dialect/FIRRTL/FIRRTLAnnotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,18 +580,6 @@ FIRRTLType PortAnnoTarget::getType() const {
return {};
}

//===----------------------------------------------------------------------===//
// Annotation Details
//===----------------------------------------------------------------------===//

/// Check if an OMIR type is a string-encoded value that the FIRRTL dialect
/// simply passes through as a string without any decoding.
bool circt::firrtl::isOMIRStringEncodedPassthrough(StringRef type) {
return type == "OMID" || type == "OMReference" || type == "OMBigInt" ||
type == "OMLong" || type == "OMString" || type == "OMDouble" ||
type == "OMBigDecimal" || type == "OMDeleted";
}

//===----------------------------------------------------------------------===//
// Utilities for Specific Annotations
//
Expand Down
24 changes: 0 additions & 24 deletions lib/Dialect/FIRRTL/Import/FIRAnnotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,6 @@ namespace json = llvm::json;
using namespace circt;
using namespace firrtl;

/// Convert a JSON value containing OMIR JSON (an array of OMNodes), convert
/// this to an OMIRAnnotation, and add it to a mutable `annotationMap` argument.
bool circt::firrtl::fromOMIRJSON(json::Value &value,
SmallVectorImpl<Attribute> &annotations,
json::Path path, MLIRContext *context) {
// The JSON value must be an array of objects. Anything else is reported as
// invalid.
auto *array = value.getAsArray();
if (!array) {
path.report(
"Expected OMIR to be an array of nodes, but found something else.");
return false;
}

NamedAttrList omirAnnoFields;
omirAnnoFields.append("class", StringAttr::get(context, omirAnnoClass));
omirAnnoFields.append("nodes", convertJSONToAttribute(context, value, path));

DictionaryAttr omirAnno = DictionaryAttr::get(context, omirAnnoFields);
annotations.push_back(omirAnno);

return true;
}

/// Deserialize a JSON value into FIRRTL Annotations. Annotations are
/// represented as a Target-keyed arrays of attributes. The input JSON value is
/// checked, at runtime, to be an array of objects. Returns true if successful,
Expand Down
6 changes: 0 additions & 6 deletions lib/Dialect/FIRRTL/Import/FIRAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ namespace firrtl {
class CircuitOp;
class PrintFOp;

/// Convert a JSON value containing OMIR JSON (an array of OMNodes), convert
/// this to an OMIRAnnotation, and add it to a mutable `annotations` argument.
bool fromOMIRJSON(llvm::json::Value &value,
SmallVectorImpl<Attribute> &annotations,
llvm::json::Path path, MLIRContext *context);

/// Classifier for legacy verif intent captured in printf + when's. Returns
/// true if the printf encodes verif intent, false otherwise.
bool isRecognizedPrintfEncodedVerif(PrintFOp printOp);
Expand Down
Loading

0 comments on commit af4b15a

Please sign in to comment.