V3Partition: use static_cast with LogicMTaskVertex
dynamic_cast is not free, and the mtask graph contains only LogicMTaskVertex vertices, use static_cast instead for some speedup.
This commit is contained in:
parent
f9f66d787e
commit
b864f5f5ba
|
|
@ -375,17 +375,17 @@ public:
|
||||||
~CpCostAccessor() = default;
|
~CpCostAccessor() = default;
|
||||||
// Return cost of this node
|
// Return cost of this node
|
||||||
uint32_t cost(const V3GraphVertex* vxp) const {
|
uint32_t cost(const V3GraphVertex* vxp) const {
|
||||||
const LogicMTask* const mtaskp = dynamic_cast<const LogicMTask*>(vxp);
|
const LogicMTask* const mtaskp = static_cast<const LogicMTask*>(vxp);
|
||||||
return mtaskp->stepCost();
|
return mtaskp->stepCost();
|
||||||
}
|
}
|
||||||
// Return stored CP to this node
|
// Return stored CP to this node
|
||||||
uint32_t critPathCost(const V3GraphVertex* vxp, GraphWay way) const {
|
uint32_t critPathCost(const V3GraphVertex* vxp, GraphWay way) const {
|
||||||
const LogicMTask* const mtaskp = dynamic_cast<const LogicMTask*>(vxp);
|
const LogicMTask* const mtaskp = static_cast<const LogicMTask*>(vxp);
|
||||||
return mtaskp->critPathCost(way);
|
return mtaskp->critPathCost(way);
|
||||||
}
|
}
|
||||||
// Store a new CP to this node
|
// Store a new CP to this node
|
||||||
void setCritPathCost(V3GraphVertex* vxp, GraphWay way, uint32_t cost) const {
|
void setCritPathCost(V3GraphVertex* vxp, GraphWay way, uint32_t cost) const {
|
||||||
LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(vxp);
|
LogicMTask* const mtaskp = static_cast<LogicMTask*>(vxp);
|
||||||
mtaskp->setCritPathCost(way, cost);
|
mtaskp->setCritPathCost(way, cost);
|
||||||
}
|
}
|
||||||
// Notify vxp that the wayward CP at the throughp-->vxp edge
|
// Notify vxp that the wayward CP at the throughp-->vxp edge
|
||||||
|
|
@ -393,15 +393,15 @@ public:
|
||||||
// This is our cue to update vxp's m_edges[!way][throughp].
|
// This is our cue to update vxp's m_edges[!way][throughp].
|
||||||
void notifyEdgeCp(V3GraphVertex* vxp, GraphWay way, V3GraphVertex* throuvhVxp,
|
void notifyEdgeCp(V3GraphVertex* vxp, GraphWay way, V3GraphVertex* throuvhVxp,
|
||||||
uint32_t cp) const {
|
uint32_t cp) const {
|
||||||
LogicMTask* const updateVxp = dynamic_cast<LogicMTask*>(vxp);
|
LogicMTask* const updateVxp = static_cast<LogicMTask*>(vxp);
|
||||||
LogicMTask* const lthrouvhVxp = dynamic_cast<LogicMTask*>(throuvhVxp);
|
LogicMTask* const lthrouvhVxp = static_cast<LogicMTask*>(throuvhVxp);
|
||||||
EdgeSet& edges = updateVxp->m_edges[way.invert()];
|
EdgeSet& edges = updateVxp->m_edges[way.invert()];
|
||||||
const uint32_t edgeCp = edges.at(lthrouvhVxp);
|
const uint32_t edgeCp = edges.at(lthrouvhVxp);
|
||||||
if (cp > edgeCp) edges.set(lthrouvhVxp, cp);
|
if (cp > edgeCp) edges.set(lthrouvhVxp, cp);
|
||||||
}
|
}
|
||||||
// Check that CP matches that of the longest edge wayward of vxp.
|
// Check that CP matches that of the longest edge wayward of vxp.
|
||||||
void checkNewCpVersusEdges(V3GraphVertex* vxp, GraphWay way, uint32_t cp) const {
|
void checkNewCpVersusEdges(V3GraphVertex* vxp, GraphWay way, uint32_t cp) const {
|
||||||
LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(vxp);
|
LogicMTask* const mtaskp = static_cast<LogicMTask*>(vxp);
|
||||||
const EdgeSet& edges = mtaskp->m_edges[way.invert()];
|
const EdgeSet& edges = mtaskp->m_edges[way.invert()];
|
||||||
// This is mtaskp's relative with longest !wayward inclusive CP:
|
// This is mtaskp's relative with longest !wayward inclusive CP:
|
||||||
const auto edgeIt = edges.rbegin();
|
const auto edgeIt = edges.rbegin();
|
||||||
|
|
@ -603,7 +603,7 @@ private:
|
||||||
for (const V3GraphEdge* followp = fromp->outBeginp(); followp;
|
for (const V3GraphEdge* followp = fromp->outBeginp(); followp;
|
||||||
followp = followp->outNextp()) {
|
followp = followp->outNextp()) {
|
||||||
if (followp == excludedEdgep) continue;
|
if (followp == excludedEdgep) continue;
|
||||||
LogicMTask* const nextp = dynamic_cast<LogicMTask*>(followp->top());
|
LogicMTask* const nextp = static_cast<LogicMTask*>(followp->top());
|
||||||
if (pathExistsFromInternal(nextp, top, nullptr, generation)) return true;
|
if (pathExistsFromInternal(nextp, top, nullptr, generation)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -634,7 +634,7 @@ public:
|
||||||
const LogicMTask* startp = nullptr;
|
const LogicMTask* startp = nullptr;
|
||||||
for (const V3GraphVertex* vxp = graphp->verticesBeginp(); vxp;
|
for (const V3GraphVertex* vxp = graphp->verticesBeginp(); vxp;
|
||||||
vxp = vxp->verticesNextp()) {
|
vxp = vxp->verticesNextp()) {
|
||||||
const LogicMTask* const mtaskp = dynamic_cast<const LogicMTask*>(vxp);
|
const LogicMTask* const mtaskp = static_cast<const LogicMTask*>(vxp);
|
||||||
if (!startp) {
|
if (!startp) {
|
||||||
startp = mtaskp;
|
startp = mtaskp;
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -805,10 +805,10 @@ public:
|
||||||
}
|
}
|
||||||
// METHODS
|
// METHODS
|
||||||
LogicMTask* furtherMTaskp(GraphWay way) const {
|
LogicMTask* furtherMTaskp(GraphWay way) const {
|
||||||
return dynamic_cast<LogicMTask*>(this->furtherp(way));
|
return static_cast<LogicMTask*>(this->furtherp(way));
|
||||||
}
|
}
|
||||||
LogicMTask* fromMTaskp() const { return dynamic_cast<LogicMTask*>(fromp()); }
|
LogicMTask* fromMTaskp() const { return static_cast<LogicMTask*>(fromp()); }
|
||||||
LogicMTask* toMTaskp() const { return dynamic_cast<LogicMTask*>(top()); }
|
LogicMTask* toMTaskp() const { return static_cast<LogicMTask*>(top()); }
|
||||||
bool mergeWouldCreateCycle() const {
|
bool mergeWouldCreateCycle() const {
|
||||||
return LogicMTask::pathExistsFrom(fromMTaskp(), toMTaskp(), this);
|
return LogicMTask::pathExistsFrom(fromMTaskp(), toMTaskp(), this);
|
||||||
}
|
}
|
||||||
|
|
@ -962,7 +962,7 @@ static void partInitHalfCriticalPaths(GraphWay way, V3Graph* mtasksp, bool check
|
||||||
GraphStreamUnordered order(mtasksp, way);
|
GraphStreamUnordered order(mtasksp, way);
|
||||||
const GraphWay rev = way.invert();
|
const GraphWay rev = way.invert();
|
||||||
for (const V3GraphVertex* vertexp; (vertexp = order.nextp());) {
|
for (const V3GraphVertex* vertexp; (vertexp = order.nextp());) {
|
||||||
const LogicMTask* const mtaskcp = dynamic_cast<const LogicMTask*>(vertexp);
|
const LogicMTask* const mtaskcp = static_cast<const LogicMTask*>(vertexp);
|
||||||
LogicMTask* const mtaskp = const_cast<LogicMTask*>(mtaskcp);
|
LogicMTask* const mtaskp = const_cast<LogicMTask*>(mtaskcp);
|
||||||
uint32_t cpCost = 0;
|
uint32_t cpCost = 0;
|
||||||
#if VL_DEBUG
|
#if VL_DEBUG
|
||||||
|
|
@ -977,7 +977,7 @@ static void partInitHalfCriticalPaths(GraphWay way, V3Graph* mtasksp, bool check
|
||||||
"Should be no redundant edges in mtasks graph");
|
"Should be no redundant edges in mtasks graph");
|
||||||
relatives.insert(edgep->furtherp(rev));
|
relatives.insert(edgep->furtherp(rev));
|
||||||
#endif
|
#endif
|
||||||
const LogicMTask* const relativep = dynamic_cast<LogicMTask*>(edgep->furtherp(rev));
|
const LogicMTask* const relativep = static_cast<LogicMTask*>(edgep->furtherp(rev));
|
||||||
cpCost = std::max(cpCost, (relativep->critPathCost(way)
|
cpCost = std::max(cpCost, (relativep->critPathCost(way)
|
||||||
+ static_cast<uint32_t>(relativep->stepCost())));
|
+ static_cast<uint32_t>(relativep->stepCost())));
|
||||||
}
|
}
|
||||||
|
|
@ -1010,7 +1010,7 @@ static void partCheckCriticalPaths(V3Graph* mtasksp) {
|
||||||
partInitHalfCriticalPaths(GraphWay::FORWARD, mtasksp, true);
|
partInitHalfCriticalPaths(GraphWay::FORWARD, mtasksp, true);
|
||||||
partInitHalfCriticalPaths(GraphWay::REVERSE, mtasksp, true);
|
partInitHalfCriticalPaths(GraphWay::REVERSE, mtasksp, true);
|
||||||
for (V3GraphVertex* vxp = mtasksp->verticesBeginp(); vxp; vxp = vxp->verticesNextp()) {
|
for (V3GraphVertex* vxp = mtasksp->verticesBeginp(); vxp; vxp = vxp->verticesNextp()) {
|
||||||
const LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(vxp);
|
const LogicMTask* const mtaskp = static_cast<LogicMTask*>(vxp);
|
||||||
mtaskp->checkRelativesCp(GraphWay::FORWARD);
|
mtaskp->checkRelativesCp(GraphWay::FORWARD);
|
||||||
mtaskp->checkRelativesCp(GraphWay::REVERSE);
|
mtaskp->checkRelativesCp(GraphWay::REVERSE);
|
||||||
}
|
}
|
||||||
|
|
@ -1326,8 +1326,8 @@ private:
|
||||||
MTaskEdge* mergeEdgep = mergeCanp->toMTaskEdge();
|
MTaskEdge* mergeEdgep = mergeCanp->toMTaskEdge();
|
||||||
const SiblingMC* mergeSibsp = nullptr;
|
const SiblingMC* mergeSibsp = nullptr;
|
||||||
if (mergeEdgep) {
|
if (mergeEdgep) {
|
||||||
top = dynamic_cast<LogicMTask*>(mergeEdgep->top());
|
top = static_cast<LogicMTask*>(mergeEdgep->top());
|
||||||
fromp = dynamic_cast<LogicMTask*>(mergeEdgep->fromp());
|
fromp = static_cast<LogicMTask*>(mergeEdgep->fromp());
|
||||||
} else {
|
} else {
|
||||||
mergeSibsp = mergeCanp->toSiblingMC();
|
mergeSibsp = mergeCanp->toSiblingMC();
|
||||||
UASSERT(mergeSibsp, "Failed to cast mergeCanp to either MTaskEdge or SiblingMC");
|
UASSERT(mergeSibsp, "Failed to cast mergeCanp to either MTaskEdge or SiblingMC");
|
||||||
|
|
@ -1437,14 +1437,14 @@ private:
|
||||||
siblingPairFromRelatives(GraphWay::FORWARD, recipientp, true);
|
siblingPairFromRelatives(GraphWay::FORWARD, recipientp, true);
|
||||||
unsigned edges = 0;
|
unsigned edges = 0;
|
||||||
for (V3GraphEdge* edgep = recipientp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
for (V3GraphEdge* edgep = recipientp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||||
LogicMTask* const postreqp = dynamic_cast<LogicMTask*>(edgep->top());
|
LogicMTask* const postreqp = static_cast<LogicMTask*>(edgep->top());
|
||||||
siblingPairFromRelatives(GraphWay::REVERSE, postreqp, false);
|
siblingPairFromRelatives(GraphWay::REVERSE, postreqp, false);
|
||||||
++edges;
|
++edges;
|
||||||
if (edges > PART_SIBLING_EDGE_LIMIT) break;
|
if (edges > PART_SIBLING_EDGE_LIMIT) break;
|
||||||
}
|
}
|
||||||
edges = 0;
|
edges = 0;
|
||||||
for (V3GraphEdge* edgep = recipientp->inBeginp(); edgep; edgep = edgep->inNextp()) {
|
for (V3GraphEdge* edgep = recipientp->inBeginp(); edgep; edgep = edgep->inNextp()) {
|
||||||
LogicMTask* const prereqp = dynamic_cast<LogicMTask*>(edgep->fromp());
|
LogicMTask* const prereqp = static_cast<LogicMTask*>(edgep->fromp());
|
||||||
siblingPairFromRelatives(GraphWay::FORWARD, prereqp, false);
|
siblingPairFromRelatives(GraphWay::FORWARD, prereqp, false);
|
||||||
++edges;
|
++edges;
|
||||||
if (edges > PART_SIBLING_EDGE_LIMIT) break;
|
if (edges > PART_SIBLING_EDGE_LIMIT) break;
|
||||||
|
|
@ -1491,8 +1491,8 @@ private:
|
||||||
// Score this edge. Lower is better. The score is the new local CP
|
// Score this edge. Lower is better. The score is the new local CP
|
||||||
// length if we merge these mtasks. ("Local" means the longest
|
// length if we merge these mtasks. ("Local" means the longest
|
||||||
// critical path running through the merged node.)
|
// critical path running through the merged node.)
|
||||||
const LogicMTask* const top = dynamic_cast<LogicMTask*>(edgep->top());
|
const LogicMTask* const top = static_cast<LogicMTask*>(edgep->top());
|
||||||
const LogicMTask* const fromp = dynamic_cast<LogicMTask*>(edgep->fromp());
|
const LogicMTask* const fromp = static_cast<LogicMTask*>(edgep->fromp());
|
||||||
const uint32_t mergedCpCostFwd
|
const uint32_t mergedCpCostFwd
|
||||||
= std::max(fromp->critPathCost(GraphWay::FORWARD),
|
= std::max(fromp->critPathCost(GraphWay::FORWARD),
|
||||||
top->critPathCostWithout(GraphWay::FORWARD, edgep));
|
top->critPathCostWithout(GraphWay::FORWARD, edgep));
|
||||||
|
|
@ -1534,7 +1534,7 @@ private:
|
||||||
std::vector<LogicMTask*> shortestPrereqs;
|
std::vector<LogicMTask*> shortestPrereqs;
|
||||||
|
|
||||||
for (V3GraphEdge* edgep = mtaskp->beginp(way); edgep; edgep = edgep->nextp(way)) {
|
for (V3GraphEdge* edgep = mtaskp->beginp(way); edgep; edgep = edgep->nextp(way)) {
|
||||||
LogicMTask* const prereqp = dynamic_cast<LogicMTask*>(edgep->furtherp(way));
|
LogicMTask* const prereqp = static_cast<LogicMTask*>(edgep->furtherp(way));
|
||||||
shortestPrereqs.push_back(prereqp);
|
shortestPrereqs.push_back(prereqp);
|
||||||
// Prevent nodes with huge numbers of edges from massively
|
// Prevent nodes with huge numbers of edges from massively
|
||||||
// slowing down the partitioner:
|
// slowing down the partitioner:
|
||||||
|
|
@ -1932,7 +1932,7 @@ public:
|
||||||
OvvSet ovvSetSystemC(ovvOrder);
|
OvvSet ovvSetSystemC(ovvOrder);
|
||||||
|
|
||||||
for (V3GraphVertex* vxp = m_mtasksp->verticesBeginp(); vxp; vxp = vxp->verticesNextp()) {
|
for (V3GraphVertex* vxp = m_mtasksp->verticesBeginp(); vxp; vxp = vxp->verticesNextp()) {
|
||||||
LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(vxp);
|
LogicMTask* const mtaskp = static_cast<LogicMTask*>(vxp);
|
||||||
// Should be only one MTaskMoveVertex in each mtask at this
|
// Should be only one MTaskMoveVertex in each mtask at this
|
||||||
// stage, but whatever, write it as a loop:
|
// stage, but whatever, write it as a loop:
|
||||||
for (LogicMTask::VxList::const_iterator it = mtaskp->vertexListp()->begin();
|
for (LogicMTask::VxList::const_iterator it = mtaskp->vertexListp()->begin();
|
||||||
|
|
@ -2042,7 +2042,7 @@ public:
|
||||||
TasksByRank tasksByRank;
|
TasksByRank tasksByRank;
|
||||||
for (V3GraphVertex* vxp = m_mtasksp->verticesBeginp(); vxp;
|
for (V3GraphVertex* vxp = m_mtasksp->verticesBeginp(); vxp;
|
||||||
vxp = vxp->verticesNextp()) {
|
vxp = vxp->verticesNextp()) {
|
||||||
LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(vxp);
|
LogicMTask* const mtaskp = static_cast<LogicMTask*>(vxp);
|
||||||
if (hasDpiHazard(mtaskp)) tasksByRank[vxp->rank()].insert(mtaskp);
|
if (hasDpiHazard(mtaskp)) tasksByRank[vxp->rank()].insert(mtaskp);
|
||||||
}
|
}
|
||||||
mergeSameRankTasks(&tasksByRank);
|
mergeSameRankTasks(&tasksByRank);
|
||||||
|
|
@ -2521,7 +2521,7 @@ void V3Partition::hashGraphDebug(const V3Graph* graphp, const char* debugName) {
|
||||||
void V3Partition::setupMTaskDeps(V3Graph* mtasksp, const Vx2MTaskMap* vx2mtaskp) {
|
void V3Partition::setupMTaskDeps(V3Graph* mtasksp, const Vx2MTaskMap* vx2mtaskp) {
|
||||||
// Look at each mtask
|
// Look at each mtask
|
||||||
for (V3GraphVertex* itp = mtasksp->verticesBeginp(); itp; itp = itp->verticesNextp()) {
|
for (V3GraphVertex* itp = mtasksp->verticesBeginp(); itp; itp = itp->verticesNextp()) {
|
||||||
LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(itp);
|
LogicMTask* const mtaskp = static_cast<LogicMTask*>(itp);
|
||||||
const LogicMTask::VxList* vertexListp = mtaskp->vertexListp();
|
const LogicMTask::VxList* vertexListp = mtaskp->vertexListp();
|
||||||
|
|
||||||
// For each logic vertex in this mtask, create an mtask-to-mtask
|
// For each logic vertex in this mtask, create an mtask-to-mtask
|
||||||
|
|
@ -2651,7 +2651,7 @@ void V3Partition::go(V3Graph* mtasksp) {
|
||||||
using SortedMTaskSet = std::set<LogicMTask*, LogicMTask::CmpLogicMTask>;
|
using SortedMTaskSet = std::set<LogicMTask*, LogicMTask::CmpLogicMTask>;
|
||||||
SortedMTaskSet sorted;
|
SortedMTaskSet sorted;
|
||||||
for (V3GraphVertex* itp = mtasksp->verticesBeginp(); itp; itp = itp->verticesNextp()) {
|
for (V3GraphVertex* itp = mtasksp->verticesBeginp(); itp; itp = itp->verticesNextp()) {
|
||||||
LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(itp);
|
LogicMTask* const mtaskp = static_cast<LogicMTask*>(itp);
|
||||||
sorted.insert(mtaskp);
|
sorted.insert(mtaskp);
|
||||||
}
|
}
|
||||||
for (auto it = sorted.begin(); it != sorted.end(); ++it) {
|
for (auto it = sorted.begin(); it != sorted.end(); ++it) {
|
||||||
|
|
@ -2667,7 +2667,7 @@ void V3Partition::go(V3Graph* mtasksp) {
|
||||||
|
|
||||||
// Set color to indicate an mtaskId on every underlying MTaskMoveVertex.
|
// Set color to indicate an mtaskId on every underlying MTaskMoveVertex.
|
||||||
for (V3GraphVertex* itp = mtasksp->verticesBeginp(); itp; itp = itp->verticesNextp()) {
|
for (V3GraphVertex* itp = mtasksp->verticesBeginp(); itp; itp = itp->verticesNextp()) {
|
||||||
const LogicMTask* const mtaskp = dynamic_cast<LogicMTask*>(itp);
|
const LogicMTask* const mtaskp = static_cast<LogicMTask*>(itp);
|
||||||
for (LogicMTask::VxList::const_iterator it = mtaskp->vertexListp()->begin();
|
for (LogicMTask::VxList::const_iterator it = mtaskp->vertexListp()->begin();
|
||||||
it != mtaskp->vertexListp()->end(); ++it) {
|
it != mtaskp->vertexListp()->end(); ++it) {
|
||||||
MTaskMoveVertex* const mvertexp = *it;
|
MTaskMoveVertex* const mvertexp = *it;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue