Internals: CFunc VL_RESTORER. No functional change intended.

This commit is contained in:
Wilson Snyder 2020-10-31 08:59:35 -04:00
parent 3a53b32a32
commit e6b0479b80
15 changed files with 106 additions and 84 deletions

View File

@ -177,7 +177,7 @@ private:
VDouble0 m_statCombs; // Statistic tracking
CombineState m_state = STATE_IDLE; // Major state
AstNodeModule* m_modp = nullptr; // Current module
AstCFunc* m_funcp = nullptr; // Current function
AstCFunc* m_cfuncp = nullptr; // Current function
CombCallVisitor m_call; // Tracking of function call users
int m_modNFuncs = 0; // Number of functions made
#ifdef VL_COMBINE_STATEMENTS
@ -330,7 +330,7 @@ private:
AstNode* last2p) { // Final node in linked list, maybe null if all statements
// to be grabbed
// Make new function
string oldname = m_funcp->name();
string oldname = m_cfuncp->name();
string::size_type pos;
if ((pos = oldname.find("_common")) != string::npos) oldname.erase(pos);
if ((pos = oldname.find("__")) != string::npos) oldname.erase(pos);
@ -423,7 +423,8 @@ private:
m_modp = nullptr;
}
virtual void visit(AstCFunc* nodep) override {
m_funcp = nodep;
VL_RESTORER(m_cfuncp);
m_cfuncp = nodep;
if (!nodep->dontCombine()) {
if (m_state == STATE_HASH) {
hashStatement(nodep); // Hash the entire function - it might be identical
@ -434,18 +435,17 @@ private:
}
#endif
}
m_funcp = nullptr;
}
virtual void visit(AstNodeStmt* nodep) override {
if (!nodep->isStatement()) {
iterateChildren(nodep);
return;
}
if (m_state == STATE_HASH && m_funcp) {
if (m_state == STATE_HASH && m_cfuncp) {
hashStatement(nodep);
}
#ifdef VL_COMBINE_STATEMENTS
else if (m_state == STATE_DUP && m_funcp) {
else if (m_state == STATE_DUP && m_cfuncp) {
walkDupCodeStart(nodep);
}
#endif

View File

@ -1297,17 +1297,21 @@ private:
virtual void visit(AstCFunc* nodep) override {
// No ASSIGNW removals under funcs, we've long eliminated INITIALs
// (We should perhaps rename the assignw's to just assigns)
m_wremove = false;
iterateChildren(nodep);
m_wremove = true;
VL_RESTORER(m_wremove);
{
m_wremove = false;
iterateChildren(nodep);
}
}
virtual void visit(AstScope* nodep) override {
// No ASSIGNW removals under scope, we've long eliminated INITIALs
m_scopep = nodep;
m_wremove = false;
iterateChildren(nodep);
m_wremove = true;
m_scopep = nullptr;
VL_RESTORER(m_wremove);
VL_RESTORER(m_scopep);
{
m_wremove = false;
m_scopep = nodep;
iterateChildren(nodep);
}
}
void swapSides(AstNodeBiCom* nodep) {

View File

@ -358,9 +358,11 @@ private:
iterateChildren(nodep);
}
virtual void visit(AstCFunc* nodep) override {
m_cfuncp = nodep;
iterateChildren(nodep);
m_cfuncp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
iterateChildren(nodep);
}
}
virtual void visit(AstActive* nodep) override {
m_activep = nodep;

View File

@ -40,7 +40,7 @@ private:
// STATE
AstNodeModule* m_modp = nullptr; // Current module
AstCFunc* m_funcp = nullptr; // Current block
AstCFunc* m_cfuncp = nullptr; // Current block
AstNode* m_stmtp = nullptr; // Current statement
int m_depth = 0; // How deep in an expression
int m_maxdepth = 0; // Maximum depth in an expression
@ -61,8 +61,8 @@ private:
// bitmask instead of widths....)
// See t_func_crc for an example test that requires this
VFlagLogicPacked(), nodep->width());
UASSERT_OBJ(m_funcp, nodep, "Deep expression not under a function");
m_funcp->addInitsp(varp);
UASSERT_OBJ(m_cfuncp, nodep, "Deep expression not under a function");
m_cfuncp->addInitsp(varp);
// Replace node tree with reference to var
AstVarRef* newp = new AstVarRef(nodep->fileline(), varp, VAccess::READ);
nodep->replaceWith(newp);
@ -81,23 +81,27 @@ private:
VL_RESTORER(m_modp);
{
m_modp = nodep;
m_funcp = nullptr;
m_cfuncp = nullptr;
iterateChildren(nodep);
}
}
virtual void visit(AstCFunc* nodep) override {
m_funcp = nodep;
m_depth = 0;
m_maxdepth = 0;
iterateChildren(nodep);
m_funcp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
m_depth = 0;
m_maxdepth = 0;
iterateChildren(nodep);
}
}
void visitStmt(AstNodeStmt* nodep) {
m_depth = 0;
m_maxdepth = 0;
m_stmtp = nodep;
iterateChildren(nodep);
m_stmtp = nullptr;
VL_RESTORER(m_stmtp);
{
m_stmtp = nodep;
m_depth = 0;
m_maxdepth = 0;
iterateChildren(nodep);
}
}
virtual void visit(AstNodeStmt* nodep) override {
if (!nodep->isStatement()) {
@ -128,10 +132,10 @@ private:
// Marking of non-static functions (because they might need "this")
// (Here instead of new visitor after V3Descope just to avoid another visitor)
void needNonStaticFunc(AstNode* nodep) {
UASSERT_OBJ(m_funcp, nodep, "Non-static accessor not under a function");
if (m_funcp->isStatic().trueUnknown()) {
UASSERT_OBJ(m_cfuncp, nodep, "Non-static accessor not under a function");
if (m_cfuncp->isStatic().trueUnknown()) {
UINFO(5, "Mark non-public due to " << nodep << endl);
m_funcp->isStatic(false);
m_cfuncp->isStatic(false);
}
}
virtual void visit(AstUCFunc* nodep) override {

View File

@ -38,7 +38,7 @@ private:
// STATE
AstNodeModule* m_modp = nullptr; // Current module
AstCFunc* m_funcp = nullptr; // Current function
AstCFunc* m_cfuncp = nullptr; // Current function
int m_depth = 0; // How deep in an expression
int m_deepNum = 0; // How many functions made
@ -49,11 +49,11 @@ private:
AstNRelinker relinkHandle;
nodep->unlinkFrBack(&relinkHandle);
// Create function
string name = m_funcp->name() + "__deep" + cvtToStr(++m_deepNum);
string name = m_cfuncp->name() + "__deep" + cvtToStr(++m_deepNum);
AstCFunc* funcp = new AstCFunc(nodep->fileline(), name, nullptr);
funcp->argTypes(EmitCBaseVisitor::symClassVar());
funcp->symProlog(true);
funcp->slow(m_funcp->slow());
funcp->slow(m_cfuncp->slow());
funcp->addStmtsp(nodep);
m_modp->addStmtp(funcp);
// Call it at the point where the body was removed from
@ -78,10 +78,10 @@ private:
virtual void visit(AstCFunc* nodep) override {
// We recurse into this.
VL_RESTORER(m_depth);
VL_RESTORER(m_funcp);
VL_RESTORER(m_cfuncp);
{
m_depth = 0;
m_funcp = nodep;
m_cfuncp = nodep;
iterateChildren(nodep);
}
}

View File

@ -268,6 +268,8 @@ private:
// nodep->funcp()->scopep(nullptr);
}
virtual void visit(AstCFunc* nodep) override {
VL_RESTORER(m_needThis);
VL_RESTORER(m_allowThis);
if (!nodep->user1()) {
m_needThis = false;
m_allowThis = nodep->isStatic().falseUnknown(); // Non-static or unknown if static

View File

@ -3372,7 +3372,7 @@ class EmitCTrace : EmitCStmts {
AstUser1InUse m_inuser1;
// MEMBERS
AstCFunc* m_funcp = nullptr; // Function we're in now
AstCFunc* m_cfuncp = nullptr; // Function we're in now
bool m_slow; // Making slow file
int m_enumNum = 0; // Enumeration number (whole netlist)
int m_baseCode = -1; // Code of first AstTraceInc in this function
@ -3704,8 +3704,9 @@ class EmitCTrace : EmitCStmts {
virtual void visit(AstNodeModule* nodep) override { iterateChildren(nodep); }
virtual void visit(AstCFunc* nodep) override {
if (nodep->slow() != m_slow) return;
VL_RESTORER(m_cfuncp);
if (nodep->funcType().isTrace()) { // TRACE_*
m_funcp = nodep;
m_cfuncp = nodep;
if (splitNeeded()) {
// Splitting file, so using parallel build.
@ -3775,7 +3776,6 @@ class EmitCTrace : EmitCStmts {
}
puts("}\n");
}
m_funcp = nullptr;
}
virtual void visit(AstTraceDecl* nodep) override {
int enumNum = emitTraceDeclDType(nodep->dtypep());

View File

@ -50,11 +50,11 @@ class EmitCSyms : EmitCBaseVisitor {
};
struct ScopeFuncData {
AstScopeName* m_scopep;
AstCFunc* m_funcp;
AstCFunc* m_cfuncp;
AstNodeModule* m_modp;
ScopeFuncData(AstScopeName* scopep, AstCFunc* funcp, AstNodeModule* modp)
: m_scopep{scopep}
, m_funcp{funcp}
, m_cfuncp{funcp}
, m_modp{modp} {}
};
struct ScopeVarData {
@ -94,7 +94,7 @@ class EmitCSyms : EmitCBaseVisitor {
};
// STATE
AstCFunc* m_funcp = nullptr; // Current function
AstCFunc* m_cfuncp = nullptr; // Current function
AstNodeModule* m_modp = nullptr; // Current module
std::vector<ScopeModPair> m_scopes; // Every scope by module
std::vector<AstCFunc*> m_dpis; // DPI functions
@ -316,9 +316,9 @@ class EmitCSyms : EmitCBaseVisitor {
name, ScopeData(name, nodep->scopePrettySymName(), timeunit, "SCOPE_OTHER")));
}
if (nodep->dpiExport()) {
UASSERT_OBJ(m_funcp, nodep, "ScopeName not under DPI function");
UASSERT_OBJ(m_cfuncp, nodep, "ScopeName not under DPI function");
m_scopeFuncs.insert(
make_pair(name + " " + m_funcp->name(), ScopeFuncData(nodep, m_funcp, m_modp)));
make_pair(name + " " + m_cfuncp->name(), ScopeFuncData(nodep, m_cfuncp, m_modp)));
} else {
if (m_scopeNames.find(nodep->scopeDpiName()) == m_scopeNames.end()) {
m_scopeNames.insert(
@ -342,9 +342,11 @@ class EmitCSyms : EmitCBaseVisitor {
virtual void visit(AstCFunc* nodep) override {
nameCheck(nodep);
if (nodep->dpiImport() || nodep->dpiExportWrapper()) m_dpis.push_back(nodep);
m_funcp = nodep;
iterateChildren(nodep);
m_funcp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
iterateChildren(nodep);
}
}
//---------------------------------------
@ -397,7 +399,7 @@ void EmitCSyms::emitSymHdr() {
puts("\n// DPI TYPES for DPI Export callbacks (Internal use)\n");
std::map<const string, int> types; // Remove duplicates and sort
for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
AstCFunc* funcp = it->second.m_funcp;
AstCFunc* funcp = it->second.m_cfuncp;
if (funcp->dpiExport()) {
string cbtype = protect(v3Global.opt.prefix() + "__Vcb_" + funcp->cname() + "_t");
types["typedef void (*" + cbtype + ") (" + cFuncArgs(funcp) + ");\n"] = 1;
@ -721,7 +723,7 @@ void EmitCSyms::emitSymImp() {
m_ofpBase->puts("for (int __Vfinal=0; __Vfinal<2; __Vfinal++) {\n");
for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
AstScopeName* scopep = it->second.m_scopep;
AstCFunc* funcp = it->second.m_funcp;
AstCFunc* funcp = it->second.m_cfuncp;
AstNodeModule* modp = it->second.m_modp;
if (funcp->dpiExport()) {
checkSplit(true);

View File

@ -111,7 +111,6 @@ private:
m_activep = nullptr;
iterateChildren(nodep);
}
virtual void visit(AstCFunc* nodep) override { iterateChildren(nodep); }
//-----
virtual void visit(AstNode* nodep) override { iterateChildren(nodep); }

View File

@ -241,13 +241,12 @@ private:
UASSERT_OBJ(m_tracingCall || nodep == m_startNodep, nodep,
"AstCFunc not under AstCCall, or not start node");
m_tracingCall = false;
bool saved_inCFunc = m_inCFunc;
m_inCFunc = true;
VL_RESTORER(m_inCFunc);
{
m_inCFunc = true;
VisitBase vb(this, nodep);
iterateChildren(nodep);
}
m_inCFunc = saved_inCFunc;
}
virtual void visit(AstNode* nodep) override {
VisitBase vb(this, nodep);

View File

@ -150,13 +150,15 @@ private:
}
virtual void visit(AstCFunc* nodep) override {
UINFO(4, " CFUNC " << nodep << endl);
m_cfuncp = nodep;
searchFuncStmts(nodep->argsp());
searchFuncStmts(nodep->initsp());
searchFuncStmts(nodep->stmtsp());
searchFuncStmts(nodep->finalsp());
iterateChildren(nodep);
m_cfuncp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
searchFuncStmts(nodep->argsp());
searchFuncStmts(nodep->initsp());
searchFuncStmts(nodep->stmtsp());
searchFuncStmts(nodep->finalsp());
iterateChildren(nodep);
}
}
void searchFuncStmts(AstNode* nodep) {
// Search for basic assignments to allow moving non-blocktemps

View File

@ -94,7 +94,7 @@ private:
// STATE
AstNodeModule* m_modp = nullptr; // Current module
AstCFunc* m_funcp = nullptr; // Current block
AstCFunc* m_cfuncp = nullptr; // Current block
AstNode* m_stmtp = nullptr; // Current statement
AstWhile* m_inWhilep = nullptr; // Inside while loop, special statement additions
AstTraceInc* m_inTracep = nullptr; // Inside while loop, special statement additions
@ -141,7 +141,7 @@ private:
string newvarname = (string("__Vtemp") + cvtToStr(m_modp->varNumGetInc()));
AstVar* varp
= new AstVar(nodep->fileline(), AstVarType::STMTTEMP, newvarname, nodep->dtypep());
m_funcp->addInitsp(varp);
m_cfuncp->addInitsp(varp);
return varp;
}
@ -189,18 +189,20 @@ private:
VL_RESTORER(m_modp);
{
m_modp = nodep;
m_funcp = nullptr;
m_cfuncp = nullptr;
iterateChildren(nodep);
}
}
virtual void visit(AstCFunc* nodep) override {
m_funcp = nodep;
iterateChildren(nodep);
m_funcp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
iterateChildren(nodep);
}
}
void startStatement(AstNode* nodep) {
m_assignLhs = false;
if (m_funcp) m_stmtp = nodep;
if (m_cfuncp) m_stmtp = nodep;
}
virtual void visit(AstWhile* nodep) override {
UINFO(4, " WHILE " << nodep << endl);

View File

@ -142,9 +142,11 @@ private:
// VISITORS
virtual void visit(AstCFunc* nodep) override {
m_cfuncp = nodep;
iterateChildren(nodep);
m_cfuncp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
iterateChildren(nodep);
}
}
virtual void visit(AstNodeAssign* nodep) override {
if (!m_cfuncp) return;

View File

@ -181,10 +181,12 @@ private:
if (!m_tracingCall && !nodep->entryPoint()) return;
m_tracingCall = false;
}
m_cfuncp = nodep;
allNodes(nodep);
iterateChildrenConst(nodep);
m_cfuncp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
allNodes(nodep);
iterateChildrenConst(nodep);
}
}
virtual void visit(AstNode* nodep) override {
allNodes(nodep);

View File

@ -169,7 +169,7 @@ private:
// STATE
AstNodeModule* m_topModp = nullptr; // Module to add variables to
AstScope* m_topScopep = nullptr; // Scope to add variables to
AstCFunc* m_funcp = nullptr; // C function adding to graph
AstCFunc* m_cfuncp = nullptr; // C function adding to graph
AstTraceDecl* m_tracep = nullptr; // Trace function adding to graph
AstVarScope* m_activityVscp = nullptr; // Activity variable
uint32_t m_activityNumber = 0; // Count of fields in activity variable
@ -826,9 +826,11 @@ private:
new V3GraphEdge(&m_graph, activityVtxp, funcVtxp, 1);
}
}
m_funcp = nodep;
iterateChildren(nodep);
m_funcp = nullptr;
VL_RESTORER(m_cfuncp);
{
m_cfuncp = nodep;
iterateChildren(nodep);
}
}
virtual void visit(AstTraceDecl* nodep) override {
UINFO(8, " TRACE " << nodep << endl);
@ -836,7 +838,7 @@ private:
V3GraphVertex* const vertexp = new TraceTraceVertex(&m_graph, nodep);
nodep->user1p(vertexp);
UASSERT_OBJ(m_funcp, nodep, "Trace not under func");
UASSERT_OBJ(m_cfuncp, nodep, "Trace not under func");
m_tracep = nodep;
iterateChildren(nodep);
m_tracep = nullptr;
@ -857,9 +859,9 @@ private:
|| nodep->varp()->isSigPublic()) { // Or ones user can change
new V3GraphEdge(&m_graph, m_alwaysVtxp, traceVtxp, 1);
}
} else if (m_funcp && m_finding && nodep->access().isWrite()) {
} else if (m_cfuncp && m_finding && nodep->access().isWrite()) {
UASSERT_OBJ(nodep->varScopep(), nodep, "No var scope?");
V3GraphVertex* const funcVtxp = getCFuncVertexp(m_funcp);
V3GraphVertex* const funcVtxp = getCFuncVertexp(m_cfuncp);
V3GraphVertex* const varVtxp = nodep->varScopep()->user1u().toGraphVertex();
if (varVtxp) { // else we're not tracing this signal
new V3GraphEdge(&m_graph, funcVtxp, varVtxp, 1);