mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 04:07:34 +00:00
Improve emitted code to use a reference for VlSelf (#5254)
This commit is contained in:
parent
67ea819d82
commit
164a7a7c5d
@ -210,6 +210,7 @@ William D. Jones
|
||||
Wilson Snyder
|
||||
Xi Zhang
|
||||
Yan Xu
|
||||
Yangyu Chen
|
||||
Yinan Xu
|
||||
Yoda Lee
|
||||
Yossi Nivin
|
||||
|
@ -445,8 +445,12 @@ void EmitCFunc::emitDereference(AstNode* nodep, const string& pointer) {
|
||||
putns(nodep, pointer.substr(2, pointer.length() - 3));
|
||||
puts(".");
|
||||
} else {
|
||||
putns(nodep, pointer);
|
||||
puts("->");
|
||||
if (pointer == "vlSelf" && m_usevlSelfRef) {
|
||||
puts("vlSelfRef.");
|
||||
} else {
|
||||
putns(nodep, pointer);
|
||||
puts("->");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,6 +148,7 @@ class EmitCFunc VL_NOT_FINAL : public EmitCConstInit {
|
||||
protected:
|
||||
EmitCLazyDecls m_lazyDecls; // Visitor for emitting lazy declarations
|
||||
bool m_useSelfForThis = false; // Replace "this" with "vlSelf"
|
||||
bool m_usevlSelfRef = false; // Use vlSelfRef reference instead of vlSelf pointer
|
||||
const AstNodeModule* m_modp = nullptr; // Current module being emitted
|
||||
const AstCFunc* m_cfuncp = nullptr; // Current function being emitted
|
||||
bool m_instantiatesOwnProcess = false;
|
||||
@ -343,6 +344,21 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
if (m_useSelfForThis) {
|
||||
m_usevlSelfRef = true;
|
||||
/*
|
||||
* Using reference to the vlSelf pointer will help the C++
|
||||
* compiler to have dereferenceable hints, which can help to
|
||||
* reduce the need for branch instructions in the generated
|
||||
* code to allow the compiler to generate load store after the
|
||||
* if condition (including short-circuit evaluation)
|
||||
* speculatively and also reduce the data cache pollution when
|
||||
* executing in the wrong path to make verilator-generated code
|
||||
* run faster.
|
||||
*/
|
||||
puts("auto &vlSelfRef = std::ref(*vlSelf).get();\n");
|
||||
}
|
||||
|
||||
if (nodep->initsp()) {
|
||||
putsDecoration(nodep, "// Init\n");
|
||||
iterateAndNextConstNull(nodep->initsp());
|
||||
@ -358,6 +374,8 @@ public:
|
||||
iterateAndNextConstNull(nodep->finalsp());
|
||||
}
|
||||
|
||||
m_usevlSelfRef = false;
|
||||
|
||||
puts("}\n");
|
||||
if (nodep->ifdef() != "") puts("#endif // " + nodep->ifdef() + "\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user