/** * Print the stack data for each variable in a loop. */ void SsaRenameState::DumpStacks() { printf("Dumping stacks:\n-------------------------------\n"); if (lvaCount == 0) { printf("None\n"); } else { EnsureStacks(); for (unsigned i = 0; i < lvaCount; ++i) { Stack* stack = stacks[i]; printf("V%02u:\t", i); if (stack != NULL) { for (Stack::iterator iter2 = stack->begin(); iter2 != stack->end(); ++iter2) { if (iter2 != stack->begin()) { printf(", "); } printf("<BB%02u, %2d>", ((*iter2).m_bb != nullptr ? (*iter2).m_bb->bbNum : 0), (*iter2).m_count); } } printf("\n"); } } }
/** * Returns a SSA count number for a local variable from top of the stack. * * @params lclNum The local variable def for which a count has to be returned. * @return the current variable name for the "use". * * @remarks If the stack is empty, then we have an use before a def. To handle this * special case, we need to initialize the count with 'default+1', so the * next definition will always use 'default+1' but return 'default' for * all uses until a definition. * */ unsigned SsaRenameState::CountForUse(unsigned lclNum) { EnsureStacks(); DBG_SSA_JITDUMP("[SsaRenameState::CountForUse] V%02u\n", lclNum); Stack* stack = stacks[lclNum]; noway_assert((stack != nullptr) && !stack->empty()); return stack->back().m_count; }
/** * Returns a SSA count number for a local variable from top of the stack. * * @params lclNum The local variable def for which a count has to be returned. * @return the current variable name for the "use". * * @remarks If the stack is empty, then we have an use before a def. To handle this * special case, we need to initialize the count with 'default+1', so the * next definition will always use 'default+1' but return 'default' for * all uses until a definition. * */ unsigned SsaRenameState::CountForUse(unsigned lclNum) { EnsureStacks(); DBG_SSA_JITDUMP("[SsaRenameState::CountForUse] V%02u\n", lclNum); Stack* stack = stacks[lclNum]; if (stack == NULL || stack->empty()) { return SsaConfig::UNINIT_SSA_NUM; } return stack->back().m_count; }
/** * Pushes a count value on the variable stack. * * @params lclNum The local variable def whose stack the count needs to be pushed onto. * @params count The current count value that needs to be pushed on to the stack. * * @remarks Usually called when renaming a "def." * Create stack lazily when needed for the first time. */ void SsaRenameState::Push(BasicBlock* bb, unsigned lclNum, unsigned count) { EnsureStacks(); // We'll use BB00 here to indicate the "block before any real blocks..." DBG_SSA_JITDUMP("[SsaRenameState::Push] " FMT_BB ", V%02u, count = %d\n", bb != nullptr ? bb->bbNum : 0, lclNum, count); Stack* stack = stacks[lclNum]; if (stack == nullptr) { DBG_SSA_JITDUMP("\tCreating a new stack\n"); stack = stacks[lclNum] = new (m_alloc) Stack(m_alloc); } if (stack->empty() || stack->back().m_bb != bb) { stack->push_back(SsaRenameStateForBlock(bb, count)); // Remember that we've pushed a def for this loc (so we don't have // to traverse *all* the locs to do the necessary pops later). definedLocs.push_back(SsaRenameStateLocDef(bb, lclNum)); } else { stack->back().m_count = count; } #ifdef DEBUG if (JitTls::GetCompiler()->verboseSsa) { printf("\tContents of the stack: ["); for (Stack::iterator iter2 = stack->begin(); iter2 != stack->end(); iter2++) { printf("<" FMT_BB ", %d>", ((*iter2).m_bb != nullptr ? (*iter2).m_bb->bbNum : 0), (*iter2).m_count); } printf("]\n"); DumpStacks(); } #endif }