16#include "mlir-c/BuiltinAttributes.h"
18#include "mlir-c/Support.h"
19#include "mlir/CAPI/IR.h"
20#include "mlir/CAPI/Registration.h"
21#include "mlir/CAPI/Support.h"
22#include "mlir/Pass/AnalysisManager.h"
23#include "llvm/ADT/ImmutableList.h"
24#include "llvm/ADT/PointerUnion.h"
25#include "llvm/Support/JSON.h"
51unwrap(AIGLongestPathObject
object) {
52 return llvm::PointerUnion<
57wrap(llvm::PointerUnion<Object *, DataflowPath::OutputPort *>
object) {
58 return AIGLongestPathObject{
object.getOpaqueValue()};
62 auto ptr = llvm::PointerUnion<Object *, DataflowPath::OutputPort *>(
63 const_cast<Object *
>(
object));
68 auto ptr = llvm::PointerUnion<Object *, DataflowPath::OutputPort *>(
78 bool traceDebugPoints) {
81 wrapper->analysisManager =
82 std::make_unique<mlir::ModuleAnalysisManager>(op,
nullptr);
83 mlir::AnalysisManager am = *wrapper->analysisManager;
85 wrapper->analysis = std::make_unique<LongestPathAnalysisWithTrace>(op, am);
87 wrapper->analysis = std::make_unique<LongestPathAnalysis>(op, am);
95AIGLongestPathCollection
97 MlirStringRef moduleName,
98 bool elaboratePaths) {
99 auto *wrapper =
unwrap(analysis);
100 auto *lpa = wrapper->analysis.get();
101 auto moduleNameAttr = StringAttr::get(lpa->getContext(),
unwrap(moduleName));
104 if (!lpa->isAnalysisAvailable(moduleNameAttr) ||
106 lpa->getAllPaths(moduleNameAttr, collection->paths, elaboratePaths)))
109 collection->sortInDescendingOrder();
110 return wrap(collection);
118 return !collection.ptr;
122 delete unwrap(collection);
126 auto *wrapper =
unwrap(collection);
127 return wrapper->paths.size();
131AIGLongestPathDataflowPath
134 auto *wrapper =
unwrap(collection);
135 auto &path = wrapper->paths[index];
144 auto *wrapper =
unwrap(path);
145 return wrapper->getDelay();
150 auto *wrapper =
unwrap(path);
151 auto &fanIn = wrapper->getFanIn();
157 auto *wrapper =
unwrap(path);
158 if (
auto *
object = std::get_if<Object>(&wrapper->getFanOut())) {
161 auto *ptr = std::get_if<DataflowPath::OutputPort>(&wrapper->getFanOut());
167 auto *wrapper =
unwrap(path);
168 return wrap(
const_cast<llvm::ImmutableListImpl<DebugPoint> *
>(
169 wrapper->getHistory().getInternalPointer()));
174 auto *wrapper =
unwrap(path);
175 return wrap(wrapper->getRoot());
183 auto *wrapper =
unwrap(history);
184 return llvm::ImmutableList<DebugPoint>(wrapper).isEmpty();
188 AIGLongestPathObject *
object, int64_t *delay,
189 MlirStringRef *comment) {
190 auto *wrapper =
unwrap(history);
191 auto list = llvm::ImmutableList<DebugPoint>(wrapper);
193 auto &head = list.getHead();
194 *
object =
wrap(&head.object);
196 *comment = mlirStringRefCreate(head.comment.data(), head.comment.size());
201 auto *wrapper =
unwrap(history);
202 auto list = llvm::ImmutableList<DebugPoint>(wrapper);
203 auto *tail = list.getTail().getInternalPointer();
204 return wrap(
const_cast<llvm::ImmutableListImpl<DebugPoint> *
>(tail));
213 auto *ptr = dyn_cast<Object *>(
unwrap(
object));
216 result.
ptr =
const_cast<igraph::InstanceOpInterface *
>(
217 ptr->instancePath.getPath().data());
218 result.
size = ptr->instancePath.getPath().size();
227 auto ptr =
unwrap(rawObject);
228 if (
auto *
object = dyn_cast<Object *>(ptr)) {
229 auto name =
object->getName();
230 return mlirStringRefCreate(name.data(), name.size());
232 auto [module, resultNumber, _] = *dyn_cast<DataflowPath::OutputPort *>(ptr);
233 auto name =
module.getOutputName(resultNumber);
234 return mlirStringRefCreate(name.data(), name.size());
238 auto ptr =
unwrap(rawObject);
239 if (
auto *
object = dyn_cast<Object *>(ptr))
240 return object->bitPos;
241 return std::get<2>(*dyn_cast<DataflowPath::OutputPort *>(ptr));
AIGLongestPathAnalysis aigLongestPathAnalysisCreate(MlirOperation module, bool traceDebugPoints)
AIGLongestPathHistory aigLongestPathHistoryGetTail(AIGLongestPathHistory history)
bool aigLongestPathCollectionIsNull(AIGLongestPathCollection collection)
AIGLongestPathObject aigLongestPathDataflowPathGetFanOut(AIGLongestPathDataflowPath path)
int64_t aigLongestPathDataflowPathGetDelay(AIGLongestPathDataflowPath path)
size_t aigLongestPathObjectBitPos(AIGLongestPathObject rawObject)
AIGLongestPathObject aigLongestPathDataflowPathGetFanIn(AIGLongestPathDataflowPath path)
bool aigLongestPathHistoryIsEmpty(AIGLongestPathHistory history)
MlirOperation aigLongestPathDataflowPathGetRoot(AIGLongestPathDataflowPath path)
MlirStringRef aigLongestPathObjectName(AIGLongestPathObject rawObject)
AIGLongestPathHistory aigLongestPathDataflowPathGetHistory(AIGLongestPathDataflowPath path)
AIGLongestPathObject wrap(llvm::PointerUnion< Object *, DataflowPath::OutputPort * > object)
AIGLongestPathCollection aigLongestPathAnalysisGetAllPaths(AIGLongestPathAnalysis analysis, MlirStringRef moduleName, bool elaboratePaths)
AIGLongestPathDataflowPath aigLongestPathCollectionGetDataflowPath(AIGLongestPathCollection collection, size_t index)
void aigLongestPathAnalysisDestroy(AIGLongestPathAnalysis analysis)
void aigLongestPathCollectionDestroy(AIGLongestPathCollection collection)
DEFINE_C_API_PTR_METHODS(AIGLongestPathHistory, llvm::ImmutableListImpl< DebugPoint >) llvm
size_t aigLongestPathCollectionGetSize(AIGLongestPathCollection collection)
void aigLongestPathHistoryGetHead(AIGLongestPathHistory history, AIGLongestPathObject *object, int64_t *delay, MlirStringRef *comment)
IgraphInstancePath aigLongestPathObjectGetInstancePath(AIGLongestPathObject object)
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(CHIRRTL, chirrtl, circt::chirrtl::CHIRRTLDialect) MlirType chirrtlTypeGetCMemory(MlirContext ctx
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
std::tuple< hw::HWModuleOp, size_t, size_t > OutputPort
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
std::unique_ptr< LongestPathAnalysis > analysis
std::unique_ptr< mlir::ModuleAnalysisManager > analysisManager