Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,18 +687,30 @@ GenTreeStmt* Compiler::impExtractLastStmt()
return stmt;
}

/*****************************************************************************
*
* Insert the given GT_STMT "stmt" before GT_STMT "stmtBefore"
*/

//-------------------------------------------------------------------------
// impInsertStmtBefore: Insert the given GT_STMT "stmt" before GT_STMT "stmtBefore".
//
// Arguments:
// stmt - a statement to insert;
// stmtBefore - an insertion point to insert "stmt" before.
//
inline void Compiler::impInsertStmtBefore(GenTreeStmt* stmt, GenTreeStmt* stmtBefore)
Copy link
Copy Markdown
Author

@sandreenko sandreenko Apr 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function and impInsertTreeBefore have only one use each. I think they will go away soon so that is why they do not need more checks/cleaning right now.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust you on that - though this is a bit confusing and I would have asked for a few more comments otherwise ;-)

{
GenTreeStmt* stmtPrev = stmtBefore->getPrevStmt();
stmt->gtPrev = stmtPrev;
stmt->gtNext = stmtBefore;
stmtPrev->gtNext = stmt;
stmtBefore->gtPrev = stmt;
assert(stmt != nullptr);
assert(stmtBefore != nullptr);

if (stmtBefore == impStmtList)
{
impStmtList = stmt;
}
else
{
GenTreeStmt* stmtPrev = stmtBefore->getPrevStmt();
stmt->gtPrev = stmtPrev;
stmtPrev->gtNext = stmt;
}
stmt->gtNext = stmtBefore;
stmtBefore->gtPrev = stmt;
}

/*****************************************************************************
Expand Down Expand Up @@ -1476,7 +1488,19 @@ GenTree* Compiler::impGetStructAddr(GenTree* structVal,
// for Op2, but that would be out of order with op1, so we need to
// spill op1 onto the statement list after whatever was last
// before we recursed on Op2 (i.e. before whatever Op2 appended).
impInsertTreeBefore(structVal->gtOp.gtOp1, impCurStmtOffs, oldLastStmt->getNextStmt());
GenTreeStmt* beforeStmt;
if (oldLastStmt == nullptr)
{
// The op1 stmt should be the first in the list.
beforeStmt = impStmtList;
}
else
{
// Insert after the oldLastStmt before the first inserted for op2.
beforeStmt = oldLastStmt->getNextStmt();
}

impInsertTreeBefore(structVal->gtOp.gtOp1, impCurStmtOffs, beforeStmt);
structVal->gtOp.gtOp1 = gtNewNothingNode();
}

Expand Down