Skip to content

Commit

Permalink
Allow larger than 0x1000 bytes allocation in genStackPointerConstantA…
Browse files Browse the repository at this point in the history
…djustment() (dotnet#47862)

* In AOT scenarios the VM reports to the JIT the minimal supported page size in src/coreclr/vm/jitinterface.cpp

* Have genStackPointerConstantAdjustment accept regTmp argument on Arm32 and Arm64

The temporary register is going to be used when sub sp,sp,#spDelta can not be encoded.
For example, this happens when spDelta corresponds to OsPageSize and the
OsPageSize is larger than 0x1000 bytes.

The following code needs to be generated in such cases

mov regTmp,#spDelta
sub sp,sp,regTmp

* Use genInstrWithConstant(INS_sub) and rsGetRsvdReg() as temporary register to encode amount of sp adjustment in src/coreclr/jit/codegenarm64.cpp

* Update comment to reflect that REG_NA can be passed for regTmp in genStackPointerConstantAdjustment in src/coreclr/jit/codegenarmarch.cpp
  • Loading branch information
echesakov authored Feb 9, 2021
1 parent aecd60a commit bf9f899
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1301,12 +1301,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

void genReturn(GenTree* treeNode);

#ifdef TARGET_ARMARCH
void genStackPointerConstantAdjustment(ssize_t spDelta);
#else // !TARGET_ARMARCH
void genStackPointerConstantAdjustment(ssize_t spDelta, regNumber regTmp);
#endif // !TARGET_ARMARCH

void genStackPointerConstantAdjustmentWithProbe(ssize_t spDelta, regNumber regTmp);
target_ssize_t genStackPointerConstantAdjustmentLoopWithProbe(ssize_t spDelta, regNumber regTmp);

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void CodeGen::genLclHeap(GenTree* tree)
}
else
{
genStackPointerConstantAdjustment(-(ssize_t)stackAdjustment);
genStackPointerConstantAdjustment(-(ssize_t)stackAdjustment, regTmp);
}

// Return the stackalloc'ed address in result register.
Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ void CodeGen::genLclHeap(GenTree* tree)
// ldr wz, [SP, #0]
GetEmitter()->emitIns_R_R_I(INS_ldr, EA_4BYTE, REG_ZR, REG_SP, 0);

inst_RV_IV(INS_sub, REG_SP, amount, EA_PTRSIZE);
genInstrWithConstant(INS_sub, EA_PTRSIZE, REG_SPBASE, REG_SPBASE, amount, rsGetRsvdReg());

lastTouchDelta = amount;

Expand Down Expand Up @@ -2363,21 +2363,23 @@ void CodeGen::genLclHeap(GenTree* tree)
assert((stackAdjustment % STACK_ALIGN) == 0); // This must be true for the stack to remain aligned
assert((lastTouchDelta == ILLEGAL_LAST_TOUCH_DELTA) || (lastTouchDelta >= 0));

const regNumber tmpReg = rsGetRsvdReg();

if ((lastTouchDelta == ILLEGAL_LAST_TOUCH_DELTA) ||
(stackAdjustment + (unsigned)lastTouchDelta + STACK_PROBE_BOUNDARY_THRESHOLD_BYTES >
compiler->eeGetPageSize()))
{
genStackPointerConstantAdjustmentLoopWithProbe(-(ssize_t)stackAdjustment, REG_ZR);
genStackPointerConstantAdjustmentLoopWithProbe(-(ssize_t)stackAdjustment, tmpReg);
}
else
{
genStackPointerConstantAdjustment(-(ssize_t)stackAdjustment);
genStackPointerConstantAdjustment(-(ssize_t)stackAdjustment, tmpReg);
}

// Return the stackalloc'ed address in result register.
// TargetReg = SP + stackAdjustment.
//
genInstrWithConstant(INS_add, EA_PTRSIZE, targetReg, REG_SPBASE, (ssize_t)stackAdjustment, rsGetRsvdReg());
genInstrWithConstant(INS_add, EA_PTRSIZE, targetReg, REG_SPBASE, (ssize_t)stackAdjustment, tmpReg);
}
else // stackAdjustment == 0
{
Expand Down
14 changes: 11 additions & 3 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,27 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//
// Arguments:
// spDelta - the value to add to SP. Must be negative or zero.
// regTmp - an available temporary register that is used if 'spDelta' cannot be encoded by
// 'sub sp, sp, #spDelta' instruction.
// Can be REG_NA if the caller knows for certain that 'spDelta' fits into the immediate
// value range.
//
// Return Value:
// None.
//
void CodeGen::genStackPointerConstantAdjustment(ssize_t spDelta)
void CodeGen::genStackPointerConstantAdjustment(ssize_t spDelta, regNumber regTmp)
{
assert(spDelta < 0);

// We assert that the SP change is less than one page. If it's greater, you should have called a
// function that does a probe, which will in turn call this function.
assert((target_size_t)(-spDelta) <= compiler->eeGetPageSize());

inst_RV_IV(INS_sub, REG_SPBASE, (target_ssize_t)-spDelta, EA_PTRSIZE);
#ifdef TARGET_ARM64
genInstrWithConstant(INS_sub, EA_PTRSIZE, REG_SPBASE, REG_SPBASE, -spDelta, regTmp);
#else
genInstrWithConstant(INS_sub, EA_PTRSIZE, REG_SPBASE, REG_SPBASE, -spDelta, INS_FLAGS_DONT_CARE, regTmp);
#endif
}

//------------------------------------------------------------------------
Expand All @@ -58,7 +66,7 @@ void CodeGen::genStackPointerConstantAdjustment(ssize_t spDelta)
void CodeGen::genStackPointerConstantAdjustmentWithProbe(ssize_t spDelta, regNumber regTmp)
{
GetEmitter()->emitIns_R_R_I(INS_ldr, EA_4BYTE, regTmp, REG_SP, 0);
genStackPointerConstantAdjustment(spDelta);
genStackPointerConstantAdjustment(spDelta, regTmp);
}

//------------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10228,7 +10228,16 @@ void CEEInfo::getEEInfo(CORINFO_EE_INFO *pEEInfoOut)
_ASSERTE(sizeof(ReversePInvokeFrame) <= pEEInfoOut->sizeOfReversePInvokeFrame);
#endif

pEEInfoOut->osPageSize = GetOsPageSize();
if (!IsReadyToRunCompilation())
{
pEEInfoOut->osPageSize = GetOsPageSize();
}
else
{
// In AOT scenarios the VM reports to the JIT the minimal supported page size.
pEEInfoOut->osPageSize = 0x1000;
}

pEEInfoOut->maxUncheckedOffsetForNullObject = MAX_UNCHECKED_OFFSET_FOR_NULL_OBJECT;
pEEInfoOut->targetAbi = CORINFO_CORECLR_ABI;

Expand Down

0 comments on commit bf9f899

Please sign in to comment.