CIRCT 24.0.0git
Loading...
Searching...
No Matches
Deduper Struct Reference
Collaboration diagram for Deduper:

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".
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.

Private Member Functions

hw::InnerSymbolNamespace & getNamespace (Operation *module)
 Get a cached namespace for a module.
void recordAnnotations (AnnoTarget target)
 For a specific annotation target, record all the unique NLAs which target it in the targetMap.
void recordAnnotations (Operation *op)
 Record all targets which use an NLA.
void replaceInstances (FModuleLike toModule, Operation *fromModule)
 This deletes and replaces all instances of the "fromModule" with instances of the "toModule".
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.
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.
void cloneAnnotation (SmallVectorImpl< FlatSymbolRefAttr > &nlas, Annotation anno, ArrayRef< NamedAttribute > attributes, unsigned nonLocalIndex, SmallVectorImpl< Annotation > &newAnnotations)
 Clone the annotation for each NLA in a list.
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.
void addAnnotationContext (RenameMap &renameMap, FModuleOp toModule, FModuleOp fromModule)
 Process all NLAs referencing the "from" module to point to the "to" module.
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.
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.
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.
void mergeAnnotations (FModuleLike toModule, Operation *to, FModuleLike fromModule, Operation *from)
 Merge all annotations and port annotations on two operations.
hw::InnerSymAttr mergeInnerSymbols (RenameMap &renameMap, FModuleLike toModule, hw::InnerSymAttr toSym, hw::InnerSymAttr fromSym)
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.
void mergeBlocks (RenameMap &renameMap, FModuleLike toModule, Block &toBlock, FModuleLike fromModule, Block &fromBlock)
 Recursively merge two blocks.
void mergeRegions (RenameMap &renameMap, FModuleLike toModule, Region &toRegion, FModuleLike fromModule, Region &fromRegion)

Private Attributes

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

Detailed Description

Definition at line 954 of file Dedup.cpp.

Member Typedef Documentation

◆ RenameMap

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

Definition at line 956 of file Dedup.cpp.

Constructor & Destructor Documentation

◆ Deduper()

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

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 1164 of file Dedup.cpp.

References cloneAnnotation(), context, createNLAs(), eraseNLA(), found, getNamespace(), circt::firrtl::OpAnnoTarget::getNLAReference(), instanceGraph, nlaCache, nlaTable, nonLocalString, and targetMap.

Referenced by rewriteModuleNLAs().

◆ 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 1135 of file Dedup.cpp.

References context, and circt::firrtl::Annotation::setDict().

Referenced by addAnnotationContext(), and makeAnnotationNonLocal().

◆ copyAnnotations()

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

Definition at line 1317 of file Dedup.cpp.

References makeAnnotationNonLocal(), and targetMap.

Referenced by mergeAnnotations().

◆ 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 1089 of file Dedup.cpp.

References context, getNamespace(), circt::firrtl::OpAnnoTarget::getNLAReference(), instanceGraph, nlaBlock, nlaCache, nlaTable, and symbolTable.

Referenced by addAnnotationContext(), createNLAs(), and makeAnnotationNonLocal().

◆ 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 1127 of file Dedup.cpp.

References createNLAs().

◆ 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 974 of file Dedup.cpp.

References context, mergeLoc(), mergeOps(), replaceInstances(), rewriteExtModuleNLAs(), and rewriteModuleNLAs().

◆ 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 1154 of file Dedup.cpp.

References nlaCache, nlaTable, symbolTable, and targetMap.

Referenced by addAnnotationContext().

◆ getNamespace()

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

Get a cached namespace for a module.

Definition at line 1021 of file Dedup.cpp.

References moduleNamespaces.

Referenced by addAnnotationContext(), createNLAs(), and mergeInnerSymbols().

◆ 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 1275 of file Dedup.cpp.

References assert(), circt::firrtl::Annotation::begin(), cloneAnnotation(), createNLAs(), circt::firrtl::Annotation::end(), nonLocalString, and targetMap.

Referenced by copyAnnotations().

◆ 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 1346 of file Dedup.cpp.

References context, copyAnnotations(), and circt::firrtl::AnnoTarget::setAnnotations().

Referenced by mergeAnnotations(), and mergeOps().

◆ 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 1369 of file Dedup.cpp.

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

◆ mergeBlocks()

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

Recursively merge two blocks.

Definition at line 1508 of file Dedup.cpp.

References context, mergeLoc(), and mergeOps().

Referenced by mergeRegions().

◆ mergeInnerSymbols()

hw::InnerSymAttr Deduper::mergeInnerSymbols ( RenameMap & renameMap,
FModuleLike toModule,
hw::InnerSymAttr toSym,
hw::InnerSymAttr fromSym )
inlineprivate

Definition at line 1394 of file Dedup.cpp.

References context, and getNamespace().

Referenced by recordSymRenames().

◆ mergeOps()

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

Recursively merge two operations.

Definition at line 1489 of file Dedup.cpp.

References context, mergeAnnotations(), mergeLoc(), mergeRegions(), and recordSymRenames().

Referenced by dedup(), and mergeBlocks().

◆ mergeRegions()

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

Definition at line 1522 of file Dedup.cpp.

References mergeBlocks().

◆ 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 1009 of file Dedup.cpp.

References circt::firrtl::getNumPorts(), and recordAnnotations().

◆ 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 1028 of file Dedup.cpp.

References circt::firrtl::AnnoTarget::getAnnotations(), and targetMap.

Referenced by record(), and recordAnnotations().

◆ recordAnnotations() [2/2]

void Deduper::recordAnnotations ( Operation * op)
inlineprivate

Record all targets which use an NLA.

Definition at line 1035 of file Dedup.cpp.

References recordAnnotations().

◆ recordSymRenames()

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

Definition at line 1444 of file Dedup.cpp.

References mergeInnerSymbols().

Referenced by mergeOps().

◆ 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 1051 of file Dedup.cpp.

References context, and instanceGraph.

Referenced by dedup().

◆ rewriteExtModuleNLAs()

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

Definition at line 1267 of file Dedup.cpp.

References nlaTable.

Referenced by dedup().

◆ 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 1259 of file Dedup.cpp.

References addAnnotationContext().

Referenced by dedup().

Member Data Documentation

◆ classString

StringAttr Deduper::classString
private

Definition at line 1549 of file Dedup.cpp.

Referenced by Deduper().

◆ context

MLIRContext* Deduper::context
private

◆ instanceGraph

InstanceGraph& Deduper::instanceGraph
private

Definition at line 1531 of file Dedup.cpp.

Referenced by addAnnotationContext(), createNLAs(), Deduper(), and replaceInstances().

◆ moduleNamespaces

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

A module namespace cache.

Definition at line 1552 of file Dedup.cpp.

Referenced by getNamespace().

◆ nlaBlock

Block* Deduper::nlaBlock
private

We insert all NLAs to the beginning of this block.

Definition at line 1538 of file Dedup.cpp.

Referenced by createNLAs(), and Deduper().

◆ nlaCache

DenseMap<Attribute, Attribute> Deduper::nlaCache
private

Definition at line 1545 of file Dedup.cpp.

Referenced by addAnnotationContext(), createNLAs(), Deduper(), and eraseNLA().

◆ nlaTable

NLATable* Deduper::nlaTable = nullptr
private

Cached nla table analysis.

Definition at line 1535 of file Dedup.cpp.

Referenced by addAnnotationContext(), createNLAs(), Deduper(), eraseNLA(), and rewriteExtModuleNLAs().

◆ nonLocalString

StringAttr Deduper::nonLocalString
private

Definition at line 1548 of file Dedup.cpp.

Referenced by addAnnotationContext(), Deduper(), and makeAnnotationNonLocal().

◆ symbolTable

SymbolTable& Deduper::symbolTable
private

Definition at line 1532 of file Dedup.cpp.

Referenced by createNLAs(), Deduper(), and eraseNLA().

◆ targetMap

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

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