forked from github/verilator
Internal: Add C++20ish reverse_view for range loops. No functional change (#3388).
Signed-off-by: HungMingWu <u9089000@gmail.com>
This commit is contained in:
parent
7bfc1a00a7
commit
880a9be3b1
@ -410,16 +410,16 @@ public:
|
|||||||
}
|
}
|
||||||
template <typename Func> VlQueue find_last(Func with_func) const {
|
template <typename Func> VlQueue find_last(Func with_func) const {
|
||||||
IData index = m_deque.size() - 1;
|
IData index = m_deque.size() - 1;
|
||||||
for (auto it = m_deque.rbegin(); it != m_deque.rend(); ++it) {
|
for (auto& item : vlstd::reverse_view(m_deque)) {
|
||||||
if (with_func(index, *it)) return VlQueue::cons(*it);
|
if (with_func(index, item)) return VlQueue::cons(item);
|
||||||
--index;
|
--index;
|
||||||
}
|
}
|
||||||
return VlQueue{};
|
return VlQueue{};
|
||||||
}
|
}
|
||||||
template <typename Func> VlQueue<IData> find_last_index(Func with_func) const {
|
template <typename Func> VlQueue<IData> find_last_index(Func with_func) const {
|
||||||
IData index = m_deque.size() - 1;
|
IData index = m_deque.size() - 1;
|
||||||
for (auto it = m_deque.rbegin(); it != m_deque.rend(); ++it) {
|
for (auto& item : vlstd::reverse_view(m_deque)) {
|
||||||
if (with_func(index, *it)) return VlQueue<IData>::cons(index);
|
if (with_func(index, item)) return VlQueue<IData>::cons(index);
|
||||||
--index;
|
--index;
|
||||||
}
|
}
|
||||||
return VlQueue<IData>{};
|
return VlQueue<IData>{};
|
||||||
|
@ -521,6 +521,19 @@ using ssize_t = uint32_t; ///< signed size_t; returned from read()
|
|||||||
// Conversions
|
// Conversions
|
||||||
|
|
||||||
namespace vlstd {
|
namespace vlstd {
|
||||||
|
|
||||||
|
template <typename T> struct reverse_wrapper {
|
||||||
|
const T& m_v;
|
||||||
|
|
||||||
|
explicit reverse_wrapper(const T& a_v)
|
||||||
|
: m_v(a_v) {}
|
||||||
|
inline auto begin() -> decltype(m_v.rbegin()) { return m_v.rbegin(); }
|
||||||
|
inline auto end() -> decltype(m_v.rend()) { return m_v.rend(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// C++20's std::ranges::reverse_view
|
||||||
|
template <typename T> reverse_wrapper<T> reverse_view(const T& v) { return reverse_wrapper<T>(v); }
|
||||||
|
|
||||||
// C++17's std::as_const
|
// C++17's std::as_const
|
||||||
template <class T> T const& as_const(T& v) { return v; }
|
template <class T> T const& as_const(T& v) { return v; }
|
||||||
}; // namespace vlstd
|
}; // namespace vlstd
|
||||||
|
@ -333,8 +333,8 @@ class EmitMkHierVerilation final {
|
|||||||
const V3HierBlockPlan::HierVector blocks
|
const V3HierBlockPlan::HierVector blocks
|
||||||
= m_planp->hierBlocksSorted(); // leaf comes first
|
= m_planp->hierBlocksSorted(); // leaf comes first
|
||||||
// List in order of leaf-last order so that linker can resolve dependency
|
// List in order of leaf-last order so that linker can resolve dependency
|
||||||
for (auto it = blocks.rbegin(); it != blocks.rend(); ++it) {
|
for (auto& block : vlstd::reverse_view(blocks)) {
|
||||||
of.puts("\t" + (*it)->hierLib(true) + " \\\n");
|
of.puts("\t" + block->hierLib(true) + " \\\n");
|
||||||
}
|
}
|
||||||
of.puts("\n");
|
of.puts("\n");
|
||||||
|
|
||||||
|
@ -190,8 +190,7 @@ private:
|
|||||||
|
|
||||||
// Iterate through all modules in bottom-up order.
|
// Iterate through all modules in bottom-up order.
|
||||||
// Make a final inlining decision for each.
|
// Make a final inlining decision for each.
|
||||||
for (auto it = m_allMods.rbegin(); it != m_allMods.rend(); ++it) {
|
for (AstNodeModule* const modp : vlstd::reverse_view(m_allMods)) {
|
||||||
AstNodeModule* const modp = *it;
|
|
||||||
|
|
||||||
// If we're going to inline some modules into this one,
|
// If we're going to inline some modules into this one,
|
||||||
// update user4 (statement count) to reflect that:
|
// update user4 (statement count) to reflect that:
|
||||||
|
@ -263,10 +263,10 @@ private:
|
|||||||
UINFO(8, " DISABLE " << nodep << endl);
|
UINFO(8, " DISABLE " << nodep << endl);
|
||||||
iterateChildren(nodep);
|
iterateChildren(nodep);
|
||||||
AstNodeBlock* blockp = nullptr;
|
AstNodeBlock* blockp = nullptr;
|
||||||
for (auto it = m_blockStack.rbegin(); it != m_blockStack.rend(); ++it) {
|
for (AstNodeBlock* const stackp : vlstd::reverse_view(m_blockStack)) {
|
||||||
UINFO(9, " UNDERBLK " << *it << endl);
|
UINFO(9, " UNDERBLK " << stackp << endl);
|
||||||
if ((*it)->name() == nodep->name()) {
|
if (stackp->name() == nodep->name()) {
|
||||||
blockp = *it;
|
blockp = stackp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,8 +128,7 @@ public:
|
|||||||
}
|
}
|
||||||
void showUpward() { // LCOV_EXCL_START
|
void showUpward() { // LCOV_EXCL_START
|
||||||
UINFO(1, "ParseSym Stack:\n");
|
UINFO(1, "ParseSym Stack:\n");
|
||||||
for (auto it = m_sympStack.rbegin(); it != m_sympStack.rend(); ++it) {
|
for (VSymEnt* const symp : vlstd::reverse_view(m_sympStack)) {
|
||||||
VSymEnt* const symp = *it;
|
|
||||||
UINFO(1, " " << symp->nodep() << endl);
|
UINFO(1, " " << symp->nodep() << endl);
|
||||||
}
|
}
|
||||||
UINFO(1, "ParseSym Current: " << symCurrentp()->nodep() << endl);
|
UINFO(1, "ParseSym Current: " << symCurrentp()->nodep() << endl);
|
||||||
|
@ -526,9 +526,9 @@ public:
|
|||||||
}
|
}
|
||||||
void checkRelativesCp(GraphWay way) const {
|
void checkRelativesCp(GraphWay way) const {
|
||||||
const EdgeSet& edges = m_edges[way];
|
const EdgeSet& edges = m_edges[way];
|
||||||
for (EdgeSet::const_reverse_iterator it = edges.rbegin(); it != edges.rend(); ++it) {
|
for (const auto& edge : vlstd::reverse_view(edges)) {
|
||||||
const LogicMTask* const relativep = (*it).key();
|
const LogicMTask* const relativep = edge.key();
|
||||||
const uint32_t cachedCp = (*it).value();
|
const uint32_t cachedCp = edge.value();
|
||||||
partCheckCachedScoreVsActual(cachedCp, relativep->critPathCost(way.invert())
|
partCheckCachedScoreVsActual(cachedCp, relativep->critPathCost(way.invert())
|
||||||
+ relativep->stepCost());
|
+ relativep->stepCost());
|
||||||
}
|
}
|
||||||
@ -555,12 +555,12 @@ public:
|
|||||||
// wayEdgeEndp(way, withoutp). This should take 2 iterations max.
|
// wayEdgeEndp(way, withoutp). This should take 2 iterations max.
|
||||||
const EdgeSet& edges = m_edges[way.invert()];
|
const EdgeSet& edges = m_edges[way.invert()];
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
for (EdgeSet::const_reverse_iterator it = edges.rbegin(); it != edges.rend(); ++it) {
|
for (const auto& edge : vlstd::reverse_view(edges)) {
|
||||||
if ((*it).key() != withoutp->furtherp(way.invert())) {
|
if (edge.key() != withoutp->furtherp(way.invert())) {
|
||||||
// Use the cached cost. It could be a small overestimate
|
// Use the cached cost. It could be a small overestimate
|
||||||
// due to stepping. This is consistent with critPathCost()
|
// due to stepping. This is consistent with critPathCost()
|
||||||
// which also returns the cached cost.
|
// which also returns the cached cost.
|
||||||
result = (*it).value();
|
result = edge.value();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,11 +182,11 @@ public:
|
|||||||
}
|
}
|
||||||
m_whyNotOptimizable = why;
|
m_whyNotOptimizable = why;
|
||||||
std::ostringstream stack;
|
std::ostringstream stack;
|
||||||
for (auto it = m_callStack.rbegin(); it != m_callStack.rend(); ++it) {
|
for (auto& callstack : vlstd::reverse_view(m_callStack)) {
|
||||||
AstFuncRef* const funcp = (*it)->m_funcp;
|
AstFuncRef* const funcp = callstack->m_funcp;
|
||||||
stack << "\n " << funcp->fileline() << "... Called from "
|
stack << "\n " << funcp->fileline() << "... Called from "
|
||||||
<< funcp->prettyName() << "() with parameters:";
|
<< funcp->prettyName() << "() with parameters:";
|
||||||
V3TaskConnects* tconnects = (*it)->m_tconnects;
|
V3TaskConnects* tconnects = callstack->m_tconnects;
|
||||||
for (V3TaskConnects::iterator conIt = tconnects->begin();
|
for (V3TaskConnects::iterator conIt = tconnects->begin();
|
||||||
conIt != tconnects->end(); ++conIt) {
|
conIt != tconnects->end(); ++conIt) {
|
||||||
AstVar* const portp = conIt->first;
|
AstVar* const portp = conIt->first;
|
||||||
|
Loading…
Reference in New Issue
Block a user