CIRCT  19.0.0git
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Deduper Struct Reference
Collaboration diagram for Deduper:
Collaboration graph
[legend]

Public Types

using RenameMap = DenseMap< StringAttr, StringAttr >
 

Public Member Functions

 Deduper (InstanceGraph &instanceGraph, SymbolTable &symbolTable, NLATable *nlaTable, CircuitOp circuit)
 
void dedup (FModuleLike toModule, FModuleLike fromModule)
 Remove the "fromModule", and replace all references to it with the "toModule". More...
 
void record (FModuleLike module)
 Record the usages of any NLA's in this module, so that we may update the annotation if the parent module is deduped with another module. More...
 

Private Member Functions

hw::InnerSymbolNamespace & getNamespace (Operation *module)
 Get a cached namespace for a module. More...
 
void recordAnnotations (AnnoTarget target)
 For a specific annotation target, record all the unique NLAs which target it in the targetMap. More...
 
void recordAnnotations (Operation *op)
 Record all targets which use an NLA. More...
 
void replaceInstances (FModuleLike toModule, Operation *fromModule)
 This deletes and replaces all instances of the "fromModule" with instances of the "toModule". More...
 
SmallVector< FlatSymbolRefAttr > createNLAs (Operation *fromModule, ArrayRef< Attribute > baseNamepath, SymbolTable::Visibility vis=SymbolTable::Visibility::Private)
 Look up the instantiations of the from module and create an NLA for each one, appending the baseNamepath to each NLA. More...
 
SmallVector< FlatSymbolRefAttr > createNLAs (StringAttr toModuleName, FModuleLike fromModule, SymbolTable::Visibility vis=SymbolTable::Visibility::Private)
 Look up the instantiations of this module and create an NLA for each one. More...
 
void cloneAnnotation (SmallVectorImpl< FlatSymbolRefAttr > &nlas, Annotation anno, ArrayRef< NamedAttribute > attributes, unsigned nonLocalIndex, SmallVectorImpl< Annotation > &newAnnotations)
 Clone the annotation for each NLA in a list. More...
 
void eraseNLA (hw::HierPathOp nla)
 This erases the NLA op, and removes the NLA from every module's NLA map, but it does not delete the NLA reference from the target operation's annotations. More...
 
void addAnnotationContext (RenameMap &renameMap, FModuleOp toModule, FModuleOp fromModule)
 Process all NLAs referencing the "from" module to point to the "to" module. More...
 
void rewriteModuleNLAs (RenameMap &renameMap, FModuleOp toModule, FModuleOp fromModule)
 Process all the NLAs that the two modules participate in, replacing references to the "from" module with references to the "to" module, and adding more context if necessary. More...
 
void rewriteExtModuleNLAs (RenameMap &renameMap, StringAttr toName, StringAttr fromName)
 
bool makeAnnotationNonLocal (StringAttr toModuleName, AnnoTarget to, FModuleLike fromModule, Annotation anno, SmallVectorImpl< Annotation > &newAnnotations)
 Take an annotation, and update it to be a non-local annotation. More...
 
void copyAnnotations (FModuleLike toModule, AnnoTarget to, FModuleLike fromModule, AnnotationSet annos, SmallVectorImpl< Annotation > &newAnnotations, SmallPtrSetImpl< Attribute > &dontTouches)
 
void mergeAnnotations (FModuleLike toModule, AnnoTarget to, AnnotationSet toAnnos, FModuleLike fromModule, AnnoTarget from, AnnotationSet fromAnnos)
 Merge the annotations of a specific target, either a operation or a port on an operation. More...
 
void mergeAnnotations (FModuleLike toModule, Operation *to, FModuleLike fromModule, Operation *from)
 Merge all annotations and port annotations on two operations. More...
 
void recordSymRenames (RenameMap &renameMap, FModuleLike toModule, Operation *to, FModuleLike fromModule, Operation *from)
 
void mergeOps (RenameMap &renameMap, FModuleLike toModule, Operation *to, FModuleLike fromModule, Operation *from)
 Recursively merge two operations. More...
 
void mergeBlocks (RenameMap &renameMap, FModuleLike toModule, Block &toBlock, FModuleLike fromModule, Block &fromBlock)
 Recursively merge two blocks. More...
 
void mergeRegions (RenameMap &renameMap, FModuleLike toModule, Region &toRegion, FModuleLike fromModule, Region &fromRegion)
 

Private Attributes

MLIRContext * context
 
InstanceGraphinstanceGraph
 
SymbolTable & symbolTable
 
NLATablenlaTable = nullptr
 Cached nla table analysis. More...
 
Block * nlaBlock
 We insert all NLAs to the beginning of this block. More...
 
DenseMap< Attribute, llvm::SmallDenseSet< AnnoTarget > > targetMap
 
DenseMap< Attribute, Attribute > nlaCache
 
StringAttr nonLocalString
 
StringAttr classString
 
DenseMap< Operation *, hw::InnerSymbolNamespace > moduleNamespaces
 A module namespace cache. More...
 

Detailed Description

Definition at line 858 of file Dedup.cpp.

Member Typedef Documentation

◆ RenameMap

using Deduper::RenameMap = DenseMap<StringAttr, StringAttr>

Definition at line 860 of file Dedup.cpp.

Constructor & Destructor Documentation

◆ Deduper()

Deduper::Deduper ( InstanceGraph instanceGraph,
SymbolTable &  symbolTable,
NLATable nlaTable,
CircuitOp  circuit 
)
inline

Definition at line 862 of file Dedup.cpp.

Member Function Documentation

◆ addAnnotationContext()

void Deduper::addAnnotationContext ( RenameMap renameMap,
FModuleOp  toModule,
FModuleOp  fromModule 
)
inlineprivate

Process all NLAs referencing the "from" module to point to the "to" module.

This is used after merging two modules together.

Definition at line 1058 of file Dedup.cpp.

◆ cloneAnnotation()

void Deduper::cloneAnnotation ( SmallVectorImpl< FlatSymbolRefAttr > &  nlas,
Annotation  anno,
ArrayRef< NamedAttribute >  attributes,
unsigned  nonLocalIndex,
SmallVectorImpl< Annotation > &  newAnnotations 
)
inlineprivate

Clone the annotation for each NLA in a list.

The attribute list should have a placeholder for the "circt.nonlocal" field, and nonLocalIndex should be the index of this field.

Definition at line 1029 of file Dedup.cpp.

References circt::firrtl::Annotation::setDict().

◆ copyAnnotations()

void Deduper::copyAnnotations ( FModuleLike  toModule,
AnnoTarget  to,
FModuleLike  fromModule,
AnnotationSet  annos,
SmallVectorImpl< Annotation > &  newAnnotations,
SmallPtrSetImpl< Attribute > &  dontTouches 
)
inlineprivate

Definition at line 1177 of file Dedup.cpp.

References circt::firrtl::dontTouchAnnoClass.

◆ createNLAs() [1/2]

SmallVector<FlatSymbolRefAttr> Deduper::createNLAs ( Operation *  fromModule,
ArrayRef< Attribute >  baseNamepath,
SymbolTable::Visibility  vis = SymbolTable::Visibility::Private 
)
inlineprivate

Look up the instantiations of the from module and create an NLA for each one, appending the baseNamepath to each NLA.

This is used to add more context to an already existing NLA. The fromModule is used to indicate which module the annotation is coming from before the merge, and will be used to create the namepaths.

Definition at line 984 of file Dedup.cpp.

References circt::calyx::direction::get(), and circt::firrtl::OpAnnoTarget::getNLAReference().

◆ createNLAs() [2/2]

SmallVector<FlatSymbolRefAttr> Deduper::createNLAs ( StringAttr  toModuleName,
FModuleLike  fromModule,
SymbolTable::Visibility  vis = SymbolTable::Visibility::Private 
)
inlineprivate

Look up the instantiations of this module and create an NLA for each one.

This returns an array of symbol references which can be used to reference the NLAs.

Definition at line 1021 of file Dedup.cpp.

References circt::calyx::direction::get().

◆ dedup()

void Deduper::dedup ( FModuleLike  toModule,
FModuleLike  fromModule 
)
inline

Remove the "fromModule", and replace all references to it with the "toModule".

Modules should be deduplicated in a bottom-up order. Any module which is not deduplicated needs to be recorded with the record call.

Definition at line 878 of file Dedup.cpp.

References circt::calyx::direction::get(), and mergeLoc().

◆ eraseNLA()

void Deduper::eraseNLA ( hw::HierPathOp  nla)
inlineprivate

This erases the NLA op, and removes the NLA from every module's NLA map, but it does not delete the NLA reference from the target operation's annotations.

Definition at line 1048 of file Dedup.cpp.

◆ getNamespace()

hw::InnerSymbolNamespace& Deduper::getNamespace ( Operation *  module)
inlineprivate

Get a cached namespace for a module.

Definition at line 925 of file Dedup.cpp.

◆ makeAnnotationNonLocal()

bool Deduper::makeAnnotationNonLocal ( StringAttr  toModuleName,
AnnoTarget  to,
FModuleLike  fromModule,
Annotation  anno,
SmallVectorImpl< Annotation > &  newAnnotations 
)
inlineprivate

Take an annotation, and update it to be a non-local annotation.

If the annotation is already non-local and has enough context, it will be skipped for now. Return true if the annotation was made non-local.

Definition at line 1135 of file Dedup.cpp.

References assert(), circt::firrtl::Annotation::begin(), and circt::firrtl::Annotation::end().

◆ mergeAnnotations() [1/2]

void Deduper::mergeAnnotations ( FModuleLike  toModule,
AnnoTarget  to,
AnnotationSet  toAnnos,
FModuleLike  fromModule,
AnnoTarget  from,
AnnotationSet  fromAnnos 
)
inlineprivate

Merge the annotations of a specific target, either a operation or a port on an operation.

Definition at line 1206 of file Dedup.cpp.

References circt::firrtl::AnnoTarget::setAnnotations().

◆ mergeAnnotations() [2/2]

void Deduper::mergeAnnotations ( FModuleLike  toModule,
Operation *  to,
FModuleLike  fromModule,
Operation *  from 
)
inlineprivate

Merge all annotations and port annotations on two operations.

Definition at line 1229 of file Dedup.cpp.

References circt::firrtl::AnnotationSet::forPort(), and circt::firrtl::getNumPorts().

◆ mergeBlocks()

void Deduper::mergeBlocks ( RenameMap renameMap,
FModuleLike  toModule,
Block &  toBlock,
FModuleLike  fromModule,
Block &  fromBlock 
)
inlineprivate

Recursively merge two blocks.

Definition at line 1337 of file Dedup.cpp.

References mergeLoc().

◆ mergeOps()

void Deduper::mergeOps ( RenameMap renameMap,
FModuleLike  toModule,
Operation *  to,
FModuleLike  fromModule,
Operation *  from 
)
inlineprivate

Recursively merge two operations.

Definition at line 1318 of file Dedup.cpp.

References mergeLoc(), and mergeRegions().

◆ mergeRegions()

void Deduper::mergeRegions ( RenameMap renameMap,
FModuleLike  toModule,
Region &  toRegion,
FModuleLike  fromModule,
Region &  fromRegion 
)
inlineprivate

Definition at line 1351 of file Dedup.cpp.

◆ record()

void Deduper::record ( FModuleLike  module)
inline

Record the usages of any NLA's in this module, so that we may update the annotation if the parent module is deduped with another module.

Definition at line 913 of file Dedup.cpp.

References circt::firrtl::getNumPorts().

◆ recordAnnotations() [1/2]

void Deduper::recordAnnotations ( AnnoTarget  target)
inlineprivate

For a specific annotation target, record all the unique NLAs which target it in the targetMap.

Definition at line 932 of file Dedup.cpp.

References circt::firrtl::AnnoTarget::getAnnotations().

◆ recordAnnotations() [2/2]

void Deduper::recordAnnotations ( Operation *  op)
inlineprivate

Record all targets which use an NLA.

Definition at line 939 of file Dedup.cpp.

◆ recordSymRenames()

void Deduper::recordSymRenames ( RenameMap renameMap,
FModuleLike  toModule,
Operation *  to,
FModuleLike  fromModule,
Operation *  from 
)
inlineprivate

◆ replaceInstances()

void Deduper::replaceInstances ( FModuleLike  toModule,
Operation *  fromModule 
)
inlineprivate

This deletes and replaces all instances of the "fromModule" with instances of the "toModule".

Definition at line 955 of file Dedup.cpp.

References circt::calyx::direction::get(), and circt::firrtl::detail::getInstanceTypeForClassLike().

◆ rewriteExtModuleNLAs()

void Deduper::rewriteExtModuleNLAs ( RenameMap renameMap,
StringAttr  toName,
StringAttr  fromName 
)
inlineprivate

Definition at line 1127 of file Dedup.cpp.

◆ rewriteModuleNLAs()

void Deduper::rewriteModuleNLAs ( RenameMap renameMap,
FModuleOp  toModule,
FModuleOp  fromModule 
)
inlineprivate

Process all the NLAs that the two modules participate in, replacing references to the "from" module with references to the "to" module, and adding more context if necessary.

Definition at line 1119 of file Dedup.cpp.

Member Data Documentation

◆ classString

StringAttr Deduper::classString
private

Definition at line 1378 of file Dedup.cpp.

◆ context

MLIRContext* Deduper::context
private

Definition at line 1359 of file Dedup.cpp.

◆ instanceGraph

InstanceGraph& Deduper::instanceGraph
private

Definition at line 1360 of file Dedup.cpp.

◆ moduleNamespaces

DenseMap<Operation *, hw::InnerSymbolNamespace> Deduper::moduleNamespaces
private

A module namespace cache.

Definition at line 1381 of file Dedup.cpp.

◆ nlaBlock

Block* Deduper::nlaBlock
private

We insert all NLAs to the beginning of this block.

Definition at line 1367 of file Dedup.cpp.

◆ nlaCache

DenseMap<Attribute, Attribute> Deduper::nlaCache
private

Definition at line 1374 of file Dedup.cpp.

◆ nlaTable

NLATable* Deduper::nlaTable = nullptr
private

Cached nla table analysis.

Definition at line 1364 of file Dedup.cpp.

◆ nonLocalString

StringAttr Deduper::nonLocalString
private

Definition at line 1377 of file Dedup.cpp.

◆ symbolTable

SymbolTable& Deduper::symbolTable
private

Definition at line 1361 of file Dedup.cpp.

◆ targetMap

DenseMap<Attribute, llvm::SmallDenseSet<AnnoTarget> > Deduper::targetMap
private

Definition at line 1370 of file Dedup.cpp.


The documentation for this struct was generated from the following file: