[AIG][NFC] Add a module to OutputPort data structure and refactor the name handling (#8759)

This is a preparation commit for subsequent AIG python binding PR. 

 - Modified OutputPort type from pair to tuple to include module reference
 - Added getName() method to Object class for consistent name access
 - Updated JSON serialization to handle the new OutputPort structure
This commit is contained in:
Hideto Ueno 2025-07-21 20:33:45 -07:00 committed by GitHub
parent f1352362d1
commit f0ec28ac16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 11 deletions

View File

@ -53,6 +53,8 @@ struct Object {
Object &prependPaths(circt::igraph::InstancePathCache &cache,
circt::igraph::InstancePath path);
StringAttr getName() const;
circt::igraph::InstancePath instancePath;
Value value;
size_t bitPos;
@ -116,7 +118,7 @@ public:
// FanOut can be either an internal circuit object or a module output port
// This flexibility allows representing both closed paths
// (register-to-register) and open paths (register-to-output) in a unified way
using OutputPort = std::pair<size_t, size_t>;
using OutputPort = std::tuple<hw::HWModuleOp, size_t, size_t>;
using FanOutType = std::variant<Object, OutputPort>;
// Constructor for paths with Object fanout (internal circuit nodes)
@ -309,4 +311,5 @@ struct DenseMapInfo<circt::aig::Object> {
}
};
} // namespace llvm
#endif // CIRCT_ANALYSIS_AIG_ANALYSIS_H

View File

@ -199,8 +199,8 @@ static void printObjectImpl(llvm::raw_ostream &os, const Object &object,
std::string pathString;
llvm::raw_string_ostream osPath(pathString);
object.instancePath.print(osPath);
os << "Object(" << pathString << "." << getNameImpl(object.value).getValue()
<< "[" << object.bitPos << "]";
os << "Object(" << pathString << "." << object.getName().getValue() << "["
<< object.bitPos << "]";
if (delay != -1)
os << ", delay=" << delay;
if (!history.isEmpty()) {
@ -230,12 +230,14 @@ void DebugPoint::print(llvm::raw_ostream &os) const {
void Object::print(llvm::raw_ostream &os) const { printObjectImpl(os, *this); }
StringAttr Object::getName() const { return getNameImpl(value); }
void DataflowPath::printFanOut(llvm::raw_ostream &os) {
if (auto *object = std::get_if<Object>(&fanOut)) {
object->print(os);
} else {
auto &[resultNumber, bitPos] =
*std::get_if<std::pair<size_t, size_t>>(&fanOut);
auto &[module, resultNumber, bitPos] =
*std::get_if<DataflowPath::OutputPort>(&fanOut);
auto outputPortName = root.getOutputName(resultNumber);
os << "Object($root." << outputPortName << "[" << bitPos << "])";
}
@ -302,7 +304,9 @@ Location DataflowPath::getFanOutLoc() {
return object->value.getLoc();
// Return output port location.
return root.getOutputLoc(std::get<std::pair<size_t, size_t>>(fanOut).first);
auto &[module, resultNumber, bitPos] =
*std::get_if<DataflowPath::OutputPort>(&fanOut);
return module.getOutputLoc(resultNumber);
}
//===----------------------------------------------------------------------===//
@ -323,7 +327,7 @@ static llvm::json::Value toJSON(const circt::igraph::InstancePath &path) {
static llvm::json::Value toJSON(const circt::aig::Object &object) {
return llvm::json::Object{
{"instance_path", toJSON(object.instancePath)},
{"name", getNameImpl(object.value).getValue()},
{"name", object.getName().getValue()},
{"bit_pos", object.bitPos},
};
}
@ -334,7 +338,8 @@ static llvm::json::Value toJSON(const DataflowPath::FanOutType &path,
if (auto *object = std::get_if<circt::aig::Object>(&path))
return toJSON(*object);
auto &[resultNumber, bitPos] = *std::get_if<std::pair<size_t, size_t>>(&path);
auto &[module, resultNumber, bitPos] =
*std::get_if<DataflowPath::OutputPort>(&path);
return llvm::json::Object{
{"instance_path", {}}, // Instance path is empty for output ports.
{"name", root.getOutputName(resultNumber)},
@ -1287,9 +1292,10 @@ LogicalResult LongestPathAnalysis::Impl::getOpenPathsFromInternalToOutputPorts(
for (auto [point, delayAndHistory] : value) {
auto [path, start, startBitPos] = point;
auto [delay, history] = delayAndHistory;
results.emplace_back(std::make_pair(resultNum, bitPos),
OpenPath(path, start, startBitPos, delay, history),
visitor->getHWModuleOp());
results.emplace_back(
std::make_tuple(visitor->getHWModuleOp(), resultNum, bitPos),
OpenPath(path, start, startBitPos, delay, history),
visitor->getHWModuleOp());
}
}