Add and use VL_CONSTEXPR_CXX17

This commit is contained in:
Geza Lore 2022-07-05 14:20:37 +01:00
parent 3aa8624658
commit 0de1bbc85b
3 changed files with 26 additions and 19 deletions

View File

@ -234,6 +234,16 @@
# error "Verilator requires a C++11 or newer compiler" # error "Verilator requires a C++11 or newer compiler"
#endif #endif
//=========================================================================
// C++-2017
#if __cplusplus >= 201703L
# define VL_CONSTEXPR_CXX17 constexpr
#else
# define VL_CONSTEXPR_CXX17
#endif
//========================================================================= //=========================================================================
// Optimization // Optimization

View File

@ -1948,7 +1948,7 @@ private:
ASTNODE_PREFETCH(nodep->op2p()); ASTNODE_PREFETCH(nodep->op2p());
ASTNODE_PREFETCH(nodep->op3p()); ASTNODE_PREFETCH(nodep->op3p());
ASTNODE_PREFETCH(nodep->op4p()); ASTNODE_PREFETCH(nodep->op4p());
if /* TODO: 'constexpr' in C++17 */ (VisitNext) ASTNODE_PREFETCH(nodep->nextp()); if VL_CONSTEXPR_CXX17 (VisitNext) ASTNODE_PREFETCH(nodep->nextp());
// Apply function in pre-order // Apply function in pre-order
if (privateTypeTest<typename std::remove_const<T_Arg>::type>(nodep)) { if (privateTypeTest<typename std::remove_const<T_Arg>::type>(nodep)) {
@ -1964,7 +1964,7 @@ private:
} }
// Traverse 'nextp()' chain if requested // Traverse 'nextp()' chain if requested
if /* TODO: 'constexpr' in C++17 */ (VisitNext) { if VL_CONSTEXPR_CXX17 (VisitNext) {
nodep = nodep->nextp(); nodep = nodep->nextp();
} else { } else {
break; break;
@ -1987,7 +1987,7 @@ private:
ASTNODE_PREFETCH(nodep->op2p()); ASTNODE_PREFETCH(nodep->op2p());
ASTNODE_PREFETCH(nodep->op3p()); ASTNODE_PREFETCH(nodep->op3p());
ASTNODE_PREFETCH(nodep->op4p()); ASTNODE_PREFETCH(nodep->op4p());
if /* TODO: 'constexpr' in C++17 */ (VisitNext) ASTNODE_PREFETCH(nodep->nextp()); if VL_CONSTEXPR_CXX17 (VisitNext) ASTNODE_PREFETCH(nodep->nextp());
// Apply function in pre-order // Apply function in pre-order
if (privateTypeTest<typename std::remove_const<T_Arg>::type>(nodep)) { if (privateTypeTest<typename std::remove_const<T_Arg>::type>(nodep)) {
@ -2011,7 +2011,7 @@ private:
} }
// Traverse 'nextp()' chain if requested // Traverse 'nextp()' chain if requested
if /* TODO: 'constexpr' in C++17 */ (VisitNext) { if VL_CONSTEXPR_CXX17 (VisitNext) {
nodep = nodep->nextp(); nodep = nodep->nextp();
} else { } else {
break; break;

View File

@ -35,17 +35,16 @@ private:
std::vector<T_Data*> m_allocated; std::vector<T_Data*> m_allocated;
inline T_Data* getUserp(const T_Node* nodep) const { inline T_Data* getUserp(const T_Node* nodep) const {
// This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'. if VL_CONSTEXPR_CXX17 (T_UserN == 1) {
if (T_UserN == 1) {
const VNUser user = nodep->user1u(); const VNUser user = nodep->user1u();
return user.to<T_Data*>(); return user.to<T_Data*>();
} else if (T_UserN == 2) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 2) {
const VNUser user = nodep->user2u(); const VNUser user = nodep->user2u();
return user.to<T_Data*>(); return user.to<T_Data*>();
} else if (T_UserN == 3) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 3) {
const VNUser user = nodep->user3u(); const VNUser user = nodep->user3u();
return user.to<T_Data*>(); return user.to<T_Data*>();
} else if (T_UserN == 4) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 4) {
const VNUser user = nodep->user4u(); const VNUser user = nodep->user4u();
return user.to<T_Data*>(); return user.to<T_Data*>();
} else { } else {
@ -55,14 +54,13 @@ private:
} }
inline void setUserp(T_Node* nodep, T_Data* userp) const { inline void setUserp(T_Node* nodep, T_Data* userp) const {
// This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'. if VL_CONSTEXPR_CXX17 (T_UserN == 1) {
if (T_UserN == 1) {
nodep->user1u(VNUser(userp)); nodep->user1u(VNUser(userp));
} else if (T_UserN == 2) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 2) {
nodep->user2u(VNUser(userp)); nodep->user2u(VNUser(userp));
} else if (T_UserN == 3) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 3) {
nodep->user3u(VNUser(userp)); nodep->user3u(VNUser(userp));
} else if (T_UserN == 4) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 4) {
nodep->user4u(VNUser(userp)); nodep->user4u(VNUser(userp));
} else { } else {
nodep->user5u(VNUser(userp)); nodep->user5u(VNUser(userp));
@ -71,14 +69,13 @@ private:
protected: protected:
AstUserAllocatorBase() { AstUserAllocatorBase() {
// This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'. if VL_CONSTEXPR_CXX17 (T_UserN == 1) {
if (T_UserN == 1) {
VNUser1InUse::check(); VNUser1InUse::check();
} else if (T_UserN == 2) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 2) {
VNUser2InUse::check(); VNUser2InUse::check();
} else if (T_UserN == 3) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 3) {
VNUser3InUse::check(); VNUser3InUse::check();
} else if (T_UserN == 4) { } else if VL_CONSTEXPR_CXX17 (T_UserN == 4) {
VNUser4InUse::check(); VNUser4InUse::check();
} else { } else {
VNUser5InUse::check(); VNUser5InUse::check();