Replace dynamic_casts with static_casts
dynamic_cast is not free. Replace obvious instances (where the result is unconditionally dereferenced) with static_cast in contexts with performance implications.
This commit is contained in:
parent
5c828b7e60
commit
2ba39b25f1
|
|
@ -107,7 +107,7 @@ public:
|
||||||
VNUser iterateInEdges(GateGraphBaseVisitor& v, VNUser vu = VNUser(0)) {
|
VNUser iterateInEdges(GateGraphBaseVisitor& v, VNUser vu = VNUser(0)) {
|
||||||
VNUser ret = VNUser(0);
|
VNUser ret = VNUser(0);
|
||||||
for (V3GraphEdge* edgep = inBeginp(); edgep; edgep = edgep->inNextp()) {
|
for (V3GraphEdge* edgep = inBeginp(); edgep; edgep = edgep->inNextp()) {
|
||||||
ret = dynamic_cast<GateEitherVertex*>(edgep->fromp())->accept(v, vu);
|
ret = static_cast<GateEitherVertex*>(edgep->fromp())->accept(v, vu);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +121,7 @@ public:
|
||||||
for (V3GraphEdge* edgep = outBeginp(); edgep; edgep = next_edgep) {
|
for (V3GraphEdge* edgep = outBeginp(); edgep; edgep = next_edgep) {
|
||||||
// Need to find the next edge before visiting in case the edge is deleted
|
// Need to find the next edge before visiting in case the edge is deleted
|
||||||
next_edgep = edgep->outNextp();
|
next_edgep = edgep->outNextp();
|
||||||
ret = dynamic_cast<GateEitherVertex*>(edgep->top())->accept(v, vu);
|
ret = static_cast<GateEitherVertex*>(edgep->top())->accept(v, vu);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -683,7 +683,7 @@ bool GateVisitor::elimLogicOkOutputs(GateLogicVertex* consumeVertexp,
|
||||||
varscopes.insert(vscp);
|
varscopes.insert(vscp);
|
||||||
}
|
}
|
||||||
for (V3GraphEdge* edgep = consumeVertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
for (V3GraphEdge* edgep = consumeVertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||||
const GateVarVertex* const consVVertexp = dynamic_cast<GateVarVertex*>(edgep->top());
|
const GateVarVertex* const consVVertexp = static_cast<GateVarVertex*>(edgep->top());
|
||||||
AstVarScope* const vscp = consVVertexp->varScp();
|
AstVarScope* const vscp = consVVertexp->varScp();
|
||||||
if (varscopes.find(vscp) != varscopes.end()) {
|
if (varscopes.find(vscp) != varscopes.end()) {
|
||||||
UINFO(9, " Block-unopt, insertion generates input vscp " << vscp << endl);
|
UINFO(9, " Block-unopt, insertion generates input vscp " << vscp << endl);
|
||||||
|
|
@ -764,8 +764,8 @@ void GateVisitor::consumedMove() {
|
||||||
if (!vvertexp->consumed() && !vvertexp->user()) {
|
if (!vvertexp->consumed() && !vvertexp->user()) {
|
||||||
UINFO(8, "Unconsumed " << vvertexp->varScp() << endl);
|
UINFO(8, "Unconsumed " << vvertexp->varScp() << endl);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if (const GateLogicVertex* const lvertexp = dynamic_cast<GateLogicVertex*>(vertexp)) {
|
const GateLogicVertex* const lvertexp = static_cast<GateLogicVertex*>(vertexp);
|
||||||
AstNode* const nodep = lvertexp->nodep();
|
AstNode* const nodep = lvertexp->nodep();
|
||||||
const AstActive* const oldactp = lvertexp->activep(); // nullptr under cfunc
|
const AstActive* const oldactp = lvertexp->activep(); // nullptr under cfunc
|
||||||
if (!lvertexp->consumed() && oldactp) {
|
if (!lvertexp->consumed() && oldactp) {
|
||||||
|
|
@ -1108,7 +1108,7 @@ private:
|
||||||
// Replace all of this varvertex's consumers with dupVarRefp
|
// Replace all of this varvertex's consumers with dupVarRefp
|
||||||
for (V3GraphEdge* outedgep = vvertexp->outBeginp(); outedgep;) {
|
for (V3GraphEdge* outedgep = vvertexp->outBeginp(); outedgep;) {
|
||||||
const GateLogicVertex* const consumeVertexp
|
const GateLogicVertex* const consumeVertexp
|
||||||
= dynamic_cast<GateLogicVertex*>(outedgep->top());
|
= static_cast<GateLogicVertex*>(outedgep->top());
|
||||||
AstNode* const consumerp = consumeVertexp->nodep();
|
AstNode* const consumerp = consumeVertexp->nodep();
|
||||||
// if (debug() >= 9) m_graphp->dumpDotFilePrefixed("gate_preelim");
|
// if (debug() >= 9) m_graphp->dumpDotFilePrefixed("gate_preelim");
|
||||||
UINFO(9,
|
UINFO(9,
|
||||||
|
|
@ -1283,7 +1283,7 @@ private:
|
||||||
V3GraphEdge* oedgep = ledgep;
|
V3GraphEdge* oedgep = ledgep;
|
||||||
ledgep = ledgep->inNextp();
|
ledgep = ledgep->inNextp();
|
||||||
GateEitherVertex* const fromvp
|
GateEitherVertex* const fromvp
|
||||||
= dynamic_cast<GateEitherVertex*>(oedgep->fromp());
|
= static_cast<GateEitherVertex*>(oedgep->fromp());
|
||||||
new V3GraphEdge(m_graphp, fromvp, m_logicvp, 1);
|
new V3GraphEdge(m_graphp, fromvp, m_logicvp, 1);
|
||||||
VL_DO_DANGLING(oedgep->unlinkDelete(), oedgep);
|
VL_DO_DANGLING(oedgep->unlinkDelete(), oedgep);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1027,8 +1027,8 @@ class OrderVerticesByDomainThenScope final {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool operator()(const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
|
virtual bool operator()(const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
|
||||||
const MTaskMoveVertex* const l_vxp = dynamic_cast<const MTaskMoveVertex*>(lhsp);
|
const MTaskMoveVertex* const l_vxp = static_cast<const MTaskMoveVertex*>(lhsp);
|
||||||
const MTaskMoveVertex* const r_vxp = dynamic_cast<const MTaskMoveVertex*>(rhsp);
|
const MTaskMoveVertex* const r_vxp = static_cast<const MTaskMoveVertex*>(rhsp);
|
||||||
uint64_t l_id = m_ids.findId(l_vxp->domainp());
|
uint64_t l_id = m_ids.findId(l_vxp->domainp());
|
||||||
uint64_t r_id = m_ids.findId(r_vxp->domainp());
|
uint64_t r_id = m_ids.findId(r_vxp->domainp());
|
||||||
if (l_id < r_id) return true;
|
if (l_id < r_id) return true;
|
||||||
|
|
@ -1047,8 +1047,8 @@ public:
|
||||||
// Sort vertex's, which must be AbstractMTask's, into a deterministic
|
// Sort vertex's, which must be AbstractMTask's, into a deterministic
|
||||||
// order by comparing their serial IDs.
|
// order by comparing their serial IDs.
|
||||||
virtual bool operator()(const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
|
virtual bool operator()(const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
|
||||||
const AbstractMTask* const lmtaskp = dynamic_cast<const AbstractLogicMTask*>(lhsp);
|
const AbstractMTask* const lmtaskp = static_cast<const AbstractLogicMTask*>(lhsp);
|
||||||
const AbstractMTask* const rmtaskp = dynamic_cast<const AbstractLogicMTask*>(rhsp);
|
const AbstractMTask* const rmtaskp = static_cast<const AbstractLogicMTask*>(rhsp);
|
||||||
return lmtaskp->id() < rmtaskp->id();
|
return lmtaskp->id() < rmtaskp->id();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1932,7 +1932,7 @@ void OrderProcess::processMTasks() {
|
||||||
GraphStream<OrderVerticesByDomainThenScope> emit_logic(&logicGraph);
|
GraphStream<OrderVerticesByDomainThenScope> emit_logic(&logicGraph);
|
||||||
const V3GraphVertex* moveVxp;
|
const V3GraphVertex* moveVxp;
|
||||||
while ((moveVxp = emit_logic.nextp())) {
|
while ((moveVxp = emit_logic.nextp())) {
|
||||||
const MTaskMoveVertex* const movep = dynamic_cast<const MTaskMoveVertex*>(moveVxp);
|
const MTaskMoveVertex* const movep = static_cast<const MTaskMoveVertex*>(moveVxp);
|
||||||
const unsigned mtaskId = movep->color();
|
const unsigned mtaskId = movep->color();
|
||||||
UASSERT(mtaskId > 0, "Every MTaskMoveVertex should have an mtask assignment >0");
|
UASSERT(mtaskId > 0, "Every MTaskMoveVertex should have an mtask assignment >0");
|
||||||
if (movep->logicp()) {
|
if (movep->logicp()) {
|
||||||
|
|
@ -1976,7 +1976,7 @@ void OrderProcess::processMTasks() {
|
||||||
GraphStream<MTaskVxIdLessThan> emit_mtasks(&mtasks);
|
GraphStream<MTaskVxIdLessThan> emit_mtasks(&mtasks);
|
||||||
const V3GraphVertex* mtaskVxp;
|
const V3GraphVertex* mtaskVxp;
|
||||||
while ((mtaskVxp = emit_mtasks.nextp())) {
|
while ((mtaskVxp = emit_mtasks.nextp())) {
|
||||||
const AbstractLogicMTask* const mtaskp = dynamic_cast<const AbstractLogicMTask*>(mtaskVxp);
|
const AbstractLogicMTask* const mtaskp = static_cast<const AbstractLogicMTask*>(mtaskVxp);
|
||||||
|
|
||||||
// Create a body for this mtask
|
// Create a body for this mtask
|
||||||
AstMTaskBody* const bodyp = new AstMTaskBody(rootFlp);
|
AstMTaskBody* const bodyp = new AstMTaskBody(rootFlp);
|
||||||
|
|
@ -2018,7 +2018,7 @@ void OrderProcess::processMTasks() {
|
||||||
for (V3GraphEdge* inp = mtaskp->inBeginp(); inp; inp = inp->inNextp()) {
|
for (V3GraphEdge* inp = mtaskp->inBeginp(); inp; inp = inp->inNextp()) {
|
||||||
const V3GraphVertex* fromVxp = inp->fromp();
|
const V3GraphVertex* fromVxp = inp->fromp();
|
||||||
const AbstractLogicMTask* const fromp
|
const AbstractLogicMTask* const fromp
|
||||||
= dynamic_cast<const AbstractLogicMTask*>(fromVxp);
|
= static_cast<const AbstractLogicMTask*>(fromVxp);
|
||||||
const MTaskState& fromState = mtaskStates[fromp->id()];
|
const MTaskState& fromState = mtaskStates[fromp->id()];
|
||||||
new V3GraphEdge(depGraphp, fromState.m_execMTaskp, state.m_execMTaskp, 1);
|
new V3GraphEdge(depGraphp, fromState.m_execMTaskp, state.m_execMTaskp, 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,14 @@ public:
|
||||||
~VarTspSorter() override = default;
|
~VarTspSorter() override = default;
|
||||||
// METHODS
|
// METHODS
|
||||||
virtual bool operator<(const TspStateBase& other) const override {
|
virtual bool operator<(const TspStateBase& other) const override {
|
||||||
return operator<(dynamic_cast<const VarTspSorter&>(other));
|
return operator<(static_cast<const VarTspSorter&>(other));
|
||||||
}
|
}
|
||||||
bool operator<(const VarTspSorter& other) const { return m_serial < other.m_serial; }
|
bool operator<(const VarTspSorter& other) const { return m_serial < other.m_serial; }
|
||||||
const MTaskIdSet& mtaskIds() const { return m_mtaskIds; }
|
const MTaskIdSet& mtaskIds() const { return m_mtaskIds; }
|
||||||
virtual int cost(const TspStateBase* otherp) const override {
|
virtual int cost(const TspStateBase* otherp) const override {
|
||||||
return cost(dynamic_cast<const VarTspSorter*>(otherp));
|
return cost(static_cast<const VarTspSorter*>(otherp));
|
||||||
}
|
}
|
||||||
virtual int cost(const VarTspSorter* otherp) const {
|
int cost(const VarTspSorter* otherp) const {
|
||||||
int cost = diffs(m_mtaskIds, otherp->m_mtaskIds);
|
int cost = diffs(m_mtaskIds, otherp->m_mtaskIds);
|
||||||
cost += diffs(otherp->m_mtaskIds, m_mtaskIds);
|
cost += diffs(otherp->m_mtaskIds, m_mtaskIds);
|
||||||
return cost;
|
return cost;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue