Skip to content

Commit

Permalink
JIT: Use AllocObj for box allocations
Browse files Browse the repository at this point in the history
Model box object allocations using the AllocObj tree node. Update
the box deconstruction utility to compensate.

Also set the OMF_HAS_NEWOBJ flag when we generate Box IR; this both
fixes an oversight from before and is a necessary step to trigger the
morphing of AllocObj into a helper call.

No diffs.

Closes #13905.
  • Loading branch information
AndyAyersMS committed Sep 14, 2017
1 parent 6ac4c99 commit dd0a673
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
29 changes: 22 additions & 7 deletions src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12525,13 +12525,28 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
GenTree* boxTypeHandle = nullptr;
if (options == BR_REMOVE_AND_NARROW_WANT_TYPE_HANDLE)
{
// Note we might see GenTreeAllocObj here, if impImportAndPushBox
// starts using it instead of a bare helper call.
GenTree* asgSrc = asg->gtOp.gtOp2;
assert(asgSrc->IsCall());
GenTreeCall* newobjCall = asgSrc->AsCall();
GenTreeArgList* newobjArgs = newobjCall->gtCallArgs->AsArgList();
boxTypeHandle = newobjArgs->Current();
GenTree* asgSrc = asg->gtOp.gtOp2;
genTreeOps asgSrcOper = asgSrc->OperGet();

// Allocation may be via AllocObj or via helper call, depending
// on when this is invoked and whether the jit is using AllocObj
// for R2R allocations.
if (asgSrcOper == GT_ALLOCOBJ)
{
GenTreeAllocObj* allocObj = asgSrc->AsAllocObj();
boxTypeHandle = allocObj->gtOp.gtOp1;
}
else if (asgSrcOper == GT_CALL)
{
GenTreeCall* newobjCall = asgSrc->AsCall();
GenTreeArgList* newobjArgs = newobjCall->gtCallArgs->AsArgList();
boxTypeHandle = newobjArgs->Current();
}
else
{
unreached();
}

assert(boxTypeHandle != nullptr);
}

Expand Down
7 changes: 4 additions & 3 deletions src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5449,12 +5449,13 @@ void Compiler::impImportAndPushBox(CORINFO_RESOLVED_TOKEN* pResolvedToken)
return;
}

op1 = gtNewHelperCallNode(info.compCompHnd->getNewHelper(pResolvedToken, info.compMethodHnd), TYP_REF,
gtNewArgList(op2));
op1 = gtNewAllocObjNode(info.compCompHnd->getNewHelper(pResolvedToken, info.compMethodHnd),
pResolvedToken->hClass, TYP_REF, op2);
}

/* Remember that this basic block contains 'new' of an object */
/* Remember that this basic block contains 'new' of an object, and so does this method */
compCurBB->bbFlags |= BBF_HAS_NEWOBJ;
optMethodFlags |= OMF_HAS_NEWOBJ;

GenTreePtr asg = gtNewTempAssign(impBoxTemp, op1);

Expand Down

0 comments on commit dd0a673

Please sign in to comment.