Program Listing for File HSCutNetFlow.h

Return to documentation for file (src/sta/HSCutNetFlow.h)

#pragma once

#include <string>
#include <utility>
#include <vector>

#include "HSCutOnlyFlow.h"
namespace HSFullTiming {

class HSTimingLocalData;

// Cut net 定义为同一个原始 net 在同一对 FPGA(part) 之间的所有普通割边。
// 该 flow 中每个 HSOuterEdge 表示一个 cut net,而不是一条普通割边。
class HSCutNetFlow : public HSPartitionFlow {
 public:
  struct CutNetInfo {
    int originalNetId = -1;
    int fromNode      = -1;
    int toNode        = -1;
    int fromPart      = -1;
    int toPart        = -1;
    std::vector<int> cutEdgeIds;
    std::vector<int> originalEdgeIds;
  };

  struct cut_net {
    std::vector<int> fpga_nodes;
    int net_id = -1;
  };

  struct CutNetTimingPath {
    int clkId = -1;
    std::string clockName;
    float slack = 0.0f;
    int level   = 0;
    std::vector<int> cutNetIds;
    std::vector<CutNetInfo> cutNetInfos;
  };

  HSCutNetFlow()           = default;
  ~HSCutNetFlow() override = default;

  // 基于已有的 cut-edge flow 合并生成 cut-net flow。
  int buildFrom(const HSPartitionFlow &srcFlow,
                const HSCutOnlyFlow &cutEdgeFlow);

  // 便捷接口:内部先构建 HSCutOnlyFlow,再合并成 cut-net flow。
  int buildFrom(const HSPartitionFlow &srcFlow,
                const HSTimingLocalData *localData);
  int buildFrom(const HSPartitionFlow &srcFlow,
                const std::vector<int> &partInfo);

  const std::vector<CutNetInfo> &getCutNetInfos() const
  {
    return m_cutNetInfos;
  }

  const std::vector<int> &getCutEdge2CutNetIds() const
  {
    return m_cutEdge2CutNetIds;
  }

  void getCutNetTimingPaths(std::vector<CutNetTimingPath> &paths) const;
  json getCutNetTimingPathsJson() const;
  int dumpCutNetTimingPaths(const std::string &filepath) const;
  vector<CutNetTimingPath> getCutNetTimingPathsInfo() const;
  std::vector<cut_net> getCutNets() const;

 private:
  struct CutNetKey {
    int originalNetId = -1;
    int fromPart      = -1;
    int toPart        = -1;

    bool operator<(const CutNetKey &rhs) const
    {
      if (originalNetId != rhs.originalNetId) {
        return originalNetId < rhs.originalNetId;
      }
      if (fromPart != rhs.fromPart) {
        return fromPart < rhs.fromPart;
      }
      return toPart < rhs.toPart;
    }
  };

  void clearCutNetData();
  void cloneClocksFrom(const HSPartitionFlow &srcFlow);
  int buildCutNetEdgesFrom(const HSPartitionFlow &srcFlow,
                           const HSCutOnlyFlow &cutEdgeFlow);
  void buildCutNetNets();
  void buildCompressedCutNetAdjacency(const HSCutOnlyFlow &cutEdgeFlow);
  void buildCompressedClockAdjacency(const HSCutOnlyFlow &cutEdgeFlow);
  void rebuildNode2EdgeIds();

  std::vector<CutNetInfo> m_cutNetInfos;
  std::vector<int> m_cutEdge2CutNetIds;
};

}  // namespace HSFullTiming