summaryrefslogtreecommitdiff
path: root/src/jit/gentree.cpp
diff options
context:
space:
mode:
authorSergey Andreenko <seandree@microsoft.com>2019-03-29 15:17:37 -0700
committerGitHub <noreply@github.com>2019-03-29 15:17:37 -0700
commit311b5e2fe413c6c74a2a3680ab54d8a978651472 (patch)
tree34b80e7da951ba003d59b42f14f928c84a4a02c2 /src/jit/gentree.cpp
parent4a4ba4d379002c8b8e77ef968f510cf0283201d0 (diff)
downloadcoreclr-311b5e2fe413c6c74a2a3680ab54d8a978651472.tar.gz
coreclr-311b5e2fe413c6c74a2a3680ab54d8a978651472.tar.bz2
coreclr-311b5e2fe413c6c74a2a3680ab54d8a978651472.zip
Use GenTreeStmt* where it is implied. (#22963)
* Extract `impAppendStmt` and `impExtractLastStmt`. * Delete `BEG_STMTS` fake stmt. Use new functions to keep the list updated. * Retype `impTreeList` and `impTreeLast` as statements. Rename `impTreeList` and `impTreeLast` to show that they are statements. * Fix fields that have to be stmt. * Start using GenTreeStmt. Change `optVNAssertionPropCurStmt` to use GenTreeStmt. Replace `GenTree* stmt = block->bbTreeList` with `GenTreeStmt* stmt = block->firstStmt()`. Save results of `FirstNonPhiDef` as `GenTreeStmt`. * Replace do-while with for loop. * Change type inside VNAssertionPropVisitorInfo. * Delete unused args fron `optVNConstantPropOnTree`. * Update fields to be stmt. Update optVNConstantPropCurStmt to use Stmt. Change `lvDefStmt` to stmt. Update LoopCloning structs. Update `optDebugLogLoopCloning`. Make `compCurStmt` a statement. Update declaration name in `BuildNode`. * Clean simple cpp files. Clean valuenum. Clean ssabuilder. Clean simd. Clean optcse. Clean loopcloning. Clean copyprop. Clean optimizer part1. * Start cleaning importer, morph, flowgraph, gentree. * Continue clean functons. Clean assertionprop. Clean morph. Clean gentree. Clean flowgraph. Clean compiler. Clean rangecheck. Clean indirectcalltransofrmer. Clean others. * Create some temp stmt. * Delete unnecessary noway_assert and casts. * Init `impStmtList` and `impLastStmt` in release. * Response review 1.
Diffstat (limited to 'src/jit/gentree.cpp')
-rw-r--r--src/jit/gentree.cpp84
1 files changed, 37 insertions, 47 deletions
diff --git a/src/jit/gentree.cpp b/src/jit/gentree.cpp
index 69e774cf9b..833d115cb2 100644
--- a/src/jit/gentree.cpp
+++ b/src/jit/gentree.cpp
@@ -571,17 +571,11 @@ void GenTree::DumpNodeSizes(FILE* fp)
void Compiler::fgWalkAllTreesPre(fgWalkPreFn* visitor, void* pCallBackData)
{
- BasicBlock* block;
-
- for (block = fgFirstBB; block; block = block->bbNext)
+ for (BasicBlock* block = fgFirstBB; block != nullptr; block = block->bbNext)
{
- GenTree* tree;
-
- for (tree = block->bbTreeList; tree; tree = tree->gtNext)
+ for (GenTreeStmt* stmt = block->firstStmt(); stmt != nullptr; stmt = stmt->getNextStmt())
{
- assert(tree->gtOper == GT_STMT);
-
- fgWalkTreePre(&tree->gtStmt.gtStmtExpr, visitor, pCallBackData);
+ fgWalkTreePre(&stmt->gtStmtExpr, visitor, pCallBackData);
}
}
}
@@ -3591,7 +3585,7 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
// under a struct assignment would not be considered for addressing modes.
if (compCurStmt != nullptr)
{
- GenTree* expr = compCurStmt->gtStmt.gtStmtExpr;
+ GenTree* expr = compCurStmt->gtStmtExpr;
if ((expr->OperGet() == GT_ASG) &&
((expr->gtGetOp1() == tree) || (expr->gtGetOp2() == tree)))
{
@@ -7619,7 +7613,7 @@ GenTreeCall* Compiler::gtCloneCandidateCall(GenTreeCall* call)
// but this method will sequence 'replacementTree', and insert it into the
// proper place in the statement sequence.
-GenTree* Compiler::gtReplaceTree(GenTree* stmt, GenTree* tree, GenTree* replacementTree)
+GenTree* Compiler::gtReplaceTree(GenTreeStmt* stmt, GenTree* tree, GenTree* replacementTree)
{
assert(fgStmtListThreaded);
assert(tree != nullptr);
@@ -7629,14 +7623,14 @@ GenTree* Compiler::gtReplaceTree(GenTree* stmt, GenTree* tree, GenTree* replacem
GenTree** treePtr = nullptr;
GenTree* treeParent = tree->gtGetParent(&treePtr);
- assert(treeParent != nullptr || tree == stmt->gtStmt.gtStmtExpr);
+ assert(treeParent != nullptr || tree == stmt->gtStmtExpr);
if (treePtr == nullptr)
{
// Replace the stmt expr and rebuild the linear order for "stmt".
assert(treeParent == nullptr);
assert(fgOrder != FGOrderLinear);
- stmt->gtStmt.gtStmtExpr = tree;
+ stmt->gtStmtExpr = tree;
fgSetStmtSeq(stmt);
}
else
@@ -7683,8 +7677,8 @@ GenTree* Compiler::gtReplaceTree(GenTree* stmt, GenTree* tree, GenTree* replacem
{
// Update the linear oder start of "stmt" if treeFirstNode
// appears to have replaced the original first node.
- assert(treeFirstNode == stmt->gtStmt.gtStmtList);
- stmt->gtStmt.gtStmtList = fgGetFirstNode(replacementTree);
+ assert(treeFirstNode == stmt->gtStmtList);
+ stmt->gtStmtList = fgGetFirstNode(replacementTree);
}
if (treeNextNode != nullptr)
@@ -7708,7 +7702,7 @@ GenTree* Compiler::gtReplaceTree(GenTree* stmt, GenTree* tree, GenTree* replacem
// Note: If tree's order hasn't been established, the method updates side effect
// flags on all statement's nodes.
-void Compiler::gtUpdateSideEffects(GenTree* stmt, GenTree* tree)
+void Compiler::gtUpdateSideEffects(GenTreeStmt* stmt, GenTree* tree)
{
if (fgStmtListThreaded)
{
@@ -7743,9 +7737,9 @@ void Compiler::gtUpdateTreeAncestorsSideEffects(GenTree* tree)
// Arguments:
// stmt - The statement to update side effects on
-void Compiler::gtUpdateStmtSideEffects(GenTree* stmt)
+void Compiler::gtUpdateStmtSideEffects(GenTreeStmt* stmt)
{
- fgWalkTree(&stmt->gtStmt.gtStmtExpr, fgUpdateSideEffectsPre, fgUpdateSideEffectsPost);
+ fgWalkTree(&stmt->gtStmtExpr, fgUpdateSideEffectsPre, fgUpdateSideEffectsPost);
}
//------------------------------------------------------------------------
@@ -9705,16 +9699,17 @@ void Compiler::gtDispNode(GenTree* tree, IndentStack* indentStack, __in __in_z _
{
if (opts.compDbgInfo)
{
- IL_OFFSET endIL = tree->gtStmt.gtStmtLastILoffs;
+ GenTreeStmt* stmt = tree->AsStmt();
+ IL_OFFSET endIL = stmt->gtStmtLastILoffs;
printf("(IL ");
- if (tree->gtStmt.gtStmtILoffsx == BAD_IL_OFFSET)
+ if (stmt->gtStmtILoffsx == BAD_IL_OFFSET)
{
printf(" ???");
}
else
{
- printf("0x%03X", jitGetILoffs(tree->gtStmt.gtStmtILoffsx));
+ printf("0x%03X", jitGetILoffs(stmt->gtStmtILoffsx));
}
printf("...");
if (endIL == BAD_IL_OFFSET)
@@ -12572,12 +12567,9 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
assert(op->IsBoxedValue());
// grab related parts for the optimization
- GenTreeBox* box = op->AsBox();
- GenTree* asgStmt = box->gtAsgStmtWhenInlinedBoxValue;
- GenTree* copyStmt = box->gtCopyStmtWhenInlinedBoxValue;
-
- assert(asgStmt->gtOper == GT_STMT);
- assert(copyStmt->gtOper == GT_STMT);
+ GenTreeBox* box = op->AsBox();
+ GenTreeStmt* asgStmt = box->gtAsgStmtWhenInlinedBoxValue;
+ GenTreeStmt* copyStmt = box->gtCopyStmtWhenInlinedBoxValue;
JITDUMP("gtTryRemoveBoxUpstreamEffects: %s to %s of BOX (valuetype)"
" [%06u] (assign/newobj [%06u] copy [%06u])\n",
@@ -12586,7 +12578,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
dspTreeID(asgStmt), dspTreeID(copyStmt));
// If we don't recognize the form of the assign, bail.
- GenTree* asg = asgStmt->gtStmt.gtStmtExpr;
+ GenTree* asg = asgStmt->gtStmtExpr;
if (asg->gtOper != GT_ASG)
{
JITDUMP(" bailing; unexpected assignment op %s\n", GenTree::OpName(asg->gtOper));
@@ -12633,7 +12625,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
}
// If we don't recognize the form of the copy, bail.
- GenTree* copy = copyStmt->gtStmt.gtStmtExpr;
+ GenTree* copy = copyStmt->gtStmtExpr;
if (copy->gtOper != GT_ASG)
{
// GT_RET_EXPR is a tolerable temporary failure.
@@ -12788,7 +12780,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
// value as the copy is fairly cheap and likely
// the optimizer can trim things down to just the
// minimal side effect parts.
- copyStmt->gtStmt.gtStmtExpr = copySrc;
+ copyStmt->gtStmtExpr = copySrc;
JITDUMP(" to scalar read via [%06u]\n", dspTreeID(copySrc));
}
else
@@ -12797,7 +12789,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
// source struct; there's no need to read the
// entire thing, and no place to put it.
assert(copySrc->gtOper == GT_OBJ || copySrc->gtOper == GT_IND || copySrc->gtOper == GT_FIELD);
- copyStmt->gtStmt.gtStmtExpr = copySrc;
+ copyStmt->gtStmtExpr = copySrc;
if (options == BR_REMOVE_AND_NARROW || options == BR_REMOVE_AND_NARROW_WANT_TYPE_HANDLE)
{
@@ -12950,11 +12942,11 @@ GenTree* Compiler::gtOptimizeEnumHasFlag(GenTree* thisOp, GenTree* flagOp)
}
else
{
- const unsigned thisTmp = lvaGrabTemp(true DEBUGARG("Enum:HasFlag this temp"));
- GenTree* thisAsg = gtNewTempAssign(thisTmp, thisVal);
- GenTree* thisAsgStmt = thisOp->AsBox()->gtCopyStmtWhenInlinedBoxValue;
- thisAsgStmt->gtStmt.gtStmtExpr = thisAsg;
- thisValOpt = gtNewLclvNode(thisTmp, type);
+ const unsigned thisTmp = lvaGrabTemp(true DEBUGARG("Enum:HasFlag this temp"));
+ GenTree* thisAsg = gtNewTempAssign(thisTmp, thisVal);
+ GenTreeStmt* thisAsgStmt = thisOp->AsBox()->gtCopyStmtWhenInlinedBoxValue;
+ thisAsgStmt->gtStmtExpr = thisAsg;
+ thisValOpt = gtNewLclvNode(thisTmp, type);
}
if (flagVal->IsIntegralConst())
@@ -12966,12 +12958,12 @@ GenTree* Compiler::gtOptimizeEnumHasFlag(GenTree* thisOp, GenTree* flagOp)
}
else
{
- const unsigned flagTmp = lvaGrabTemp(true DEBUGARG("Enum:HasFlag flag temp"));
- GenTree* flagAsg = gtNewTempAssign(flagTmp, flagVal);
- GenTree* flagAsgStmt = flagOp->AsBox()->gtCopyStmtWhenInlinedBoxValue;
- flagAsgStmt->gtStmt.gtStmtExpr = flagAsg;
- flagValOpt = gtNewLclvNode(flagTmp, type);
- flagValOptCopy = gtNewLclvNode(flagTmp, type);
+ const unsigned flagTmp = lvaGrabTemp(true DEBUGARG("Enum:HasFlag flag temp"));
+ GenTree* flagAsg = gtNewTempAssign(flagTmp, flagVal);
+ GenTreeStmt* flagAsgStmt = flagOp->AsBox()->gtCopyStmtWhenInlinedBoxValue;
+ flagAsgStmt->gtStmtExpr = flagAsg;
+ flagValOpt = gtNewLclvNode(flagTmp, type);
+ flagValOptCopy = gtNewLclvNode(flagTmp, type);
}
// Turn the call into (thisValTmp & flagTmp) == flagTmp.
@@ -14425,7 +14417,7 @@ DONE:
// May set compFloatingPointUsed.
GenTree* Compiler::gtNewTempAssign(
- unsigned tmp, GenTree* val, GenTree** pAfterStmt, IL_OFFSETX ilOffset, BasicBlock* block)
+ unsigned tmp, GenTree* val, GenTreeStmt** pAfterStmt, IL_OFFSETX ilOffset, BasicBlock* block)
{
// Self-assignment is a nop.
if (val->OperGet() == GT_LCL_VAR && val->gtLclVarCommon.gtLclNum == tmp)
@@ -15157,13 +15149,11 @@ static Compiler::fgWalkResult gtFindLinkCB(GenTree** pTree, Compiler::fgWalkData
return Compiler::WALK_CONTINUE;
}
-GenTree** Compiler::gtFindLink(GenTree* stmt, GenTree* node)
+GenTree** Compiler::gtFindLink(GenTreeStmt* stmt, GenTree* node)
{
- assert(stmt->gtOper == GT_STMT);
-
FindLinkData data = {node, nullptr};
- fgWalkResult result = fgWalkTreePre(&stmt->gtStmt.gtStmtExpr, gtFindLinkCB, &data);
+ fgWalkResult result = fgWalkTreePre(&stmt->gtStmtExpr, gtFindLinkCB, &data);
if (result == WALK_ABORT)
{