From 7fe0f9548d5136a06456798e5cdf197c956c78fd Mon Sep 17 00:00:00 2001 From: Pat Gavlin Date: Tue, 12 Jul 2016 14:48:52 -0700 Subject: [PATCH] Remove RenameUpdatedVars. The variable renaming performed by rationalize was originally intended (according to its comments) to allow assignments that were embedded in subtrees to be hoisted out into a preceding statement. It appears that this logic has been removed, so the rename pass is no longer needed. Commit migrated from https://github.com/dotnet/coreclr/commit/c30ee385bc69e677c29a3907daa4a460a20c6b5a --- src/coreclr/src/jit/rationalize.cpp | 145 ------------------------------------ src/coreclr/src/jit/rationalize.h | 12 --- 2 files changed, 157 deletions(-) diff --git a/src/coreclr/src/jit/rationalize.cpp b/src/coreclr/src/jit/rationalize.cpp index ba81b87..6c322fb 100644 --- a/src/coreclr/src/jit/rationalize.cpp +++ b/src/coreclr/src/jit/rationalize.cpp @@ -328,138 +328,6 @@ Compiler::fgInsertEmbeddedFormTemp(GenTree** ppTree, unsigned lclNum) return stmt; } -//------------------------------------------------------------------------------ -// RenameUpdatedVars - detect trees that have internal assignments with preceding reads -// of the variables being written. -// Replace the preceding reads with references to copies made in advance -// in order to make breaking out the assignments legal -//------------------------------------------------------------------------------ - -void Rationalizer::RenameUpdatedVars(Location loc) -{ - // A variable which is assigned within the tree will have different - // values at different points in the tree. The rationalizer tries to - // break internal assignments out into their own tree and place those trees before - // the original tree. This could result in changed meaning unless - // we have a way of differentiating between original and modified values - - GenTree *statement = loc.tree; - assert(statement->IsStatement()); - - GenTree *tree = loc.tree->gtStmt.gtStmtExpr; - - use->ZeroAll(); - usedef->ZeroAll(); - rename->ZeroAll(); - unexp->ZeroAll(); - - int *renameMap = (int *) alloca(sizeof(int) * comp->lvaCount); - var_types *renameTypeMap = (var_types *) alloca(sizeof(var_types) * comp->lvaCount); - - // find locals that are redefined within the tree - foreach_treenode_execution_order(tree, statement) - { - if (tree->IsLocal()) - { - int varIdx = tree->gtLclVarCommon.gtLclNum; - if (tree->gtFlags & GTF_VAR_DEF // definition - || tree->gtFlags & GTF_VAR_USEDEF // this is a use/def as in x=x+y (only the lhs x is tagged) - || tree->gtFlags & GTF_VAR_USEASG)// this is a use/def for a x=y - { - if (use->testBit(varIdx)) - { - usedef->setBit(varIdx); - } - else - { - unexp->setBit(varIdx); - } - } - else - { - if (usedef->testBit(varIdx)) - { - rename->setBit(varIdx); - renameTypeMap[varIdx] = tree->TypeGet(); - } - else - { - use->setBit(varIdx); // it's a plain use - } - } - } - } - - if (!rename->anySet()) - return; - - indexType index; - - // create the new variables and establish the mapping - // also insert copies before the statement - FOREACH_HBV_BIT_SET(index, rename) - { - JITDUMP("had to rename idx:%d in tree!\n", index); - DISPTREE(statement); - - unsigned tmpIndex = - renameMap[index] = - comp->lvaGrabTemp(true DEBUGARG("rationalize renaming")); - - LclVarDsc *newVar = &comp->lvaTable[tmpIndex]; - - newVar->lvType = renameTypeMap[index]; - - // Increment its lvRefCnt and lvRefCntWtd - comp->lvaTable[tmpIndex].incRefCnts(loc.block->getBBWeight(comp), comp); - - // only need a copy for exposed uses, otherwise a def is the first occurence - if (!unexp->testBit(index)) - { - GenTree *write = comp->gtNewAssignNode(comp->gtNewLclvNode(renameMap[index], newVar->TypeGet()), - comp->gtNewLclvNode((int)index, newVar->TypeGet())); - - write = comp->fgNewStmtFromTree(write, statement->gtStmt.gtStmtILoffsx); - comp->fgInsertStmtBefore(loc.block, statement, write); - - JITDUMP("New write tree:\n"); - DISPTREE(write); - } - } - NEXT_HBV_BIT_SET; - - hashBv *seenUse = hashBv::Create(this->comp); - hashBv *seenRedef = hashBv::Create(this->comp); - - // we are looking for a def after use - // don't just start renaming if it kicks off with a def - foreach_treenode_execution_order(tree, statement) - { - if (tree->IsLocal()) - { - int varIdx = tree->gtLclVarCommon.gtLclNum; - if (rename->testBit(varIdx)) - { - if (tree->gtFlags & GTF_VAR_DEF - //|| tree->gtFlags & GTF_VAR_USEDEF - || tree->gtFlags & GTF_VAR_USEASG) - { - if (seenUse->testBit(varIdx)) - seenRedef->setBit(varIdx); - } - else - { - seenUse->setBit(varIdx); - } - if (!seenRedef->testBit(varIdx)) - { - tree->gtLclVarCommon.SetLclNum(renameMap[varIdx]); - } - } - } - } -} - // return op that is the store equivalent of the given load opcode genTreeOps storeForm(genTreeOps loadForm) { @@ -1933,23 +1801,10 @@ void Rationalizer::DoPhase() comp->compCurBB = NULL; comp->fgOrder = Compiler::FGOrderLinear; - use = hashBv::Create(this->comp); // is used - usedef = hashBv::Create(this->comp); // is used and then defined - rename = hashBv::Create(this->comp); // is used, defined and used again - unexp = hashBv::Create(this->comp); // is unexposed - there is a def in this tree before any uses - // break up the trees at side effects, etc Location loc(comp->fgFirstBB); while (loc.block) { - RenameUpdatedVars(loc); - loc = loc.Next(); - } - - loc.Reset(comp); - - while (loc.block) - { loc = TreeTransformRationalization(loc); loc = loc.Next(); } diff --git a/src/coreclr/src/jit/rationalize.h b/src/coreclr/src/jit/rationalize.h index b6f6ee7..7d3b00b 100644 --- a/src/coreclr/src/jit/rationalize.h +++ b/src/coreclr/src/jit/rationalize.h @@ -89,23 +89,11 @@ private: class Rationalizer : public Phase { //=============================================================================== - // Data members - - // used for renaming updated variables - hashBv *use; - hashBv *usedef; - hashBv *rename; - hashBv *unexp; - - - //=============================================================================== // Methods public: Rationalizer(Compiler* comp); Location TreeTransformRationalization (Location loc); - void RenameUpdatedVars(Location loc); - #ifdef DEBUG static void ValidateStatement(Location loc); -- 2.7.4