void SsaRenameState::PopBlockStacks(BasicBlock* block) { DBG_SSA_JITDUMP("[SsaRenameState::PopBlockStacks] BB%02u\n", block->bbNum); // Iterate over the stacks for all the variables, popping those that have an entry // for "block" on top. while (!definedLocs.empty() && definedLocs.back().m_bb == block) { unsigned lclNum = definedLocs.back().m_lclNum; assert(stacks != NULL); // Cannot be empty because definedLocs is not empty. Stack* stack = stacks[lclNum]; assert(stack != NULL); assert(stack->back().m_bb == block); stack->pop_back(); definedLocs.pop_back(); } #ifdef DEBUG // It should now be the case that no stack in stacks has an entry for "block" on top -- // the loop above popped them all. for (unsigned i = 0; i < lvaCount; ++i) { if (stacks != NULL && stacks[i] != NULL && !stacks[i]->empty()) { assert(stacks[i]->back().m_bb != block); } } if (JitTls::GetCompiler()->verboseSsa) { DumpStacks(); } #endif // DEBUG }
/** * 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 }