Skip to content

Commit

Permalink
Rename DEBUG_NOT_OSX_ARM64 to DEBUG_ARG_SLOTS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Andreenko committed Sep 30, 2020
1 parent aec6b3a commit e674e5a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 52 deletions.
18 changes: 9 additions & 9 deletions src/coreclr/src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1459,15 +1459,15 @@ struct fgArgTabEntry
unsigned structFloatRegs;
#endif // UNIX_AMD64_ABI

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
// These fields were used to calculate stack size in stack slots for arguments
// but now they are replaced by precise `m_byteOffset/m_byteSize` because of
// arm64 apple abi requirements.

// A slot is a pointer sized region in the OutArg area.
unsigned slotNum; // When an argument is passed in the OutArg area this is the slot number in the OutArg area
unsigned numSlots; // Count of number of slots that this argument uses
#endif // DEBUG_NOT_OSX_ARM64_ABI
#endif // DEBUG_ARG_SLOTS

// Return number of stack slots that this argument is taking.
// TODO-Cleanup: this function does not align with arm64 apple model,
Expand Down Expand Up @@ -1741,7 +1741,7 @@ struct fgArgTabEntry
return !IsSplit() && ((numRegs == 1) || (m_byteSize <= TARGET_POINTER_SIZE));
}

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
// Returns the number of "slots" used, where for this purpose a
// register counts as a slot.
unsigned getSlotCount() const
Expand All @@ -1764,7 +1764,7 @@ struct fgArgTabEntry
}
#endif

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
// Returns the size as a multiple of pointer-size.
// For targets without HFAs, this is the same as getSlotCount().
unsigned getSize() const
Expand Down Expand Up @@ -1809,19 +1809,19 @@ struct fgArgTabEntry
public:
void SetByteOffset(unsigned byteOffset)
{
DEBUG_NOT_OSX_ARM64_ASSERT(byteOffset / TARGET_POINTER_SIZE == slotNum);
DEBUG_ARG_SLOTS_ASSERT(byteOffset / TARGET_POINTER_SIZE == slotNum);
m_byteOffset = byteOffset;
}

unsigned GetByteOffset() const
{
DEBUG_NOT_OSX_ARM64_ASSERT(m_byteOffset / TARGET_POINTER_SIZE == slotNum);
DEBUG_ARG_SLOTS_ASSERT(m_byteOffset / TARGET_POINTER_SIZE == slotNum);
return m_byteOffset;
}

void SetByteSize(unsigned byteSize)
{
#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
assert(byteAlignment != 0);
if (!isStruct)
{
Expand Down Expand Up @@ -1919,7 +1919,7 @@ class fgArgInfo
Compiler* compiler; // Back pointer to the compiler instance so that we can allocate memory
GenTreeCall* callTree; // Back pointer to the GT_CALL node for this fgArgInfo
unsigned argCount; // Updatable arg count value
#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
unsigned nextSlotNum; // Updatable slot count value
#endif
unsigned nextStackByteOffset;
Expand Down Expand Up @@ -2011,7 +2011,7 @@ class fgArgInfo
return argTable;
}

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
unsigned GetNextSlotNum() const
{
return nextSlotNum;
Expand Down
19 changes: 11 additions & 8 deletions src/coreclr/src/jit/jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,20 @@
#endif // defined(UNIX_AMD64_ABI)

#if defined(DEBUG) && !defined(OSX_ARM64_ABI)
#define DEBUG_NOT_OSX_ARM64_ABI
// On all platforms except Arm64 OSX arguments on the stack are taking
// register size slots. On these platforms we could check that stack slots count
// matchs out new byte size calculations.
#define DEBUG_ARG_SLOTS
#endif

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#define DEBUG_NOT_OSX_ARM64_ARG(x) , x
#define DEBUG_NOT_OSX_ARM64(x) x
#define DEBUG_NOT_OSX_ARM64_ASSERT(x) assert(x)
#if defined(DEBUG_ARG_SLOTS)
#define DEBUG_ARG_SLOTS_ARG(x) , x
#define DEBUG_ARG_SLOTS_ONLY(x) x
#define DEBUG_ARG_SLOTS_ASSERT(x) assert(x)
#else
#define DEBUG_NOT_OSX_ARM64_ARG(x)
#define DEBUG_NOT_OSX_ARM64(x)
#define DEBUG_NOT_OSX_ARM64_ASSERT(x)
#define DEBUG_ARG_SLOTS_ARG(x)
#define DEBUG_ARG_SLOTS_ONLY(x)
#define DEBUG_ARG_SLOTS_ASSERT(x)
#endif

#if defined(UNIX_AMD64_ABI) || !defined(TARGET_64BIT) || defined(TARGET_ARM64)
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/src/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,9 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf
unsigned slotNumber = info->GetByteOffset() / TARGET_POINTER_SIZE;
#if defined(FEATURE_PUT_STRUCT_ARG_STK)
unsigned numberOfStackSlots = info->GetStackSlotsNumber();
DEBUG_NOT_OSX_ARM64_ASSERT(numberOfStackSlots == info->numSlots);
DEBUG_ARG_SLOTS_ASSERT(numberOfStackSlots == info->numSlots);
#endif
DEBUG_NOT_OSX_ARM64_ASSERT(slotNumber == info->slotNum);
DEBUG_ARG_SLOTS_ASSERT(slotNumber == info->slotNum);

putArg = new (comp, GT_PUTARG_SPLIT)
GenTreePutArgSplit(arg, slotNumber PUT_STRUCT_ARG_STK_ONLY_ARG(numberOfStackSlots), info->numRegs,
Expand Down Expand Up @@ -1159,9 +1159,9 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf
unsigned slotNumber = info->GetByteOffset() / TARGET_POINTER_SIZE;
#if defined(FEATURE_PUT_STRUCT_ARG_STK)
unsigned numberOfStackSlots = info->GetStackSlotsNumber();
DEBUG_NOT_OSX_ARM64_ASSERT(numberOfStackSlots == info->numSlots);
DEBUG_ARG_SLOTS_ASSERT(numberOfStackSlots == info->numSlots);
#endif
DEBUG_NOT_OSX_ARM64_ASSERT(slotNumber == info->slotNum);
DEBUG_ARG_SLOTS_ASSERT(slotNumber == info->slotNum);

putArg =
new (comp, GT_PUTARG_STK) GenTreePutArgStk(GT_PUTARG_STK, TYP_VOID, arg,
Expand Down Expand Up @@ -2135,7 +2135,7 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar
unsigned nNewStkArgsBytes = call->fgArgInfo->GetNextSlotByteOffset();
const int wordSize = 4;
unsigned nNewStkArgsWords = nNewStkArgsBytes / wordSize;
DEBUG_NOT_OSX_ARM64_ASSERT(call->fgArgInfo->GetNextSlotNum() == nNewStkArgsWords);
DEBUG_ARG_SLOTS_ASSERT(call->fgArgInfo->GetNextSlotNum() == nNewStkArgsWords);
assert(nNewStkArgsWords >= 4); // There must be at least the four special stack args.
nNewStkArgsWords -= 4;

Expand Down
60 changes: 30 additions & 30 deletions src/coreclr/src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ void fgArgTabEntry::Dump() const
}
if (GetStackByteSize() > 0)
{
#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
printf(", numSlots=%u, slotNum=%u, byteSize=%u, byteOffset=%u", numSlots, slotNum, m_byteSize, m_byteOffset);
#else
printf(", byteSize=%u, byteOffset=%u", m_byteSize, m_byteOffset);
Expand Down Expand Up @@ -842,7 +842,7 @@ fgArgInfo::fgArgInfo(Compiler* comp, GenTreeCall* call, unsigned numArgs)
compiler = comp;
callTree = call;
argCount = 0; // filled in arg count, starts at zero
DEBUG_NOT_OSX_ARM64(nextSlotNum = INIT_ARG_STACK_SLOT;)
DEBUG_ARG_SLOTS_ONLY(nextSlotNum = INIT_ARG_STACK_SLOT;)
nextStackByteOffset = INIT_ARG_STACK_SLOT * TARGET_POINTER_SIZE;
stkLevel = 0;
#if defined(UNIX_X86_ABI)
Expand Down Expand Up @@ -890,7 +890,7 @@ fgArgInfo::fgArgInfo(GenTreeCall* newCall, GenTreeCall* oldCall)
compiler = oldArgInfo->compiler;
callTree = newCall;
argCount = 0; // filled in arg count, starts at zero
DEBUG_NOT_OSX_ARM64(nextSlotNum = INIT_ARG_STACK_SLOT;)
DEBUG_ARG_SLOTS_ONLY(nextSlotNum = INIT_ARG_STACK_SLOT;)
nextStackByteOffset = INIT_ARG_STACK_SLOT * TARGET_POINTER_SIZE;
stkLevel = oldArgInfo->stkLevel;
#if defined(UNIX_X86_ABI)
Expand Down Expand Up @@ -967,7 +967,7 @@ fgArgInfo::fgArgInfo(GenTreeCall* newCall, GenTreeCall* oldCall)
}

argCount = oldArgInfo->argCount;
DEBUG_NOT_OSX_ARM64(nextSlotNum = oldArgInfo->nextSlotNum;)
DEBUG_ARG_SLOTS_ONLY(nextSlotNum = oldArgInfo->nextSlotNum;)
nextStackByteOffset = oldArgInfo->nextStackByteOffset;

hasRegArgs = oldArgInfo->hasRegArgs;
Expand Down Expand Up @@ -1007,7 +1007,7 @@ fgArgTabEntry* fgArgInfo::AddRegArg(unsigned argNum,
curArgTabEntry->lateUse = nullptr;
curArgTabEntry->numRegs = numRegs;

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
curArgTabEntry->slotNum = 0;
curArgTabEntry->numSlots = 0;
#endif
Expand Down Expand Up @@ -1085,19 +1085,19 @@ fgArgTabEntry* fgArgInfo::AddStkArg(unsigned argNum,
{
fgArgTabEntry* curArgTabEntry = new (compiler, CMK_fgArgInfo) fgArgTabEntry;

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
nextSlotNum = roundUp(nextSlotNum, byteAlignment / TARGET_POINTER_SIZE);
#endif

nextStackByteOffset = roundUp(nextStackByteOffset, byteAlignment);
DEBUG_NOT_OSX_ARM64_ASSERT(nextStackByteOffset / TARGET_POINTER_SIZE == nextSlotNum);
DEBUG_ARG_SLOTS_ASSERT(nextStackByteOffset / TARGET_POINTER_SIZE == nextSlotNum);

curArgTabEntry->setRegNum(0, REG_STK);
curArgTabEntry->argNum = argNum;
curArgTabEntry->argType = node->TypeGet();
curArgTabEntry->use = use;
curArgTabEntry->lateUse = nullptr;
#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
curArgTabEntry->numSlots = numSlots;
curArgTabEntry->slotNum = nextSlotNum;
#endif
Expand Down Expand Up @@ -1128,14 +1128,14 @@ fgArgTabEntry* fgArgInfo::AddStkArg(unsigned argNum,

hasStackArgs = true;
AddArg(curArgTabEntry);
DEBUG_NOT_OSX_ARM64(nextSlotNum += numSlots;)
DEBUG_ARG_SLOTS_ONLY(nextSlotNum += numSlots;)
nextStackByteOffset += byteSize;
return curArgTabEntry;
}

void fgArgInfo::RemorphReset()
{
DEBUG_NOT_OSX_ARM64(nextSlotNum = INIT_ARG_STACK_SLOT;)
DEBUG_ARG_SLOTS_ONLY(nextSlotNum = INIT_ARG_STACK_SLOT;)
nextStackByteOffset = INIT_ARG_STACK_SLOT * TARGET_POINTER_SIZE;
}

Expand Down Expand Up @@ -1182,7 +1182,7 @@ void fgArgInfo::UpdateStkArg(fgArgTabEntry* curArgTabEntry, GenTree* node, bool
noway_assert(curArgTabEntry->use != callTree->gtCallThisArg);
assert((curArgTabEntry->GetRegNum() == REG_STK) || curArgTabEntry->IsSplit());
assert(curArgTabEntry->use->GetNode() == node);
#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
nextSlotNum = roundUp(nextSlotNum, curArgTabEntry->byteAlignment / TARGET_POINTER_SIZE);
assert(curArgTabEntry->slotNum == nextSlotNum);
nextSlotNum += curArgTabEntry->numSlots;
Expand Down Expand Up @@ -1220,18 +1220,18 @@ void fgArgInfo::SplitArg(unsigned argNum, unsigned numRegs, unsigned numSlots)
{
assert(curArgTabEntry->IsSplit() == true);
assert(curArgTabEntry->numRegs == numRegs);
DEBUG_NOT_OSX_ARM64(assert(curArgTabEntry->numSlots == numSlots);)
DEBUG_ARG_SLOTS_ONLY(assert(curArgTabEntry->numSlots == numSlots);)
assert(hasStackArgs == true);
}
else
{
curArgTabEntry->SetSplit(true);
curArgTabEntry->numRegs = numRegs;
DEBUG_NOT_OSX_ARM64(curArgTabEntry->numSlots = numSlots;)
DEBUG_ARG_SLOTS_ONLY(curArgTabEntry->numSlots = numSlots;)
curArgTabEntry->SetByteOffset(0);
hasStackArgs = true;
}
DEBUG_NOT_OSX_ARM64(nextSlotNum += numSlots;)
DEBUG_ARG_SLOTS_ONLY(nextSlotNum += numSlots;)
// TODO-Cleanup: structs are aligned to 8 bytes on arm64 apple, so it would work, but pass the precise size.
nextStackByteOffset += numSlots * TARGET_POINTER_SIZE;
}
Expand Down Expand Up @@ -2433,7 +2433,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
unsigned argIndex = 0;
unsigned intArgRegNum = 0;
unsigned fltArgRegNum = 0;
DEBUG_NOT_OSX_ARM64(unsigned argSlots = 0;)
DEBUG_ARG_SLOTS_ONLY(unsigned argSlots = 0;)

bool callHasRetBuffArg = call->HasRetBufArg();
bool callIsVararg = call->IsVarargs();
Expand Down Expand Up @@ -2803,7 +2803,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
fltArgRegNum++;
#endif // WINDOWS_AMD64_ABI
argIndex++;
DEBUG_NOT_OSX_ARM64(argSlots++;)
DEBUG_ARG_SLOTS_ONLY(argSlots++;)
}

#ifdef TARGET_X86
Expand Down Expand Up @@ -3497,7 +3497,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call)
newArgEntry->argType = argx->TypeGet();
}

DEBUG_NOT_OSX_ARM64(argSlots += size;)
DEBUG_ARG_SLOTS_ONLY(argSlots += size;)
} // end foreach argument loop

#ifdef DEBUG
Expand Down Expand Up @@ -3560,7 +3560,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)

unsigned argIndex = 0;

DEBUG_NOT_OSX_ARM64(unsigned argSlots = 0;)
DEBUG_ARG_SLOTS_ONLY(unsigned argSlots = 0;)

bool reMorphing = call->AreArgsComplete();

Expand Down Expand Up @@ -3599,7 +3599,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
flagsSummary |= argx->gtFlags;
assert(argIndex == 0);
argIndex++;
DEBUG_NOT_OSX_ARM64(argSlots++;)
DEBUG_ARG_SLOTS_ONLY(argSlots++;)
}

// Note that this name is a bit of a misnomer - it indicates that there are struct args
Expand All @@ -3616,10 +3616,10 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
*parentArgx = argx;
assert(argx == args->GetNode());

DEBUG_NOT_OSX_ARM64(unsigned size = argEntry->getSize();)
DEBUG_ARG_SLOTS_ONLY(unsigned size = argEntry->getSize();)
CORINFO_CLASS_HANDLE copyBlkClass = NO_CLASS_HANDLE;

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
if (argEntry->byteAlignment == 2 * TARGET_POINTER_SIZE)
{
if (argSlots % 2 == 1)
Expand All @@ -3636,8 +3636,8 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
flagsSummary |= argx->gtFlags;
continue;
}
DEBUG_NOT_OSX_ARM64_ASSERT(size != 0);
DEBUG_NOT_OSX_ARM64(argSlots += argEntry->getSlotCount();)
DEBUG_ARG_SLOTS_ASSERT(size != 0);
DEBUG_ARG_SLOTS_ONLY(argSlots += argEntry->getSlotCount();)

if (argx->IsLocalAddrExpr() != nullptr)
{
Expand Down Expand Up @@ -3688,7 +3688,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
// First, handle the case where the argument is passed by reference.
if (argEntry->passedByRef)
{
DEBUG_NOT_OSX_ARM64_ASSERT(size == 1);
DEBUG_ARG_SLOTS_ASSERT(size == 1);
copyBlkClass = objClass;
#ifdef UNIX_AMD64_ABI
assert(!"Structs are not passed by reference on x64/ux");
Expand All @@ -3700,7 +3700,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
#ifndef TARGET_X86
// Check to see if we can transform this into load of a primitive type.
// 'size' must be the number of pointer sized items
DEBUG_NOT_OSX_ARM64_ASSERT(size == roundupSize / TARGET_POINTER_SIZE);
DEBUG_ARG_SLOTS_ASSERT(size == roundupSize / TARGET_POINTER_SIZE);

structSize = originalSize;
unsigned passingSize = originalSize;
Expand Down Expand Up @@ -3798,10 +3798,10 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
// Change our argument, as needed, into a value of the appropriate type.
CLANG_FORMAT_COMMENT_ANCHOR;
#ifdef TARGET_ARM
DEBUG_NOT_OSX_ARM64_ASSERT((size == 1) || ((structBaseType == TYP_DOUBLE) && (size == 2)));
DEBUG_ARG_SLOTS_ASSERT((size == 1) || ((structBaseType == TYP_DOUBLE) && (size == 2)));
#else
DEBUG_NOT_OSX_ARM64_ASSERT((size == 1) || (varTypeIsSIMD(structBaseType) &&
size == (genTypeSize(structBaseType) / REGSIZE_BYTES)));
DEBUG_ARG_SLOTS_ASSERT((size == 1) || (varTypeIsSIMD(structBaseType) &&
size == (genTypeSize(structBaseType) / REGSIZE_BYTES)));
#endif

assert((structBaseType != TYP_STRUCT) && (genTypeSize(structBaseType) >= originalSize));
Expand Down Expand Up @@ -4075,7 +4075,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)

const unsigned outgoingArgSpaceSize = GetOutgoingArgByteSize(call->fgArgInfo->GetNextSlotByteOffset());

#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
unsigned preallocatedArgCount = call->fgArgInfo->GetNextSlotNum();
assert(outgoingArgSpaceSize == preallocatedArgCount * REGSIZE_BYTES);
#endif
Expand All @@ -4085,7 +4085,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
if (verbose)
{
const fgArgInfo* argInfo = call->fgArgInfo;
#if defined(DEBUG_NOT_OSX_ARM64_ABI)
#if defined(DEBUG_ARG_SLOTS)
printf("argSlots=%d, preallocatedArgCount=%d, nextSlotNum=%d, nextSlotByteOffset=%d, "
"outgoingArgSpaceSize=%d\n",
argSlots, preallocatedArgCount, argInfo->GetNextSlotNum(), argInfo->GetNextSlotByteOffset(),
Expand Down

0 comments on commit e674e5a

Please sign in to comment.