From c7f0fcd1b79256ae9a69c0e918e428091099220a Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Thu, 25 Apr 2019 16:05:51 -0700 Subject: [PATCH] Change gtFindLink to return parent as well. Commit migrated from https://github.com/dotnet/coreclr/commit/332bd2ec8a6bad66e1fb9b2dc3cf37e9e4d77727 --- src/coreclr/src/jit/assertionprop.cpp | 3 ++- src/coreclr/src/jit/compiler.h | 9 ++++++++- src/coreclr/src/jit/gentree.cpp | 21 ++++++++++----------- src/coreclr/src/jit/optcse.cpp | 3 ++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/coreclr/src/jit/assertionprop.cpp b/src/coreclr/src/jit/assertionprop.cpp index cd1b90f..3d5e0ed 100644 --- a/src/coreclr/src/jit/assertionprop.cpp +++ b/src/coreclr/src/jit/assertionprop.cpp @@ -3901,7 +3901,8 @@ GenTree* Compiler::optAssertionProp_Update(GenTree* newTree, GenTree* tree, GenT // locate our parent node and update it so that it points to newTree. if (newTree != tree) { - GenTree** link = gtFindLink(stmt, tree); + FindLinkData linkData = gtFindLink(stmt, tree); + GenTree** link = linkData.result; noway_assert(link != nullptr); // Replace the old operand with the newTree diff --git a/src/coreclr/src/jit/compiler.h b/src/coreclr/src/jit/compiler.h index b091c92..fed7003 100644 --- a/src/coreclr/src/jit/compiler.h +++ b/src/coreclr/src/jit/compiler.h @@ -2994,7 +2994,14 @@ public: static fgWalkPreFn gtMarkColonCond; static fgWalkPreFn gtClearColonCond; - GenTree** gtFindLink(GenTreeStmt* stmt, GenTree* node); + struct FindLinkData + { + GenTree* nodeToFind; + GenTree** result; + GenTree* parent; + }; + + FindLinkData gtFindLink(GenTreeStmt* stmt, GenTree* node); bool gtHasCatchArg(GenTree* tree); typedef ArrayStack GenTreeStack; diff --git a/src/coreclr/src/jit/gentree.cpp b/src/coreclr/src/jit/gentree.cpp index 5be0160..f5a7982 100644 --- a/src/coreclr/src/jit/gentree.cpp +++ b/src/coreclr/src/jit/gentree.cpp @@ -7948,6 +7948,9 @@ GenTree* Compiler::gtGetThisArg(GenTreeCall* call) fgArgTabEntry* thisArgTabEntry = gtArgEntryByArgNum(call, argNum); GenTree* result = thisArgTabEntry->node; + // Assert if we used DEBUG_DESTROY_NODE. + assert(result->gtOper != GT_COUNT); + #if !FEATURE_FIXED_OUT_ARGS && defined(DEBUG) // Check that call->fgArgInfo used in gtArgEntryByArgNum was not // left outdated by assertion propogation updates. @@ -7972,6 +7975,7 @@ GenTree* Compiler::gtGetThisArg(GenTreeCall* call) index++; } #endif // !FEATURE_FIXED_OUT_ARGS && defined(DEBUG) + return result; } } @@ -15162,42 +15166,37 @@ Compiler::fgWalkResult Compiler::gtClearColonCond(GenTree** pTree, fgWalkData* d return WALK_CONTINUE; } -struct FindLinkData -{ - GenTree* nodeToFind; - GenTree** result; -}; - /***************************************************************************** * * Callback used by the tree walker to implement fgFindLink() */ static Compiler::fgWalkResult gtFindLinkCB(GenTree** pTree, Compiler::fgWalkData* cbData) { - FindLinkData* data = (FindLinkData*)cbData->pCallbackData; + Compiler::FindLinkData* data = (Compiler::FindLinkData*)cbData->pCallbackData; if (*pTree == data->nodeToFind) { data->result = pTree; + data->parent = cbData->parent; return Compiler::WALK_ABORT; } return Compiler::WALK_CONTINUE; } -GenTree** Compiler::gtFindLink(GenTreeStmt* stmt, GenTree* node) +Compiler::FindLinkData Compiler::gtFindLink(GenTreeStmt* stmt, GenTree* node) { - FindLinkData data = {node, nullptr}; + FindLinkData data = {node, nullptr, nullptr}; fgWalkResult result = fgWalkTreePre(&stmt->gtStmtExpr, gtFindLinkCB, &data); if (result == WALK_ABORT) { assert(data.nodeToFind == *data.result); - return data.result; + return data; } else { - return nullptr; + return {node, nullptr, nullptr}; } } diff --git a/src/coreclr/src/jit/optcse.cpp b/src/coreclr/src/jit/optcse.cpp index 3178932..d813fdd 100644 --- a/src/coreclr/src/jit/optcse.cpp +++ b/src/coreclr/src/jit/optcse.cpp @@ -2364,7 +2364,8 @@ public: // Walk the statement 'stmt' and find the pointer // in the tree is pointing to 'exp' // - GenTree** link = m_pCompiler->gtFindLink(stmt, exp); + Compiler::FindLinkData linkData = m_pCompiler->gtFindLink(stmt, exp); + GenTree** link = linkData.result; #ifdef DEBUG if (link == nullptr) -- 2.7.4