Skip to content

Commit

Permalink
Find who needs new stmts from impAssignStructPtr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Andreenko committed Jan 6, 2020
1 parent efba255 commit 0867566
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 56 deletions.
6 changes: 1 addition & 5 deletions src/coreclr/src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3780,11 +3780,7 @@ class Compiler
CORINFO_CLASS_HANDLE structHnd,
const impAssignPlace& asgPlace,
IL_OFFSETX ilOffset = BAD_IL_OFFSET);
GenTree* impAssignStructPtr(GenTree* dest,
GenTree* src,
CORINFO_CLASS_HANDLE structHnd,
const impAssignPlace& asgPlace,
IL_OFFSETX ilOffset = BAD_IL_OFFSET);
GenTree* impAssignStructPtr(GenTree* dest, GenTree* src, CORINFO_CLASS_HANDLE structHnd);

GenTree* impGetStructAddr(GenTree* structVal, CORINFO_CLASS_HANDLE structHnd, unsigned curLevel, bool willDeref);

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15055,7 +15055,7 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr,
{
if (varTypeIsStruct(lclTyp))
{
result = impAssignStructPtr(result, assg, structType, impAssignPlace::s_SpillAll);
result = impAssignStructPtr(result, assg, structType);
}
else
{
Expand Down
65 changes: 15 additions & 50 deletions src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ GenTree* Compiler::impAssignStruct(GenTree* dest,
destAddr = gtNewOperNode(GT_ADDR, TYP_BYREF, dest);
}

return impAssignStructPtr(destAddr, src, structHnd, asgPlace, ilOffset);
return impAssignStructPtr(destAddr, src, structHnd);
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1159,21 +1159,11 @@ GenTree* Compiler::impAssignStruct(GenTree* dest,
//
//

GenTree* Compiler::impAssignStructPtr(GenTree* destAddr,
GenTree* src,
CORINFO_CLASS_HANDLE structHnd,
const impAssignPlace& asgPlace,
IL_OFFSETX ilOffset /* = BAD_IL_OFFSET */
)
GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, GenTree* src, CORINFO_CLASS_HANDLE structHnd)
{
GenTree* dest = nullptr;
unsigned destFlags = 0;

if (ilOffset == BAD_IL_OFFSET)
{
ilOffset = impCurStmtOffs;
}

assert(src->OperIs(GT_LCL_VAR, GT_FIELD, GT_IND, GT_OBJ, GT_CALL, GT_MKREFANY, GT_RET_EXPR, GT_COMMA) ||
(src->TypeGet() != TYP_STRUCT && (src->OperIsSimdOrHWintrinsic() || src->OperIs(GT_LCL_FLD))));

Expand Down Expand Up @@ -1307,14 +1297,12 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr,
}
else if (src->gtOper == GT_MKREFANY)
{
assert(fgImportPhase && !asgPlace.useStmts); // GT_MKREFANY can come only from impImportBlockCode.
assert(fgImportPhase); // GT_MKREFANY can come only from impImportBlockCode.

// Since we are assigning the result of a GT_MKREFANY,
// "destAddr" must point to a refany.

GenTree* destAddrClone;
destAddr =
impCloneExpr(destAddr, &destAddrClone, structHnd, asgPlace.spillLevel DEBUGARG("MKREFANY assignment"));
GenTree* destAddrClone = gtCloneExpr(destAddr);

assert(OFFSETOF__CORINFO_TypedReference__dataPtr == 0);
assert(destAddr->gtType == TYP_I_IMPL || destAddr->gtType == TYP_BYREF);
Expand All @@ -1326,40 +1314,17 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr,
GenTree* typeSlot =
gtNewOperNode(GT_IND, TYP_I_IMPL, gtNewOperNode(GT_ADD, destAddr->gtType, destAddrClone, typeFieldOffset));

// append the assign of the pointer value
GenTree* asg = gtNewAssignNode(ptrSlot, src->AsOp()->gtOp1);
impAppendTree(asg, asgPlace.spillLevel, ilOffset);

// return the assign of the type value, to be appended
return gtNewAssignNode(typeSlot, src->AsOp()->gtOp2);
GenTree* asgOp1 = gtNewAssignNode(ptrSlot, src->AsOp()->gtOp1);
GenTree* asgOp2 = gtNewAssignNode(typeSlot, src->AsOp()->gtOp2);
GenTree* commaOfBoth = gtNewOperNode(GT_COMMA, asgOp2->gtType, asgOp1, asgOp2);
return commaOfBoth;
}
else if (src->gtOper == GT_COMMA)
{
// The second thing is the struct or its address.
assert(varTypeIsStruct(src->AsOp()->gtOp2) || src->AsOp()->gtOp2->gtType == TYP_BYREF);
if (asgPlace.useStmts)
{
// Insert op1 after '*pAfterStmt'
Statement* newStmt = gtNewStmt(src->AsOp()->gtOp1, ilOffset);
fgInsertStmtAfter(asgPlace.block, *asgPlace.pAfterStmt, newStmt);
*asgPlace.pAfterStmt = newStmt;
}
else if (impLastStmt != nullptr)
{
// Do the side-effect as a separate statement.
impAppendTree(src->AsOp()->gtOp1, asgPlace.spillLevel, ilOffset);
}
else
{
// In this case we have neither been given a statement to insert after, nor are we
// in the importer where we can append the side effect.
// Instead, we're going to sink the assignment below the COMMA.
src->AsOp()->gtOp2 = impAssignStructPtr(destAddr, src->AsOp()->gtOp2, structHnd, asgPlace, ilOffset);
return src;
}

// Evaluate the second thing using recursion.
return impAssignStructPtr(destAddr, src->AsOp()->gtOp2, structHnd, asgPlace, ilOffset);
// Use the entire comma expression as our rhs.
asgType = impNormStructType(structHnd);
}
else if (src->IsLocal())
{
Expand Down Expand Up @@ -6040,7 +6005,7 @@ void Compiler::impImportAndPushBox(CORINFO_RESOLVED_TOKEN* pResolvedToken)
if (varTypeIsStruct(exprToBox))
{
assert(info.compCompHnd->getClassSize(pResolvedToken->hClass) == info.compCompHnd->getClassSize(operCls));
op1 = impAssignStructPtr(op1, exprToBox, operCls, impAssignPlace::s_SpillAll);
op1 = impAssignStructPtr(op1, exprToBox, operCls);
}
else
{
Expand Down Expand Up @@ -15817,7 +15782,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)

assertImp(varTypeIsStruct(op2));

op1 = impAssignStructPtr(op1, op2, resolvedToken.hClass, impAssignPlace::s_SpillAll);
op1 = impAssignStructPtr(op1, op2, resolvedToken.hClass);

if (op1->OperIsBlkOp() && (prefixFlags & PREFIX_UNALIGNED))
{
Expand Down Expand Up @@ -16626,12 +16591,12 @@ bool Compiler::impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE&
{
impInlineInfo->retExpr =
impAssignStructPtr(dest, gtNewLclvNode(lvaInlineeReturnSpillTemp, info.compRetType),
retClsHnd, impAssignPlace::s_SpillAll);
retClsHnd);
}
}
else
{
impInlineInfo->retExpr = impAssignStructPtr(dest, op2, retClsHnd, impAssignPlace::s_SpillAll);
impInlineInfo->retExpr = impAssignStructPtr(dest, op2, retClsHnd);
}
}
}
Expand All @@ -16653,7 +16618,7 @@ bool Compiler::impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE&
// Assign value to return buff (first param)
GenTree* retBuffAddr = gtNewLclvNode(info.compRetBuffArg, TYP_BYREF DEBUGARG(impCurStmtOffs));

op2 = impAssignStructPtr(retBuffAddr, op2, retClsHnd, impAssignPlace::s_SpillAll);
op2 = impAssignStructPtr(retBuffAddr, op2, retClsHnd);
impAppendTree(op2, (unsigned)CHECK_SPILL_NONE, impCurStmtOffs);

// There are cases where the address of the implicit RetBuf should be returned explicitly (in RAX).
Expand Down

0 comments on commit 0867566

Please sign in to comment.