17#ifndef CIRCT_ANALYSIS_AIG_ANALYSIS_H
18#define CIRCT_ANALYSIS_AIG_ANALYSIS_H
25#include "mlir/IR/BuiltinOps.h"
26#include "mlir/IR/MLIRContext.h"
27#include "mlir/IR/Operation.h"
28#include "mlir/Transforms/Passes.h"
29#include "llvm/ADT/ArrayRef.h"
30#include "llvm/ADT/ImmutableList.h"
31#include "llvm/ADT/SmallVector.h"
32#include "llvm/Support/JSON.h"
56 void print(llvm::raw_ostream &os)
const;
76 void Profile(llvm::FoldingSetNodeID &ID)
const {
77 for (
auto &inst :
object.instancePath) {
78 ID.AddPointer(inst.getAsOpaquePointer());
80 ID.AddPointer(
object.value.getAsOpaquePointer());
81 ID.AddInteger(
object.bitPos);
85 void print(llvm::raw_ostream &os)
const;
96 int64_t
delay = 0, llvm::ImmutableList<DebugPoint>
history = {})
104 void print(llvm::raw_ostream &os)
const;
107 llvm::ImmutableListFactory<DebugPoint> *debugPointFactory,
125 using OutputPort = std::tuple<hw::HWModuleOp, size_t, size_t>;
143 return std::get<OutputPort>(
fanOut);
156 void print(llvm::raw_ostream &os);
163 llvm::ImmutableListFactory<DebugPoint> *debugPointFactory,
201 SmallVectorImpl<DataflowPath> &results)
const;
218 SmallVectorImpl<DataflowPath> &results,
219 bool elaboratePaths =
false)
const;
225 StringAttr moduleName, SmallVectorImpl<DataflowPath> &results)
const;
231 StringAttr moduleName, SmallVectorImpl<DataflowPath> &results)
const;
239 SmallVectorImpl<DataflowPath> &results,
240 bool elaboratePaths =
false)
const;
255 return "aig.longest-path-analysis-top";
311 llvm::SmallVector<DataflowPath, 64>
paths;
327 hw::registerHWAggregateToCombPass();
328 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
329 return createConvertCombToAIG();
331 mlir::registerCSEPass();
332 mlir::registerCanonicalizerPass();
343 std::tuple<circt::igraph::InstancePath, mlir::Value, size_t>>;
346 auto [path, value, bitPos] = Info::getEmptyKey();
347 return Object(path, value, bitPos);
351 auto [path, value, bitPos] = Info::getTombstoneKey();
352 return Object(path, value, bitPos);
355 return Info::getHashValue(
356 {
object.instancePath,
object.value,
object.bitPos});
const OpenPath & getPath() const
std::tuple< hw::HWModuleOp, size_t, size_t > OutputPort
const OutputPort & getFanOutAsPort() const
const llvm::ImmutableList< DebugPoint > & getHistory() const
const Object & getFanOutAsObject() const
std::variant< Object, OutputPort > FanOutType
const FanOutType & getFanOut() const
DataflowPath & prependPaths(circt::igraph::InstancePathCache &cache, llvm::ImmutableListFactory< DebugPoint > *debugPointFactory, circt::igraph::InstancePath path)
DataflowPath(OutputPort fanOut, OpenPath fanIn, hw::HWModuleOp root)
const Object & getFanIn() const
DataflowPath(Object fanOut, OpenPath fanIn, hw::HWModuleOp root)
void printFanOut(llvm::raw_ostream &os)
void print(llvm::raw_ostream &os)
hw::HWModuleOp getRoot() const
void setDelay(int64_t delay)
void notifyOperationModified(Operation *op) override
void notifyOperationReplaced(Operation *op, ValueRange replacement) override
void notifyOperationErased(Operation *op) override
FailureOr< ArrayRef< OpenPath > > getOrComputePaths(Value value, size_t bitPos)
bool isOperationValidToMutate(Operation *op) const
IncrementalLongestPathAnalysis(Operation *moduleOp, mlir::AnalysisManager &am)
FailureOr< int64_t > getOrComputeMaxDelay(Value value, size_t bitPos)
LongestPathAnalysisWithTrace(Operation *moduleOp, mlir::AnalysisManager &am)
LogicalResult getResults(Value value, size_t bitPos, SmallVectorImpl< DataflowPath > &results) const
LogicalResult getClosedPaths(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results, bool elaboratePaths=false) const
int64_t getMaxDelay(Value value) const
int64_t getAverageMaxDelay(Value value) const
LogicalResult getAllPaths(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results, bool elaboratePaths=false) const
MLIRContext * getContext() const
LogicalResult getOpenPathsFromInternalToOutputPorts(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results) const
static StringRef getTopModuleNameAttrName()
llvm::ArrayRef< hw::HWModuleOp > getTopModules() const
bool isAnalysisAvailable(StringAttr moduleName) const
LogicalResult getOpenPathsFromInputPortsToInternal(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results) const
const DataflowPath & getPath(unsigned index) const
void sortAndDropNonCriticalPathsPerFanOut()
MLIRContext * getContext() const
void sortInDescendingOrder()
LongestPathCollection(MLIRContext *ctx)
llvm::SmallVector< DataflowPath, 64 > paths
This graph tracks modules and where they are instantiated.
An instance path composed of a series of instances.
void registerAIGAnalysisPrerequisitePasses()
llvm::json::Value toJSON(const circt::aig::DataflowPath &path)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
void Profile(llvm::FoldingSetNodeID &ID) const
DebugPoint(circt::igraph::InstancePath path, Value value, size_t bitPos, int64_t delay=0, StringRef comment="")
void print(llvm::raw_ostream &os) const
LongestPathAnalysisOption()=default
LongestPathAnalysisOption(bool traceDebugPoints, bool incremental)
circt::igraph::InstancePath instancePath
Object & prependPaths(circt::igraph::InstancePathCache &cache, circt::igraph::InstancePath path)
StringAttr getName() const
bool operator==(const Object &other) const
void print(llvm::raw_ostream &os) const
Object(circt::igraph::InstancePath path, Value value, size_t bitPos)
const Object & getFanIn() const
void print(llvm::raw_ostream &os) const
OpenPath(circt::igraph::InstancePath path, Value value, size_t bitPos, int64_t delay=0, llvm::ImmutableList< DebugPoint > history={})
OpenPath & prependPaths(circt::igraph::InstancePathCache &cache, llvm::ImmutableListFactory< DebugPoint > *debugPointFactory, circt::igraph::InstancePath path)
llvm::ImmutableList< DebugPoint > history
const llvm::ImmutableList< DebugPoint > & getHistory() const
A data structure that caches and provides paths to module instances in the IR.
static Object getTombstoneKey()
static llvm::hash_code getHashValue(Object object)
static Object getEmptyKey()
static bool isEqual(const Object &a, const Object &b)