Add and use VL_CONSTEXPR_CXX17

This commit is contained in:
Geza Lore
2022-07-05 14:21:28 +01:00
parent 3aa8624658
commit 0de1bbc85b
3 changed files with 26 additions and 19 deletions
+10
View File
@@ -234,6 +234,16 @@
# error "Verilator requires a C++11 or newer compiler"
#endif
//=========================================================================
// C++-2017
#if __cplusplus >= 201703L
# define VL_CONSTEXPR_CXX17 constexpr
#else
# define VL_CONSTEXPR_CXX17
#endif
//=========================================================================
// Optimization
+4 -4
View File
@@ -1948,7 +1948,7 @@ private:
ASTNODE_PREFETCH(nodep->op2p());
ASTNODE_PREFETCH(nodep->op3p());
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
if (privateTypeTest<typename std::remove_const<T_Arg>::type>(nodep)) {
@@ -1964,7 +1964,7 @@ private:
}
// Traverse 'nextp()' chain if requested
if /* TODO: 'constexpr' in C++17 */ (VisitNext) {
if VL_CONSTEXPR_CXX17 (VisitNext) {
nodep = nodep->nextp();
} else {
break;
@@ -1987,7 +1987,7 @@ private:
ASTNODE_PREFETCH(nodep->op2p());
ASTNODE_PREFETCH(nodep->op3p());
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
if (privateTypeTest<typename std::remove_const<T_Arg>::type>(nodep)) {
@@ -2011,7 +2011,7 @@ private:
}
// Traverse 'nextp()' chain if requested
if /* TODO: 'constexpr' in C++17 */ (VisitNext) {
if VL_CONSTEXPR_CXX17 (VisitNext) {
nodep = nodep->nextp();
} else {
break;
+12 -15
View File
@@ -35,17 +35,16 @@ private:
std::vector<T_Data*> m_allocated;
inline T_Data* getUserp(const T_Node* nodep) const {
// This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'.
if (T_UserN == 1) {
if VL_CONSTEXPR_CXX17 (T_UserN == 1) {
const VNUser user = nodep->user1u();
return user.to<T_Data*>();
} else if (T_UserN == 2) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 2) {
const VNUser user = nodep->user2u();
return user.to<T_Data*>();
} else if (T_UserN == 3) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 3) {
const VNUser user = nodep->user3u();
return user.to<T_Data*>();
} else if (T_UserN == 4) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 4) {
const VNUser user = nodep->user4u();
return user.to<T_Data*>();
} else {
@@ -55,14 +54,13 @@ private:
}
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 (T_UserN == 1) {
if VL_CONSTEXPR_CXX17 (T_UserN == 1) {
nodep->user1u(VNUser(userp));
} else if (T_UserN == 2) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 2) {
nodep->user2u(VNUser(userp));
} else if (T_UserN == 3) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 3) {
nodep->user3u(VNUser(userp));
} else if (T_UserN == 4) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 4) {
nodep->user4u(VNUser(userp));
} else {
nodep->user5u(VNUser(userp));
@@ -71,14 +69,13 @@ private:
protected:
AstUserAllocatorBase() {
// This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'.
if (T_UserN == 1) {
if VL_CONSTEXPR_CXX17 (T_UserN == 1) {
VNUser1InUse::check();
} else if (T_UserN == 2) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 2) {
VNUser2InUse::check();
} else if (T_UserN == 3) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 3) {
VNUser3InUse::check();
} else if (T_UserN == 4) {
} else if VL_CONSTEXPR_CXX17 (T_UserN == 4) {
VNUser4InUse::check();
} else {
VNUser5InUse::check();