Skip to content

Commit

Permalink
Jit preparation for arm64 apple: Use bytes in fgArgTabEntry. (#42503)
Browse files Browse the repository at this point in the history
* fix a dumping error introduced in my recent ref PR.

* add a pinvoke test with many small stack arguments.

It will fail on arm64 apple.

* Add get/set for lclVar::lvStkOffs.

* Change some types from `size_t` to `unsigned` when working with stack offsets.

* Rename `stackSize` to `GetStackSize`.

* Do not run stack level setter for arm64 apple.

* Use bytes in `fgArgTabEntry`.

* fix comments/rename vars.

* Add en explanation about `GetStackSlotsNumber`.

* Rename `DEBUG_NOT_OSX_ARM64` to `DEBUG_ARG_SLOTS`.
  • Loading branch information
Sergey Andreenko authored Oct 1, 2020
1 parent eb91a96 commit 334bd84
Show file tree
Hide file tree
Showing 19 changed files with 525 additions and 268 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3281,7 +3281,7 @@ void CodeGen::genCreateAndStoreGCInfo(unsigned codeSize,
unsigned reversePInvokeFrameVarNumber = compiler->lvaReversePInvokeFrameVar;
assert(reversePInvokeFrameVarNumber != BAD_VAR_NUM && reversePInvokeFrameVarNumber < compiler->lvaRefCount);
LclVarDsc& reversePInvokeFrameVar = compiler->lvaTable[reversePInvokeFrameVarNumber];
gcInfoEncoder->SetReversePInvokeFrameSlot(reversePInvokeFrameVar.lvStkOffs);
gcInfoEncoder->SetReversePInvokeFrameSlot(reversePInvokeFrameVar.GetStackOffset());
}

gcInfoEncoder->Build();
Expand Down
37 changes: 19 additions & 18 deletions src/coreclr/src/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2355,25 +2355,25 @@ void CodeGen::genEmitMachineCode()
}
#endif

#if EMIT_TRACK_STACK_DEPTH
#if EMIT_TRACK_STACK_DEPTH && defined(DEBUG) && !defined(OSX_ARM64_ABI)
// Check our max stack level. Needed for fgAddCodeRef().
// We need to relax the assert as our estimation won't include code-gen
// stack changes (which we know don't affect fgAddCodeRef()).
// NOTE: after emitEndCodeGen (including here), emitMaxStackDepth is a
// count of DWORD-sized arguments, NOT argument size in bytes.
{
unsigned maxAllowedStackDepth = compiler->fgPtrArgCntMax + // Max number of pointer-sized stack arguments.
compiler->compHndBBtabCount + // Return address for locally-called finallys
genTypeStSz(TYP_LONG) + // longs/doubles may be transferred via stack, etc
unsigned maxAllowedStackDepth = compiler->fgGetPtrArgCntMax() + // Max number of pointer-sized stack arguments.
compiler->compHndBBtabCount + // Return address for locally-called finallys
genTypeStSz(TYP_LONG) + // longs/doubles may be transferred via stack, etc
(compiler->compTailCallUsed ? 4 : 0); // CORINFO_HELP_TAILCALL args
#if defined(UNIX_X86_ABI)
// Convert maxNestedAlignment to DWORD count before adding to maxAllowedStackDepth.
assert(maxNestedAlignment % sizeof(int) == 0);
maxAllowedStackDepth += maxNestedAlignment / sizeof(int);
#endif
noway_assert(GetEmitter()->emitMaxStackDepth <= maxAllowedStackDepth);
assert(GetEmitter()->emitMaxStackDepth <= maxAllowedStackDepth);
}
#endif // EMIT_TRACK_STACK_DEPTH
#endif // EMIT_TRACK_STACK_DEPTH && DEBUG

*nativeSizeOfCode = codeSize;
compiler->info.compNativeCodeSize = (UNATIVE_OFFSET)codeSize;
Expand Down Expand Up @@ -6763,15 +6763,15 @@ void CodeGen::genReportGenericContextArg(regNumber initReg, bool* pInitRegZeroed
if (isFramePointerUsed())
{
#if defined(TARGET_ARM)
// lvStkOffs is always valid for incoming stack-arguments, even if the argument
// GetStackOffset() is always valid for incoming stack-arguments, even if the argument
// will become enregistered.
// On Arm compiler->compArgSize doesn't include r11 and lr sizes and hence we need to add 2*REGSIZE_BYTES
noway_assert((2 * REGSIZE_BYTES <= varDsc->lvStkOffs) &&
(size_t(varDsc->lvStkOffs) < compiler->compArgSize + 2 * REGSIZE_BYTES));
noway_assert((2 * REGSIZE_BYTES <= varDsc->GetStackOffset()) &&
(size_t(varDsc->GetStackOffset()) < compiler->compArgSize + 2 * REGSIZE_BYTES));
#else
// lvStkOffs is always valid for incoming stack-arguments, even if the argument
// GetStackOffset() is always valid for incoming stack-arguments, even if the argument
// will become enregistered.
noway_assert((0 < varDsc->lvStkOffs) && (size_t(varDsc->lvStkOffs) < compiler->compArgSize));
noway_assert((0 < varDsc->GetStackOffset()) && (size_t(varDsc->GetStackOffset()) < compiler->compArgSize));
#endif
}

Expand All @@ -6781,7 +6781,8 @@ void CodeGen::genReportGenericContextArg(regNumber initReg, bool* pInitRegZeroed
*pInitRegZeroed = false;

// mov reg, [compiler->info.compTypeCtxtArg]
GetEmitter()->emitIns_R_AR(ins_Load(TYP_I_IMPL), EA_PTRSIZE, reg, genFramePointerReg(), varDsc->lvStkOffs);
GetEmitter()->emitIns_R_AR(ins_Load(TYP_I_IMPL), EA_PTRSIZE, reg, genFramePointerReg(),
varDsc->GetStackOffset());
regSet.verifyRegUsed(reg);
}

Expand Down Expand Up @@ -7459,8 +7460,8 @@ void CodeGen::genFnProlog()
continue;
}

signed int loOffs = varDsc->lvStkOffs;
signed int hiOffs = varDsc->lvStkOffs + compiler->lvaLclSize(varNum);
signed int loOffs = varDsc->GetStackOffset();
signed int hiOffs = varDsc->GetStackOffset() + compiler->lvaLclSize(varNum);

/* We need to know the offset range of tracked stack GC refs */
/* We assume that the GC reference can be anywhere in the TYP_STRUCT */
Expand Down Expand Up @@ -7860,7 +7861,7 @@ void CodeGen::genFnProlog()
#else
// mov [lvaStubArgumentVar], EAX
GetEmitter()->emitIns_AR_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SECRET_STUB_PARAM, genFramePointerReg(),
compiler->lvaTable[compiler->lvaStubArgumentVar].lvStkOffs);
compiler->lvaTable[compiler->lvaStubArgumentVar].GetStackOffset());
#endif
assert(intRegState.rsCalleeRegArgMaskLiveIn & RBM_SECRET_STUB_PARAM);

Expand Down Expand Up @@ -8109,7 +8110,7 @@ void CodeGen::genFnProlog()

LclVarDsc* lastArg = &compiler->lvaTable[compiler->info.compArgsCount - 1];
noway_assert(!lastArg->lvRegister);
signed offset = lastArg->lvStkOffs;
signed offset = lastArg->GetStackOffset();
assert(offset != BAD_STK_OFFS);
noway_assert(lastArg->lvFramePointerBased);

Expand Down Expand Up @@ -10617,8 +10618,8 @@ void CodeGen::genSetScopeInfo(unsigned which,
// Can't check compiler->lvaTable[varNum].lvOnFrame as we don't set it for
// arguments of vararg functions to avoid reporting them to GC.
noway_assert(!compiler->lvaTable[varNum].lvRegister);
unsigned cookieOffset = compiler->lvaTable[compiler->lvaVarargsHandleArg].lvStkOffs;
unsigned varOffset = compiler->lvaTable[varNum].lvStkOffs;
unsigned cookieOffset = compiler->lvaTable[compiler->lvaVarargsHandleArg].GetStackOffset();
unsigned varOffset = compiler->lvaTable[varNum].GetStackOffset();

noway_assert(cookieOffset < varOffset);
unsigned offset = varOffset - cookieOffset;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ void CodeGen::genPutArgStkFieldList(GenTreePutArgStk* putArgStk, unsigned outArg
// We can't write beyond the arg area unless this is a tail call, in which case we use
// the first stack arg as the base of the incoming arg area.
#ifdef DEBUG
size_t areaSize = compiler->lvaLclSize(outArgVarNum);
unsigned areaSize = compiler->lvaLclSize(outArgVarNum);
#if FEATURE_FASTTAILCALL
if (putArgStk->gtCall->IsFastTailCall())
{
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/src/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8285,7 +8285,7 @@ void CodeGen::genCreateAndStoreGCInfoX64(unsigned codeSize, unsigned prologSize
unsigned reversePInvokeFrameVarNumber = compiler->lvaReversePInvokeFrameVar;
assert(reversePInvokeFrameVarNumber != BAD_VAR_NUM && reversePInvokeFrameVarNumber < compiler->lvaRefCount);
LclVarDsc& reversePInvokeFrameVar = compiler->lvaTable[reversePInvokeFrameVarNumber];
gcInfoEncoder->SetReversePInvokeFrameSlot(reversePInvokeFrameVar.lvStkOffs);
gcInfoEncoder->SetReversePInvokeFrameSlot(reversePInvokeFrameVar.GetStackOffset());
}

gcInfoEncoder->Build();
Expand Down Expand Up @@ -8561,7 +8561,7 @@ void CodeGen::genProfilingEnterCallback(regNumber initReg, bool* pInitRegZeroed)
EA_UNKNOWN); // retSize

// Check that we have place for the push.
assert(compiler->fgPtrArgCntMax >= 1);
assert(compiler->fgGetPtrArgCntMax() >= 1);

#if defined(UNIX_X86_ABI)
// Restoring alignment manually. This is similar to CodeGen::genRemoveAlignmentAfterCall
Expand Down Expand Up @@ -8642,7 +8642,7 @@ void CodeGen::genProfilingLeaveCallback(unsigned helper)
genEmitHelperCall(helper, argSize, EA_UNKNOWN /* retSize */);

// Check that we have place for the push.
assert(compiler->fgPtrArgCntMax >= 1);
assert(compiler->fgGetPtrArgCntMax() >= 1);

#if defined(UNIX_X86_ABI)
// Restoring alignment manually. This is similar to CodeGen::genRemoveAlignmentAfterCall
Expand Down
11 changes: 7 additions & 4 deletions src/coreclr/src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4911,10 +4911,13 @@ void Compiler::compCompile(void** methodCodePtr, ULONG* methodCodeSize, JitFlags
m_pLowering = new (this, CMK_LSRA) Lowering(this, m_pLinearScan); // PHASE_LOWERING
m_pLowering->Run();

// Set stack levels
//
#if !defined(OSX_ARM64_ABI)
// Set stack levels; this information is necessary for x86
// but on other platforms it is used only in asserts.
// TODO: do not run it in release on other platforms, see https://github.com/dotnet/runtime/issues/42673.
StackLevelSetter stackLevelSetter(this);
stackLevelSetter.Run();
#endif // !OSX_ARM64_ABI

// We can not add any new tracked variables after this point.
lvaTrackedFixed = true;
Expand Down Expand Up @@ -5018,7 +5021,7 @@ void Compiler::generatePatchpointInfo()
assert(varDsc->lvFramePointerBased);

// Record FramePtr relative offset (no localloc yet)
patchpointInfo->SetOffset(lclNum, varDsc->lvStkOffs);
patchpointInfo->SetOffset(lclNum, varDsc->GetStackOffset());

// Note if IL stream contained an address-of that potentially leads to exposure.
// This bit of IL may be skipped by OSR partial importation.
Expand Down Expand Up @@ -5051,7 +5054,7 @@ void Compiler::generatePatchpointInfo()
{
assert(lvaGSSecurityCookie != BAD_VAR_NUM);
LclVarDsc* const varDsc = lvaGetDesc(lvaGSSecurityCookie);
patchpointInfo->SetSecurityCookieOffset(varDsc->lvStkOffs);
patchpointInfo->SetSecurityCookieOffset(varDsc->GetStackOffset());
JITDUMP("--OSR-- security cookie V%02u offset is FP %d\n", lvaGSSecurityCookie,
patchpointInfo->SecurityCookieOffset());
}
Expand Down
Loading

0 comments on commit 334bd84

Please sign in to comment.