17#ifndef CIRCT_DIALECT_SYNTH_ANALYSIS_LONGESTPATHANALYSIS_H
18#define CIRCT_DIALECT_SYNTH_ANALYSIS_LONGESTPATHANALYSIS_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/ErrorHandling.h"
33#include "llvm/Support/JSON.h"
57 void print(llvm::raw_ostream &os)
const;
77 void Profile(llvm::FoldingSetNodeID &ID)
const {
78 for (
auto &inst :
object.instancePath) {
79 ID.AddPointer(inst.getAsOpaquePointer());
81 ID.AddPointer(
object.value.getAsOpaquePointer());
82 ID.AddInteger(
object.bitPos);
86 void print(llvm::raw_ostream &os)
const;
97 int64_t
delay = 0, llvm::ImmutableList<DebugPoint>
history = {})
105 void print(llvm::raw_ostream &os)
const;
108 llvm::ImmutableListFactory<DebugPoint> *debugPointFactory,
126 using OutputPort = std::tuple<hw::HWModuleOp, size_t, size_t>;
146 return std::get<OutputPort>(
endPoint);
159 void print(llvm::raw_ostream &os);
166 llvm::ImmutableListFactory<DebugPoint> *debugPointFactory,
239 SmallVectorImpl<DataflowPath> &results);
247 FailureOr<int64_t>
getMaxDelay(Value value, int64_t bitPos = -1);
261 SmallVectorImpl<DataflowPath> &results,
262 bool elaboratePaths =
false)
const;
268 StringAttr moduleName, SmallVectorImpl<DataflowPath> &results)
const;
274 StringAttr moduleName, SmallVectorImpl<DataflowPath> &results)
const;
282 SmallVectorImpl<DataflowPath> &results,
283 bool elaboratePaths =
false)
const;
340 llvm::SmallVector<DataflowPath, 64>
paths;
359 hw::registerHWAggregateToCombPass();
360 ::mlir::registerPass([]() -> std::unique_ptr<::mlir::Pass> {
361 return createConvertCombToSynth();
363 mlir::registerCSEPass();
364 mlir::registerCanonicalizerPass();
375 std::tuple<circt::igraph::InstancePath, mlir::Value, size_t>>;
378 auto [path, value, bitPos] = Info::getEmptyKey();
379 return Object(path, value, bitPos);
383 auto [path, value, bitPos] = Info::getTombstoneKey();
384 return Object(path, value, bitPos);
387 return Info::getHashValue(
388 {
object.instancePath,
object.value,
object.bitPos});
assert(baseType &&"element must be base type")
This graph tracks modules and where they are instantiated.
An instance path composed of a series of instances.
void setDelay(int64_t delay)
const Object & getStartPoint() const
const OutputPort & getEndPointAsPort() const
std::variant< Object, OutputPort > EndPointType
const Object & getEndPointAsObject() const
DataflowPath & prependPaths(circt::igraph::InstancePathCache &cache, llvm::ImmutableListFactory< DebugPoint > *debugPointFactory, circt::igraph::InstancePath path)
const OpenPath & getPath() const
Location getEndPointLoc()
const llvm::ImmutableList< DebugPoint > & getHistory() const
hw::HWModuleOp getRoot() const
std::tuple< hw::HWModuleOp, size_t, size_t > OutputPort
DataflowPath(OutputPort endPoint, OpenPath startPoint, hw::HWModuleOp root)
DataflowPath(Object endPoint, OpenPath startPoint, hw::HWModuleOp root)
void print(llvm::raw_ostream &os)
void printEndPoint(llvm::raw_ostream &os)
const EndPointType & getEndPoint() const
void notifyOperationModified(Operation *op) override
void notifyOperationReplaced(Operation *op, ValueRange replacement) override
void notifyOperationErased(Operation *op) override
IncrementalLongestPathAnalysis(Operation *moduleOp, mlir::AnalysisManager &am, const LongestPathAnalysisOptions &option)
IncrementalLongestPathAnalysis(Operation *moduleOp, mlir::AnalysisManager &am)
bool isOperationValidToMutate(Operation *op) const
FailureOr< int64_t > getAverageMaxDelay(Value value)
LogicalResult computeGlobalPaths(Value value, size_t bitPos, SmallVectorImpl< DataflowPath > &results)
MLIRContext * getContext() const
LogicalResult getClosedPaths(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results, bool elaboratePaths=false) const
FailureOr< int64_t > getMaxDelay(Value value, int64_t bitPos=-1)
FailureOr< ArrayRef< OpenPath > > computeLocalPaths(Value value, size_t bitPos)
LogicalResult getAllPaths(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results, bool elaboratePaths=false) const
LogicalResult getOpenPathsFromInternalToOutputPorts(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results) const
llvm::ArrayRef< hw::HWModuleOp > getTopModules() const
bool isAnalysisAvailable(StringAttr moduleName) const
LogicalResult getOpenPathsFromInputPortsToInternal(StringAttr moduleName, SmallVectorImpl< DataflowPath > &results) const
void merge(const LongestPathCollection &other)
const DataflowPath & getPath(unsigned index) const
MLIRContext * getContext() const
LongestPathCollection(MLIRContext *ctx)
llvm::SmallVector< DataflowPath, 64 > paths
void sortAndDropNonCriticalPathsPerEndPoint()
void sortInDescendingOrder()
llvm::json::Value toJSON(const circt::synth::DataflowPath &path)
void registerSynthAnalysisPrerequisitePasses()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
A data structure that caches and provides paths to module instances in the IR.
DebugPoint(circt::igraph::InstancePath path, Value value, size_t bitPos, int64_t delay=0, StringRef comment="")
void Profile(llvm::FoldingSetNodeID &ID) const
void print(llvm::raw_ostream &os) const
Configuration options for the longest path analysis.
LongestPathAnalysisOptions(bool collectDebugInfo=false, bool lazyComputation=false, bool keepOnlyMaxDelayPaths=false, StringAttr topModuleName={})
Construct analysis options with the specified settings.
bool collectDebugInfo
Enable collection of debug points along timing paths.
bool lazyComputation
Enable lazy computation mode for on-demand analysis.
bool keepOnlyMaxDelayPaths
Keep only the maximum delay path per end point.
StringAttr topModuleName
Name of the top module for the analysis.
Object(circt::igraph::InstancePath path, Value value, size_t bitPos)
Object & prependPaths(circt::igraph::InstancePathCache &cache, circt::igraph::InstancePath path)
circt::igraph::InstancePath instancePath
bool operator==(const Object &other) const
StringAttr getName() 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={})
const Object & getStartPoint() const
void print(llvm::raw_ostream &os) const
const llvm::ImmutableList< DebugPoint > & getHistory() const
OpenPath & prependPaths(circt::igraph::InstancePathCache &cache, llvm::ImmutableListFactory< DebugPoint > *debugPointFactory, circt::igraph::InstancePath path)
llvm::ImmutableList< DebugPoint > history
static Object getEmptyKey()
static bool isEqual(const Object &a, const Object &b)
static llvm::hash_code getHashValue(Object object)
static Object getTombstoneKey()