CIRCT  20.0.0git
Namespaces | Macros | Functions
EmitOMIR.cpp File Reference
#include "circt/Dialect/Emit/EmitOps.h"
#include "circt/Dialect/FIRRTL/AnnotationDetails.h"
#include "circt/Dialect/FIRRTL/FIRParser.h"
#include "circt/Dialect/FIRRTL/FIRRTLAnnotationHelper.h"
#include "circt/Dialect/FIRRTL/FIRRTLInstanceGraph.h"
#include "circt/Dialect/FIRRTL/FIRRTLOps.h"
#include "circt/Dialect/FIRRTL/FIRRTLUtils.h"
#include "circt/Dialect/FIRRTL/NLATable.h"
#include "circt/Dialect/FIRRTL/Namespace.h"
#include "circt/Dialect/FIRRTL/Passes.h"
#include "circt/Dialect/HW/HWAttributes.h"
#include "circt/Dialect/HW/InnerSymbolNamespace.h"
#include "circt/Dialect/SV/SVDialect.h"
#include "circt/Dialect/SV/SVOps.h"
#include "mlir/IR/ImplicitLocOpBuilder.h"
#include "mlir/Pass/Pass.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/JSON.h"
#include <functional>
#include "circt/Dialect/FIRRTL/Passes.h.inc"
Include dependency graph for EmitOMIR.cpp:

Go to the source code of this file.

Namespaces

 circt
 The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
 
 circt::firrtl
 

Macros

#define DEBUG_TYPE   "omir"
 
#define GEN_PASS_DEF_EMITOMIR
 

Functions

static IntegerAttr isOMSRAM (Attribute &node)
 Check if an OMNode is an OMSRAM and requires special treatment of its instance path field. More...
 
static std::optional< Attribute > scatterOMIR (Attribute original, ApplyState &state)
 Recursively walk Object Model IR and convert FIRRTL targets to identifiers while scattering trackers into the newAnnotations argument. More...
 
static std::optional< std::pair< StringRef, DictionaryAttr > > scatterOMField (Attribute original, const Attribute root, unsigned index, ApplyState &state)
 Convert an Object Model Field into an optional pair of a string key and a dictionary attribute. More...
 
static std::optional< DictionaryAttr > scatterOMNode (Attribute original, const Attribute root, ApplyState &state)
 Convert an Object Model Node to an optional dictionary, convert source locator strings to location attributes, and scatter FIRRTL targets into the circuit. More...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "omir"

Definition at line 34 of file EmitOMIR.cpp.

◆ GEN_PASS_DEF_EMITOMIR

#define GEN_PASS_DEF_EMITOMIR

Definition at line 38 of file EmitOMIR.cpp.

Function Documentation

◆ isOMSRAM()

static IntegerAttr isOMSRAM ( Attribute &  node)
static

Check if an OMNode is an OMSRAM and requires special treatment of its instance path field.

This returns the ID of the tracker stored in the instancePath or finalPath field if the node has an array field omType that contains a OMString:OMSRAM entry.

Definition at line 169 of file EmitOMIR.cpp.

◆ scatterOMField()

static std::optional<std::pair<StringRef, DictionaryAttr> > scatterOMField ( Attribute  original,
const Attribute  root,
unsigned  index,
ApplyState state 
)
static

Convert an Object Model Field into an optional pair of a string key and a dictionary attribute.

Expand internal source locator strings to location attributes. Scatter any FIRRTL targets into the circuit. If this is an illegal Object Model Field return None.

Each Object Model Field consists of three mandatory members with the following names and types:

  • "info": Source Locator String
  • "name": String
  • "value": Object Model IR

The key is the "name" and the dictionary consists of the "info" and "value" members. Each value is recursively traversed to scatter any FIRRTL targets that may be used inside it.

This conversion from an object (dictionary) to key–value pair is safe because each Object Model Field in an Object Model Node must have a unique "name". Anything else is illegal Object Model.

Definition at line 362 of file EmitOMIR.cpp.

References circt::firrtl::ApplyState::circuit, circt::calyx::direction::get(), circt::firrtl::maybeStringToLocation(), circt::firrtl::omirAnnoClass, and scatterOMIR().

Referenced by scatterOMNode().

◆ scatterOMIR()

static std::optional<Attribute> scatterOMIR ( Attribute  original,
ApplyState state 
)
static

Recursively walk Object Model IR and convert FIRRTL targets to identifiers while scattering trackers into the newAnnotations argument.

Object Model IR consists of a type hierarchy built around recursive arrays and dictionaries whose leaves are "string-encoded types". This is an Object Model-specific construct that puts type information alongside a value. Concretely, these look like:

'OM' type ':' value

This function is only concerned with unpacking types whose values are FIRRTL targets. This is because these need to be kept up-to-date with modifications made to the circuit whereas other types are just passing through CIRCT.

At a later time this understanding may be expanded or Object Model IR may become its own Dialect. At this time, this function is trying to do as minimal work as possible to just validate that the OMIR looks okay without doing lots of unnecessary unpacking/repacking of string-encoded types.

Definition at line 219 of file EmitOMIR.cpp.

References circt::firrtl::ApplyState::addToWorklistFn, circt::firrtl::ApplyState::circuit, circt::calyx::direction::get(), circt::firrtl::isOMIRStringEncodedPassthrough(), circt::firrtl::ApplyState::newID(), and circt::firrtl::omirTrackerAnnoClass.

Referenced by scatterOMField().

◆ scatterOMNode()

static std::optional<DictionaryAttr> scatterOMNode ( Attribute  original,
const Attribute  root,
ApplyState state 
)
static

Convert an Object Model Node to an optional dictionary, convert source locator strings to location attributes, and scatter FIRRTL targets into the circuit.

If this is an illegal Object Model Node, then return None.

An Object Model Node is expected to look like:

  • "info": Source Locator String
  • "id": String-encoded integer ('OMID' ':' Integer)
  • "fields": Array<Object>

The "fields" member may be absent. If so, then construct an empty array.

The input attribute must be a dictionary.

Definition at line 428 of file EmitOMIR.cpp.

References circt::firrtl::ApplyState::circuit, circt::calyx::direction::get(), circt::firrtl::maybeStringToLocation(), circt::firrtl::omirAnnoClass, and scatterOMField().

Referenced by circt::firrtl::applyOMIR().