From 4a1ba97bd1678a24c730aa3ddab607ecb132436e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sat, 26 Mar 2022 15:10:28 +0100 Subject: [PATCH 01/52] Refactor call argument representation This refactors the JIT's representation of call arguments. It replaces `GenTreeCall::Use` and `fgArgTabEntry` with a single class `CallArg`. `CallArg` always contains space for ABI information and contains two intrusive linked list nodes: one for all args (similar to current `gtCallArgs`) where all standard arguments are always in argument order, and one for late args (similar to current `gtCallLateArgs`) that may be reordered. The late args list may also not contain all arguments. `fgArgInfo` is also replaced by a new class `CallArgs` that is stored inline in `GenTreeCall`. It encapsulates all handling of arguments (insertion/removal). The change also begins treating the 'this' argument as a normal argument with `CallArgs` providing convenient access to it when necessary. The main benefit of this change is to avoid keeping track of the side table `fgArgInfo` and having to scan through this side table repeatedly when we need to query argument information. In addition it gives more convenient ways to access well known arguments like 'this', the ret buffer, VSD cell, etc. Follow-up changes I want to make after this: * Remove quirks. In trying to keep this zero-diff several quirks were added. In particular we currently miss a significant optimization opportunity by not retyping 'this' arguments as unmanaged pointers when they are on stack. * Remove GT_PUTARG_TYPE nodes. These are used only to transfer information from import to morph. Now that we always allocate argument information we can just store this information directly. --- src/coreclr/inc/corinfo.h | 2 +- src/coreclr/jit/assertionprop.cpp | 13 +- src/coreclr/jit/codegen.h | 2 +- src/coreclr/jit/codegenarmarch.cpp | 35 +- src/coreclr/jit/codegencommon.cpp | 18 +- src/coreclr/jit/codegenxarch.cpp | 36 +- src/coreclr/jit/compiler.cpp | 19 +- src/coreclr/jit/compiler.h | 859 +------ src/coreclr/jit/compiler.hpp | 41 +- src/coreclr/jit/decomposelongs.cpp | 7 +- src/coreclr/jit/earlyprop.cpp | 10 +- src/coreclr/jit/fgdiagnostic.cpp | 35 +- src/coreclr/jit/fgprofile.cpp | 18 +- src/coreclr/jit/flowgraph.cpp | 125 +- src/coreclr/jit/forwardsub.cpp | 9 +- src/coreclr/jit/gentree.cpp | 1552 ++++++++----- src/coreclr/jit/gentree.h | 630 ++++-- src/coreclr/jit/gschecks.cpp | 18 +- src/coreclr/jit/importer.cpp | 639 ++---- src/coreclr/jit/importer_vectorization.cpp | 7 +- src/coreclr/jit/indirectcalltransformer.cpp | 84 +- src/coreclr/jit/inline.h | 1 - src/coreclr/jit/inlinepolicy.cpp | 2 +- src/coreclr/jit/lclmorph.cpp | 10 +- src/coreclr/jit/lclvars.cpp | 1 - src/coreclr/jit/lower.cpp | 299 +-- src/coreclr/jit/lower.h | 6 +- src/coreclr/jit/lowerxarch.cpp | 12 +- src/coreclr/jit/lsraarmarch.cpp | 29 +- src/coreclr/jit/lsraxarch.cpp | 41 +- src/coreclr/jit/morph.cpp | 2215 ++++++------------- src/coreclr/jit/objectalloc.cpp | 11 +- src/coreclr/jit/patchpoint.cpp | 6 +- src/coreclr/jit/rationalize.cpp | 28 +- src/coreclr/jit/rationalize.h | 3 +- src/coreclr/jit/stacklevelsetter.cpp | 10 +- src/coreclr/jit/valuenum.cpp | 79 +- 37 files changed, 2842 insertions(+), 4070 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 99dd1fb7c2831a..22a4e4f812d622 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1114,7 +1114,7 @@ struct CORINFO_SIG_INFO CorInfoCallConv getCallConv() { return CorInfoCallConv((callConv & CORINFO_CALLCONV_MASK)); } bool hasThis() { return ((callConv & CORINFO_CALLCONV_HASTHIS) != 0); } bool hasExplicitThis() { return ((callConv & CORINFO_CALLCONV_EXPLICITTHIS) != 0); } - unsigned totalILArgs() { return (numArgs + hasThis()); } + unsigned totalILArgs() { return (numArgs + (hasThis() ? 1 : 0)); } bool isVarArg() { return ((getCallConv() == CORINFO_CALLCONV_VARARG) || (getCallConv() == CORINFO_CALLCONV_NATIVEVARARG)); } bool hasTypeArg() { return ((callConv & CORINFO_CALLCONV_PARAMTYPE) != 0); } }; diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 1e5d32e1f48847..dd509757b53cdc 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -2548,9 +2548,8 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree) (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFCLASS)) || (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFANY))) { - fgArgInfo* const argInfo = call->fgArgInfo; - GenTree* objectNode = argInfo->GetArgNode(1); - GenTree* methodTableNode = argInfo->GetArgNode(0); + GenTree* objectNode = call->gtArgs.GetArgByIndex(1)->GetArgNode(); + GenTree* methodTableNode = call->gtArgs.GetArgByIndex(0)->GetArgNode(); assert(objectNode->TypeGet() == TYP_REF); assert(methodTableNode->TypeGet() == TYP_I_IMPL); @@ -2697,7 +2696,7 @@ void Compiler::optAssertionGen(GenTree* tree) if (call->NeedsNullCheck() || (call->IsVirtual() && !call->IsTailCall())) { // Retrieve the 'this' arg. - GenTree* thisArg = gtGetThisArg(call); + GenTree* thisArg = call->gtArgs.GetThisArg()->GetArgNode(); assert(thisArg != nullptr); assertionInfo = optCreateAssertion(thisArg, nullptr, OAK_NOT_EQUAL); } @@ -4496,7 +4495,7 @@ GenTree* Compiler::optNonNullAssertionProp_Call(ASSERT_VALARG_TP assertions, Gen { return nullptr; } - GenTree* op1 = gtGetThisArg(call); + GenTree* op1 = call->gtArgs.GetThisArg()->GetArgNode(); noway_assert(op1 != nullptr); if (op1->gtOper != GT_LCL_VAR) { @@ -4555,13 +4554,13 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTANY) || call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTCLASS_SPECIAL)) { - GenTree* arg1 = gtArgEntryByArgNum(call, 1)->GetNode(); + GenTree* arg1 = call->gtArgs.GetArgByIndex(1)->GetArgNode(); if (arg1->gtOper != GT_LCL_VAR) { return nullptr; } - GenTree* arg2 = gtArgEntryByArgNum(call, 0)->GetNode(); + GenTree* arg2 = call->gtArgs.GetArgByIndex(0)->GetArgNode(); unsigned index = optAssertionIsSubtype(arg1, arg2, assertions); if (index != NO_ASSERTION_INDEX) diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index 7820c437429dad..9d290f6ed8bc83 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -1327,7 +1327,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX instruction genGetInsForOper(genTreeOps oper, var_types type); bool genEmitOptimizedGCWriteBarrier(GCInfo::WriteBarrierForm writeBarrierForm, GenTree* addr, GenTree* data); GenTree* getCallTarget(const GenTreeCall* call, CORINFO_METHOD_HANDLE* methHnd); - regNumber getCallIndirectionCellReg(const GenTreeCall* call); + regNumber getCallIndirectionCellReg(GenTreeCall* call); void genCall(GenTreeCall* call); void genCallInstruction(GenTreeCall* call X86_ARG(target_ssize_t stackArgBytes)); void genJmpMethod(GenTree* jmp); diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index 01fbaff7a8c4d7..94381c3efeee97 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -762,9 +762,9 @@ void CodeGen::genPutArgStk(GenTreePutArgStk* treeNode) unsigned argOffsetOut = treeNode->getArgOffset(); #ifdef DEBUG - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(treeNode->gtCall, treeNode); - assert(curArgTabEntry != nullptr); - DEBUG_ARG_SLOTS_ASSERT(argOffsetOut == (curArgTabEntry->slotNum * TARGET_POINTER_SIZE)); + CallArg* callArg = treeNode->gtCall->gtArgs.FindByNode(treeNode); + assert(callArg != nullptr); + DEBUG_ARG_SLOTS_ASSERT(argOffsetOut == (callArg->AbiInfo.SlotNum * TARGET_POINTER_SIZE)); #endif // DEBUG // Whether to setup stk arg in incoming or out-going arg area? @@ -3120,23 +3120,21 @@ void CodeGen::genCodeForInitBlkHelper(GenTreeBlk* initBlkNode) void CodeGen::genCall(GenTreeCall* call) { // Consume all the arg regs - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - GenTree* argNode = use.GetNode(); - - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, argNode); - assert(curArgTabEntry); + CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; + GenTree* argNode = arg.GetNode(); // GT_RELOAD/GT_COPY use the child node argNode = argNode->gtSkipReloadOrCopy(); - if (curArgTabEntry->GetRegNum() == REG_STK) + if (abiInfo.GetRegNum() == REG_STK) continue; // Deal with multi register passed struct args. if (argNode->OperGet() == GT_FIELD_LIST) { - regNumber argReg = curArgTabEntry->GetRegNum(); + regNumber argReg = abiInfo.GetRegNum(); for (GenTreeFieldList::Use& use : argNode->AsFieldList()->Uses()) { GenTree* putArgRegNode = use.GetNode(); @@ -3157,14 +3155,14 @@ void CodeGen::genCall(GenTreeCall* call) #endif // TARGET_ARM } } - else if (curArgTabEntry->IsSplit()) + else if (abiInfo.IsSplit()) { assert(compFeatureArgSplit()); - assert(curArgTabEntry->numRegs >= 1); + assert(abiInfo.NumRegs >= 1); genConsumeArgSplitStruct(argNode->AsPutArgSplit()); - for (unsigned idx = 0; idx < curArgTabEntry->numRegs; idx++) + for (unsigned idx = 0; idx < abiInfo.NumRegs; idx++) { - regNumber argReg = (regNumber)((unsigned)curArgTabEntry->GetRegNum() + idx); + regNumber argReg = (regNumber)((unsigned)abiInfo.GetRegNum() + idx); regNumber allocReg = argNode->AsPutArgSplit()->GetRegNumByIdx(idx); inst_Mov_Extend(argNode->TypeGet(), /* srcInReg */ true, argReg, allocReg, /* canSkip */ true, emitActualTypeSize(TYP_I_IMPL)); @@ -3172,7 +3170,7 @@ void CodeGen::genCall(GenTreeCall* call) } else { - regNumber argReg = curArgTabEntry->GetRegNum(); + regNumber argReg = abiInfo.GetRegNum(); genConsumeReg(argNode); inst_Mov_Extend(argNode->TypeGet(), /* srcInReg */ true, argReg, argNode->GetRegNum(), /* canSkip */ true, emitActualTypeSize(TYP_I_IMPL)); @@ -3404,12 +3402,11 @@ void CodeGen::genCallInstruction(GenTreeCall* call) trashedByEpilog |= genRegMask(REG_GSCOOKIE_TMP_1); } - for (unsigned i = 0; i < call->fgArgInfo->ArgCount(); i++) + for (CallArg& arg : call->gtArgs.Args()) { - fgArgTabEntry* entry = call->fgArgInfo->GetArgEntry(i); - for (unsigned j = 0; j < entry->numRegs; j++) + for (unsigned j = 0; j < arg.AbiInfo.NumRegs; j++) { - regNumber reg = entry->GetRegNum(j); + regNumber reg = arg.AbiInfo.GetRegNum(j); if ((trashedByEpilog & genRegMask(reg)) != 0) { JITDUMP("Tail call node:\n"); diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 87de50188d24d8..ab5585f4da71c9 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6434,17 +6434,17 @@ GenTree* CodeGen::getCallTarget(const GenTreeCall* call, CORINFO_METHOD_HANDLE* // Notes: // We currently use indirection cells for VSD on all platforms and for R2R calls on ARM architectures. // -regNumber CodeGen::getCallIndirectionCellReg(const GenTreeCall* call) +regNumber CodeGen::getCallIndirectionCellReg(GenTreeCall* call) { regNumber result = REG_NA; switch (call->GetIndirectionCellArgKind()) { - case NonStandardArgKind::None: + case WellKnownArg::None: break; - case NonStandardArgKind::R2RIndirectionCell: + case WellKnownArg::R2RIndirectionCell: result = REG_R2R_INDIRECT_PARAM; break; - case NonStandardArgKind::VirtualStubCell: + case WellKnownArg::VirtualStubCell: result = compiler->virtualStubParamInfo->GetReg(); break; default: @@ -6453,14 +6453,12 @@ regNumber CodeGen::getCallIndirectionCellReg(const GenTreeCall* call) #ifdef DEBUG regNumber foundReg = REG_NA; - unsigned argCount = call->fgArgInfo->ArgCount(); - fgArgTabEntry** argTable = call->fgArgInfo->ArgTable(); - for (unsigned i = 0; i < argCount; i++) + for (CallArg& arg : call->gtArgs.Args()) { - NonStandardArgKind kind = argTable[i]->nonStandardArgKind; - if ((kind == NonStandardArgKind::R2RIndirectionCell) || (kind == NonStandardArgKind::VirtualStubCell)) + WellKnownArg kind = arg.GetWellKnownArg(); + if ((kind == WellKnownArg::R2RIndirectionCell) || (kind == WellKnownArg::VirtualStubCell)) { - foundReg = argTable[i]->GetRegNum(); + foundReg = arg.AbiInfo.GetRegNum(); break; } } diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 1cdc55a8141587..94904f16c51680 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -5322,14 +5322,12 @@ void CodeGen::genCall(GenTreeCall* call) } // Consume all the arg regs - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - GenTree* argNode = use.GetNode(); + CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; + GenTree* argNode = arg.GetNode(); - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, argNode->gtSkipReloadOrCopy()); - assert(curArgTabEntry); - - if (curArgTabEntry->GetRegNum() == REG_STK) + if (abiInfo.GetRegNum() == REG_STK) { continue; } @@ -5343,7 +5341,7 @@ void CodeGen::genCall(GenTreeCall* call) { GenTree* putArgRegNode = use.GetNode(); assert(putArgRegNode->gtOper == GT_PUTARG_REG); - regNumber argReg = curArgTabEntry->GetRegNum(regIndex++); + regNumber argReg = abiInfo.GetRegNum(regIndex++); genConsumeReg(putArgRegNode); @@ -5356,7 +5354,7 @@ void CodeGen::genCall(GenTreeCall* call) else #endif // UNIX_AMD64_ABI { - regNumber argReg = curArgTabEntry->GetRegNum(); + regNumber argReg = abiInfo.GetRegNum(); genConsumeReg(argNode); inst_Mov_Extend(argNode->TypeGet(), /* srcInReg */ false, argReg, argNode->GetRegNum(), /* canSkip */ true, emitActualTypeSize(TYP_I_IMPL)); @@ -5378,18 +5376,16 @@ void CodeGen::genCall(GenTreeCall* call) // The call will pop its arguments. // for each putarg_stk: target_ssize_t stackArgBytes = 0; - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree* arg = use.GetNode(); - if (arg->OperIs(GT_PUTARG_STK) && ((arg->gtFlags & GTF_LATE_ARG) == 0)) + GenTree* argNode = arg.GetNode(); + if (argNode->OperIs(GT_PUTARG_STK) && ((argNode->gtFlags & GTF_LATE_ARG) == 0)) { - GenTree* source = arg->AsPutArgStk()->gtGetOp1(); - unsigned size = arg->AsPutArgStk()->GetStackByteSize(); + GenTree* source = argNode->AsPutArgStk()->gtGetOp1(); + unsigned size = argNode->AsPutArgStk()->GetStackByteSize(); stackArgBytes += size; #ifdef DEBUG - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, arg); - assert(curArgTabEntry != nullptr); - assert(size == (curArgTabEntry->numSlots * TARGET_POINTER_SIZE)); + assert(size == (arg.AbiInfo.NumSlots * TARGET_POINTER_SIZE)); #ifdef FEATURE_PUT_STRUCT_ARG_STK if (!source->OperIs(GT_FIELD_LIST) && (source->TypeGet() == TYP_STRUCT)) { @@ -5401,7 +5397,7 @@ void CodeGen::genCall(GenTreeCall* call) // Note that on x64/ux this will be handled by unrolling in genStructPutArgUnroll. assert((argBytes == obj->GetLayout()->GetSize()) || obj->Addr()->IsLocalAddrExpr()); #endif // TARGET_X86 - assert((curArgTabEntry->numSlots * TARGET_POINTER_SIZE) == argBytes); + assert((arg.AbiInfo.NumSlots * TARGET_POINTER_SIZE) == argBytes); } #endif // FEATURE_PUT_STRUCT_ARG_STK #endif // DEBUG @@ -7995,9 +7991,9 @@ void CodeGen::genPutArgStk(GenTreePutArgStk* putArgStk) unsigned argOffset = putArgStk->getArgOffset(); #ifdef DEBUG - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(putArgStk->gtCall, putArgStk); - assert(curArgTabEntry != nullptr); - assert(argOffset == curArgTabEntry->slotNum * TARGET_POINTER_SIZE); + CallArg* callArg = putArgStk->gtCall->gtArgs.FindByNode(putArgStk); + assert(callArg != nullptr); + assert(argOffset == callArg->AbiInfo.SlotNum * TARGET_POINTER_SIZE); #endif if (data->isContainedIntOrIImmed()) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index e348db612e52e6..733f4819601c45 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -4464,8 +4464,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl { // confirm that the argument is a GC pointer (for debugging (GC stress)) GenTree* op = gtNewLclvNode(i, TYP_REF); - GenTreeCall::Use* args = gtNewCallArgs(op); - op = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_VOID, args); + op = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_VOID, op); fgEnsureFirstBBisScratch(); fgNewStmtAtEnd(fgFirstBB, op); @@ -7454,16 +7453,12 @@ Compiler::NodeToIntMap* Compiler::FindReachableNodesInNodeTestData() { GenTreeCall* call = tree->AsCall(); unsigned i = 0; - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - if ((use.GetNode()->gtFlags & GTF_LATE_ARG) != 0) + GenTree* argNode = arg.GetArgNode(); + if (GetNodeTestData()->Lookup(argNode, &tlAndN)) { - // Find the corresponding late arg. - GenTree* lateArg = call->fgArgInfo->GetArgNode(i); - if (GetNodeTestData()->Lookup(lateArg, &tlAndN)) - { - reachable->Set(lateArg, 0); - } + reachable->Set(argNode, 0); } i++; } @@ -9477,10 +9472,6 @@ void cTreeFlags(Compiler* comp, GenTree* tree) { chars += printf("[CALL_M_TAILCALL]"); } - if (call->gtCallMoreFlags & GTF_CALL_M_VARARGS) - { - chars += printf("[CALL_M_VARARGS]"); - } if (call->gtCallMoreFlags & GTF_CALL_M_RETBUFFARG) { chars += printf("[CALL_M_RETBUFFARG]"); diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 92748da27e6ab1..30213d6ca0561c 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -1666,798 +1666,6 @@ struct FuncInfoDsc // that isn't shared between the main function body and funclets. }; -struct fgArgTabEntry -{ - GenTreeCall::Use* use; // Points to the argument's GenTreeCall::Use in gtCallArgs or gtCallThisArg. - GenTreeCall::Use* lateUse; // Points to the argument's GenTreeCall::Use in gtCallLateArgs, if any. - - // Get the node that coresponds to this argument entry. - // This is the "real" node and not a placeholder or setup node. - GenTree* GetNode() const - { - return lateUse == nullptr ? use->GetNode() : lateUse->GetNode(); - } - - unsigned argNum; // The original argument number, also specifies the required argument evaluation order from the IL - -private: - regNumberSmall regNums[MAX_ARG_REG_COUNT]; // The registers to use when passing this argument, set to REG_STK for - // arguments passed on the stack -public: - unsigned numRegs; // Count of number of registers that this argument uses. - // Note that on ARM, if we have a double hfa, this reflects the number - // of DOUBLE registers. - -#if defined(UNIX_AMD64_ABI) - // Unix amd64 will split floating point types and integer types in structs - // between floating point and general purpose registers. Keep track of that - // information so we do not need to recompute it later. - unsigned structIntRegs; - unsigned structFloatRegs; -#endif // UNIX_AMD64_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_ARG_SLOTS - - // Return number of stack slots that this argument is taking. - // TODO-Cleanup: this function does not align with arm64 apple model, - // delete it. In most cases we just want to know if we it is using stack or not - // but in some cases we are checking if it is a multireg arg, like: - // `numRegs + GetStackSlotsNumber() > 1` that is harder to replace. - // - unsigned GetStackSlotsNumber() const - { - return roundUp(GetStackByteSize(), TARGET_POINTER_SIZE) / TARGET_POINTER_SIZE; - } - -private: - unsigned _lateArgInx; // index into gtCallLateArgs list; UINT_MAX if this is not a late arg. -public: - unsigned tmpNum; // the LclVar number if we had to force evaluation of this arg - - var_types argType; // The type used to pass this argument. This is generally the original argument type, but when a - // struct is passed as a scalar type, this is that type. - // Note that if a struct is passed by reference, this will still be the struct type. - - bool needTmp : 1; // True when we force this argument's evaluation into a temp LclVar - bool needPlace : 1; // True when we must replace this argument with a placeholder node - bool isTmp : 1; // True when we setup a temp LclVar for this argument due to size issues with the struct - bool processed : 1; // True when we have decided the evaluation order for this argument in the gtCallLateArgs - bool isBackFilled : 1; // True when the argument fills a register slot skipped due to alignment requirements of - // previous arguments. - NonStandardArgKind nonStandardArgKind : 4; // The non-standard arg kind. Non-standard args are args that are forced - // to be in certain registers or on the stack, regardless of where they - // appear in the arg list. - bool isStruct : 1; // True if this is a struct arg - bool _isVararg : 1; // True if the argument is in a vararg context. - bool passedByRef : 1; // True iff the argument is passed by reference. -#if FEATURE_ARG_SPLIT - bool _isSplit : 1; // True when this argument is split between the registers and OutArg area -#endif // FEATURE_ARG_SPLIT -#ifdef FEATURE_HFA_FIELDS_PRESENT - CorInfoHFAElemType _hfaElemKind : 3; // What kind of an HFA this is (CORINFO_HFA_ELEM_NONE if it is not an HFA). -#endif - CorInfoHFAElemType GetHfaElemKind() const - { -#ifdef FEATURE_HFA_FIELDS_PRESENT - return _hfaElemKind; -#else - NOWAY_MSG("GetHfaElemKind"); - return CORINFO_HFA_ELEM_NONE; -#endif - } - - void SetHfaElemKind(CorInfoHFAElemType elemKind) - { -#ifdef FEATURE_HFA_FIELDS_PRESENT - _hfaElemKind = elemKind; -#else - NOWAY_MSG("SetHfaElemKind"); -#endif - } - - bool isNonStandard() const - { - return nonStandardArgKind != NonStandardArgKind::None; - } - - // Returns true if the IR node for this non-standarg arg is added by fgInitArgInfo. - // In this case, it must be removed by GenTreeCall::ResetArgInfo. - bool isNonStandardArgAddedLate() const - { - switch (static_cast(nonStandardArgKind)) - { - case NonStandardArgKind::None: - case NonStandardArgKind::PInvokeFrame: - case NonStandardArgKind::ShiftLow: - case NonStandardArgKind::ShiftHigh: - case NonStandardArgKind::FixedRetBuffer: - case NonStandardArgKind::ValidateIndirectCallTarget: - return false; - case NonStandardArgKind::WrapperDelegateCell: - case NonStandardArgKind::VirtualStubCell: - case NonStandardArgKind::PInvokeCookie: - case NonStandardArgKind::PInvokeTarget: - case NonStandardArgKind::R2RIndirectionCell: - return true; - default: - unreached(); - } - } - - bool isLateArg() const - { - bool isLate = (_lateArgInx != UINT_MAX); - return isLate; - } - - unsigned GetLateArgInx() const - { - assert(isLateArg()); - return _lateArgInx; - } - void SetLateArgInx(unsigned inx) - { - _lateArgInx = inx; - } - regNumber GetRegNum() const - { - return (regNumber)regNums[0]; - } - - regNumber GetOtherRegNum() const - { - return (regNumber)regNums[1]; - } - -#if defined(UNIX_AMD64_ABI) - SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR structDesc; -#endif - - void setRegNum(unsigned int i, regNumber regNum) - { - assert(i < MAX_ARG_REG_COUNT); - regNums[i] = (regNumberSmall)regNum; - } - regNumber GetRegNum(unsigned int i) - { - assert(i < MAX_ARG_REG_COUNT); - return (regNumber)regNums[i]; - } - - bool IsSplit() const - { -#if FEATURE_ARG_SPLIT - return compFeatureArgSplit() && _isSplit; -#else // FEATURE_ARG_SPLIT - return false; -#endif - } - void SetSplit(bool value) - { -#if FEATURE_ARG_SPLIT - _isSplit = value; -#endif - } - - bool IsVararg() const - { - return compFeatureVarArg() && _isVararg; - } - void SetIsVararg(bool value) - { - if (compFeatureVarArg()) - { - _isVararg = value; - } - } - - bool IsHfaArg() const - { - if (GlobalJitOptions::compFeatureHfa) - { - return IsHfa(GetHfaElemKind()); - } - else - { - return false; - } - } - - bool IsHfaRegArg() const - { - if (GlobalJitOptions::compFeatureHfa) - { - return IsHfa(GetHfaElemKind()) && isPassedInRegisters(); - } - else - { - return false; - } - } - - unsigned intRegCount() const - { -#if defined(UNIX_AMD64_ABI) - if (this->isStruct) - { - return this->structIntRegs; - } -#endif // defined(UNIX_AMD64_ABI) - - if (!this->isPassedInFloatRegisters()) - { - return this->numRegs; - } - - return 0; - } - - unsigned floatRegCount() const - { -#if defined(UNIX_AMD64_ABI) - if (this->isStruct) - { - return this->structFloatRegs; - } -#endif // defined(UNIX_AMD64_ABI) - - if (this->isPassedInFloatRegisters()) - { - return this->numRegs; - } - - return 0; - } - - // Get the number of bytes that this argument is occupying on the stack, - // including padding up to the target pointer size for platforms - // where a stack argument can't take less. - unsigned GetStackByteSize() const - { - if (!IsSplit() && numRegs > 0) - { - return 0; - } - - assert(!IsHfaArg() || !IsSplit()); - - assert(GetByteSize() > TARGET_POINTER_SIZE * numRegs); - const unsigned stackByteSize = GetByteSize() - TARGET_POINTER_SIZE * numRegs; - return stackByteSize; - } - - var_types GetHfaType() const - { - if (GlobalJitOptions::compFeatureHfa) - { - return HfaTypeFromElemKind(GetHfaElemKind()); - } - else - { - return TYP_UNDEF; - } - } - - void SetHfaType(var_types type, unsigned hfaSlots) - { - if (GlobalJitOptions::compFeatureHfa) - { - if (type != TYP_UNDEF) - { - // We must already have set the passing mode. - assert(numRegs != 0 || GetStackByteSize() != 0); - // We originally set numRegs according to the size of the struct, but if the size of the - // hfaType is not the same as the pointer size, we need to correct it. - // Note that hfaSlots is the number of registers we will use. For ARM, that is twice - // the number of "double registers". - unsigned numHfaRegs = hfaSlots; -#ifdef TARGET_ARM - if (type == TYP_DOUBLE) - { - // Must be an even number of registers. - assert((numRegs & 1) == 0); - numHfaRegs = hfaSlots / 2; - } -#endif // TARGET_ARM - - if (!IsHfaArg()) - { - // We haven't previously set this; do so now. - CorInfoHFAElemType elemKind = HfaElemKindFromType(type); - SetHfaElemKind(elemKind); - // Ensure we've allocated enough bits. - assert(GetHfaElemKind() == elemKind); - if (isPassedInRegisters()) - { - numRegs = numHfaRegs; - } - } - else - { - // We've already set this; ensure that it's consistent. - if (isPassedInRegisters()) - { - assert(numRegs == numHfaRegs); - } - assert(type == HfaTypeFromElemKind(GetHfaElemKind())); - } - } - } - } - -#ifdef TARGET_ARM - void SetIsBackFilled(bool backFilled) - { - isBackFilled = backFilled; - } - - bool IsBackFilled() const - { - return isBackFilled; - } -#else // !TARGET_ARM - void SetIsBackFilled(bool backFilled) - { - } - - bool IsBackFilled() const - { - return false; - } -#endif // !TARGET_ARM - - bool isPassedInRegisters() const - { - return !IsSplit() && (numRegs != 0); - } - - bool isPassedInFloatRegisters() const - { -#ifdef TARGET_X86 - return false; -#else - return isValidFloatArgReg(GetRegNum()); -#endif - } - - // Can we replace the struct type of this node with a primitive type for argument passing? - bool TryPassAsPrimitive() const - { - return !IsSplit() && ((numRegs == 1) || (m_byteSize <= TARGET_POINTER_SIZE)); - } - -#if defined(DEBUG_ARG_SLOTS) - // Returns the number of "slots" used, where for this purpose a - // register counts as a slot. - unsigned getSlotCount() const - { - if (isBackFilled) - { - assert(isPassedInRegisters()); - assert(numRegs == 1); - } - else if (GetRegNum() == REG_STK) - { - assert(!isPassedInRegisters()); - assert(numRegs == 0); - } - else - { - assert(numRegs > 0); - } - return numSlots + numRegs; - } -#endif - -#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 - { - unsigned size = getSlotCount(); - if (GlobalJitOptions::compFeatureHfa) - { - if (IsHfaRegArg()) - { -#ifdef TARGET_ARM - // We counted the number of regs, but if they are DOUBLE hfa regs we have to double the size. - if (GetHfaType() == TYP_DOUBLE) - { - assert(!IsSplit()); - size <<= 1; - } -#elif defined(TARGET_ARM64) - // We counted the number of regs, but if they are FLOAT hfa regs we have to halve the size, - // or if they are SIMD16 vector hfa regs we have to double the size. - if (GetHfaType() == TYP_FLOAT) - { - // Round up in case of odd HFA count. - size = (size + 1) >> 1; - } -#ifdef FEATURE_SIMD - else if (GetHfaType() == TYP_SIMD16) - { - size <<= 1; - } -#endif // FEATURE_SIMD -#endif // TARGET_ARM64 - } - } - return size; - } - -#endif // DEBUG_ARG_SLOTS - -private: - unsigned m_byteOffset; - - // byte size that this argument takes including the padding after. - // For example, 1-byte arg on x64 with 8-byte alignment - // will have `m_byteSize == 8`, the same arg on apple arm64 will have `m_byteSize == 1`. - unsigned m_byteSize; - - unsigned m_byteAlignment; // usually 4 or 8 bytes (slots/registers). - -public: - void SetByteOffset(unsigned byteOffset) - { - DEBUG_ARG_SLOTS_ASSERT(byteOffset / TARGET_POINTER_SIZE == slotNum); - m_byteOffset = byteOffset; - } - - unsigned GetByteOffset() const - { - DEBUG_ARG_SLOTS_ASSERT(m_byteOffset / TARGET_POINTER_SIZE == slotNum); - return m_byteOffset; - } - - void SetByteSize(unsigned byteSize, bool isStruct, bool isFloatHfa) - { - - unsigned roundedByteSize; - if (compMacOsArm64Abi()) - { - // Only struct types need extension or rounding to pointer size, but HFA does not. - if (isStruct && !isFloatHfa) - { - roundedByteSize = roundUp(byteSize, TARGET_POINTER_SIZE); - } - else - { - roundedByteSize = byteSize; - } - } - else - { - roundedByteSize = roundUp(byteSize, TARGET_POINTER_SIZE); - } - -#if !defined(TARGET_ARM) - // Arm32 could have a struct with 8 byte alignment - // which rounded size % 8 is not 0. - assert(m_byteAlignment != 0); - assert(roundedByteSize % m_byteAlignment == 0); -#endif // TARGET_ARM - -#if defined(DEBUG_ARG_SLOTS) - if (!compMacOsArm64Abi() && !isStruct) - { - assert(roundedByteSize == getSlotCount() * TARGET_POINTER_SIZE); - } -#endif - m_byteSize = roundedByteSize; - } - - unsigned GetByteSize() const - { - return m_byteSize; - } - - void SetByteAlignment(unsigned byteAlignment) - { - m_byteAlignment = byteAlignment; - } - - unsigned GetByteAlignment() const - { - return m_byteAlignment; - } - - // Set the register numbers for a multireg argument. - // There's nothing to do on x64/Ux because the structDesc has already been used to set the - // register numbers. - void SetMultiRegNums() - { -#if FEATURE_MULTIREG_ARGS && !defined(UNIX_AMD64_ABI) - if (numRegs == 1) - { - return; - } - - regNumber argReg = GetRegNum(0); -#ifdef TARGET_ARM - unsigned int regSize = (GetHfaType() == TYP_DOUBLE) ? 2 : 1; -#else - unsigned int regSize = 1; -#endif - - if (numRegs > MAX_ARG_REG_COUNT) - NO_WAY("Multireg argument exceeds the maximum length"); - - for (unsigned int regIndex = 1; regIndex < numRegs; regIndex++) - { - argReg = (regNumber)(argReg + regSize); - setRegNum(regIndex, argReg); - } -#endif // FEATURE_MULTIREG_ARGS && !defined(UNIX_AMD64_ABI) - } - -#ifdef DEBUG - // Check that the value of 'isStruct' is consistent. - // A struct arg must be one of the following: - // - A node of struct type, - // - A GT_FIELD_LIST, or - // - A node of a scalar type, passed in a single register or slot - // (or two slots in the case of a struct pass on the stack as TYP_DOUBLE). - // - void checkIsStruct() const - { - GenTree* node = GetNode(); - if (isStruct) - { - if (!varTypeIsStruct(node) && !node->OperIs(GT_FIELD_LIST)) - { - // This is the case where we are passing a struct as a primitive type. - // On most targets, this is always a single register or slot. - // However, on ARM this could be two slots if it is TYP_DOUBLE. - bool isPassedAsPrimitiveType = - ((numRegs == 1) || ((numRegs == 0) && (GetByteSize() <= TARGET_POINTER_SIZE))); -#ifdef TARGET_ARM - if (!isPassedAsPrimitiveType) - { - if (node->TypeGet() == TYP_DOUBLE && numRegs == 0 && (numSlots == 2)) - { - isPassedAsPrimitiveType = true; - } - } -#endif // TARGET_ARM - assert(isPassedAsPrimitiveType); - } - } - else - { - assert(!varTypeIsStruct(node)); - } - } - - void Dump() const; -#endif -}; - -//------------------------------------------------------------------------- -// -// The class fgArgInfo is used to handle the arguments -// when morphing a GT_CALL node. -// - -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_ARG_SLOTS) - unsigned nextSlotNum; // Updatable slot count value -#endif - unsigned nextStackByteOffset; - unsigned stkLevel; // Stack depth when we make this call (for x86) - -#if defined(UNIX_X86_ABI) - bool alignmentDone; // Updateable flag, set to 'true' after we've done any required alignment. - unsigned stkSizeBytes; // Size of stack used by this call, in bytes. Calculated during fgMorphArgs(). - unsigned padStkAlign; // Stack alignment in bytes required before arguments are pushed for this call. - // Computed dynamically during codegen, based on stkSizeBytes and the current - // stack level (genStackLevel) when the first stack adjustment is made for - // this call. -#endif - -#if FEATURE_FIXED_OUT_ARGS - unsigned outArgSize; // Size of the out arg area for the call, will be at least MIN_ARG_AREA_FOR_CALL -#endif - - unsigned argTableSize; // size of argTable array (equal to the argCount when done with fgMorphArgs) - bool hasRegArgs; // true if we have one or more register arguments - bool hasStackArgs; // true if we have one or more stack arguments - bool argsComplete; // marker for state - bool argsSorted; // marker for state - bool needsTemps; // one or more arguments must be copied to a temp by EvalArgsToTemps - fgArgTabEntry** argTable; // variable sized array of per argument descrption: (i.e. argTable[argTableSize]) - -private: - void AddArg(fgArgTabEntry* curArgTabEntry); - -public: - fgArgInfo(Compiler* comp, GenTreeCall* call, unsigned argCount); - fgArgInfo(GenTreeCall* newCall, GenTreeCall* oldCall); - - fgArgTabEntry* AddRegArg(unsigned argNum, - GenTree* node, - GenTreeCall::Use* use, - regNumber regNum, - unsigned numRegs, - unsigned byteSize, - unsigned byteAlignment, - bool isStruct, - bool isFloatHfa, - bool isVararg = false); - -#ifdef UNIX_AMD64_ABI - fgArgTabEntry* AddRegArg(unsigned argNum, - GenTree* node, - GenTreeCall::Use* use, - regNumber regNum, - unsigned numRegs, - unsigned byteSize, - unsigned byteAlignment, - const bool isStruct, - const bool isFloatHfa, - const bool isVararg, - const regNumber otherRegNum, - const unsigned structIntRegs, - const unsigned structFloatRegs, - const SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR* const structDescPtr = nullptr); -#endif // UNIX_AMD64_ABI - - fgArgTabEntry* AddStkArg(unsigned argNum, - GenTree* node, - GenTreeCall::Use* use, - unsigned numSlots, - unsigned byteSize, - unsigned byteAlignment, - bool isStruct, - bool isFloatHfa, - bool isVararg = false); - - void RemorphReset(); - void UpdateRegArg(fgArgTabEntry* argEntry, GenTree* node, bool reMorphing); - void UpdateStkArg(fgArgTabEntry* argEntry, GenTree* node, bool reMorphing); - - void SplitArg(unsigned argNum, unsigned numRegs, unsigned numSlots); - - void EvalToTmp(fgArgTabEntry* curArgTabEntry, unsigned tmpNum, GenTree* newNode); - - void ArgsComplete(); - - void SortArgs(); - - void EvalArgsToTemps(); - - unsigned ArgCount() const - { - return argCount; - } - fgArgTabEntry** ArgTable() const - { - return argTable; - } - -#if defined(DEBUG_ARG_SLOTS) - unsigned GetNextSlotNum() const - { - return nextSlotNum; - } -#endif - - unsigned GetNextSlotByteOffset() const - { - return nextStackByteOffset; - } - - bool HasRegArgs() const - { - return hasRegArgs; - } - bool NeedsTemps() const - { - return needsTemps; - } - bool HasStackArgs() const - { - return hasStackArgs; - } - bool AreArgsComplete() const - { - return argsComplete; - } -#if FEATURE_FIXED_OUT_ARGS - unsigned GetOutArgSize() const - { - return outArgSize; - } - void SetOutArgSize(unsigned newVal) - { - outArgSize = newVal; - } -#endif // FEATURE_FIXED_OUT_ARGS - -#if defined(UNIX_X86_ABI) - void ComputeStackAlignment(unsigned curStackLevelInBytes) - { - padStkAlign = AlignmentPad(curStackLevelInBytes, STACK_ALIGN); - } - - unsigned GetStkAlign() const - { - return padStkAlign; - } - - void SetStkSizeBytes(unsigned newStkSizeBytes) - { - stkSizeBytes = newStkSizeBytes; - } - - unsigned GetStkSizeBytes() const - { - return stkSizeBytes; - } - - bool IsStkAlignmentDone() const - { - return alignmentDone; - } - - void SetStkAlignmentDone() - { - alignmentDone = true; - } -#endif // defined(UNIX_X86_ABI) - - // Get the fgArgTabEntry for the arg at position argNum. - fgArgTabEntry* GetArgEntry(unsigned argNum, bool reMorphing = true) const - { - fgArgTabEntry* curArgTabEntry = nullptr; - - if (!reMorphing) - { - // The arg table has not yet been sorted. - curArgTabEntry = argTable[argNum]; - assert(curArgTabEntry->argNum == argNum); - return curArgTabEntry; - } - - for (unsigned i = 0; i < argCount; i++) - { - curArgTabEntry = argTable[i]; - if (curArgTabEntry->argNum == argNum) - { - return curArgTabEntry; - } - } - noway_assert(!"GetArgEntry: argNum not found"); - return nullptr; - } - void SetNeedsTemps() - { - needsTemps = true; - } - - // Get the node for the arg at position argIndex. - // Caller must ensure that this index is a valid arg index. - GenTree* GetArgNode(unsigned argIndex) const - { - return GetArgEntry(argIndex)->GetNode(); - } - - void Dump(Compiler* compiler) const; -}; - #ifdef DEBUG // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // We have the ability to mark source expressions with "Test Labels." @@ -2621,6 +1829,7 @@ class Compiler friend struct GenTree; friend class MorphInitBlockHelper; friend class MorphCopyBlockHelper; + friend class CallArgs; #ifdef FEATURE_HW_INTRINSICS friend struct HWIntrinsicInfo; @@ -3117,25 +2326,16 @@ class Compiler GenTree* gtNewCpObjNode(GenTree* dst, GenTree* src, CORINFO_CLASS_HANDLE structHnd, bool isVolatile); - GenTreeCall::Use* gtNewCallArgs(GenTree* node); - GenTreeCall::Use* gtNewCallArgs(GenTree* node1, GenTree* node2); - GenTreeCall::Use* gtNewCallArgs(GenTree* node1, GenTree* node2, GenTree* node3); - GenTreeCall::Use* gtNewCallArgs(GenTree* node1, GenTree* node2, GenTree* node3, GenTree* node4); - GenTreeCall::Use* gtPrependNewCallArg(GenTree* node, GenTreeCall::Use* args); - GenTreeCall::Use* gtInsertNewCallArgAfter(GenTree* node, GenTreeCall::Use* after); - GenTreeCall* gtNewCallNode(gtCallTypes callType, CORINFO_METHOD_HANDLE handle, var_types type, - GenTreeCall::Use* args, const DebugInfo& di = DebugInfo()); GenTreeCall* gtNewIndCallNode(GenTree* addr, var_types type, - GenTreeCall::Use* args, const DebugInfo& di = DebugInfo()); - GenTreeCall* gtNewHelperCallNode(unsigned helper, var_types type, GenTreeCall::Use* args = nullptr); + GenTreeCall* gtNewHelperCallNode(unsigned helper, var_types type, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, GenTree* arg3 = nullptr); GenTreeCall* gtNewRuntimeLookupHelperCallNode(CORINFO_RUNTIME_LOOKUP* pRuntimeLookup, GenTree* ctxTree, @@ -3404,10 +2604,7 @@ class Compiler var_types gtTypeForNullCheck(GenTree* tree); void gtChangeOperToNullCheck(GenTree* tree, BasicBlock* block); - static fgArgTabEntry* gtArgEntryByArgNum(GenTreeCall* call, unsigned argNum); - static fgArgTabEntry* gtArgEntryByNode(GenTreeCall* call, GenTree* node); - fgArgTabEntry* gtArgEntryByLateArgIndex(GenTreeCall* call, unsigned lateArgInx); - static GenTree* gtArgNodeByLateArgInx(GenTreeCall* call, unsigned lateArgInx); + void gtChangeCallToHelperCall(GenTreeCall* call, CorInfoHelpFunc func); GenTreeOp* gtNewAssignNode(GenTree* dst, GenTree* src); @@ -3506,7 +2703,7 @@ class Compiler bool gtHasLocalsWithAddrOp(GenTree* tree); - unsigned gtSetCallArgsOrder(const GenTreeCall::UseList& args, bool lateArgs, int* callCostEx, int* callCostSz); + unsigned gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCostEx, int* callCostSz); unsigned gtSetMultiOpOrder(GenTreeMultiOp* multiOp); void gtWalkOp(GenTree** op1, GenTree** op2, GenTree* base, bool constOnly); @@ -3549,8 +2746,6 @@ class Compiler GenTreeFlags GenTreeFlags = GTF_SIDE_EFFECT, bool ignoreRoot = false); - GenTree* gtGetThisArg(GenTreeCall* call); - // Static fields of struct types (and sometimes the types that those are reduced to) are represented by having the // static field contain an object pointer to the boxed struct. This simplifies the GC implementation...but // complicates the JIT somewhat. This predicate returns "true" iff a node with type "fieldNodeType", representing @@ -3662,8 +2857,10 @@ class Compiler void gtDispILLocation(const ILLocation& loc); void gtDispStmt(Statement* stmt, const char* msg = nullptr); void gtDispBlockStmts(BasicBlock* block); - void gtGetArgMsg(GenTreeCall* call, GenTree* arg, unsigned argNum, char* bufp, unsigned bufLength); - void gtGetLateArgMsg(GenTreeCall* call, GenTree* arg, int argNum, char* bufp, unsigned bufLength); + void gtPrintArgPrefix(GenTreeCall* call, CallArg* arg, char** bufp, unsigned* bufLength); + const char* gtGetWellKnownArgNameForArgMsg(WellKnownArg arg); + void gtGetArgMsg(GenTreeCall* call, CallArg* arg, char* bufp, unsigned bufLength); + void gtGetLateArgMsg(GenTreeCall* call, CallArg* arg, char* bufp, unsigned bufLength); void gtDispArgList(GenTreeCall* call, GenTree* lastCallOperand, IndentStack* indentStack); void gtDispAnyFieldSeq(FieldSeqNode* fieldSeq); void gtDispFieldSeq(FieldSeqNode* pfsn); @@ -4386,7 +3583,7 @@ class Compiler void impCheckForPInvokeCall( GenTreeCall* call, CORINFO_METHOD_HANDLE methHnd, CORINFO_SIG_INFO* sig, unsigned mflags, BasicBlock* block); GenTreeCall* impImportIndirectCall(CORINFO_SIG_INFO* sig, const DebugInfo& di = DebugInfo()); - void impPopArgsForUnmanagedCall(GenTree* call, CORINFO_SIG_INFO* sig); + void impPopArgsForUnmanagedCall(GenTreeCall* call, CORINFO_SIG_INFO* sig); void impInsertHelperCall(CORINFO_HELPER_DESC* helperCall); void impHandleAccessAllowed(CorInfoIsAccessAllowedResult result, CORINFO_HELPER_DESC* helperCall); @@ -4653,7 +3850,7 @@ class Compiler GenTreeCall* impReadyToRunHelperToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken, CorInfoHelpFunc helper, var_types type, - GenTreeCall::Use* args = nullptr, + GenTree* arg1 = nullptr, CORINFO_LOOKUP_KIND* pGenericLookupKind = nullptr); bool impIsCastHelperEligibleForClassProbe(GenTree* tree); @@ -4714,11 +3911,11 @@ class Compiler ((opcode >= CEE_STLOC_0) && (opcode <= CEE_STLOC_3))); } - GenTreeCall::Use* impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, GenTreeCall::Use* prefixArgs = nullptr); + void impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList); bool impCheckImplicitArgumentCoercion(var_types sigType, var_types nodeType) const; - GenTreeCall::Use* impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, unsigned skipReverseCount = 0); + void impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList, unsigned skipReverseCount = 0); //---------------- Spilling the importer stack ---------------------------- @@ -4954,7 +4151,7 @@ class Compiler bool impInlineIsThis(GenTree* tree, InlArgInfo* inlArgInfo); bool impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* additionalTree, - GenTreeCall::Use* additionalCallArgs, + CallArgs* additionalCallArgs, GenTree* dereferencedAddress, InlArgInfo* inlArgInfo); @@ -6054,7 +5251,6 @@ class Compiler bool fgCastNeeded(GenTree* tree, var_types toType); GenTree* fgDoNormalizeOnStore(GenTree* tree); - GenTree* fgMakeTmpArgNode(fgArgTabEntry* curArgTabEntry); // The following check for loops that don't execute calls bool fgLoopCallMarked; @@ -6377,7 +5573,7 @@ class Compiler GenTree* fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* oper); - GenTree* fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeCall::Use* args, bool morphArgs = true); + GenTree* fgMorphIntoHelperCall(GenTree* tree, int helper, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, bool morphArgs = true); GenTree* fgMorphStackArgForVarArgs(unsigned lclNum, var_types varType, unsigned lclOffs); @@ -6431,7 +5627,7 @@ class Compiler void fgInitArgInfo(GenTreeCall* call); GenTreeCall* fgMorphArgs(GenTreeCall* call); - void fgMakeOutgoingStructArgCopy(GenTreeCall* call, GenTreeCall::Use* args, CORINFO_CLASS_HANDLE copyBlkClass); + void fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg, CORINFO_CLASS_HANDLE copyBlkClass); GenTree* fgMorphLocalVar(GenTree* tree, bool forceRemorph); @@ -6465,10 +5661,10 @@ class Compiler GenTree* fgMorphPotentialTailCall(GenTreeCall* call); GenTree* fgGetStubAddrArg(GenTreeCall* call); - unsigned fgGetArgTabEntryParameterLclNum(GenTreeCall* call, fgArgTabEntry* argTabEntry); + unsigned fgGetArgParameterLclNum(GenTreeCall* call, CallArg* arg); void fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCall* recursiveTailCall); - Statement* fgAssignRecursiveCallArgToCallerParam(GenTree* arg, - fgArgTabEntry* argTabEntry, + Statement* fgAssignRecursiveCallArgToCallerParam(GenTree* arg, + CallArg* callArg, unsigned lclParamNum, BasicBlock* block, const DebugInfo& callDI, @@ -11329,7 +10525,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #endif // defined(UNIX_AMD64_ABI) void fgMorphMultiregStructArgs(GenTreeCall* call); - GenTree* fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntryPtr); + GenTree* fgMorphMultiregStructArg(CallArg* arg); bool killGCRefs(GenTree* tree); }; // end of class Compiler @@ -11677,27 +10873,18 @@ class GenTreeVisitor { GenTreeCall* const call = node->AsCall(); - if (call->gtCallThisArg != nullptr) - { - result = WalkTree(&call->gtCallThisArg->NodeRef(), call); - if (result == fgWalkResult::WALK_ABORT) - { - return result; - } - } - - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - result = WalkTree(&use.NodeRef(), call); + result = WalkTree(&arg.NodeRef(), call); if (result == fgWalkResult::WALK_ABORT) { return result; } } - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - result = WalkTree(&use.NodeRef(), call); + result = WalkTree(&arg.NodeRef(), call); if (result == fgWalkResult::WALK_ABORT) { return result; diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index c0a08412a10ad4..d4177f06e3076c 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -1002,10 +1002,10 @@ inline GenTree* Compiler::gtNewIconEmbFldHndNode(CORINFO_FIELD_HANDLE fldHnd) // Return Value: // New CT_HELPER node -inline GenTreeCall* Compiler::gtNewHelperCallNode(unsigned helper, var_types type, GenTreeCall::Use* args) +inline GenTreeCall* Compiler::gtNewHelperCallNode(unsigned helper, var_types type, GenTree* arg1, GenTree* arg2, GenTree* arg3) { GenTreeFlags flags = s_helperCallProperties.NoThrow((CorInfoHelpFunc)helper) ? GTF_EMPTY : GTF_EXCEPT; - GenTreeCall* result = gtNewCallNode(CT_HELPER, eeFindHelper(helper), type, args); + GenTreeCall* result = gtNewCallNode(CT_HELPER, eeFindHelper(helper), type); result->gtFlags |= flags; #if DEBUG @@ -1014,6 +1014,22 @@ inline GenTreeCall* Compiler::gtNewHelperCallNode(unsigned helper, var_types typ result->gtInlineObservation = InlineObservation::CALLSITE_IS_CALL_TO_HELPER; #endif + if (arg1 != nullptr) + { + result->gtFlags |= arg1->gtFlags & GTF_ALL_EFFECT; + CallArg* lastArg = result->gtArgs.PushFront(this, arg1); + if (arg2 != nullptr) + { + lastArg = result->gtArgs.InsertAfter(this, lastArg, arg2); + result->gtFlags |= arg2->gtFlags & GTF_ALL_EFFECT; + if (arg3 != nullptr) + { + result->gtArgs.InsertAfter(this, lastArg, arg3); + result->gtFlags |= arg3->gtFlags & GTF_ALL_EFFECT; + } + } + } + return result; } @@ -1034,9 +1050,10 @@ inline GenTreeCall* Compiler::gtNewRuntimeLookupHelperCallNode(CORINFO_RUNTIME_L void* compileTimeHandle) { GenTree* argNode = gtNewIconEmbHndNode(pRuntimeLookup->signature, nullptr, GTF_ICON_GLOBAL_PTR, compileTimeHandle); - GenTreeCall::Use* helperArgs = gtNewCallArgs(ctxTree, argNode); + GenTreeCall* call = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL); + call->gtArgs.PushFront(this, ctxTree, argNode); - return gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL, helperArgs); + return call; } //------------------------------------------------------------------------ @@ -1351,6 +1368,10 @@ inline void GenTree::SetOper(genTreeOps oper, ValueNumberUpdate vnUpdate) AsLclFld()->SetFieldSeq(FieldSeqStore::NotAField()); break; + case GT_CALL: + new (&AsCall()->gtArgs, jitstd::placement_t()) CallArgs(); + break; + default: break; } @@ -4350,22 +4371,18 @@ void GenTree::VisitOperands(TVisitor visitor) case GT_CALL: { GenTreeCall* const call = this->AsCall(); - if ((call->gtCallThisArg != nullptr) && (visitor(call->gtCallThisArg->GetNode()) == VisitResult::Abort)) - { - return; - } - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - if (visitor(use.GetNode()) == VisitResult::Abort) + if (visitor(arg.GetNode()) == VisitResult::Abort) { return; } } - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - if (visitor(use.GetNode()) == VisitResult::Abort) + if (visitor(arg.GetNode()) == VisitResult::Abort) { return; } diff --git a/src/coreclr/jit/decomposelongs.cpp b/src/coreclr/jit/decomposelongs.cpp index 9b75e4c73727b9..76bb3f95601100 100644 --- a/src/coreclr/jit/decomposelongs.cpp +++ b/src/coreclr/jit/decomposelongs.cpp @@ -1355,9 +1355,10 @@ GenTree* DecomposeLongs::DecomposeShift(LIR::Use& use) unreached(); } - GenTreeCall::Use* argList = m_compiler->gtNewCallArgs(loOp1, hiOp1, shiftByOp); - - GenTreeCall* call = m_compiler->gtNewHelperCallNode(helper, TYP_LONG, argList); + GenTreeCall* call = m_compiler->gtNewHelperCallNode(helper, TYP_LONG); + call->gtArgs.PushBack(m_compiler, loOp1, WellKnownArg::ShiftLow); + call->gtArgs.PushBack(m_compiler, hiOp1, WellKnownArg::ShiftHigh); + call->gtArgs.PushBack(m_compiler, shiftByOp); call->gtFlags |= shift->gtFlags & GTF_ALL_EFFECT; if (shift->IsUnusedValue()) diff --git a/src/coreclr/jit/earlyprop.cpp b/src/coreclr/jit/earlyprop.cpp index 283c9c8901ae7c..e1401f1d3469a0 100644 --- a/src/coreclr/jit/earlyprop.cpp +++ b/src/coreclr/jit/earlyprop.cpp @@ -58,15 +58,17 @@ GenTree* Compiler::getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBloc call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_NEWARR_1_ALIGN8)) { // This is an array allocation site. Grab the array length node. - arrayLength = gtArgEntryByArgNum(call, 1)->GetNode(); + arrayLength = call->gtArgs.GetArgByIndex(1)->GetArgNode(); } else if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_READYTORUN_NEWARR_1)) { // On arm when compiling on certain platforms for ready to run, a handle will be // inserted before the length. To handle this case, we will grab the last argument - // as that's always the length. See fgInitArgInfo for where the handle is inserted. - int arrLenArgNum = call->fgArgInfo->ArgCount() - 1; - arrayLength = gtArgEntryByArgNum(call, arrLenArgNum)->GetNode(); + // as that's always the length. See DetermineABIArgInformation for where the handle is inserted. + for (CallArg& arg : call->gtArgs.Args()) + { + arrayLength = arg.GetArgNode(); + } } #ifdef DEBUG if (arrayLength != nullptr) diff --git a/src/coreclr/jit/fgdiagnostic.cpp b/src/coreclr/jit/fgdiagnostic.cpp index 0e4f7ec3ec487f..4061f396e05153 100644 --- a/src/coreclr/jit/fgdiagnostic.cpp +++ b/src/coreclr/jit/fgdiagnostic.cpp @@ -3029,44 +3029,17 @@ void Compiler::fgDebugCheckFlags(GenTree* tree) call = tree->AsCall(); - if ((call->gtCallThisArg != nullptr) && ((call->gtCallThisArg->GetNode()->gtFlags & GTF_ASG) != 0)) + for (CallArg& arg : call->gtArgs.Args()) { // TODO-Cleanup: this is a patch for a violation in our GT_ASG propagation. // see https://github.com/dotnet/runtime/issues/13758 - actualFlags |= GTF_ASG; - } - - for (GenTreeCall::Use& use : call->Args()) - { - if ((use.GetNode()->gtFlags & GTF_ASG) != 0) - { - // TODO-Cleanup: this is a patch for a violation in our GT_ASG propagation. - // see https://github.com/dotnet/runtime/issues/13758 - actualFlags |= GTF_ASG; - } - } - - for (GenTreeCall::Use& use : call->LateArgs()) - { - if ((use.GetNode()->gtFlags & GTF_ASG) != 0) + actualFlags |= arg.GetNode()->gtFlags & GTF_ASG; + if (arg.GetLateNode() != nullptr) { - // TODO-Cleanup: this is a patch for a violation in our GT_ASG propagation. - // see https://github.com/dotnet/runtime/issues/13758 - actualFlags |= GTF_ASG; + actualFlags |= arg.GetLateNode()->gtFlags & GTF_ASG; } } - if (call->IsUnmanaged() && ((call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) != 0)) - { - if (call->gtCallArgs->GetNode()->OperGet() == GT_NOP) - { - assert(call->gtCallLateArgs->GetNode()->TypeIs(TYP_I_IMPL, TYP_BYREF)); - } - else - { - assert(call->gtCallArgs->GetNode()->TypeIs(TYP_I_IMPL, TYP_BYREF)); - } - } break; case GT_CMPXCHG: diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index 25de6f11e07217..8ccc3adfaf827b 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -715,8 +715,7 @@ void BlockCountInstrumentor::InstrumentMethodEntry(Schema& schema, uint8_t* prof // the first time this method is called. So make the call conditional // on the entry block's profile count. // - GenTreeCall::Use* args = m_comp->gtNewCallArgs(arg); - GenTree* call = m_comp->gtNewHelperCallNode(CORINFO_HELP_BBT_FCN_ENTER, TYP_VOID, args); + GenTreeCall* call = m_comp->gtNewHelperCallNode(CORINFO_HELP_BBT_FCN_ENTER, TYP_VOID, arg); var_types typ = entry.InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::BasicBlockIntCount ? TYP_INT : TYP_LONG; @@ -1561,16 +1560,15 @@ class ClassProbeInserter uint8_t* classProfile = m_schema[*m_currentSchemaIndex].Offset + m_profileMemory; *m_currentSchemaIndex += 2; // There are 2 schema entries per class probe - GenTreeCall::Use* objUse = nullptr; + CallArg* objUse = nullptr; if (compiler->impIsCastHelperEligibleForClassProbe(call)) { - // Grab the second arg of cast/isinst helper call - objUse = call->gtCallArgs->GetNext(); + // Second arg of cast/isinst helper call is the object instance + objUse = call->gtArgs.GetArgByIndex(1); } else { - // Grab 'this' arg - objUse = call->gtCallThisArg; + objUse = call->gtArgs.GetThisArg(); } assert(objUse->GetNode()->TypeIs(TYP_REF)); @@ -1584,10 +1582,8 @@ class ClassProbeInserter // GenTree* const classProfileNode = compiler->gtNewIconNode((ssize_t)classProfile, TYP_I_IMPL); GenTree* const tmpNode = compiler->gtNewLclvNode(tmpNum, TYP_REF); - GenTreeCall::Use* const args = compiler->gtNewCallArgs(tmpNode, classProfileNode); - GenTree* const helperCallNode = - compiler->gtNewHelperCallNode(is32 ? CORINFO_HELP_CLASSPROFILE32 : CORINFO_HELP_CLASSPROFILE64, TYP_VOID, - args); + GenTreeCall* const helperCallNode = + compiler->gtNewHelperCallNode(is32 ? CORINFO_HELP_CLASSPROFILE32 : CORINFO_HELP_CLASSPROFILE64, TYP_VOID, tmpNode, classProfileNode); GenTree* const tmpNode2 = compiler->gtNewLclvNode(tmpNum, TYP_REF); GenTree* const callCommaNode = compiler->gtNewOperNode(GT_COMMA, TYP_REF, helperCallNode, tmpNode2); GenTree* const tmpNode3 = compiler->gtNewLclvNode(tmpNum, TYP_REF); diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index afc066f9682073..eb201e1b8d6a06 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -840,8 +840,6 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo break; } - GenTreeCall::Use* argList = nullptr; - GenTree* opModuleIDArg; GenTree* opClassIDArg; @@ -872,6 +870,8 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo opModuleIDArg = gtNewIconNode((size_t)moduleID, TYP_I_IMPL); } + GenTreeCall* result = gtNewHelperCallNode(helper, type); + CallArg* opModuleIDCallArg = result->gtArgs.PushFront(this, opModuleIDArg); if (bNeedClassID) { if (pclsID) @@ -883,15 +883,9 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo opClassIDArg = gtNewIconNode(clsID, TYP_INT); } - // call the helper to get the base - argList = gtNewCallArgs(opModuleIDArg, opClassIDArg); - } - else - { - argList = gtNewCallArgs(opModuleIDArg); + result->gtArgs.InsertAfter(this, opModuleIDCallArg, opClassIDArg); } - GenTreeCall* result = gtNewHelperCallNode(helper, type, argList); result->gtFlags |= callFlags; // If we're importing the special EqualityComparer.Default or Comparer.Default @@ -1054,7 +1048,8 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, CORINFO_METHOD_HANDLE methHnd = call->gtCallMethHnd; CORINFO_CLASS_HANDLE clsHnd = info.compCompHnd->getMethodClass(methHnd); - GenTree* targetMethod = call->gtCallArgs->GetNext()->GetNode(); + assert(call->gtArgs.CountArgs() == 3); + GenTree* targetMethod = call->gtArgs.GetArgByIndex(2)->GetNode(); noway_assert(targetMethod->TypeGet() == TYP_I_IMPL); genTreeOps oper = targetMethod->OperGet(); CORINFO_METHOD_HANDLE targetMethodHnd = nullptr; @@ -1067,7 +1062,8 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, } else if (oper == GT_CALL && targetMethod->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_VIRTUAL_FUNC_PTR)) { - GenTree* handleNode = targetMethod->AsCall()->gtCallArgs->GetNext()->GetNext()->GetNode(); + assert(targetMethod->AsCall()->gtArgs.CountArgs() == 3); + GenTree* handleNode = targetMethod->AsCall()->gtArgs.GetArgByIndex(2)->GetNode(); if (handleNode->OperGet() == GT_CNS_INT) { @@ -1106,7 +1102,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, GenTreeCall* runtimeLookupCall = qmarkNode->AsOp()->gtOp2->AsOp()->gtOp1->AsCall(); // This could be any of CORINFO_HELP_RUNTIMEHANDLE_(METHOD|CLASS)(_LOG?) - GenTree* tokenNode = runtimeLookupCall->gtCallArgs->GetNext()->GetNode(); + GenTree* tokenNode = runtimeLookupCall->gtArgs.GetArgByIndex(1)->GetNode(); noway_assert(tokenNode->OperGet() == GT_CNS_INT); targetMethodHnd = CORINFO_METHOD_HANDLE(tokenNode->AsIntCon()->gtCompileTimeHandle); } @@ -1138,16 +1134,17 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - GenTree* thisPointer = call->gtCallThisArg->GetNode(); - GenTree* targetObjPointers = call->gtCallArgs->GetNode(); - GenTreeCall::Use* helperArgs = nullptr; + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID); + + GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); CORINFO_LOOKUP pLookup; CORINFO_CONST_LOOKUP entryPoint; info.compCompHnd->getReadyToRunDelegateCtorHelper(ldftnToken, clsHnd, &pLookup); if (!pLookup.lookupKind.needsRuntimeLookup) { - helperArgs = gtNewCallArgs(thisPointer, targetObjPointers); entryPoint = pLookup.constLookup; + call->gtArgs.PushFront(this, thisPointer, targetObjPointers); } else { @@ -1156,10 +1153,9 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, info.compCompHnd->getReadyToRunHelper(ldftnToken, &pLookup.lookupKind, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, &genericLookup); GenTree* ctxTree = getRuntimeContextTree(pLookup.lookupKind.runtimeLookupKind); - helperArgs = gtNewCallArgs(thisPointer, targetObjPointers, ctxTree); + call->gtArgs.PushFront(this, thisPointer, targetObjPointers, ctxTree); entryPoint = genericLookup; } - call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, helperArgs); call->setEntryPoint(entryPoint); } else @@ -1172,11 +1168,10 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - GenTree* thisPointer = call->gtCallThisArg->GetNode(); - GenTree* targetObjPointers = call->gtCallArgs->GetNode(); - GenTreeCall::Use* helperArgs = gtNewCallArgs(thisPointer, targetObjPointers); - - call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, helperArgs); + GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID); + call->gtArgs.PushFront(this, thisPointer, targetObjPointers); CORINFO_LOOKUP entryPoint; info.compCompHnd->getReadyToRunDelegateCtorHelper(ldftnToken, clsHnd, &entryPoint); @@ -1209,24 +1204,24 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, call->gtCallMethHnd = alternateCtor; - noway_assert(call->gtCallArgs->GetNext()->GetNext() == nullptr); - GenTreeCall::Use* addArgs = nullptr; - if (ctorData.pArg5) + CallArg* lastArg = nullptr; + if (ctorData.pArg3 != nullptr) { - GenTree* arg5 = gtNewIconHandleNode(size_t(ctorData.pArg5), GTF_ICON_FTN_ADDR); - addArgs = gtPrependNewCallArg(arg5, addArgs); + GenTree* arg3 = gtNewIconHandleNode(size_t(ctorData.pArg3), GTF_ICON_FTN_ADDR); + lastArg = call->gtArgs.PushBack(this, arg3); } - if (ctorData.pArg4) + + if (ctorData.pArg4 != nullptr) { GenTree* arg4 = gtNewIconHandleNode(size_t(ctorData.pArg4), GTF_ICON_FTN_ADDR); - addArgs = gtPrependNewCallArg(arg4, addArgs); + lastArg = call->gtArgs.InsertAfter(this, lastArg, arg4); } - if (ctorData.pArg3) + + if (ctorData.pArg5 != nullptr) { - GenTree* arg3 = gtNewIconHandleNode(size_t(ctorData.pArg3), GTF_ICON_FTN_ADDR); - addArgs = gtPrependNewCallArg(arg3, addArgs); + GenTree* arg5 = gtNewIconHandleNode(size_t(ctorData.pArg5), GTF_ICON_FTN_ADDR); + lastArg = call->gtArgs.InsertAfter(this, lastArg, arg5); } - call->gtCallArgs->GetNext()->SetNext(addArgs); } else { @@ -1556,11 +1551,12 @@ GenTree* Compiler::fgGetCritSectOfStaticMethod() case CORINFO_LOOKUP_METHODPARAM: { // In this case, the hidden param is the method handle. - tree = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL); - tree->gtFlags |= GTF_VAR_CONTEXT; + GenTree* arg = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL); + arg->gtFlags |= GTF_VAR_CONTEXT; // Call helper CORINFO_HELP_GETCLASSFROMMETHODPARAM to get the class handle // from the method handle. - tree = gtNewHelperCallNode(CORINFO_HELP_GETCLASSFROMMETHODPARAM, TYP_I_IMPL, gtNewCallArgs(tree)); + tree = gtNewHelperCallNode(CORINFO_HELP_GETCLASSFROMMETHODPARAM, TYP_I_IMPL); + tree->AsCall()->gtArgs.PushFront(this, arg); break; } @@ -1574,7 +1570,9 @@ GenTree* Compiler::fgGetCritSectOfStaticMethod() noway_assert(tree); // tree should now contain the CORINFO_CLASS_HANDLE for the exact class. // Given the class handle, get the pointer to the Monitor. - tree = gtNewHelperCallNode(CORINFO_HELP_GETSYNCFROMCLASSHANDLE, TYP_I_IMPL, gtNewCallArgs(tree)); + GenTreeCall* call = gtNewHelperCallNode(CORINFO_HELP_GETSYNCFROMCLASSHANDLE, TYP_I_IMPL); + call->gtArgs.PushFront(this, tree); + tree = call; } noway_assert(tree); @@ -1859,13 +1857,13 @@ GenTree* Compiler::fgCreateMonitorTree(unsigned lvaMonAcquired, unsigned lvaThis { tree = fgGetCritSectOfStaticMethod(); tree = gtNewHelperCallNode(enter ? CORINFO_HELP_MON_ENTER_STATIC : CORINFO_HELP_MON_EXIT_STATIC, TYP_VOID, - gtNewCallArgs(tree, varAddrNode)); + tree, varAddrNode); } else { tree = gtNewLclvNode(lvaThisVar, TYP_REF); tree = gtNewHelperCallNode(enter ? CORINFO_HELP_MON_ENTER : CORINFO_HELP_MON_EXIT, TYP_VOID, - gtNewCallArgs(tree, varAddrNode)); + tree, varAddrNode); } #ifdef DEBUG @@ -1992,14 +1990,8 @@ void Compiler::fgAddReversePInvokeEnterExit() GenTree* tree; - CorInfoHelpFunc reversePInvokeEnterHelper; - - GenTreeCall::Use* args; - if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TRACK_TRANSITIONS)) { - reversePInvokeEnterHelper = CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER_TRACK_TRANSITIONS; - GenTree* stubArgument; if (info.compPublishStubParam) { @@ -2013,16 +2005,21 @@ void Compiler::fgAddReversePInvokeEnterExit() stubArgument = gtNewIconNode(0, TYP_I_IMPL); } - args = gtNewCallArgs(pInvokeFrameVar, gtNewIconEmbMethHndNode(info.compMethodHnd), stubArgument); + tree = gtNewHelperCallNode( + CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER_TRACK_TRANSITIONS, + TYP_VOID, + pInvokeFrameVar, + gtNewIconEmbMethHndNode(info.compMethodHnd), + stubArgument); } else { - reversePInvokeEnterHelper = CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER; - args = gtNewCallArgs(pInvokeFrameVar); + tree = gtNewHelperCallNode( + CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER, + TYP_VOID, + pInvokeFrameVar); } - tree = gtNewHelperCallNode(reversePInvokeEnterHelper, TYP_VOID, args); - fgEnsureFirstBBisScratch(); fgNewStmtAtBeg(fgFirstBB, tree); @@ -2045,7 +2042,7 @@ void Compiler::fgAddReversePInvokeEnterExit() ? CORINFO_HELP_JIT_REVERSE_PINVOKE_EXIT_TRACK_TRANSITIONS : CORINFO_HELP_JIT_REVERSE_PINVOKE_EXIT; - tree = gtNewHelperCallNode(reversePInvokeExitHelper, TYP_VOID, gtNewCallArgs(tree)); + tree = gtNewHelperCallNode(reversePInvokeExitHelper, TYP_VOID, tree); assert(genReturnBB != nullptr); @@ -2809,7 +2806,7 @@ void Compiler::fgAddInternal() { tree = fgGetCritSectOfStaticMethod(); - tree = gtNewHelperCallNode(CORINFO_HELP_MON_ENTER_STATIC, TYP_VOID, gtNewCallArgs(tree)); + tree = gtNewHelperCallNode(CORINFO_HELP_MON_ENTER_STATIC, TYP_VOID, tree); } else { @@ -2817,7 +2814,7 @@ void Compiler::fgAddInternal() tree = gtNewLclvNode(info.compThisArg, TYP_REF); - tree = gtNewHelperCallNode(CORINFO_HELP_MON_ENTER, TYP_VOID, gtNewCallArgs(tree)); + tree = gtNewHelperCallNode(CORINFO_HELP_MON_ENTER, TYP_VOID, tree); } /* Create a new basic block and stick the call in it */ @@ -2846,13 +2843,13 @@ void Compiler::fgAddInternal() { tree = fgGetCritSectOfStaticMethod(); - tree = gtNewHelperCallNode(CORINFO_HELP_MON_EXIT_STATIC, TYP_VOID, gtNewCallArgs(tree)); + tree = gtNewHelperCallNode(CORINFO_HELP_MON_EXIT_STATIC, TYP_VOID, tree); } else { tree = gtNewLclvNode(info.compThisArg, TYP_REF); - tree = gtNewHelperCallNode(CORINFO_HELP_MON_EXIT, TYP_VOID, gtNewCallArgs(tree)); + tree = gtNewHelperCallNode(CORINFO_HELP_MON_EXIT, TYP_VOID, tree); } fgNewStmtNearEnd(genReturnBB, tree); @@ -3000,7 +2997,7 @@ void Compiler::fgSimpleLowering() if (!call->IsFastTailCall() && !call->IsHelperCall(this, CORINFO_HELP_VALIDATE_INDIRECT_CALL)) { // Update outgoing arg size to handle this call - const unsigned thisCallOutAreaSize = call->fgArgInfo->GetOutArgSize(); + const unsigned thisCallOutAreaSize = call->gtArgs.OutgoingArgsStackSize(); assert(thisCallOutAreaSize >= MIN_ARG_AREA_FOR_CALL); if (thisCallOutAreaSize > outgoingArgSpaceSize) @@ -3979,20 +3976,14 @@ void Compiler::fgSetTreeSeqHelper(GenTree* tree, bool isLIR) { case GT_CALL: - /* We'll evaluate the 'this' argument value first */ - if (tree->AsCall()->gtCallThisArg != nullptr) + for (CallArg& arg : tree->AsCall()->gtArgs.Args()) { - fgSetTreeSeqHelper(tree->AsCall()->gtCallThisArg->GetNode(), isLIR); + fgSetTreeSeqHelper(arg.GetNode(), isLIR); } - for (GenTreeCall::Use& use : tree->AsCall()->Args()) + for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) { - fgSetTreeSeqHelper(use.GetNode(), isLIR); - } - - for (GenTreeCall::Use& use : tree->AsCall()->LateArgs()) - { - fgSetTreeSeqHelper(use.GetNode(), isLIR); + fgSetTreeSeqHelper(arg.GetNode(), isLIR); } if ((tree->AsCall()->gtCallType == CT_INDIRECT) && (tree->AsCall()->gtCallCookie != nullptr)) diff --git a/src/coreclr/jit/forwardsub.cpp b/src/coreclr/jit/forwardsub.cpp index c14cbf7a791f10..3620204491bde1 100644 --- a/src/coreclr/jit/forwardsub.cpp +++ b/src/coreclr/jit/forwardsub.cpp @@ -286,14 +286,9 @@ class ForwardSubVisitor final : public GenTreeVisitor // GenTreeFlags oldUseFlags = m_useFlags; - if (m_callAncestor->gtCallThisArg != nullptr) + for (CallArg& arg : m_callAncestor->gtArgs.Args()) { - m_useFlags |= (m_callAncestor->gtCallThisArg->GetNode()->gtFlags & GTF_GLOB_EFFECT); - } - - for (GenTreeCall::Use& use : m_callAncestor->Args()) - { - m_useFlags |= (use.GetNode()->gtFlags & GTF_GLOB_EFFECT); + m_useFlags |= (arg.GetNode()->gtFlags & GTF_GLOB_EFFECT); } if (oldUseFlags != m_useFlags) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 48ee8c67860cbd..b969085f53588d 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -971,6 +971,605 @@ void GenTreeFieldList::InsertFieldLIR( m_uses.InsertUse(insertAfter, new (compiler, CMK_ASTNode) Use(node, offset, type)); } +bool CallArgABIInformation::IsHfaArg() const +{ + if (GlobalJitOptions::compFeatureHfa) + { + return IsHfa(GetHfaElemKind()); + } + else + { + return false; + } +} + +bool CallArgABIInformation::IsHfaRegArg() const +{ + if (GlobalJitOptions::compFeatureHfa) + { + return IsHfa(GetHfaElemKind()) && IsPassedInRegisters(); + } + else + { + return false; + } +} + +var_types CallArgABIInformation::GetHfaType() const +{ + if (GlobalJitOptions::compFeatureHfa) + { + return HfaTypeFromElemKind(GetHfaElemKind()); + } + else + { + return TYP_UNDEF; + } +} + +void CallArgABIInformation::SetHfaType(var_types type, unsigned hfaSlots) +{ + if (GlobalJitOptions::compFeatureHfa) + { + if (type != TYP_UNDEF) + { + // We must already have set the passing mode. + assert(NumRegs != 0 || GetStackByteSize() != 0); + // We originally set numRegs according to the size of the struct, but if the size of the + // hfaType is not the same as the pointer size, we need to correct it. + // Note that hfaSlots is the number of registers we will use. For ARM, that is twice + // the number of "double registers". + unsigned numHfaRegs = hfaSlots; +#ifdef TARGET_ARM + if (type == TYP_DOUBLE) + { + // Must be an even number of registers. + assert((NumRegs & 1) == 0); + numHfaRegs = hfaSlots / 2; + } +#endif // TARGET_ARM + + if (!IsHfaArg()) + { + // We haven't previously set this; do so now. + CorInfoHFAElemType elemKind = HfaElemKindFromType(type); + SetHfaElemKind(elemKind); + // Ensure we've allocated enough bits. + assert(GetHfaElemKind() == elemKind); + if (IsPassedInRegisters()) + { + NumRegs = numHfaRegs; + } + } + else + { + // We've already set this; ensure that it's consistent. + if (IsPassedInRegisters()) + { + assert(NumRegs == numHfaRegs); + } + assert(type == HfaTypeFromElemKind(GetHfaElemKind())); + } + } + } +} + +void CallArgABIInformation::SetByteSize(unsigned byteSize, unsigned byteAlignment, bool isStruct, bool isFloatHfa) +{ + ByteAlignment = byteAlignment; + unsigned roundedByteSize; + if (compMacOsArm64Abi()) + { + // Only struct types need extension or rounding to pointer size, but HFA does not. + if (isStruct && !isFloatHfa) + { + roundedByteSize = roundUp(byteSize, TARGET_POINTER_SIZE); + } + else + { + roundedByteSize = byteSize; + } + } + else + { + roundedByteSize = roundUp(byteSize, TARGET_POINTER_SIZE); + } + +#if !defined(TARGET_ARM) + // Arm32 could have a struct with 8 byte alignment + // which rounded size % 8 is not 0. + assert(ByteAlignment != 0); + assert(roundedByteSize % ByteAlignment == 0); +#endif // TARGET_ARM + +#if defined(DEBUG_ARG_SLOTS) + if (!compMacOsArm64Abi() && !isStruct) + { + assert(roundedByteSize == GetSlotCount() * TARGET_POINTER_SIZE); + } +#endif + ByteSize = roundedByteSize; +} + +#ifdef DEBUG_ARG_SLOTS +unsigned CallArgABIInformation::GetSlotCount() const +{ + if (IsBackFilled) + { + assert(IsPassedInRegisters()); + assert(NumRegs == 1); + } + else if (GetRegNum() == REG_STK) + { + assert(!IsPassedInRegisters()); + assert(NumRegs == 0); + } + else + { + assert(NumRegs > 0); + } + return NumSlots + NumRegs; +} + +unsigned CallArgABIInformation::GetSize() const +{ + unsigned size = GetSlotCount(); + if (GlobalJitOptions::compFeatureHfa) + { + if (IsHfaRegArg()) + { +#ifdef TARGET_ARM + // We counted the number of regs, but if they are DOUBLE hfa regs we have to double the size. + if (GetHfaType() == TYP_DOUBLE) + { + assert(!IsSplit()); + size <<= 1; + } +#elif defined(TARGET_ARM64) + // We counted the number of regs, but if they are FLOAT hfa regs we have to halve the size, + // or if they are SIMD16 vector hfa regs we have to double the size. + if (GetHfaType() == TYP_FLOAT) + { + // Round up in case of odd HFA count. + size = (size + 1) >> 1; + } +#ifdef FEATURE_SIMD + else if (GetHfaType() == TYP_SIMD16) + { + size <<= 1; + } +#endif // FEATURE_SIMD +#endif // TARGET_ARM64 + } + } + return size; +} +#endif + +void CallArgABIInformation::SetMultiRegNums() +{ +#if FEATURE_MULTIREG_ARGS && !defined(UNIX_AMD64_ABI) + if (NumRegs == 1) + { + return; + } + + regNumber argReg = GetRegNum(0); +#ifdef TARGET_ARM + unsigned int regSize = (GetHfaType() == TYP_DOUBLE) ? 2 : 1; +#else + unsigned int regSize = 1; +#endif + + if (NumRegs > MAX_ARG_REG_COUNT) + NO_WAY("Multireg argument exceeds the maximum length"); + + for (unsigned int regIndex = 1; regIndex < NumRegs; regIndex++) + { + argReg = (regNumber)(argReg + regSize); + SetRegNum(regIndex, argReg); + } +#endif // FEATURE_MULTIREG_ARGS && !defined(UNIX_AMD64_ABI) +} + +unsigned CallArgABIInformation::GetStackByteSize() const +{ + if (!IsSplit() && NumRegs > 0) + { + return 0; + } + + assert(!IsHfaArg() || !IsSplit()); + + assert(ByteSize > TARGET_POINTER_SIZE * NumRegs); + const unsigned stackByteSize = ByteSize - TARGET_POINTER_SIZE * NumRegs; + return stackByteSize; +} + +bool CallArg::IsArgAddedLate() const +{ + switch (m_wellKnownArg) + { + case WellKnownArg::WrapperDelegateCell: + case WellKnownArg::VirtualStubCell: + case WellKnownArg::PInvokeCookie: + case WellKnownArg::PInvokeTarget: + case WellKnownArg::R2RIndirectionCell: + return true; + default: + return false; + } +} + +#ifdef DEBUG +void CallArg::CheckIsStruct() +{ + GenTree* node = GetArgNode(); + if (AbiInfo.IsStruct) + { + if (!varTypeIsStruct(node) && !node->OperIs(GT_FIELD_LIST)) + { + // This is the case where we are passing a struct as a primitive type. + // On most targets, this is always a single register or slot. + // However, on ARM this could be two slots if it is TYP_DOUBLE. + bool isPassedAsPrimitiveType = + ((AbiInfo.NumRegs == 1) || ((AbiInfo.NumRegs == 0) && (AbiInfo.ByteSize <= TARGET_POINTER_SIZE))); +#ifdef TARGET_ARM + if (!isPassedAsPrimitiveType) + { + if (node->TypeGet() == TYP_DOUBLE && AbiInfo.NumRegs == 0 && (AbiInfo.NumSlots == 2)) + { + isPassedAsPrimitiveType = true; + } + } +#endif // TARGET_ARM + assert(isPassedAsPrimitiveType); + } + } + else + { + assert(!varTypeIsStruct(node)); + } +} +#endif + +CallArgs::CallArgs() +{ + Clear(); +} + +CallArg* CallArgs::FindByNode(GenTree* node) +{ + assert(node != nullptr); + for (CallArg& arg : Args()) + { + if ((arg.GetNode() == node) || (arg.GetLateNode() == node)) + { + return &arg; + } + } + + return nullptr; +} + +CallArg* CallArgs::FindWellKnownArg(WellKnownArg arg) +{ + assert(arg != WellKnownArg::None); + for (CallArg& callArg : Args()) + { + if (callArg.GetWellKnownArg() == arg) + { + return &callArg; + } + } + + return nullptr; +} + +CallArg* CallArgs::GetThisArg() +{ + if (!HasThisPointer()) + { + return nullptr; + } + + // For calls that do have 'this' pointer the loop is cheap as this is + // almost always the first or second argument. + CallArg* result = FindWellKnownArg(WellKnownArg::ThisPointer); + assert(result && "Expected to find this pointer argument"); + return result; +} + +CallArg* CallArgs::GetRetBufferArg() +{ + if (!HasRetBuffer()) + { + return nullptr; + } + + CallArg* result = FindWellKnownArg(WellKnownArg::RetBuffer); + assert(result && "Expected to find ret buffer argument"); + return result; +} + +CallArg* CallArgs::GetArgByIndex(unsigned index) +{ + CallArg* cur = m_head; + for (unsigned i = 0; i < index && cur != nullptr; i++) + { + cur = cur->GetNext(); + } + + return cur; +} + +unsigned CallArgs::GetIndex(CallArg* arg) +{ + unsigned i = 0; + for (CallArg& a : Args()) + { + if (&a == arg) + { + return i; + } + + i++; + } + + assert(!"Could not find argument in arg list"); + return (unsigned)-1; +} + +void CallArgs::Reverse(unsigned index, unsigned count) +{ + CallArg** headSlot = &m_head; + for (unsigned i = 0; i < index; i++) + { + assert(*headSlot != nullptr); + headSlot = &(*headSlot)->NextRef(); + } + + if (count > 1) + { + CallArg* newEnd = *headSlot; + CallArg* cur = (*headSlot)->GetNext(); + + for (unsigned i = 1; i < count; i++) + { + CallArg* next = cur->GetNext(); + cur->SetNext(*headSlot); + *headSlot = cur; + cur = next; + } + newEnd->SetNext(cur); + } +} + +void CallArgs::AddedWellKnownArg(WellKnownArg arg) +{ + switch (arg) + { + case WellKnownArg::ThisPointer: + m_hasThisPointer = true; + break; + case WellKnownArg::RetBuffer: + m_hasRetBuffer = true; + break; + } +} + +void CallArgs::RemovedWellKnownArg(WellKnownArg arg) +{ + switch (arg) + { + case WellKnownArg::ThisPointer: + assert(FindWellKnownArg(arg) == nullptr); + m_hasThisPointer = false; + break; + case WellKnownArg::RetBuffer: + assert(FindWellKnownArg(arg) == nullptr); + m_hasRetBuffer = false; + break; + } +} + +regNumber CallArgs::GetCustomRegister(Compiler* comp, CorInfoCallConvExtension cc, WellKnownArg arg) +{ + switch (arg) + { +#if defined(TARGET_X86) || defined(TARGET_ARM) + // The x86 and arm32 CORINFO_HELP_INIT_PINVOKE_FRAME helpers have a custom calling convention. + case WellKnownArg::PInvokeFrame: + return REG_PINVOKE_FRAME; +#endif +#if defined(TARGET_ARM) + // A non-standard calling convention using wrapper delegate invoke is used + // on ARM, only, for wrapper delegates. It is used for VSD delegate calls + // where the VSD custom calling convention ABI requires passing R4, a + // callee-saved register, with a special value. Since R4 is a callee-saved + // register, its value needs to be preserved. Thus, the VM uses a wrapper + // delegate IL stub, which preserves R4 and also sets up R4 correctly for + // the VSD call. The VM is simply reusing an existing mechanism (wrapper + // delegate IL stub) to achieve its goal for delegate VSD call. See + // COMDelegate::NeedsWrapperDelegate() in the VM for details. + case WellKnownArg::WrapperDelegateCell: + return comp->virtualStubParamInfo->GetReg(); +#endif +#if defined(TARGET_X86) + // The x86 shift helpers have custom calling conventions and expect the lo + // part of the long to be in EAX and the hi part to be in EDX. This sets + // the argument registers up correctly. + case WellKnownArg::ShiftLow: + return REG_LNGARG_LO; + case WellKnownArg::ShiftHigh: + return REG_LNGARG_HI; +#endif + case WellKnownArg::RetBuffer: + if (hasFixedRetBuffReg()) + { + // Windows does not use fixed ret buff arg for instance calls, but does otherwise. + if (!TargetOS::IsWindows || !callConvIsInstanceMethodCallConv(cc)) + { + return theFixedRetBuffReg(); + } + } + + break; + + case WellKnownArg::VirtualStubCell: + return comp->virtualStubParamInfo->GetReg(); + + case WellKnownArg::PInvokeCookie: + return REG_PINVOKE_COOKIE_PARAM; + + case WellKnownArg::PInvokeTarget: + return REG_PINVOKE_TARGET_PARAM; + + case WellKnownArg::R2RIndirectionCell: + return REG_R2R_INDIRECT_PARAM; + + case WellKnownArg::ValidateIndirectCallTarget: + if (REG_VALIDATE_INDIRECT_CALL_ADDR != REG_ARG_0) + { + return REG_VALIDATE_INDIRECT_CALL_ADDR; + } + + break; + +#ifdef REG_DISPATCH_INDIRECT_CELL_ADDR + case WellKnownArg::DispatchIndirectCallTarget: + return REG_DISPATCH_INDIRECT_CALL_ADDR; +#endif + } + + return REG_NA; +} + +bool CallArgs::IsNonStandard(Compiler* comp, GenTreeCall* call, CallArg* arg) +{ + return GetCustomRegister(comp, call->GetUnmanagedCallConv(), arg->GetWellKnownArg()) != REG_NA; +} + +CallArg* CallArgs::PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) +{ + CallArg* arg = new (comp, CMK_fgArgInfo) CallArg(wellKnownArg); + arg->SetNode(node); + arg->SetNext(m_head); + m_head = arg; + AddedWellKnownArg(wellKnownArg); + return arg; +} + +CallArg* CallArgs::PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) +{ + CallArg** slot = &m_head; + while (*slot != nullptr) + { + slot = &(*slot)->NextRef(); + } + + *slot = new (comp, CMK_fgArgInfo) CallArg(wellKnownArg); + (*slot)->SetNode(node); + AddedWellKnownArg(wellKnownArg); + return *slot; +} + +CallArg* CallArgs::InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, WellKnownArg wellKnownArg) +{ +#ifdef DEBUG + bool found = false; + for (CallArg& arg : Args()) + { + if (&arg == after) + { + found = true; + break; + } + } + + assert(found && "Could not find arg to insert after in argument list"); +#endif + + CallArg* newArg = new (comp, CMK_fgArgInfo) CallArg(wellKnownArg); + newArg->SetNode(arg); + newArg->SetNext(after->GetNext()); + after->SetNext(newArg); + AddedWellKnownArg(wellKnownArg); + return newArg; +} + +CallArg* CallArgs::InsertInstParam(Compiler* comp, GenTree* arg) +{ + if (Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) + { + CallArg* retBufferArg = GetRetBufferArg(); + if (retBufferArg != nullptr) + { + return InsertAfter(comp, retBufferArg, arg, WellKnownArg::InstParam); + } + else + { + return InsertAfterThisOrFirst(comp, arg, WellKnownArg::InstParam); + } + } + else + { + return PushBack(comp, arg, WellKnownArg::InstParam); + } +} + +CallArg* CallArgs::InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) +{ + CallArg* thisArg = GetThisArg(); + if (thisArg != nullptr) + { + return InsertAfter(comp, thisArg, node, wellKnownArg); + } + else + { + return PushFront(comp, node, wellKnownArg); + } +} + +bool CallArgs::Remove(CallArg* arg) +{ + CallArg** slot = &m_head; + while (*slot != nullptr) + { + if (*slot == arg) + { + *slot = arg->GetNext(); + RemovedWellKnownArg(arg->GetWellKnownArg()); + return true; + } + + slot = &(*slot)->NextRef(); + } + + return false; +} + +void CallArgs::Clear() +{ + m_head = nullptr; + m_lateHead = nullptr; + m_nextStackByteOffset = 0; + m_hasThisPointer = false; + m_hasRetBuffer = false; + m_isVarArgs = false; + m_abiInformationDetermined = false; + m_hasRegArgs = false; + m_hasStackArgs = false; + m_argsComplete = false; + m_argsSorted = false; + m_needsTemps = false; +#ifdef UNIX_X86_ABI + m_stkSizeBytes = 0; + m_padStkAlign = 0; + m_alignmentDone = false; +#endif +} + //--------------------------------------------------------------- // GetOtherRegMask: Get the reg mask of gtOtherRegs of call node // @@ -1130,7 +1729,7 @@ int GenTreeCall::GetNonStandardAddedArgCount(Compiler* compiler) const } //------------------------------------------------------------------------- -// TreatAsHasRetBufArg: +// TreatAsShouldGetRetBufArg: // // Arguments: // compiler, the compiler instance so that we can call eeGetHelperNum @@ -1150,36 +1749,34 @@ int GenTreeCall::GetNonStandardAddedArgCount(Compiler* compiler) const // aren't actually defined to return a struct, so they don't expect // their RetBuf to be passed in x8, instead they expect it in x0. // -bool GenTreeCall::TreatAsHasRetBufArg(Compiler* compiler) const +bool GenTreeCall::TreatAsShouldGetRetBufArg(Compiler* compiler) const { - if (HasRetBufArg()) + if (ShouldGetRetBufArg()) { return true; } - else + + // If we see a Jit helper call that returns a TYP_STRUCT we will + // transform it as if it has a Return Buffer Argument + // + if (IsHelperCall() && (gtReturnType == TYP_STRUCT)) { - // If we see a Jit helper call that returns a TYP_STRUCT we will - // transform it as if it has a Return Buffer Argument + // There are two possible helper calls that use this path: + // CORINFO_HELP_GETFIELDSTRUCT and CORINFO_HELP_UNBOX_NULLABLE // - if (IsHelperCall() && (gtReturnType == TYP_STRUCT)) - { - // There are two possible helper calls that use this path: - // CORINFO_HELP_GETFIELDSTRUCT and CORINFO_HELP_UNBOX_NULLABLE - // - CorInfoHelpFunc helpFunc = compiler->eeGetHelperNum(gtCallMethHnd); + CorInfoHelpFunc helpFunc = compiler->eeGetHelperNum(gtCallMethHnd); - if (helpFunc == CORINFO_HELP_GETFIELDSTRUCT) - { - return true; - } - else if (helpFunc == CORINFO_HELP_UNBOX_NULLABLE) - { - return true; - } - else - { - assert(!"Unexpected JIT helper in TreatAsHasRetBufArg"); - } + if (helpFunc == CORINFO_HELP_GETFIELDSTRUCT) + { + return true; + } + else if (helpFunc == CORINFO_HELP_UNBOX_NULLABLE) + { + return true; + } + else + { + assert(!"Unexpected JIT helper in TreatAsHasRetBufArg"); } } return false; @@ -1230,9 +1827,7 @@ void GenTreeCall::ReplaceCallOperand(GenTree** useEdge, GenTree* replacement) else { assert((replacement->gtFlags & GTF_LATE_ARG) == 0); - - fgArgTabEntry* fp = Compiler::gtArgEntryByNode(this, replacement); - assert(fp->GetNode() == replacement); + assert(gtArgs.FindByNode(replacement)->GetArgNode() == replacement); } } } @@ -1245,35 +1840,7 @@ void GenTreeCall::ReplaceCallOperand(GenTree** useEdge, GenTree* replacement) // bool GenTreeCall::AreArgsComplete() const { - if (fgArgInfo == nullptr) - { - return false; - } - if (fgArgInfo->AreArgsComplete()) - { - assert((gtCallLateArgs != nullptr) || !fgArgInfo->HasRegArgs()); - return true; - } - -#if defined(FEATURE_FASTTAILCALL) -// If we have FEATURE_FASTTAILCALL, 'fgCanFastTailCall()' can call 'fgInitArgInfo()', and in that -// scenario it is valid to have 'fgArgInfo' be non-null when 'fgMorphArgs()' first queries this, -// when it hasn't yet morphed the arguments. -#else - assert(gtCallArgs == nullptr); -#endif - - return false; -} - -//------------------------------------------------------------------------- -// SetRetBufArg: Sets the "return buffer" argument use. -// -void GenTreeCall::SetLclRetBufArg(Use* retBufArg) -{ - assert(retBufArg->GetNode()->TypeIs(TYP_I_IMPL, TYP_BYREF) && retBufArg->GetNode()->OperIs(GT_ADDR, GT_ASG)); - assert(HasRetBufArg()); - gtRetBufArg = retBufArg; + return gtArgs.AreArgsComplete(); } //-------------------------------------------------------------------------- @@ -1322,52 +1889,46 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) } } - if ((c1->gtCallThisArg != nullptr) != (c2->gtCallThisArg != nullptr)) { - return false; - } + auto i1 = c1->gtArgs.Args().begin(); + auto end1 = c1->gtArgs.Args().end(); + auto i2 = c2->gtArgs.Args().begin(); + auto end2 = c2->gtArgs.Args().end(); - if ((c1->gtCallThisArg != nullptr) && !Compare(c1->gtCallThisArg->GetNode(), c2->gtCallThisArg->GetNode())) - { - return false; - } - - GenTreeCall::UseIterator i1 = c1->Args().begin(); - GenTreeCall::UseIterator end1 = c1->Args().end(); - GenTreeCall::UseIterator i2 = c2->Args().begin(); - GenTreeCall::UseIterator end2 = c2->Args().end(); + for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) + { + if (!Compare(i1->GetNode(), i2->GetNode())) + { + return false; + } + } - for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) - { - if (!Compare(i1->GetNode(), i2->GetNode())) + if ((i1 != end1) || (i2 != end2)) { return false; } } - if ((i1 != end1) || (i2 != end2)) { - return false; - } + auto i1 = c1->gtArgs.LateArgs().begin(); + auto end1 = c1->gtArgs.LateArgs().end(); + auto i2 = c2->gtArgs.LateArgs().begin(); + auto end2 = c2->gtArgs.LateArgs().end(); - i1 = c1->LateArgs().begin(); - end1 = c1->LateArgs().end(); - i2 = c2->LateArgs().begin(); - end2 = c2->LateArgs().end(); + for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) + { + if (!Compare(i1.GetNode(), i2.GetNode())) + { + return false; + } + } - for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) - { - if (!Compare(i1->GetNode(), i2->GetNode())) + if ((i1 != end1) || (i2 != end2)) { return false; } } - if ((i1 != end1) || (i2 != end2)) - { - return false; - } - if (!Compare(c1->gtControlExpr, c2->gtControlExpr)) { return false; @@ -1376,37 +1937,29 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) return true; } -//-------------------------------------------------------------------------- -// ResetArgInfo: The argument info needs to be reset so it can be recomputed based on some change -// in conditions, such as changing the return type of a call due to giving up on doing a tailcall. -// If there is no fgArgInfo computed yet for this call, then there is nothing to reset. -// -void GenTreeCall::ResetArgInfo() +void CallArgs::ResetArgABIInformation() { - if (fgArgInfo == nullptr) + if (!IsAbiInformationDetermined()) { return; } - // We would like to just set `fgArgInfo = nullptr`. But `fgInitArgInfo()` not - // only sets up fgArgInfo, it also adds non-standard args to the IR, and we need - // to remove that extra IR so it doesn't get added again. - // - unsigned argNum = 0; - if (gtCallThisArg != nullptr) - { - argNum++; - } + // `CallArgs::DetermineArgABIInformation` not only sets up arg info, it + // also adds non-standard args to the IR, and we need to remove that extra + // IR so it doesn't get added again. + CallArg** link = &m_head; + + // We cannot handle this being called after fgMorphArgs, only + // CallArgs::DetermineArgABIInformation. + assert(m_lateHead == nullptr); - Use** link = >CallArgs; while ((*link) != nullptr) { - const fgArgTabEntry* entry = fgArgInfo->GetArgEntry(argNum); - if (entry->isNonStandard() && entry->isNonStandardArgAddedLate()) + // Check if this is an argument added by DetermineArgABIInformation. + if ((*link)->IsArgAddedLate()) { - JITDUMP("Removing non-standarg arg %s [%06u] to prepare for re-morphing call [%06u]\n", - getNonStandardArgKindName(entry->nonStandardArgKind), Compiler::dspTreeID((*link)->GetNode()), - gtTreeID); + JITDUMP("Removing arg %s [%06u] to prepare for re-morphing call\n", + getWellKnownArgName((*link)->GetWellKnownArg()), Compiler::dspTreeID((*link)->GetNode())); *link = (*link)->GetNext(); } @@ -1414,11 +1967,9 @@ void GenTreeCall::ResetArgInfo() { link = &(*link)->NextRef(); } - - argNum++; } - fgArgInfo = nullptr; + m_abiInformationDetermined = false; } #if !defined(FEATURE_PUT_STRUCT_ARG_STK) @@ -2183,14 +2734,9 @@ unsigned Compiler::gtHashValue(GenTree* tree) break; case GT_CALL: - if ((tree->AsCall()->gtCallThisArg != nullptr) && !tree->AsCall()->gtCallThisArg->GetNode()->OperIs(GT_NOP)) - { - hash = genTreeHashAdd(hash, gtHashValue(tree->AsCall()->gtCallThisArg->GetNode())); - } - - for (GenTreeCall::Use& use : tree->AsCall()->Args()) + for (CallArg& arg : tree->AsCall()->gtArgs.Args()) { - hash = genTreeHashAdd(hash, gtHashValue(use.GetNode())); + hash = genTreeHashAdd(hash, gtHashValue(arg.GetNode())); } if (tree->AsCall()->gtCallType == CT_INDIRECT) @@ -2204,9 +2750,9 @@ unsigned Compiler::gtHashValue(GenTree* tree) hash = genTreeHashAdd(hash, tree->AsCall()->gtCallMethHnd); } - for (GenTreeCall::Use& use : tree->AsCall()->LateArgs()) + for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) { - hash = genTreeHashAdd(hash, gtHashValue(use.GetNode())); + hash = genTreeHashAdd(hash, gtHashValue(arg.GetNode())); } break; @@ -2517,17 +3063,14 @@ void GenTreeOp::DebugCheckLongMul() #endif // !defined(TARGET_64BIT) && defined(DEBUG) #endif // !defined(TARGET_64BIT) || defined(TARGET_ARM64) -unsigned Compiler::gtSetCallArgsOrder(const GenTreeCall::UseList& args, bool lateArgs, int* callCostEx, int* callCostSz) +unsigned Compiler::gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCostEx, int* callCostSz) { unsigned level = 0; unsigned costEx = 0; unsigned costSz = 0; - for (GenTreeCall::Use& use : args) + auto update = [&level, &costEx, &costSz, lateArgs](GenTree* argNode, unsigned argLevel) { - GenTree* argNode = use.GetNode(); - unsigned argLevel = gtSetEvalOrder(argNode); - if (argLevel > level) { level = argLevel; @@ -2538,15 +3081,43 @@ unsigned Compiler::gtSetCallArgsOrder(const GenTreeCall::UseList& args, bool lat costEx += argNode->GetCostEx(); costEx += lateArgs ? 0 : IND_COST_EX; } - if (argNode->GetCostSz() != 0) { - costSz += argNode->GetCostSz(); -#ifdef TARGET_XARCH - if (lateArgs) // push is smaller than mov to reg -#endif + costSz += argNode->GetCostSz(); +#ifdef TARGET_XARCH + if (lateArgs) // push is smaller than mov to reg +#endif + { + costSz += 1; + } + } + }; + + if (lateArgs) + { + for (LateArg arg : args->LateArgs()) + { + GenTree* argNode = arg.GetNode(); + unsigned argLevel = gtSetEvalOrder(argNode); + update(argNode, argLevel); + } + } + else + { + for (CallArg& arg : args->Args()) + { + GenTree* argNode = arg.GetNode(); + unsigned argLevel = gtSetEvalOrder(argNode); + + if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) { - costSz += 1; + // TODO-ARGS: Quirk to match old costs assigned to 'this' + costEx += argNode->GetCostEx(); + costSz += argNode->GetCostSz() + 1; + } + else + { + update(argNode, argLevel); } } } @@ -4607,45 +5178,20 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree) GenTreeCall* call; call = tree->AsCall(); - /* Evaluate the 'this' argument, if present */ - - if (tree->AsCall()->gtCallThisArg != nullptr) - { - GenTree* thisVal = tree->AsCall()->gtCallThisArg->GetNode(); - - lvl2 = gtSetEvalOrder(thisVal); - if (level < lvl2) - { - level = lvl2; - } - costEx += thisVal->GetCostEx(); - costSz += thisVal->GetCostSz() + 1; - } - - /* Evaluate the arguments, right to left */ + // Evaluate the arguments - if (call->gtCallArgs != nullptr) + lvl2 = gtSetCallArgsOrder(&call->gtArgs, /* lateArgs */ false, &costEx, &costSz); + if (level < lvl2) { - const bool lateArgs = false; - lvl2 = gtSetCallArgsOrder(call->Args(), lateArgs, &costEx, &costSz); - if (level < lvl2) - { - level = lvl2; - } + level = lvl2; } - /* Evaluate the temp register arguments list - * This is a "hidden" list and its only purpose is to - * extend the life of temps until we make the call */ + // Evaluate the temp register arguments list - if (call->gtCallLateArgs != nullptr) + lvl2 = gtSetCallArgsOrder(&call->gtArgs, /* lateArgs */ true, &costEx, &costSz); + if (level < lvl2) { - const bool lateArgs = true; - lvl2 = gtSetCallArgsOrder(call->LateArgs(), lateArgs, &costEx, &costSz); - if (level < lvl2) - { - level = lvl2; - } + level = lvl2; } if (call->gtCallType == CT_INDIRECT) @@ -5191,11 +5737,6 @@ bool GenTree::TryGetUse(GenTree* operand, GenTree*** pUse) case GT_CALL: { GenTreeCall* const call = this->AsCall(); - if ((call->gtCallThisArg != nullptr) && (operand == call->gtCallThisArg->GetNode())) - { - *pUse = &call->gtCallThisArg->NodeRef(); - return true; - } if (operand == call->gtControlExpr) { *pUse = &call->gtControlExpr; @@ -5214,19 +5755,16 @@ bool GenTree::TryGetUse(GenTree* operand, GenTree*** pUse) return true; } } - for (GenTreeCall::Use& argUse : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - if (argUse.GetNode() == operand) + if (arg.GetNode() == operand) { - *pUse = &argUse.NodeRef(); + *pUse = &arg.NodeRef(); return true; } - } - for (GenTreeCall::Use& argUse : call->LateArgs()) - { - if (argUse.GetNode() == operand) + if (arg.GetLateNode() == operand) { - *pUse = &argUse.NodeRef(); + *pUse = &arg.LateNodeRef(); return true; } } @@ -6170,13 +6708,13 @@ GenTree* Compiler::gtNewSIMDVectorZero(var_types simdType, CorInfoType simdBaseJ } #endif // FEATURE_SIMD -GenTreeCall* Compiler::gtNewIndCallNode(GenTree* addr, var_types type, GenTreeCall::Use* args, const DebugInfo& di) +GenTreeCall* Compiler::gtNewIndCallNode(GenTree* addr, var_types type, const DebugInfo& di) { - return gtNewCallNode(CT_INDIRECT, (CORINFO_METHOD_HANDLE)addr, type, args, di); + return gtNewCallNode(CT_INDIRECT, (CORINFO_METHOD_HANDLE)addr, type, di); } GenTreeCall* Compiler::gtNewCallNode( - gtCallTypes callType, CORINFO_METHOD_HANDLE callHnd, var_types type, GenTreeCall::Use* args, const DebugInfo& di) + gtCallTypes callType, CORINFO_METHOD_HANDLE callHnd, var_types type, const DebugInfo& di) { GenTreeCall* node = new (this, GT_CALL) GenTreeCall(genActualType(type)); @@ -6185,15 +6723,8 @@ GenTreeCall* Compiler::gtNewCallNode( if (callType == CT_INDIRECT || callType == CT_HELPER) node->gtFlags |= GTF_CALL_POP_ARGS; #endif // UNIX_X86_ABI - for (GenTreeCall::Use& use : GenTreeCall::UseList(args)) - { - node->gtFlags |= (use.GetNode()->gtFlags & GTF_ALL_EFFECT); - } node->gtCallType = callType; node->gtCallMethHnd = callHnd; - node->gtCallArgs = args; - node->gtCallThisArg = nullptr; - node->fgArgInfo = nullptr; INDEBUG(node->callSig = nullptr;) node->tailCallInfo = nullptr; node->gtRetClsHnd = nullptr; @@ -6208,7 +6739,6 @@ GenTreeCall* Compiler::gtNewCallNode( { node->gtInlineCandidateInfo = nullptr; } - node->gtCallLateArgs = nullptr; node->gtReturnType = type; #ifdef FEATURE_READYTORUN @@ -6366,138 +6896,6 @@ GenTree* Compiler::gtNewInlineCandidateReturnExpr(GenTree* inlineCandidate, var_ return node; } -GenTreeCall::Use* Compiler::gtPrependNewCallArg(GenTree* node, GenTreeCall::Use* args) -{ - return new (this, CMK_ASTNode) GenTreeCall::Use(node, args); -} - -GenTreeCall::Use* Compiler::gtInsertNewCallArgAfter(GenTree* node, GenTreeCall::Use* after) -{ - after->SetNext(new (this, CMK_ASTNode) GenTreeCall::Use(node, after->GetNext())); - return after->GetNext(); -} - -GenTreeCall::Use* Compiler::gtNewCallArgs(GenTree* node) -{ - return new (this, CMK_ASTNode) GenTreeCall::Use(node); -} - -GenTreeCall::Use* Compiler::gtNewCallArgs(GenTree* node1, GenTree* node2) -{ - return new (this, CMK_ASTNode) GenTreeCall::Use(node1, gtNewCallArgs(node2)); -} - -GenTreeCall::Use* Compiler::gtNewCallArgs(GenTree* node1, GenTree* node2, GenTree* node3) -{ - return new (this, CMK_ASTNode) GenTreeCall::Use(node1, gtNewCallArgs(node2, node3)); -} - -GenTreeCall::Use* Compiler::gtNewCallArgs(GenTree* node1, GenTree* node2, GenTree* node3, GenTree* node4) -{ - return new (this, CMK_ASTNode) GenTreeCall::Use(node1, gtNewCallArgs(node2, node3, node4)); -} - -/***************************************************************************** - * - * Given a GT_CALL node, access the fgArgInfo and find the entry - * that has the matching argNum and return the fgArgTableEntryPtr - */ - -fgArgTabEntry* Compiler::gtArgEntryByArgNum(GenTreeCall* call, unsigned argNum) -{ - fgArgInfo* argInfo = call->fgArgInfo; - noway_assert(argInfo != nullptr); - return argInfo->GetArgEntry(argNum); -} - -/***************************************************************************** - * - * Given a GT_CALL node, access the fgArgInfo and find the entry - * that has the matching node and return the fgArgTableEntryPtr - */ - -fgArgTabEntry* Compiler::gtArgEntryByNode(GenTreeCall* call, GenTree* node) -{ - fgArgInfo* argInfo = call->fgArgInfo; - noway_assert(argInfo != nullptr); - - unsigned argCount = argInfo->ArgCount(); - fgArgTabEntry** argTable = argInfo->ArgTable(); - fgArgTabEntry* curArgTabEntry = nullptr; - - for (unsigned i = 0; i < argCount; i++) - { - curArgTabEntry = argTable[i]; - - if (curArgTabEntry->GetNode() == node) - { - return curArgTabEntry; - } - else if (curArgTabEntry->use->GetNode() == node) - { - return curArgTabEntry; - } - } - noway_assert(!"gtArgEntryByNode: node not found"); - return nullptr; -} - -/***************************************************************************** - * - * Find and return the entry with the given "lateArgInx". Requires that one is found - * (asserts this). - */ -fgArgTabEntry* Compiler::gtArgEntryByLateArgIndex(GenTreeCall* call, unsigned lateArgInx) -{ - fgArgInfo* argInfo = call->fgArgInfo; - noway_assert(argInfo != nullptr); - assert(lateArgInx != UINT_MAX); - - unsigned argCount = argInfo->ArgCount(); - fgArgTabEntry** argTable = argInfo->ArgTable(); - fgArgTabEntry* curArgTabEntry = nullptr; - - for (unsigned i = 0; i < argCount; i++) - { - curArgTabEntry = argTable[i]; - if (curArgTabEntry->isLateArg() && curArgTabEntry->GetLateArgInx() == lateArgInx) - { - return curArgTabEntry; - } - } - noway_assert(!"gtArgEntryByNode: node not found"); - return nullptr; -} - -//------------------------------------------------------------------------ -// gtArgNodeByLateArgInx: Given a call instruction, find the argument with the given -// late arg index (i.e. the given position in the gtCallLateArgs list). -// Arguments: -// call - the call node -// lateArgInx - the index into the late args list -// -// Return value: -// The late argument node. -// -GenTree* Compiler::gtArgNodeByLateArgInx(GenTreeCall* call, unsigned lateArgInx) -{ - GenTree* argx = nullptr; - unsigned regIndex = 0; - - for (GenTreeCall::Use& use : call->LateArgs()) - { - argx = use.GetNode(); - assert(!argx->IsArgPlaceHolderNode()); // No placeholder nodes are in gtCallLateArgs; - if (regIndex == lateArgInx) - { - break; - } - regIndex++; - } - noway_assert(argx != nullptr); - return argx; -} - /***************************************************************************** * * Create a node that will assign 'src' to 'dst'. @@ -7922,6 +8320,61 @@ GenTree* Compiler::gtCloneExpr( return copy; } +// Copy all information from the specified CallArgs, making these argument lists equivalent. +// Nodes are cloned using the specified function. +template +void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc copyNode) +{ + assert((m_head == nullptr) && (m_lateHead == nullptr)); + + m_nextStackByteOffset = other->m_nextStackByteOffset; + m_hasThisPointer = other->m_hasThisPointer; + m_hasRetBuffer = other->m_hasRetBuffer; + m_isVarArgs = other->m_isVarArgs; + m_abiInformationDetermined = other->m_abiInformationDetermined; + m_hasRegArgs = other->m_hasRegArgs; + m_hasStackArgs = other->m_hasStackArgs; + m_argsComplete = other->m_argsComplete; + m_argsSorted = other->m_argsSorted; + m_needsTemps = other->m_needsTemps; + + // Unix x86 flags related to stack alignment intentionally not copied as it + // depends on where the call will be inserted. + + CallArg** tail = &m_head; + for (CallArg& arg : other->Args()) + { + CallArg* carg = new (comp, CMK_fgArgInfo) CallArg(arg.GetWellKnownArg()); + carg->m_node = arg.m_node != nullptr ? copyNode(arg.m_node) : nullptr; + carg->m_lateNode = arg.m_lateNode != nullptr ? copyNode(arg.m_lateNode) : nullptr; + carg->m_needTmp = arg.m_needTmp; + carg->m_needPlace = arg.m_needPlace; + carg->m_isTmp = arg.m_isTmp; + carg->m_processed = arg.m_processed; + carg->m_tmpNum = arg.m_tmpNum; + carg->AbiInfo = arg.AbiInfo; + *tail = carg; + tail = &carg->m_next; + } + + // Now copy late pointers. Note that these may not come in order. + tail = &m_lateHead; + for (LateArg arg : other->LateArgs()) + { + CallArg* it = m_head; + CallArg* otherIt = other->m_head; + while (otherIt != arg.GetArg()) + { + assert(it != nullptr && otherIt != nullptr); + it = it->m_next; + otherIt = otherIt->m_next; + } + + *tail = it; + tail = &it->m_lateNext; + } +} + //------------------------------------------------------------------------ // gtCloneExprCallHelper: clone a call tree // @@ -7945,58 +8398,15 @@ GenTreeCall* Compiler::gtCloneExprCallHelper(GenTreeCall* tree, { GenTreeCall* copy = new (this, GT_CALL) GenTreeCall(tree->TypeGet()); - if (tree->gtCallThisArg == nullptr) - { - copy->gtCallThisArg = nullptr; - } - else - { - copy->gtCallThisArg = - gtNewCallArgs(gtCloneExpr(tree->gtCallThisArg->GetNode(), addFlags, deepVarNum, deepVarVal)); - } - copy->gtCallMoreFlags = tree->gtCallMoreFlags; - copy->gtCallArgs = nullptr; - copy->gtCallLateArgs = nullptr; - copy->gtRetBufArg = nullptr; - - GenTreeCall::Use** argsTail = ©->gtCallArgs; - for (GenTreeCall::Use& use : tree->Args()) - { - GenTree* argNode = use.GetNode(); - GenTree* copyArgNode = gtCloneExpr(argNode, addFlags, deepVarNum, deepVarVal); - *argsTail = gtNewCallArgs(copyArgNode); - - if (tree->gtRetBufArg == &use) - { - // Set the return buffer arg, if any. - assert(copy->gtRetBufArg == nullptr); - copy->gtRetBufArg = *argsTail; - } - - argsTail = &((*argsTail)->NextRef()); - } - argsTail = ©->gtCallLateArgs; - for (GenTreeCall::Use& use : tree->LateArgs()) - { - GenTree* argNode = use.GetNode(); - GenTree* copyArgNode = gtCloneExpr(argNode, addFlags, deepVarNum, deepVarVal); - *argsTail = gtNewCallArgs(copyArgNode); - - if (tree->gtRetBufArg == &use) + copy->gtArgs.InternalCopyFrom( + this, + &tree->gtArgs, + [=](GenTree* node) { - // Set the return buffer arg, if any. - assert(copy->gtRetBufArg == nullptr); - copy->gtRetBufArg = *argsTail; - } - - argsTail = &((*argsTail)->NextRef()); - } - - // Either there was not return buffer for the "tree" or else we successfully set the - // return buffer in the copy. - assert((tree->gtRetBufArg == nullptr) || (copy->gtRetBufArg != nullptr)); + return gtCloneExpr(node, addFlags, deepVarNum, deepVarVal); + }); // The call sig comes from the EE and doesn't change throughout the compilation process, meaning // we only really need one physical copy of it. Therefore a shallow pointer copy will suffice. @@ -8028,16 +8438,6 @@ GenTreeCall* Compiler::gtCloneExprCallHelper(GenTreeCall* tree, copy->gtCallType = tree->gtCallType; copy->gtReturnType = tree->gtReturnType; - if (tree->fgArgInfo) - { - // Create and initialize the fgArgInfo for our copy of the call tree - copy->fgArgInfo = new (this, CMK_Unknown) fgArgInfo(copy, tree); - } - else - { - copy->fgArgInfo = nullptr; - } - #if FEATURE_MULTIREG_RET copy->gtReturnTypeDesc = tree->gtReturnTypeDesc; #endif @@ -8299,40 +8699,6 @@ Compiler::fgWalkResult Compiler::fgUpdateSideEffectsPost(GenTree** pTree, fgWalk return WALK_CONTINUE; } -//------------------------------------------------------------------------ -// gtGetThisArg: Return this pointer node for the call. -// -// Arguments: -// call - the call node with a this argument. -// -// Return value: -// the this pointer node. -// -GenTree* Compiler::gtGetThisArg(GenTreeCall* call) -{ - assert(call->gtCallThisArg != nullptr); - - GenTree* thisArg = call->gtCallThisArg->GetNode(); - if (!thisArg->OperIs(GT_ASG)) - { - if ((thisArg->gtFlags & GTF_LATE_ARG) == 0) - { - return thisArg; - } - } - - assert(call->gtCallLateArgs != nullptr); - - unsigned argNum = 0; - fgArgTabEntry* thisArgTabEntry = gtArgEntryByArgNum(call, argNum); - GenTree* result = thisArgTabEntry->GetNode(); - - // Assert if we used DEBUG_DESTROY_NODE. - assert(result->gtOper != GT_COUNT); - - return result; -} - bool GenTree::gtSetFlags() const { // @@ -8580,7 +8946,9 @@ GenTreeUseEdgeIterator::GenTreeUseEdgeIterator(GenTree* node) return; case GT_CALL: - AdvanceCall(); + m_statePtr = &*m_node->AsCall()->gtArgs.Args().begin(); + m_advance = &GenTreeUseEdgeIterator::AdvanceCall; + AdvanceCall(); return; // Binary nodes @@ -8841,7 +9209,7 @@ void GenTreeUseEdgeIterator::SetEntryStateForMultiOp() // This sort of templating allows each state to avoid processing earlier states without unnecessary // duplication of code. // -// Note that this method expands the argument lists (`gtCallArgs` and `gtCallLateArgs`) into their +// Note that this method expands the argument list (`gtArgs.Args()` and `gtArgs.LateArgs()`) into their // component operands. // template @@ -8851,34 +9219,24 @@ void GenTreeUseEdgeIterator::AdvanceCall() switch (state) { - case CALL_INSTANCE: - m_statePtr = call->gtCallArgs; - m_advance = &GenTreeUseEdgeIterator::AdvanceCall; - if (call->gtCallThisArg != nullptr) - { - m_edge = &call->gtCallThisArg->NodeRef(); - return; - } - FALLTHROUGH; - case CALL_ARGS: if (m_statePtr != nullptr) { - GenTreeCall::Use* use = static_cast(m_statePtr); - m_edge = &use->NodeRef(); - m_statePtr = use->GetNext(); + CallArg* arg = static_cast(m_statePtr); + m_edge = &arg->NodeRef(); + m_statePtr = arg->GetNext(); return; } - m_statePtr = call->gtCallLateArgs; + m_statePtr = call->gtArgs.LateArgs().begin().GetArg(); m_advance = &GenTreeUseEdgeIterator::AdvanceCall; FALLTHROUGH; case CALL_LATE_ARGS: if (m_statePtr != nullptr) { - GenTreeCall::Use* use = static_cast(m_statePtr); - m_edge = &use->NodeRef(); - m_statePtr = use->GetNext(); + CallArg* arg = static_cast(m_statePtr); + m_edge = &arg->LateNodeRef(); + m_statePtr = arg->GetLateNext(); return; } m_advance = &GenTreeUseEdgeIterator::AdvanceCall; @@ -11178,28 +11536,8 @@ void Compiler::gtDispTree(GenTree* tree, if (!topOnly) { char buf[64]; - char* bufp; - - bufp = &buf[0]; - - if ((call->gtCallThisArg != nullptr) && !call->gtCallThisArg->GetNode()->OperIs(GT_NOP, GT_ARGPLACE)) - { - if (call->gtCallThisArg->GetNode()->OperIs(GT_ASG)) - { - sprintf_s(bufp, sizeof(buf), "this SETUP%c", 0); - } - else - { - sprintf_s(bufp, sizeof(buf), "this in %s%c", compRegVarName(REG_ARG_0), 0); - } - gtDispChild(call->gtCallThisArg->GetNode(), indentStack, - (call->gtCallThisArg->GetNode() == lastChild) ? IIArcBottom : IIArc, bufp, topOnly); - } - if (call->gtCallArgs) - { - gtDispArgList(call, lastChild, indentStack); - } + gtDispArgList(call, lastChild, indentStack); if (call->gtCallType == CT_INDIRECT) { @@ -11213,13 +11551,11 @@ void Compiler::gtDispTree(GenTree* tree, (call->gtControlExpr == lastChild) ? IIArcBottom : IIArc, "control expr", topOnly); } - int lateArgIndex = 0; - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - IndentInfo arcType = (use.GetNext() == nullptr) ? IIArcBottom : IIArc; - gtGetLateArgMsg(call, use.GetNode(), lateArgIndex, bufp, sizeof(buf)); - gtDispChild(use.GetNode(), indentStack, arcType, bufp, topOnly); - lateArgIndex++; + IndentInfo arcType = (arg.GetArg()->GetLateNext() == nullptr) ? IIArcBottom : IIArc; + gtGetLateArgMsg(call, arg.GetArg(), buf, sizeof(buf)); + gtDispChild(arg.GetNode(), indentStack, arcType, buf, topOnly); } } } @@ -11331,76 +11667,104 @@ void Compiler::gtDispTree(GenTree* tree, } } +const char* Compiler::gtGetWellKnownArgNameForArgMsg(WellKnownArg arg) +{ + switch (arg) + { + case WellKnownArg::ThisPointer: return "this"; + case WellKnownArg::VarArgsCookie: return "va cookie"; + case WellKnownArg::InstParam: return "gctx"; + case WellKnownArg::RetBuffer: return "retbuf"; + case WellKnownArg::PInvokeFrame: return "pinv frame"; + case WellKnownArg::SecretStubParam: return "stub param"; + case WellKnownArg::WrapperDelegateCell: return "wrap cell"; + case WellKnownArg::ShiftLow: return "shift low"; + case WellKnownArg::ShiftHigh: return "shift high"; + case WellKnownArg::VirtualStubCell: return "vsd cell"; + case WellKnownArg::PInvokeCookie: return "pinv cookie"; + case WellKnownArg::PInvokeTarget: return "pinv tgt"; + case WellKnownArg::R2RIndirectionCell: return "r2r cell"; + case WellKnownArg::ValidateIndirectCallTarget: + case WellKnownArg::DispatchIndirectCallTarget: return "cfg tgt"; + default: return nullptr; + } +} + +void Compiler::gtPrintArgPrefix(GenTreeCall* call, CallArg* arg, char** bufp, unsigned* bufLength) +{ + int prefLen; + const char* wellKnownName = gtGetWellKnownArgNameForArgMsg(arg->GetWellKnownArg()); + if (wellKnownName != nullptr) + { + prefLen = sprintf_s(*bufp, *bufLength, "%s", wellKnownName); + } + else + { + unsigned argNum = call->gtArgs.GetIndex(arg); + prefLen = sprintf_s(*bufp, *bufLength, "arg%u", argNum); + } + assert(prefLen != -1); + *bufp += prefLen; + *bufLength -= (unsigned)prefLen; +} + //------------------------------------------------------------------------ // gtGetArgMsg: Construct a message about the given argument // // Arguments: // call - The call for which 'arg' is an argument // arg - The argument for which a message should be constructed -// argNum - The ordinal number of the arg in the argument list // bufp - A pointer to the buffer into which the message is written // bufLength - The length of the buffer pointed to by bufp // // Return Value: // No return value, but bufp is written. // -// Assumptions: -// 'call' must be a call node -// 'arg' must be an argument to 'call' (else gtArgEntryByNode will assert) - -void Compiler::gtGetArgMsg(GenTreeCall* call, GenTree* arg, unsigned argNum, char* bufp, unsigned bufLength) +void Compiler::gtGetArgMsg(GenTreeCall* call, CallArg* arg, char* bufp, unsigned bufLength) { - if (call->gtCallLateArgs != nullptr) - { - fgArgTabEntry* curArgTabEntry = gtArgEntryByArgNum(call, argNum); - assert(curArgTabEntry); + gtPrintArgPrefix(call, arg, &bufp, &bufLength); - if (arg->gtFlags & GTF_LATE_ARG) - { - sprintf_s(bufp, bufLength, "arg%d SETUP%c", argNum, 0); - } - else - { + if (arg->GetLateNode() != nullptr) + { + sprintf_s(bufp, bufLength, " setup"); + } + else if (call->gtArgs.IsAbiInformationDetermined()) + { #ifdef TARGET_ARM - if (curArgTabEntry->IsSplit()) + if (arg->AbiInfo.IsSplit()) + { + regNumber firstReg = arg->AbiInfo.GetRegNum(); + if (arg->AbiInfo.NumRegs == 1) + { + sprintf_s(bufp, bufLength, " %s out+%02x", compRegVarName(firstReg), + arg->AbiInfo.SlotNum * TARGET_POINTER_SIZE); + } + else { - regNumber firstReg = curArgTabEntry->GetRegNum(); - if (curArgTabEntry->numRegs == 1) + regNumber lastReg = REG_STK; + char separator = (arg->AbiInfo.NumRegs == 2) ? ',' : '-'; + if (arg->AbiInfo.IsHfaRegArg()) { - sprintf_s(bufp, bufLength, "arg%d %s out+%02x%c", argNum, compRegVarName(firstReg), - (curArgTabEntry->slotNum) * TARGET_POINTER_SIZE, 0); + unsigned lastRegNum = genMapFloatRegNumToRegArgNum(firstReg) + arg->AbiInfo.NumRegs - 1; + lastReg = genMapFloatRegArgNumToRegNum(lastRegNum); } else { - regNumber lastReg = REG_STK; - char separator = (curArgTabEntry->numRegs == 2) ? ',' : '-'; - if (curArgTabEntry->IsHfaRegArg()) - { - unsigned lastRegNum = genMapFloatRegNumToRegArgNum(firstReg) + curArgTabEntry->numRegs - 1; - lastReg = genMapFloatRegArgNumToRegNum(lastRegNum); - } - else - { - unsigned lastRegNum = genMapIntRegNumToRegArgNum(firstReg) + curArgTabEntry->numRegs - 1; - lastReg = genMapIntRegArgNumToRegNum(lastRegNum); - } - sprintf_s(bufp, bufLength, "arg%d %s%c%s out+%02x%c", argNum, compRegVarName(firstReg), separator, - compRegVarName(lastReg), (curArgTabEntry->slotNum) * TARGET_POINTER_SIZE, 0); + unsigned lastRegNum = genMapIntRegNumToRegArgNum(firstReg) + arg->AbiInfo.NumRegs - 1; + lastReg = genMapIntRegArgNumToRegNum(lastRegNum); } - - return; + sprintf_s(bufp, bufLength, " %s%c%s out+%02x", compRegVarName(firstReg), separator, + compRegVarName(lastReg), arg->AbiInfo.SlotNum * TARGET_POINTER_SIZE); } + + return; + } #endif // TARGET_ARM #if FEATURE_FIXED_OUT_ARGS - sprintf_s(bufp, bufLength, "arg%d out+%02x%c", argNum, curArgTabEntry->GetByteOffset(), 0); + sprintf_s(bufp, bufLength, " out+%02x", arg->AbiInfo.ByteOffset); #else - sprintf_s(bufp, bufLength, "arg%d on STK%c", argNum, 0); + sprintf_s(bufp, bufLength, " on STK"); #endif - } - } - else - { - sprintf_s(bufp, bufLength, "arg%d%c", argNum, 0); } } @@ -11409,82 +11773,69 @@ void Compiler::gtGetArgMsg(GenTreeCall* call, GenTree* arg, unsigned argNum, cha // // Arguments: // call - The call for which 'arg' is an argument -// argx - The argument for which a message should be constructed -// lateArgIndex - The ordinal number of the arg in the lastArg list +// arg - The argument for which a message should be constructed // bufp - A pointer to the buffer into which the message is written // bufLength - The length of the buffer pointed to by bufp // // Return Value: // No return value, but bufp is written. -// -// Assumptions: -// 'call' must be a call node -// 'arg' must be an argument to 'call' (else gtArgEntryByNode will assert) -void Compiler::gtGetLateArgMsg(GenTreeCall* call, GenTree* argx, int lateArgIndex, char* bufp, unsigned bufLength) +void Compiler::gtGetLateArgMsg(GenTreeCall* call, CallArg* arg, char* bufp, unsigned bufLength) { - assert(!argx->IsArgPlaceHolderNode()); // No place holders nodes are in gtCallLateArgs; + assert(arg->GetLateNode() != nullptr); + regNumber argReg = arg->AbiInfo.GetRegNum(); - fgArgTabEntry* curArgTabEntry = gtArgEntryByLateArgIndex(call, lateArgIndex); - assert(curArgTabEntry); - regNumber argReg = curArgTabEntry->GetRegNum(); + gtPrintArgPrefix(call, arg, &bufp, &bufLength); #if FEATURE_FIXED_OUT_ARGS if (argReg == REG_STK) { - sprintf_s(bufp, bufLength, "arg%d in out+%02x%c", curArgTabEntry->argNum, curArgTabEntry->GetByteOffset(), 0); + sprintf_s(bufp, bufLength, " in out+%02x", arg->AbiInfo.ByteOffset); } else #endif { - if (curArgTabEntry->use == call->gtCallThisArg) - { - sprintf_s(bufp, bufLength, "this in %s%c", compRegVarName(argReg), 0); - } #ifdef TARGET_ARM - else if (curArgTabEntry->IsSplit()) + if (arg->AbiInfo.IsSplit()) { - regNumber firstReg = curArgTabEntry->GetRegNum(); - unsigned argNum = curArgTabEntry->argNum; - if (curArgTabEntry->numRegs == 1) + regNumber firstReg = arg->AbiInfo.GetRegNum(); + if (arg->AbiInfo.NumRegs == 1) { - sprintf_s(bufp, bufLength, "arg%d %s out+%02x%c", argNum, compRegVarName(firstReg), - (curArgTabEntry->slotNum) * TARGET_POINTER_SIZE, 0); + sprintf_s(bufp, bufLength, " %s out+%02x", compRegVarName(firstReg), + arg->AbiInfo.SlotNum * TARGET_POINTER_SIZE); } else { regNumber lastReg = REG_STK; - char separator = (curArgTabEntry->numRegs == 2) ? ',' : '-'; - if (curArgTabEntry->IsHfaRegArg()) + char separator = (arg->AbiInfo.NumRegs == 2) ? ',' : '-'; + if (arg->AbiInfo.IsHfaRegArg()) { - unsigned lastRegNum = genMapFloatRegNumToRegArgNum(firstReg) + curArgTabEntry->numRegs - 1; + unsigned lastRegNum = genMapFloatRegNumToRegArgNum(firstReg) + arg->AbiInfo.NumRegs - 1; lastReg = genMapFloatRegArgNumToRegNum(lastRegNum); } else { - unsigned lastRegNum = genMapIntRegNumToRegArgNum(firstReg) + curArgTabEntry->numRegs - 1; + unsigned lastRegNum = genMapIntRegNumToRegArgNum(firstReg) + arg->AbiInfo.NumRegs - 1; lastReg = genMapIntRegArgNumToRegNum(lastRegNum); } - sprintf_s(bufp, bufLength, "arg%d %s%c%s out+%02x%c", argNum, compRegVarName(firstReg), separator, - compRegVarName(lastReg), (curArgTabEntry->slotNum) * TARGET_POINTER_SIZE, 0); + sprintf_s(bufp, bufLength, " %s%c%s out+%02x", compRegVarName(firstReg), separator, + compRegVarName(lastReg), arg->AbiInfo.SlotNum * TARGET_POINTER_SIZE); } + return; } #endif // TARGET_ARM - else - { #if FEATURE_MULTIREG_ARGS - if (curArgTabEntry->numRegs >= 2) - { - char separator = (curArgTabEntry->numRegs == 2) ? ',' : '-'; - sprintf_s(bufp, bufLength, "arg%d %s%c%s%c", curArgTabEntry->argNum, compRegVarName(argReg), separator, - compRegVarName(curArgTabEntry->GetRegNum(curArgTabEntry->numRegs - 1)), 0); - } - else + if (arg->AbiInfo.NumRegs >= 2) + { + char separator = (arg->AbiInfo.NumRegs == 2) ? ',' : '-'; + sprintf_s(bufp, bufLength, " %s%c%s", compRegVarName(argReg), separator, + compRegVarName(arg->AbiInfo.GetRegNum(arg->AbiInfo.NumRegs - 1))); + } + else #endif - { - sprintf_s(bufp, bufLength, "arg%d in %s%c", curArgTabEntry->argNum, compRegVarName(argReg), 0); - } + { + sprintf_s(bufp, bufLength, " in %s", compRegVarName(argReg)); } } } @@ -11502,23 +11853,16 @@ void Compiler::gtGetLateArgMsg(GenTreeCall* call, GenTree* argx, int lateArgInde // void Compiler::gtDispArgList(GenTreeCall* call, GenTree* lastCallOperand, IndentStack* indentStack) { - unsigned argnum = 0; - - if (call->gtCallThisArg != nullptr) - { - argnum++; - } + unsigned argNum = 0; - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree* argNode = use.GetNode(); - if (!argNode->IsNothingNode() && !argNode->IsArgPlaceHolderNode()) + if (!arg.GetNode()->IsNothingNode() && !arg.GetNode()->IsArgPlaceHolderNode()) { char buf[256]; - gtGetArgMsg(call, argNode, argnum, buf, sizeof(buf)); - gtDispChild(argNode, indentStack, (argNode == lastCallOperand) ? IIArcBottom : IIArc, buf, false); + gtGetArgMsg(call, &arg, buf, sizeof(buf)); + gtDispChild(arg.GetNode(), indentStack, (arg.GetNode() == lastCallOperand) ? IIArcBottom : IIArc, buf, false); } - argnum++; } } @@ -11638,7 +11982,7 @@ void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr * printf("%*s", (int)prefixIndent, ""); } - // 50 spaces for alignment + // 60 spaces for alignment printf("%-50s", ""); #if FEATURE_SET_FLAGS // additional flag enlarges the flag field by one character @@ -11679,12 +12023,12 @@ void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr * if (nodeIsCall) { GenTreeCall* call = node->AsCall(); - if ((call->gtCallThisArg != nullptr) && (operand == call->gtCallThisArg->GetNode())) - { - sprintf_s(buf, sizeof(buf), "this in %s", compRegVarName(REG_ARG_0)); - displayOperand(operand, buf, operandArc, indentStack, prefixIndent); - } - else if (operand == call->gtCallAddr) + //if ((call->gtCallThisArg != nullptr) && (operand == call->gtCallThisArg->GetNode())) + //{ + // sprintf_s(buf, sizeof(buf), "this in %s", compRegVarName(REG_ARG_0)); + // displayOperand(operand, buf, operandArc, indentStack, prefixIndent); + //} + if (operand == call->gtCallAddr) { displayOperand(operand, "calli tgt", operandArc, indentStack, prefixIndent); } @@ -11698,16 +12042,16 @@ void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr * } else { - fgArgTabEntry* curArgTabEntry = gtArgEntryByNode(call, operand); - assert(curArgTabEntry); + CallArg* curArg = call->gtArgs.FindByNode(operand); + assert(curArg); - if (!curArgTabEntry->isLateArg()) + if (operand == curArg->GetNode()) { - gtGetArgMsg(call, operand, curArgTabEntry->argNum, buf, sizeof(buf)); + gtGetArgMsg(call, curArg, buf, sizeof(buf)); } else { - gtGetLateArgMsg(call, operand, curArgTabEntry->GetLateArgInx(), buf, sizeof(buf)); + gtGetLateArgMsg(call, curArg, buf, sizeof(buf)); } displayOperand(operand, buf, operandArc, indentStack, prefixIndent); @@ -11882,8 +12226,8 @@ GenTree* Compiler::gtFoldExprCall(GenTreeCall* call) { case NI_System_Enum_HasFlag: { - GenTree* thisOp = call->gtCallThisArg->GetNode(); - GenTree* flagOp = call->gtCallArgs->GetNode(); + GenTree* thisOp = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* flagOp = call->gtArgs.GetArgByIndex(1)->GetNode(); GenTree* result = gtOptimizeEnumHasFlag(thisOp, flagOp); if (result != nullptr) @@ -11897,8 +12241,8 @@ GenTree* Compiler::gtFoldExprCall(GenTreeCall* call) case NI_System_Type_op_Inequality: { noway_assert(call->TypeGet() == TYP_INT); - GenTree* op1 = call->gtCallArgs->GetNode(); - GenTree* op2 = call->gtCallArgs->GetNext()->GetNode(); + GenTree* op1 = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* op2 = call->gtArgs.GetArgByIndex(1)->GetNode(); // If either operand is known to be a RuntimeType, this can be folded GenTree* result = gtFoldTypeEqualityCall(ni == NI_System_Type_op_Equality, op1, op2); @@ -12075,8 +12419,7 @@ GenTree* Compiler::gtCreateHandleCompare(genTreeOps oper, assert(typeCheckInliningResult == CORINFO_INLINE_TYPECHECK_USE_HELPER); // Emit a call to a runtime helper - GenTreeCall::Use* helperArgs = gtNewCallArgs(op1, op2); - GenTree* ret = gtNewHelperCallNode(CORINFO_HELP_ARE_TYPES_EQUIVALENT, TYP_INT, helperArgs); + GenTree* ret = gtNewHelperCallNode(CORINFO_HELP_ARE_TYPES_EQUIVALENT, TYP_INT, op1, op2); if (oper == GT_EQ) { ret = gtNewOperNode(GT_NE, TYP_INT, ret, gtNewIconNode(0, TYP_INT)); @@ -12139,8 +12482,9 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) if ((op1Kind == TPK_Handle) && (op2Kind == TPK_Handle)) { JITDUMP("Optimizing compare of types-from-handles to instead compare handles\n"); - GenTree* op1ClassFromHandle = tree->AsOp()->gtOp1->AsCall()->gtCallArgs->GetNode(); - GenTree* op2ClassFromHandle = tree->AsOp()->gtOp2->AsCall()->gtCallArgs->GetNode(); + assert((tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.CountArgs() == 1) &&(tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.CountArgs() == 1)); + GenTree* op1ClassFromHandle = tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* op2ClassFromHandle = tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); CORINFO_CLASS_HANDLE cls1Hnd = NO_CLASS_HANDLE; CORINFO_CLASS_HANDLE cls2Hnd = NO_CLASS_HANDLE; @@ -12217,7 +12561,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) } else { - arg1 = op1->AsCall()->gtCallThisArg->GetNode(); + arg1 = op1->AsCall()->gtArgs.GetThisArg()->GetArgNode(); } arg1 = gtNewMethodTableLookup(arg1); @@ -12230,7 +12574,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) } else { - arg2 = op2->AsCall()->gtCallThisArg->GetNode(); + arg2 = op2->AsCall()->gtArgs.GetThisArg()->GetArgNode(); } arg2 = gtNewMethodTableLookup(arg2); @@ -12262,7 +12606,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) GenTree* const opOther = (op1Kind == TPK_Handle) ? op2 : op1; // Tunnel through the handle operand to get at the class handle involved. - GenTree* const opHandleArgument = opHandle->AsCall()->gtCallArgs->GetNode(); + GenTree* const opHandleArgument = opHandle->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); CORINFO_CLASS_HANDLE clsHnd = gtGetHelperArgClassHandle(opHandleArgument); // If we couldn't find the class handle, give up. @@ -12297,7 +12641,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) } else { - objOp = opOther->AsCall()->gtCallThisArg->GetNode(); + objOp = opOther->AsCall()->gtArgs.GetThisArg()->GetArgNode(); } bool pIsExact = false; @@ -12799,7 +13143,7 @@ GenTree* Compiler::gtFoldBoxNullable(GenTree* tree) JITDUMP("\nAttempting to optimize BOX_NULLABLE(&x) %s null [%06u]\n", GenTree::OpName(oper), dspTreeID(tree)); // Get the address of the struct being boxed - GenTree* const arg = call->gtCallArgs->GetNext()->GetNode(); + GenTree* const arg = call->gtArgs.GetArgByIndex(1)->GetNode(); if (arg->OperIs(GT_ADDR) && ((arg->gtFlags & GTF_LATE_ARG) == 0)) { @@ -12908,18 +13252,17 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions else if (asgSrcOper == GT_CALL) { GenTreeCall* newobjCall = asgSrc->AsCall(); - GenTreeCall::Use* newobjArgs = newobjCall->gtCallArgs; // In R2R expansions the handle may not be an explicit operand to the helper, // so we can't remove the box. - if (newobjArgs == nullptr) + if (newobjCall->gtArgs.Args().begin() == newobjCall->gtArgs.Args().end()) { assert(newobjCall->IsHelperCall(this, CORINFO_HELP_READYTORUN_NEW)); JITDUMP(" bailing; newobj via R2R helper\n"); return nullptr; } - boxTypeHandle = newobjArgs->GetNode(); + boxTypeHandle = newobjCall->gtArgs.GetArgByIndex(0)->GetArgNode(); } else { @@ -14417,7 +14760,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree) assert(op1 != nullptr); op2 = op1; - op1 = gtNewHelperCallNode(CORINFO_HELP_OVERFLOW, TYP_VOID, gtNewCallArgs(gtNewIconNode(compCurBB->bbTryIndex))); + op1 = gtNewHelperCallNode(CORINFO_HELP_OVERFLOW, TYP_VOID, gtNewIconNode(compCurBB->bbTryIndex)); // op1 is a call to the JIT helper that throws an Overflow exception. // Attach the ExcSet for VNF_OverflowExc(Void) to this call. @@ -14640,8 +14983,10 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr, pFieldInfo->fieldAccessor == CORINFO_FIELD_INSTANCE_ADDR_HELPER || pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_ADDR_HELPER); + // Arguments in reverse order + GenTree* args[4]; + size_t nArgs = 0; /* If we can't access it directly, we need to call a helper function */ - GenTreeCall::Use* args = nullptr; var_types helperType = TYP_BYREF; if (pFieldInfo->fieldAccessor == CORINFO_FIELD_INSTANCE_HELPER) @@ -14664,7 +15009,7 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr, assg = gtNewCastNode(TYP_FLOAT, assg, false, TYP_FLOAT); } - args = gtNewCallArgs(assg); + args[nArgs++] = assg; helperType = TYP_VOID; } else if (access & CORINFO_ACCESS_GET) @@ -14683,7 +15028,7 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr, if (pFieldInfo->helper == CORINFO_HELP_GETFIELDSTRUCT || pFieldInfo->helper == CORINFO_HELP_SETFIELDSTRUCT) { assert(pFieldInfo->structType != nullptr); - args = gtPrependNewCallArg(gtNewIconEmbClsHndNode(pFieldInfo->structType), args); + args[nArgs++] = gtNewIconEmbClsHndNode(pFieldInfo->structType); } GenTree* fieldHnd = impTokenToHandle(pResolvedToken); @@ -14692,7 +15037,7 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr, return nullptr; } - args = gtPrependNewCallArg(fieldHnd, args); + args[nArgs++] = fieldHnd; // If it's a static field, we shouldn't have an object node // If it's an instance field, we have an object node @@ -14700,10 +15045,16 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr, if (objPtr != nullptr) { - args = gtPrependNewCallArg(objPtr, args); + args[nArgs++] = objPtr; } - GenTreeCall* call = gtNewHelperCallNode(pFieldInfo->helper, genActualType(helperType), args); + GenTreeCall* call = gtNewHelperCallNode(pFieldInfo->helper, genActualType(helperType)); + + for (size_t i = 0; i < nArgs; i++) + { + call->gtArgs.PushFront(this, args[i]); + call->gtFlags |= args[i]->gtFlags & GTF_ALL_EFFECT; + } #if FEATURE_MULTIREG_RET if (varTypeIsStruct(call)) @@ -14805,18 +15156,16 @@ bool Compiler::gtNodeHasSideEffects(GenTree* tree, GenTreeFlags flags) if (!call->HasSideEffects(this, ignoreExceptions, ignoreCctors)) { // If this call is otherwise side effect free, check its arguments. - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - if (gtTreeHasSideEffects(use.GetNode(), flags)) + // I'm a little worried that args that assign to temps that are late args will look like + // side effects...but better to be conservative for now. + if (gtTreeHasSideEffects(arg.GetNode(), flags)) { return true; } - } - // I'm a little worried that args that assign to temps that are late args will look like - // side effects...but better to be conservative for now. - for (GenTreeCall::Use& use : call->LateArgs()) - { - if (gtTreeHasSideEffects(use.GetNode(), flags)) + + if (arg.GetLateNode() != nullptr && gtTreeHasSideEffects(arg.GetLateNode(), flags)) { return true; } @@ -16768,7 +17117,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b NamedIntrinsic ni = lookupNamedIntrinsic(call->gtCallMethHnd); if ((ni == NI_System_Array_Clone) || (ni == NI_System_Object_MemberwiseClone)) { - objClass = gtGetClassHandle(call->gtCallThisArg->GetNode(), pIsExact, pIsNonNull); + objClass = gtGetClassHandle(call->gtArgs.GetThisArg()->GetArgNode(), pIsExact, pIsNonNull); break; } @@ -17034,8 +17383,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetHelperCallClassHandle(GenTreeCall* call, boo case CORINFO_HELP_ISINSTANCEOFANY: { // Fetch the class handle from the helper call arglist - GenTreeCall::Use* args = call->gtCallArgs; - GenTree* typeArg = args->GetNode(); + GenTree* typeArg = call->gtArgs.GetArgByIndex(0)->GetArgNode(); CORINFO_CLASS_HANDLE castHnd = gtGetHelperArgClassHandle(typeArg); // We generally assume the type being cast to is the best type @@ -17061,7 +17409,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetHelperCallClassHandle(GenTreeCall* call, boo // type from the value being cast instead. if (castHnd == nullptr) { - GenTree* valueArg = args->GetNext()->GetNode(); + GenTree* valueArg = call->gtArgs.GetArgByIndex(1)->GetArgNode(); castHnd = gtGetClassHandle(valueArg, pIsExact, pIsNonNull); } diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 5547363600b725..4a4a13d40d41fa 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -2743,13 +2743,12 @@ class GenTreeUseEdgeIterator final enum { - CALL_INSTANCE = 0, - CALL_ARGS = 1, - CALL_LATE_ARGS = 2, - CALL_CONTROL_EXPR = 3, - CALL_COOKIE = 4, - CALL_ADDRESS = 5, - CALL_TERMINAL = 6, + CALL_ARGS = 0, + CALL_LATE_ARGS = 1, + CALL_CONTROL_EXPR = 2, + CALL_COOKIE = 3, + CALL_ADDRESS = 4, + CALL_TERMINAL = 5, }; typedef void (GenTreeUseEdgeIterator::*AdvanceFn)(); @@ -2757,7 +2756,7 @@ class GenTreeUseEdgeIterator final AdvanceFn m_advance; GenTree* m_node; GenTree** m_edge; - // Pointer sized state storage, GenTreePhi::Use* or GenTreeCall::Use* + // Pointer sized state storage, GenTreePhi::Use* or CallArg* // or the exclusive end/beginning of GenTreeMultiOp's operand array. void* m_statePtr; // Integer sized state storage, usually the operand index for non-list based nodes. @@ -3710,8 +3709,8 @@ enum GenTreeCallFlags : unsigned int GTF_CALL_M_EXPLICIT_TAILCALL = 0x00000001, // the call is "tail" prefixed and importer has performed tail call checks GTF_CALL_M_TAILCALL = 0x00000002, // the call is a tailcall - GTF_CALL_M_VARARGS = 0x00000004, // the call uses varargs ABI - GTF_CALL_M_RETBUFFARG = 0x00000008, // call has a return buffer argument + GTF_CALL_M_RETBUFFARG = 0x00000004, // the ABI dictates that this call needs a ret buffer + GTF_CALL_M_RETBUFFARG_LCLOPT = 0x00000008, // Does this call have a local ret buffer that we are optimizing? GTF_CALL_M_DELEGATE_INV = 0x00000010, // call to Delegate.Invoke GTF_CALL_M_NOGCCHECK = 0x00000020, // not a call for computing full interruptability and therefore no GC check is required. GTF_CALL_M_SPECIAL_INTRINSIC = 0x00000040, // function that could be optimized as an intrinsic @@ -3996,158 +3995,548 @@ class TailCallSiteInfo } }; -class fgArgInfo; +enum class CFGCallKind +{ + ValidateAndCall, + Dispatch, +}; + +class CallArgs; -enum class NonStandardArgKind : unsigned +enum class WellKnownArg { None, + ThisPointer, + VarArgsCookie, + InstParam, + RetBuffer, PInvokeFrame, - PInvokeTarget, - PInvokeCookie, + SecretStubParam, WrapperDelegateCell, ShiftLow, ShiftHigh, - FixedRetBuffer, VirtualStubCell, + PInvokeCookie, + PInvokeTarget, R2RIndirectionCell, ValidateIndirectCallTarget, - - // If changing this enum also change getNonStandardArgKindName and isNonStandardArgAddedLate in fgArgInfo + DispatchIndirectCallTarget, }; #ifdef DEBUG -const char* getNonStandardArgKindName(NonStandardArgKind kind); +const char* getWellKnownArgName(WellKnownArg arg); #endif -enum class CFGCallKind +struct CallArgABIInformation { - ValidateAndCall, - Dispatch, + CallArgABIInformation() + : ArgNum((unsigned)-1) + , NumRegs(0) + , ByteOffset(0) + , ByteSize(0) + , ByteAlignment(0) +#ifdef UNIX_AMD64_ABI + , StructIntRegs(0) + , StructFloatRegs(0) +#endif +#ifdef DEBUG_ARG_SLOTS + , SlotNum(0) + , NumSlots(0) +#endif + , ArgType(TYP_UNDEF) + , IsBackFilled(false) + , IsStruct(false) + , PassedByRef(false) +#ifdef FEATURE_ARG_SPLIT + , m_isSplit(false) +#endif +#ifdef FEATURE_HFA_FIELDS_PRESENT + , m_hfaElemKind(CORINFO_HFA_ELEM_NONE) +#endif + { + for (size_t i = 0; i < MAX_ARG_REG_COUNT; i++) + { + RegNums[i] = REG_NA; + } + } + + // The original argument number, also specifies the required argument + // evaluation order from the IL + unsigned ArgNum; +private: + // The registers to use when passing this argument, set to REG_STK for + // arguments passed on the stack + regNumberSmall RegNums[MAX_ARG_REG_COUNT]; +public: + // Count of number of registers that this argument uses. Note that on ARM, + // if we have a double hfa, this reflects the number of DOUBLE registers. + unsigned NumRegs; + unsigned ByteOffset; + unsigned ByteSize; + unsigned ByteAlignment; +#if defined(UNIX_AMD64_ABI) + // Unix amd64 will split floating point types and integer types in structs + // between floating point and general purpose registers. Keep track of that + // information so we do not need to recompute it later. + unsigned StructIntRegs; + unsigned StructFloatRegs; + SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR StructDesc; +#endif // UNIX_AMD64_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_ARG_SLOTS + // The type used to pass this argument. This is generally the original + // argument type, but when a struct is passed as a scalar type, this is + // that type. Note that if a struct is passed by reference, this will still + // be the struct type. + var_types ArgType : 5; + // True when the argument fills a register slot skipped due to alignment + // requirements of previous arguments. + bool IsBackFilled : 1; + // True if this is a struct arg + bool IsStruct : 1; + // True iff the argument is passed by reference. + bool PassedByRef : 1; + +private: +#ifdef FEATURE_ARG_SPLIT + // True when this argument is split between the registers and OutArg area + bool m_isSplit : 1; +#endif + +#ifdef FEATURE_HFA_FIELDS_PRESENT + // What kind of an HFA this is (CORINFO_HFA_ELEM_NONE if it is not an HFA). + CorInfoHFAElemType m_hfaElemKind : 3; +#endif + +public: + CorInfoHFAElemType GetHfaElemKind() const + { +#ifdef FEATURE_HFA_FIELDS_PRESENT + return m_hfaElemKind; +#else + NOWAY_MSG("GetHfaElemKind"); + return CORINFO_HFA_ELEM_NONE; +#endif + } + + void SetHfaElemKind(CorInfoHFAElemType elemKind) + { +#ifdef FEATURE_HFA_FIELDS_PRESENT + m_hfaElemKind = elemKind; +#else + NOWAY_MSG("SetHfaElemKind"); +#endif + } + + bool IsHfaArg() const; + bool IsHfaRegArg() const; + var_types GetHfaType() const; + void SetHfaType(var_types type, unsigned hfaSlots); + + regNumber GetRegNum() const + { + return (regNumber)RegNums[0]; + } + + regNumber GetOtherRegNum() const + { + return (regNumber)RegNums[1]; + } + regNumber GetRegNum(unsigned int i) + { + assert(i < MAX_ARG_REG_COUNT); + return (regNumber)RegNums[i]; + } + void SetRegNum(unsigned int i, regNumber regNum) + { + assert(i < MAX_ARG_REG_COUNT); + RegNums[i] = (regNumberSmall)regNum; + } + + bool IsSplit() const + { +#if FEATURE_ARG_SPLIT + return compFeatureArgSplit() && m_isSplit; +#else // FEATURE_ARG_SPLIT + return false; +#endif + } + void SetSplit(bool value) + { +#if FEATURE_ARG_SPLIT + m_isSplit = value; +#endif + } + + bool IsPassedInRegisters() const + { + return !IsSplit() && (NumRegs != 0); + } + + bool IsPassedInFloatRegisters() const + { +#ifdef TARGET_X86 + return false; +#else + return isValidFloatArgReg(GetRegNum()); +#endif + } + + void SetByteSize(unsigned byteSize, unsigned byteAlignment, bool isStruct, bool isFloatHfa); + +#if defined(DEBUG_ARG_SLOTS) + // Returns the number of "slots" used, where for this purpose a + // register counts as a slot. + unsigned GetSlotCount() const; + unsigned GetSize() const; +#endif + + // Get the number of bytes that this argument is occupying on the stack, + // including padding up to the target pointer size for platforms + // where a stack argument can't take less. + unsigned GetStackByteSize() const; + + // Set the register numbers for a multireg argument. + // There's nothing to do on x64/Ux because the structDesc has already been used to set the + // register numbers. + void SetMultiRegNums(); + + // Return number of stack slots that this argument is taking. + // TODO-Cleanup: this function does not align with arm64 apple model, + // delete it. In most cases we just want to know if we it is using stack or not + // but in some cases we are checking if it is a multireg arg, like: + // `numRegs + GetStackSlotsNumber() > 1` that is harder to replace. + // + unsigned GetStackSlotsNumber() const + { + return roundUp(GetStackByteSize(), TARGET_POINTER_SIZE) / TARGET_POINTER_SIZE; + } + + // Can we replace the struct type of this node with a primitive type for argument passing? + bool TryPassAsPrimitive() const + { + return !IsSplit() && ((NumRegs == 1) || (ByteSize <= TARGET_POINTER_SIZE)); + } }; -struct GenTreeCall final : public GenTree +class CallArg +{ + friend class CallArgs; + + GenTree* m_node; + GenTree* m_lateNode; + CallArg* m_next; + CallArg* m_lateNext; + WellKnownArg m_wellKnownArg : 5; + + // True when we force this argument's evaluation into a temp LclVar. + bool m_needTmp : 1; + // True when we must replace this argument with a placeholder node. + bool m_needPlace : 1; + // True when we setup a temp LclVar for this argument due to size issues + // with the struct. + bool m_isTmp : 1; + // True when we have decided the evaluation order for this argument in LateArgs + bool m_processed : 1; + // The LclVar number if we had to force evaluation of this arg + unsigned m_tmpNum; +public: + CallArgABIInformation AbiInfo; + + CallArg(WellKnownArg specialArgKind) + : m_node(nullptr) + , m_lateNode(nullptr) + , m_next(nullptr) + , m_lateNext(nullptr) + , m_wellKnownArg(specialArgKind) + , m_needTmp(false) + , m_needPlace(false) + , m_isTmp(false) + , m_processed(false) + , m_tmpNum(BAD_VAR_NUM) + { + } + + CallArg(const CallArg&) = delete; + CallArg& operator=(CallArg&) = delete; + + // clang format off + GenTree*& NodeRef() { return m_node; } + GenTree* GetNode() { return m_node; } + void SetNode(GenTree* node) { m_node = node; } + GenTree*& LateNodeRef() { return m_lateNode; } + GenTree* GetLateNode() { return m_lateNode; } + void SetLateNode(GenTree* lateNode) { m_lateNode = lateNode; } + CallArg*& NextRef() { return m_next; } + CallArg* GetNext() { return m_next; } + void SetNext(CallArg* next) { m_next = next; } + CallArg*& LateNextRef() { return m_lateNext; } + CallArg* GetLateNext() { return m_lateNext; } + void SetLateNext(CallArg* lateNext) { m_lateNext = lateNext; } + WellKnownArg GetWellKnownArg() { return m_wellKnownArg; } + // TODO-ARGS: Remove + bool IsTemp() { return m_isTmp; } + // clang format on + + // Get the real argument node, i.e. not a setup or placeholder node. + // This is the same as GetNode() until morph. + GenTree* GetArgNode() + { + return m_lateNode == nullptr ? m_node : m_lateNode; + } + + bool IsArgAddedLate() const; + +#ifdef DEBUG + void Dump(Compiler* comp); + // Check that the value of 'AbiInfo.IsStruct' is consistent. + // A struct arg must be one of the following: + // - A node of struct type, + // - A GT_FIELD_LIST, or + // - A node of a scalar type, passed in a single register or slot + // (or two slots in the case of a struct pass on the stack as TYP_DOUBLE). + // + void CheckIsStruct(); +#endif +}; + +// Used in iterator to avoid pitfall with accessing early arg when iterating +// late args. +class LateArg { - class Use + CallArg* m_arg; + +public: + explicit LateArg(CallArg* arg) + : m_arg(arg) { - GenTree* m_node; - Use* m_next; + } + CallArg* GetArg() { return m_arg; } + GenTree* GetNode() { return m_arg->GetLateNode(); } + void SetNode(GenTree* node) { m_arg->SetLateNode(node); } + GenTree*& NodeRef() { return m_arg->LateNodeRef(); } +}; + +class CallArgs +{ + CallArg* m_head; + CallArg* m_lateHead; + + unsigned m_nextStackByteOffset; +#ifdef UNIX_X86_ABI + // Number of stack bytes pushed before we start pushing these arguments. + unsigned m_stkSizeBytes; + // Stack alignment in bytes required before arguments are pushed for this + // call. Computed dynamically during codegen, based on m_stkSizeBytes and the + // current stack level (genStackLevel) when the first stack adjustment is + // made for this call. + unsigned m_padStkAlign; +#endif + bool m_hasThisPointer : 1; + bool m_hasRetBuffer : 1; + bool m_isVarArgs : 1; + bool m_abiInformationDetermined : 1; + // True if we have one or more register arguments. + bool m_hasRegArgs : 1; + // True if we have one or more stack arguments. + bool m_hasStackArgs : 1; + bool m_argsComplete : 1; + bool m_argsSorted : 1; + // One or more arguments must be copied to a temp by EvalArgsToTemps. + bool m_needsTemps : 1; +#ifdef UNIX_X86_ABI + // Updateable flag, set to 'true' after we've done any required alignment. + bool m_alignmentDone : 1; +#endif + + void AddedWellKnownArg(WellKnownArg arg); + void RemovedWellKnownArg(WellKnownArg arg); + regNumber GetCustomRegister(Compiler* comp, CorInfoCallConvExtension cc, WellKnownArg arg); + void SplitArg(CallArg* arg, unsigned numRegs, unsigned numSlots, unsigned* nextSlotNum); +public: + CallArgs(); + CallArgs(const CallArgs&) = delete; + CallArgs& operator=(CallArgs&) = delete; + + CallArg* FindByNode(GenTree* node); + CallArg* FindWellKnownArg(WellKnownArg arg); + CallArg* GetThisArg(); + CallArg* GetRetBufferArg(); + CallArg* GetArgByIndex(unsigned index); + unsigned GetIndex(CallArg* arg); + + bool IsEmpty() const { return m_head == nullptr; } + + // Reverse the args from [index..index + count) in place. + void Reverse(unsigned index, unsigned count); + + // Create a new call argument at the beginning of the list. + CallArg* PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); + CallArg* PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); + CallArg* InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, WellKnownArg wellKnownArg = WellKnownArg::None); + CallArg* InsertInstParam(Compiler* comp, GenTree* value); + CallArg* InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); + bool Remove(CallArg* arg); + void Clear(); + + template + void InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc copyFunc); + + template + void PushFront(Compiler* comp, GenTree* node, T... rest) + { + PushFront(comp, rest...); + PushFront(comp, node); + } + + void ResetArgABIInformation(); + // Determine argument ABI information. + // TODO-ARGS: This is equivalent to old fgInitArgInfo and thus may add arguments. + // Refactor this to be idempotent. + void DetermineArgABIInformation(Compiler* comp, GenTreeCall* call); + + void ArgsComplete(Compiler* comp, GenTreeCall* call); + void SortArgs(Compiler* comp, GenTreeCall* call); + void EvalArgsToTemps(Compiler* comp, GenTreeCall* call); + void SetNeedsTemp(CallArg* arg); + bool IsNonStandard(Compiler* comp, GenTreeCall* call, CallArg* arg); + + GenTree* MakeTmpArgNode(Compiler* comp, CallArg* arg); + void SetTemp(CallArg* arg, unsigned tmpNum); + + // clang-format off + bool HasThisPointer() const { return m_hasThisPointer; } + bool HasRetBuffer() const { return m_hasRetBuffer; } + bool IsVarArgs() const { return m_isVarArgs; } + void SetIsVarArgs() { m_isVarArgs = true; } + void ClearIsVarArgs() { m_isVarArgs = false; } + bool IsAbiInformationDetermined() const { return m_abiInformationDetermined; } + bool AreArgsComplete() const { return m_argsComplete; } + bool HasRegArgs() const { return m_hasRegArgs; } + bool HasStackArgs() const { return m_hasStackArgs; } + bool NeedsTemps() const { return m_needsTemps; } + // clang-format on + + unsigned OutgoingArgsStackSize() const; + + unsigned CountArgs(); + + class CallArgIterator + { + CallArg* m_arg; public: - Use(GenTree* node, Use* next = nullptr) : m_node(node), m_next(next) + explicit CallArgIterator(CallArg* arg) + : m_arg(arg) { - assert(node != nullptr); } - GenTree*& NodeRef() + CallArg& operator*() const { - return m_node; + return *m_arg; } - GenTree* GetNode() const + CallArg* operator->() const { - assert(m_node != nullptr); - return m_node; + return m_arg; } - void SetNode(GenTree* node) + CallArg* GetArg() const { - assert(node != nullptr); - m_node = node; + return m_arg; } - Use*& NextRef() + CallArgIterator& operator++() { - return m_next; + m_arg = m_arg->GetNext(); + return *this; } - Use* GetNext() const + bool operator==(const CallArgIterator& i) const { - return m_next; + return m_arg == i.m_arg; } - void SetNext(Use* next) + bool operator!=(const CallArgIterator& i) const { - m_next = next; + return m_arg != i.m_arg; } }; - class UseIterator + IteratorPair Args() { - Use* m_use; - - public: - UseIterator(Use* use) : m_use(use) - { - } + return + IteratorPair( + CallArgIterator(m_head), + CallArgIterator(nullptr)); + } - Use& operator*() const - { - return *m_use; - } + class LateArgsIterator + { + CallArg* m_arg; - Use* operator->() const + public: + explicit LateArgsIterator(CallArg* arg) + : m_arg(arg) { - return m_use; } - Use* GetUse() const + LateArg operator*() const { - return m_use; + return LateArg(m_arg); } - UseIterator& operator++() + CallArg* GetArg() const { - m_use = m_use->GetNext(); - return *this; + return m_arg; } - bool operator==(const UseIterator& i) const + GenTree* GetNode() const { - return m_use == i.m_use; + return m_arg->GetLateNode(); } - bool operator!=(const UseIterator& i) const + GenTree*& NodeRef() { - return m_use != i.m_use; + return m_arg->LateNodeRef(); } - }; - class UseList - { - Use* m_uses; - - public: - UseList(Use* uses) : m_uses(uses) + LateArgsIterator& operator++() { + m_arg = m_arg->GetLateNext(); + return *this; } - UseIterator begin() const + bool operator==(const LateArgsIterator& i) const { - return UseIterator(m_uses); + return m_arg == i.m_arg; } - UseIterator end() const + bool operator!=(const LateArgsIterator& i) const { - return UseIterator(nullptr); + return m_arg != i.m_arg; } }; - Use* gtCallThisArg; // The instance argument ('this' pointer) - Use* gtCallArgs; // The list of arguments in original evaluation order - Use* gtCallLateArgs; // On x86: The register arguments in an optimal order - // On ARM/x64: - also includes any outgoing arg space arguments - // - that were evaluated into a temp LclVar - fgArgInfo* fgArgInfo; - - UseList Args() + IteratorPair LateArgs() { - return UseList(gtCallArgs); + return + IteratorPair( + LateArgsIterator(m_lateHead), + LateArgsIterator(nullptr)); } +}; - UseList LateArgs() - { - return UseList(gtCallLateArgs); - } +struct GenTreeCall final : public GenTree +{ + CallArgs gtArgs; #ifdef DEBUG // Used to register callsites with the EE @@ -4404,14 +4793,16 @@ struct GenTreeCall final : public GenTree bool HasNonStandardAddedArgs(Compiler* compiler) const; int GetNonStandardAddedArgCount(Compiler* compiler) const; - // Returns true if this call uses a retBuf argument and its calling convention - bool HasRetBufArg() const + // Returns true if the ABI dictates that this call should get a ret buf + // arg. This may be out of sync with gtArgs.HasRetBuffer during import + // until we actually create the ret buffer. + bool ShouldGetRetBufArg() const { return (gtCallMoreFlags & GTF_CALL_M_RETBUFFARG) != 0; } //------------------------------------------------------------------------- - // TreatAsHasRetBufArg: + // TreatAsShouldGetRetBufArg: // // Arguments: // compiler, the compiler instance so that we can call eeGetHelperNum @@ -4424,23 +4815,10 @@ struct GenTreeCall final : public GenTree // // Notes: // On ARM64 marking the method with the GTF_CALL_M_RETBUFFARG flag - // will make HasRetBufArg() return true, but will also force the + // will make ShouldGetRetBufArg() return true, but will also force the // use of register x8 to pass the RetBuf argument. // - bool TreatAsHasRetBufArg(Compiler* compiler) const; - - bool HasFixedRetBufArg() const - { - if (!(hasFixedRetBuffReg() && HasRetBufArg())) - { - return false; - } -#if !defined(TARGET_ARM) - return !TargetOS::IsWindows || !callConvIsInstanceMethodCallConv(GetUnmanagedCallConv()); -#else - return true; -#endif - } + bool TreatAsShouldGetRetBufArg(Compiler* compiler) const; //----------------------------------------------------------------------------------------- // HasMultiRegRetVal: whether the call node returns its value in multiple return registers. @@ -4461,7 +4839,7 @@ struct GenTreeCall final : public GenTree } #endif - if (!varTypeIsStruct(gtType) || HasRetBufArg()) + if (!varTypeIsStruct(gtType) || ShouldGetRetBufArg()) { return false; } @@ -4596,7 +4974,7 @@ struct GenTreeCall final : public GenTree bool IsVarargs() const { - return (gtCallMoreFlags & GTF_CALL_M_VARARGS) != 0; + return gtArgs.IsVarArgs(); } bool IsNoReturn() const @@ -4701,30 +5079,30 @@ struct GenTreeCall final : public GenTree // // Return Value: // The kind (either R2RIndirectionCell or VirtualStubCell), - // or NonStandardArgKind::None if this call does not have an indirection cell. + // or WellKnownArg::None if this call does not have an indirection cell. // - NonStandardArgKind GetIndirectionCellArgKind() const + WellKnownArg GetIndirectionCellArgKind() const { if (IsVirtualStub()) { - return NonStandardArgKind::VirtualStubCell; + return WellKnownArg::VirtualStubCell; } #if defined(TARGET_ARMARCH) // For ARM architectures, we always use an indirection cell for R2R calls. if (IsR2RRelativeIndir()) { - return NonStandardArgKind::R2RIndirectionCell; + return WellKnownArg::R2RIndirectionCell; } #elif defined(TARGET_XARCH) // On XARCH we disassemble it from callsite except for tailcalls that need indirection cell. if (IsR2RRelativeIndir() && IsFastTailCall()) { - return NonStandardArgKind::R2RIndirectionCell; + return WellKnownArg::R2RIndirectionCell; } #endif - return NonStandardArgKind::None; + return WellKnownArg::None; } CFGCallKind GetCFGCallKind() @@ -4733,7 +5111,7 @@ struct GenTreeCall final : public GenTree // On x64 the dispatcher is more performant, but we cannot use it when // we need to pass indirection cells as those go into registers that // are clobbered by the dispatch helper. - bool mayUseDispatcher = GetIndirectionCellArgKind() == NonStandardArgKind::None; + bool mayUseDispatcher = GetIndirectionCellArgKind() == WellKnownArg::None; bool shouldUseDispatcher = true; #elif defined(TARGET_ARM64) bool mayUseDispatcher = true; @@ -4763,8 +5141,6 @@ struct GenTreeCall final : public GenTree return mayUseDispatcher && shouldUseDispatcher ? CFGCallKind::Dispatch : CFGCallKind::ValidateAndCall; } - void ResetArgInfo(); - GenTreeCallFlags gtCallMoreFlags; // in addition to gtFlags gtCallTypes gtCallType : 3; // value from the gtCallTypes enumeration var_types gtReturnType : 5; // exact return type @@ -4833,26 +5209,28 @@ struct GenTreeCall final : public GenTree static bool Equals(GenTreeCall* c1, GenTreeCall* c2); - GenTreeCall(var_types type) : GenTree(GT_CALL, type) + GenTreeCall(var_types type) : GenTree(GT_CALL, type), gtArgs() { - fgArgInfo = nullptr; - gtRetBufArg = nullptr; } #if DEBUGGABLE_GENTREE - GenTreeCall() : GenTree() + GenTreeCall() : GenTree(), gtArgs() { } #endif - GenTree* GetLclRetBufArgNode() const + GenTree* GetLclRetBufArgNode() { - if (gtRetBufArg == nullptr) + if (!gtArgs.HasRetBuffer() || ((gtCallMoreFlags & GTF_CALL_M_RETBUFFARG_LCLOPT) == 0)) { return nullptr; } - assert(HasRetBufArg()); - GenTree* lclRetBufArgNode = gtRetBufArg->GetNode(); + CallArg* retBufArg = gtArgs.GetRetBufferArg(); + GenTree* lclRetBufArgNode = retBufArg->GetNode(); + if (lclRetBufArgNode->IsArgPlaceHolderNode()) + { + lclRetBufArgNode = retBufArg->GetLateNode(); + } switch (lclRetBufArgNode->OperGet()) { @@ -4873,9 +5251,7 @@ struct GenTreeCall final : public GenTree } } - void SetLclRetBufArg(Use* retBufArg); - - Use* gtRetBufArg; // The argument that holds return buffer argument + void SetLclRetBufArg(CallArg* retBufArg); }; struct GenTreeCmpXchg : public GenTree diff --git a/src/coreclr/jit/gschecks.cpp b/src/coreclr/jit/gschecks.cpp index 60634f60cfcea8..80089d4f238432 100644 --- a/src/coreclr/jit/gschecks.cpp +++ b/src/coreclr/jit/gschecks.cpp @@ -189,20 +189,18 @@ Compiler::fgWalkResult Compiler::gsMarkPtrsAndAssignGroups(GenTree** pTree, fgWa newState.isUnderIndir = false; newState.isAssignSrc = false; { - if (tree->AsCall()->gtCallThisArg != nullptr) + for (CallArg& arg : tree->AsCall()->gtArgs.Args()) { - newState.isUnderIndir = true; - comp->fgWalkTreePre(&tree->AsCall()->gtCallThisArg->NodeRef(), gsMarkPtrsAndAssignGroups, - (void*)&newState); - } + if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) + { + newState.isUnderIndir = true; + } - for (GenTreeCall::Use& use : tree->AsCall()->Args()) - { - comp->fgWalkTreePre(&use.NodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); + comp->fgWalkTreePre(&arg.NodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); } - for (GenTreeCall::Use& use : tree->AsCall()->LateArgs()) + for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) { - comp->fgWalkTreePre(&use.NodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); + comp->fgWalkTreePre(&arg.NodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); } if (tree->AsCall()->gtCallType == CT_INDIRECT) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 1de3bad31a91e9..e9f9cda02dae68 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -801,35 +801,12 @@ void Compiler::impAssignTempGen(unsigned tmpNum, * * Pop the given number of values from the stack and return a list node with * their values. - * The 'prefixTree' argument may optionally contain an argument - * list that is prepended to the list returned from this function. - * - * The notion of prepended is a bit misleading in that the list is backwards - * from the way I would expect: The first element popped is at the end of - * the returned list, and prefixTree is 'before' that, meaning closer to - * the end of the list. To get to prefixTree, you have to walk to the - * end of the list. - * - * For ARG_ORDER_R2L prefixTree is only used to insert extra arguments, as - * such we reverse its meaning such that returnValue has a reversed - * prefixTree at the head of the list. */ -GenTreeCall::Use* Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, GenTreeCall::Use* prefixArgs) +void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList) { assert(sig == nullptr || count == sig->numArgs); - - CORINFO_CLASS_HANDLE structType; - GenTreeCall::Use* argList; - - if (Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) - { - argList = nullptr; - } - else - { // ARG_ORDER_L2R - argList = prefixArgs; - } + assert(argList->IsEmpty()); while (count--) { @@ -841,7 +818,7 @@ GenTreeCall::Use* Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig { // Morph trees that aren't already OBJs or MKREFANY to be OBJs assert(ti.IsType(TI_STRUCT)); - structType = ti.GetClassHandleForValueClass(); + CORINFO_CLASS_HANDLE structType = ti.GetClassHandleForValueClass(); bool forceNormalization = false; if (varTypeIsSIMD(temp)) @@ -876,7 +853,7 @@ GenTreeCall::Use* Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig } /* NOTE: we defer bashing the type for I_IMPL to fgMorphArgs */ - argList = gtPrependNewCallArg(temp, argList); + argList->PushFront(this, temp); } if (sig != nullptr) @@ -893,34 +870,34 @@ GenTreeCall::Use* Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig } CORINFO_ARG_LIST_HANDLE sigArgs = sig->args; - GenTreeCall::Use* arg; - - for (arg = argList, count = sig->numArgs; count > 0; arg = arg->GetNext(), count--) + unsigned index = 0; + for (CallArg& arg : argList->Args()) { - PREFIX_ASSUME(arg != nullptr); + if (index >= sig->numArgs) + break; CORINFO_CLASS_HANDLE classHnd; CorInfoType corType = strip(info.compCompHnd->getArgType(sig, sigArgs, &classHnd)); var_types jitSigType = JITtype2varType(corType); - if (!impCheckImplicitArgumentCoercion(jitSigType, arg->GetNode()->TypeGet())) + if (!impCheckImplicitArgumentCoercion(jitSigType, arg.GetNode()->TypeGet())) { BADCODE("the call argument has a type that can't be implicitly converted to the signature type"); } // insert implied casts (from float to double or double to float) - if ((jitSigType == TYP_DOUBLE) && (arg->GetNode()->TypeGet() == TYP_FLOAT)) + if ((jitSigType == TYP_DOUBLE) && (arg.GetNode()->TypeGet() == TYP_FLOAT)) { - arg->SetNode(gtNewCastNode(TYP_DOUBLE, arg->GetNode(), false, TYP_DOUBLE)); + arg.SetNode(gtNewCastNode(TYP_DOUBLE, arg.GetNode(), false, TYP_DOUBLE)); } - else if ((jitSigType == TYP_FLOAT) && (arg->GetNode()->TypeGet() == TYP_DOUBLE)) + else if ((jitSigType == TYP_FLOAT) && (arg.GetNode()->TypeGet() == TYP_DOUBLE)) { - arg->SetNode(gtNewCastNode(TYP_FLOAT, arg->GetNode(), false, TYP_FLOAT)); + arg.SetNode(gtNewCastNode(TYP_FLOAT, arg.GetNode(), false, TYP_FLOAT)); } // insert any widening or narrowing casts for backwards compatibility - arg->SetNode(impImplicitIorI4Cast(arg->GetNode(), jitSigType)); + arg.SetNode(impImplicitIorI4Cast(arg.GetNode(), jitSigType)); if (corType != CORINFO_TYPE_CLASS && corType != CORINFO_TYPE_BYREF && corType != CORINFO_TYPE_PTR && corType != CORINFO_TYPE_VAR) @@ -937,36 +914,24 @@ GenTreeCall::Use* Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig } } - const var_types nodeArgType = arg->GetNode()->TypeGet(); + const var_types nodeArgType = arg.GetNode()->TypeGet(); if (!varTypeIsStruct(jitSigType) && genTypeSize(nodeArgType) != genTypeSize(jitSigType)) { assert(!varTypeIsStruct(nodeArgType)); // Some ABI require precise size information for call arguments less than target pointer size, // for example arm64 OSX. Create a special node to keep this information until morph // consumes it into `fgArgInfo`. - GenTree* putArgType = gtNewOperNode(GT_PUTARG_TYPE, jitSigType, arg->GetNode()); - arg->SetNode(putArgType); + GenTree* putArgType = gtNewOperNode(GT_PUTARG_TYPE, jitSigType, arg.GetNode()); + arg.SetNode(putArgType); } sigArgs = info.compCompHnd->getArgNext(sigArgs); - } - } - - if (Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) - { - // Prepend the prefixTree - // Simple in-place reversal to place treeList - // at the end of a reversed prefixTree - while (prefixArgs != nullptr) - { - GenTreeCall::Use* next = prefixArgs->GetNext(); - prefixArgs->SetNext(argList); - argList = prefixArgs; - prefixArgs = next; + index++; } + + assert(index == sig->numArgs); } - return argList; } static bool TypeIs(var_types type1, var_types type2) @@ -1080,57 +1045,13 @@ bool Compiler::impCheckImplicitArgumentCoercion(var_types sigType, var_types nod * The first "skipReverseCount" items are not reversed. */ -GenTreeCall::Use* Compiler::impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, unsigned skipReverseCount) +void Compiler::impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList, unsigned skipReverseCount) { assert(skipReverseCount <= count); - GenTreeCall::Use* list = impPopCallArgs(count, sig); + impPopCallArgs(count, sig, argList); - // reverse the list - if (list == nullptr || skipReverseCount == count) - { - return list; - } - - GenTreeCall::Use* ptr = nullptr; // Initialized to the first node that needs to be reversed - GenTreeCall::Use* lastSkipNode = nullptr; // Will be set to the last node that does not need to be reversed - - if (skipReverseCount == 0) - { - ptr = list; - } - else - { - lastSkipNode = list; - // Get to the first node that needs to be reversed - for (unsigned i = 0; i < skipReverseCount - 1; i++) - { - lastSkipNode = lastSkipNode->GetNext(); - } - - PREFIX_ASSUME(lastSkipNode != nullptr); - ptr = lastSkipNode->GetNext(); - } - - GenTreeCall::Use* reversedList = nullptr; - - do - { - GenTreeCall::Use* tmp = ptr->GetNext(); - ptr->SetNext(reversedList); - reversedList = ptr; - ptr = tmp; - } while (ptr != nullptr); - - if (skipReverseCount) - { - lastSkipNode->SetNext(reversedList); - return list; - } - else - { - return reversedList; - } + argList->Reverse(skipReverseCount, count - skipReverseCount); } //------------------------------------------------------------------------ @@ -1280,11 +1201,17 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, if (src->gtOper == GT_CALL) { GenTreeCall* srcCall = src->AsCall(); - if (srcCall->TreatAsHasRetBufArg(this)) + if (srcCall->TreatAsShouldGetRetBufArg(this)) { // Case of call returning a struct via hidden retbuf arg CLANG_FORMAT_COMMENT_ANCHOR; + // Some calls have an "out buffer" that is not actually a ret buff + // in the ABI sense. We take the path here for those but it should + // not be marked as the ret buff arg since it always follow the + // normal ABI for parameters. + WellKnownArg wellKnownArgType = srcCall->ShouldGetRetBufArg() ? WellKnownArg::RetBuffer : WellKnownArg::None; + #if !defined(TARGET_ARM) // Unmanaged instance methods on Windows or Unix X86 need the retbuf arg after the first (this) parameter if ((TargetOS::IsWindows || compUnixX86Abi()) && srcCall->IsUnmanaged()) @@ -1292,39 +1219,46 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, if (callConvIsInstanceMethodCallConv(srcCall->GetUnmanagedCallConv())) { #ifdef TARGET_X86 - // The argument list has already been reversed. - // Insert the return buffer as the second-to-last node - // so it will be pushed on to the stack after the user args but before the native this arg - // as required by the native ABI. - GenTreeCall::Use* lastArg = srcCall->gtCallArgs; - if (lastArg == nullptr) + // The argument list has already been reversed making it + // complicated to figure out where the retbuffer should be + // inserted. There are several cases. + + if (srcCall->gtArgs.Args().begin() == srcCall->gtArgs.Args().end()) { - srcCall->gtCallArgs = gtPrependNewCallArg(destAddr, srcCall->gtCallArgs); + // Empty arg list + srcCall->gtArgs.PushFront(this, destAddr, wellKnownArgType); } else if (srcCall->GetUnmanagedCallConv() == CorInfoCallConvExtension::Thiscall) { // For thiscall, the "this" parameter is not included in the argument list reversal, // so we need to put the return buffer as the last parameter. - for (; lastArg->GetNext() != nullptr; lastArg = lastArg->GetNext()) - ; - gtInsertNewCallArgAfter(destAddr, lastArg); + srcCall->gtArgs.PushBack(this, destAddr, wellKnownArgType); } - else if (lastArg->GetNext() == nullptr) + else if (srcCall->gtArgs.Args().begin()->GetNext() == nullptr) { - srcCall->gtCallArgs = gtPrependNewCallArg(destAddr, lastArg); + // Only 1 arg, so insert at beginning + srcCall->gtArgs.PushFront(this, destAddr, wellKnownArgType); } else { - assert(lastArg != nullptr && lastArg->GetNext() != nullptr); - GenTreeCall::Use* secondLastArg = lastArg; - lastArg = lastArg->GetNext(); - for (; lastArg->GetNext() != nullptr; secondLastArg = lastArg, lastArg = lastArg->GetNext()) - ; - assert(secondLastArg->GetNext() != nullptr); - gtInsertNewCallArgAfter(destAddr, secondLastArg); + // Find second last arg + CallArg* secondLastArg = nullptr; + for (CallArg& arg : srcCall->gtArgs.Args()) + { + assert(arg.GetNext() != nullptr); + if (arg.GetNext()->GetNext() == nullptr) + { + secondLastArg = &arg; + break; + } + } + + assert(secondLastArg && "Expected to find second last arg"); + srcCall->gtArgs.InsertAfter(this, secondLastArg, destAddr, wellKnownArgType); } + #else - GenTreeCall::Use* thisArg = gtInsertNewCallArgAfter(destAddr, srcCall->gtCallArgs); + srcCall->gtArgs.InsertAfter(this, &*srcCall->gtArgs.Args().begin(), destAddr, wellKnownArgType); #endif } else @@ -1333,28 +1267,18 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, // The argument list has already been reversed. // Insert the return buffer as the last node so it will be pushed on to the stack last // as required by the native ABI. - GenTreeCall::Use* lastArg = srcCall->gtCallArgs; - if (lastArg == nullptr) - { - srcCall->gtCallArgs = gtPrependNewCallArg(destAddr, srcCall->gtCallArgs); - } - else - { - for (; lastArg->GetNext() != nullptr; lastArg = lastArg->GetNext()) - ; - gtInsertNewCallArgAfter(destAddr, lastArg); - } + srcCall->gtArgs.PushBack(this, destAddr, wellKnownArgType); #else // insert the return value buffer into the argument list as first byref parameter - srcCall->gtCallArgs = gtPrependNewCallArg(destAddr, srcCall->gtCallArgs); + srcCall->gtArgs.PushFront(this, destAddr, wellKnownArgType); #endif } } else #endif // !defined(TARGET_ARM) { - // insert the return value buffer into the argument list as first byref parameter - srcCall->gtCallArgs = gtPrependNewCallArg(destAddr, srcCall->gtCallArgs); + // insert the return value buffer into the argument list as first byref parameter after 'this' + srcCall->gtArgs.InsertAfterThisOrFirst(this, destAddr, wellKnownArgType); } // now returns void, not a struct @@ -1423,10 +1347,10 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, GenTreeCall* call = src->AsRetExpr()->gtInlineCandidate->AsCall(); noway_assert(call->gtOper == GT_CALL); - if (call->HasRetBufArg()) + if (call->ShouldGetRetBufArg()) { // insert the return value buffer into the argument list as first byref parameter - call->gtCallArgs = gtPrependNewCallArg(destAddr, call->gtCallArgs); + call->gtArgs.InsertAfterThisOrFirst(this, destAddr, WellKnownArg::RetBuffer); // now returns void, not a struct src->gtType = TYP_VOID; @@ -2161,7 +2085,7 @@ GenTreeCall* Compiler::impReadyToRunHelperToTree( CORINFO_RESOLVED_TOKEN* pResolvedToken, CorInfoHelpFunc helper, var_types type, - GenTreeCall::Use* args /* = nullptr */, + GenTree* arg1, CORINFO_LOOKUP_KIND* pGenericLookupKind /* =NULL. Only used with generics */) { CORINFO_CONST_LOOKUP lookup; @@ -2170,7 +2094,7 @@ GenTreeCall* Compiler::impReadyToRunHelperToTree( return nullptr; } - GenTreeCall* op1 = gtNewHelperCallNode(helper, type, args); + GenTreeCall* op1 = gtNewHelperCallNode(helper, type, arg1); op1->setEntryPoint(lookup); @@ -2282,7 +2206,7 @@ GenTree* Compiler::impRuntimeLookupToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken if (opts.IsReadyToRun()) { return impReadyToRunHelperToTree(pResolvedToken, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, TYP_I_IMPL, - gtNewCallArgs(ctxTree), &pLookup->lookupKind); + ctxTree, &pLookup->lookupKind); } #endif return gtNewRuntimeLookupHelperCallNode(pRuntimeLookup, ctxTree, compileTimeHandle); @@ -2397,8 +2321,7 @@ GenTree* Compiler::impRuntimeLookupToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken // - Setup argNode with the pointer to the signature returned by the lookup GenTree* argNode = gtNewIconEmbHndNode(pRuntimeLookup->signature, nullptr, GTF_ICON_GLOBAL_PTR, compileTimeHandle); - GenTreeCall::Use* helperArgs = gtNewCallArgs(ctxTree, argNode); - GenTreeCall* helperCall = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL, helperArgs); + GenTreeCall* helperCall = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL, ctxTree, argNode); // Check for null and possibly call helper GenTree* nullCheck = gtNewOperNode(GT_NE, TYP_INT, handleForNullCheck, gtNewIconNode(0, TYP_I_IMPL)); @@ -2427,9 +2350,7 @@ GenTree* Compiler::impRuntimeLookupToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken // ((sizeCheck fails || nullCheck fails))) ? (helperCall : handle). // Add checks and the handle as call arguments, indirect call transformer will handle this. - helperCall->gtCallArgs = gtPrependNewCallArg(handleForResult, helperCall->gtCallArgs); - helperCall->gtCallArgs = gtPrependNewCallArg(sizeCheck, helperCall->gtCallArgs); - helperCall->gtCallArgs = gtPrependNewCallArg(nullCheck, helperCall->gtCallArgs); + helperCall->gtArgs.PushFront(this, nullCheck, sizeCheck, handleForResult); result = helperCall; addExpRuntimeLookupCandidate(helperCall); } @@ -3276,7 +3197,7 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) } // Strip helper call away - fieldTokenNode = fieldTokenNode->AsCall()->gtCallArgs->GetNode(); + fieldTokenNode = fieldTokenNode->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); if (fieldTokenNode->gtOper == GT_IND) { @@ -3375,11 +3296,11 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) return nullptr; } - GenTreeCall::Use* tokenArg = newArrayCall->AsCall()->gtCallArgs; + CallArg* tokenArg = &*newArrayCall->AsCall()->gtArgs.Args().begin(); assert(tokenArg != nullptr); - GenTreeCall::Use* numArgsArg = tokenArg->GetNext(); + CallArg* numArgsArg = tokenArg->GetNext(); assert(numArgsArg != nullptr); - GenTreeCall::Use* argsArg = numArgsArg->GetNext(); + CallArg* argsArg = numArgsArg->GetNext(); assert(argsArg != nullptr); // @@ -3514,18 +3435,17 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) GenTree* arrayLengthNode; - GenTreeCall::Use* args = newArrayCall->AsCall()->gtCallArgs; #ifdef FEATURE_READYTORUN if (newArrayCall->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_READYTORUN_NEWARR_1)) { // Array length is 1st argument for readytorun helper - arrayLengthNode = args->GetNode(); + arrayLengthNode = newArrayCall->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); } else #endif { // Array length is 2nd argument for regular helper - arrayLengthNode = args->GetNext()->GetNode(); + arrayLengthNode = newArrayCall->AsCall()->gtArgs.GetArgByIndex(1)->GetArgNode(); } // @@ -3633,7 +3553,7 @@ GenTree* Compiler::impCreateSpanIntrinsic(CORINFO_SIG_INFO* sig) } // Strip helper call away - fieldTokenNode = fieldTokenNode->AsCall()->gtCallArgs->GetNode(); + fieldTokenNode = fieldTokenNode->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); if (fieldTokenNode->gtOper == GT_IND) { fieldTokenNode = fieldTokenNode->AsOp()->gtOp1; @@ -4176,9 +4096,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, op1 = impPopStack().val; // Get native TypeHandle argument to old helper - GenTreeCall::Use* arg = op1->AsCall()->gtCallArgs; - assert(arg->GetNext() == nullptr); - op1 = arg->GetNode(); + assert(op1->AsCall()->gtArgs.CountArgs() == 1); + op1 = op1->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); retNode = op1; } // Call the regular function. @@ -4203,8 +4122,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, assert(typeHandleHelper == CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_MAYBENULL); typeHandleHelper = CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL; } - assert(op1->AsCall()->gtCallArgs->GetNext() == nullptr); - op1 = gtNewHelperCallNode(typeHandleHelper, TYP_REF, op1->AsCall()->gtCallArgs); + assert(op1->AsCall()->gtArgs.CountArgs() == 1); + op1 = gtNewHelperCallNode(typeHandleHelper, TYP_REF, op1->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); op1->gtType = TYP_REF; retNode = op1; } @@ -4294,7 +4213,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, GenTreeCall* call = impStackTop().val->AsCall(); if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE)) { - CORINFO_CLASS_HANDLE hClass = gtGetHelperArgClassHandle(call->gtCallArgs->GetNode()); + assert(call->gtArgs.CountArgs() == 1); + CORINFO_CLASS_HANDLE hClass = gtGetHelperArgClassHandle(call->gtArgs.GetArgByIndex(0)->GetNode()); if (hClass != NO_CLASS_HANDLE) { retNode = @@ -4573,9 +4493,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, // do for LDTOKEN since the return value of this operator is Type, // not RuntimeTypeHandle. impPopStack(); - GenTreeCall::Use* helperArgs = gtNewCallArgs(boxTypeHandle); GenTree* runtimeType = - gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, TYP_REF, helperArgs); + gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, TYP_REF, boxTypeHandle); retNode = runtimeType; } } @@ -4603,9 +4522,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, assert(compDonotInline()); return nullptr; } - GenTreeCall::Use* helperArgs = gtNewCallArgs(typeHandleOp); GenTree* runtimeType = - gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, TYP_REF, helperArgs); + gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, TYP_REF, typeHandleOp); retNode = runtimeType; } } @@ -4861,8 +4779,10 @@ GenTree* Compiler::impTypeIsAssignable(GenTree* typeTo, GenTree* typeFrom) CORINFO_METHOD_HANDLE hTypeof = eeFindHelper(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE); if ((typeTo->AsCall()->gtCallMethHnd == hTypeof) && (typeFrom->AsCall()->gtCallMethHnd == hTypeof)) { - CORINFO_CLASS_HANDLE hClassTo = gtGetHelperArgClassHandle(typeTo->AsCall()->gtCallArgs->GetNode()); - CORINFO_CLASS_HANDLE hClassFrom = gtGetHelperArgClassHandle(typeFrom->AsCall()->gtCallArgs->GetNode()); + assert((typeTo->AsCall()->gtArgs.CountArgs() == 1) && + (typeFrom->AsCall()->gtArgs.CountArgs() == 1)); + CORINFO_CLASS_HANDLE hClassTo = gtGetHelperArgClassHandle(typeTo->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); + CORINFO_CLASS_HANDLE hClassFrom = gtGetHelperArgClassHandle(typeFrom->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); if (hClassTo == NO_CLASS_HANDLE || hClassFrom == NO_CLASS_HANDLE) { @@ -5905,7 +5825,7 @@ void Compiler::verConvertBBToThrowVerificationException(BasicBlock* block DEBUGA assert(verCurrentState.esStackDepth == 0); GenTree* op1 = - gtNewHelperCallNode(CORINFO_HELP_VERIFICATION, TYP_VOID, gtNewCallArgs(gtNewIconNode(block->bbCodeOffs))); + gtNewHelperCallNode(CORINFO_HELP_VERIFICATION, TYP_VOID, gtNewIconNode(block->bbCodeOffs)); // verCurrentState.esStackDepth = 0; impAppendTree(op1, (unsigned)CHECK_SPILL_NONE, impCurStmtDI); @@ -6876,7 +6796,7 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr, GenTree* runtimeMethodHandle = impLookupToTree(pResolvedToken, &pCallInfo->codePointerLookup, GTF_ICON_METHOD_HDL, pCallInfo->hMethod); return gtNewHelperCallNode(CORINFO_HELP_GVMLOOKUP_FOR_SLOT, TYP_I_IMPL, - gtNewCallArgs(thisPtr, runtimeMethodHandle)); + thisPtr, runtimeMethodHandle); } #ifdef FEATURE_READYTORUN @@ -6885,7 +6805,7 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr, if (!pCallInfo->exactContextNeedsRuntimeLookup) { GenTreeCall* call = - gtNewHelperCallNode(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, TYP_I_IMPL, gtNewCallArgs(thisPtr)); + gtNewHelperCallNode(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, TYP_I_IMPL, thisPtr); call->setEntryPoint(pCallInfo->codePointerLookup.constLookup); @@ -6898,7 +6818,7 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr, GenTree* ctxTree = getRuntimeContextTree(pCallInfo->codePointerLookup.lookupKind.runtimeLookupKind); return impReadyToRunHelperToTree(pResolvedToken, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, TYP_I_IMPL, - gtNewCallArgs(ctxTree), &pCallInfo->codePointerLookup.lookupKind); + ctxTree, &pCallInfo->codePointerLookup.lookupKind); } } #endif @@ -6916,15 +6836,9 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr, return nullptr; } - GenTreeCall::Use* helpArgs = gtNewCallArgs(exactMethodDesc); - - helpArgs = gtPrependNewCallArg(exactTypeDesc, helpArgs); - - helpArgs = gtPrependNewCallArg(thisPtr, helpArgs); - // Call helper function. This gets the target address of the final destination callsite. - return gtNewHelperCallNode(CORINFO_HELP_VIRTUAL_FUNC_PTR, TYP_I_IMPL, helpArgs); + return gtNewHelperCallNode(CORINFO_HELP_VIRTUAL_FUNC_PTR, TYP_I_IMPL, thisPtr, exactTypeDesc, exactMethodDesc); } //------------------------------------------------------------------------ @@ -7327,7 +7241,7 @@ void Compiler::impImportAndPushBox(CORINFO_RESOLVED_TOKEN* pResolvedToken) { GenTreeCall* const call = exprToBox->AsRetExpr()->gtInlineCandidate->AsCall(); - if (call->HasRetBufArg()) + if (call->ShouldGetRetBufArg()) { JITDUMP("Must insert newobj stmts for box before call [%06u]\n", dspTreeID(call)); @@ -7467,9 +7381,7 @@ void Compiler::impImportAndPushBox(CORINFO_RESOLVED_TOKEN* pResolvedToken) return; } - GenTreeCall::Use* args = - gtNewCallArgs(op2, impGetStructAddr(exprToBox, operCls, (unsigned)CHECK_SPILL_ALL, true)); - op1 = gtNewHelperCallNode(boxHelper, TYP_REF, args); + op1 = gtNewHelperCallNode(boxHelper, TYP_REF, op2, impGetStructAddr(exprToBox, operCls, (unsigned)CHECK_SPILL_ALL, true)); } /* Push the result back on the stack, */ @@ -7552,18 +7464,11 @@ void Compiler::impImportNewObjArray(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORI node = gtNewOperNode(GT_COMMA, node->TypeGet(), gtNewAssignNode(dest, arg), node); } - GenTreeCall::Use* args = gtNewCallArgs(node); - - // pass number of arguments to the helper - args = gtPrependNewCallArg(gtNewIconNode(pCallInfo->sig.numArgs), args); - - args = gtPrependNewCallArg(classHandle, args); + node = gtNewHelperCallNode(CORINFO_HELP_NEW_MDARR, TYP_REF, classHandle, gtNewIconNode(pCallInfo->sig.numArgs), node); - node = gtNewHelperCallNode(CORINFO_HELP_NEW_MDARR, TYP_REF, args); - - for (GenTreeCall::Use& use : node->AsCall()->Args()) + for (CallArg& arg : node->AsCall()->gtArgs.Args()) { - node->gtFlags |= use.GetNode()->gtFlags & GTF_GLOB_EFFECT; + node->gtFlags |= arg.GetNode()->gtFlags & GTF_GLOB_EFFECT; } node->AsCall()->compileTimeHelperArgumentHandle = (CORINFO_GENERIC_HANDLE)pResolvedToken->hClass; @@ -7923,7 +7828,7 @@ GenTreeCall* Compiler::impImportIndirectCall(CORINFO_SIG_INFO* sig, const DebugI /* Create the call node */ - GenTreeCall* call = gtNewIndCallNode(fptr, callRetTyp, nullptr, di); + GenTreeCall* call = gtNewIndCallNode(fptr, callRetTyp, di); call->gtFlags |= GTF_EXCEPT | (fptr->gtFlags & GTF_GLOB_EFFECT); #ifdef UNIX_X86_ABI @@ -7935,7 +7840,7 @@ GenTreeCall* Compiler::impImportIndirectCall(CORINFO_SIG_INFO* sig, const DebugI /*****************************************************************************/ -void Compiler::impPopArgsForUnmanagedCall(GenTree* call, CORINFO_SIG_INFO* sig) +void Compiler::impPopArgsForUnmanagedCall(GenTreeCall* call, CORINFO_SIG_INFO* sig) { assert(call->gtFlags & GTF_CALL_UNMANAGED); @@ -7953,7 +7858,7 @@ void Compiler::impPopArgsForUnmanagedCall(GenTree* call, CORINFO_SIG_INFO* sig) // For "thiscall", the first argument goes in a register. Since its // order does not need to be changed, we do not need to spill it - if (call->AsCall()->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) + if (call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) { assert(argsToReverse); argsToReverse--; @@ -7996,23 +7901,22 @@ void Compiler::impPopArgsForUnmanagedCall(GenTree* call, CORINFO_SIG_INFO* sig) /* The argument list is now "clean" - no out-of-order side effects * Pop the argument list in reverse order */ - GenTreeCall::Use* args = impPopReverseCallArgs(sig->numArgs, sig, sig->numArgs - argsToReverse); - call->AsCall()->gtCallArgs = args; + impPopReverseCallArgs(sig->numArgs, sig, &call->gtArgs, sig->numArgs - argsToReverse); - if (call->AsCall()->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) + if (call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) { - GenTree* thisPtr = args->GetNode(); + GenTree* thisPtr = call->gtArgs.Args().begin()->GetNode(); impBashVarAddrsToI(thisPtr); assert(thisPtr->TypeGet() == TYP_I_IMPL || thisPtr->TypeGet() == TYP_BYREF); } - for (GenTreeCall::Use& argUse : GenTreeCall::UseList(args)) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree* arg = argUse.GetNode(); - call->gtFlags |= arg->gtFlags & GTF_GLOB_EFFECT; + GenTree* argNode = arg.GetNode(); + call->gtFlags |= argNode->gtFlags & GTF_GLOB_EFFECT; // We should not be passing gc typed args to an unmanaged call. - if (varTypeIsGC(arg->TypeGet())) + if (varTypeIsGC(argNode->TypeGet())) { // Tolerate byrefs by retyping to native int. // @@ -8020,9 +7924,9 @@ void Compiler::impPopArgsForUnmanagedCall(GenTree* call, CORINFO_SIG_INFO* sig) // for this arg at the call site (gc info says byref, // pinvoke sig says native int). // - if (arg->TypeGet() == TYP_BYREF) + if (argNode->TypeGet() == TYP_BYREF) { - arg->ChangeType(TYP_I_IMPL); + argNode->ChangeType(TYP_I_IMPL); } else { @@ -8065,7 +7969,7 @@ GenTree* Compiler::impInitClass(CORINFO_RESOLVED_TOKEN* pResolvedToken) if (runtimeLookup) { - node = gtNewHelperCallNode(CORINFO_HELP_INITCLASS, TYP_VOID, gtNewCallArgs(node)); + node = gtNewHelperCallNode(CORINFO_HELP_INITCLASS, TYP_VOID, node); } else { @@ -8257,7 +8161,7 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT break; } - op1 = gtNewHelperCallNode(pFieldInfo->helper, type, gtNewCallArgs(op1)); + op1 = gtNewHelperCallNode(pFieldInfo->helper, type, op1); op1 = gtNewOperNode(GT_ADD, type, op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); } break; @@ -8299,7 +8203,6 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT assert(kind.needsRuntimeLookup); GenTree* ctxTree = getRuntimeContextTree(kind.runtimeLookupKind); - GenTreeCall::Use* args = gtNewCallArgs(ctxTree); GenTreeFlags callFlags = GTF_EMPTY; @@ -8308,7 +8211,7 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT callFlags |= GTF_CALL_HOISTABLE; } var_types type = TYP_BYREF; - op1 = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, type, args); + op1 = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, type, ctxTree); op1->gtFlags |= callFlags; op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); @@ -8440,9 +8343,14 @@ void Compiler::impHandleAccessAllowedInternal(CorInfoIsAccessAllowedResult resul void Compiler::impInsertHelperCall(CORINFO_HELPER_DESC* helperInfo) { - // Construct the argument list - GenTreeCall::Use* args = nullptr; assert(helperInfo->helperNum != CORINFO_HELP_UNDEF); + + /* TODO-Review: + * Mark as CSE'able, and hoistable. Consider marking hoistable unless you're in the inlinee. + * Also, consider sticking this in the first basic block. + */ + GenTreeCall* callout = gtNewHelperCallNode(helperInfo->helperNum, TYP_VOID); + // Add the arguments for (unsigned i = helperInfo->numArgs; i > 0; --i) { const CORINFO_HELPER_ARG& helperArg = helperInfo->args[i - 1]; @@ -8471,14 +8379,9 @@ void Compiler::impInsertHelperCall(CORINFO_HELPER_DESC* helperInfo) default: NO_WAY("Illegal helper arg type"); } - args = gtPrependNewCallArg(currentArg, args); + callout->gtArgs.PushFront(this, currentArg); } - /* TODO-Review: - * Mark as CSE'able, and hoistable. Consider marking hoistable unless you're in the inlinee. - * Also, consider sticking this in the first basic block. - */ - GenTree* callout = gtNewHelperCallNode(helperInfo->helperNum, TYP_VOID, args); impAppendTree(callout, (unsigned)CHECK_SPILL_NONE, impCurStmtDI); } @@ -8707,7 +8610,6 @@ var_types Compiler::impImportCall(OPCODE opcode, unsigned clsFlags = 0; unsigned mflags = 0; GenTree* call = nullptr; - GenTreeCall::Use* args = nullptr; CORINFO_THIS_TRANSFORM constraintCallThisTransform = CORINFO_NO_THIS_TRANSFORM; CORINFO_CONTEXT_HANDLE exactContextHnd = nullptr; bool exactContextNeedsRuntimeLookup = false; @@ -8758,7 +8660,8 @@ var_types Compiler::impImportCall(OPCODE opcode, bool bIntrinsicImported = false; CORINFO_SIG_INFO calliSig; - GenTreeCall::Use* extraArg = nullptr; + GenTree* extraArg = nullptr; + WellKnownArg extraArgKind = WellKnownArg::None; /*------------------------------------------------------------------------- * First create the call node @@ -8979,7 +8882,7 @@ var_types Compiler::impImportCall(OPCODE opcode, assert((sig->callConv & CORINFO_CALLCONV_MASK) != CORINFO_CALLCONV_VARARG && (sig->callConv & CORINFO_CALLCONV_MASK) != CORINFO_CALLCONV_NATIVEVARARG); - call = gtNewIndCallNode(stubAddr, callRetTyp, nullptr); + call = gtNewIndCallNode(stubAddr, callRetTyp); call->gtFlags |= GTF_EXCEPT | (stubAddr->gtFlags & GTF_GLOB_EFFECT); call->gtFlags |= GTF_CALL_VIRT_STUB; @@ -8993,7 +8896,7 @@ var_types Compiler::impImportCall(OPCODE opcode, else { // The stub address is known at compile time - call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, nullptr, di); + call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, di); call->AsCall()->gtStubCallStubAddr = callInfo->stubLookup.constLookup.addr; call->gtFlags |= GTF_CALL_VIRT_STUB; assert(callInfo->stubLookup.constLookup.accessType != IAT_PPVALUE && @@ -9023,7 +8926,7 @@ var_types Compiler::impImportCall(OPCODE opcode, { assert(!(mflags & CORINFO_FLG_STATIC)); // can't call a static method assert(!(clsFlags & CORINFO_FLG_VALUECLASS)); - call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, nullptr, di); + call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, di); call->gtFlags |= GTF_CALL_VIRT_VTABLE; // Should we expand virtual call targets early for this method? @@ -9048,8 +8951,9 @@ var_types Compiler::impImportCall(OPCODE opcode, assert(!(clsFlags & CORINFO_FLG_VALUECLASS)); // OK, We've been told to call via LDVIRTFTN, so just // take the call now.... + call = gtNewIndCallNode(nullptr, callRetTyp, di); - GenTreeCall::Use* args = impPopCallArgs(sig->numArgs, sig); + impPopCallArgs(sig->numArgs, sig, &call->AsCall()->gtArgs); GenTree* thisPtr = impPopStack().val; thisPtr = impTransformThis(thisPtr, pConstrainedResolvedToken, callInfo->thisTransform); @@ -9063,7 +8967,9 @@ var_types Compiler::impImportCall(OPCODE opcode, GenTree* fptr = impImportLdvirtftn(thisPtr, pResolvedToken, callInfo); assert(fptr != nullptr); + call->AsCall()->gtArgs.PushFront(this, thisPtrCopy, WellKnownArg::ThisPointer); thisPtr = nullptr; // can't reuse it + thisPtrCopy = nullptr; // Now make an indirect call through the function pointer @@ -9071,10 +8977,7 @@ var_types Compiler::impImportCall(OPCODE opcode, impAssignTempGen(lclNum, fptr, (unsigned)CHECK_SPILL_ALL); fptr = gtNewLclvNode(lclNum, TYP_I_IMPL); - // Create the actual call node - - call = gtNewIndCallNode(fptr, callRetTyp, args, di); - call->AsCall()->gtCallThisArg = gtNewCallArgs(thisPtrCopy); + call->AsCall()->gtCallAddr = fptr; call->gtFlags |= GTF_EXCEPT | (fptr->gtFlags & GTF_GLOB_EFFECT); if ((sig->sigInst.methInstCount != 0) && IsTargetAbi(CORINFO_CORERT_ABI)) @@ -9100,7 +9003,7 @@ var_types Compiler::impImportCall(OPCODE opcode, case CORINFO_CALL: { // This is for a non-virtual, non-interface etc. call - call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, nullptr, di); + call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, di); // We remove the nullcheck for the GetType call intrinsic. // TODO-CQ: JIT64 does not introduce the null check for many more helper calls @@ -9145,7 +9048,7 @@ var_types Compiler::impImportCall(OPCODE opcode, impAssignTempGen(lclNum, fptr, (unsigned)CHECK_SPILL_ALL); fptr = gtNewLclvNode(lclNum, TYP_I_IMPL); - call = gtNewIndCallNode(fptr, callRetTyp, nullptr, di); + call = gtNewIndCallNode(fptr, callRetTyp, di); call->gtFlags |= GTF_EXCEPT | (fptr->gtFlags & GTF_GLOB_EFFECT); if (callInfo->nullInstanceCheck) { @@ -9234,7 +9137,7 @@ var_types Compiler::impImportCall(OPCODE opcode, /* Set the right flags */ call->gtFlags |= GTF_CALL_POP_ARGS; - call->AsCall()->gtCallMoreFlags |= GTF_CALL_M_VARARGS; + call->AsCall()->gtArgs.SetIsVarArgs(); /* Can't allow tailcall for varargs as it is caller-pop. The caller will be expecting to pop a certain number of arguments, but if we @@ -9321,7 +9224,7 @@ var_types Compiler::impImportCall(OPCODE opcode, checkForSmallType = true; - impPopArgsForUnmanagedCall(call, sig); + impPopArgsForUnmanagedCall(call->AsCall(), sig); goto DONE; } @@ -9393,10 +9296,9 @@ var_types Compiler::impImportCall(OPCODE opcode, varCookie = info.compCompHnd->getVarArgsHandle(sig, &pVarCookie); assert((!varCookie) != (!pVarCookie)); - GenTree* cookie = gtNewIconEmbHndNode(varCookie, pVarCookie, GTF_ICON_VARG_HDL, sig); - assert(extraArg == nullptr); - extraArg = gtNewCallArgs(cookie); + extraArg = gtNewIconEmbHndNode(varCookie, pVarCookie, GTF_ICON_VARG_HDL, sig); + extraArgKind = WellKnownArg::VarArgsCookie; } //------------------------------------------------------------------------- @@ -9519,7 +9421,8 @@ var_types Compiler::impImportCall(OPCODE opcode, } assert(extraArg == nullptr); - extraArg = gtNewCallArgs(instParam); + extraArg = instParam; + extraArgKind = WellKnownArg::InstParam; } if ((opcode == CEE_NEWOBJ) && ((clsFlags & CORINFO_FLG_DELEGATE) != 0)) @@ -9540,12 +9443,22 @@ var_types Compiler::impImportCall(OPCODE opcode, //------------------------------------------------------------------------- // The main group of arguments - args = impPopCallArgs(sig->numArgs, sig, extraArg); - call->AsCall()->gtCallArgs = args; + impPopCallArgs(sig->numArgs, sig, &call->AsCall()->gtArgs); + if (extraArg != nullptr) + { + if (Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) + { + call->AsCall()->gtArgs.PushFront(this, extraArg, extraArgKind); + } + else + { + call->AsCall()->gtArgs.PushBack(this, extraArg, extraArgKind); + } + } - for (GenTreeCall::Use& use : call->AsCall()->Args()) + for (CallArg& arg : call->AsCall()->gtArgs.Args()) { - call->gtFlags |= use.GetNode()->gtFlags & GTF_GLOB_EFFECT; + call->gtFlags |= arg.GetNode()->gtFlags & GTF_GLOB_EFFECT; } //------------------------------------------------------------------------- @@ -9572,7 +9485,7 @@ var_types Compiler::impImportCall(OPCODE opcode, // Store the "this" value in the call call->gtFlags |= obj->gtFlags & GTF_GLOB_EFFECT; - call->AsCall()->gtCallThisArg = gtNewCallArgs(obj); + call->AsCall()->gtArgs.PushFront(this, obj, WellKnownArg::ThisPointer); // Is this a virtual or interface call? if (call->AsCall()->IsVirtual()) @@ -9841,10 +9754,11 @@ var_types Compiler::impImportCall(OPCODE opcode, if (compIsForInlining() && opcode == CEE_CALLVIRT) { - GenTree* callObj = call->AsCall()->gtCallThisArg->GetNode(); + assert(call->AsCall()->gtArgs.HasThisPointer()); + GenTree* callObj = call->AsCall()->gtArgs.GetThisArg()->GetNode(); if ((call->AsCall()->IsVirtual() || (call->gtFlags & GTF_CALL_NULLCHECK)) && - impInlineIsGuaranteedThisDerefBeforeAnySideEffects(nullptr, call->AsCall()->gtCallArgs, callObj, + impInlineIsGuaranteedThisDerefBeforeAnySideEffects(nullptr, &call->AsCall()->gtArgs, callObj, impInlineInfo->inlArgInfo)) { impInlineInfo->thisDereferencedFirst = true; @@ -10419,7 +10333,7 @@ GenTree* Compiler::impFixupStructReturnType(GenTree* op, #endif // FEATURE_MULTIREG_RET && TARGET_ARM64 - if (!op->IsCall() || !op->AsCall()->TreatAsHasRetBufArg(this)) + if (!op->IsCall() || !op->AsCall()->TreatAsShouldGetRetBufArg(this)) { // Don't retype `struct` as a primitive type in `ret` instruction. return op; @@ -11650,7 +11564,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // op2->gtFlags |= GTF_DONT_CSE; - GenTreeCall* call = gtNewHelperCallNode(helper, TYP_REF, gtNewCallArgs(op2, op1)); + GenTreeCall* call = gtNewHelperCallNode(helper, TYP_REF, op2, op1); if (impIsCastHelperEligibleForClassProbe(call) && !impIsClassExact(pResolvedToken->hClass)) { ClassProfileCandidateInfo* pInfo = new (this, CMK_Inlining) ClassProfileCandidateInfo; @@ -11718,7 +11632,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // const CorInfoHelpFunc specialHelper = CORINFO_HELP_CHKCASTCLASS_SPECIAL; - condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, gtNewCallArgs(op2Var, gtClone(op1))); + condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, op2Var, gtClone(op1)); } else { @@ -13020,10 +12934,10 @@ void Compiler::impImportBlockCode(BasicBlock* block) } { - GenTreeCall::Use* args = gtNewCallArgs(op1); // Type - args = gtPrependNewCallArg(impPopStack().val, args); // index - args = gtPrependNewCallArg(impPopStack().val, args); // array - op1 = gtNewHelperCallNode(CORINFO_HELP_LDELEMA_REF, TYP_BYREF, args); + GenTree* type = op1; + GenTree* index = impPopStack().val; + GenTree* arr = impPopStack().val; + op1 = gtNewHelperCallNode(CORINFO_HELP_LDELEMA_REF, TYP_BYREF, arr, index, type); } impPushOnStack(op1, tiRetVal); @@ -13218,7 +13132,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) } // Else call a helper function to do the assignment - op1 = gtNewHelperCallNode(CORINFO_HELP_ARRADDR_ST, TYP_VOID, impPopCallArgs(3, nullptr)); + op1 = gtNewHelperCallNode(CORINFO_HELP_ARRADDR_ST, TYP_VOID); + impPopCallArgs(3, nullptr, &op1->AsCall()->gtArgs); goto SPILL_APPEND; case CEE_STELEM_I1: @@ -15794,7 +15709,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) if (opts.IsReadyToRun()) { op1 = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_NEWARR_1, TYP_REF, - gtNewCallArgs(op2)); + op2); usingReadyToRunHelper = (op1 != nullptr); if (!usingReadyToRunHelper) @@ -15818,13 +15733,11 @@ void Compiler::impImportBlockCode(BasicBlock* block) if (!usingReadyToRunHelper) #endif { - GenTreeCall::Use* args = gtNewCallArgs(op1, op2); - /* Create a call to 'new' */ // Note that this only works for shared generic code because the same helper is used for all // reference array types - op1 = gtNewHelperCallNode(info.compCompHnd->getNewArrHelper(resolvedToken.hClass), TYP_REF, args); + op1 = gtNewHelperCallNode(info.compCompHnd->getNewArrHelper(resolvedToken.hClass), TYP_REF, op1, op2); } op1->AsCall()->compileTimeHelperArgumentHandle = (CORINFO_GENERIC_HANDLE)resolvedToken.hClass; @@ -15988,7 +15901,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) { GenTreeCall* opLookup = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_ISINSTANCEOF, TYP_REF, - gtNewCallArgs(op1)); + op1); usingReadyToRunHelper = (opLookup != nullptr); op1 = (usingReadyToRunHelper ? opLookup : op1); @@ -16044,7 +15957,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) op1 = impNormStructVal(op1, impGetRefAnyClass(), (unsigned)CHECK_SPILL_ALL); // Call helper GETREFANY(classHandle, op1); - op1 = gtNewHelperCallNode(CORINFO_HELP_GETREFANY, TYP_BYREF, gtNewCallArgs(op2, op1)); + op1 = gtNewHelperCallNode(CORINFO_HELP_GETREFANY, TYP_BYREF, op2, op1); impPushOnStack(op1, tiRetVal); break; @@ -16085,10 +15998,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) // convert native TypeHandle to RuntimeTypeHandle { - GenTreeCall::Use* helperArgs = gtNewCallArgs(op1); - - op1 = gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_MAYBENULL, TYP_STRUCT, - helperArgs); + op1 = gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_MAYBENULL, TYP_STRUCT, op1); CORINFO_CLASS_HANDLE classHandle = impGetTypeHandleClass(); @@ -16132,9 +16042,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) helper = CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD; } - GenTreeCall::Use* helperArgs = gtNewCallArgs(op1); - - op1 = gtNewHelperCallNode(helper, TYP_STRUCT, helperArgs); + op1 = gtNewHelperCallNode(helper, TYP_STRUCT, op1); // The handle struct is returned in register and // it could be consumed both as `TYP_STRUCT` and `TYP_REF`. @@ -16272,7 +16180,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) { // compDonotInline() return; } - op1 = gtNewHelperCallNode(helper, TYP_VOID, gtNewCallArgs(op2, op1)); + op1 = gtNewHelperCallNode(helper, TYP_VOID, op2, op1); op1 = new (this, GT_COLON) GenTreeColon(TYP_VOID, gtNewNothingNode(), op1); op1 = gtNewQmarkNode(TYP_VOID, condBox, op1->AsColon()); @@ -16298,7 +16206,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) // Don't optimize, just call the helper and be done with it op1 = gtNewHelperCallNode(helper, (var_types)((helper == CORINFO_HELP_UNBOX) ? TYP_BYREF : TYP_STRUCT), - gtNewCallArgs(op2, op1)); + op2, op1); if (op1->gtType == TYP_STRUCT) { op1->AsCall()->gtRetClsHnd = resolvedToken.hClass; @@ -16513,7 +16421,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) { GenTreeCall* opLookup = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_CHKCAST, TYP_REF, - gtNewCallArgs(op1)); + op1); usingReadyToRunHelper = (opLookup != nullptr); op1 = (usingReadyToRunHelper ? opLookup : op1); @@ -16557,7 +16465,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) block->bbSetRunRarely(); // Pop the exception object and create the 'throw' helper call - op1 = gtNewHelperCallNode(CORINFO_HELP_THROW, TYP_VOID, gtNewCallArgs(impPopStack().val)); + op1 = gtNewHelperCallNode(CORINFO_HELP_THROW, TYP_VOID, impPopStack().val); // Fall through to clear out the eval stack. @@ -17164,8 +17072,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) assert(op2->gtType == TYP_REF); // confirm that the argument is a GC pointer (for debugging (GC stress)) - GenTreeCall::Use* args = gtNewCallArgs(op2); - op2 = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_REF, args); + op2 = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_REF, op2); if (verbose) { @@ -17384,7 +17291,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) if (retRegCount != 0) { - assert(!iciCall->HasRetBufArg()); + assert(!iciCall->ShouldGetRetBufArg()); assert(retRegCount >= 2); if (fgNeedReturnSpillTemp()) { @@ -17408,7 +17315,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) if (retRegCount != 0) { - assert(!iciCall->HasRetBufArg()); + assert(!iciCall->ShouldGetRetBufArg()); assert(retRegCount == MAX_RET_REG_COUNT); if (fgNeedReturnSpillTemp()) { @@ -17427,8 +17334,8 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) else #endif // defined(TARGET_ARM64) { - assert(iciCall->HasRetBufArg()); - GenTree* dest = gtCloneExpr(iciCall->gtCallArgs->GetNode()); + assert(iciCall->gtArgs.HasRetBuffer()); + GenTree* dest = gtCloneExpr(iciCall->gtArgs.GetRetBufferArg()->GetNode()); // spill temp only exists if there are multiple return points if (fgNeedReturnSpillTemp()) { @@ -18991,7 +18898,7 @@ void Compiler::impMakeDiscretionaryInlineObservations(InlineInfo* pInlineInfo, I // Check if the callee has the same 'this' as the root. if (pInlineInfo != nullptr) { - GenTree* thisArg = pInlineInfo->iciCall->AsCall()->gtCallThisArg->GetNode(); + GenTree* thisArg = pInlineInfo->iciCall->AsCall()->gtArgs.GetThisArg()->GetArgNode(); assert(thisArg); bool isSameThis = impIsThis(thisArg); inlineResult->NoteBool(InlineObservation::CALLSITE_IS_SAME_THIS, isSameThis); @@ -19013,10 +18920,15 @@ void Compiler::impMakeDiscretionaryInlineObservations(InlineInfo* pInlineInfo, I CORINFO_SIG_INFO sig = info.compMethodInfo->args; CORINFO_ARG_LIST_HANDLE sigArg = sig.args; - GenTreeCall::Use* argUse = pInlineInfo == nullptr ? nullptr : pInlineInfo->iciCall->AsCall()->gtCallArgs; + CallArg* argUse = pInlineInfo == nullptr ? nullptr : &*pInlineInfo->iciCall->AsCall()->gtArgs.Args().begin(); for (unsigned i = 0; i < info.compMethodInfo->args.numArgs; i++) { + if ((argUse != nullptr) && (argUse->GetWellKnownArg() == WellKnownArg::ThisPointer)) + { + argUse = argUse->GetNext(); + } + CORINFO_CLASS_HANDLE sigClass; CorInfoType corType = strip(info.compCompHnd->getArgType(&sig, sigArg, &sigClass)); GenTree* argNode = argUse == nullptr ? nullptr : argUse->GetNode()->gtSkipPutArgType(); @@ -19625,63 +19537,33 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) memset(inlArgInfo, 0, (MAX_INL_ARGS + 1) * sizeof(inlArgInfo[0])); - GenTreeCall::Use* thisArg = call->gtCallThisArg; - unsigned argCnt = 0; // Count of the arguments - - assert((methInfo->args.hasThis()) == (thisArg != nullptr)); - - if (thisArg != nullptr) + unsigned ilArgCnt = 0; + for (CallArg& arg : call->gtArgs.Args()) { - inlArgInfo[0].argIsThis = true; - impInlineRecordArgInfo(pInlineInfo, thisArg->GetNode(), argCnt, inlineResult); - - if (inlineResult->IsFailure()) + switch (arg.GetWellKnownArg()) { - return; - } - - /* Increment the argument count */ - argCnt++; - } - - /* Record some information about each of the arguments */ - bool hasTypeCtxtArg = (methInfo->args.callConv & CORINFO_CALLCONV_PARAMTYPE) != 0; - -#if USER_ARGS_COME_LAST - unsigned typeCtxtArg = (thisArg != nullptr) ? 1 : 0; -#else // USER_ARGS_COME_LAST - unsigned typeCtxtArg = methInfo->args.totalILArgs(); -#endif // USER_ARGS_COME_LAST - - for (GenTreeCall::Use& use : call->Args()) - { - if (hasRetBuffArg && (&use == call->gtCallArgs)) - { - continue; - } - - // Ignore the type context argument - if (hasTypeCtxtArg && (argCnt == typeCtxtArg)) - { - pInlineInfo->typeContextArg = typeCtxtArg; - typeCtxtArg = 0xFFFFFFFF; + case WellKnownArg::ThisPointer: + inlArgInfo[ilArgCnt].argIsThis = true; + break; + case WellKnownArg::RetBuffer: + case WellKnownArg::InstParam: + // These do not appear in the signature; do not include them continue; } - GenTree* actualArg = gtFoldExpr(use.GetNode()); - impInlineRecordArgInfo(pInlineInfo, actualArg, argCnt, inlineResult); + GenTree* actualArg = gtFoldExpr(arg.GetNode()); + impInlineRecordArgInfo(pInlineInfo, actualArg, ilArgCnt, inlineResult); if (inlineResult->IsFailure()) { return; } - /* Increment the argument count */ - argCnt++; + ilArgCnt++; } /* Make sure we got the arg number right */ - assert(argCnt == methInfo->args.totalILArgs()); + assert(ilArgCnt == methInfo->args.totalILArgs()); #ifdef FEATURE_SIMD bool foundSIMDType = pInlineInfo->hasSIMDTypeArgLocalOrReturn; @@ -19689,6 +19571,7 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) /* We have typeless opcodes, get type information from the signature */ + CallArg* thisArg = call->gtArgs.GetThisArg(); if (thisArg != nullptr) { lclVarInfo[0].lclVerTypeInfo = verMakeTypeInfo(pInlineInfo->inlineCandidateInfo->clsHandle); @@ -19739,7 +19622,7 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) argLst = methInfo->args.args; unsigned i; - for (i = (thisArg ? 1 : 0); i < argCnt; i++, argLst = info.compCompHnd->getArgNext(argLst)) + for (i = (thisArg ? 1 : 0); i < ilArgCnt; i++, argLst = info.compCompHnd->getArgNext(argLst)) { var_types sigType = (var_types)eeGetArgType(argLst, &methInfo->args); @@ -19884,15 +19767,15 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) bool isPinned; var_types type = (var_types)eeGetArgType(localsSig, &methInfo->locals, &isPinned); - lclVarInfo[i + argCnt].lclHasLdlocaOp = false; - lclVarInfo[i + argCnt].lclTypeInfo = type; + lclVarInfo[i + ilArgCnt].lclHasLdlocaOp = false; + lclVarInfo[i + ilArgCnt].lclTypeInfo = type; if (varTypeIsGC(type)) { if (isPinned) { JITDUMP("Inlinee local #%02u is pinned\n", i); - lclVarInfo[i + argCnt].lclIsPinned = true; + lclVarInfo[i + ilArgCnt].lclIsPinned = true; // Pinned locals may cause inlines to fail. inlineResult->Note(InlineObservation::CALLEE_HAS_PINNED_LOCALS); @@ -19909,13 +19792,13 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) JITDUMP("Ignoring pin on inlinee local #%02u -- not a GC type\n", i); } - lclVarInfo[i + argCnt].lclVerTypeInfo = verParseArgSigToTypeInfo(&methInfo->locals, localsSig); + lclVarInfo[i + ilArgCnt].lclVerTypeInfo = verParseArgSigToTypeInfo(&methInfo->locals, localsSig); // If this local is a struct type with GC fields, inform the inliner. It may choose to bail // out on the inline. if (type == TYP_STRUCT) { - CORINFO_CLASS_HANDLE lclHandle = lclVarInfo[i + argCnt].lclVerTypeInfo.GetClassHandle(); + CORINFO_CLASS_HANDLE lclHandle = lclVarInfo[i + ilArgCnt].lclVerTypeInfo.GetClassHandle(); DWORD typeFlags = info.compCompHnd->getClassAttribs(lclHandle); if ((typeFlags & CORINFO_FLG_CONTAINS_GC_PTR) != 0) { @@ -19942,13 +19825,13 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) localsSig = info.compCompHnd->getArgNext(localsSig); #ifdef FEATURE_SIMD - if ((!foundSIMDType || (type == TYP_STRUCT)) && isSIMDorHWSIMDClass(&(lclVarInfo[i + argCnt].lclVerTypeInfo))) + if ((!foundSIMDType || (type == TYP_STRUCT)) && isSIMDorHWSIMDClass(&(lclVarInfo[i + ilArgCnt].lclVerTypeInfo))) { foundSIMDType = true; if (type == TYP_STRUCT) { - var_types structType = impNormStructType(lclVarInfo[i + argCnt].lclVerTypeInfo.GetClassHandle()); - lclVarInfo[i + argCnt].lclTypeInfo = structType; + var_types structType = impNormStructType(lclVarInfo[i + ilArgCnt].lclVerTypeInfo.GetClassHandle()); + lclVarInfo[i + ilArgCnt].lclTypeInfo = structType; } } #endif // FEATURE_SIMD @@ -20321,7 +20204,7 @@ bool Compiler::impInlineIsThis(GenTree* tree, InlArgInfo* inlArgInfo) // additionalTree and additionalCallArgs. // bool Compiler::impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* additionalTree, - GenTreeCall::Use* additionalCallArgs, + CallArgs* additionalCallArgs, GenTree* dereferencedAddress, InlArgInfo* inlArgInfo) { @@ -20345,11 +20228,14 @@ bool Compiler::impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* return false; } - for (GenTreeCall::Use& use : GenTreeCall::UseList(additionalCallArgs)) + if (additionalCallArgs != nullptr) { - if (GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS(use.GetNode()->gtFlags)) + for (CallArg& arg : additionalCallArgs->Args()) { - return false; + if (GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS(arg.GetNode()->gtFlags)) + { + return false; + } } } @@ -20997,7 +20883,9 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, const bool isInterface = (baseClassAttribs & CORINFO_FLG_INTERFACE) != 0; // See what we know about the type of 'this' in the call. - GenTree* thisObj = call->gtCallThisArg->GetNode()->gtEffectiveVal(false); + assert(call->gtArgs.HasThisPointer()); + CallArg* thisArg = call->gtArgs.GetThisArg(); + GenTree* thisObj = thisArg->GetNode()->gtEffectiveVal(false); bool isExact = false; bool objIsNonNull = false; CORINFO_CLASS_HANDLE objClass = gtGetClassHandle(thisObj, &isExact, &objIsNonNull); @@ -21359,35 +21247,12 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // JITDUMP("Success! invoking unboxed entry point on local copy, and passing method table " "arg\n"); - call->gtCallThisArg = gtNewCallArgs(localCopyThis); + // TODO-CallArgs-REVIEW: Might discard commas otherwise? + assert(thisObj == thisArg->GetNode()); + thisArg->SetNode(localCopyThis); call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; - // Prepend for R2L arg passing or empty L2R passing - // Append for non-empty L2R - // - if ((Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) || (call->gtCallArgs == nullptr)) - { - // If there's a ret buf, the method table is the second arg. - // - if (call->HasRetBufArg()) - { - gtInsertNewCallArgAfter(methodTableArg, call->gtCallArgs); - } - else - { - call->gtCallArgs = gtPrependNewCallArg(methodTableArg, call->gtCallArgs); - } - } - else - { - GenTreeCall::Use* beforeArg = call->gtCallArgs; - while (beforeArg->GetNext() != nullptr) - { - beforeArg = beforeArg->GetNext(); - } - - beforeArg->SetNext(gtNewCallArgs(methodTableArg)); - } + call->gtArgs.InsertInstParam(this, methodTableArg); call->gtCallMethHnd = unboxedEntryMethod; derivedMethod = unboxedEntryMethod; @@ -21420,7 +21285,9 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, if (localCopyThis != nullptr) { JITDUMP("Success! invoking unboxed entry point on local copy\n"); - call->gtCallThisArg = gtNewCallArgs(localCopyThis); + assert(thisObj == thisArg->GetNode()); + // TODO-CallArgs-REVIEW: Might discard commas otherwise? + thisArg->SetNode(localCopyThis); call->gtCallMethHnd = unboxedEntryMethod; call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; derivedMethod = unboxedEntryMethod; @@ -21464,8 +21331,8 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, { // Get the method table from the boxed object. // - GenTree* const thisArg = call->gtCallThisArg->GetNode(); - GenTree* const clonedThisArg = gtClone(thisArg); + // TODO-CallArgs-REVIEW: Use thisObj here? Differs by gtEffectiveVal. + GenTree* const clonedThisArg = gtClone(thisArg->GetNode()); if (clonedThisArg == nullptr) { @@ -21481,9 +21348,10 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // Update the 'this' pointer to refer to the box payload // GenTree* const payloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); - GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg, payloadOffset); + GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); - call->gtCallThisArg = gtNewCallArgs(boxPayload); + assert(thisObj == thisArg->GetNode()); + thisArg->SetNode(boxPayload); call->gtCallMethHnd = unboxedEntryMethod; call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; @@ -21496,45 +21364,17 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, pDerivedResolvedToken = &dvInfo.resolvedTokenDevirtualizedUnboxedMethod; derivedMethodAttribs = unboxedMethodAttribs; - // Add the method table argument. - // - // Prepend for R2L arg passing or empty L2R passing - // Append for non-empty L2R - // - if ((Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) || (call->gtCallArgs == nullptr)) - { - // If there's a ret buf, the method table is the second arg. - // - if (call->HasRetBufArg()) - { - gtInsertNewCallArgAfter(methodTableArg, call->gtCallArgs); - } - else - { - call->gtCallArgs = gtPrependNewCallArg(methodTableArg, call->gtCallArgs); - } - } - else - { - GenTreeCall::Use* beforeArg = call->gtCallArgs; - while (beforeArg->GetNext() != nullptr) - { - beforeArg = beforeArg->GetNext(); - } - - beforeArg->SetNext(gtNewCallArgs(methodTableArg)); - } + call->gtArgs.InsertInstParam(this, methodTableArg); } } else { JITDUMP("revising call to invoke unboxed entry\n"); - GenTree* const thisArg = call->gtCallThisArg->GetNode(); GenTree* const payloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); - GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg, payloadOffset); + GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); - call->gtCallThisArg = gtNewCallArgs(boxPayload); + thisArg->SetNode(boxPayload); call->gtCallMethHnd = unboxedEntryMethod; call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; derivedMethod = unboxedEntryMethod; @@ -21688,15 +21528,12 @@ class SpillRetExprHelper void StoreRetExprResultsInArgs(GenTreeCall* call) { - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - comp->fgWalkTreePre(&use.NodeRef(), SpillRetExprVisitor, this); + comp->fgWalkTreePre(&arg.NodeRef(), SpillRetExprVisitor, this); } - if (call->gtCallThisArg != nullptr) - { - comp->fgWalkTreePre(&call->gtCallThisArg->NodeRef(), SpillRetExprVisitor, this); - } + // TODO-ARGS-REVIEW: Different order of this and rest of args } private: diff --git a/src/coreclr/jit/importer_vectorization.cpp b/src/coreclr/jit/importer_vectorization.cpp index 9752f3a69a76cc..9efa2602cdecd1 100644 --- a/src/coreclr/jit/importer_vectorization.cpp +++ b/src/coreclr/jit/importer_vectorization.cpp @@ -574,10 +574,11 @@ GenTreeStrCon* Compiler::impGetStrConFromSpan(GenTree* span) const NamedIntrinsic ni = lookupNamedIntrinsic(argCall->gtCallMethHnd); if ((ni == NI_System_MemoryExtensions_AsSpan) || (ni == NI_System_String_op_Implicit)) { - assert(argCall->gtCallArgs->GetNext() == nullptr); - if (argCall->gtCallArgs->GetNode()->OperIs(GT_CNS_STR)) + assert(argCall->gtArgs.CountArgs() == 1); + GenTree* arg = argCall->gtArgs.GetArgByIndex(0)->GetNode(); + if (arg->OperIs(GT_CNS_STR)) { - return argCall->gtCallArgs->GetNode()->AsStrCon(); + return arg->AsStrCon(); } } } diff --git a/src/coreclr/jit/indirectcalltransformer.cpp b/src/coreclr/jit/indirectcalltransformer.cpp index c0bc70a2850ade..868efc5455523c 100644 --- a/src/coreclr/jit/indirectcalltransformer.cpp +++ b/src/coreclr/jit/indirectcalltransformer.cpp @@ -436,58 +436,10 @@ class IndirectCallTransformer Statement* fatStmt = compiler->gtCloneStmt(stmt); GenTreeCall* fatCall = GetCall(fatStmt); fatCall->gtCallAddr = actualCallAddress; - AddHiddenArgument(fatCall, hiddenArgument); + fatCall->gtArgs.InsertInstParam(compiler, hiddenArgument); return fatStmt; } - //------------------------------------------------------------------------ - // AddHiddenArgument: add hidden argument to the call argument list. - // - // Arguments: - // fatCall - fat call node - // hiddenArgument - generic context hidden argument - // - void AddHiddenArgument(GenTreeCall* fatCall, GenTree* hiddenArgument) - { -#if USER_ARGS_COME_LAST - if (fatCall->HasRetBufArg()) - { - GenTreeCall::Use* retBufArg = fatCall->gtCallArgs; - compiler->gtInsertNewCallArgAfter(hiddenArgument, retBufArg); - } - else - { - fatCall->gtCallArgs = compiler->gtPrependNewCallArg(hiddenArgument, fatCall->gtCallArgs); - } -#else - if (fatCall->gtCallArgs == nullptr) - { - fatCall->gtCallArgs = compiler->gtNewCallArgs(hiddenArgument); - } - else - { - AddArgumentToTail(fatCall->gtCallArgs, hiddenArgument); - } -#endif - } - - //------------------------------------------------------------------------ - // AddArgumentToTail: add hidden argument to the tail of the call argument list. - // - // Arguments: - // argList - fat call node - // hiddenArgument - generic context hidden argument - // - void AddArgumentToTail(GenTreeCall::Use* argList, GenTree* hiddenArgument) - { - GenTreeCall::Use* iterator = argList; - while (iterator->GetNext() != nullptr) - { - iterator = iterator->GetNext(); - } - iterator->SetNext(compiler->gtNewCallArgs(hiddenArgument)); - } - private: const int FAT_POINTER_MASK = 0x2; @@ -587,7 +539,7 @@ class IndirectCallTransformer checkBlock->bbJumpKind = BBJ_COND; // Fetch method table from object arg to call. - GenTree* thisTree = compiler->gtCloneExpr(origCall->gtCallThisArg->GetNode()); + GenTree* thisTree = compiler->gtCloneExpr(origCall->gtArgs.GetThisArg()->GetNode()); // Create temp for this if the tree is costly. if (!thisTree->IsLocal()) @@ -602,7 +554,7 @@ class IndirectCallTransformer // Propagate the new this to the call. Must be a new expr as the call // will live on in the else block and thisTree is used below. - origCall->gtCallThisArg = compiler->gtNewCallArgs(compiler->gtNewLclvNode(thisTempNum, TYP_REF)); + origCall->gtArgs.GetThisArg()->SetNode(compiler->gtNewLclvNode(thisTempNum, TYP_REF)); } // Remember the current last statement. If we're doing a chained GDV, we'll clone/copy @@ -732,14 +684,14 @@ class IndirectCallTransformer // copy 'this' to temp with exact type. const unsigned thisTemp = compiler->lvaGrabTemp(false DEBUGARG("guarded devirt this exact temp")); - GenTree* clonedObj = compiler->gtCloneExpr(origCall->gtCallThisArg->GetNode()); + GenTree* clonedObj = compiler->gtCloneExpr(origCall->gtArgs.GetThisArg()->GetNode()); GenTree* assign = compiler->gtNewTempAssign(thisTemp, clonedObj); compiler->lvaSetClass(thisTemp, clsHnd, true); compiler->fgNewStmtAtEnd(thenBlock, assign); // Clone call. Note we must use the special candidate helper. GenTreeCall* call = compiler->gtCloneCandidateCall(origCall); - call->gtCallThisArg = compiler->gtNewCallArgs(compiler->gtNewLclvNode(thisTemp, TYP_REF)); + call->gtArgs.GetThisArg()->SetNode(compiler->gtNewLclvNode(thisTemp, TYP_REF)); call->SetIsGuarded(); JITDUMP("Direct call [%06u] in block " FMT_BB "\n", compiler->dspTreeID(call), thenBlock->bbNum); @@ -1147,23 +1099,21 @@ class IndirectCallTransformer // virtual void CreateCheck() override { - GenTreeCall::UseIterator argsIter = origCall->Args().begin(); - GenTree* nullCheck = argsIter.GetUse()->GetNode(); - ++argsIter; - GenTree* sizeCheck = argsIter.GetUse()->GetNode(); - ++argsIter; - origCall->gtCallArgs = argsIter.GetUse(); + CallArg* nullCheck = origCall->gtArgs.GetArgByIndex(0); + CallArg* sizeCheck = origCall->gtArgs.GetArgByIndex(1); + origCall->gtArgs.Remove(nullCheck); + origCall->gtArgs.Remove(sizeCheck); // The first argument is the handle now. checkBlock = CreateAndInsertBasicBlock(BBJ_COND, currBlock); - assert(sizeCheck->OperIs(GT_LE)); - GenTree* sizeJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, sizeCheck); + assert(sizeCheck->GetNode()->OperIs(GT_LE)); + GenTree* sizeJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, sizeCheck->GetNode()); Statement* sizeJmpStmt = compiler->fgNewStmtFromTree(sizeJmpTree, stmt->GetDebugInfo()); compiler->fgInsertStmtAtEnd(checkBlock, sizeJmpStmt); checkBlock2 = CreateAndInsertBasicBlock(BBJ_COND, checkBlock); - assert(nullCheck->OperIs(GT_EQ)); - GenTree* nullJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, nullCheck); + assert(nullCheck->GetNode()->OperIs(GT_EQ)); + GenTree* nullJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, nullCheck->GetNode()); Statement* nullJmpStmt = compiler->fgNewStmtFromTree(nullJmpTree, stmt->GetDebugInfo()); compiler->fgInsertStmtAtEnd(checkBlock2, nullJmpStmt); } @@ -1176,13 +1126,11 @@ class IndirectCallTransformer { thenBlock = CreateAndInsertBasicBlock(BBJ_ALWAYS, checkBlock2); - GenTreeCall::UseIterator argsIter = origCall->Args().begin(); - GenTree* resultHandle = argsIter.GetUse()->GetNode(); - ++argsIter; + CallArg* resultHandle = origCall->gtArgs.GetArgByIndex(0); // The first argument is the real first argument for the call now. - origCall->gtCallArgs = argsIter.GetUse(); + origCall->gtArgs.Remove(resultHandle); - GenTree* asg = compiler->gtNewTempAssign(resultLclNum, resultHandle); + GenTree* asg = compiler->gtNewTempAssign(resultLclNum, resultHandle->GetNode()); Statement* asgStmt = compiler->gtNewStmt(asg, stmt->GetDebugInfo()); compiler->fgInsertStmtAtEnd(thenBlock, asgStmt); } diff --git a/src/coreclr/jit/inline.h b/src/coreclr/jit/inline.h index 7182bdf78fa92a..f505657553b5cd 100644 --- a/src/coreclr/jit/inline.h +++ b/src/coreclr/jit/inline.h @@ -668,7 +668,6 @@ struct InlineInfo } bool thisDereferencedFirst; - unsigned typeContextArg; #ifdef FEATURE_SIMD bool hasSIMDTypeArgLocalOrReturn; diff --git a/src/coreclr/jit/inlinepolicy.cpp b/src/coreclr/jit/inlinepolicy.cpp index dafb34f8781ed2..f08edfc6a5cd0f 100644 --- a/src/coreclr/jit/inlinepolicy.cpp +++ b/src/coreclr/jit/inlinepolicy.cpp @@ -1508,7 +1508,7 @@ double ExtendedDefaultPolicy::DetermineMultiplier() // TODO: handle 'if (SomeMethod(constArg))' patterns in fgFindJumpTargets // The previous version of inliner optimistically assumed this is "has const arg that feeds a conditional" multiplier += 3.0; - JITDUMP("\nCallsite passes a consant. Multiplier increased to %g.", multiplier); + JITDUMP("\nCallsite passes a constant. Multiplier increased to %g.", multiplier); } if ((m_FoldableBox > 0) && m_NonGenericCallsGeneric) diff --git a/src/coreclr/jit/lclmorph.cpp b/src/coreclr/jit/lclmorph.cpp index 6cd7d53e14e95d..648e9a8f8af048 100644 --- a/src/coreclr/jit/lclmorph.cpp +++ b/src/coreclr/jit/lclmorph.cpp @@ -683,8 +683,8 @@ class LocalAddressVisitor final : public GenTreeVisitor // beyond "this" instance. And calling struct member methods is common enough that attempting to // mark the entire struct as address exposed results in CQ regressions. GenTreeCall* callTree = user->IsCall() ? user->AsCall() : nullptr; - bool isThisArg = (callTree != nullptr) && (callTree->gtCallThisArg != nullptr) && - (val.Node() == callTree->gtCallThisArg->GetNode()); + bool isThisArg = (callTree != nullptr) && callTree->gtArgs.HasThisPointer() && + (val.Node() == callTree->gtArgs.GetThisArg()->GetNode()); bool exposeParentLcl = varDsc->lvIsStructField && !isThisArg; bool hasHiddenStructArg = false; @@ -692,15 +692,13 @@ class LocalAddressVisitor final : public GenTreeVisitor { if (varTypeIsStruct(varDsc) && varDsc->lvIsTemp) { - // We rely here on the fact that the return buffer, if present, is always first in the arg list. - if ((callTree != nullptr) && callTree->HasRetBufArg() && - (val.Node() == callTree->gtCallArgs->GetNode())) + if ((callTree != nullptr) && callTree->gtArgs.HasRetBuffer() && (val.Node() == callTree->gtArgs.GetRetBufferArg()->GetNode())) { assert(!exposeParentLcl); m_compiler->lvaSetHiddenBufferStructArg(val.LclNum()); hasHiddenStructArg = true; - callTree->SetLclRetBufArg(callTree->gtCallArgs); + callTree->gtCallMoreFlags |= GTF_CALL_M_RETBUFFARG_LCLOPT; } } } diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 64f4dd690b8ed0..ea3b0684c39d0a 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -416,7 +416,6 @@ void Compiler::lvaInitArgs(InitVarDscInfo* varDscInfo) // Now walk the function signature for the explicit user arguments //------------------------------------------------------------------------- lvaInitUserArgs(varDscInfo, numUserArgsToSkip, numUserArgs); - #if !USER_ARGS_COME_LAST //@GENERICS: final instantiation-info argument for shared generic methods // and shared generic struct instance methods diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index c9ab4fa81a63a8..6f64447689ea18 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1070,15 +1070,15 @@ void Lowering::ReplaceArgWithPutArgOrBitcast(GenTree** argSlot, GenTree* putArgO // layout object, so the codegen of the GT_PUTARG_STK could use this for optimizing copying to the stack by value. // (using block copy primitives for non GC pointers and a single TARGET_POINTER_SIZE copy with recording GC info.) // -GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* info, var_types type) +GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, CallArg* callArg, var_types type) { assert(call != nullptr); assert(arg != nullptr); - assert(info != nullptr); + assert(callArg != nullptr); GenTree* putArg = nullptr; - bool isOnStack = (info->GetRegNum() == REG_STK); + bool isOnStack = (callArg->AbiInfo.GetRegNum() == REG_STK); #ifdef TARGET_ARMARCH // Mark contained when we pass struct @@ -1095,7 +1095,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf #if FEATURE_ARG_SPLIT // Struct can be split into register(s) and stack on ARM - if (compFeatureArgSplit() && info->IsSplit()) + if (compFeatureArgSplit() && callArg->AbiInfo.IsSplit()) { assert(arg->OperGet() == GT_OBJ || arg->OperGet() == GT_FIELD_LIST); // TODO: Need to check correctness for FastTailCall @@ -1106,28 +1106,28 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf #endif // TARGET_ARM } - const unsigned slotNumber = info->GetByteOffset() / TARGET_POINTER_SIZE; - DEBUG_ARG_SLOTS_ASSERT(slotNumber == info->slotNum); + const unsigned slotNumber = callArg->AbiInfo.ByteOffset / TARGET_POINTER_SIZE; + DEBUG_ARG_SLOTS_ASSERT(slotNumber == callArg->AbiInfo.SlotNum); const bool putInIncomingArgArea = call->IsFastTailCall(); putArg = new (comp, GT_PUTARG_SPLIT) - GenTreePutArgSplit(arg, info->GetByteOffset(), + GenTreePutArgSplit(arg, callArg->AbiInfo.ByteOffset, #if defined(DEBUG_ARG_SLOTS) && defined(FEATURE_PUT_STRUCT_ARG_STK) - info->GetStackByteSize(), slotNumber, info->GetStackSlotsNumber(), + callArg->AbiInfo.GetStackByteSize(), slotNumber, callArg->AbiInfo.GetStackSlotsNumber(), #elif defined(DEBUG_ARG_SLOTS) && !defined(FEATURE_PUT_STRUCT_ARG_STK) slotNumber, #elif !defined(DEBUG_ARG_SLOTS) && defined(FEATURE_PUT_STRUCT_ARG_STK) - info->GetStackByteSize(), + callArg->AbiInfo.GetStackByteSize(), #endif - info->numRegs, call, putInIncomingArgArea); + callArg->AbiInfo.NumRegs, call, putInIncomingArgArea); // If struct argument is morphed to GT_FIELD_LIST node(s), // we can know GC info by type of each GT_FIELD_LIST node. // So we skip setting GC Pointer info. // GenTreePutArgSplit* argSplit = putArg->AsPutArgSplit(); - for (unsigned regIndex = 0; regIndex < info->numRegs; regIndex++) + for (unsigned regIndex = 0; regIndex < callArg->AbiInfo.NumRegs; regIndex++) { - argSplit->SetRegNumByIdx(info->GetRegNum(regIndex), regIndex); + argSplit->SetRegNumByIdx(callArg->AbiInfo.GetRegNum(regIndex), regIndex); } if (arg->OperGet() == GT_OBJ) @@ -1135,7 +1135,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf ClassLayout* layout = arg->AsObj()->GetLayout(); // Set type of registers - for (unsigned index = 0; index < info->numRegs; index++) + for (unsigned index = 0; index < callArg->AbiInfo.NumRegs; index++) { argSplit->m_regType[index] = layout->GetGCPtrType(index); } @@ -1145,7 +1145,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf unsigned regIndex = 0; for (GenTreeFieldList::Use& use : arg->AsFieldList()->Uses()) { - if (regIndex >= info->numRegs) + if (regIndex >= callArg->AbiInfo.NumRegs) { break; } @@ -1169,12 +1169,12 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf if (!isOnStack) { #if FEATURE_MULTIREG_ARGS - if ((info->numRegs > 1) && (arg->OperGet() == GT_FIELD_LIST)) + if ((callArg->AbiInfo.NumRegs > 1) && (arg->OperGet() == GT_FIELD_LIST)) { unsigned int regIndex = 0; for (GenTreeFieldList::Use& use : arg->AsFieldList()->Uses()) { - regNumber argReg = info->GetRegNum(regIndex); + regNumber argReg = callArg->AbiInfo.GetRegNum(regIndex); GenTree* curOp = use.GetNode(); var_types curTyp = curOp->TypeGet(); @@ -1193,7 +1193,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf else #endif // FEATURE_MULTIREG_ARGS { - putArg = comp->gtNewPutArgReg(type, arg, info->GetRegNum()); + putArg = comp->gtNewPutArgReg(type, arg, callArg->AbiInfo.GetRegNum()); } } else @@ -1208,7 +1208,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf // a result. So the type of its operand must be the correct type to push on the stack. // For a FIELD_LIST, this will be the type of the field (not the type of the arg), // but otherwise it is generally the type of the operand. - info->checkIsStruct(); + callArg->CheckIsStruct(); #endif if ((arg->OperGet() != GT_FIELD_LIST)) @@ -1217,15 +1217,15 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf if (type == TYP_SIMD12) { #if !defined(TARGET_64BIT) - assert(info->GetByteSize() == 12); + assert(callArg->AbiInfo.ByteSize == 12); #else // TARGET_64BIT if (compMacOsArm64Abi()) { - assert(info->GetByteSize() == 12); + assert(callArg->AbiInfo.ByteSize == 12); } else { - assert(info->GetByteSize() == 16); + assert(callArg->AbiInfo.ByteSize == 16); } #endif // TARGET_64BIT } @@ -1235,17 +1235,17 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf assert(genActualType(arg->TypeGet()) == type); } } - const unsigned slotNumber = info->GetByteOffset() / TARGET_POINTER_SIZE; + const unsigned slotNumber = callArg->AbiInfo.ByteOffset / TARGET_POINTER_SIZE; const bool putInIncomingArgArea = call->IsFastTailCall(); putArg = new (comp, GT_PUTARG_STK) - GenTreePutArgStk(GT_PUTARG_STK, TYP_VOID, arg, info->GetByteOffset(), + GenTreePutArgStk(GT_PUTARG_STK, TYP_VOID, arg, callArg->AbiInfo.ByteOffset, #if defined(DEBUG_ARG_SLOTS) && defined(FEATURE_PUT_STRUCT_ARG_STK) - info->GetStackByteSize(), slotNumber, info->GetStackSlotsNumber(), + callArg->AbiInfo.GetStackByteSize(), slotNumber, callArg->AbiInfo.GetStackSlotsNumber(), #elif defined(DEBUG_ARG_SLOTS) && !defined(FEATURE_PUT_STRUCT_ARG_STK) slotNumber, #elif !defined(DEBUG_ARG_SLOTS) && defined(FEATURE_PUT_STRUCT_ARG_STK) - info->GetStackByteSize(), + callArg->AbiInfo.GetStackByteSize(), #endif call, putInIncomingArgArea); @@ -1257,7 +1257,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf // to be done (only for reference slots), so gcinfo is emitted. // For non-reference slots faster/smaller size instructions are used - // pair copying using XMM registers or rep mov instructions. - if (info->isStruct) + if (callArg->AbiInfo.IsStruct) { // We use GT_OBJ only for non-lclVar, non-SIMD, non-FIELD_LIST struct arguments. if (arg->OperIsLocal()) @@ -1309,10 +1309,10 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf else if (!arg->OperIs(GT_FIELD_LIST)) { #ifdef TARGET_ARM - assert((info->GetStackSlotsNumber() == 1) || - ((arg->TypeGet() == TYP_DOUBLE) && (info->GetStackSlotsNumber() == 2))); + assert((callArg->AbiInfo.GetStackSlotsNumber() == 1) || + ((arg->TypeGet() == TYP_DOUBLE) && (callArg->AbiInfo.GetStackSlotsNumber() == 2))); #else - assert(varTypeIsSIMD(arg) || (info->GetStackSlotsNumber() == 1)); + assert(varTypeIsSIMD(arg) || (callArg->AbiInfo.GetStackSlotsNumber() == 1)); #endif } } @@ -1338,16 +1338,18 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* inf // convention. // // Arguments: -// call - The call node -// ppArg - Pointer to the call argument pointer. We might replace the call argument by -// changing *ppArg. +// call - The call node +// callArg - Call argument +// late - Whether it is the late arg that is being lowered. // // Return Value: // None. // -void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) +void Lowering::LowerArg(GenTreeCall* call, CallArg* callArg, bool late) { + GenTree** ppArg = late ? &callArg->LateNodeRef() : &callArg->NodeRef(); GenTree* arg = *ppArg; + assert(arg != nullptr); JITDUMP("lowering arg : "); DISPNODE(arg); @@ -1367,8 +1369,6 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) return; } - fgArgTabEntry* info = comp->gtArgEntryByNode(call, arg); - assert(info->GetNode() == arg); var_types type = arg->TypeGet(); if (varTypeIsSmall(type)) @@ -1409,13 +1409,12 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) } #elif defined(TARGET_AMD64) // TYP_SIMD8 parameters that are passed as longs - if (type == TYP_SIMD8 && genIsValidIntReg(info->GetRegNum())) + if (type == TYP_SIMD8 && genIsValidIntReg(callArg->AbiInfo.GetRegNum())) { GenTree* bitcast = comp->gtNewBitCastNode(TYP_LONG, arg); BlockRange().InsertAfter(arg, bitcast); *ppArg = arg = bitcast; - assert(info->GetNode() == arg); type = TYP_LONG; } #endif // defined(TARGET_X86) @@ -1431,11 +1430,11 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) GenTreeFieldList* fieldList = new (comp, GT_FIELD_LIST) GenTreeFieldList(); fieldList->AddFieldLIR(comp, arg->AsOp()->gtGetOp1(), 0, TYP_INT); fieldList->AddFieldLIR(comp, arg->AsOp()->gtGetOp2(), 4, TYP_INT); - GenTree* newArg = NewPutArg(call, fieldList, info, type); + GenTree* newArg = NewPutArg(call, fieldList, callArg, type); - if (info->GetRegNum() != REG_STK) + if (callArg->AbiInfo.GetRegNum() != REG_STK) { - assert(info->numRegs == 2); + assert(callArg->AbiInfo.NumRegs == 2); // In the register argument case, NewPutArg replaces the original field list args with new // GT_PUTARG_REG nodes, inserts them in linear order and returns the field list. So the // only thing left to do is to insert the field list itself in linear order. @@ -1447,14 +1446,12 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) // For longs, we will replace the GT_LONG with a GT_FIELD_LIST, and put that under a PUTARG_STK. // Although the hi argument needs to be pushed first, that will be handled by the general case, // in which the fields will be reversed. - assert(info->numSlots == 2); + assert(callArg->AbiInfo.NumSlots == 2); newArg->SetRegNum(REG_STK); BlockRange().InsertBefore(arg, fieldList, newArg); } *ppArg = newArg; - assert(info->GetNode() == newArg); - BlockRange().Remove(arg); } else @@ -1466,7 +1463,7 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) { // For vararg call or on armel, reg args should be all integer. // Insert copies as needed to move float value to integer register. - GenTree* newNode = LowerFloatArg(ppArg, info); + GenTree* newNode = LowerFloatArg(ppArg, callArg); if (newNode != nullptr) { type = newNode->TypeGet(); @@ -1474,7 +1471,7 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) } #endif // TARGET_ARMARCH - GenTree* putArg = NewPutArg(call, arg, info, type); + GenTree* putArg = NewPutArg(call, arg, callArg, type); // In the case of register passable struct (in one or two registers) // the NewPutArg returns a new node (GT_PUTARG_REG or a GT_FIELD_LIST with two GT_PUTARG_REGs.) @@ -1492,7 +1489,7 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) // // Arguments: // arg - The arg node -// info - call argument info +// callArg - call argument info // // Return Value: // Return nullptr, if no transformation was done; @@ -1503,19 +1500,19 @@ void Lowering::LowerArg(GenTreeCall* call, GenTree** ppArg) // This must handle scalar float arguments as well as GT_FIELD_LISTs // with floating point fields. // -GenTree* Lowering::LowerFloatArg(GenTree** pArg, fgArgTabEntry* info) +GenTree* Lowering::LowerFloatArg(GenTree** pArg, CallArg* callArg) { GenTree* arg = *pArg; - if (info->GetRegNum() != REG_STK) + if (callArg->AbiInfo.GetRegNum() != REG_STK) { if (arg->OperIs(GT_FIELD_LIST)) { // Transform fields that are passed as registers in place. - regNumber currRegNumber = info->GetRegNum(); + regNumber currRegNumber = callArg->AbiInfo.GetRegNum(); unsigned regIndex = 0; for (GenTreeFieldList::Use& use : arg->AsFieldList()->Uses()) { - if (regIndex >= info->numRegs) + if (regIndex >= callArg->AbiInfo.NumRegs) { break; } @@ -1544,7 +1541,7 @@ GenTree* Lowering::LowerFloatArg(GenTree** pArg, fgArgTabEntry* info) } else if (varTypeIsFloating(arg)) { - GenTree* intNode = LowerFloatArgReg(arg, info->GetRegNum()); + GenTree* intNode = LowerFloatArgReg(arg, callArg->AbiInfo.GetRegNum()); assert(intNode != nullptr); ReplaceArgWithPutArgOrBitcast(pArg, intNode); return *pArg; @@ -1589,22 +1586,16 @@ GenTree* Lowering::LowerFloatArgReg(GenTree* arg, regNumber regNum) // do lowering steps for each arg of a call void Lowering::LowerArgsForCall(GenTreeCall* call) { - JITDUMP("objp:\n======\n"); - if (call->gtCallThisArg != nullptr) - { - LowerArg(call, &call->gtCallThisArg->NodeRef()); - } - - JITDUMP("\nargs:\n======\n"); - for (GenTreeCall::Use& use : call->Args()) + JITDUMP("args:\n======\n"); + for (CallArg& arg : call->gtArgs.Args()) { - LowerArg(call, &use.NodeRef()); + LowerArg(call, &arg, false); } JITDUMP("\nlate:\n======\n"); - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - LowerArg(call, &use.NodeRef()); + LowerArg(call, arg.GetArg(), true); } } @@ -1810,26 +1801,26 @@ void Lowering::InsertProfTailCallHook(GenTreeCall* call, GenTree* insertionPoint if (insertionPoint == nullptr) { - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - assert(!use.GetNode()->OperIs(GT_PUTARG_REG)); // We don't expect to see these in gtCallArgs + assert(!arg.GetNode()->OperIs(GT_PUTARG_REG)); // We don't expect to see these in gtCallArgs - if (use.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetNode()->OperIs(GT_PUTARG_STK)) { // found it - insertionPoint = use.GetNode(); + insertionPoint = arg.GetNode(); break; } } if (insertionPoint == nullptr) { - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - if (use.GetNode()->OperIs(GT_PUTARG_REG, GT_PUTARG_STK)) + if (arg.GetNode()->OperIs(GT_PUTARG_REG, GT_PUTARG_STK)) { // found it - insertionPoint = use.GetNode(); + insertionPoint = arg.GetNode(); break; } } @@ -1919,19 +1910,19 @@ void Lowering::LowerFastTailCall(GenTreeCall* call) // call could over-write the stack arg that is setup earlier. ArrayStack putargs(comp->getAllocator(CMK_ArrayStack)); - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - if (use.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetNode()->OperIs(GT_PUTARG_STK)) { - putargs.Push(use.GetNode()); + putargs.Push(arg.GetNode()); } } - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - if (use.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetNode()->OperIs(GT_PUTARG_STK)) { - putargs.Push(use.GetNode()); + putargs.Push(arg.GetNode()); } } @@ -2224,19 +2215,16 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar // We need to figure out the size of the outgoing stack arguments, not including the special args. // The number of 4-byte words is passed to the helper for the incoming and outgoing argument sizes. // This number is exactly the next slot number in the call's argument info struct. - unsigned nNewStkArgsBytes = call->fgArgInfo->GetNextSlotByteOffset(); + unsigned nNewStkArgsBytes = call->gtArgs.OutgoingArgsStackSize(); const int wordSize = 4; unsigned nNewStkArgsWords = nNewStkArgsBytes / wordSize; - DEBUG_ARG_SLOTS_ASSERT(call->fgArgInfo->GetNextSlotNum() == nNewStkArgsWords); assert(nNewStkArgsWords >= 4); // There must be at least the four special stack args. nNewStkArgsWords -= 4; - unsigned numArgs = call->fgArgInfo->ArgCount(); - - fgArgTabEntry* argEntry; + unsigned numArgs = call->gtArgs.CountArgs(); // arg 0 == callTarget. - argEntry = comp->gtArgEntryByArgNum(call, numArgs - 1); + CallArg* argEntry = call->gtArgs.GetArgByIndex(numArgs - 1); assert(argEntry != nullptr); GenTree* arg0 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); @@ -2251,7 +2239,7 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar argEntry->GetNode()->AsPutArgStk()->gtOp1 = callTarget; // arg 1 == flags - argEntry = comp->gtArgEntryByArgNum(call, numArgs - 2); + argEntry = call->gtArgs.GetArgByIndex(numArgs - 2); assert(argEntry != nullptr); GenTree* arg1 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); assert(arg1->gtOper == GT_CNS_INT); @@ -2261,7 +2249,7 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar arg1->AsIntCon()->gtIconVal = tailCallHelperFlags; // arg 2 == numberOfNewStackArgsWords - argEntry = comp->gtArgEntryByArgNum(call, numArgs - 3); + argEntry = call->gtArgs.GetArgByIndex(numArgs - 3); assert(argEntry != nullptr); GenTree* arg2 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); assert(arg2->gtOper == GT_CNS_INT); @@ -2270,7 +2258,7 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar #ifdef DEBUG // arg 3 == numberOfOldStackArgsWords - argEntry = comp->gtArgEntryByArgNum(call, numArgs - 4); + argEntry = call->gtArgs.GetArgByIndex(numArgs - 4); assert(argEntry != nullptr); GenTree* arg3 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); assert(arg3->gtOper == GT_CNS_INT); @@ -2367,11 +2355,11 @@ void Lowering::LowerCFGCall(GenTreeCall* call) assert(gotUse); useOfTar.ReplaceWith(regNode); - GenTree* targetPlaceholder = comp->gtNewZeroConNode(callTarget->TypeGet()); + GenTreeCall* validate = comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID); // Add the call to the validator. Use a placeholder for the target while we // morph, sequence and lower, to avoid redoing that for the actual target. - GenTreeCall::Use* args = comp->gtNewCallArgs(targetPlaceholder); - GenTreeCall* validate = comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID, args); + GenTree* targetPlaceholder = comp->gtNewZeroConNode(callTarget->TypeGet()); + CallArg* targetArg = validate->gtArgs.PushFront(comp, targetPlaceholder, WellKnownArg::ValidateIndirectCallTarget); comp->fgMorphTree(validate); @@ -2394,24 +2382,22 @@ void Lowering::LowerCFGCall(GenTreeCall* call) LowerNode(regNode); // Finally move all GT_PUTARG_* nodes - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree* node = use.GetNode(); - if (!node->IsValue()) + GenTree* node = arg.GetNode(); + // Non-value nodes in early args are setup nodes for late args. + if (node->IsValue()) { - // Non-value nodes in early args are setup nodes for late args. - continue; + assert(node->OperIsPutArg() || node->OperIsFieldList()); + MoveCFGCallArg(call, node); } - assert(node->OperIsPutArg() || node->OperIsFieldList()); - MoveCFGCallArg(call, node); - } - - for (GenTreeCall::Use& use : call->LateArgs()) - { - GenTree* node = use.GetNode(); - assert(node->OperIsPutArg() || node->OperIsFieldList()); - MoveCFGCallArg(call, node); + node = arg.GetLateNode(); + if (node != nullptr) + { + assert(node->OperIsPutArg() || node->OperIsFieldList()); + MoveCFGCallArg(call, node); + } } break; } @@ -2420,59 +2406,26 @@ void Lowering::LowerCFGCall(GenTreeCall* call) #ifdef REG_DISPATCH_INDIRECT_CALL_ADDR // Now insert the call target as an extra argument. // - // First append the early placeholder arg - GenTreeCall::Use** earlySlot = &call->gtCallArgs; - unsigned int index = call->gtCallThisArg != nullptr ? 1 : 0; - while (*earlySlot != nullptr) - { - earlySlot = &(*earlySlot)->NextRef(); - index++; - } - - assert(index == call->fgArgInfo->ArgCount()); GenTree* placeHolder = comp->gtNewArgPlaceHolderNode(callTarget->TypeGet(), NO_CLASS_HANDLE); + CallArg* targetArg = call->gtArgs.PushBack(comp, placeHolder, WellKnownArg::DispatchIndirectCallTarget); placeHolder->gtFlags |= GTF_LATE_ARG; - *earlySlot = comp->gtNewCallArgs(placeHolder); - - // Append the late actual arg - GenTreeCall::Use** lateSlot = &call->gtCallLateArgs; - unsigned int lateIndex = 0; - while (*lateSlot != nullptr) - { - lateSlot = &(*lateSlot)->NextRef(); - lateIndex++; - } + targetArg->SetLateNode(callTarget); - *lateSlot = comp->gtNewCallArgs(callTarget); - - // Add an entry into the arg info - regNumber regNum = REG_DISPATCH_INDIRECT_CALL_ADDR; - unsigned numRegs = 1; - unsigned byteSize = TARGET_POINTER_SIZE; - unsigned byteAlignment = TARGET_POINTER_SIZE; - bool isStruct = false; - bool isFloatHfa = false; - bool isVararg = false; - - fgArgTabEntry* entry = - call->fgArgInfo->AddRegArg(index, placeHolder, *earlySlot, regNum, numRegs, byteSize, byteAlignment, - isStruct, isFloatHfa, - isVararg UNIX_AMD64_ABI_ONLY_ARG(REG_STK) UNIX_AMD64_ABI_ONLY_ARG(0) - UNIX_AMD64_ABI_ONLY_ARG(0) UNIX_AMD64_ABI_ONLY_ARG(nullptr)); - - entry->lateUse = *lateSlot; - entry->SetLateArgInx(lateIndex); + // Set up ABI information for this call. + targetArg->AbiInfo.SetRegNum(0, REG_DISPATCH_INDIRECT_CALL_ADDR); + targetArg->AbiInfo.NumRegs = 1; + targetArg->AbiInfo.SetByteSize(TARGET_POINTER_SIZE, TARGET_POINTER_SIZE, false, false); // Lower the newly added args now that call is updated - LowerArg(call, &(*earlySlot)->NodeRef()); - LowerArg(call, &(*lateSlot)->NodeRef()); + LowerArg(call, targetArg, false /* late */); + LowerArg(call, targetArg, true /* late */); // Finally update the call to be a helper call - call->gtCallType = CT_HELPER; - call->gtCallMethHnd = comp->eeFindHelper(CORINFO_HELP_DISPATCH_INDIRECT_CALL); + call->gtCallType = CT_HELPER; + call->gtCallMethHnd = Compiler::eeFindHelper(CORINFO_HELP_DISPATCH_INDIRECT_CALL); call->gtFlags &= ~GTF_CALL_VIRT_KIND_MASK; #ifdef FEATURE_READYTORUN - call->gtEntryPoint.addr = nullptr; + call->gtEntryPoint.addr = nullptr; call->gtEntryPoint.accessType = IAT_VALUE; #endif @@ -4080,7 +4033,7 @@ GenTree* Lowering::LowerDirectCall(GenTreeCall* call) // If we are using an indirection cell for a direct call then apply // an optimization that loads the call target directly from the // indirection cell, instead of duplicating the tree. - bool hasIndirectionCell = call->GetIndirectionCellArgKind() != NonStandardArgKind::None; + bool hasIndirectionCell = call->GetIndirectionCellArgKind() != WellKnownArg::None; if (!hasIndirectionCell) { @@ -4142,13 +4095,11 @@ GenTree* Lowering::LowerDelegateInvoke(GenTreeCall* call) GenTree* thisArgNode; if (call->IsTailCallViaJitHelper()) { - const unsigned argNum = 0; - fgArgTabEntry* thisArgTabEntry = comp->gtArgEntryByArgNum(call, argNum); - thisArgNode = thisArgTabEntry->GetNode(); + thisArgNode = call->gtArgs.GetArgByIndex(0)->GetArgNode(); } else { - thisArgNode = comp->gtGetThisArg(call); + thisArgNode = call->gtArgs.GetThisArg()->GetArgNode(); } assert(thisArgNode != nullptr); @@ -4401,15 +4352,13 @@ void Lowering::InsertPInvokeMethodProlog() // TCB = CORINFO_HELP_INIT_PINVOKE_FRAME(&symFrameStart, secretArg); // for x86, don't pass the secretArg. CLANG_FORMAT_COMMENT_ANCHOR; + GenTreeCall* call = comp->gtNewHelperCallNode(CORINFO_HELP_INIT_PINVOKE_FRAME, TYP_I_IMPL); -#if defined(TARGET_X86) || defined(TARGET_ARM) - GenTreeCall::Use* argList = comp->gtNewCallArgs(frameAddr); -#else - GenTreeCall::Use* argList = comp->gtNewCallArgs(frameAddr, PhysReg(REG_SECRET_STUB_PARAM)); + call->gtArgs.PushBack(comp, frameAddr, WellKnownArg::PInvokeFrame); +#if !defined(TARGET_X86) && !defined(TARGET_ARM) + call->gtArgs.PushBack(comp, PhysReg(REG_SECRET_STUB_PARAM), WellKnownArg::SecretStubParam); #endif - GenTree* call = comp->gtNewHelperCallNode(CORINFO_HELP_INIT_PINVOKE_FRAME, TYP_I_IMPL, argList); - // some sanity checks on the frame list root vardsc const unsigned lclNum = comp->info.compLvFrameListRoot; const LclVarDsc* varDsc = comp->lvaGetDesc(lclNum); @@ -4579,14 +4528,13 @@ void Lowering::InsertPInvokeCallProlog(GenTreeCall* call) // On x86 targets, PInvoke calls need the size of the stack args in InlinedCallFrame.m_Datum. // This is because the callee pops stack arguments, and we need to keep track of this during stack // walking - const unsigned numStkArgBytes = call->fgArgInfo->GetNextSlotByteOffset(); + const unsigned numStkArgBytes = call->gtArgs.OutgoingArgsStackSize(); GenTree* stackBytes = comp->gtNewIconNode(numStkArgBytes, TYP_INT); - GenTreeCall::Use* args = comp->gtNewCallArgs(frameAddr, stackBytes); + // Insert call to CORINFO_HELP_JIT_PINVOKE_BEGIN + GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, frameAddr, stackBytes); #else - GenTreeCall::Use* args = comp->gtNewCallArgs(frameAddr); + GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, frameAddr); #endif - // Insert call to CORINFO_HELP_JIT_PINVOKE_BEGIN - GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, args); comp->fgMorphTree(helperCall); BlockRange().InsertBefore(insertBefore, LIR::SeqTree(comp, helperCall)); @@ -4613,7 +4561,7 @@ void Lowering::InsertPInvokeCallProlog(GenTreeCall* call) { #if !defined(TARGET_64BIT) // On 32-bit targets, indirect calls need the size of the stack args in InlinedCallFrame.m_Datum. - const unsigned stackByteOffset = call->fgArgInfo->GetNextSlotByteOffset(); + const unsigned stackByteOffset = call->gtArgs.OutgoingArgsStackSize(); src = comp->gtNewIconNode(stackByteOffset, TYP_INT); #else // On 64-bit targets, indirect calls may need the stub parameter value in InlinedCallFrame.m_Datum. @@ -4745,7 +4693,7 @@ void Lowering::InsertPInvokeCallEpilog(GenTreeCall* call) // Insert call to CORINFO_HELP_JIT_PINVOKE_END GenTreeCall* helperCall = - comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_END, TYP_VOID, comp->gtNewCallArgs(frameAddr)); + comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_END, TYP_VOID, frameAddr); comp->fgMorphTree(helperCall); BlockRange().InsertAfter(call, LIR::SeqTree(comp, helperCall)); @@ -4951,13 +4899,11 @@ GenTree* Lowering::LowerVirtualVtableCall(GenTreeCall* call) { noway_assert(call->gtCallType == CT_USER_FUNC); - regNumber thisPtrArgReg = comp->codeGen->genGetThisArgReg(call); - + assert(call->gtArgs.HasThisPointer()); + CallArg* thisArg = call->gtArgs.GetThisArg(); // get a reference to the thisPtr being passed - fgArgTabEntry* argEntry = comp->gtArgEntryByArgNum(call, 0); - assert(argEntry->GetRegNum() == thisPtrArgReg); - assert(argEntry->GetNode()->OperIs(GT_PUTARG_REG)); - GenTree* thisPtr = argEntry->GetNode()->AsUnOp()->gtGetOp1(); + assert(thisArg->GetArgNode()->OperIs(GT_PUTARG_REG)); + GenTree* thisPtr = thisArg->GetArgNode()->AsUnOp()->gtGetOp1(); // If what we are passing as the thisptr is not already a local, make a new local to place it in // because we will be creating expressions based on it. @@ -4974,7 +4920,7 @@ GenTree* Lowering::LowerVirtualVtableCall(GenTreeCall* call) vtableCallTemp = comp->lvaGrabTemp(true DEBUGARG("virtual vtable call")); } - LIR::Use thisPtrUse(BlockRange(), &(argEntry->GetNode()->AsUnOp()->gtOp1), argEntry->GetNode()); + LIR::Use thisPtrUse(BlockRange(), &thisArg->GetArgNode()->AsUnOp()->gtOp1, thisArg->GetArgNode()); ReplaceWithLclVar(thisPtrUse, vtableCallTemp); lclNum = vtableCallTemp; @@ -6503,19 +6449,14 @@ void Lowering::CheckCallArg(GenTree* arg) // void Lowering::CheckCall(GenTreeCall* call) { - if (call->gtCallThisArg != nullptr) - { - CheckCallArg(call->gtCallThisArg->GetNode()); - } - - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - CheckCallArg(use.GetNode()); + CheckCallArg(arg.GetNode()); } - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - CheckCallArg(use.GetNode()); + CheckCallArg(arg.GetNode()); } } diff --git a/src/coreclr/jit/lower.h b/src/coreclr/jit/lower.h index 1a0bb8b5ed9926..616c36918849a8 100644 --- a/src/coreclr/jit/lower.h +++ b/src/coreclr/jit/lower.h @@ -159,10 +159,10 @@ class Lowering final : public Phase GenTree* LowerVirtualStubCall(GenTreeCall* call); void LowerArgsForCall(GenTreeCall* call); void ReplaceArgWithPutArgOrBitcast(GenTree** ppChild, GenTree* newNode); - GenTree* NewPutArg(GenTreeCall* call, GenTree* arg, fgArgTabEntry* info, var_types type); - void LowerArg(GenTreeCall* call, GenTree** ppTree); + GenTree* NewPutArg(GenTreeCall* call, GenTree* arg, CallArg* callArg, var_types type); + void LowerArg(GenTreeCall* call, CallArg* callArg, bool late); #ifdef TARGET_ARMARCH - GenTree* LowerFloatArg(GenTree** pArg, fgArgTabEntry* info); + GenTree* LowerFloatArg(GenTree** pArg, CallArg* callArg); GenTree* LowerFloatArgReg(GenTree* arg, regNumber regNum); #endif diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index f20af690fa7fe8..0c790562ec886e 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -4537,19 +4537,19 @@ void Lowering::ContainCheckCallOperands(GenTreeCall* call) } } - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - if (use.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetNode()->OperIs(GT_PUTARG_STK)) { - LowerPutArgStk(use.GetNode()->AsPutArgStk()); + LowerPutArgStk(arg.GetNode()->AsPutArgStk()); } } - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - if (use.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetNode()->OperIs(GT_PUTARG_STK)) { - LowerPutArgStk(use.GetNode()->AsPutArgStk()); + LowerPutArgStk(arg.GetNode()->AsPutArgStk()); } } } diff --git a/src/coreclr/jit/lsraarmarch.cpp b/src/coreclr/jit/lsraarmarch.cpp index bc60614c6ced3c..5137d71d70a085 100644 --- a/src/coreclr/jit/lsraarmarch.cpp +++ b/src/coreclr/jit/lsraarmarch.cpp @@ -247,22 +247,19 @@ int LinearScan::BuildCall(GenTreeCall* call) // Each register argument corresponds to one source. bool callHasFloatRegArgs = false; - for (GenTreeCall::Use& arg : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { + CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; GenTree* argNode = arg.GetNode(); #ifdef DEBUG - // During Build, we only use the ArgTabEntry for validation, - // as getting it is rather expensive. - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, argNode); - regNumber argReg = curArgTabEntry->GetRegNum(); - assert(curArgTabEntry != nullptr); + regNumber argReg = abiInfo.GetRegNum(); #endif if (argNode->gtOper == GT_PUTARG_STK) { // late arg that is not passed in a register - assert(curArgTabEntry->GetRegNum() == REG_STK); + assert(abiInfo.GetRegNum() == REG_STK); // These should never be contained. assert(!argNode->isContained()); continue; @@ -297,7 +294,7 @@ int LinearScan::BuildCall(GenTreeCall* call) else if (argNode->OperGet() == GT_PUTARG_SPLIT) { unsigned regCount = argNode->AsPutArgSplit()->gtNumRegs; - assert(regCount == curArgTabEntry->numRegs); + assert(regCount == abiInfo.NumRegs); for (unsigned int i = 0; i < regCount; i++) { BuildUse(argNode, genRegMask(argNode->AsPutArgSplit()->GetRegNumByIdx(i)), i); @@ -337,25 +334,23 @@ int LinearScan::BuildCall(GenTreeCall* call) // because the code generator doesn't actually consider it live, // so it can't be spilled. - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree* arg = use.GetNode(); + GenTree* argNode = arg.GetNode(); // Skip arguments that have been moved to the Late Arg list - if ((arg->gtFlags & GTF_LATE_ARG) == 0) + if ((argNode->gtFlags & GTF_LATE_ARG) == 0) { - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, arg); - assert(curArgTabEntry != nullptr); // PUTARG_SPLIT nodes must be in the gtCallLateArgs list, since they // define registers used by the call. - assert(arg->OperGet() != GT_PUTARG_SPLIT); - if (arg->gtOper == GT_PUTARG_STK) + assert(argNode->OperGet() != GT_PUTARG_SPLIT); + if (argNode->gtOper == GT_PUTARG_STK) { - assert(curArgTabEntry->GetRegNum() == REG_STK); + assert(arg.AbiInfo.GetRegNum() == REG_STK); } else { - assert(!arg->IsValue() || arg->IsUnusedValue()); + assert(!argNode->IsValue() || argNode->IsUnusedValue()); } } } diff --git a/src/coreclr/jit/lsraxarch.cpp b/src/coreclr/jit/lsraxarch.cpp index f9e69773d70cbb..6bb2f1537dbe31 100644 --- a/src/coreclr/jit/lsraxarch.cpp +++ b/src/coreclr/jit/lsraxarch.cpp @@ -1092,9 +1092,9 @@ int LinearScan::BuildCall(GenTreeCall* call) // First, determine internal registers. // We will need one for any float arguments to a varArgs call. - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - GenTree* argNode = use.GetNode(); + GenTree* argNode = arg.GetNode(); if (argNode->OperIsPutArgReg()) { HandleFloatVarArgs(call, argNode, &callHasFloatRegArgs); @@ -1110,7 +1110,7 @@ int LinearScan::BuildCall(GenTreeCall* call) } // Now, count reg args - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { // By this point, lowering has ensured that all call arguments are one of the following: // - an arg setup store @@ -1121,7 +1121,8 @@ int LinearScan::BuildCall(GenTreeCall* call) // - a put arg // // Note that this property is statically checked by LinearScan::CheckBlock. - GenTree* argNode = use.GetNode(); + CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; + GenTree* argNode = arg.GetNode(); // Each register argument corresponds to one source. if (argNode->OperIsPutArgReg()) @@ -1144,10 +1145,7 @@ int LinearScan::BuildCall(GenTreeCall* call) #ifdef DEBUG // In DEBUG only, check validity with respect to the arg table entry. - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, argNode); - assert(curArgTabEntry); - - if (curArgTabEntry->GetRegNum() == REG_STK) + if (abiInfo.GetRegNum() == REG_STK) { // late arg that is not passed in a register assert(argNode->gtOper == GT_PUTARG_STK); @@ -1170,12 +1168,12 @@ int LinearScan::BuildCall(GenTreeCall* call) if (argNode->OperGet() == GT_FIELD_LIST) { assert(argNode->isContained()); - assert(varTypeIsStruct(argNode) || curArgTabEntry->isStruct); + assert(varTypeIsStruct(argNode) || abiInfo.IsStruct); unsigned regIndex = 0; for (GenTreeFieldList::Use& use : argNode->AsFieldList()->Uses()) { - const regNumber argReg = curArgTabEntry->GetRegNum(regIndex); + const regNumber argReg = abiInfo.GetRegNum(regIndex); assert(use.GetNode()->GetRegNum() == argReg); regIndex++; } @@ -1183,33 +1181,12 @@ int LinearScan::BuildCall(GenTreeCall* call) else #endif // UNIX_AMD64_ABI { - const regNumber argReg = curArgTabEntry->GetRegNum(); + const regNumber argReg = abiInfo.GetRegNum(); assert(argNode->GetRegNum() == argReg); } #endif // DEBUG } -#ifdef DEBUG - // Now, count stack args - // Note that these need to be computed into a register, but then - // they're just stored to the stack - so the reg doesn't - // need to remain live until the call. In fact, it must not - // because the code generator doesn't actually consider it live, - // so it can't be spilled. - - for (GenTreeCall::Use& use : call->Args()) - { - GenTree* arg = use.GetNode(); - if (!(arg->gtFlags & GTF_LATE_ARG) && !arg) - { - if (arg->IsValue() && !arg->isContained()) - { - assert(arg->IsUnusedValue()); - } - } - } -#endif // DEBUG - // set reg requirements on call target represented as control sequence. if (ctrlExpr != nullptr) { diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index d233393dca0a64..18ebd491400d38 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -46,7 +46,7 @@ GenTree* Compiler::fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* ope noway_assert(tree->AsCast()->CastOp() == oper); noway_assert(tree->gtOper == GT_CAST); } - result = fgMorphIntoHelperCall(tree, helper, gtNewCallArgs(oper)); + result = fgMorphIntoHelperCall(tree, helper, oper); assert(result == tree); return result; } @@ -57,7 +57,7 @@ GenTree* Compiler::fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* ope * the given argument list. */ -GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeCall::Use* args, bool morphArgs) +GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTree* arg1, GenTree* arg2, bool morphArgs) { // The helper call ought to be semantically equivalent to the original node, so preserve its VN. tree->ChangeOper(GT_CALL, GenTree::PRESERVE_VN); @@ -66,15 +66,10 @@ GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeCall: call->gtCallType = CT_HELPER; call->gtReturnType = tree->TypeGet(); call->gtCallMethHnd = eeFindHelper(helper); - call->gtCallThisArg = nullptr; - call->gtCallArgs = args; - call->gtCallLateArgs = nullptr; - call->fgArgInfo = nullptr; call->gtRetClsHnd = nullptr; call->gtCallMoreFlags = GTF_CALL_M_EMPTY; call->gtInlineCandidateInfo = nullptr; call->gtControlExpr = nullptr; - call->gtRetBufArg = nullptr; #ifdef UNIX_X86_ABI call->gtFlags |= GTF_CALL_POP_ARGS; #endif // UNIX_X86_ABI @@ -114,12 +109,21 @@ GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTreeCall: } tree->gtFlags |= GTF_CALL; - for (GenTreeCall::Use& use : GenTreeCall::UseList(args)) + if (arg1 != nullptr) { - tree->gtFlags |= (use.GetNode()->gtFlags & GTF_ALL_EFFECT); + CallArg* carg1 = tree->AsCall()->gtArgs.PushFront(this, arg1); + if (arg2 != nullptr) + { + tree->AsCall()->gtArgs.InsertAfter(this, carg1, arg2); + } } - /* Perform the morphing */ + for (CallArg& arg : tree->AsCall()->gtArgs.Args()) + { + tree->gtFlags |= (arg.GetNode()->gtFlags & GTF_ALL_EFFECT); + } + + // Perform the morphing if (morphArgs) { @@ -567,98 +571,91 @@ GenTree* Compiler::fgMorphExpandCast(GenTreeCast* tree) } #ifdef DEBUG -const char* getNonStandardArgKindName(NonStandardArgKind kind) +const char* getWellKnownArgName(WellKnownArg arg) { - switch (kind) - { - case NonStandardArgKind::None: - return "None"; - case NonStandardArgKind::PInvokeFrame: - return "PInvokeFrame"; - case NonStandardArgKind::PInvokeTarget: - return "PInvokeTarget"; - case NonStandardArgKind::PInvokeCookie: - return "PInvokeCookie"; - case NonStandardArgKind::WrapperDelegateCell: - return "WrapperDelegateCell"; - case NonStandardArgKind::ShiftLow: - return "ShiftLow"; - case NonStandardArgKind::ShiftHigh: - return "ShiftHigh"; - case NonStandardArgKind::FixedRetBuffer: - return "FixedRetBuffer"; - case NonStandardArgKind::VirtualStubCell: - return "VirtualStubCell"; - case NonStandardArgKind::R2RIndirectionCell: - return "R2RIndirectionCell"; - case NonStandardArgKind::ValidateIndirectCallTarget: - return "ValidateIndirectCallTarget"; - default: - unreached(); + switch (arg) + { + case WellKnownArg::None: return "None"; + case WellKnownArg::ThisPointer: return "ThisPointer"; + case WellKnownArg::VarArgsCookie: return "VarArgsCookie"; + case WellKnownArg::InstParam: return "InstParam"; + case WellKnownArg::RetBuffer: return "RetBuffer"; + case WellKnownArg::PInvokeFrame: return "PInvokeFrame"; + case WellKnownArg::SecretStubParam: return "SecretStubParam"; + case WellKnownArg::WrapperDelegateCell: return "WrapperDelegateCell"; + case WellKnownArg::ShiftLow: return "ShiftLow"; + case WellKnownArg::ShiftHigh: return "ShiftHigh"; + case WellKnownArg::VirtualStubCell: return "VirtualStubCell"; + case WellKnownArg::PInvokeCookie: return "PInvokeCookie"; + case WellKnownArg::PInvokeTarget: return "PInvokeTarget"; + case WellKnownArg::R2RIndirectionCell: return "R2RIndirectionCell"; + case WellKnownArg::ValidateIndirectCallTarget: return "ValidateIndirectCallTarget"; + case WellKnownArg::DispatchIndirectCallTarget: return "DispatchIndirectCallTarget"; + default: return "N/A"; } } -void fgArgTabEntry::Dump() const +void CallArg::Dump(Compiler* comp) { - printf("fgArgTabEntry[arg %u", argNum); - printf(" %d.%s", GetNode()->gtTreeID, GenTree::OpName(GetNode()->OperGet())); - printf(" %s", varTypeName(argType)); - printf(" (%s)", passedByRef ? "By ref" : "By value"); - if (GetRegNum() != REG_STK) + printf("CallArg[arg %u", AbiInfo.ArgNum); + printf(" [%06u].%s", comp->dspTreeID(GetArgNode()), GenTree::OpName(GetNode()->OperGet())); + printf(" %s", varTypeName(AbiInfo.ArgType)); + printf(" (%s)", AbiInfo.PassedByRef ? "By ref" : "By value"); + if (AbiInfo.GetRegNum() != REG_STK) { - printf(", %u reg%s:", numRegs, numRegs == 1 ? "" : "s"); - for (unsigned i = 0; i < numRegs; i++) + printf(", %u reg%s:", AbiInfo.NumRegs, AbiInfo.NumRegs == 1 ? "" : "s"); + for (unsigned i = 0; i < AbiInfo.NumRegs; i++) { - printf(" %s", getRegName(regNums[i])); + printf(" %s", getRegName(AbiInfo.GetRegNum(i))); } } - if (GetStackByteSize() > 0) + if (AbiInfo.GetStackByteSize() > 0) { #if defined(DEBUG_ARG_SLOTS) - printf(", numSlots=%u, slotNum=%u, byteSize=%u, byteOffset=%u", numSlots, slotNum, m_byteSize, m_byteOffset); + printf(", numSlots=%u, slotNum=%u, byteSize=%u, byteOffset=%u", AbiInfo.NumSlots, AbiInfo.SlotNum, AbiInfo.ByteSize, AbiInfo.ByteOffset); #else - printf(", byteSize=%u, byteOffset=%u", m_byteSize, m_byteOffset); + printf(", byteSize=%u, byteOffset=%u", AbiInfo.ByteSize, AbiInfo.ByteOffset); #endif } - printf(", byteAlignment=%u", m_byteAlignment); - if (isLateArg()) + printf(", byteAlignment=%u", AbiInfo.ByteAlignment); + if (GetLateNode() != nullptr) { - printf(", lateArgInx=%u", GetLateArgInx()); + printf(", isLate"); } - if (IsSplit()) + if (AbiInfo.IsSplit()) { printf(", isSplit"); } - if (needTmp) + if (m_needTmp) { - printf(", tmpNum=V%02u", tmpNum); + printf(", tmpNum=V%02u", m_tmpNum); } - if (needPlace) + if (m_needPlace) { printf(", needPlace"); } - if (isTmp) + if (m_isTmp) { printf(", isTmp"); } - if (processed) + if (m_processed) { printf(", processed"); } - if (IsHfaRegArg()) + if (AbiInfo.IsHfaRegArg()) { - printf(", isHfa(%s)", varTypeName(GetHfaType())); + printf(", isHfa(%s)", varTypeName(AbiInfo.GetHfaType())); } - if (isBackFilled) + if (AbiInfo.IsBackFilled) { printf(", isBackFilled"); } - if (nonStandardArgKind != NonStandardArgKind::None) + if (m_wellKnownArg != WellKnownArg::None) { - printf(", nonStandard[%s]", getNonStandardArgKindName(nonStandardArgKind)); + printf(", wellKnown[%s]", getWellKnownArgName(m_wellKnownArg)); } - if (isStruct) + if (AbiInfo.IsStruct) { printf(", isStruct"); } @@ -666,453 +663,55 @@ void fgArgTabEntry::Dump() const } #endif -fgArgInfo::fgArgInfo(Compiler* comp, GenTreeCall* call, unsigned numArgs) -{ - compiler = comp; - callTree = call; - argCount = 0; // filled in arg count, starts at zero - DEBUG_ARG_SLOTS_ONLY(nextSlotNum = INIT_ARG_STACK_SLOT;) - nextStackByteOffset = INIT_ARG_STACK_SLOT * TARGET_POINTER_SIZE; - stkLevel = 0; -#if defined(UNIX_X86_ABI) - alignmentDone = false; - stkSizeBytes = 0; - padStkAlign = 0; -#endif -#if FEATURE_FIXED_OUT_ARGS - outArgSize = 0; -#endif - - argTableSize = numArgs; // the allocated table size - - hasRegArgs = false; - hasStackArgs = false; - argsComplete = false; - argsSorted = false; - needsTemps = false; - - if (argTableSize == 0) - { - argTable = nullptr; - } - else - { - argTable = new (compiler, CMK_fgArgInfoPtrArr) fgArgTabEntry*[argTableSize]; - } -} - -/***************************************************************************** - * - * fgArgInfo Copy Constructor - * - * This method needs to act like a copy constructor for fgArgInfo. - * The newCall needs to have its fgArgInfo initialized such that - * we have newCall that is an exact copy of the oldCall. - * We have to take care since the argument information - * in the argTable contains pointers that must point to the - * new arguments and not the old arguments. - */ -fgArgInfo::fgArgInfo(GenTreeCall* newCall, GenTreeCall* oldCall) -{ - fgArgInfo* oldArgInfo = oldCall->AsCall()->fgArgInfo; - - compiler = oldArgInfo->compiler; - callTree = newCall; - argCount = 0; // filled in arg count, starts at zero - 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) - alignmentDone = oldArgInfo->alignmentDone; - stkSizeBytes = oldArgInfo->stkSizeBytes; - padStkAlign = oldArgInfo->padStkAlign; -#endif -#if FEATURE_FIXED_OUT_ARGS - outArgSize = oldArgInfo->outArgSize; -#endif - argTableSize = oldArgInfo->argTableSize; - argsComplete = false; - argTable = nullptr; - - assert(oldArgInfo->argsComplete); - - if (argTableSize > 0) - { - argTable = new (compiler, CMK_fgArgInfoPtrArr) fgArgTabEntry*[argTableSize]; - - // Copy the old arg entries - for (unsigned i = 0; i < argTableSize; i++) - { - argTable[i] = new (compiler, CMK_fgArgInfo) fgArgTabEntry(*oldArgInfo->argTable[i]); - } - - // The copied arg entries contain pointers to old uses, they need - // to be updated to point to new uses. - if (newCall->gtCallThisArg != nullptr) - { - for (unsigned i = 0; i < argTableSize; i++) - { - if (argTable[i]->use == oldCall->gtCallThisArg) - { - argTable[i]->use = newCall->gtCallThisArg; - break; - } - } - } - - GenTreeCall::UseIterator newUse = newCall->Args().begin(); - GenTreeCall::UseIterator newUseEnd = newCall->Args().end(); - GenTreeCall::UseIterator oldUse = oldCall->Args().begin(); - GenTreeCall::UseIterator oldUseEnd = newCall->Args().end(); - - for (; newUse != newUseEnd; ++newUse, ++oldUse) - { - for (unsigned i = 0; i < argTableSize; i++) - { - if (argTable[i]->use == oldUse.GetUse()) - { - argTable[i]->use = newUse.GetUse(); - break; - } - } - } - - newUse = newCall->LateArgs().begin(); - newUseEnd = newCall->LateArgs().end(); - oldUse = oldCall->LateArgs().begin(); - oldUseEnd = newCall->LateArgs().end(); - - for (; newUse != newUseEnd; ++newUse, ++oldUse) - { - for (unsigned i = 0; i < argTableSize; i++) - { - if (argTable[i]->lateUse == oldUse.GetUse()) - { - argTable[i]->lateUse = newUse.GetUse(); - break; - } - } - } - } - - argCount = oldArgInfo->argCount; - DEBUG_ARG_SLOTS_ONLY(nextSlotNum = oldArgInfo->nextSlotNum;) - nextStackByteOffset = oldArgInfo->nextStackByteOffset; - - hasRegArgs = oldArgInfo->hasRegArgs; - hasStackArgs = oldArgInfo->hasStackArgs; - argsComplete = true; - argsSorted = true; -} - -void fgArgInfo::AddArg(fgArgTabEntry* curArgTabEntry) -{ - assert(argCount < argTableSize); - argTable[argCount] = curArgTabEntry; - argCount++; -} - -fgArgTabEntry* fgArgInfo::AddRegArg(unsigned argNum, - GenTree* node, - GenTreeCall::Use* use, - regNumber regNum, - unsigned numRegs, - unsigned byteSize, - unsigned byteAlignment, - bool isStruct, - bool isFloatHfa, - bool isVararg /*=false*/) -{ - fgArgTabEntry* curArgTabEntry = new (compiler, CMK_fgArgInfo) fgArgTabEntry; - - // Any additional register numbers are set by the caller. - // This is primarily because on ARM we don't yet know if it - // will be split or if it is a double HFA, so the number of registers - // may actually be less. - curArgTabEntry->setRegNum(0, regNum); - - curArgTabEntry->argNum = argNum; - curArgTabEntry->argType = node->TypeGet(); - curArgTabEntry->use = use; - curArgTabEntry->lateUse = nullptr; - curArgTabEntry->numRegs = numRegs; - -#if defined(DEBUG_ARG_SLOTS) - curArgTabEntry->slotNum = 0; - curArgTabEntry->numSlots = 0; -#endif - - curArgTabEntry->SetLateArgInx(UINT_MAX); - curArgTabEntry->tmpNum = BAD_VAR_NUM; - curArgTabEntry->SetSplit(false); - curArgTabEntry->isTmp = false; - curArgTabEntry->needTmp = false; - curArgTabEntry->needPlace = false; - curArgTabEntry->processed = false; - if (GlobalJitOptions::compFeatureHfa) - { - curArgTabEntry->SetHfaElemKind(CORINFO_HFA_ELEM_NONE); - } - curArgTabEntry->isBackFilled = false; - curArgTabEntry->nonStandardArgKind = NonStandardArgKind::None; - curArgTabEntry->isStruct = isStruct; - curArgTabEntry->SetIsVararg(isVararg); - curArgTabEntry->SetByteAlignment(byteAlignment); - curArgTabEntry->SetByteSize(byteSize, isStruct, isFloatHfa); - curArgTabEntry->SetByteOffset(0); - - hasRegArgs = true; - if (argCount >= argTableSize) - { - fgArgTabEntry** oldTable = argTable; - argTable = new (compiler, CMK_fgArgInfoPtrArr) fgArgTabEntry*[argCount + 1]; - memcpy(argTable, oldTable, argCount * sizeof(fgArgTabEntry*)); - argTableSize++; - } - - AddArg(curArgTabEntry); - return curArgTabEntry; -} - -#if defined(UNIX_AMD64_ABI) -fgArgTabEntry* fgArgInfo::AddRegArg(unsigned argNum, - GenTree* node, - GenTreeCall::Use* use, - regNumber regNum, - unsigned numRegs, - unsigned byteSize, - unsigned byteAlignment, - const bool isStruct, - const bool isFloatHfa, - const bool isVararg, - const regNumber otherRegNum, - const unsigned structIntRegs, - const unsigned structFloatRegs, - const SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR* const structDescPtr) -{ - fgArgTabEntry* curArgTabEntry = - AddRegArg(argNum, node, use, regNum, numRegs, byteSize, byteAlignment, isStruct, isFloatHfa, isVararg); - assert(curArgTabEntry != nullptr); - - curArgTabEntry->isStruct = isStruct; // is this a struct arg - curArgTabEntry->structIntRegs = structIntRegs; - curArgTabEntry->structFloatRegs = structFloatRegs; - - INDEBUG(curArgTabEntry->checkIsStruct();) - assert(numRegs <= 2); - if (numRegs == 2) - { - curArgTabEntry->setRegNum(1, otherRegNum); - } - - if (isStruct && structDescPtr != nullptr) - { - curArgTabEntry->structDesc.CopyFrom(*structDescPtr); - } - - return curArgTabEntry; -} -#endif // defined(UNIX_AMD64_ABI) - -fgArgTabEntry* fgArgInfo::AddStkArg(unsigned argNum, - GenTree* node, - GenTreeCall::Use* use, - unsigned numSlots, - unsigned byteSize, - unsigned byteAlignment, - bool isStruct, - bool isFloatHfa, - bool isVararg /*=false*/) -{ - fgArgTabEntry* curArgTabEntry = new (compiler, CMK_fgArgInfo) fgArgTabEntry; - -#if defined(DEBUG_ARG_SLOTS) - if (!compMacOsArm64Abi()) - { - nextSlotNum = roundUp(nextSlotNum, byteAlignment / TARGET_POINTER_SIZE); - } -#endif - - nextStackByteOffset = roundUp(nextStackByteOffset, byteAlignment); - 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_ARG_SLOTS) - curArgTabEntry->numSlots = numSlots; - curArgTabEntry->slotNum = nextSlotNum; -#endif - - curArgTabEntry->numRegs = 0; -#if defined(UNIX_AMD64_ABI) - curArgTabEntry->structIntRegs = 0; - curArgTabEntry->structFloatRegs = 0; -#endif // defined(UNIX_AMD64_ABI) - curArgTabEntry->SetLateArgInx(UINT_MAX); - curArgTabEntry->tmpNum = BAD_VAR_NUM; - curArgTabEntry->SetSplit(false); - curArgTabEntry->isTmp = false; - curArgTabEntry->needTmp = false; - curArgTabEntry->needPlace = false; - curArgTabEntry->processed = false; - if (GlobalJitOptions::compFeatureHfa) - { - curArgTabEntry->SetHfaElemKind(CORINFO_HFA_ELEM_NONE); - } - curArgTabEntry->isBackFilled = false; - curArgTabEntry->nonStandardArgKind = NonStandardArgKind::None; - curArgTabEntry->isStruct = isStruct; - curArgTabEntry->SetIsVararg(isVararg); - - curArgTabEntry->SetByteAlignment(byteAlignment); - curArgTabEntry->SetByteSize(byteSize, isStruct, isFloatHfa); - curArgTabEntry->SetByteOffset(nextStackByteOffset); - - hasStackArgs = true; - AddArg(curArgTabEntry); - DEBUG_ARG_SLOTS_ONLY(nextSlotNum += numSlots;) - nextStackByteOffset += curArgTabEntry->GetByteSize(); - - return curArgTabEntry; -} - -void fgArgInfo::RemorphReset() -{ - DEBUG_ARG_SLOTS_ONLY(nextSlotNum = INIT_ARG_STACK_SLOT;) - nextStackByteOffset = INIT_ARG_STACK_SLOT * TARGET_POINTER_SIZE; -} - -//------------------------------------------------------------------------ -// UpdateRegArg: Update the given fgArgTabEntry while morphing. -// -// Arguments: -// curArgTabEntry - the fgArgTabEntry to update. -// node - the tree node that defines the argument -// reMorphing - a boolean value indicate whether we are remorphing the call -// -// Assumptions: -// This must have already been determined to be at least partially passed in registers. -// -void fgArgInfo::UpdateRegArg(fgArgTabEntry* curArgTabEntry, GenTree* node, bool reMorphing) -{ - bool isLateArg = curArgTabEntry->isLateArg(); - // If this is a late arg, we'd better be updating it with a correctly marked node, and vice-versa. - assert((isLateArg && ((node->gtFlags & GTF_LATE_ARG) != 0)) || - (!isLateArg && ((node->gtFlags & GTF_LATE_ARG) == 0))); - - assert(curArgTabEntry->numRegs != 0); - assert(curArgTabEntry->use->GetNode() == node); -} - -//------------------------------------------------------------------------ -// UpdateStkArg: Update the given fgArgTabEntry while morphing. -// -// Arguments: -// curArgTabEntry - the fgArgTabEntry to update. -// node - the tree node that defines the argument -// reMorphing - a boolean value indicate whether we are remorphing the call -// -// Assumptions: -// This must have already been determined to be passed on the stack. -// -void fgArgInfo::UpdateStkArg(fgArgTabEntry* curArgTabEntry, GenTree* node, bool reMorphing) -{ - bool isLateArg = curArgTabEntry->isLateArg(); - // If this is a late arg, we'd better be updating it with a correctly marked node, and vice-versa. - assert((isLateArg && ((node->gtFlags & GTF_LATE_ARG) != 0)) || - (!isLateArg && ((node->gtFlags & GTF_LATE_ARG) == 0))); - - noway_assert(curArgTabEntry->use != callTree->gtCallThisArg); - assert((curArgTabEntry->GetRegNum() == REG_STK) || curArgTabEntry->IsSplit()); - assert(curArgTabEntry->use->GetNode() == node); -#if defined(DEBUG_ARG_SLOTS) - if (!compMacOsArm64Abi()) - { - nextSlotNum = roundUp(nextSlotNum, curArgTabEntry->GetByteAlignment() / TARGET_POINTER_SIZE); - assert(curArgTabEntry->slotNum == nextSlotNum); - nextSlotNum += curArgTabEntry->numSlots; - } -#endif - - nextStackByteOffset = roundUp(nextStackByteOffset, curArgTabEntry->GetByteAlignment()); - assert(curArgTabEntry->GetByteOffset() == nextStackByteOffset); - nextStackByteOffset += curArgTabEntry->GetStackByteSize(); -} - -void fgArgInfo::SplitArg(unsigned argNum, unsigned numRegs, unsigned numSlots) +void CallArgs::SplitArg(CallArg* arg, unsigned numRegs, unsigned numSlots, unsigned* nextSlotNum) { - fgArgTabEntry* curArgTabEntry = nullptr; - assert(argNum < argCount); - for (unsigned inx = 0; inx < argCount; inx++) - { - curArgTabEntry = argTable[inx]; - if (curArgTabEntry->argNum == argNum) - { - break; - } - } - assert(numRegs > 0); assert(numSlots > 0); - if (argsComplete) + if (m_argsComplete) { - assert(curArgTabEntry->IsSplit() == true); - assert(curArgTabEntry->numRegs == numRegs); - DEBUG_ARG_SLOTS_ONLY(assert(curArgTabEntry->numSlots == numSlots);) - assert(hasStackArgs == true); + assert(arg->AbiInfo.IsSplit() == true); + assert(arg->AbiInfo.NumRegs == numRegs); + DEBUG_ARG_SLOTS_ONLY(assert(arg->AbiInfo.NumSlots == numSlots);) + assert(m_hasStackArgs); } else { - curArgTabEntry->SetSplit(true); - curArgTabEntry->numRegs = numRegs; - DEBUG_ARG_SLOTS_ONLY(curArgTabEntry->numSlots = numSlots;) - curArgTabEntry->SetByteOffset(0); - hasStackArgs = true; + arg->AbiInfo.SetSplit(true); + arg->AbiInfo.NumRegs = numRegs; + DEBUG_ARG_SLOTS_ONLY(arg->AbiInfo.NumSlots = numSlots;) + arg->AbiInfo.ByteOffset = 0; + m_hasStackArgs = true; } - 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; + *nextSlotNum += numSlots; + m_nextStackByteOffset += numSlots * TARGET_POINTER_SIZE; } -//------------------------------------------------------------------------ -// EvalToTmp: Replace the node in the given fgArgTabEntry with a temp -// -// Arguments: -// curArgTabEntry - the fgArgTabEntry for the argument -// tmpNum - the varNum for the temp -// newNode - the assignment of the argument value to the temp -// -// Notes: -// Although the name of this method is EvalToTmp, it doesn't actually create -// the temp or the copy. -// -void fgArgInfo::EvalToTmp(fgArgTabEntry* curArgTabEntry, unsigned tmpNum, GenTree* newNode) +void CallArgs::SetTemp(CallArg* arg, unsigned tmpNum) { - assert(curArgTabEntry->use != callTree->gtCallThisArg); - assert(curArgTabEntry->use->GetNode() == newNode); - - assert(curArgTabEntry->GetNode() == newNode); - curArgTabEntry->tmpNum = tmpNum; - curArgTabEntry->isTmp = true; + arg->m_tmpNum = tmpNum; + arg->m_isTmp = true; } -void fgArgInfo::ArgsComplete() +void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) { bool hasStructRegArg = false; - for (unsigned curInx = 0; curInx < argCount; curInx++) + unsigned argCount = 0; + + for (CallArg& arg : Args()) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; - assert(curArgTabEntry != nullptr); - GenTree* argx = curArgTabEntry->GetNode(); + argCount++; + } + + for (CallArg& arg : Args()) + { + GenTree* argx = arg.GetNode(); - if (curArgTabEntry->GetRegNum() == REG_STK) + if (arg.AbiInfo.GetRegNum() == REG_STK) { - assert(hasStackArgs == true); + assert(m_hasStackArgs); #if !FEATURE_FIXED_OUT_ARGS // On x86 we use push instructions to pass arguments: // The non-register arguments are evaluated and pushed in order @@ -1122,15 +721,15 @@ void fgArgInfo::ArgsComplete() #endif } #if FEATURE_ARG_SPLIT - else if (curArgTabEntry->IsSplit()) + else if (arg.AbiInfo.IsSplit()) { hasStructRegArg = true; - assert(hasStackArgs == true); + assert(m_hasStackArgs == true); } #endif // FEATURE_ARG_SPLIT else // we have a register argument, next we look for a struct type. { - if (varTypeIsStruct(argx) UNIX_AMD64_ABI_ONLY(|| curArgTabEntry->isStruct)) + if (varTypeIsStruct(argx) UNIX_AMD64_ABI_ONLY(|| arg.AbiInfo.IsStruct)) { hasStructRegArg = true; } @@ -1155,26 +754,26 @@ void fgArgInfo::ArgsComplete() // a tmp, then we need a temp in the late arg list. if ((argCount > 1) || argx->OperIsCopyBlkOp() #ifdef FEATURE_FIXED_OUT_ARGS - || curArgTabEntry->isTmp // I protect this by "FEATURE_FIXED_OUT_ARGS" to preserve the property - // that we only have late non-register args when that feature is on. -#endif // FEATURE_FIXED_OUT_ARGS + || arg.m_isTmp // Protect this by "FEATURE_FIXED_OUT_ARGS" to preserve the property + // that we only have late non-register args when that feature is on. +#endif ) { - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } // For all previous arguments, unless they are a simple constant // we require that they be evaluated into temps - for (unsigned prevInx = 0; prevInx < curInx; prevInx++) + for (CallArg& prevArg : Args()) { - fgArgTabEntry* prevArgTabEntry = argTable[prevInx]; - assert(prevArgTabEntry->argNum < curArgTabEntry->argNum); + if (&prevArg == &arg) + { + break; + } - if (!prevArgTabEntry->GetNode()->IsInvariant()) + if (!prevArg.GetNode()->IsInvariant()) { - prevArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&prevArg); } } } @@ -1188,17 +787,17 @@ void fgArgInfo::ArgsComplete() // conservative, but I want to avoid as much special-case debug-only code // as possible, so leveraging the GTF_CALL flag is the easiest. // - if (!treatLikeCall && (argx->gtFlags & GTF_EXCEPT) && (argCount > 1) && compiler->opts.compDbgCode && - (compiler->fgWalkTreePre(&argx, Compiler::fgChkThrowCB) == Compiler::WALK_ABORT)) + if (!treatLikeCall && (argx->gtFlags & GTF_EXCEPT) && (argCount > 1) && comp->opts.compDbgCode && + (comp->fgWalkTreePre(&argx, Compiler::fgChkThrowCB) == Compiler::WALK_ABORT)) { - for (unsigned otherInx = 0; otherInx < argCount; otherInx++) + for (CallArg& otherArg : Args()) { - if (otherInx == curInx) + if (&otherArg == &arg) { continue; } - if (argTable[otherInx]->GetRegNum() == REG_STK) + if (otherArg.AbiInfo.GetRegNum() == REG_STK) { treatLikeCall = true; break; @@ -1219,41 +818,40 @@ void fgArgInfo::ArgsComplete() { if (argCount > 1) // If this is not the only argument { - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } else if (varTypeIsFloating(argx->TypeGet()) && (argx->OperGet() == GT_CALL)) { // Spill all arguments that are floating point calls - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } // All previous arguments may need to be evaluated into temps - for (unsigned prevInx = 0; prevInx < curInx; prevInx++) + for (CallArg& prevArg : Args()) { - fgArgTabEntry* prevArgTabEntry = argTable[prevInx]; - assert(prevArgTabEntry->argNum < curArgTabEntry->argNum); + if (&prevArg == &arg) + { + break; + } // For all previous arguments, if they have any GTF_ALL_EFFECT // we require that they be evaluated into a temp - if ((prevArgTabEntry->GetNode()->gtFlags & GTF_ALL_EFFECT) != 0) + if ((prevArg.GetNode()->gtFlags & GTF_ALL_EFFECT) != 0) { - prevArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&prevArg); } #if FEATURE_FIXED_OUT_ARGS // Or, if they are stored into the FIXED_OUT_ARG area // we require that they be moved to the gtCallLateArgs // and replaced with a placeholder node - else if (prevArgTabEntry->GetRegNum() == REG_STK) + else if (prevArg.AbiInfo.GetRegNum() == REG_STK) { - prevArgTabEntry->needPlace = true; + prevArg.m_needPlace = true; } #if FEATURE_ARG_SPLIT - else if (prevArgTabEntry->IsSplit()) + else if (prevArg.AbiInfo.IsSplit()) { - prevArgTabEntry->needPlace = true; + prevArg.m_needPlace = true; } #endif // FEATURE_ARG_SPLIT #endif @@ -1267,29 +865,27 @@ void fgArgInfo::ArgsComplete() CLANG_FORMAT_COMMENT_ANCHOR; #ifdef TARGET_ARM bool isMultiRegArg = - (curArgTabEntry->numRegs > 0) && (curArgTabEntry->numRegs + curArgTabEntry->GetStackSlotsNumber() > 1); + (arg.AbiInfo.NumRegs > 0) && (arg.AbiInfo.NumRegs + arg.AbiInfo.GetStackSlotsNumber() > 1); #else - bool isMultiRegArg = (curArgTabEntry->numRegs > 1); + bool isMultiRegArg = (arg.AbiInfo.NumRegs > 1); #endif - if ((varTypeIsStruct(argx->TypeGet())) && (curArgTabEntry->needTmp == false)) + if (varTypeIsStruct(argx->TypeGet()) && !arg.m_needTmp) { if (isMultiRegArg && ((argx->gtFlags & GTF_PERSISTENT_SIDE_EFFECTS) != 0)) { // Spill multireg struct arguments that have Assignments or Calls embedded in them - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } else { // We call gtPrepareCost to measure the cost of evaluating this tree - compiler->gtPrepareCost(argx); + comp->gtPrepareCost(argx); if (isMultiRegArg && (argx->GetCostEx() > (6 * IND_COST_EX))) { // Spill multireg struct arguments that are expensive to evaluate twice - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } #if defined(FEATURE_SIMD) && defined(TARGET_ARM64) else if (isMultiRegArg && varTypeIsSIMD(argx->TypeGet())) @@ -1299,8 +895,7 @@ void fgArgInfo::ArgsComplete() (argx->OperIs(GT_OBJ) && argx->AsObj()->gtOp1->OperIs(GT_ADDR) && argx->AsObj()->gtOp1->AsOp()->gtOp1->OperIsSimdOrHWintrinsic())) { - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } } #endif @@ -1325,8 +920,7 @@ void fgArgInfo::ArgsComplete() // If we don't have a LclVar we need to read exactly 3,5,6 or 7 bytes // For now we use a a GT_CPBLK to copy the exact size into a GT_LCL_VAR temp. // - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } break; case 11: @@ -1342,8 +936,7 @@ void fgArgInfo::ArgsComplete() // Then we can just load all 16 bytes of the GT_LCL_VAR temp when passing // the argument. // - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); break; default: @@ -1360,7 +953,7 @@ void fgArgInfo::ArgsComplete() // if we don't have qmarks, then it doesn't matter. // So check for Qmark's globally once here, instead of inside the loop. // - const bool hasStructRegArgWeCareAbout = (hasStructRegArg && compiler->compQmarkUsed); + const bool hasStructRegArgWeCareAbout = (hasStructRegArg && comp->compQmarkUsed); #if FEATURE_FIXED_OUT_ARGS @@ -1368,11 +961,11 @@ void fgArgInfo::ArgsComplete() // argument that uses GT_LCLHEAP. This is an optimization to // save a check inside the below loop. // - const bool hasStackArgsWeCareAbout = (hasStackArgs && compiler->compLocallocUsed); + const bool hasStackArgsWeCareAbout = (m_hasStackArgs && comp->compLocallocUsed); #else - const bool hasStackArgsWeCareAbout = hasStackArgs; + const bool hasStackArgsWeCareAbout = m_hasStackArgs; #endif // FEATURE_FIXED_OUT_ARGS @@ -1385,15 +978,13 @@ void fgArgInfo::ArgsComplete() // if (hasStackArgsWeCareAbout || hasStructRegArgWeCareAbout) { - for (unsigned curInx = 0; curInx < argCount; curInx++) + for (CallArg& arg : Args()) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; - assert(curArgTabEntry != nullptr); - GenTree* argx = curArgTabEntry->GetNode(); + GenTree* argx = arg.GetNode(); // Examine the register args that are currently not marked needTmp // - if (!curArgTabEntry->needTmp && (curArgTabEntry->GetRegNum() != REG_STK)) + if (!arg.m_needTmp && (arg.AbiInfo.GetRegNum() != REG_STK)) { if (hasStackArgsWeCareAbout) { @@ -1406,8 +997,7 @@ void fgArgInfo::ArgsComplete() // if (argx->gtFlags & GTF_EXCEPT) { - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); continue; } #else @@ -1415,14 +1005,13 @@ void fgArgInfo::ArgsComplete() // if (argx->gtFlags & GTF_EXCEPT) { - assert(compiler->compLocallocUsed); + assert(comp->compLocallocUsed); // Returns WALK_ABORT if a GT_LCLHEAP node is encountered in the argx tree // - if (compiler->fgWalkTreePre(&argx, Compiler::fgChkLocAllocCB) == Compiler::WALK_ABORT) + if (comp->fgWalkTreePre(&argx, Compiler::fgChkLocAllocCB) == Compiler::WALK_ABORT) { - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); continue; } } @@ -1432,10 +1021,9 @@ void fgArgInfo::ArgsComplete() { // Returns true if a GT_QMARK node is encountered in the argx tree // - if (compiler->fgWalkTreePre(&argx, Compiler::fgChkQmarkCB) == Compiler::WALK_ABORT) + if (comp->fgWalkTreePre(&argx, Compiler::fgChkQmarkCB) == Compiler::WALK_ABORT) { - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); continue; } } @@ -1448,58 +1036,70 @@ void fgArgInfo::ArgsComplete() // effectively null-check 'this', which should happen only after all // arguments are evaluated. Thus we must evaluate all args with side // effects to a temp. - if (compiler->opts.IsCFGEnabled() && (callTree->IsVirtualVtable() || callTree->IsDelegateInvoke())) + if (comp->opts.IsCFGEnabled() && (call->IsVirtualVtable() || call->IsDelegateInvoke())) { // Always evaluate 'this' to temp. - argTable[0]->needTmp = true; - needsTemps = true; + assert(HasThisPointer()); + SetNeedsTemp(GetThisArg()); - for (unsigned curInx = 1; curInx < argCount; curInx++) + for (CallArg& arg : Args()) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; - GenTree* arg = curArgTabEntry->GetNode(); - if ((arg->gtFlags & GTF_ALL_EFFECT) != 0) + if ((arg.GetNode()->gtFlags & GTF_ALL_EFFECT) != 0) { - curArgTabEntry->needTmp = true; - needsTemps = true; + SetNeedsTemp(&arg); } } } - argsComplete = true; + m_argsComplete = true; } -void fgArgInfo::SortArgs() +void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) { - assert(argsComplete == true); + assert(m_argsComplete); #ifdef DEBUG - if (compiler->verbose) + if (comp->verbose) { printf("\nSorting the arguments:\n"); } #endif - /* Shuffle the arguments around before we build the gtCallLateArgs list. - The idea is to move all "simple" arguments like constants and local vars - to the end of the table, and move the complex arguments towards the beginning - of the table. This will help prevent registers from being spilled by - allowing us to evaluate the more complex arguments before the simpler arguments. - The argTable ends up looking like: - +------------------------------------+ <--- argTable[argCount - 1] - | constants | - +------------------------------------+ - | local var / local field | - +------------------------------------+ - | remaining arguments sorted by cost | - +------------------------------------+ - | temps (argTable[].needTmp = true) | - +------------------------------------+ - | args with calls (GTF_CALL) | - +------------------------------------+ <--- argTable[0] - */ + // Shuffle the arguments around before we build the late args list. The + // idea is to move all "simple" arguments like constants and local vars to + // the end, and move the complex arguments towards the beginning. This will + // help prevent registers from being spilled by allowing us to evaluate the + // more complex arguments before the simpler arguments. We use the late + // list to keep the sorted result at this point, and the ordering ends up + // looking like: + // +------------------------------------+ <--- end + // | constants | + // +------------------------------------+ + // | local var / local field | + // +------------------------------------+ + // | remaining arguments sorted by cost | + // +------------------------------------+ + // | temps (argTable[].needTmp = true) | + // +------------------------------------+ + // | args with calls (GTF_CALL) | + // +------------------------------------+ <--- m_lateHead + // + + unsigned argCount = CountArgs(); + CallArg* table[32]; + CallArg** argTable = table; + if (argCount > 32) + { + argTable = new (comp, CMK_fgArgInfo) CallArg*[argCount]; + } + + argCount = 0; + for (CallArg& arg : Args()) + { + argTable[argCount++] = &arg; + } - /* Set the beginning and end for the new argument table */ + // Set the beginning and end for the new argument table unsigned curInx; int regCount = 0; unsigned begTab = 0; @@ -1514,20 +1114,20 @@ void fgArgInfo::SortArgs() { curInx--; - fgArgTabEntry* curArgTabEntry = argTable[curInx]; + CallArg* arg = argTable[curInx]; - if (curArgTabEntry->GetRegNum() != REG_STK) + if (arg->AbiInfo.GetRegNum() != REG_STK) { regCount++; } - assert(curArgTabEntry->lateUse == nullptr); + assert(arg->GetLateNode() == nullptr); // Skip any already processed args // - if (!curArgTabEntry->processed) + if (!arg->m_processed) { - GenTree* argx = curArgTabEntry->GetNode(); + GenTree* argx = arg->GetNode(); // put constants at the end of the table // @@ -1535,14 +1135,14 @@ void fgArgInfo::SortArgs() { noway_assert(curInx <= endTab); - curArgTabEntry->processed = true; + arg->m_processed = true; // place curArgTabEntry at the endTab position by performing a swap // if (curInx != endTab) { argTable[curInx] = argTable[endTab]; - argTable[endTab] = curArgTabEntry; + argTable[endTab] = arg; } endTab--; @@ -1558,26 +1158,26 @@ void fgArgInfo::SortArgs() // for (curInx = begTab; curInx <= endTab; curInx++) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; + CallArg* arg = argTable[curInx]; // Skip any already processed args // - if (!curArgTabEntry->processed) + if (!arg->m_processed) { - GenTree* argx = curArgTabEntry->GetNode(); + GenTree* argx = arg->GetNode(); // put calls at the beginning of the table // if (argx->gtFlags & GTF_CALL) { - curArgTabEntry->processed = true; + arg->m_processed = true; // place curArgTabEntry at the begTab position by performing a swap // if (curInx != begTab) { argTable[curInx] = argTable[begTab]; - argTable[begTab] = curArgTabEntry; + argTable[begTab] = arg; } begTab++; @@ -1598,22 +1198,22 @@ void fgArgInfo::SortArgs() // for (curInx = begTab; curInx <= endTab; curInx++) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; + CallArg* arg = argTable[curInx]; // Skip any already processed args // - if (!curArgTabEntry->processed) + if (!arg->m_processed) { - if (curArgTabEntry->needTmp) + if (arg->m_needTmp) { - curArgTabEntry->processed = true; + arg->m_processed = true; // place curArgTabEntry at the begTab position by performing a swap // if (curInx != begTab) { argTable[curInx] = argTable[begTab]; - argTable[begTab] = curArgTabEntry; + argTable[begTab] = arg; } begTab++; @@ -1634,26 +1234,26 @@ void fgArgInfo::SortArgs() { curInx--; - fgArgTabEntry* curArgTabEntry = argTable[curInx]; + CallArg* arg = argTable[curInx]; // Skip any already processed args // - if (!curArgTabEntry->processed) + if (!arg->m_processed) { - GenTree* argx = curArgTabEntry->GetNode(); + GenTree* argx = arg->GetNode(); if ((argx->gtOper == GT_LCL_VAR) || (argx->gtOper == GT_LCL_FLD)) { noway_assert(curInx <= endTab); - curArgTabEntry->processed = true; + arg->m_processed = true; // place curArgTabEntry at the endTab position by performing a swap // if (curInx != endTab) { argTable[curInx] = argTable[endTab]; - argTable[endTab] = curArgTabEntry; + argTable[endTab] = arg; } endTab--; @@ -1670,21 +1270,21 @@ void fgArgInfo::SortArgs() { /* Find the most expensive arg remaining and evaluate it next */ - fgArgTabEntry* expensiveArgTabEntry = nullptr; - unsigned expensiveArg = UINT_MAX; + CallArg* expensiveArg = nullptr; + unsigned expensiveArgIndex = UINT_MAX; unsigned expensiveArgCost = 0; // [We use a forward iterator pattern] // for (curInx = begTab; curInx <= endTab; curInx++) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; + CallArg* arg = argTable[curInx]; // Skip any already processed args // - if (!curArgTabEntry->processed) + if (!arg->m_processed) { - GenTree* argx = curArgTabEntry->GetNode(); + GenTree* argx = arg->GetNode(); // We should have already handled these kinds of args assert(argx->gtOper != GT_LCL_VAR); @@ -1697,8 +1297,8 @@ void fgArgInfo::SortArgs() if (argsRemaining == 1) { // This is the last arg to place - expensiveArg = curInx; - expensiveArgTabEntry = curArgTabEntry; + expensiveArgIndex = curInx; + expensiveArg = arg; assert(begTab == endTab); break; } @@ -1707,32 +1307,32 @@ void fgArgInfo::SortArgs() if (!costsPrepared) { /* We call gtPrepareCost to measure the cost of evaluating this tree */ - compiler->gtPrepareCost(argx); + comp->gtPrepareCost(argx); } if (argx->GetCostEx() > expensiveArgCost) { // Remember this arg as the most expensive one that we have yet seen expensiveArgCost = argx->GetCostEx(); - expensiveArg = curInx; - expensiveArgTabEntry = curArgTabEntry; + expensiveArgIndex = curInx; + expensiveArg = arg; } } } } - noway_assert(expensiveArg != UINT_MAX); + noway_assert(expensiveArgIndex != UINT_MAX); // put the most expensive arg towards the beginning of the table - expensiveArgTabEntry->processed = true; + expensiveArg->m_processed = true; // place expensiveArgTabEntry at the begTab position by performing a swap // - if (expensiveArg != begTab) + if (expensiveArgIndex != begTab) { - argTable[expensiveArg] = argTable[begTab]; - argTable[begTab] = expensiveArgTabEntry; + argTable[expensiveArgIndex] = argTable[begTab]; + argTable[begTab] = expensiveArg; } begTab++; @@ -1746,19 +1346,15 @@ void fgArgInfo::SortArgs() assert(begTab == (endTab + 1)); assert(argsRemaining == 0); - argsSorted = true; -} - -#ifdef DEBUG -void fgArgInfo::Dump(Compiler* compiler) const -{ - for (unsigned curInx = 0; curInx < ArgCount(); curInx++) + CallArg** tail = &m_lateHead; + for (unsigned i = 0; i < argCount; i++) { - fgArgTabEntry* curArgEntry = ArgTable()[curInx]; - curArgEntry->Dump(); + *tail = argTable[i]; + tail = &(*tail)->LateNextRef(); } + + m_argsSorted = true; } -#endif //------------------------------------------------------------------------------ // fgMakeTmpArgNode : This function creates a tmp var only if needed. @@ -1766,20 +1362,21 @@ void fgArgInfo::Dump(Compiler* compiler) const // of the evaluation of arguments. // // Arguments: -// curArgTabEntry +// comp +// arg // // Return Value: // the newly created temp var tree. -GenTree* Compiler::fgMakeTmpArgNode(fgArgTabEntry* curArgTabEntry) +GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) { - unsigned tmpVarNum = curArgTabEntry->tmpNum; - LclVarDsc* varDsc = lvaGetDesc(tmpVarNum); + unsigned tmpVarNum = arg->m_tmpNum; + LclVarDsc* varDsc = comp->lvaGetDesc(tmpVarNum); assert(varDsc->lvIsTemp); var_types type = varDsc->TypeGet(); // Create a copy of the temp to go into the late argument list - GenTree* arg = gtNewLclvNode(tmpVarNum, type); + GenTree* argNode = comp->gtNewLclvNode(tmpVarNum, type); GenTree* addrNode = nullptr; if (varTypeIsStruct(type)) @@ -1792,21 +1389,21 @@ GenTree* Compiler::fgMakeTmpArgNode(fgArgTabEntry* curArgTabEntry) // Otherwise, it will return TYP_UNKNOWN and we will pass it as a struct type. bool passedAsPrimitive = false; - if (curArgTabEntry->TryPassAsPrimitive()) + if (arg->AbiInfo.TryPassAsPrimitive()) { CORINFO_CLASS_HANDLE clsHnd = varDsc->GetStructHnd(); var_types structBaseType = - getPrimitiveTypeForStruct(lvaLclExactSize(tmpVarNum), clsHnd, curArgTabEntry->IsVararg()); + comp->getPrimitiveTypeForStruct(comp->lvaLclExactSize(tmpVarNum), clsHnd, m_isVarArgs); if (structBaseType != TYP_UNKNOWN) { passedAsPrimitive = true; #if defined(UNIX_AMD64_ABI) - // TODO-Cleanup: This is inelegant, but eventually we'll track this in the fgArgTabEntry, + // TODO-Cleanup: This is inelegant, we should track this in the CallArgABIInformation, // and otherwise we'd have to either modify getPrimitiveTypeForStruct() to take // a structDesc or call eeGetSystemVAmd64PassStructInRegisterDescriptor yet again. // - if (genIsValidFloatReg(curArgTabEntry->GetRegNum())) + if (genIsValidFloatReg(arg->AbiInfo.GetRegNum())) { if (structBaseType == TYP_INT) { @@ -1827,32 +1424,32 @@ GenTree* Compiler::fgMakeTmpArgNode(fgArgTabEntry* curArgTabEntry) // field instead. It will be loaded in registers with putarg_reg tree in lower. if (passedAsPrimitive) { - arg->ChangeOper(GT_LCL_FLD); - arg->gtType = type; - lvaSetVarDoNotEnregister(tmpVarNum DEBUGARG(DoNotEnregisterReason::SwizzleArg)); + argNode->ChangeOper(GT_LCL_FLD); + argNode->gtType = type; + comp->lvaSetVarDoNotEnregister(tmpVarNum DEBUGARG(DoNotEnregisterReason::SwizzleArg)); } else { var_types addrType = TYP_BYREF; - arg = gtNewOperNode(GT_ADDR, addrType, arg); - lvaSetVarAddrExposed(tmpVarNum DEBUGARG(AddressExposedReason::ESCAPE_ADDRESS)); - addrNode = arg; + argNode = comp->gtNewOperNode(GT_ADDR, addrType, argNode); + comp->lvaSetVarAddrExposed(tmpVarNum DEBUGARG(AddressExposedReason::ESCAPE_ADDRESS)); + addrNode = argNode; #if FEATURE_MULTIREG_ARGS #ifdef TARGET_ARM64 assert(varTypeIsStruct(type)); - if (lvaIsMultiregStruct(varDsc, curArgTabEntry->IsVararg())) + if (comp->lvaIsMultiregStruct(varDsc, m_isVarArgs)) { // We will create a GT_OBJ for the argument below. // This will be passed by value in two registers. assert(addrNode != nullptr); // Create an Obj of the temp to use it as a call argument. - arg = gtNewObjNode(lvaGetStruct(tmpVarNum), arg); + argNode = comp->gtNewObjNode(comp->lvaGetStruct(tmpVarNum), argNode); } #else // Always create an Obj of the temp to use it as a call argument. - arg = gtNewObjNode(lvaGetStruct(tmpVarNum), arg); + argNode = comp->gtNewObjNode(comp->lvaGetStruct(tmpVarNum), argNode); #endif // !TARGET_ARM64 #endif // FEATURE_MULTIREG_ARGS } @@ -1862,11 +1459,11 @@ GenTree* Compiler::fgMakeTmpArgNode(fgArgTabEntry* curArgTabEntry) // other targets, we pass the struct by value assert(varTypeIsStruct(type)); - addrNode = gtNewOperNode(GT_ADDR, TYP_BYREF, arg); + addrNode = comp->gtNewOperNode(GT_ADDR, TYP_BYREF, argNode); // Get a new Obj node temp to use it as a call argument. // gtNewObjNode will set the GTF_EXCEPT flag if this is not a local stack object. - arg = gtNewObjNode(lvaGetStruct(tmpVarNum), addrNode); + argNode = comp->gtNewObjNode(comp->lvaGetStruct(tmpVarNum), addrNode); #endif // not (TARGET_AMD64 or TARGET_ARM64 or TARGET_ARM) @@ -1879,47 +1476,43 @@ GenTree* Compiler::fgMakeTmpArgNode(fgArgTabEntry* curArgTabEntry) addrNode->AsOp()->gtOp1->gtFlags |= GTF_DONT_CSE; } - return arg; + return argNode; } -//------------------------------------------------------------------------------ -// EvalArgsToTemps : Create temp assignments and populate the LateArgs list. - -void fgArgInfo::EvalArgsToTemps() +void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) { - assert(argsSorted); + assert(m_argsSorted); unsigned regArgInx = 0; - // Now go through the argument table and perform the necessary evaluation into temps - GenTreeCall::Use* tmpRegArgNext = nullptr; - for (unsigned curInx = 0; curInx < argCount; curInx++) + // Now go through the argument table and perform the necessary evaluation into temps. + // SortArgs stored the sorted result in the late list. + for (LateArg lateArg : LateArgs()) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; - - assert(curArgTabEntry->lateUse == nullptr); + CallArg& arg = *lateArg.GetArg(); + assert(arg.GetLateNode() == nullptr); - GenTree* argx = curArgTabEntry->GetNode(); + GenTree* argx = arg.GetNode(); GenTree* setupArg = nullptr; GenTree* defArg; #if !FEATURE_FIXED_OUT_ARGS // Only ever set for FEATURE_FIXED_OUT_ARGS - assert(curArgTabEntry->needPlace == false); + assert(arg.m_needPlace == false); // On x86 and other archs that use push instructions to pass arguments: // Only the register arguments need to be replaced with placeholder nodes. // Stacked arguments are evaluated and pushed (or stored into the stack) in order. // - if (curArgTabEntry->GetRegNum() == REG_STK) + if (arg.AbiInfo.GetRegNum() == REG_STK) continue; #endif - if (curArgTabEntry->needTmp) + if (arg.m_needTmp) { - if (curArgTabEntry->isTmp) + if (arg.m_isTmp) { // Create a copy of the temp to go into the late argument list - defArg = compiler->fgMakeTmpArgNode(curArgTabEntry); + defArg = MakeTmpArgNode(comp, &arg); // mark the original node as a late argument argx->gtFlags |= GTF_LATE_ARG; @@ -1931,10 +1524,10 @@ void fgArgInfo::EvalArgsToTemps() CLANG_FORMAT_COMMENT_ANCHOR; #ifdef DEBUG - if (compiler->verbose) + if (comp->verbose) { printf("Argument with 'side effect'...\n"); - compiler->gtDispTree(argx); + comp->gtDispTree(argx); } #endif @@ -1942,7 +1535,7 @@ void fgArgInfo::EvalArgsToTemps() noway_assert(argx->gtType != TYP_STRUCT); #endif - unsigned tmpVarNum = compiler->lvaGrabTemp(true DEBUGARG("argument with side effect")); + unsigned tmpVarNum = comp->lvaGrabTemp(true DEBUGARG("argument with side effect")); if (argx->gtOper == GT_MKREFANY) { // For GT_MKREFANY, typically the actual struct copying does @@ -1956,10 +1549,10 @@ void fgArgInfo::EvalArgsToTemps() // In the early argument evaluation, place an assignment to the temp // from the source operand of the mkrefany - setupArg = compiler->gtNewTempAssign(tmpVarNum, operand); + setupArg = comp->gtNewTempAssign(tmpVarNum, operand); // Replace the operand for the mkrefany with the new temp. - argx->AsOp()->gtOp1 = compiler->gtNewLclvNode(tmpVarNum, operand->TypeGet()); + argx->AsOp()->gtOp1 = comp->gtNewLclvNode(tmpVarNum, operand->TypeGet()); } else if ((argx->AsOp()->gtOp1->gtFlags & GTF_ALL_EFFECT) == 0) { @@ -1967,10 +1560,10 @@ void fgArgInfo::EvalArgsToTemps() // In the early argument evaluation, place an assignment to the temp // from the source operand of the mkrefany - setupArg = compiler->gtNewTempAssign(tmpVarNum, operand); + setupArg = comp->gtNewTempAssign(tmpVarNum, operand); // Replace the operand for the mkrefany with the new temp. - argx->AsOp()->gtOp2 = compiler->gtNewLclvNode(tmpVarNum, operand->TypeGet()); + argx->AsOp()->gtOp2 = comp->gtNewLclvNode(tmpVarNum, operand->TypeGet()); } } @@ -1984,25 +1577,25 @@ void fgArgInfo::EvalArgsToTemps() } else { - setupArg = compiler->gtNewTempAssign(tmpVarNum, argx); + setupArg = comp->gtNewTempAssign(tmpVarNum, argx); - LclVarDsc* varDsc = compiler->lvaGetDesc(tmpVarNum); + LclVarDsc* varDsc = comp->lvaGetDesc(tmpVarNum); var_types lclVarType = genActualType(argx->gtType); var_types scalarType = TYP_UNKNOWN; if (setupArg->OperIsCopyBlkOp()) { - setupArg = compiler->fgMorphCopyBlock(setupArg); + setupArg = comp->fgMorphCopyBlock(setupArg); #if defined(TARGET_ARMARCH) || defined(UNIX_AMD64_ABI) if (lclVarType == TYP_STRUCT) { // This scalar LclVar widening step is only performed for ARM architectures. // - CORINFO_CLASS_HANDLE clsHnd = compiler->lvaGetStruct(tmpVarNum); + CORINFO_CLASS_HANDLE clsHnd = comp->lvaGetStruct(tmpVarNum); unsigned structSize = varDsc->lvExactSize; scalarType = - compiler->getPrimitiveTypeForStruct(structSize, clsHnd, curArgTabEntry->IsVararg()); + comp->getPrimitiveTypeForStruct(structSize, clsHnd, m_isVarArgs); } #endif // TARGET_ARMARCH || defined (UNIX_AMD64_ABI) } @@ -2012,27 +1605,27 @@ void fgArgInfo::EvalArgsToTemps() if ((scalarType != TYP_UNKNOWN) && (scalarType != lclVarType)) { // Create a GT_LCL_FLD using the wider type to go to the late argument list - defArg = compiler->gtNewLclFldNode(tmpVarNum, scalarType, 0); + defArg = comp->gtNewLclFldNode(tmpVarNum, scalarType, 0); } else { // Create a copy of the temp to go to the late argument list - defArg = compiler->gtNewLclvNode(tmpVarNum, lclVarType); + defArg = comp->gtNewLclvNode(tmpVarNum, lclVarType); } - curArgTabEntry->isTmp = true; - curArgTabEntry->tmpNum = tmpVarNum; + arg.m_isTmp = true; + arg.m_tmpNum = tmpVarNum; #ifdef TARGET_ARM // Previously we might have thought the local was promoted, and thus the 'COPYBLK' // might have left holes in the used registers (see // fgAddSkippedRegsInPromotedStructArg). // Too bad we're not that smart for these intermediate temps... - if (isValidIntArgReg(curArgTabEntry->GetRegNum()) && (curArgTabEntry->numRegs > 1)) + if (isValidIntArgReg(arg.AbiInfo.GetRegNum()) && (arg.AbiInfo.NumRegs > 1)) { - regNumber argReg = curArgTabEntry->GetRegNum(); - regMaskTP allUsedRegs = genRegMask(curArgTabEntry->GetRegNum()); - for (unsigned i = 1; i < curArgTabEntry->numRegs; i++) + regNumber argReg = arg.AbiInfo.GetRegNum(); + regMaskTP allUsedRegs = genRegMask(arg.AbiInfo.GetRegNum()); + for (unsigned i = 1; i < arg.AbiInfo.NumRegs; i++) { argReg = genRegArgNext(argReg); allUsedRegs |= genRegMask(argReg); @@ -2045,10 +1638,10 @@ void fgArgInfo::EvalArgsToTemps() setupArg->gtFlags |= GTF_LATE_ARG; #ifdef DEBUG - if (compiler->verbose) + if (comp->verbose) { printf("\n Evaluate to a temp:\n"); - compiler->gtDispTree(setupArg); + comp->gtDispTree(setupArg); } #endif } @@ -2065,7 +1658,7 @@ void fgArgInfo::EvalArgsToTemps() // this argument so we have to replace it in the gtCallArgs list // (the initial argument evaluation list) with a placeholder. // - if ((curArgTabEntry->GetRegNum() == REG_STK) && (curArgTabEntry->needPlace == false)) + if ((arg.AbiInfo.GetRegNum() == REG_STK) && !arg.m_needPlace) { continue; } @@ -2091,82 +1684,81 @@ void fgArgInfo::EvalArgsToTemps() if (defArg->TypeGet() == TYP_STRUCT) { - clsHnd = compiler->gtGetStructHandleIfPresent(defArg); + clsHnd = comp->gtGetStructHandleIfPresent(defArg); noway_assert(clsHnd != NO_CLASS_HANDLE); } #endif // !(defined(TARGET_AMD64) && !defined(UNIX_AMD64_ABI)) - setupArg = compiler->gtNewArgPlaceHolderNode(defArg->gtType, clsHnd); + setupArg = comp->gtNewArgPlaceHolderNode(defArg->gtType, clsHnd); /* mark the placeholder node as a late argument */ setupArg->gtFlags |= GTF_LATE_ARG; #ifdef DEBUG - if (compiler->verbose) + if (comp->verbose) { - if (curArgTabEntry->GetRegNum() == REG_STK) + if (arg.AbiInfo.GetRegNum() == REG_STK) { printf("Deferred stack argument :\n"); } else { - printf("Deferred argument ('%s'):\n", getRegName(curArgTabEntry->GetRegNum())); + printf("Deferred argument ('%s'):\n", getRegName(arg.AbiInfo.GetRegNum())); } - compiler->gtDispTree(argx); + comp->gtDispTree(argx); printf("Replaced with placeholder node:\n"); - compiler->gtDispTree(setupArg); + comp->gtDispTree(setupArg); } #endif } if (setupArg != nullptr) { - noway_assert(curArgTabEntry->use->GetNode() == argx); - curArgTabEntry->use->SetNode(setupArg); + noway_assert(arg.GetNode() == argx); + arg.SetNode(setupArg); } - /* deferred arg goes into the late argument list */ + arg.SetLateNode(defArg); + } - if (tmpRegArgNext == nullptr) + // We used the late list to store sorted nodes. However not all arg may + // need to get late nodes, so unlink the arguments that do not. + CallArg** link = &m_lateHead; + while (*link != nullptr) + { + if ((*link)->GetLateNode() == nullptr) { - tmpRegArgNext = compiler->gtNewCallArgs(defArg); - callTree->AsCall()->gtCallLateArgs = tmpRegArgNext; + *link = (*link)->GetLateNext(); } else { - noway_assert(tmpRegArgNext->GetNode() != nullptr); - tmpRegArgNext->SetNext(compiler->gtNewCallArgs(defArg)); - - tmpRegArgNext = tmpRegArgNext->GetNext(); - } - - curArgTabEntry->lateUse = tmpRegArgNext; - curArgTabEntry->SetLateArgInx(regArgInx++); - - if ((setupArg != nullptr) && setupArg->OperIs(GT_ARGPLACE) && (callTree->gtRetBufArg == curArgTabEntry->use)) - { - callTree->SetLclRetBufArg(tmpRegArgNext); + link = &(*link)->LateNextRef(); } } #ifdef DEBUG - if (compiler->verbose) + if (comp->verbose) { printf("\nShuffled argument table: "); - for (unsigned curInx = 0; curInx < argCount; curInx++) + for (LateArg arg : LateArgs()) { - fgArgTabEntry* curArgTabEntry = argTable[curInx]; - - if (curArgTabEntry->GetRegNum() != REG_STK) + if (arg.GetArg()->AbiInfo.GetRegNum() != REG_STK) { - printf("%s ", getRegName(curArgTabEntry->GetRegNum())); + printf("%s ", getRegName(arg.GetArg()->AbiInfo.GetRegNum())); } } printf("\n"); } #endif + +} + +void CallArgs::SetNeedsTemp(CallArg* arg) +{ + arg->m_needTmp = true; + m_needsTemps = true; } //------------------------------------------------------------------------------ @@ -2247,36 +1839,16 @@ GenTree* Compiler::fgInsertCommaFormTemp(GenTree** ppTree, CORINFO_CLASS_HANDLE return new (this, GT_LCL_VAR) GenTreeLclVar(GT_LCL_VAR, subTree->TypeGet(), lclNum); } -//------------------------------------------------------------------------ -// fgInitArgInfo: Construct the fgArgInfo for the call with the fgArgEntry for each arg -// -// Arguments: -// callNode - the call for which we are generating the fgArgInfo -// -// Return Value: -// None -// -// Notes: -// This method is idempotent in that it checks whether the fgArgInfo has already been -// constructed, and just returns. -// This method only computes the arg table and arg entries for the call (the fgArgInfo), -// and makes no modification of the args themselves. -// -// The IR for the call args can change for calls with non-standard arguments: some non-standard -// arguments add new call argument IR nodes. -// -void Compiler::fgInitArgInfo(GenTreeCall* call) +void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) { - GenTreeCall::Use* args; - GenTree* argx; - + assert(&call->gtArgs == this); unsigned argIndex = 0; unsigned intArgRegNum = 0; unsigned fltArgRegNum = 0; - DEBUG_ARG_SLOTS_ONLY(unsigned argSlots = 0;) + unsigned nextSlotNum = INIT_ARG_STACK_SLOT; - bool callHasRetBuffArg = call->HasRetBufArg(); - bool callIsVararg = call->IsVarargs(); + bool callHasRetBuffArg = HasRetBuffer(); + bool callIsVararg = IsVarArgs(); #ifdef TARGET_ARM regMaskTP argSkippedRegMask = RBM_NONE; @@ -2289,15 +1861,18 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) const unsigned maxRegArgs = MAX_REG_ARG; // other arch: fixed constant number #endif - if (call->fgArgInfo != nullptr) + if (IsAbiInformationDetermined()) { - // We've already initialized and set the fgArgInfo. + // We've already determined ABI information. return; } JITDUMP("Initializing arg info for %d.%s:\n", call->gtTreeID, GenTree::OpName(call->gtOper)); - // At this point, we should never have gtCallLateArgs, as this needs to be done before those are determined. - assert(call->gtCallLateArgs == nullptr); + m_nextStackByteOffset = INIT_ARG_STACK_SLOT * TARGET_POINTER_SIZE; + m_hasRegArgs = false; + m_hasStackArgs = false; + // At this point, we should not have any late args, as this needs to be done before those are determined. + assert(m_lateHead == nullptr); if (TargetOS::IsUnix && callIsVararg) { @@ -2309,127 +1884,6 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) NYI("Morphing Vararg call not yet implemented on non Windows targets."); } - // Data structure for keeping track of non-standard args. Non-standard args are those that are not passed - // following the normal calling convention or in the normal argument registers. We either mark existing - // arguments as non-standard (such as the x8 return buffer register on ARM64), or we manually insert the - // non-standard arguments into the argument list, below. - class NonStandardArgs - { - struct NonStandardArg - { - GenTree* node; // The tree node representing this non-standard argument. - // Note that this must be updated if the tree node changes due to morphing! - regNumber reg; // The register to be assigned to this non-standard argument. - NonStandardArgKind kind; // The kind of the non-standard arg - }; - - ArrayStack args; - - public: - NonStandardArgs(CompAllocator alloc) : args(alloc, 3) // We will have at most 3 non-standard arguments - { - } - - //----------------------------------------------------------------------------- - // Add: add a non-standard argument to the table of non-standard arguments - // - // Arguments: - // node - a GenTree node that has a non-standard argument. - // reg - the register to assign to this node. - // - // Return Value: - // None. - // - void Add(GenTree* node, regNumber reg, NonStandardArgKind kind) - { - NonStandardArg nsa = {node, reg, kind}; - args.Push(nsa); - } - - //----------------------------------------------------------------------------- - // Find: Look for a GenTree* in the set of non-standard args. - // - // Arguments: - // node - a GenTree node to look for - // - // Return Value: - // The index of the non-standard argument (a non-negative, unique, stable number). - // If the node is not a non-standard argument, return -1. - // - int Find(GenTree* node) - { - for (int i = 0; i < args.Height(); i++) - { - if (node == args.Top(i).node) - { - return i; - } - } - return -1; - } - - //----------------------------------------------------------------------------- - // Find: Look for a GenTree node in the non-standard arguments set. If found, - // set the register to use for the node. - // - // Arguments: - // node - a GenTree node to look for - // pReg - an OUT argument. *pReg is set to the non-standard register to use if - // 'node' is found in the non-standard argument set. - // pKind - an OUT argument. *pKind is set to the kind of the non-standard arg. - // - // Return Value: - // 'true' if 'node' is a non-standard argument. In this case, *pReg and *pKing are set. - // 'false' otherwise (in this case, *pReg and *pKind are unmodified). - // - bool Find(GenTree* node, regNumber* pReg, NonStandardArgKind* pKind) - { - for (int i = 0; i < args.Height(); i++) - { - NonStandardArg& nsa = args.TopRef(i); - if (node == nsa.node) - { - *pReg = nsa.reg; - *pKind = nsa.kind; - return true; - } - } - return false; - } - - //----------------------------------------------------------------------------- - // Replace: Replace the non-standard argument node at a given index. This is done when - // the original node was replaced via morphing, but we need to continue to assign a - // particular non-standard arg to it. - // - // Arguments: - // index - the index of the non-standard arg. It must exist. - // node - the new GenTree node. - // - // Return Value: - // None. - // - void Replace(int index, GenTree* node) - { - args.TopRef(index).node = node; - } - - } nonStandardArgs(getAllocator(CMK_ArrayStack)); - - // Count of args. On first morph, this is counted before we've filled in the arg table. - // On remorph, we grab it from the arg table. - unsigned numArgs = 0; - - // First we need to count the args - if (call->gtCallThisArg != nullptr) - { - numArgs++; - } - for (GenTreeCall::Use& use : call->Args()) - { - numArgs++; - } - // Insert or mark non-standard args. These are either outside the normal calling convention, or // arguments registers that don't follow the normal progression of argument registers in the calling // convention (such as for the ARM64 fixed return buffer argument x8). @@ -2440,17 +1894,6 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) // *********** END NOTE ********* CLANG_FORMAT_COMMENT_ANCHOR; -#if defined(TARGET_X86) || defined(TARGET_ARM) - // The x86 and arm32 CORINFO_HELP_INIT_PINVOKE_FRAME helpers has a custom calling convention. - // Set the argument registers correctly here. - if (call->IsHelperCall(this, CORINFO_HELP_INIT_PINVOKE_FRAME)) - { - GenTreeCall::Use* args = call->gtCallArgs; - GenTree* arg1 = args->GetNode(); - assert(arg1 != nullptr); - nonStandardArgs.Add(arg1, REG_PINVOKE_FRAME, NonStandardArgKind::PInvokeFrame); - } -#endif // defined(TARGET_X86) || defined(TARGET_ARM) #if defined(TARGET_ARM) // A non-standard calling convention using wrapper delegate invoke is used on ARM, only, for wrapper // delegates. It is used for VSD delegate calls where the VSD custom calling convention ABI requires passing @@ -2458,77 +1901,36 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) // to be preserved. Thus, the VM uses a wrapper delegate IL stub, which preserves R4 and also sets up R4 // correctly for the VSD call. The VM is simply reusing an existing mechanism (wrapper delegate IL stub) // to achieve its goal for delegate VSD call. See COMDelegate::NeedsWrapperDelegate() in the VM for details. - else if (call->gtCallMoreFlags & GTF_CALL_M_WRAPPER_DELEGATE_INV) + if (call->gtCallMoreFlags & GTF_CALL_M_WRAPPER_DELEGATE_INV) { - GenTree* arg = call->gtCallThisArg->GetNode(); - if (arg->OperIsLocal()) + CallArg* thisArg = GetThisArg(); + assert(thisArg != nullptr); + + GenTree* cloned; + if (thisArg->GetNode()->OperIsLocal()) { - arg = gtClone(arg, true); + cloned = comp->gtClone(thisArg->GetNode(), true); } else { - GenTree* tmp = fgInsertCommaFormTemp(&arg); - call->gtCallThisArg->SetNode(arg); + cloned = comp->fgInsertCommaFormTemp(&thisArg->NodeRef()); call->gtFlags |= GTF_ASG; - arg = tmp; } - noway_assert(arg != nullptr); + noway_assert(cloned != nullptr); - GenTree* newArg = new (this, GT_ADDR) - GenTreeAddrMode(TYP_BYREF, arg, nullptr, 0, eeGetEEInfo()->offsetOfWrapperDelegateIndirectCell); + GenTree* newArg = new (comp, GT_ADDR) + GenTreeAddrMode(TYP_BYREF, cloned, nullptr, 0, comp->eeGetEEInfo()->offsetOfWrapperDelegateIndirectCell); // Append newArg as the last arg - GenTreeCall::Use** insertionPoint = &call->gtCallArgs; - for (; *insertionPoint != nullptr; insertionPoint = &((*insertionPoint)->NextRef())) - { - } - *insertionPoint = gtNewCallArgs(newArg); - - numArgs++; - nonStandardArgs.Add(newArg, virtualStubParamInfo->GetReg(), NonStandardArgKind::WrapperDelegateCell); + PushBack(comp, newArg, WellKnownArg::WrapperDelegateCell); } #endif // defined(TARGET_ARM) -#if defined(TARGET_X86) - // The x86 shift helpers have custom calling conventions and expect the lo part of the long to be in EAX and the - // hi part to be in EDX. This sets the argument registers up correctly. - else if (call->IsHelperCall(this, CORINFO_HELP_LLSH) || call->IsHelperCall(this, CORINFO_HELP_LRSH) || - call->IsHelperCall(this, CORINFO_HELP_LRSZ)) - { - GenTreeCall::Use* args = call->gtCallArgs; - GenTree* arg1 = args->GetNode(); - assert(arg1 != nullptr); - nonStandardArgs.Add(arg1, REG_LNGARG_LO, NonStandardArgKind::ShiftLow); - - args = args->GetNext(); - GenTree* arg2 = args->GetNode(); - assert(arg2 != nullptr); - nonStandardArgs.Add(arg2, REG_LNGARG_HI, NonStandardArgKind::ShiftHigh); - } -#else // !TARGET_X86 +#ifndef TARGET_X86 // TODO-X86-CQ: Currently RyuJIT/x86 passes args on the stack, so this is not needed. // If/when we change that, the following code needs to be changed to correctly support the (TBD) managed calling // convention for x86/SSE. - // If we have a Fixed Return Buffer argument register then we setup a non-standard argument for it. - // - // We don't use the fixed return buffer argument if we have the special unmanaged instance call convention. - // That convention doesn't use the fixed return buffer register. - // - CLANG_FORMAT_COMMENT_ANCHOR; - - if (call->HasFixedRetBufArg()) - { - args = call->gtCallArgs; - assert(args != nullptr); - - argx = call->gtCallArgs->GetNode(); - - // We don't increment numArgs here, since we already counted this argument above. - - nonStandardArgs.Add(argx, theFixedRetBuffReg(), NonStandardArgKind::FixedRetBuffer); - } - - // We are allowed to have a Fixed Return Buffer argument combined + // We are allowed to have a ret buffer argument combined // with any of the remaining non-standard arguments // CLANG_FORMAT_COMMENT_ANCHOR; @@ -2537,12 +1939,9 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) { if (!call->IsTailCallViaJitHelper()) { - GenTree* stubAddrArg = fgGetStubAddrArg(call); + GenTree* stubAddrArg = comp->fgGetStubAddrArg(call); // And push the stub address onto the list of arguments - call->gtCallArgs = gtPrependNewCallArg(stubAddrArg, call->gtCallArgs); - - numArgs++; - nonStandardArgs.Add(stubAddrArg, stubAddrArg->GetRegNum(), NonStandardArgKind::VirtualStubCell); + InsertAfterThisOrFirst(comp, stubAddrArg, WellKnownArg::VirtualStubCell); } else { @@ -2563,21 +1962,14 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) call->gtCallCookie = nullptr; // All architectures pass the cookie in a register. - call->gtCallArgs = gtPrependNewCallArg(arg, call->gtCallArgs); - - nonStandardArgs.Add(arg, REG_PINVOKE_COOKIE_PARAM, NonStandardArgKind::PInvokeCookie); - numArgs++; - + InsertAfterThisOrFirst(comp, arg, WellKnownArg::PInvokeCookie); // put destination into R10/EAX - arg = gtClone(call->gtCallAddr, true); - call->gtCallArgs = gtPrependNewCallArg(arg, call->gtCallArgs); - numArgs++; - - nonStandardArgs.Add(arg, REG_PINVOKE_TARGET_PARAM, NonStandardArgKind::PInvokeTarget); + arg = comp->gtClone(call->gtCallAddr, true); + InsertAfterThisOrFirst(comp, arg, WellKnownArg::PInvokeTarget); // finally change this call to a helper call call->gtCallType = CT_HELPER; - call->gtCallMethHnd = eeFindHelper(CORINFO_HELP_PINVOKE_CALLI); + call->gtCallMethHnd = comp->eeFindHelper(CORINFO_HELP_PINVOKE_CALLI); } #if defined(FEATURE_READYTORUN) // For arm/arm64, we dispatch code same as VSD using virtualStubParamInfo->GetReg() @@ -2598,7 +1990,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) assert(call->gtEntryPoint.addr != nullptr); size_t addrValue = (size_t)call->gtEntryPoint.addr; - GenTree* indirectCellAddress = gtNewIconHandleNode(addrValue, GTF_ICON_FTN_ADDR); + GenTree* indirectCellAddress = comp->gtNewIconHandleNode(addrValue, GTF_ICON_FTN_ADDR); #ifdef DEBUG indirectCellAddress->AsIntCon()->gtTargetHandle = (size_t)call->gtCallMethHnd; #endif @@ -2612,56 +2004,11 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) #endif // TARGET_ARM // Push the stub address onto the list of arguments. - call->gtCallArgs = gtPrependNewCallArg(indirectCellAddress, call->gtCallArgs); - - numArgs++; - nonStandardArgs.Add(indirectCellAddress, indirectCellAddress->GetRegNum(), - NonStandardArgKind::R2RIndirectionCell); + InsertAfterThisOrFirst(comp, indirectCellAddress, WellKnownArg::R2RIndirectionCell); } #endif - if ((REG_VALIDATE_INDIRECT_CALL_ADDR != REG_ARG_0) && call->IsHelperCall(this, CORINFO_HELP_VALIDATE_INDIRECT_CALL)) - { - assert(call->gtCallArgs != nullptr); - GenTreeCall::Use* args = call->gtCallArgs; - GenTree* tar = args->GetNode(); - nonStandardArgs.Add(tar, REG_VALIDATE_INDIRECT_CALL_ADDR, NonStandardArgKind::ValidateIndirectCallTarget); - } - - // Allocate the fgArgInfo for the call node; - // - call->fgArgInfo = new (this, CMK_Unknown) fgArgInfo(this, call, numArgs); - - // Add the 'this' argument value, if present. - if (call->gtCallThisArg != nullptr) - { - argx = call->gtCallThisArg->GetNode(); - assert(argIndex == 0); - assert(call->gtCallType == CT_USER_FUNC || call->gtCallType == CT_INDIRECT); - assert(varTypeIsGC(argx) || (argx->gtType == TYP_I_IMPL)); - - const regNumber regNum = genMapIntRegArgNumToRegNum(intArgRegNum); - const unsigned numRegs = 1; - const unsigned byteSize = TARGET_POINTER_SIZE; - const unsigned byteAlignment = TARGET_POINTER_SIZE; - const bool isStruct = false; - const bool isFloatHfa = false; - - // This is a register argument - put it in the table. - call->fgArgInfo->AddRegArg(argIndex, argx, call->gtCallThisArg, regNum, numRegs, byteSize, byteAlignment, - isStruct, isFloatHfa, - callIsVararg UNIX_AMD64_ABI_ONLY_ARG(REG_STK) UNIX_AMD64_ABI_ONLY_ARG(0) - UNIX_AMD64_ABI_ONLY_ARG(0) UNIX_AMD64_ABI_ONLY_ARG(nullptr)); - - intArgRegNum++; -#ifdef WINDOWS_AMD64_ABI - // Whenever we pass an integer register argument - // we skip the corresponding floating point register argument - fltArgRegNum++; -#endif // WINDOWS_AMD64_ABI - argIndex++; - DEBUG_ARG_SLOTS_ONLY(argSlots++;) - } + unsigned numArgs = CountArgs(); #ifdef TARGET_X86 // Compute the maximum number of arguments that can be passed in registers. @@ -2674,6 +2021,9 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) // No more register arguments for varargs (CALL_POP_ARGS) maxRegArgs = intArgRegNum; + // Add in this arg + if (HasThisPointer()) + maxRegArgs++; // Add in the ret buff arg if (callHasRetBuffArg) maxRegArgs++; @@ -2686,9 +2036,9 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) if (call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) { - noway_assert(call->gtCallArgs->GetNode()->TypeGet() == TYP_I_IMPL || - call->gtCallArgs->GetNode()->TypeGet() == TYP_BYREF || - call->gtCallArgs->GetNode()->gtOper == + noway_assert(call->gtArgs.GetArgByIndex(0)->GetNode()->TypeGet() == TYP_I_IMPL || + call->gtArgs.GetArgByIndex(0)->GetNode()->TypeGet() == TYP_BYREF || + call->gtArgs.GetArgByIndex(0)->GetNode()->gtOper == GT_NOP); // the arg was already morphed to a register (fgMorph called twice) maxRegArgs = 1; } @@ -2763,16 +2113,10 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) CORINFO_SIG_INFO* sig = call->callSig; const unsigned sigArgsCount = sig->numArgs; - GenTreeCall::Use* nodeArgs = call->gtCallArgs; // It could include many arguments not included in `sig->numArgs`, for example, `this`, runtime lookup, cookie // etc. - unsigned nodeArgsCount = 0; - call->VisitOperands([&nodeArgsCount](GenTree* operand) -> GenTree::VisitResult { - nodeArgsCount++; - return GenTree::VisitResult::Continue; - }); - - if (call->gtCallThisArg != nullptr) + unsigned nodeArgsCount = call->gtArgs.CountArgs(); + if (call->gtArgs.HasThisPointer()) { // Handle the most common argument not in the `sig->numArgs`. // so the following check works on more methods. @@ -2784,36 +2128,41 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) ((Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) || (nodeArgsCount == 1))) { CORINFO_ARG_LIST_HANDLE sigArg = sig->args; - for (unsigned i = 0; i < sig->numArgs; ++i) + for (CallArg& arg : call->gtArgs.Args()) { + switch (arg.GetWellKnownArg()) + { + case WellKnownArg::ThisPointer: + continue; + } + CORINFO_CLASS_HANDLE argClass; - const CorInfoType corType = strip(info.compCompHnd->getArgType(sig, sigArg, &argClass)); + const CorInfoType corType = strip(comp->info.compCompHnd->getArgType(sig, sigArg, &argClass)); const var_types sigType = JITtype2varType(corType); - assert(nodeArgs != nullptr); - const GenTree* nodeArg = nodeArgs->GetNode(); + const GenTree* nodeArg = arg.GetNode(); assert(nodeArg != nullptr); const var_types nodeType = nodeArg->TypeGet(); assert((nodeType == sigType) || varTypeIsStruct(sigType) || genTypeSize(nodeType) == genTypeSize(sigType)); - sigArg = info.compCompHnd->getArgNext(sigArg); - nodeArgs = nodeArgs->GetNext(); + sigArg = comp->info.compCompHnd->getArgNext(sigArg); } - assert(nodeArgs == nullptr); } } #endif // DEBUG - for (args = call->gtCallArgs; args != nullptr; args = args->GetNext(), argIndex++) + for (CallArg& arg : Args()) { - argx = args->GetNode()->gtSkipPutArgType(); + GenTree* argx = arg.GetNode()->gtSkipPutArgType(); // Change the node to TYP_I_IMPL so we don't report GC info // NOTE: We deferred this from the importer because of the inliner. - if (argx->IsLocalAddrExpr() != nullptr) + // TODO-ARGS: Quirk this to match previous behavior. This optimization + // is not being done for 'this' pointer. It should be. + if ((arg.GetWellKnownArg() != WellKnownArg::ThisPointer) && argx->IsLocalAddrExpr() != nullptr) { argx->gtType = TYP_I_IMPL; } @@ -2833,7 +2182,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) if (GlobalJitOptions::compFeatureHfa) { - hfaType = GetHfaType(argx); + hfaType = comp->GetHfaType(argx); isHfaArg = varTypeIsValidHfaType(hfaType); #if defined(TARGET_ARM64) @@ -2847,25 +2196,25 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) if (isHfaArg) { isHfaArg = true; - hfaSlots = GetHfaCount(argx); + hfaSlots = comp->GetHfaCount(argx); // If we have a HFA struct it's possible we transition from a method that originally // only had integer types to now start having FP types. We have to communicate this // through this flag since LSRA later on will use this flag to determine whether // or not to track the FP register set. // - compFloatingPointUsed = true; + comp->compFloatingPointUsed = true; } } const bool isFloatHfa = (hfaType == TYP_FLOAT); #ifdef TARGET_ARM - passUsingFloatRegs = !callIsVararg && (isHfaArg || varTypeUsesFloatReg(argx)) && !opts.compUseSoftFP; + passUsingFloatRegs = !callIsVararg && (isHfaArg || varTypeUsesFloatReg(argx)) && !comp->opts.compUseSoftFP; bool passUsingIntRegs = passUsingFloatRegs ? false : (intArgRegNum < MAX_REG_ARG); // We don't use the "size" return value from InferOpSizeAlign(). - codeGen->InferOpSizeAlign(argx, &argAlignBytes); + comp->codeGen->InferOpSizeAlign(argx, &argAlignBytes); argAlignBytes = roundUp(argAlignBytes, TARGET_POINTER_SIZE); @@ -2887,13 +2236,6 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) intArgRegNum++; } } - -#if defined(DEBUG) - if (argSlots % 2 == 1) - { - argSlots++; - } -#endif } #elif defined(TARGET_ARM64) @@ -2931,7 +2273,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) CORINFO_CLASS_HANDLE objClass = NO_CLASS_HANDLE; if (isStructArg) { - objClass = gtGetStructHandle(argx); + objClass = comp->gtGetStructHandle(argx); if (argx->TypeGet() == TYP_STRUCT) { // For TYP_STRUCT arguments we must have an OBJ, LCL_VAR or MKREFANY @@ -2939,13 +2281,13 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) { case GT_OBJ: structSize = actualArg->AsObj()->GetLayout()->GetSize(); - assert(structSize == info.compCompHnd->getClassSize(objClass)); + assert(structSize == comp->info.compCompHnd->getClassSize(objClass)); break; case GT_LCL_VAR: - structSize = lvaGetDesc(actualArg->AsLclVarCommon())->lvExactSize; + structSize = comp->lvaGetDesc(actualArg->AsLclVarCommon())->lvExactSize; break; case GT_MKREFANY: - structSize = info.compCompHnd->getClassSize(objClass); + structSize = comp->info.compCompHnd->getClassSize(objClass); break; default: BADCODE("illegal argument tree in fgInitArgInfo"); @@ -2955,7 +2297,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) else { structSize = genTypeSize(argx); - assert(structSize == info.compCompHnd->getClassSize(objClass)); + assert(structSize == comp->info.compCompHnd->getClassSize(objClass)); } } #if defined(TARGET_AMD64) @@ -2969,7 +2311,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) { size = (unsigned)(roundUp(structSize, TARGET_POINTER_SIZE)) / TARGET_POINTER_SIZE; byteSize = structSize; - eeGetSystemVAmd64PassStructInRegisterDescriptor(objClass, &structDesc); + comp->eeGetSystemVAmd64PassStructInRegisterDescriptor(objClass, &structDesc); } #else // !UNIX_AMD64_ABI size = 1; // On AMD64 Windows, all args fit in a single (64-bit) 'slot' @@ -2986,9 +2328,9 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) { // HFA structs are passed by value in multiple registers. // The "size" in registers may differ the size in pointer-sized units. - CORINFO_CLASS_HANDLE structHnd = gtGetStructHandle(argx); - size = GetHfaCount(structHnd); - byteSize = info.compCompHnd->getClassSize(structHnd); + CORINFO_CLASS_HANDLE structHnd = comp->gtGetStructHandle(argx); + size = comp->GetHfaCount(structHnd); + byteSize = comp->info.compCompHnd->getClassSize(structHnd); } else { @@ -3031,13 +2373,13 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) if (isStructArg) { - assert(argx == args->GetNode()); + assert(argx == arg.GetNode()); assert(structSize != 0); - structPassingKind howToPassStruct; - structBaseType = getArgTypeForStruct(objClass, &howToPassStruct, callIsVararg, structSize); - passStructByRef = (howToPassStruct == SPK_ByReference); - if (howToPassStruct == SPK_ByReference) + Compiler::structPassingKind howToPassStruct; + structBaseType = comp->getArgTypeForStruct(objClass, &howToPassStruct, callIsVararg, structSize); + passStructByRef = (howToPassStruct == Compiler::SPK_ByReference); + if (howToPassStruct == Compiler::SPK_ByReference) { byteSize = TARGET_POINTER_SIZE; } @@ -3046,7 +2388,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) byteSize = structSize; } - if (howToPassStruct == SPK_PrimitiveType) + if (howToPassStruct == Compiler::SPK_PrimitiveType) { #ifdef TARGET_ARM // TODO-CQ: getArgTypeForStruct should *not* return TYP_DOUBLE for a double struct, @@ -3067,8 +2409,8 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) } } - const var_types argType = args->GetNode()->TypeGet(); - if (args->GetNode()->OperIs(GT_PUTARG_TYPE)) + const var_types argType = arg.GetNode()->TypeGet(); + if (arg.GetNode()->OperIs(GT_PUTARG_TYPE)) { byteSize = genTypeSize(argType); } @@ -3082,21 +2424,20 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) // Arm64 Apple has a special ABI for passing small size arguments on stack, // bytes are aligned to 1-byte, shorts to 2-byte, int/float to 4-byte, etc. // It means passing 8 1-byte arguments on stack can take as small as 8 bytes. - argAlignBytes = eeGetArgSizeAlignment(argType, isFloatHfa); + argAlignBytes = comp->eeGetArgSizeAlignment(argType, isFloatHfa); } // // Figure out if the argument will be passed in a register. // bool isRegArg = false; - NonStandardArgKind nonStandardArgKind = NonStandardArgKind::None; regNumber nonStdRegNum = REG_NA; if (isRegParamType(genActualType(argx->TypeGet())) #ifdef UNIX_AMD64_ABI && (!isStructArg || structDesc.passedInRegisters) #elif defined(TARGET_X86) - || (isStructArg && isTrivialPointerSizedStruct(objClass)) + || (isStructArg && comp->isTrivialPointerSizedStruct(objClass)) #endif ) { @@ -3225,15 +2566,13 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) isRegArg = false; } - // If there are nonstandard args (outside the calling convention) they were inserted above - // and noted them in a table so we can recognize them here and build their argInfo. - // - // They should not affect the placement of any other args or stack space required. + // Some well known args have custom register assignment. + // These should not affect the placement of any other args or stack space required. // Example: on AMD64 R10 and R11 are used for indirect VSD (generic interface) and cookie calls. - bool isNonStandard = nonStandardArgs.Find(argx, &nonStdRegNum, &nonStandardArgKind); - if (isNonStandard) + nonStdRegNum = GetCustomRegister(comp, call->GetUnmanagedCallConv(), arg.GetWellKnownArg()); + if (nonStdRegNum != REG_NA) { - isRegArg = (nonStdRegNum != REG_STK); + isRegArg = true; } else if (call->IsTailCallViaJitHelper()) { @@ -3278,8 +2617,11 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) } #endif // TARGET_ARM - // Now create the fgArgTabEntry. - fgArgTabEntry* newArgEntry; + arg.AbiInfo = {}; + arg.AbiInfo.ArgNum = argIndex; + arg.AbiInfo.ArgType = argx->TypeGet(); + arg.AbiInfo.IsStruct = isStructArg; + if (isRegArg) { regNumber nextRegNum = REG_STK; @@ -3290,7 +2632,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) unsigned int structIntRegs = 0; #endif // defined(UNIX_AMD64_ABI) - if (isNonStandard) + if (nonStdRegNum != REG_NA) { nextRegNum = nonStdRegNum; } @@ -3328,14 +2670,28 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) #endif #endif - // This is a register argument - put it in the table - newArgEntry = - call->fgArgInfo->AddRegArg(argIndex, argx, args, nextRegNum, size, byteSize, argAlignBytes, isStructArg, - isFloatHfa, callIsVararg UNIX_AMD64_ABI_ONLY_ARG(nextOtherRegNum) - UNIX_AMD64_ABI_ONLY_ARG(structIntRegs) - UNIX_AMD64_ABI_ONLY_ARG(structFloatRegs) - UNIX_AMD64_ABI_ONLY_ARG(&structDesc)); - newArgEntry->SetIsBackFilled(isBackFilled); + // This is a register argument + m_hasRegArgs = true; + arg.AbiInfo.SetRegNum(0, nextRegNum); + arg.AbiInfo.NumRegs = size; + arg.AbiInfo.SetByteSize(byteSize, argAlignBytes, isStructArg, isFloatHfa); +#ifdef UNIX_AMD64_ABI + arg.AbiInfo.StructIntRegs = structIntRegs; + arg.AbiInfo.StructFloatRegs = structFloatRegs; + assert(size <= 2); + if (size == 2) + { + arg.AbiInfo.SetRegNum(1, nextOtherRegNum); + } + + if (isStructArg) + { + arg.AbiInfo.StructDesc.CopyFrom(structDesc); + } + + INDEBUG(arg.CheckIsStruct()); +#endif + arg.AbiInfo.IsBackFilled = isBackFilled; // Set up the next intArgRegNum and fltArgRegNum values. if (!isBackFilled) @@ -3350,7 +2706,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) else #endif // defined(UNIX_AMD64_ABI) { - if (!isNonStandard) + if (nonStdRegNum == REG_NA) { #if FEATURE_ARG_SPLIT // Check for a split (partially enregistered) struct @@ -3361,7 +2717,7 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) (argx->gtOper == GT_COMMA && (argx->gtFlags & GTF_ASG))); unsigned numRegsPartial = MAX_REG_ARG - intArgRegNum; assert((unsigned char)numRegsPartial == numRegsPartial); - call->fgArgInfo->SplitArg(argIndex, numRegsPartial, size - numRegsPartial); + SplitArg(&arg, numRegsPartial, size - numRegsPartial, &nextSlotNum); } #endif // FEATURE_ARG_SPLIT @@ -3392,52 +2748,101 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) } else // We have an argument that is not passed in a register { - // This is a stack argument - put it in the table - newArgEntry = call->fgArgInfo->AddStkArg(argIndex, argx, args, size, byteSize, argAlignBytes, isStructArg, - isFloatHfa, callIsVararg); + // This is a stack argument + m_hasStackArgs = true; + arg.AbiInfo.SetRegNum(0, REG_STK); + m_nextStackByteOffset = roundUp(m_nextStackByteOffset, argAlignBytes); + +#ifdef DEBUG_ARG_SLOTS + arg.AbiInfo.NumSlots = size; + + if (!compMacOsArm64Abi()) + { + nextSlotNum = roundUp(nextSlotNum, argAlignBytes / TARGET_POINTER_SIZE); + } + assert(m_nextStackByteOffset / TARGET_POINTER_SIZE == nextSlotNum); + + arg.AbiInfo.SlotNum = nextSlotNum; + nextSlotNum += size; +#endif + arg.AbiInfo.ByteOffset = m_nextStackByteOffset; + arg.AbiInfo.SetByteSize(byteSize, argAlignBytes, isStructArg, isFloatHfa); + + m_nextStackByteOffset += arg.AbiInfo.ByteSize; #ifdef UNIX_AMD64_ABI // TODO-Amd64-Unix-CQ: This is temporary (see also in fgMorphArgs). if (structDesc.passedInRegisters) { - newArgEntry->structDesc.CopyFrom(structDesc); + arg.AbiInfo.StructDesc.CopyFrom(structDesc); } #endif } - newArgEntry->nonStandardArgKind = nonStandardArgKind; - if (GlobalJitOptions::compFeatureHfa) { if (isHfaArg) { - newArgEntry->SetHfaType(hfaType, hfaSlots); + arg.AbiInfo.SetHfaType(hfaType, hfaSlots); } } - newArgEntry->SetMultiRegNums(); + arg.AbiInfo.SetMultiRegNums(); - noway_assert(newArgEntry != nullptr); - if (newArgEntry->isStruct) + if (arg.AbiInfo.IsStruct) { - newArgEntry->passedByRef = passStructByRef; - newArgEntry->argType = (structBaseType == TYP_UNKNOWN) ? argx->TypeGet() : structBaseType; + arg.AbiInfo.PassedByRef = passStructByRef; + arg.AbiInfo.ArgType = (structBaseType == TYP_UNKNOWN) ? argx->TypeGet() : structBaseType; } else { - newArgEntry->argType = argx->TypeGet(); + arg.AbiInfo.ArgType = argx->TypeGet(); } - DEBUG_ARG_SLOTS_ONLY(argSlots += size;) + argIndex++; } // end foreach argument loop + #ifdef DEBUG - if (verbose) + +#if defined(DEBUG_ARG_SLOTS) + if (!compMacOsArm64Abi()) { - JITDUMP("ArgTable for %d.%s after fgInitArgInfo:\n", call->gtTreeID, GenTree::OpName(call->gtOper)); - call->fgArgInfo->Dump(this); + assert(AlignUp(m_nextStackByteOffset, TARGET_POINTER_SIZE) == nextSlotNum * REGSIZE_BYTES); + } +#endif + +#endif + +#ifdef DEBUG + if (VERBOSE) + { + JITDUMP("Args for call [%06u] %s after DetermineArgABIInformation:\n", comp->dspTreeID(call), GenTree::OpName(call->gtOper)); + for (CallArg& arg : Args()) + { + arg.Dump(comp); + } JITDUMP("\n"); } #endif + + m_abiInformationDetermined = true; +} + +unsigned CallArgs::OutgoingArgsStackSize() const +{ + unsigned aligned = Compiler::GetOutgoingArgByteSize(m_nextStackByteOffset); + return max(aligned, MIN_ARG_AREA_FOR_CALL);; +} + +unsigned CallArgs::CountArgs() +{ + unsigned numArgs = 0; + for (CallArg& arg : Args()) + { + numArgs++; + } + + return numArgs; } //------------------------------------------------------------------------ @@ -3483,84 +2888,60 @@ void Compiler::fgInitArgInfo(GenTreeCall* call) #endif GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) { - GenTreeCall::Use* args; - GenTree* argx; - GenTreeFlags flagsSummary = GTF_EMPTY; - unsigned argIndex = 0; - DEBUG_ARG_SLOTS_ONLY(unsigned argSlots = 0;) bool reMorphing = call->AreArgsComplete(); - // Set up the fgArgInfo. - fgInitArgInfo(call); + call->gtArgs.DetermineArgABIInformation(this, call); JITDUMP("%sMorphing args for %d.%s:\n", (reMorphing) ? "Re" : "", call->gtTreeID, GenTree::OpName(call->gtOper)); // If we are remorphing, process the late arguments (which were determined by a previous caller). if (reMorphing) { - for (GenTreeCall::Use& use : call->LateArgs()) + for (LateArg arg : call->gtArgs.LateArgs()) { - use.SetNode(fgMorphTree(use.GetNode())); - flagsSummary |= use.GetNode()->gtFlags; + arg.SetNode(fgMorphTree(arg.GetNode())); + flagsSummary |= arg.GetNode()->gtFlags; } - - assert(call->fgArgInfo != nullptr); } - call->fgArgInfo->RemorphReset(); // First we morph the argument subtrees ('this' pointer, arguments, etc.). // During the first call to fgMorphArgs we also record the // information about late arguments we have in 'fgArgInfo'. - // This information is used later to contruct the gtCallLateArgs */ - - // Process the 'this' argument value, if present. - if (call->gtCallThisArg != nullptr) - { - argx = call->gtCallThisArg->GetNode(); - fgArgTabEntry* thisArgEntry = call->fgArgInfo->GetArgEntry(0, reMorphing); - argx = fgMorphTree(argx); - call->gtCallThisArg->SetNode(argx); - // This is a register argument - possibly update it in the table. - call->fgArgInfo->UpdateRegArg(thisArgEntry, argx, reMorphing); - flagsSummary |= argx->gtFlags; - - if (!reMorphing && call->IsExpandedEarly() && call->IsVirtualVtable()) - { - if (!argx->OperIsLocal()) - { - thisArgEntry->needTmp = true; - call->fgArgInfo->SetNeedsTemps(); - } - } - assert(argIndex == 0); - argIndex++; - DEBUG_ARG_SLOTS_ONLY(argSlots++;) - } + // This information is used later to contruct the late args // Note that this name is a bit of a misnomer - it indicates that there are struct args // that occupy more than a single slot that are passed by value (not necessarily in regs). bool hasMultiregStructArgs = false; - for (args = call->gtCallArgs; args != nullptr; args = args->GetNext(), argIndex++) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree** parentArgx = &args->NodeRef(); - fgArgTabEntry* argEntry = call->fgArgInfo->GetArgEntry(argIndex, reMorphing); + GenTree** parentArgx = &arg.NodeRef(); // Morph the arg node, and update the parent and argEntry pointers. - argx = *parentArgx; + GenTree* argx = *parentArgx; argx = fgMorphTree(argx); *parentArgx = argx; - assert(argx == args->GetNode()); - DEBUG_ARG_SLOTS_ONLY(unsigned size = argEntry->getSize();) + if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) + { + // We may want to force 'this' into a temp because we want to use + // it to expand the call target in morph so that CSE can pick it + // up. + if (!reMorphing && call->IsExpandedEarly() && call->IsVirtualVtable() && !argx->OperIsLocal()) + { + call->gtArgs.SetNeedsTemp(&arg); + } + } + + DEBUG_ARG_SLOTS_ONLY(unsigned size = arg.AbiInfo.GetSize();) CORINFO_CLASS_HANDLE copyBlkClass = NO_CLASS_HANDLE; #if defined(DEBUG_ARG_SLOTS) if (!compMacOsArm64Abi()) { - if (argEntry->GetByteAlignment() == 2 * TARGET_POINTER_SIZE) + if (arg.AbiInfo.ByteAlignment == 2 * TARGET_POINTER_SIZE) { if (argSlots % 2 == 1) { @@ -3569,32 +2950,32 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) } } #endif // DEBUG - if (argEntry->isNonStandard() && argEntry->isPassedInRegisters()) + // TODO-ARGS: Review this, is it really necessary to treat them specially here? + if (call->gtArgs.IsNonStandard(this, call, &arg) && arg.AbiInfo.IsPassedInRegisters()) { - // We need to update the node field for this nonStandard arg here - // as it may have been changed by the call to fgMorphTree. - call->fgArgInfo->UpdateRegArg(argEntry, argx, reMorphing); flagsSummary |= argx->gtFlags; continue; } DEBUG_ARG_SLOTS_ASSERT(size != 0); - DEBUG_ARG_SLOTS_ONLY(argSlots += argEntry->getSlotCount();) + DEBUG_ARG_SLOTS_ONLY(argSlots += arg.AbiInfo.GetSlotCount();) - if (argx->IsLocalAddrExpr() != nullptr) + // TODO-ARGS: Quirk this to match previous behavior where it was + // skipped for 'this' pointer. We should turn it off. + if ((arg.GetWellKnownArg() != WellKnownArg::ThisPointer) && (argx->IsLocalAddrExpr() != nullptr)) { argx->gtType = TYP_I_IMPL; } // Get information about this argument. - var_types hfaType = argEntry->GetHfaType(); + var_types hfaType = arg.AbiInfo.GetHfaType(); bool isHfaArg = (hfaType != TYP_UNDEF); - bool passUsingFloatRegs = argEntry->isPassedInFloatRegisters(); + bool passUsingFloatRegs = arg.AbiInfo.IsPassedInFloatRegisters(); unsigned structSize = 0; // Struct arguments may be morphed into a node that is not a struct type. // In such case the fgArgTabEntry keeps track of whether the original node (before morphing) // was a struct and the struct classification. - bool isStructArg = argEntry->isStruct; + bool isStructArg = arg.AbiInfo.IsStruct; GenTree* argObj = argx->gtEffectiveVal(true /*commaOnly*/); if (isStructArg && varTypeIsStruct(argObj) && !argObj->OperIs(GT_ASG, GT_MKREFANY, GT_FIELD_LIST, GT_ARGPLACE)) @@ -3622,10 +3003,10 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) assert(originalSize == info.compCompHnd->getClassSize(objClass)); } unsigned roundupSize = (unsigned)roundUp(originalSize, TARGET_POINTER_SIZE); - var_types structBaseType = argEntry->argType; + var_types structBaseType = arg.AbiInfo.ArgType; // First, handle the case where the argument is passed by reference. - if (argEntry->passedByRef) + if (arg.AbiInfo.PassedByRef) { DEBUG_ARG_SLOTS_ASSERT(size == 1); copyBlkClass = objClass; @@ -3655,7 +3036,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) { if (isPow2(passingSize)) { - canTransform = (!argEntry->IsHfaArg() || (passingSize == genTypeSize(argEntry->GetHfaType()))); + canTransform = (!arg.AbiInfo.IsHfaArg() || (passingSize == genTypeSize(arg.AbiInfo.GetHfaType()))); } #if defined(TARGET_ARM64) || defined(UNIX_AMD64_ABI) @@ -3686,7 +3067,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) // - We have a known struct type (e.g. SIMD) that requires multiple registers. // TODO-Amd64-Unix-Throughput: We don't need to keep the structDesc in the argEntry if it's not // actually passed in registers. - if (argEntry->isPassedInRegisters()) + if (arg.AbiInfo.IsPassedInRegisters()) { if (argObj->OperIs(GT_OBJ)) { @@ -3699,7 +3080,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) { // This should only be the case of a value directly producing a known struct type. assert(argObj->TypeGet() != TYP_STRUCT); - if (argEntry->numRegs > 1) + if (arg.AbiInfo.NumRegs > 1) { copyBlkClass = objClass; } @@ -3863,18 +3244,9 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) } } - if (argEntry->isPassedInRegisters()) - { - call->fgArgInfo->UpdateRegArg(argEntry, argx, reMorphing); - } - else - { - call->fgArgInfo->UpdateStkArg(argEntry, argx, reMorphing); - } - if (copyBlkClass != NO_CLASS_HANDLE) { - fgMakeOutgoingStructArgCopy(call, args, copyBlkClass); + fgMakeOutgoingStructArgCopy(call, &arg, copyBlkClass); } if (argx->gtOper == GT_MKREFANY) @@ -3887,9 +3259,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) GenTreeFieldList* fieldList = new (this, GT_FIELD_LIST) GenTreeFieldList(); fieldList->AddField(this, argx->AsOp()->gtGetOp1(), OFFSETOF__CORINFO_TypedReference__dataPtr, TYP_BYREF); fieldList->AddField(this, argx->AsOp()->gtGetOp2(), OFFSETOF__CORINFO_TypedReference__type, TYP_I_IMPL); - fgArgTabEntry* fp = gtArgEntryByNode(call, argx); - args->SetNode(fieldList); - assert(fp->GetNode() == fieldList); + arg.SetNode(fieldList); #else // !TARGET_X86 // Get a new temp @@ -3911,10 +3281,9 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) GenTree* asg = gtNewOperNode(GT_COMMA, TYP_VOID, asgPtrSlot, asgTypeSlot); // Change the expression to "(tmp=val)" - args->SetNode(asg); + arg.SetNode(asg); - // EvalArgsToTemps will cause tmp to actually get loaded as the argument - call->fgArgInfo->EvalToTmp(argEntry, tmp, asg); + call->gtArgs.SetTemp(&arg, tmp); lvaSetVarAddrExposed(tmp DEBUGARG(AddressExposedReason::TOO_CONSERVATIVE)); #endif // !TARGET_X86 } @@ -3922,23 +3291,23 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) #if FEATURE_MULTIREG_ARGS if (isStructArg) { - if (((argEntry->numRegs + argEntry->GetStackSlotsNumber()) > 1) || + if (((arg.AbiInfo.NumRegs + arg.AbiInfo.GetStackSlotsNumber()) > 1) || (isHfaArg && argx->TypeGet() == TYP_STRUCT)) { hasMultiregStructArgs = true; } } #ifdef TARGET_ARM - else if ((argEntry->argType == TYP_LONG) || (argEntry->argType == TYP_DOUBLE)) + else if ((arg.AbiInfo.ArgType == TYP_LONG) || (arg.AbiInfo.ArgType == TYP_DOUBLE)) { - assert((argEntry->numRegs == 2) || (argEntry->numSlots == 2)); + assert((arg.AbiInfo.NumRegs == 2) || (arg.AbiInfo.NumSlots == 2)); } #endif else { // We must have exactly one register or slot. - assert(((argEntry->numRegs == 1) && (argEntry->GetStackSlotsNumber() == 0)) || - ((argEntry->numRegs == 0) && (argEntry->GetStackSlotsNumber() == 1))); + assert(((arg.AbiInfo.NumRegs == 1) && (arg.AbiInfo.GetStackSlotsNumber() == 0)) || + ((arg.AbiInfo.NumRegs == 0) && (arg.AbiInfo.GetStackSlotsNumber() == 1))); } #endif @@ -3953,10 +3322,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) GenTreeLclVarCommon* lcl = lclNode->AsLclVarCommon(); LclVarDsc* varDsc = lvaGetDesc(lcl); GenTreeFieldList* fieldList = new (this, GT_FIELD_LIST) GenTreeFieldList(); - - fgArgTabEntry* fp = gtArgEntryByNode(call, argx); - args->SetNode(fieldList); - assert(fp->GetNode() == fieldList); + arg.SetNode(fieldList); for (unsigned fieldLclNum = varDsc->lvFieldLclStart; fieldLclNum < varDsc->lvFieldLclStart + varDsc->lvFieldCnt; ++fieldLclNum) @@ -3982,16 +3348,16 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) } #endif // TARGET_X86 - flagsSummary |= args->GetNode()->gtFlags; + flagsSummary |= arg.GetNode()->gtFlags; } // end foreach argument loop if (!reMorphing) { - call->fgArgInfo->ArgsComplete(); + call->gtArgs.ArgsComplete(this, call); } - /* Process the function address, if indirect call */ + // Process the function address, if indirect call if (call->gtCallType == CT_INDIRECT) { @@ -4000,57 +3366,13 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) flagsSummary |= call->gtCallAddr->gtFlags; } -#if FEATURE_FIXED_OUT_ARGS - - // Record the outgoing argument size. If the call is a fast tail - // call, it will setup its arguments in incoming arg area instead - // of the out-going arg area, so we don't need to track the - // outgoing arg size. +#if FEATURE_FIXED_OUT_ARGS && defined(UNIX_AMD64_ABI) if (!call->IsFastTailCall()) { - -#if defined(UNIX_AMD64_ABI) // This is currently required for the UNIX ABI to work correctly. opts.compNeedToAlignFrame = true; -#endif // UNIX_AMD64_ABI - - const unsigned outgoingArgSpaceSize = GetOutgoingArgByteSize(call->fgArgInfo->GetNextSlotByteOffset()); - -#if defined(DEBUG_ARG_SLOTS) - unsigned preallocatedArgCount = 0; - if (!compMacOsArm64Abi()) - { - preallocatedArgCount = call->fgArgInfo->GetNextSlotNum(); - assert(outgoingArgSpaceSize == preallocatedArgCount * REGSIZE_BYTES); - } -#endif - call->fgArgInfo->SetOutArgSize(max(outgoingArgSpaceSize, MIN_ARG_AREA_FOR_CALL)); - -#ifdef DEBUG - if (verbose) - { - const fgArgInfo* argInfo = call->fgArgInfo; -#if defined(DEBUG_ARG_SLOTS) - if (!compMacOsArm64Abi()) - { - printf("argSlots=%d, preallocatedArgCount=%d, nextSlotNum=%d, nextSlotByteOffset=%d, " - "outgoingArgSpaceSize=%d\n", - argSlots, preallocatedArgCount, argInfo->GetNextSlotNum(), argInfo->GetNextSlotByteOffset(), - outgoingArgSpaceSize); - } - else - { - printf("nextSlotByteOffset=%d, outgoingArgSpaceSize=%d\n", argInfo->GetNextSlotByteOffset(), - outgoingArgSpaceSize); - } -#else - printf("nextSlotByteOffset=%d, outgoingArgSpaceSize=%d\n", argInfo->GetNextSlotByteOffset(), - outgoingArgSpaceSize); -#endif - } -#endif } -#endif // FEATURE_FIXED_OUT_ARGS +#endif // FEATURE_FIXED_OUT_ARGS && UNIX_AMD64_ABI // Clear the ASG and EXCEPT (if possible) flags on the call node call->gtFlags &= ~GTF_ASG; @@ -4065,13 +3387,12 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) // If we are remorphing or don't have any register arguments or other arguments that need // temps, then we don't need to call SortArgs() and EvalArgsToTemps(). // - if (!reMorphing && (call->fgArgInfo->HasRegArgs() || call->fgArgInfo->NeedsTemps())) + if (!reMorphing && (call->gtArgs.HasRegArgs() || call->gtArgs.NeedsTemps())) { // Do the 'defer or eval to temp' analysis. - call->fgArgInfo->SortArgs(); - - call->fgArgInfo->EvalArgsToTemps(); + call->gtArgs.SortArgs(this, call); + call->gtArgs.EvalArgsToTemps(this, call); } if (hasMultiregStructArgs) @@ -4082,9 +3403,12 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) #ifdef DEBUG if (verbose) { - JITDUMP("ArgTable for %d.%s after fgMorphArgs:\n", call->gtTreeID, GenTree::OpName(call->gtOper)); - call->fgArgInfo->Dump(this); - JITDUMP("\n"); + JITDUMP("Args for [%06u].%s after fgMorphArgs:\n", dspTreeID(call), GenTree::OpName(call->gtOper)); + for (CallArg& arg : call->gtArgs.Args()) + { + arg.Dump(this); + } + printf("OutgoingArgsStackSize is %u\n\n", call->gtArgs.OutgoingArgsStackSize()); } #endif return call; @@ -4117,49 +3441,30 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) assert(!"Logic error: no MultiregStructArgs for Windows X64 ABI"); #endif - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { // For late arguments the arg tree that is overridden is in the gtCallLateArgs list. // For such late args the gtCallArgList contains the setup arg node (evaluating the arg.) // The tree from the gtCallLateArgs list is passed to the callee. The fgArgEntry node contains the mapping // between the nodes in both lists. If the arg is not a late arg, the fgArgEntry->node points to itself, // otherwise points to the list in the late args list. - bool isLateArg = (use.GetNode()->gtFlags & GTF_LATE_ARG) != 0; - fgArgTabEntry* fgEntryPtr = gtArgEntryByNode(call, use.GetNode()); - assert(fgEntryPtr != nullptr); - GenTree* argx = fgEntryPtr->GetNode(); - GenTreeCall::Use* lateUse = nullptr; - GenTree* lateNode = nullptr; - - if (isLateArg) - { - for (GenTreeCall::Use& lateArgUse : call->LateArgs()) - { - GenTree* argNode = lateArgUse.GetNode(); - if (argx == argNode) - { - lateUse = &lateArgUse; - lateNode = argNode; - break; - } - } - assert((lateUse != nullptr) && (lateNode != nullptr)); - } + bool isLateArg = (arg.GetNode()->gtFlags & GTF_LATE_ARG) != 0; + GenTree* argx = arg.GetArgNode(); - if (!fgEntryPtr->isStruct) + if (!arg.AbiInfo.IsStruct) { continue; } - unsigned size = (fgEntryPtr->numRegs + fgEntryPtr->GetStackSlotsNumber()); - if ((size > 1) || (fgEntryPtr->IsHfaArg() && argx->TypeGet() == TYP_STRUCT)) + unsigned size = (arg.AbiInfo.NumRegs + arg.AbiInfo.GetStackSlotsNumber()); + if ((size > 1) || (arg.AbiInfo.IsHfaArg() && argx->TypeGet() == TYP_STRUCT)) { foundStructArg = true; if (varTypeIsStruct(argx) && !argx->OperIs(GT_FIELD_LIST)) { - if (fgEntryPtr->IsHfaRegArg()) + if (arg.AbiInfo.IsHfaRegArg()) { - var_types hfaType = fgEntryPtr->GetHfaType(); + var_types hfaType = arg.AbiInfo.GetHfaType(); unsigned structSize; if (argx->OperIs(GT_OBJ)) { @@ -4186,7 +3491,7 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) } } - GenTree* newArgx = fgMorphMultiregStructArg(argx, fgEntryPtr); + GenTree* newArgx = fgMorphMultiregStructArg(&arg); // Did we replace 'argx' with a new tree? if (newArgx != argx) @@ -4194,14 +3499,12 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) // link the new arg node into either the late arg list or the gtCallArgs list if (isLateArg) { - lateUse->SetNode(newArgx); + arg.SetLateNode(newArgx); } else { - use.SetNode(newArgx); + arg.SetNode(newArgx); } - - assert(fgEntryPtr->GetNode() == newArgx); } } } @@ -4219,8 +3522,7 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) // morph the argument as needed to be passed correctly. // // Arguments: -// arg - A GenTree node containing a TYP_STRUCT arg -// fgEntryPtr - the fgArgTabEntry information for the current 'arg' +// arg - The argument // // Notes: // The arg must be a GT_OBJ or GT_LCL_VAR or GT_LCL_FLD of TYP_STRUCT. @@ -4240,23 +3542,24 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) // indirections. // Currently the implementation handles ARM64/ARM and will NYI for other architectures. // -GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntryPtr) +GenTree* Compiler::fgMorphMultiregStructArg(CallArg* arg) { - assert(varTypeIsStruct(arg->TypeGet())); + GenTree* argNode = arg->GetArgNode(); + assert(varTypeIsStruct(argNode->TypeGet())); #if !defined(TARGET_ARMARCH) && !defined(UNIX_AMD64_ABI) NYI("fgMorphMultiregStructArg requires implementation for this target"); #endif #ifdef TARGET_ARM - if ((fgEntryPtr->IsSplit() && fgEntryPtr->GetStackSlotsNumber() + fgEntryPtr->numRegs > 4) || - (!fgEntryPtr->IsSplit() && fgEntryPtr->GetRegNum() == REG_STK)) + if ((arg->AbiInfo.IsSplit() && arg->AbiInfo.GetStackSlotsNumber() + arg->AbiInfo.NumRegs > 4) || + (!arg->AbiInfo.IsSplit() && arg->AbiInfo.GetRegNum() == REG_STK)) #else - if (fgEntryPtr->GetRegNum() == REG_STK) + if (arg->AbiInfo.GetRegNum() == REG_STK) #endif { GenTreeLclVarCommon* lcl = nullptr; - GenTree* actualArg = arg->gtEffectiveVal(); + GenTree* actualArg = argNode->gtEffectiveVal(); if (actualArg->OperGet() == GT_OBJ) { @@ -4273,40 +3576,40 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry { if (lvaGetPromotionType(lcl->GetLclNum()) == PROMOTION_TYPE_INDEPENDENT) { - arg = fgMorphLclArgToFieldlist(lcl); + argNode = fgMorphLclArgToFieldlist(lcl); } - else if (arg->TypeGet() == TYP_STRUCT) + else if (argNode->TypeGet() == TYP_STRUCT) { // If this is a non-register struct, it must be referenced from memory. if (!actualArg->OperIs(GT_OBJ)) { // Create an Obj of the temp to use it as a call argument. - arg = gtNewOperNode(GT_ADDR, TYP_I_IMPL, arg); - arg = gtNewObjNode(lvaGetStruct(lcl->GetLclNum()), arg); + argNode = gtNewOperNode(GT_ADDR, TYP_I_IMPL, argNode); + argNode = gtNewObjNode(lvaGetStruct(lcl->GetLclNum()), argNode); } // Its fields will need to be accessed by address. lvaSetVarDoNotEnregister(lcl->GetLclNum() DEBUG_ARG(DoNotEnregisterReason::IsStructArg)); } } - return arg; + return argNode; } #if FEATURE_MULTIREG_ARGS // Examine 'arg' and setup argValue objClass and structSize // - const CORINFO_CLASS_HANDLE objClass = gtGetStructHandle(arg); - GenTree* argValue = arg; // normally argValue will be arg, but see right below + const CORINFO_CLASS_HANDLE objClass = gtGetStructHandle(argNode); + GenTree* argValue = argNode; // normally argValue will be arg, but see right below unsigned structSize = 0; - if (arg->TypeGet() != TYP_STRUCT) + if (argNode->TypeGet() != TYP_STRUCT) { - structSize = genTypeSize(arg->TypeGet()); + structSize = genTypeSize(argNode->TypeGet()); assert(structSize == info.compCompHnd->getClassSize(objClass)); } - else if (arg->OperGet() == GT_OBJ) + else if (argNode->OperGet() == GT_OBJ) { - GenTreeObj* argObj = arg->AsObj(); + GenTreeObj* argObj = argNode->AsObj(); const ClassLayout* objLayout = argObj->GetLayout(); structSize = objLayout->GetSize(); assert(structSize == info.compCompHnd->getClassSize(objClass)); @@ -4328,9 +3631,9 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry } } } - else if (arg->OperGet() == GT_LCL_VAR) + else if (argNode->OperGet() == GT_LCL_VAR) { - LclVarDsc* varDsc = lvaGetDesc(arg->AsLclVarCommon()); + LclVarDsc* varDsc = lvaGetDesc(argNode->AsLclVarCommon()); structSize = varDsc->lvExactSize; assert(structSize == info.compCompHnd->getClassSize(objClass)); } @@ -4345,8 +3648,8 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry unsigned elemSize = 0; var_types type[MAX_ARG_REG_COUNT] = {}; // TYP_UNDEF = 0 - hfaType = fgEntryPtr->GetHfaType(); - if (varTypeIsValidHfaType(hfaType) && fgEntryPtr->isPassedInFloatRegisters()) + hfaType = arg->AbiInfo.GetHfaType(); + if (varTypeIsValidHfaType(hfaType) && arg->AbiInfo.IsPassedInFloatRegisters()) { elemType = hfaType; elemSize = genTypeSize(elemType); @@ -4369,8 +3672,8 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry #ifdef UNIX_AMD64_ABI if (gcPtrs[inx] == TYPE_GC_NONE) { - type[inx] = GetTypeFromClassificationAndSizes(fgEntryPtr->structDesc.eightByteClassifications[inx], - fgEntryPtr->structDesc.eightByteSizes[inx]); + type[inx] = GetTypeFromClassificationAndSizes(arg->AbiInfo.StructDesc.eightByteClassifications[inx], + arg->AbiInfo.StructDesc.eightByteSizes[inx]); } else #endif // UNIX_AMD64_ABI @@ -4447,13 +3750,13 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry if (verbose) { JITDUMP("Multireg struct argument V%02u : ", varNum); - fgEntryPtr->Dump(); + arg->Dump(this); } #endif // DEBUG #ifndef UNIX_AMD64_ABI // This local variable must match the layout of the 'objClass' type exactly - if (varDsc->lvIsHfa() && fgEntryPtr->isPassedInFloatRegisters()) + if (varDsc->lvIsHfa() && arg->AbiInfo.IsPassedInFloatRegisters()) { // We have a HFA struct. noway_assert(elemType == varDsc->GetHfaType()); @@ -4495,7 +3798,7 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry } } - if (varDsc->lvPromoted && varDsc->lvIsHfa() && fgEntryPtr->isPassedInFloatRegisters()) + if (varDsc->lvPromoted && varDsc->lvIsHfa() && arg->AbiInfo.IsPassedInFloatRegisters()) { bool canMorphToFieldList = true; @@ -4534,8 +3837,8 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry var_types loType = loVarDsc->lvType; var_types hiType = hiVarDsc->lvType; - if ((varTypeIsFloating(loType) != genIsValidFloatReg(fgEntryPtr->GetRegNum(0))) || - (varTypeIsFloating(hiType) != genIsValidFloatReg(fgEntryPtr->GetRegNum(1)))) + if ((varTypeIsFloating(loType) != genIsValidFloatReg(arg->AbiInfo.GetRegNum(0))) || + (varTypeIsFloating(hiType) != genIsValidFloatReg(arg->AbiInfo.GetRegNum(1)))) { // TODO-LSRA - It currently doesn't support the passing of floating point LCL_VARS in the integer // registers. So for now we will use GT_LCLFLD's to pass this struct (it won't be enregistered) @@ -4632,10 +3935,10 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry // if (newArg == nullptr) { - if (fgEntryPtr->GetRegNum() == REG_STK) + if (arg->AbiInfo.GetRegNum() == REG_STK) { // We leave this stack passed argument alone - return arg; + return argNode; } // Are we passing a GT_LCL_FLD (or a GT_LCL_VAR that was not struct promoted ) @@ -4769,11 +4072,11 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry } #endif - arg = newArg; // consider calling fgMorphTree(newArg); + argNode = newArg; // consider calling fgMorphTree(newArg); #endif // FEATURE_MULTIREG_ARGS - return arg; + return argNode; } //------------------------------------------------------------------------ @@ -4809,16 +4112,15 @@ GenTreeFieldList* Compiler::fgMorphLclArgToFieldlist(GenTreeLclVarCommon* lcl) // // Arguments: // call - call being processed -// args - args for the call +// arg - arg for the call // copyBlkClass - class handle for the struct // // The arg is updated if necessary with the copy. // -void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, GenTreeCall::Use* args, CORINFO_CLASS_HANDLE copyBlkClass) +void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg, CORINFO_CLASS_HANDLE copyBlkClass) { - GenTree* argx = args->GetNode(); + GenTree* argx = arg->GetNode(); noway_assert(argx->gtOper != GT_MKREFANY); - fgArgTabEntry* argEntry = Compiler::gtArgEntryByNode(call, argx); // If we're optimizing, see if we can avoid making a copy. // @@ -4855,9 +4157,7 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, GenTreeCall::Use* ((totalAppearances == 1) && call->IsNoReturn()) || // ((totalAppearances == 1) && !fgMightHaveLoop())) { - args->SetNode(lcl); - assert(argEntry->GetNode() == lcl); - + arg->SetNode(lcl); JITDUMP("did not need to make outgoing copy for last use of implicit byref V%2d\n", varNum); return; } @@ -4927,26 +4227,25 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, GenTreeCall::Use* GenTree* copyBlk = gtNewBlkOpNode(dest, argx, false /* not volatile */, true /* copyBlock */); copyBlk = fgMorphCopyBlock(copyBlk); + call->gtArgs.SetTemp(arg, tmp); #if FEATURE_FIXED_OUT_ARGS // Do the copy early, and evalute the temp later (see EvalArgsToTemps) // When on Unix create LCL_FLD for structs passed in more than one registers. See fgMakeTmpArgNode - GenTree* arg = copyBlk; + GenTree* argNode = copyBlk; #else // FEATURE_FIXED_OUT_ARGS // Structs are always on the stack, and thus never need temps // so we have to put the copy and temp all into one expression. - argEntry->tmpNum = tmp; - GenTree* arg = fgMakeTmpArgNode(argEntry); + GenTree* argNode = call->gtArgs.MakeTmpArgNode(this, arg); // Change the expression to "(tmp=val),tmp" - arg = gtNewOperNode(GT_COMMA, arg->TypeGet(), copyBlk, arg); + argNode = gtNewOperNode(GT_COMMA, argNode->TypeGet(), copyBlk, argNode); #endif // FEATURE_FIXED_OUT_ARGS - args->SetNode(arg); - call->fgArgInfo->EvalToTmp(argEntry, tmp, arg); + arg->SetNode(argNode); } #ifdef TARGET_ARM @@ -6771,9 +6070,7 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason) assert(!callee->AreArgsComplete()); - fgInitArgInfo(callee); - - fgArgInfo* argInfo = callee->fgArgInfo; + callee->gtArgs.DetermineArgABIInformation(this, callee); unsigned calleeArgStackSize = 0; unsigned callerArgStackSize = info.compArgStackSize; @@ -6828,20 +6125,20 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason) #endif // DEBUG }; - for (unsigned index = 0; index < argInfo->ArgCount(); ++index) - { - fgArgTabEntry* arg = argInfo->GetArgEntry(index, false); - calleeArgStackSize = roundUp(calleeArgStackSize, arg->GetByteAlignment()); - calleeArgStackSize += arg->GetStackByteSize(); + for (CallArg& arg : callee->gtArgs.Args()) + { + calleeArgStackSize = roundUp(calleeArgStackSize, arg.AbiInfo.ByteAlignment); + calleeArgStackSize += arg.AbiInfo.GetStackByteSize(); #ifdef TARGET_ARM - if (arg->IsSplit()) + if (arg.AbiInfo.IsSplit()) { reportFastTailCallDecision("Splitted argument in callee is not supported on ARM32"); return false; } #endif // TARGET_ARM } + calleeArgStackSize = GetOutgoingArgByteSize(calleeArgStackSize); #ifdef TARGET_ARM @@ -6933,7 +6230,7 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason) return false; } - if (callee->HasRetBufArg()) // RetBuf + if (callee->gtArgs.HasRetBuffer()) { // If callee has RetBuf param, caller too must have it. // Otherwise go the slow route. @@ -6987,17 +6284,14 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason) #if FEATURE_FASTTAILCALL bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) { - fgArgInfo* argInfo = callee->fgArgInfo; - bool hasMustCopyByrefParameter = false; - for (unsigned index = 0; index < argInfo->ArgCount(); ++index) + unsigned argCount = callee->gtArgs.CountArgs(); + for (CallArg& arg : callee->gtArgs.Args()) { - fgArgTabEntry* arg = argInfo->GetArgEntry(index, false); - - if (arg->isStruct) + if (arg.AbiInfo.IsStruct) { - if (arg->passedByRef) + if (arg.AbiInfo.PassedByRef) { // Generally a byref arg will block tail calling, as we have to // make a local copy of the struct for the callee. @@ -7008,7 +6302,7 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) if (opts.OptimizationEnabled()) { // First, see if this arg is an implicit byref param. - GenTreeLclVar* const lcl = arg->GetNode()->IsImplicitByrefParameterValue(this); + GenTreeLclVar* const lcl = arg.GetArgNode()->IsImplicitByrefParameterValue(this); if (lcl != nullptr) { @@ -7021,12 +6315,12 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) if (varDsc->lvPromoted) { JITDUMP("Arg [%06u] is promoted implicit byref V%02u, so no tail call\n", - dspTreeID(arg->GetNode()), lclNum); + dspTreeID(arg.GetNode()), lclNum); } else { JITDUMP("Arg [%06u] is unpromoted implicit byref V%02u, seeing if we can still tail call\n", - dspTreeID(arg->GetNode()), lclNum); + dspTreeID(arg.GetNode()), lclNum); // We have to worry about introducing aliases if we bypass copying // the struct at the call. We'll do some limited analysis to see if we @@ -7060,34 +6354,33 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) JITDUMP("... no, arg has %u non-call appearance(s)\n", totalAppearances - callAppearances); } - else if (argInfo->ArgCount() <= argLimit) + else if (argCount <= argLimit) { JITDUMP("... all %u appearance(s) are as implicit byref args to calls.\n" "... Running alias analysis on this call's args\n", totalAppearances); GenTree* interferingArg = nullptr; - for (unsigned index2 = 0; index2 < argInfo->ArgCount(); ++index2) + for (CallArg& arg2 : callee->gtArgs.Args()) { - if (index2 == index) + if (&arg2 == &arg) { continue; } - fgArgTabEntry* const arg2 = argInfo->GetArgEntry(index2, false); - JITDUMP("... checking other arg [%06u]...\n", dspTreeID(arg2->GetNode())); - DISPTREE(arg2->GetNode()); + JITDUMP("... checking other arg [%06u]...\n", dspTreeID(arg2.GetArgNode())); + DISPTREE(arg2.GetArgNode()); // Do we pass 'lcl' more than once to the callee? - if (arg2->isStruct && arg2->passedByRef) + if (arg2.AbiInfo.IsStruct && arg2.AbiInfo.PassedByRef) { GenTreeLclVarCommon* const lcl2 = - arg2->GetNode()->IsImplicitByrefParameterValue(this); + arg2.GetArgNode()->IsImplicitByrefParameterValue(this); if ((lcl2 != nullptr) && (lclNum == lcl2->GetLclNum())) { // not copying would introduce aliased implicit byref structs // in the callee ... we can't optimize. - interferingArg = arg2->GetNode(); + interferingArg = arg2.GetArgNode(); break; } else @@ -7121,14 +6414,14 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) // transiently retype all simple address-of implicit parameter args as // TYP_I_IMPL. // - if ((arg2->argType == TYP_BYREF) || (arg2->argType == TYP_I_IMPL)) + if ((arg2.AbiInfo.ArgType == TYP_BYREF) || (arg2.AbiInfo.ArgType == TYP_I_IMPL)) { JITDUMP("...arg is a byref, must run an alias check\n"); bool checkExposure = true; bool hasExposure = false; // See if there is any way arg could refer to a parameter struct. - GenTree* arg2Node = arg2->GetNode(); + GenTree* arg2Node = arg2.GetArgNode(); if (arg2Node->OperIs(GT_LCL_VAR)) { GenTreeLclVarCommon* arg2LclNode = arg2Node->AsLclVarCommon(); @@ -7193,14 +6486,14 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) if (hasExposure) { - interferingArg = arg2->GetNode(); + interferingArg = arg2.GetArgNode(); break; } } else { JITDUMP("...arg is not a byref or implicit byref (%s)\n", - varTypeName(arg2->GetNode()->TypeGet())); + varTypeName(arg2.GetArgNode()->TypeGet())); } } @@ -7218,7 +6511,7 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) else { JITDUMP(" ... no, call has %u > %u args, alias analysis deemed too costly\n", - argInfo->ArgCount(), argLimit); + argCount, argLimit); } } } @@ -7332,7 +6625,8 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) if (info.compRetBuffArg != BAD_VAR_NUM) { noway_assert(call->TypeGet() == TYP_VOID); - GenTree* retValBuf = call->gtCallArgs->GetNode(); + noway_assert(call->gtArgs.HasRetBuffer()); + GenTree* retValBuf = call->gtArgs.GetRetBufferArg()->GetArgNode(); if (retValBuf->gtOper != GT_LCL_VAR || retValBuf->AsLclVarCommon()->GetLclNum() != info.compRetBuffArg) { failTailCall("Need to copy return buffer"); @@ -7485,9 +6779,9 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) } } - if (call->gtCallThisArg != nullptr) + if (call->gtArgs.HasThisPointer()) { - var_types thisArgType = call->gtCallThisArg->GetNode()->TypeGet(); + var_types thisArgType = call->gtArgs.GetThisArg()->GetNode()->TypeGet(); if (thisArgType != TYP_REF) { flags |= CORINFO_TAILCALL_THIS_ARG_IS_BYREF; @@ -7545,6 +6839,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) // if (call->IsExpandedEarly() && call->IsVirtualVtable()) { + assert(call->gtArgs.HasThisPointer()); // It isn't alway profitable to expand a virtual call early // // We alway expand the TAILCALL_HELPER type late. @@ -7560,7 +6855,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) call->ClearExpandedEarly(); } else if ((tailCallResult == TAILCALL_OPTIMIZED) && - ((call->gtCallThisArg->GetNode()->gtFlags & GTF_SIDE_EFFECT) != 0)) + ((call->gtArgs.GetThisArg()->GetNode()->gtFlags & GTF_SIDE_EFFECT) != 0)) { // We generate better code when we expand this late in lower instead. // @@ -7618,7 +6913,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) #ifdef TARGET_XARCH // We have already computed arg info to make the fast tailcall decision, but on X64 we now // have to pass the indirection cell, so redo arg info. - call->ResetArgInfo(); + call->gtArgs.ResetArgABIInformation(); #endif } @@ -7878,7 +7173,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) // Force re-evaluating the argInfo. fgMorphTailCallViaJitHelper will modify the // argument list, invalidating the argInfo. - call->fgArgInfo = nullptr; + call->gtArgs.ResetArgABIInformation(); } // Tail call via JIT helper: The VM can't use return address hijacking @@ -8028,16 +7323,16 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL // for non-standard args that we must get rid of. Get rid of that IR here // and do this first as it will 'expose' the retbuf as the first arg, which // we rely upon in fgCreateCallDispatcherAndGetResult. - call->ResetArgInfo(); + call->gtArgs.ResetArgABIInformation(); GenTree* callDispatcherAndGetResult = fgCreateCallDispatcherAndGetResult(call, help.hCallTarget, help.hDispatcher); // Change the call to a call to the StoreArgs stub. - if (call->HasRetBufArg()) + if (call->gtArgs.HasRetBuffer()) { JITDUMP("Removing retbuf"); - call->gtCallArgs = call->gtCallArgs->GetNext(); + call->gtArgs.Remove(call->gtArgs.GetRetBufferArg()); call->gtCallMoreFlags &= ~GTF_CALL_M_RETBUFFARG; } @@ -8047,12 +7342,12 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL GenTree* thisPtrStubArg = nullptr; // Put 'this' in normal param list - if (call->gtCallThisArg != nullptr) + if (call->gtArgs.HasThisPointer()) { JITDUMP("Moving this pointer into arg list\n"); - GenTree* objp = call->gtCallThisArg->GetNode(); + CallArg* thisArg = call->gtArgs.GetThisArg(); + GenTree* objp = thisArg->GetArgNode(); GenTree* thisPtr = nullptr; - call->gtCallThisArg = nullptr; // JIT will need one or two copies of "this" in the following cases: // 1) the call needs null check; @@ -8062,11 +7357,6 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL const bool callNeedsNullCheck = call->NeedsNullCheck(); const bool stubNeedsThisPtr = stubNeedsTargetFnPtr && call->IsVirtual(); - // TODO-Review: The following transformation is implemented under assumption that - // both conditions can be true. However, I could not construct such example - // where a virtual tail call would require null check. In case, if the conditions - // are mutually exclusive the following could be simplified. - if (callNeedsNullCheck || stubNeedsThisPtr) { // Clone "this" if "this" has no side effects. @@ -8129,8 +7419,8 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL // During rationalization tmp="this" and null check will be materialized // in the right execution order. - assert(thisPtr != nullptr); - call->gtCallArgs = gtPrependNewCallArg(thisPtr, call->gtCallArgs); + call->gtArgs.PushFront(this, thisPtr); + call->gtArgs.Remove(thisArg); } // We may need to pass the target, for instance for calli or generic methods @@ -8181,14 +7471,7 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL target = getVirtMethodPointerTree(thisPtrStubArg, call->tailCallInfo->GetToken(), &callInfo); } - // Insert target as last arg - GenTreeCall::Use** newArgSlot = &call->gtCallArgs; - while (*newArgSlot != nullptr) - { - newArgSlot = &(*newArgSlot)->NextRef(); - } - - *newArgSlot = gtNewCallArgs(target); + call->gtArgs.PushBack(this, target); } // This is now a direct call to the store args stub and not a tailcall. @@ -8250,7 +7533,7 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig CORINFO_METHOD_HANDLE dispatcherHnd) { GenTreeCall* callDispatcherNode = - gtNewCallNode(CT_USER_FUNC, dispatcherHnd, TYP_VOID, nullptr, fgMorphStmt->GetDebugInfo()); + gtNewCallNode(CT_USER_FUNC, dispatcherHnd, TYP_VOID, fgMorphStmt->GetDebugInfo()); // The dispatcher has signature // void DispatchTailCalls(void* callersRetAddrSlot, void* callTarget, void* retValue) @@ -8260,10 +7543,10 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig unsigned int newRetLcl = BAD_VAR_NUM; GenTree* copyToRetBufNode = nullptr; - if (origCall->HasRetBufArg()) + if (origCall->gtArgs.HasRetBuffer()) { JITDUMP("Transferring retbuf\n"); - GenTree* retBufArg = origCall->gtCallArgs->GetNode(); + GenTree* retBufArg = origCall->gtArgs.GetRetBufferArg()->GetNode(); assert(info.compRetBuffArg != BAD_VAR_NUM); assert(retBufArg->OperIsLocal()); @@ -8331,12 +7614,8 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig retValArg = gtNewZeroConNode(TYP_I_IMPL); } - callDispatcherNode->gtCallArgs = gtPrependNewCallArg(retValArg, callDispatcherNode->gtCallArgs); - - // Add callTarget - callDispatcherNode->gtCallArgs = - gtPrependNewCallArg(new (this, GT_FTN_ADDR) GenTreeFptrVal(TYP_I_IMPL, callTargetStubHnd), - callDispatcherNode->gtCallArgs); + // Args are (void** callersReturnAddressSlot, void* callTarget, void* retVal) + GenTree* callTarget = new (this, GT_FTN_ADDR) GenTreeFptrVal(TYP_I_IMPL, callTargetStubHnd); // Add the caller's return address slot. if (lvaRetAddrVar == BAD_VAR_NUM) @@ -8347,7 +7626,8 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig } GenTree* retAddrSlot = gtNewOperNode(GT_ADDR, TYP_I_IMPL, gtNewLclvNode(lvaRetAddrVar, TYP_I_IMPL)); - callDispatcherNode->gtCallArgs = gtPrependNewCallArg(retAddrSlot, callDispatcherNode->gtCallArgs); + + callDispatcherNode->gtArgs.PushFront(this, retAddrSlot, callTarget, retValArg); GenTree* finalTree = callDispatcherNode; @@ -8536,8 +7816,7 @@ GenTree* Compiler::getVirtMethodPointerTree(GenTree* thisPtr, GenTree* exactTypeDesc = getTokenHandleTree(pResolvedToken, true); GenTree* exactMethodDesc = getTokenHandleTree(pResolvedToken, false); - GenTreeCall::Use* helpArgs = gtNewCallArgs(thisPtr, exactTypeDesc, exactMethodDesc); - return gtNewHelperCallNode(CORINFO_HELP_VIRTUAL_FUNC_PTR, TYP_I_IMPL, helpArgs); + return gtNewHelperCallNode(CORINFO_HELP_VIRTUAL_FUNC_PTR, TYP_I_IMPL, thisPtr, exactTypeDesc, exactMethodDesc); } //------------------------------------------------------------------------ @@ -8646,11 +7925,11 @@ void Compiler::fgMorphTailCallViaJitHelper(GenTreeCall* call) // for those cases where call lowering creates an embedded form temp of "this", we will // create a temp here, early, that will later get morphed correctly. - if (call->gtCallThisArg != nullptr) + CallArg* thisArg = call->gtArgs.GetThisArg(); + if (thisArg != nullptr) { GenTree* thisPtr = nullptr; - GenTree* objp = call->gtCallThisArg->GetNode(); - call->gtCallThisArg = nullptr; + GenTree* objp = thisArg->GetNode(); if ((call->IsDelegateInvoke() || call->IsVirtualVtable()) && !objp->OperIs(GT_LCL_VAR)) { @@ -8712,44 +7991,29 @@ void Compiler::fgMorphTailCallViaJitHelper(GenTreeCall* call) // During rationalization tmp="this" and null check will // materialize as embedded stmts in right execution order. assert(thisPtr != nullptr); - call->gtCallArgs = gtPrependNewCallArg(thisPtr, call->gtCallArgs); + call->gtArgs.PushFront(this, thisPtr); + call->gtArgs.Remove(thisArg); } - // Find the end of the argument list. ppArg will point at the last pointer; setting *ppArg will - // append to the list. - GenTreeCall::Use** ppArg = &call->gtCallArgs; - for (GenTreeCall::Use& use : call->Args()) - { - ppArg = &use.NextRef(); - } - assert(ppArg != nullptr); - assert(*ppArg == nullptr); - unsigned nOldStkArgsWords = (compArgSize - (codeGen->intRegState.rsCalleeRegArgCount * REGSIZE_BYTES)) / REGSIZE_BYTES; - GenTree* arg3 = gtNewIconNode((ssize_t)nOldStkArgsWords, TYP_I_IMPL); - *ppArg = gtNewCallArgs(arg3); // numberOfOldStackArgs - ppArg = &((*ppArg)->NextRef()); - + GenTree* arg3Node = gtNewIconNode((ssize_t)nOldStkArgsWords, TYP_I_IMPL); + CallArg* arg3 = call->gtArgs.PushBack(this, arg3Node); // Inject a placeholder for the count of outgoing stack arguments that the Lowering phase will generate. // The constant will be replaced. - GenTree* arg2 = gtNewIconNode(9, TYP_I_IMPL); - *ppArg = gtNewCallArgs(arg2); // numberOfNewStackArgs - ppArg = &((*ppArg)->NextRef()); - + GenTree* arg2Node = gtNewIconNode(9, TYP_I_IMPL); + CallArg* arg2 = call->gtArgs.InsertAfter(this, arg3, arg2Node); // Inject a placeholder for the flags. // The constant will be replaced. - GenTree* arg1 = gtNewIconNode(8, TYP_I_IMPL); - *ppArg = gtNewCallArgs(arg1); - ppArg = &((*ppArg)->NextRef()); - + GenTree* arg1Node = gtNewIconNode(8, TYP_I_IMPL); + CallArg* arg1 = call->gtArgs.InsertAfter(this, arg2, arg1Node); // Inject a placeholder for the real call target that the Lowering phase will generate. // The constant will be replaced. - GenTree* arg0 = gtNewIconNode(7, TYP_I_IMPL); - *ppArg = gtNewCallArgs(arg0); + GenTree* arg0Node = gtNewIconNode(7, TYP_I_IMPL); + CallArg* arg0 = call->gtArgs.InsertAfter(this, arg1, arg0Node); // It is now a varargs tail call. - call->gtCallMoreFlags |= GTF_CALL_M_VARARGS; + call->gtArgs.SetIsVarArgs(); call->gtFlags &= ~GTF_CALL_POP_ARGS; // The function is responsible for doing explicit null check when it is necessary. @@ -8804,27 +8068,26 @@ GenTree* Compiler::fgGetStubAddrArg(GenTreeCall* call) // arg for the R2R indirection cell. // // Arguments: -// argTabEntry - the arg +// arg - the arg // -unsigned Compiler::fgGetArgTabEntryParameterLclNum(GenTreeCall* call, fgArgTabEntry* argTabEntry) +unsigned Compiler::fgGetArgParameterLclNum(GenTreeCall* call, CallArg* arg) { - fgArgInfo* argInfo = call->fgArgInfo; - unsigned argCount = argInfo->ArgCount(); - fgArgTabEntry** argTable = argInfo->ArgTable(); + unsigned num = arg->AbiInfo.ArgNum; - unsigned numToRemove = 0; - for (unsigned i = 0; i < argCount; i++) + for (CallArg& otherArg : call->gtArgs.Args()) { - fgArgTabEntry* arg = argTable[i]; + if (&otherArg == arg) + { + break; + } // Late added args add extra args that do not map to IL parameters and that we should not reassign. - if (!arg->isNonStandard() || !arg->isNonStandardArgAddedLate()) + if (!otherArg.IsArgAddedLate()) continue; - if (arg->argNum < argTabEntry->argNum) - numToRemove++; + num--; } - return argTabEntry->argNum - numToRemove; + return num; } //------------------------------------------------------------------------------ @@ -8849,14 +8112,6 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa Statement* earlyArgInsertionPoint = lastStmt; const DebugInfo& callDI = lastStmt->GetDebugInfo(); - // Hoist arg setup statement for the 'this' argument. - GenTreeCall::Use* thisArg = recursiveTailCall->gtCallThisArg; - if ((thisArg != nullptr) && !thisArg->GetNode()->IsNothingNode() && !thisArg->GetNode()->IsArgPlaceHolderNode()) - { - Statement* thisArgStmt = gtNewStmt(thisArg->GetNode(), callDI); - fgInsertStmtBefore(block, earlyArgInsertionPoint, thisArgStmt); - } - // All arguments whose trees may involve caller parameter local variables need to be assigned to temps first; // then the temps need to be assigned to the method parameters. This is done so that the caller // parameters are not re-assigned before call arguments depending on them are evaluated. @@ -8902,10 +8157,9 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa // Process early args. They may contain both setup statements for late args and actual args. // Early args don't include 'this' arg. We need to account for that so that the call to gtArgEntryByArgNum // below has the correct second argument. - int earlyArgIndex = (thisArg == nullptr) ? 0 : 1; - for (GenTreeCall::Use& use : recursiveTailCall->Args()) + for (CallArg& arg : recursiveTailCall->gtArgs.Args()) { - GenTree* earlyArg = use.GetNode(); + GenTree* earlyArg = arg.GetNode(); if (!earlyArg->IsNothingNode() && !earlyArg->IsArgPlaceHolderNode()) { if ((earlyArg->gtFlags & GTF_LATE_ARG) != 0) @@ -8917,14 +8171,12 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa else { // This is an actual argument that needs to be assigned to the corresponding caller parameter. - fgArgTabEntry* curArgTabEntry = gtArgEntryByArgNum(recursiveTailCall, earlyArgIndex); // Late-added non-standard args are extra args that are not passed as locals, so skip those - if (!curArgTabEntry->isNonStandard() || !curArgTabEntry->isNonStandardArgAddedLate()) + if (!arg.IsArgAddedLate()) { Statement* paramAssignStmt = - fgAssignRecursiveCallArgToCallerParam(earlyArg, curArgTabEntry, - fgGetArgTabEntryParameterLclNum(recursiveTailCall, - curArgTabEntry), + fgAssignRecursiveCallArgToCallerParam(earlyArg, &arg, + fgGetArgParameterLclNum(recursiveTailCall, &arg), block, callDI, tmpAssignmentInsertionPoint, paramAssignmentInsertionPoint); if ((tmpAssignmentInsertionPoint == lastStmt) && (paramAssignStmt != nullptr)) @@ -8935,23 +8187,19 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa } } } - earlyArgIndex++; } // Process late args. - int lateArgIndex = 0; - for (GenTreeCall::Use& use : recursiveTailCall->LateArgs()) + for (LateArg arg : recursiveTailCall->gtArgs.LateArgs()) { // A late argument is an actual argument that needs to be assigned to the corresponding caller's parameter. - GenTree* lateArg = use.GetNode(); - fgArgTabEntry* curArgTabEntry = gtArgEntryByLateArgIndex(recursiveTailCall, lateArgIndex); + GenTree* lateArg = arg.GetNode(); // Late-added non-standard args are extra args that are not passed as locals, so skip those - if (!curArgTabEntry->isNonStandard() || !curArgTabEntry->isNonStandardArgAddedLate()) + if (!arg.GetArg()->IsArgAddedLate()) { Statement* paramAssignStmt = - fgAssignRecursiveCallArgToCallerParam(lateArg, curArgTabEntry, - fgGetArgTabEntryParameterLclNum(recursiveTailCall, - curArgTabEntry), + fgAssignRecursiveCallArgToCallerParam(lateArg, arg.GetArg(), + fgGetArgParameterLclNum(recursiveTailCall, arg.GetArg()), block, callDI, tmpAssignmentInsertionPoint, paramAssignmentInsertionPoint); @@ -8961,7 +8209,6 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa tmpAssignmentInsertionPoint = paramAssignStmt; } } - lateArgIndex++; } // If the method has starg.s 0 or ldarga.s 0 a special local (lvaArg0Var) is created so that @@ -9054,7 +8301,7 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa // // Arguments: // arg - argument to assign -// argTabEntry - argument table entry corresponding to arg +// late - whether to use early or late arg // lclParamNum - the lcl num of the parameter // block --- basic block the call is in // callILOffset - IL offset of the call @@ -9064,8 +8311,8 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa // Return Value: // parameter assignment statement if one was inserted; nullptr otherwise. -Statement* Compiler::fgAssignRecursiveCallArgToCallerParam(GenTree* arg, - fgArgTabEntry* argTabEntry, +Statement* Compiler::fgAssignRecursiveCallArgToCallerParam(GenTree* arg, + CallArg* callArg, unsigned lclParamNum, BasicBlock* block, const DebugInfo& callDI, @@ -9081,7 +8328,7 @@ Statement* Compiler::fgAssignRecursiveCallArgToCallerParam(GenTree* arg, // TODO-CQ: enable calls with struct arguments passed in registers. noway_assert(!varTypeIsStruct(arg->TypeGet())); - if ((argTabEntry->isTmp) || arg->IsCnsIntOrI() || arg->IsCnsFltOrDbl()) + if (callArg->IsTemp() || arg->IsCnsIntOrI() || arg->IsCnsFltOrDbl()) { // The argument is already assigned to a temp or is a const. argInTemp = arg; @@ -9165,7 +8412,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) // ret temp // Force re-evaluating the argInfo as the return argument has changed. - call->ResetArgInfo(); + call->gtArgs.ResetArgABIInformation(); // Create a new temp. unsigned tmpNum = @@ -9215,7 +8462,8 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) // This is call to CORINFO_HELP_VIRTUAL_FUNC_PTR with ignored result. // Transform it into a null check. - GenTree* thisPtr = call->gtCallArgs->GetNode(); + assert(call->gtArgs.CountArgs() >= 1); + GenTree* thisPtr = call->gtArgs.GetArgByIndex(0)->GetArgNode(); GenTree* nullCheck = gtNewNullCheck(thisPtr, compCurBB); @@ -9317,29 +8565,30 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) if (opts.OptimizationEnabled() && (call->gtCallType == CT_HELPER) && (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ARRADDR_ST))) { - GenTree* value = gtArgEntryByArgNum(call, 2)->GetNode(); + assert(call->gtArgs.CountArgs() == 3); + GenTree* value = call->gtArgs.GetArgByIndex(2)->GetArgNode(); if (value->IsIntegralConst(0)) { assert(value->OperGet() == GT_CNS_INT); - GenTree* arr = gtArgEntryByArgNum(call, 0)->GetNode(); - GenTree* index = gtArgEntryByArgNum(call, 1)->GetNode(); + GenTree* arr = call->gtArgs.GetArgByIndex(0)->GetArgNode(); + GenTree* index = call->gtArgs.GetArgByIndex(1)->GetArgNode(); // Either or both of the array and index arguments may have been spilled to temps by `fgMorphArgs`. Copy // the spill trees as well if necessary. GenTreeOp* argSetup = nullptr; - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree* const arg = use.GetNode(); - if (arg->OperGet() != GT_ASG) + GenTree* const argNode = arg.GetNode(); + if (argNode->OperGet() != GT_ASG) { continue; } - assert(arg != arr); - assert(arg != index); + assert(argNode != arr); + assert(argNode != index); - arg->gtFlags &= ~GTF_LATE_ARG; + argNode->gtFlags &= ~GTF_LATE_ARG; GenTree* op1 = argSetup; if (op1 == nullptr) @@ -9350,7 +8599,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) #endif // DEBUG } - argSetup = new (this, GT_COMMA) GenTreeOp(GT_COMMA, TYP_VOID, op1, arg); + argSetup = new (this, GT_COMMA) GenTreeOp(GT_COMMA, TYP_VOID, op1, argNode); #if DEBUG argSetup->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED; @@ -9420,9 +8669,9 @@ GenTree* Compiler::fgExpandVirtualVtableCallTarget(GenTreeCall* call) noway_assert(call->gtCallType == CT_USER_FUNC); + assert(call->gtArgs.HasThisPointer()); // get a reference to the thisPtr being passed - fgArgTabEntry* thisArgTabEntry = gtArgEntryByArgNum(call, 0); - GenTree* thisPtr = thisArgTabEntry->GetNode(); + GenTree* thisPtr = call->gtArgs.GetThisArg()->GetArgNode(); // fgMorphArgs must enforce this invariant by creating a temp // @@ -9580,18 +8829,15 @@ GenTree* Compiler::fgMorphConst(GenTree* tree) { // For un-important blocks, we want to construct the string lazily - GenTreeCall::Use* args; if (helper == CORINFO_HELP_STRCNS_CURRENT_MODULE) { - args = gtNewCallArgs(gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT)); + tree = gtNewHelperCallNode(helper, TYP_REF, gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT)); } else { - args = gtNewCallArgs(gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT), - gtNewIconEmbScpHndNode(tree->AsStrCon()->gtScpHnd)); + tree = gtNewHelperCallNode(helper, TYP_REF, gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT), gtNewIconEmbScpHndNode(tree->AsStrCon()->gtScpHnd)); } - tree = gtNewHelperCallNode(helper, TYP_REF, args); return fgMorphTree(tree); } } @@ -11556,7 +10802,8 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) return fgMorphTree(tree); } } - return fgMorphIntoHelperCall(tree, helper, gtNewCallArgs(op1, op2)); + + return fgMorphIntoHelperCall(tree, helper, op1, op2); case GT_RETURN: if (!tree->TypeIs(TYP_VOID)) @@ -11686,9 +10933,9 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) switch (tree->TypeGet()) { case TYP_DOUBLE: - return fgMorphIntoHelperCall(tree, CORINFO_HELP_DBLROUND, gtNewCallArgs(op1)); + return fgMorphIntoHelperCall(tree, CORINFO_HELP_DBLROUND, op1); case TYP_FLOAT: - return fgMorphIntoHelperCall(tree, CORINFO_HELP_FLTROUND, gtNewCallArgs(op1)); + return fgMorphIntoHelperCall(tree, CORINFO_HELP_FLTROUND, op1); default: unreached(); } @@ -16695,7 +15942,7 @@ GenTree* Compiler::fgInitThisClass() // base of the class that owns the method being compiled". If we're in this method, it means we're not // inlining and there's no ambiguity. return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, TYP_BYREF, - gtNewCallArgs(ctxTree), &kind); + ctxTree, &kind); } #endif @@ -16716,14 +15963,14 @@ GenTree* Compiler::fgInitThisClass() vtTree = gtNewMethodTableLookup(vtTree); GenTree* methodHnd = gtNewIconEmbMethHndNode(info.compMethodHnd); - return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, TYP_VOID, gtNewCallArgs(vtTree, methodHnd)); + return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, TYP_VOID, vtTree, methodHnd); } case CORINFO_LOOKUP_CLASSPARAM: { GenTree* vtTree = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL); vtTree->gtFlags |= GTF_VAR_CONTEXT; - return gtNewHelperCallNode(CORINFO_HELP_INITCLASS, TYP_VOID, gtNewCallArgs(vtTree)); + return gtNewHelperCallNode(CORINFO_HELP_INITCLASS, TYP_VOID, vtTree); } case CORINFO_LOOKUP_METHODPARAM: @@ -16731,7 +15978,7 @@ GenTree* Compiler::fgInitThisClass() GenTree* methHndTree = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL); methHndTree->gtFlags |= GTF_VAR_CONTEXT; return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, TYP_VOID, - gtNewCallArgs(gtNewIconNode(0), methHndTree)); + gtNewIconNode(0), methHndTree); } default: diff --git a/src/coreclr/jit/objectalloc.cpp b/src/coreclr/jit/objectalloc.cpp index 0c66dd39a17736..68ec4391dc3d1e 100644 --- a/src/coreclr/jit/objectalloc.cpp +++ b/src/coreclr/jit/objectalloc.cpp @@ -451,25 +451,20 @@ GenTree* ObjectAllocator::MorphAllocObjNodeIntoHelperCall(GenTreeAllocObj* alloc { assert(allocObj != nullptr); - GenTree* op1 = allocObj->gtGetOp1(); + GenTree* arg = allocObj->gtGetOp1(); unsigned int helper = allocObj->gtNewHelper; bool helperHasSideEffects = allocObj->gtHelperHasSideEffects; - GenTreeCall::Use* args; #ifdef FEATURE_READYTORUN CORINFO_CONST_LOOKUP entryPoint = allocObj->gtEntryPoint; if (helper == CORINFO_HELP_READYTORUN_NEW) { - args = nullptr; + arg = nullptr; } - else #endif - { - args = comp->gtNewCallArgs(op1); - } const bool morphArgs = false; - GenTree* helperCall = comp->fgMorphIntoHelperCall(allocObj, allocObj->gtNewHelper, args, morphArgs); + GenTree* helperCall = comp->fgMorphIntoHelperCall(allocObj, allocObj->gtNewHelper, arg, nullptr, morphArgs); if (helperHasSideEffects) { helperCall->AsCall()->gtCallMoreFlags |= GTF_CALL_M_ALLOC_SIDE_EFFECTS; diff --git a/src/coreclr/jit/patchpoint.cpp b/src/coreclr/jit/patchpoint.cpp index 15a37150326183..8c14eba1b5c2f0 100644 --- a/src/coreclr/jit/patchpoint.cpp +++ b/src/coreclr/jit/patchpoint.cpp @@ -179,8 +179,7 @@ class PatchpointTransformer GenTree* ilOffsetNode = compiler->gtNewIconNode(ilOffset, TYP_INT); GenTree* ppCounterRef = compiler->gtNewLclvNode(ppCounterLclNum, TYP_INT); GenTree* ppCounterAddr = compiler->gtNewOperNode(GT_ADDR, TYP_I_IMPL, ppCounterRef); - GenTreeCall::Use* helperArgs = compiler->gtNewCallArgs(ppCounterAddr, ilOffsetNode); - GenTreeCall* helperCall = compiler->gtNewHelperCallNode(CORINFO_HELP_PATCHPOINT, TYP_VOID, helperArgs); + GenTreeCall* helperCall = compiler->gtNewHelperCallNode(CORINFO_HELP_PATCHPOINT, TYP_VOID, ppCounterAddr, ilOffsetNode); compiler->fgNewStmtAtEnd(helperBlock, helperCall); } @@ -240,9 +239,8 @@ class PatchpointTransformer // call PartialCompilationPatchpointHelper(ilOffset) // GenTree* ilOffsetNode = compiler->gtNewIconNode(ilOffset, TYP_INT); - GenTreeCall::Use* helperArgs = compiler->gtNewCallArgs(ilOffsetNode); GenTreeCall* helperCall = - compiler->gtNewHelperCallNode(CORINFO_HELP_PARTIAL_COMPILATION_PATCHPOINT, TYP_VOID, helperArgs); + compiler->gtNewHelperCallNode(CORINFO_HELP_PARTIAL_COMPILATION_PATCHPOINT, TYP_VOID, ilOffsetNode); compiler->fgNewStmtAtEnd(block, helperCall); } diff --git a/src/coreclr/jit/rationalize.cpp b/src/coreclr/jit/rationalize.cpp index 9b357e2668592b..8635961e9dc49f 100644 --- a/src/coreclr/jit/rationalize.cpp +++ b/src/coreclr/jit/rationalize.cpp @@ -197,7 +197,8 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use, #ifdef FEATURE_READYTORUN CORINFO_CONST_LOOKUP entryPoint, #endif - GenTreeCall::Use* args) + GenTree* arg1, + GenTree* arg2) { GenTree* const tree = *use; GenTree* const treeFirstNode = comp->fgGetFirstNode(tree); @@ -206,7 +207,16 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use, BlockRange().Remove(treeFirstNode, tree); // Create the call node - GenTreeCall* call = comp->gtNewCallNode(CT_USER_FUNC, callHnd, tree->gtType, args); + GenTreeCall* call = comp->gtNewCallNode(CT_USER_FUNC, callHnd, tree->gtType); + + if (arg1 != nullptr) + { + CallArg* carg1 = call->gtArgs.PushFront(comp, arg1); + if (arg2 != nullptr) + { + call->gtArgs.InsertAfter(comp, carg1, arg2); + } + } #if DEBUG CORINFO_SIG_INFO sig; @@ -267,21 +277,13 @@ void Rationalizer::RewriteIntrinsicAsUserCall(GenTree** use, ArrayStackAsIntrinsic(); - GenTreeCall::Use* args; - if (intrinsic->AsOp()->gtOp2 == nullptr) - { - args = comp->gtNewCallArgs(intrinsic->gtGetOp1()); - } - else - { - args = comp->gtNewCallArgs(intrinsic->gtGetOp1(), intrinsic->gtGetOp2()); - } - + GenTree* arg1 = intrinsic->gtGetOp1(); + GenTree* arg2 = intrinsic->gtGetOp2(); RewriteNodeAsCall(use, parents, intrinsic->gtMethodHandle, #ifdef FEATURE_READYTORUN intrinsic->gtEntryPoint, #endif - args); + arg1, arg2); } #ifdef DEBUG diff --git a/src/coreclr/jit/rationalize.h b/src/coreclr/jit/rationalize.h index cbcbbfef070368..47d355cbbd38f4 100644 --- a/src/coreclr/jit/rationalize.h +++ b/src/coreclr/jit/rationalize.h @@ -49,7 +49,8 @@ class Rationalizer final : public Phase #ifdef FEATURE_READYTORUN CORINFO_CONST_LOOKUP entryPoint, #endif - GenTreeCall::Use* args); + GenTree* arg1 = nullptr, + GenTree* arg2 = nullptr); void RewriteIntrinsicAsUserCall(GenTree** use, Compiler::GenTreeStack& parents); diff --git a/src/coreclr/jit/stacklevelsetter.cpp b/src/coreclr/jit/stacklevelsetter.cpp index 54d5d48d4cf2ca..363629e40f9623 100644 --- a/src/coreclr/jit/stacklevelsetter.cpp +++ b/src/coreclr/jit/stacklevelsetter.cpp @@ -238,16 +238,14 @@ void StackLevelSetter::SetThrowHelperBlock(SpecialCodeKind kind, BasicBlock* blo unsigned StackLevelSetter::PopArgumentsFromCall(GenTreeCall* call) { unsigned usedStackSlotsCount = 0; - fgArgInfo* argInfo = call->fgArgInfo; - if (argInfo->HasStackArgs()) + if (call->gtArgs.HasStackArgs()) { - for (unsigned i = 0; i < argInfo->ArgCount(); ++i) + for (CallArg& arg : call->gtArgs.Args()) { - const fgArgTabEntry* argTab = argInfo->ArgTable()[i]; - const unsigned slotCount = argTab->GetStackSlotsNumber(); + const unsigned slotCount = arg.AbiInfo.GetStackSlotsNumber(); if (slotCount != 0) { - GenTree* node = argTab->GetNode(); + GenTree* node = arg.GetArgNode(); assert(node->OperIsPutArgStkOrSplit()); GenTreePutArgStk* putArg = node->AsPutArgStk(); diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 0375e31f972622..c67cbc407af761 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -9776,7 +9776,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN { unsigned nArgs = ValueNumStore::VNFuncArity(vnf); assert(vnf != VNF_Boundary); - GenTreeCall::Use* args = call->gtCallArgs; + CallArgs* args = &call->gtArgs; bool generateUniqueVN = false; bool useEntryPointAddrAsArg0 = false; @@ -9792,7 +9792,8 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_JitNewArr: { generateUniqueVN = true; - ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetNext()->GetNode()->gtVNPair); + // TODO-ARGS: Should this really be early arg? + ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetArgByIndex(1)->GetNode()->gtVNPair); // The New Array helper may throw an overflow exception vnpExc = vnStore->VNPExcSetSingleton(vnStore->VNPairForFunc(TYP_REF, VNF_NewArrOverflowExc, vnp1)); @@ -9829,7 +9830,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_JitReadyToRunNewArr: { generateUniqueVN = true; - ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetNode()->gtVNPair); + ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetArgByIndex(0)->GetNode()->gtVNPair); // The New Array helper may throw an overflow exception vnpExc = vnStore->VNPExcSetSingleton(vnStore->VNPairForFunc(TYP_REF, VNF_NewArrOverflowExc, vnp1)); @@ -9870,10 +9871,10 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN if (call->IsR2RRelativeIndir()) { #ifdef DEBUG - assert(args->GetNode()->OperGet() == GT_ARGPLACE); + assert(args->GetArgByIndex(0)->GetNode()->OperGet() == GT_ARGPLACE); // Find the corresponding late arg. - GenTree* indirectCellAddress = call->fgArgInfo->GetArgNode(0); + GenTree* indirectCellAddress = args->GetArgByIndex(0)->GetArgNode(); assert(indirectCellAddress->IsCnsIntOrI() && indirectCellAddress->GetRegNum() == REG_R2R_INDIRECT_PARAM); #endif // DEBUG @@ -9883,6 +9884,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN } #endif // FEATURE_READYTORUN && TARGET_ARMARCH + CallArg* curArg = &*args->Args().begin(); if (nArgs == 0) { if (generateUniqueVN) @@ -9896,24 +9898,6 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN } else { - auto getCurrentArg = [call, &args, useEntryPointAddrAsArg0](int currentIndex) { - GenTree* arg = args->GetNode(); - if ((arg->gtFlags & GTF_LATE_ARG) != 0) - { - // This arg is a setup node that moves the arg into position. - // Value-numbering will have visited the separate late arg that - // holds the actual value, and propagated/computed the value number - // for this arg there. - if (useEntryPointAddrAsArg0) - { - // The args in the fgArgInfo don't include the entry point, so - // index into them using one less than the requested index. - --currentIndex; - } - return call->fgArgInfo->GetArgNode(currentIndex); - } - return arg; - }; // Has at least one argument. ValueNumPair vnp0; ValueNumPair vnp0x = ValueNumStore::VNPForEmptyExcSet(); @@ -9928,13 +9912,13 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN #endif // FEATURE_READYTORUN { assert(!useEntryPointAddrAsArg0); - ValueNumPair vnp0wx = getCurrentArg(0)->gtVNPair; + ValueNumPair vnp0wx = curArg->GetArgNode()->gtVNPair; vnStore->VNPUnpackExc(vnp0wx, &vnp0, &vnp0x); // Also include in the argument exception sets vnpExc = vnStore->VNPExcSetUnion(vnpExc, vnp0x); - args = args->GetNext(); + curArg = curArg->GetNext(); } if (nArgs == 1) { @@ -9950,13 +9934,13 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN else { // Has at least two arguments. - ValueNumPair vnp1wx = getCurrentArg(1)->gtVNPair; + ValueNumPair vnp1wx = curArg->GetArgNode()->gtVNPair; ValueNumPair vnp1; ValueNumPair vnp1x; vnStore->VNPUnpackExc(vnp1wx, &vnp1, &vnp1x); vnpExc = vnStore->VNPExcSetUnion(vnpExc, vnp1x); - args = args->GetNext(); + curArg = curArg->GetNext(); if (nArgs == 2) { if (generateUniqueVN) @@ -9970,15 +9954,15 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN } else { - ValueNumPair vnp2wx = getCurrentArg(2)->gtVNPair; + ValueNumPair vnp2wx = curArg->GetNode()->gtVNPair; ValueNumPair vnp2; ValueNumPair vnp2x; vnStore->VNPUnpackExc(vnp2wx, &vnp2, &vnp2x); vnpExc = vnStore->VNPExcSetUnion(vnpExc, vnp2x); - args = args->GetNext(); + curArg = curArg->GetNext(); assert(nArgs == 3); // Our current maximum. - assert(args == nullptr); + assert(curArg == nullptr); if (generateUniqueVN) { call->gtVNPair = vnStore->VNPairForFunc(call->TypeGet(), vnf, vnp0, vnp1, vnp2, vnpUniq); @@ -9992,8 +9976,8 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN // Add the accumulated exceptions. call->gtVNPair = vnStore->VNPWithExc(call->gtVNPair, vnpExc); } - assert(args == nullptr || generateUniqueVN); // All arguments should be processed or we generate unique VN and do - // not care. + assert(curArg == nullptr || generateUniqueVN); // All arguments should be processed or we generate unique VN and do + // not care. } void Compiler::fgValueNumberCall(GenTreeCall* call) @@ -10001,37 +9985,24 @@ void Compiler::fgValueNumberCall(GenTreeCall* call) // First: do value numbering of any argument placeholder nodes in the argument list // (by transferring from the VN of the late arg that they are standing in for...) - auto updateArgVN = [=](GenTree* arg, unsigned argIndex) { - if (arg->OperGet() == GT_ARGPLACE) + for (LateArg lateArg : call->gtArgs.LateArgs()) + { + CallArg* arg = lateArg.GetArg(); + if (arg->GetNode()->OperIs(GT_ARGPLACE)) { - // Find the corresponding late arg. - GenTree* lateArg = call->fgArgInfo->GetArgNode(argIndex); - assert(lateArg->gtVNPair.BothDefined()); - arg->gtVNPair = lateArg->gtVNPair; + assert(lateArg.GetNode()->gtVNPair.BothDefined()); + arg->GetNode()->gtVNPair = lateArg.GetNode()->gtVNPair; #ifdef DEBUG if (verbose) { printf("VN of ARGPLACE tree "); - Compiler::printTreeID(arg); + Compiler::printTreeID(arg->GetNode()); printf(" updated to "); - vnpPrint(arg->gtVNPair, 1); + vnpPrint(arg->GetNode()->gtVNPair, 1); printf("\n"); } #endif } - }; - - unsigned argIndex = 0; - if (call->gtCallThisArg != nullptr) - { - updateArgVN(call->gtCallThisArg->GetNode(), argIndex); - argIndex++; - } - - for (GenTreeCall::Use& use : call->Args()) - { - updateArgVN(use.GetNode(), argIndex); - argIndex++; } if (call->gtCallType == CT_HELPER) @@ -10151,7 +10122,7 @@ void Compiler::fgValueNumberCastHelper(GenTreeCall* call) unreached(); } - ValueNumPair argVNP = call->fgArgInfo->GetArgNode(0)->gtVNPair; + ValueNumPair argVNP = call->gtArgs.GetArgByIndex(0)->GetArgNode()->gtVNPair; ValueNumPair castVNP = vnStore->VNPairForCast(argVNP, castToType, castFromType, srcIsUnsigned, hasOverflowCheck); call->SetVNs(castVNP); From 8b8271993a396b8d4a854efcb7fdca57d69277b1 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 17:46:27 +0200 Subject: [PATCH 02/52] Run jit-format --- src/coreclr/jit/assertionprop.cpp | 4 +- src/coreclr/jit/codegenarmarch.cpp | 2 +- src/coreclr/jit/codegencommon.cpp | 2 +- src/coreclr/jit/codegenxarch.cpp | 6 +- src/coreclr/jit/compiler.cpp | 4 +- src/coreclr/jit/compiler.h | 24 +- src/coreclr/jit/compiler.hpp | 5 +- src/coreclr/jit/fgprofile.cpp | 11 +- src/coreclr/jit/flowgraph.cpp | 40 +-- src/coreclr/jit/gentree.cpp | 339 ++++++++++---------- src/coreclr/jit/gentree.h | 142 +++++--- src/coreclr/jit/importer.cpp | 116 +++---- src/coreclr/jit/indirectcalltransformer.cpp | 2 +- src/coreclr/jit/inline.h | 2 +- src/coreclr/jit/lclmorph.cpp | 3 +- src/coreclr/jit/lower.cpp | 38 +-- src/coreclr/jit/lsraarmarch.cpp | 4 +- src/coreclr/jit/lsraxarch.cpp | 2 +- src/coreclr/jit/morph.cpp | 203 ++++++------ src/coreclr/jit/patchpoint.cpp | 13 +- src/coreclr/jit/stacklevelsetter.cpp | 4 +- src/coreclr/jit/valuenum.cpp | 8 +- 22 files changed, 530 insertions(+), 444 deletions(-) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index dd509757b53cdc..0b22ff406345fd 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -2548,8 +2548,8 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree) (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFCLASS)) || (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFANY))) { - GenTree* objectNode = call->gtArgs.GetArgByIndex(1)->GetArgNode(); - GenTree* methodTableNode = call->gtArgs.GetArgByIndex(0)->GetArgNode(); + GenTree* objectNode = call->gtArgs.GetArgByIndex(1)->GetArgNode(); + GenTree* methodTableNode = call->gtArgs.GetArgByIndex(0)->GetArgNode(); assert(objectNode->TypeGet() == TYP_REF); assert(methodTableNode->TypeGet() == TYP_I_IMPL); diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index 94381c3efeee97..bf1a4308b71ce8 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -3123,7 +3123,7 @@ void CodeGen::genCall(GenTreeCall* call) for (LateArg arg : call->gtArgs.LateArgs()) { CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetNode(); // GT_RELOAD/GT_COPY use the child node argNode = argNode->gtSkipReloadOrCopy(); diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index ab5585f4da71c9..befb8b8bf77591 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6452,7 +6452,7 @@ regNumber CodeGen::getCallIndirectionCellReg(GenTreeCall* call) } #ifdef DEBUG - regNumber foundReg = REG_NA; + regNumber foundReg = REG_NA; for (CallArg& arg : call->gtArgs.Args()) { WellKnownArg kind = arg.GetWellKnownArg(); diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 94904f16c51680..51f9fdb5253e01 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -5325,7 +5325,7 @@ void CodeGen::genCall(GenTreeCall* call) for (LateArg arg : call->gtArgs.LateArgs()) { CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetNode(); if (abiInfo.GetRegNum() == REG_STK) { @@ -7988,10 +7988,10 @@ void CodeGen::genPutArgStk(GenTreePutArgStk* putArgStk) // Get argument offset on stack. // Here we cross check that argument offset hasn't changed from lowering to codegen since // we are storing arg slot number in GT_PUTARG_STK node in lowering phase. - unsigned argOffset = putArgStk->getArgOffset(); + unsigned argOffset = putArgStk->getArgOffset(); #ifdef DEBUG - CallArg* callArg = putArgStk->gtCall->gtArgs.FindByNode(putArgStk); + CallArg* callArg = putArgStk->gtCall->gtArgs.FindByNode(putArgStk); assert(callArg != nullptr); assert(argOffset == callArg->AbiInfo.SlotNum * TARGET_POINTER_SIZE); #endif diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 733f4819601c45..fdafbbf38e91be 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -4463,8 +4463,8 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl if (lvaGetDesc(i)->TypeGet() == TYP_REF) { // confirm that the argument is a GC pointer (for debugging (GC stress)) - GenTree* op = gtNewLclvNode(i, TYP_REF); - op = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_VOID, op); + GenTree* op = gtNewLclvNode(i, TYP_REF); + op = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_VOID, op); fgEnsureFirstBBisScratch(); fgNewStmtAtEnd(fgFirstBB, op); diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 30213d6ca0561c..96b4c85fae008c 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -2331,11 +2331,10 @@ class Compiler var_types type, const DebugInfo& di = DebugInfo()); - GenTreeCall* gtNewIndCallNode(GenTree* addr, - var_types type, - const DebugInfo& di = DebugInfo()); + GenTreeCall* gtNewIndCallNode(GenTree* addr, var_types type, const DebugInfo& di = DebugInfo()); - GenTreeCall* gtNewHelperCallNode(unsigned helper, var_types type, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, GenTree* arg3 = nullptr); + GenTreeCall* gtNewHelperCallNode( + unsigned helper, var_types type, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, GenTree* arg3 = nullptr); GenTreeCall* gtNewRuntimeLookupHelperCallNode(CORINFO_RUNTIME_LOOKUP* pRuntimeLookup, GenTree* ctxTree, @@ -3850,7 +3849,7 @@ class Compiler GenTreeCall* impReadyToRunHelperToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken, CorInfoHelpFunc helper, var_types type, - GenTree* arg1 = nullptr, + GenTree* arg1 = nullptr, CORINFO_LOOKUP_KIND* pGenericLookupKind = nullptr); bool impIsCastHelperEligibleForClassProbe(GenTree* tree); @@ -4150,10 +4149,10 @@ class Compiler bool impInlineIsThis(GenTree* tree, InlArgInfo* inlArgInfo); - bool impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* additionalTree, - CallArgs* additionalCallArgs, - GenTree* dereferencedAddress, - InlArgInfo* inlArgInfo); + bool impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* additionalTree, + CallArgs* additionalCallArgs, + GenTree* dereferencedAddress, + InlArgInfo* inlArgInfo); void impMarkInlineCandidate(GenTree* call, CORINFO_CONTEXT_HANDLE exactContextHnd, @@ -5573,7 +5572,8 @@ class Compiler GenTree* fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* oper); - GenTree* fgMorphIntoHelperCall(GenTree* tree, int helper, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, bool morphArgs = true); + GenTree* fgMorphIntoHelperCall( + GenTree* tree, int helper, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, bool morphArgs = true); GenTree* fgMorphStackArgForVarArgs(unsigned lclNum, var_types varType, unsigned lclOffs); @@ -5663,8 +5663,8 @@ class Compiler GenTree* fgGetStubAddrArg(GenTreeCall* call); unsigned fgGetArgParameterLclNum(GenTreeCall* call, CallArg* arg); void fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCall* recursiveTailCall); - Statement* fgAssignRecursiveCallArgToCallerParam(GenTree* arg, - CallArg* callArg, + Statement* fgAssignRecursiveCallArgToCallerParam(GenTree* arg, + CallArg* callArg, unsigned lclParamNum, BasicBlock* block, const DebugInfo& callDI, diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index d4177f06e3076c..d54e71b1f39682 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -1002,7 +1002,8 @@ inline GenTree* Compiler::gtNewIconEmbFldHndNode(CORINFO_FIELD_HANDLE fldHnd) // Return Value: // New CT_HELPER node -inline GenTreeCall* Compiler::gtNewHelperCallNode(unsigned helper, var_types type, GenTree* arg1, GenTree* arg2, GenTree* arg3) +inline GenTreeCall* Compiler::gtNewHelperCallNode( + unsigned helper, var_types type, GenTree* arg1, GenTree* arg2, GenTree* arg3) { GenTreeFlags flags = s_helperCallProperties.NoThrow((CorInfoHelpFunc)helper) ? GTF_EMPTY : GTF_EXCEPT; GenTreeCall* result = gtNewCallNode(CT_HELPER, eeFindHelper(helper), type); @@ -1049,7 +1050,7 @@ inline GenTreeCall* Compiler::gtNewRuntimeLookupHelperCallNode(CORINFO_RUNTIME_L GenTree* ctxTree, void* compileTimeHandle) { - GenTree* argNode = gtNewIconEmbHndNode(pRuntimeLookup->signature, nullptr, GTF_ICON_GLOBAL_PTR, compileTimeHandle); + GenTree* argNode = gtNewIconEmbHndNode(pRuntimeLookup->signature, nullptr, GTF_ICON_GLOBAL_PTR, compileTimeHandle); GenTreeCall* call = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL); call->gtArgs.PushFront(this, ctxTree, argNode); diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index 8ccc3adfaf827b..61118821f839ee 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -715,7 +715,7 @@ void BlockCountInstrumentor::InstrumentMethodEntry(Schema& schema, uint8_t* prof // the first time this method is called. So make the call conditional // on the entry block's profile count. // - GenTreeCall* call = m_comp->gtNewHelperCallNode(CORINFO_HELP_BBT_FCN_ENTER, TYP_VOID, arg); + GenTreeCall* call = m_comp->gtNewHelperCallNode(CORINFO_HELP_BBT_FCN_ENTER, TYP_VOID, arg); var_types typ = entry.InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::BasicBlockIntCount ? TYP_INT : TYP_LONG; @@ -1580,10 +1580,11 @@ class ClassProbeInserter // Generate the IR... // - GenTree* const classProfileNode = compiler->gtNewIconNode((ssize_t)classProfile, TYP_I_IMPL); - GenTree* const tmpNode = compiler->gtNewLclvNode(tmpNum, TYP_REF); - GenTreeCall* const helperCallNode = - compiler->gtNewHelperCallNode(is32 ? CORINFO_HELP_CLASSPROFILE32 : CORINFO_HELP_CLASSPROFILE64, TYP_VOID, tmpNode, classProfileNode); + GenTree* const classProfileNode = compiler->gtNewIconNode((ssize_t)classProfile, TYP_I_IMPL); + GenTree* const tmpNode = compiler->gtNewLclvNode(tmpNum, TYP_REF); + GenTreeCall* const helperCallNode = + compiler->gtNewHelperCallNode(is32 ? CORINFO_HELP_CLASSPROFILE32 : CORINFO_HELP_CLASSPROFILE64, TYP_VOID, + tmpNode, classProfileNode); GenTree* const tmpNode2 = compiler->gtNewLclvNode(tmpNum, TYP_REF); GenTree* const callCommaNode = compiler->gtNewOperNode(GT_COMMA, TYP_REF, helperCallNode, tmpNode2); GenTree* const tmpNode3 = compiler->gtNewLclvNode(tmpNum, TYP_REF); diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index eb201e1b8d6a06..9177708e1515ed 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -870,8 +870,8 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo opModuleIDArg = gtNewIconNode((size_t)moduleID, TYP_I_IMPL); } - GenTreeCall* result = gtNewHelperCallNode(helper, type); - CallArg* opModuleIDCallArg = result->gtArgs.PushFront(this, opModuleIDArg); + GenTreeCall* result = gtNewHelperCallNode(helper, type); + CallArg* opModuleIDCallArg = result->gtArgs.PushFront(this, opModuleIDArg); if (bNeedClassID) { if (pclsID) @@ -1136,8 +1136,8 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID); - GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); CORINFO_LOOKUP pLookup; CORINFO_CONST_LOOKUP entryPoint; info.compCompHnd->getReadyToRunDelegateCtorHelper(ldftnToken, clsHnd, &pLookup); @@ -1154,7 +1154,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, &genericLookup); GenTree* ctxTree = getRuntimeContextTree(pLookup.lookupKind.runtimeLookupKind); call->gtArgs.PushFront(this, thisPointer, targetObjPointers, ctxTree); - entryPoint = genericLookup; + entryPoint = genericLookup; } call->setEntryPoint(entryPoint); } @@ -1168,9 +1168,9 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); - call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID); + GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID); call->gtArgs.PushFront(this, thisPointer, targetObjPointers); CORINFO_LOOKUP entryPoint; @@ -1208,13 +1208,13 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, if (ctorData.pArg3 != nullptr) { GenTree* arg3 = gtNewIconHandleNode(size_t(ctorData.pArg3), GTF_ICON_FTN_ADDR); - lastArg = call->gtArgs.PushBack(this, arg3); + lastArg = call->gtArgs.PushBack(this, arg3); } if (ctorData.pArg4 != nullptr) { GenTree* arg4 = gtNewIconHandleNode(size_t(ctorData.pArg4), GTF_ICON_FTN_ADDR); - lastArg = call->gtArgs.InsertAfter(this, lastArg, arg4); + lastArg = call->gtArgs.InsertAfter(this, lastArg, arg4); } if (ctorData.pArg5 != nullptr) @@ -1856,14 +1856,13 @@ GenTree* Compiler::fgCreateMonitorTree(unsigned lvaMonAcquired, unsigned lvaThis if (info.compIsStatic) { tree = fgGetCritSectOfStaticMethod(); - tree = gtNewHelperCallNode(enter ? CORINFO_HELP_MON_ENTER_STATIC : CORINFO_HELP_MON_EXIT_STATIC, TYP_VOID, - tree, varAddrNode); + tree = gtNewHelperCallNode(enter ? CORINFO_HELP_MON_ENTER_STATIC : CORINFO_HELP_MON_EXIT_STATIC, TYP_VOID, tree, + varAddrNode); } else { tree = gtNewLclvNode(lvaThisVar, TYP_REF); - tree = gtNewHelperCallNode(enter ? CORINFO_HELP_MON_ENTER : CORINFO_HELP_MON_EXIT, TYP_VOID, - tree, varAddrNode); + tree = gtNewHelperCallNode(enter ? CORINFO_HELP_MON_ENTER : CORINFO_HELP_MON_EXIT, TYP_VOID, tree, varAddrNode); } #ifdef DEBUG @@ -2005,19 +2004,12 @@ void Compiler::fgAddReversePInvokeEnterExit() stubArgument = gtNewIconNode(0, TYP_I_IMPL); } - tree = gtNewHelperCallNode( - CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER_TRACK_TRANSITIONS, - TYP_VOID, - pInvokeFrameVar, - gtNewIconEmbMethHndNode(info.compMethodHnd), - stubArgument); + tree = gtNewHelperCallNode(CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER_TRACK_TRANSITIONS, TYP_VOID, pInvokeFrameVar, + gtNewIconEmbMethHndNode(info.compMethodHnd), stubArgument); } else { - tree = gtNewHelperCallNode( - CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER, - TYP_VOID, - pInvokeFrameVar); + tree = gtNewHelperCallNode(CORINFO_HELP_JIT_REVERSE_PINVOKE_ENTER, TYP_VOID, pInvokeFrameVar); } fgEnsureFirstBBisScratch(); diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index b969085f53588d..4093cc71f1a757 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1190,14 +1190,14 @@ bool CallArg::IsArgAddedLate() const { switch (m_wellKnownArg) { - case WellKnownArg::WrapperDelegateCell: - case WellKnownArg::VirtualStubCell: - case WellKnownArg::PInvokeCookie: - case WellKnownArg::PInvokeTarget: - case WellKnownArg::R2RIndirectionCell: - return true; - default: - return false; + case WellKnownArg::WrapperDelegateCell: + case WellKnownArg::VirtualStubCell: + case WellKnownArg::PInvokeCookie: + case WellKnownArg::PInvokeTarget: + case WellKnownArg::R2RIndirectionCell: + return true; + default: + return false; } } @@ -1332,14 +1332,14 @@ void CallArgs::Reverse(unsigned index, unsigned count) if (count > 1) { CallArg* newEnd = *headSlot; - CallArg* cur = (*headSlot)->GetNext(); + CallArg* cur = (*headSlot)->GetNext(); for (unsigned i = 1; i < count; i++) { CallArg* next = cur->GetNext(); cur->SetNext(*headSlot); *headSlot = cur; - cur = next; + cur = next; } newEnd->SetNext(cur); } @@ -1349,12 +1349,12 @@ void CallArgs::AddedWellKnownArg(WellKnownArg arg) { switch (arg) { - case WellKnownArg::ThisPointer: - m_hasThisPointer = true; - break; - case WellKnownArg::RetBuffer: - m_hasRetBuffer = true; - break; + case WellKnownArg::ThisPointer: + m_hasThisPointer = true; + break; + case WellKnownArg::RetBuffer: + m_hasRetBuffer = true; + break; } } @@ -1362,14 +1362,14 @@ void CallArgs::RemovedWellKnownArg(WellKnownArg arg) { switch (arg) { - case WellKnownArg::ThisPointer: - assert(FindWellKnownArg(arg) == nullptr); - m_hasThisPointer = false; - break; - case WellKnownArg::RetBuffer: - assert(FindWellKnownArg(arg) == nullptr); - m_hasRetBuffer = false; - break; + case WellKnownArg::ThisPointer: + assert(FindWellKnownArg(arg) == nullptr); + m_hasThisPointer = false; + break; + case WellKnownArg::RetBuffer: + assert(FindWellKnownArg(arg) == nullptr); + m_hasRetBuffer = false; + break; } } @@ -1378,73 +1378,73 @@ regNumber CallArgs::GetCustomRegister(Compiler* comp, CorInfoCallConvExtension c switch (arg) { #if defined(TARGET_X86) || defined(TARGET_ARM) - // The x86 and arm32 CORINFO_HELP_INIT_PINVOKE_FRAME helpers have a custom calling convention. - case WellKnownArg::PInvokeFrame: - return REG_PINVOKE_FRAME; + // The x86 and arm32 CORINFO_HELP_INIT_PINVOKE_FRAME helpers have a custom calling convention. + case WellKnownArg::PInvokeFrame: + return REG_PINVOKE_FRAME; #endif #if defined(TARGET_ARM) - // A non-standard calling convention using wrapper delegate invoke is used - // on ARM, only, for wrapper delegates. It is used for VSD delegate calls - // where the VSD custom calling convention ABI requires passing R4, a - // callee-saved register, with a special value. Since R4 is a callee-saved - // register, its value needs to be preserved. Thus, the VM uses a wrapper - // delegate IL stub, which preserves R4 and also sets up R4 correctly for - // the VSD call. The VM is simply reusing an existing mechanism (wrapper - // delegate IL stub) to achieve its goal for delegate VSD call. See - // COMDelegate::NeedsWrapperDelegate() in the VM for details. - case WellKnownArg::WrapperDelegateCell: - return comp->virtualStubParamInfo->GetReg(); + // A non-standard calling convention using wrapper delegate invoke is used + // on ARM, only, for wrapper delegates. It is used for VSD delegate calls + // where the VSD custom calling convention ABI requires passing R4, a + // callee-saved register, with a special value. Since R4 is a callee-saved + // register, its value needs to be preserved. Thus, the VM uses a wrapper + // delegate IL stub, which preserves R4 and also sets up R4 correctly for + // the VSD call. The VM is simply reusing an existing mechanism (wrapper + // delegate IL stub) to achieve its goal for delegate VSD call. See + // COMDelegate::NeedsWrapperDelegate() in the VM for details. + case WellKnownArg::WrapperDelegateCell: + return comp->virtualStubParamInfo->GetReg(); #endif #if defined(TARGET_X86) - // The x86 shift helpers have custom calling conventions and expect the lo - // part of the long to be in EAX and the hi part to be in EDX. This sets - // the argument registers up correctly. - case WellKnownArg::ShiftLow: - return REG_LNGARG_LO; - case WellKnownArg::ShiftHigh: - return REG_LNGARG_HI; + // The x86 shift helpers have custom calling conventions and expect the lo + // part of the long to be in EAX and the hi part to be in EDX. This sets + // the argument registers up correctly. + case WellKnownArg::ShiftLow: + return REG_LNGARG_LO; + case WellKnownArg::ShiftHigh: + return REG_LNGARG_HI; #endif - case WellKnownArg::RetBuffer: - if (hasFixedRetBuffReg()) - { - // Windows does not use fixed ret buff arg for instance calls, but does otherwise. - if (!TargetOS::IsWindows || !callConvIsInstanceMethodCallConv(cc)) + case WellKnownArg::RetBuffer: + if (hasFixedRetBuffReg()) { - return theFixedRetBuffReg(); + // Windows does not use fixed ret buff arg for instance calls, but does otherwise. + if (!TargetOS::IsWindows || !callConvIsInstanceMethodCallConv(cc)) + { + return theFixedRetBuffReg(); + } } - } - break; + break; - case WellKnownArg::VirtualStubCell: - return comp->virtualStubParamInfo->GetReg(); + case WellKnownArg::VirtualStubCell: + return comp->virtualStubParamInfo->GetReg(); - case WellKnownArg::PInvokeCookie: - return REG_PINVOKE_COOKIE_PARAM; + case WellKnownArg::PInvokeCookie: + return REG_PINVOKE_COOKIE_PARAM; - case WellKnownArg::PInvokeTarget: - return REG_PINVOKE_TARGET_PARAM; + case WellKnownArg::PInvokeTarget: + return REG_PINVOKE_TARGET_PARAM; - case WellKnownArg::R2RIndirectionCell: - return REG_R2R_INDIRECT_PARAM; + case WellKnownArg::R2RIndirectionCell: + return REG_R2R_INDIRECT_PARAM; - case WellKnownArg::ValidateIndirectCallTarget: - if (REG_VALIDATE_INDIRECT_CALL_ADDR != REG_ARG_0) - { - return REG_VALIDATE_INDIRECT_CALL_ADDR; - } + case WellKnownArg::ValidateIndirectCallTarget: + if (REG_VALIDATE_INDIRECT_CALL_ADDR != REG_ARG_0) + { + return REG_VALIDATE_INDIRECT_CALL_ADDR; + } - break; + break; #ifdef REG_DISPATCH_INDIRECT_CELL_ADDR - case WellKnownArg::DispatchIndirectCallTarget: - return REG_DISPATCH_INDIRECT_CALL_ADDR; + case WellKnownArg::DispatchIndirectCallTarget: + return REG_DISPATCH_INDIRECT_CALL_ADDR; #endif } return REG_NA; } - + bool CallArgs::IsNonStandard(Compiler* comp, GenTreeCall* call, CallArg* arg) { return GetCustomRegister(comp, call->GetUnmanagedCallConv(), arg->GetWellKnownArg()) != REG_NA; @@ -1551,21 +1551,21 @@ bool CallArgs::Remove(CallArg* arg) void CallArgs::Clear() { - m_head = nullptr; - m_lateHead = nullptr; - m_nextStackByteOffset = 0; - m_hasThisPointer = false; - m_hasRetBuffer = false; - m_isVarArgs = false; + m_head = nullptr; + m_lateHead = nullptr; + m_nextStackByteOffset = 0; + m_hasThisPointer = false; + m_hasRetBuffer = false; + m_isVarArgs = false; m_abiInformationDetermined = false; - m_hasRegArgs = false; - m_hasStackArgs = false; - m_argsComplete = false; - m_argsSorted = false; - m_needsTemps = false; + m_hasRegArgs = false; + m_hasStackArgs = false; + m_argsComplete = false; + m_argsSorted = false; + m_needsTemps = false; #ifdef UNIX_X86_ABI - m_stkSizeBytes = 0; - m_padStkAlign = 0; + m_stkSizeBytes = 0; + m_padStkAlign = 0; m_alignmentDone = false; #endif } @@ -1890,9 +1890,9 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) } { - auto i1 = c1->gtArgs.Args().begin(); + auto i1 = c1->gtArgs.Args().begin(); auto end1 = c1->gtArgs.Args().end(); - auto i2 = c2->gtArgs.Args().begin(); + auto i2 = c2->gtArgs.Args().begin(); auto end2 = c2->gtArgs.Args().end(); for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) @@ -1910,9 +1910,9 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) } { - auto i1 = c1->gtArgs.LateArgs().begin(); + auto i1 = c1->gtArgs.LateArgs().begin(); auto end1 = c1->gtArgs.LateArgs().end(); - auto i2 = c2->gtArgs.LateArgs().begin(); + auto i2 = c2->gtArgs.LateArgs().begin(); auto end2 = c2->gtArgs.LateArgs().end(); for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) @@ -2523,7 +2523,7 @@ unsigned Compiler::gtHashValue(GenTree* tree) #ifdef HOST_64BIT add = bits; #else // 32-bit host - add = genTreeHashAdd(uhi32(bits), ulo32(bits)); + add = genTreeHashAdd(uhi32(bits), ulo32(bits)); #endif break; case GT_CNS_DBL: @@ -2531,7 +2531,7 @@ unsigned Compiler::gtHashValue(GenTree* tree) #ifdef HOST_64BIT add = bits; #else // 32-bit host - add = genTreeHashAdd(uhi32(bits), ulo32(bits)); + add = genTreeHashAdd(uhi32(bits), ulo32(bits)); #endif break; case GT_CNS_STR: @@ -3069,8 +3069,7 @@ unsigned Compiler::gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCo unsigned costEx = 0; unsigned costSz = 0; - auto update = [&level, &costEx, &costSz, lateArgs](GenTree* argNode, unsigned argLevel) - { + auto update = [&level, &costEx, &costSz, lateArgs](GenTree* argNode, unsigned argLevel) { if (argLevel > level) { level = argLevel; @@ -3097,7 +3096,7 @@ unsigned Compiler::gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCo { for (LateArg arg : args->LateArgs()) { - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetNode(); unsigned argLevel = gtSetEvalOrder(argNode); update(argNode, argLevel); } @@ -3106,7 +3105,7 @@ unsigned Compiler::gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCo { for (CallArg& arg : args->Args()) { - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetNode(); unsigned argLevel = gtSetEvalOrder(argNode); if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) @@ -5180,7 +5179,7 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree) // Evaluate the arguments - lvl2 = gtSetCallArgsOrder(&call->gtArgs, /* lateArgs */ false, &costEx, &costSz); + lvl2 = gtSetCallArgsOrder(&call->gtArgs, /* lateArgs */ false, &costEx, &costSz); if (level < lvl2) { level = lvl2; @@ -5188,7 +5187,7 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree) // Evaluate the temp register arguments list - lvl2 = gtSetCallArgsOrder(&call->gtArgs, /* lateArgs */ true, &costEx, &costSz); + lvl2 = gtSetCallArgsOrder(&call->gtArgs, /* lateArgs */ true, &costEx, &costSz); if (level < lvl2) { level = lvl2; @@ -6713,8 +6712,10 @@ GenTreeCall* Compiler::gtNewIndCallNode(GenTree* addr, var_types type, const Deb return gtNewCallNode(CT_INDIRECT, (CORINFO_METHOD_HANDLE)addr, type, di); } -GenTreeCall* Compiler::gtNewCallNode( - gtCallTypes callType, CORINFO_METHOD_HANDLE callHnd, var_types type, const DebugInfo& di) +GenTreeCall* Compiler::gtNewCallNode(gtCallTypes callType, + CORINFO_METHOD_HANDLE callHnd, + var_types type, + const DebugInfo& di) { GenTreeCall* node = new (this, GT_CALL) GenTreeCall(genActualType(type)); @@ -6739,7 +6740,7 @@ GenTreeCall* Compiler::gtNewCallNode( { node->gtInlineCandidateInfo = nullptr; } - node->gtReturnType = type; + node->gtReturnType = type; #ifdef FEATURE_READYTORUN node->gtEntryPoint.addr = nullptr; @@ -8322,21 +8323,21 @@ GenTree* Compiler::gtCloneExpr( // Copy all information from the specified CallArgs, making these argument lists equivalent. // Nodes are cloned using the specified function. -template +template void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc copyNode) { assert((m_head == nullptr) && (m_lateHead == nullptr)); - m_nextStackByteOffset = other->m_nextStackByteOffset; - m_hasThisPointer = other->m_hasThisPointer; - m_hasRetBuffer = other->m_hasRetBuffer; - m_isVarArgs = other->m_isVarArgs; + m_nextStackByteOffset = other->m_nextStackByteOffset; + m_hasThisPointer = other->m_hasThisPointer; + m_hasRetBuffer = other->m_hasRetBuffer; + m_isVarArgs = other->m_isVarArgs; m_abiInformationDetermined = other->m_abiInformationDetermined; - m_hasRegArgs = other->m_hasRegArgs; - m_hasStackArgs = other->m_hasStackArgs; - m_argsComplete = other->m_argsComplete; - m_argsSorted = other->m_argsSorted; - m_needsTemps = other->m_needsTemps; + m_hasRegArgs = other->m_hasRegArgs; + m_hasStackArgs = other->m_hasStackArgs; + m_argsComplete = other->m_argsComplete; + m_argsSorted = other->m_argsSorted; + m_needsTemps = other->m_needsTemps; // Unix x86 flags related to stack alignment intentionally not copied as it // depends on where the call will be inserted. @@ -8344,34 +8345,34 @@ void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc co CallArg** tail = &m_head; for (CallArg& arg : other->Args()) { - CallArg* carg = new (comp, CMK_fgArgInfo) CallArg(arg.GetWellKnownArg()); - carg->m_node = arg.m_node != nullptr ? copyNode(arg.m_node) : nullptr; - carg->m_lateNode = arg.m_lateNode != nullptr ? copyNode(arg.m_lateNode) : nullptr; - carg->m_needTmp = arg.m_needTmp; + CallArg* carg = new (comp, CMK_fgArgInfo) CallArg(arg.GetWellKnownArg()); + carg->m_node = arg.m_node != nullptr ? copyNode(arg.m_node) : nullptr; + carg->m_lateNode = arg.m_lateNode != nullptr ? copyNode(arg.m_lateNode) : nullptr; + carg->m_needTmp = arg.m_needTmp; carg->m_needPlace = arg.m_needPlace; - carg->m_isTmp = arg.m_isTmp; + carg->m_isTmp = arg.m_isTmp; carg->m_processed = arg.m_processed; - carg->m_tmpNum = arg.m_tmpNum; - carg->AbiInfo = arg.AbiInfo; - *tail = carg; - tail = &carg->m_next; + carg->m_tmpNum = arg.m_tmpNum; + carg->AbiInfo = arg.AbiInfo; + *tail = carg; + tail = &carg->m_next; } // Now copy late pointers. Note that these may not come in order. tail = &m_lateHead; for (LateArg arg : other->LateArgs()) { - CallArg* it = m_head; + CallArg* it = m_head; CallArg* otherIt = other->m_head; while (otherIt != arg.GetArg()) { assert(it != nullptr && otherIt != nullptr); - it = it->m_next; + it = it->m_next; otherIt = otherIt->m_next; } *tail = it; - tail = &it->m_lateNext; + tail = &it->m_lateNext; } } @@ -8400,13 +8401,8 @@ GenTreeCall* Compiler::gtCloneExprCallHelper(GenTreeCall* tree, copy->gtCallMoreFlags = tree->gtCallMoreFlags; - copy->gtArgs.InternalCopyFrom( - this, - &tree->gtArgs, - [=](GenTree* node) - { - return gtCloneExpr(node, addFlags, deepVarNum, deepVarVal); - }); + copy->gtArgs.InternalCopyFrom(this, &tree->gtArgs, + [=](GenTree* node) { return gtCloneExpr(node, addFlags, deepVarNum, deepVarVal); }); // The call sig comes from the EE and doesn't change throughout the compilation process, meaning // we only really need one physical copy of it. Therefore a shallow pointer copy will suffice. @@ -8947,7 +8943,7 @@ GenTreeUseEdgeIterator::GenTreeUseEdgeIterator(GenTree* node) case GT_CALL: m_statePtr = &*m_node->AsCall()->gtArgs.Args().begin(); - m_advance = &GenTreeUseEdgeIterator::AdvanceCall; + m_advance = &GenTreeUseEdgeIterator::AdvanceCall; AdvanceCall(); return; @@ -9223,8 +9219,8 @@ void GenTreeUseEdgeIterator::AdvanceCall() if (m_statePtr != nullptr) { CallArg* arg = static_cast(m_statePtr); - m_edge = &arg->NodeRef(); - m_statePtr = arg->GetNext(); + m_edge = &arg->NodeRef(); + m_statePtr = arg->GetNext(); return; } m_statePtr = call->gtArgs.LateArgs().begin().GetArg(); @@ -9235,8 +9231,8 @@ void GenTreeUseEdgeIterator::AdvanceCall() if (m_statePtr != nullptr) { CallArg* arg = static_cast(m_statePtr); - m_edge = &arg->LateNodeRef(); - m_statePtr = arg->GetLateNext(); + m_edge = &arg->LateNodeRef(); + m_statePtr = arg->GetLateNext(); return; } m_advance = &GenTreeUseEdgeIterator::AdvanceCall; @@ -11535,7 +11531,7 @@ void Compiler::gtDispTree(GenTree* tree, if (!topOnly) { - char buf[64]; + char buf[64]; gtDispArgList(call, lastChild, indentStack); @@ -11671,28 +11667,43 @@ const char* Compiler::gtGetWellKnownArgNameForArgMsg(WellKnownArg arg) { switch (arg) { - case WellKnownArg::ThisPointer: return "this"; - case WellKnownArg::VarArgsCookie: return "va cookie"; - case WellKnownArg::InstParam: return "gctx"; - case WellKnownArg::RetBuffer: return "retbuf"; - case WellKnownArg::PInvokeFrame: return "pinv frame"; - case WellKnownArg::SecretStubParam: return "stub param"; - case WellKnownArg::WrapperDelegateCell: return "wrap cell"; - case WellKnownArg::ShiftLow: return "shift low"; - case WellKnownArg::ShiftHigh: return "shift high"; - case WellKnownArg::VirtualStubCell: return "vsd cell"; - case WellKnownArg::PInvokeCookie: return "pinv cookie"; - case WellKnownArg::PInvokeTarget: return "pinv tgt"; - case WellKnownArg::R2RIndirectionCell: return "r2r cell"; - case WellKnownArg::ValidateIndirectCallTarget: - case WellKnownArg::DispatchIndirectCallTarget: return "cfg tgt"; - default: return nullptr; + case WellKnownArg::ThisPointer: + return "this"; + case WellKnownArg::VarArgsCookie: + return "va cookie"; + case WellKnownArg::InstParam: + return "gctx"; + case WellKnownArg::RetBuffer: + return "retbuf"; + case WellKnownArg::PInvokeFrame: + return "pinv frame"; + case WellKnownArg::SecretStubParam: + return "stub param"; + case WellKnownArg::WrapperDelegateCell: + return "wrap cell"; + case WellKnownArg::ShiftLow: + return "shift low"; + case WellKnownArg::ShiftHigh: + return "shift high"; + case WellKnownArg::VirtualStubCell: + return "vsd cell"; + case WellKnownArg::PInvokeCookie: + return "pinv cookie"; + case WellKnownArg::PInvokeTarget: + return "pinv tgt"; + case WellKnownArg::R2RIndirectionCell: + return "r2r cell"; + case WellKnownArg::ValidateIndirectCallTarget: + case WellKnownArg::DispatchIndirectCallTarget: + return "cfg tgt"; + default: + return nullptr; } } void Compiler::gtPrintArgPrefix(GenTreeCall* call, CallArg* arg, char** bufp, unsigned* bufLength) { - int prefLen; + int prefLen; const char* wellKnownName = gtGetWellKnownArgNameForArgMsg(arg->GetWellKnownArg()); if (wellKnownName != nullptr) { @@ -11701,7 +11712,7 @@ void Compiler::gtPrintArgPrefix(GenTreeCall* call, CallArg* arg, char** bufp, un else { unsigned argNum = call->gtArgs.GetIndex(arg); - prefLen = sprintf_s(*bufp, *bufLength, "arg%u", argNum); + prefLen = sprintf_s(*bufp, *bufLength, "arg%u", argNum); } assert(prefLen != -1); *bufp += prefLen; @@ -11861,7 +11872,8 @@ void Compiler::gtDispArgList(GenTreeCall* call, GenTree* lastCallOperand, Indent { char buf[256]; gtGetArgMsg(call, &arg, buf, sizeof(buf)); - gtDispChild(arg.GetNode(), indentStack, (arg.GetNode() == lastCallOperand) ? IIArcBottom : IIArc, buf, false); + gtDispChild(arg.GetNode(), indentStack, (arg.GetNode() == lastCallOperand) ? IIArcBottom : IIArc, buf, + false); } } } @@ -12023,7 +12035,7 @@ void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr * if (nodeIsCall) { GenTreeCall* call = node->AsCall(); - //if ((call->gtCallThisArg != nullptr) && (operand == call->gtCallThisArg->GetNode())) + // if ((call->gtCallThisArg != nullptr) && (operand == call->gtCallThisArg->GetNode())) //{ // sprintf_s(buf, sizeof(buf), "this in %s", compRegVarName(REG_ARG_0)); // displayOperand(operand, buf, operandArc, indentStack, prefixIndent); @@ -12419,7 +12431,7 @@ GenTree* Compiler::gtCreateHandleCompare(genTreeOps oper, assert(typeCheckInliningResult == CORINFO_INLINE_TYPECHECK_USE_HELPER); // Emit a call to a runtime helper - GenTree* ret = gtNewHelperCallNode(CORINFO_HELP_ARE_TYPES_EQUIVALENT, TYP_INT, op1, op2); + GenTree* ret = gtNewHelperCallNode(CORINFO_HELP_ARE_TYPES_EQUIVALENT, TYP_INT, op1, op2); if (oper == GT_EQ) { ret = gtNewOperNode(GT_NE, TYP_INT, ret, gtNewIconNode(0, TYP_INT)); @@ -12482,11 +12494,12 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) if ((op1Kind == TPK_Handle) && (op2Kind == TPK_Handle)) { JITDUMP("Optimizing compare of types-from-handles to instead compare handles\n"); - assert((tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.CountArgs() == 1) &&(tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.CountArgs() == 1)); - GenTree* op1ClassFromHandle = tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* op2ClassFromHandle = tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); - CORINFO_CLASS_HANDLE cls1Hnd = NO_CLASS_HANDLE; - CORINFO_CLASS_HANDLE cls2Hnd = NO_CLASS_HANDLE; + assert((tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.CountArgs() == 1) && + (tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.CountArgs() == 1)); + GenTree* op1ClassFromHandle = tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* op2ClassFromHandle = tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); + CORINFO_CLASS_HANDLE cls1Hnd = NO_CLASS_HANDLE; + CORINFO_CLASS_HANDLE cls2Hnd = NO_CLASS_HANDLE; // Try and find class handles from op1 and op2 cls1Hnd = gtGetHelperArgClassHandle(op1ClassFromHandle); @@ -13251,7 +13264,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions } else if (asgSrcOper == GT_CALL) { - GenTreeCall* newobjCall = asgSrc->AsCall(); + GenTreeCall* newobjCall = asgSrc->AsCall(); // In R2R expansions the handle may not be an explicit operand to the helper, // so we can't remove the box. @@ -14985,9 +14998,9 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr, // Arguments in reverse order GenTree* args[4]; - size_t nArgs = 0; + size_t nArgs = 0; /* If we can't access it directly, we need to call a helper function */ - var_types helperType = TYP_BYREF; + var_types helperType = TYP_BYREF; if (pFieldInfo->fieldAccessor == CORINFO_FIELD_INSTANCE_HELPER) { @@ -15010,7 +15023,7 @@ GenTree* Compiler::gtNewRefCOMfield(GenTree* objPtr, } args[nArgs++] = assg; - helperType = TYP_VOID; + helperType = TYP_VOID; } else if (access & CORINFO_ACCESS_GET) { diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 4a4a13d40d41fa..2d219244cef9f9 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4062,11 +4062,13 @@ struct CallArgABIInformation // The original argument number, also specifies the required argument // evaluation order from the IL - unsigned ArgNum; + unsigned ArgNum; + private: // The registers to use when passing this argument, set to REG_STK for // arguments passed on the stack regNumberSmall RegNums[MAX_ARG_REG_COUNT]; + public: // Count of number of registers that this argument uses. Note that on ARM, // if we have a double hfa, this reflects the number of DOUBLE registers. @@ -4078,8 +4080,8 @@ struct CallArgABIInformation // Unix amd64 will split floating point types and integer types in structs // between floating point and general purpose registers. Keep track of that // information so we do not need to recompute it later. - unsigned StructIntRegs; - unsigned StructFloatRegs; + unsigned StructIntRegs; + unsigned StructFloatRegs; SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR StructDesc; #endif // UNIX_AMD64_ABI #if defined(DEBUG_ARG_SLOTS) @@ -4135,8 +4137,8 @@ struct CallArgABIInformation #endif } - bool IsHfaArg() const; - bool IsHfaRegArg() const; + bool IsHfaArg() const; + bool IsHfaRegArg() const; var_types GetHfaType() const; void SetHfaType(var_types type, unsigned hfaSlots); @@ -4230,10 +4232,10 @@ class CallArg { friend class CallArgs; - GenTree* m_node; - GenTree* m_lateNode; - CallArg* m_next; - CallArg* m_lateNext; + GenTree* m_node; + GenTree* m_lateNode; + CallArg* m_next; + CallArg* m_lateNext; WellKnownArg m_wellKnownArg : 5; // True when we force this argument's evaluation into a temp LclVar. @@ -4247,6 +4249,7 @@ class CallArg bool m_processed : 1; // The LclVar number if we had to force evaluation of this arg unsigned m_tmpNum; + public: CallArgABIInformation AbiInfo; @@ -4268,21 +4271,63 @@ class CallArg CallArg& operator=(CallArg&) = delete; // clang format off - GenTree*& NodeRef() { return m_node; } - GenTree* GetNode() { return m_node; } - void SetNode(GenTree* node) { m_node = node; } - GenTree*& LateNodeRef() { return m_lateNode; } - GenTree* GetLateNode() { return m_lateNode; } - void SetLateNode(GenTree* lateNode) { m_lateNode = lateNode; } - CallArg*& NextRef() { return m_next; } - CallArg* GetNext() { return m_next; } - void SetNext(CallArg* next) { m_next = next; } - CallArg*& LateNextRef() { return m_lateNext; } - CallArg* GetLateNext() { return m_lateNext; } - void SetLateNext(CallArg* lateNext) { m_lateNext = lateNext; } - WellKnownArg GetWellKnownArg() { return m_wellKnownArg; } + GenTree*& NodeRef() + { + return m_node; + } + GenTree* GetNode() + { + return m_node; + } + void SetNode(GenTree* node) + { + m_node = node; + } + GenTree*& LateNodeRef() + { + return m_lateNode; + } + GenTree* GetLateNode() + { + return m_lateNode; + } + void SetLateNode(GenTree* lateNode) + { + m_lateNode = lateNode; + } + CallArg*& NextRef() + { + return m_next; + } + CallArg* GetNext() + { + return m_next; + } + void SetNext(CallArg* next) + { + m_next = next; + } + CallArg*& LateNextRef() + { + return m_lateNext; + } + CallArg* GetLateNext() + { + return m_lateNext; + } + void SetLateNext(CallArg* lateNext) + { + m_lateNext = lateNext; + } + WellKnownArg GetWellKnownArg() + { + return m_wellKnownArg; + } // TODO-ARGS: Remove - bool IsTemp() { return m_isTmp; } + bool IsTemp() + { + return m_isTmp; + } // clang format on // Get the real argument node, i.e. not a setup or placeholder node. @@ -4314,14 +4359,25 @@ class LateArg CallArg* m_arg; public: - explicit LateArg(CallArg* arg) - : m_arg(arg) + explicit LateArg(CallArg* arg) : m_arg(arg) + { + } + CallArg* GetArg() + { + return m_arg; + } + GenTree* GetNode() { + return m_arg->GetLateNode(); + } + void SetNode(GenTree* node) + { + m_arg->SetLateNode(node); + } + GenTree*& NodeRef() + { + return m_arg->LateNodeRef(); } - CallArg* GetArg() { return m_arg; } - GenTree* GetNode() { return m_arg->GetLateNode(); } - void SetNode(GenTree* node) { m_arg->SetLateNode(node); } - GenTree*& NodeRef() { return m_arg->LateNodeRef(); } }; class CallArgs @@ -4360,6 +4416,7 @@ class CallArgs void RemovedWellKnownArg(WellKnownArg arg); regNumber GetCustomRegister(Compiler* comp, CorInfoCallConvExtension cc, WellKnownArg arg); void SplitArg(CallArg* arg, unsigned numRegs, unsigned numSlots, unsigned* nextSlotNum); + public: CallArgs(); CallArgs(const CallArgs&) = delete; @@ -4372,7 +4429,10 @@ class CallArgs CallArg* GetArgByIndex(unsigned index); unsigned GetIndex(CallArg* arg); - bool IsEmpty() const { return m_head == nullptr; } + bool IsEmpty() const + { + return m_head == nullptr; + } // Reverse the args from [index..index + count) in place. void Reverse(unsigned index, unsigned count); @@ -4386,10 +4446,10 @@ class CallArgs bool Remove(CallArg* arg); void Clear(); - template + template void InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc copyFunc); - template + template void PushFront(Compiler* comp, GenTree* node, T... rest) { PushFront(comp, rest...); @@ -4433,8 +4493,7 @@ class CallArgs CallArg* m_arg; public: - explicit CallArgIterator(CallArg* arg) - : m_arg(arg) + explicit CallArgIterator(CallArg* arg) : m_arg(arg) { } @@ -4472,10 +4531,7 @@ class CallArgs IteratorPair Args() { - return - IteratorPair( - CallArgIterator(m_head), - CallArgIterator(nullptr)); + return IteratorPair(CallArgIterator(m_head), CallArgIterator(nullptr)); } class LateArgsIterator @@ -4483,8 +4539,7 @@ class CallArgs CallArg* m_arg; public: - explicit LateArgsIterator(CallArg* arg) - : m_arg(arg) + explicit LateArgsIterator(CallArg* arg) : m_arg(arg) { } @@ -4527,10 +4582,7 @@ class CallArgs IteratorPair LateArgs() { - return - IteratorPair( - LateArgsIterator(m_lateHead), - LateArgsIterator(nullptr)); + return IteratorPair(LateArgsIterator(m_lateHead), LateArgsIterator(nullptr)); } }; @@ -5225,7 +5277,7 @@ struct GenTreeCall final : public GenTree return nullptr; } - CallArg* retBufArg = gtArgs.GetRetBufferArg(); + CallArg* retBufArg = gtArgs.GetRetBufferArg(); GenTree* lclRetBufArgNode = retBufArg->GetNode(); if (lclRetBufArgNode->IsArgPlaceHolderNode()) { diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index e9f9cda02dae68..3b9cd8f380e9bf 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -870,7 +870,7 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a } CORINFO_ARG_LIST_HANDLE sigArgs = sig->args; - unsigned index = 0; + unsigned index = 0; for (CallArg& arg : argList->Args()) { if (index >= sig->numArgs) @@ -1045,7 +1045,10 @@ bool Compiler::impCheckImplicitArgumentCoercion(var_types sigType, var_types nod * The first "skipReverseCount" items are not reversed. */ -void Compiler::impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList, unsigned skipReverseCount) +void Compiler::impPopReverseCallArgs(unsigned count, + CORINFO_SIG_INFO* sig, + CallArgs* argList, + unsigned skipReverseCount) { assert(skipReverseCount <= count); @@ -1210,7 +1213,8 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, // in the ABI sense. We take the path here for those but it should // not be marked as the ret buff arg since it always follow the // normal ABI for parameters. - WellKnownArg wellKnownArgType = srcCall->ShouldGetRetBufArg() ? WellKnownArg::RetBuffer : WellKnownArg::None; + WellKnownArg wellKnownArgType = + srcCall->ShouldGetRetBufArg() ? WellKnownArg::RetBuffer : WellKnownArg::None; #if !defined(TARGET_ARM) // Unmanaged instance methods on Windows or Unix X86 need the retbuf arg after the first (this) parameter @@ -2321,7 +2325,7 @@ GenTree* Compiler::impRuntimeLookupToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken // - Setup argNode with the pointer to the signature returned by the lookup GenTree* argNode = gtNewIconEmbHndNode(pRuntimeLookup->signature, nullptr, GTF_ICON_GLOBAL_PTR, compileTimeHandle); - GenTreeCall* helperCall = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL, ctxTree, argNode); + GenTreeCall* helperCall = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL, ctxTree, argNode); // Check for null and possibly call helper GenTree* nullCheck = gtNewOperNode(GT_NE, TYP_INT, handleForNullCheck, gtNewIconNode(0, TYP_I_IMPL)); @@ -2351,7 +2355,7 @@ GenTree* Compiler::impRuntimeLookupToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken // ((sizeCheck fails || nullCheck fails))) ? (helperCall : handle). // Add checks and the handle as call arguments, indirect call transformer will handle this. helperCall->gtArgs.PushFront(this, nullCheck, sizeCheck, handleForResult); - result = helperCall; + result = helperCall; addExpRuntimeLookupCandidate(helperCall); } else @@ -4097,7 +4101,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, // Get native TypeHandle argument to old helper assert(op1->AsCall()->gtArgs.CountArgs() == 1); - op1 = op1->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); + op1 = op1->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); retNode = op1; } // Call the regular function. @@ -4123,7 +4127,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, typeHandleHelper = CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL; } assert(op1->AsCall()->gtArgs.CountArgs() == 1); - op1 = gtNewHelperCallNode(typeHandleHelper, TYP_REF, op1->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); + op1 = gtNewHelperCallNode(typeHandleHelper, TYP_REF, + op1->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); op1->gtType = TYP_REF; retNode = op1; } @@ -4214,7 +4219,8 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE)) { assert(call->gtArgs.CountArgs() == 1); - CORINFO_CLASS_HANDLE hClass = gtGetHelperArgClassHandle(call->gtArgs.GetArgByIndex(0)->GetNode()); + CORINFO_CLASS_HANDLE hClass = + gtGetHelperArgClassHandle(call->gtArgs.GetArgByIndex(0)->GetNode()); if (hClass != NO_CLASS_HANDLE) { retNode = @@ -4493,7 +4499,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, // do for LDTOKEN since the return value of this operator is Type, // not RuntimeTypeHandle. impPopStack(); - GenTree* runtimeType = + GenTree* runtimeType = gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, TYP_REF, boxTypeHandle); retNode = runtimeType; } @@ -4522,7 +4528,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, assert(compDonotInline()); return nullptr; } - GenTree* runtimeType = + GenTree* runtimeType = gtNewHelperCallNode(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, TYP_REF, typeHandleOp); retNode = runtimeType; } @@ -4779,10 +4785,11 @@ GenTree* Compiler::impTypeIsAssignable(GenTree* typeTo, GenTree* typeFrom) CORINFO_METHOD_HANDLE hTypeof = eeFindHelper(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE); if ((typeTo->AsCall()->gtCallMethHnd == hTypeof) && (typeFrom->AsCall()->gtCallMethHnd == hTypeof)) { - assert((typeTo->AsCall()->gtArgs.CountArgs() == 1) && - (typeFrom->AsCall()->gtArgs.CountArgs() == 1)); - CORINFO_CLASS_HANDLE hClassTo = gtGetHelperArgClassHandle(typeTo->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); - CORINFO_CLASS_HANDLE hClassFrom = gtGetHelperArgClassHandle(typeFrom->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); + assert((typeTo->AsCall()->gtArgs.CountArgs() == 1) && (typeFrom->AsCall()->gtArgs.CountArgs() == 1)); + CORINFO_CLASS_HANDLE hClassTo = + gtGetHelperArgClassHandle(typeTo->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); + CORINFO_CLASS_HANDLE hClassFrom = + gtGetHelperArgClassHandle(typeFrom->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); if (hClassTo == NO_CLASS_HANDLE || hClassFrom == NO_CLASS_HANDLE) { @@ -5824,8 +5831,7 @@ void Compiler::verConvertBBToThrowVerificationException(BasicBlock* block DEBUGA } assert(verCurrentState.esStackDepth == 0); - GenTree* op1 = - gtNewHelperCallNode(CORINFO_HELP_VERIFICATION, TYP_VOID, gtNewIconNode(block->bbCodeOffs)); + GenTree* op1 = gtNewHelperCallNode(CORINFO_HELP_VERIFICATION, TYP_VOID, gtNewIconNode(block->bbCodeOffs)); // verCurrentState.esStackDepth = 0; impAppendTree(op1, (unsigned)CHECK_SPILL_NONE, impCurStmtDI); @@ -6795,8 +6801,7 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr, { GenTree* runtimeMethodHandle = impLookupToTree(pResolvedToken, &pCallInfo->codePointerLookup, GTF_ICON_METHOD_HDL, pCallInfo->hMethod); - return gtNewHelperCallNode(CORINFO_HELP_GVMLOOKUP_FOR_SLOT, TYP_I_IMPL, - thisPtr, runtimeMethodHandle); + return gtNewHelperCallNode(CORINFO_HELP_GVMLOOKUP_FOR_SLOT, TYP_I_IMPL, thisPtr, runtimeMethodHandle); } #ifdef FEATURE_READYTORUN @@ -6804,8 +6809,7 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr, { if (!pCallInfo->exactContextNeedsRuntimeLookup) { - GenTreeCall* call = - gtNewHelperCallNode(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, TYP_I_IMPL, thisPtr); + GenTreeCall* call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, TYP_I_IMPL, thisPtr); call->setEntryPoint(pCallInfo->codePointerLookup.constLookup); @@ -7381,7 +7385,8 @@ void Compiler::impImportAndPushBox(CORINFO_RESOLVED_TOKEN* pResolvedToken) return; } - op1 = gtNewHelperCallNode(boxHelper, TYP_REF, op2, impGetStructAddr(exprToBox, operCls, (unsigned)CHECK_SPILL_ALL, true)); + op1 = gtNewHelperCallNode(boxHelper, TYP_REF, op2, + impGetStructAddr(exprToBox, operCls, (unsigned)CHECK_SPILL_ALL, true)); } /* Push the result back on the stack, */ @@ -7464,7 +7469,8 @@ void Compiler::impImportNewObjArray(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORI node = gtNewOperNode(GT_COMMA, node->TypeGet(), gtNewAssignNode(dest, arg), node); } - node = gtNewHelperCallNode(CORINFO_HELP_NEW_MDARR, TYP_REF, classHandle, gtNewIconNode(pCallInfo->sig.numArgs), node); + node = + gtNewHelperCallNode(CORINFO_HELP_NEW_MDARR, TYP_REF, classHandle, gtNewIconNode(pCallInfo->sig.numArgs), node); for (CallArg& arg : node->AsCall()->gtArgs.Args()) { @@ -8202,7 +8208,7 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT info.compCompHnd->getLocationOfThisType(info.compMethodHnd, &kind); assert(kind.needsRuntimeLookup); - GenTree* ctxTree = getRuntimeContextTree(kind.runtimeLookupKind); + GenTree* ctxTree = getRuntimeContextTree(kind.runtimeLookupKind); GenTreeFlags callFlags = GTF_EMPTY; @@ -8659,9 +8665,9 @@ var_types Compiler::impImportCall(OPCODE opcode, bool checkForSmallType = opts.IsReadyToRun(); bool bIntrinsicImported = false; - CORINFO_SIG_INFO calliSig; - GenTree* extraArg = nullptr; - WellKnownArg extraArgKind = WellKnownArg::None; + CORINFO_SIG_INFO calliSig; + GenTree* extraArg = nullptr; + WellKnownArg extraArgKind = WellKnownArg::None; /*------------------------------------------------------------------------- * First create the call node @@ -8896,7 +8902,7 @@ var_types Compiler::impImportCall(OPCODE opcode, else { // The stub address is known at compile time - call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, di); + call = gtNewCallNode(CT_USER_FUNC, callInfo->hMethod, callRetTyp, di); call->AsCall()->gtStubCallStubAddr = callInfo->stubLookup.constLookup.addr; call->gtFlags |= GTF_CALL_VIRT_STUB; assert(callInfo->stubLookup.constLookup.accessType != IAT_PPVALUE && @@ -8968,7 +8974,7 @@ var_types Compiler::impImportCall(OPCODE opcode, assert(fptr != nullptr); call->AsCall()->gtArgs.PushFront(this, thisPtrCopy, WellKnownArg::ThisPointer); - thisPtr = nullptr; // can't reuse it + thisPtr = nullptr; // can't reuse it thisPtrCopy = nullptr; // Now make an indirect call through the function pointer @@ -9297,7 +9303,7 @@ var_types Compiler::impImportCall(OPCODE opcode, varCookie = info.compCompHnd->getVarArgsHandle(sig, &pVarCookie); assert((!varCookie) != (!pVarCookie)); assert(extraArg == nullptr); - extraArg = gtNewIconEmbHndNode(varCookie, pVarCookie, GTF_ICON_VARG_HDL, sig); + extraArg = gtNewIconEmbHndNode(varCookie, pVarCookie, GTF_ICON_VARG_HDL, sig); extraArgKind = WellKnownArg::VarArgsCookie; } @@ -9421,7 +9427,7 @@ var_types Compiler::impImportCall(OPCODE opcode, } assert(extraArg == nullptr); - extraArg = instParam; + extraArg = instParam; extraArgKind = WellKnownArg::InstParam; } @@ -12934,10 +12940,10 @@ void Compiler::impImportBlockCode(BasicBlock* block) } { - GenTree* type = op1; + GenTree* type = op1; GenTree* index = impPopStack().val; - GenTree* arr = impPopStack().val; - op1 = gtNewHelperCallNode(CORINFO_HELP_LDELEMA_REF, TYP_BYREF, arr, index, type); + GenTree* arr = impPopStack().val; + op1 = gtNewHelperCallNode(CORINFO_HELP_LDELEMA_REF, TYP_BYREF, arr, index, type); } impPushOnStack(op1, tiRetVal); @@ -15708,8 +15714,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) #ifdef FEATURE_READYTORUN if (opts.IsReadyToRun()) { - op1 = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_NEWARR_1, TYP_REF, - op2); + op1 = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_NEWARR_1, TYP_REF, op2); usingReadyToRunHelper = (op1 != nullptr); if (!usingReadyToRunHelper) @@ -15737,7 +15742,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) // Note that this only works for shared generic code because the same helper is used for all // reference array types - op1 = gtNewHelperCallNode(info.compCompHnd->getNewArrHelper(resolvedToken.hClass), TYP_REF, op1, op2); + op1 = + gtNewHelperCallNode(info.compCompHnd->getNewArrHelper(resolvedToken.hClass), TYP_REF, op1, op2); } op1->AsCall()->compileTimeHelperArgumentHandle = (CORINFO_GENERIC_HANDLE)resolvedToken.hClass; @@ -16205,8 +16211,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) // Don't optimize, just call the helper and be done with it op1 = gtNewHelperCallNode(helper, - (var_types)((helper == CORINFO_HELP_UNBOX) ? TYP_BYREF : TYP_STRUCT), - op2, op1); + (var_types)((helper == CORINFO_HELP_UNBOX) ? TYP_BYREF : TYP_STRUCT), op2, + op1); if (op1->gtType == TYP_STRUCT) { op1->AsCall()->gtRetClsHnd = resolvedToken.hClass; @@ -16420,8 +16426,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) if (opts.IsReadyToRun()) { GenTreeCall* opLookup = - impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_CHKCAST, TYP_REF, - op1); + impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_CHKCAST, TYP_REF, op1); usingReadyToRunHelper = (opLookup != nullptr); op1 = (usingReadyToRunHelper ? opLookup : op1); @@ -17072,7 +17077,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) assert(op2->gtType == TYP_REF); // confirm that the argument is a GC pointer (for debugging (GC stress)) - op2 = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_REF, op2); + op2 = gtNewHelperCallNode(CORINFO_HELP_CHECK_OBJ, TYP_REF, op2); if (verbose) { @@ -19542,13 +19547,13 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) { switch (arg.GetWellKnownArg()) { - case WellKnownArg::ThisPointer: - inlArgInfo[ilArgCnt].argIsThis = true; - break; - case WellKnownArg::RetBuffer: - case WellKnownArg::InstParam: - // These do not appear in the signature; do not include them - continue; + case WellKnownArg::ThisPointer: + inlArgInfo[ilArgCnt].argIsThis = true; + break; + case WellKnownArg::RetBuffer: + case WellKnownArg::InstParam: + // These do not appear in the signature; do not include them + continue; } GenTree* actualArg = gtFoldExpr(arg.GetNode()); @@ -20203,10 +20208,10 @@ bool Compiler::impInlineIsThis(GenTree* tree, InlArgInfo* inlArgInfo) // statement list and have to be checked for side effects may be provided via // additionalTree and additionalCallArgs. // -bool Compiler::impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* additionalTree, - CallArgs* additionalCallArgs, - GenTree* dereferencedAddress, - InlArgInfo* inlArgInfo) +bool Compiler::impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* additionalTree, + CallArgs* additionalCallArgs, + GenTree* dereferencedAddress, + InlArgInfo* inlArgInfo) { assert(compIsForInlining()); assert(opts.OptEnabled(CLFLG_INLINING)); @@ -20884,7 +20889,7 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // See what we know about the type of 'this' in the call. assert(call->gtArgs.HasThisPointer()); - CallArg* thisArg = call->gtArgs.GetThisArg(); + CallArg* thisArg = call->gtArgs.GetThisArg(); GenTree* thisObj = thisArg->GetNode()->gtEffectiveVal(false); bool isExact = false; bool objIsNonNull = false; @@ -21348,7 +21353,8 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // Update the 'this' pointer to refer to the box payload // GenTree* const payloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); - GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); + GenTree* const boxPayload = + gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); assert(thisObj == thisArg->GetNode()); thisArg->SetNode(boxPayload); @@ -21372,7 +21378,7 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, JITDUMP("revising call to invoke unboxed entry\n"); GenTree* const payloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); - GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); + GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); thisArg->SetNode(boxPayload); call->gtCallMethHnd = unboxedEntryMethod; diff --git a/src/coreclr/jit/indirectcalltransformer.cpp b/src/coreclr/jit/indirectcalltransformer.cpp index 868efc5455523c..ccfddc8b6d370d 100644 --- a/src/coreclr/jit/indirectcalltransformer.cpp +++ b/src/coreclr/jit/indirectcalltransformer.cpp @@ -690,7 +690,7 @@ class IndirectCallTransformer compiler->fgNewStmtAtEnd(thenBlock, assign); // Clone call. Note we must use the special candidate helper. - GenTreeCall* call = compiler->gtCloneCandidateCall(origCall); + GenTreeCall* call = compiler->gtCloneCandidateCall(origCall); call->gtArgs.GetThisArg()->SetNode(compiler->gtNewLclvNode(thisTemp, TYP_REF)); call->SetIsGuarded(); diff --git a/src/coreclr/jit/inline.h b/src/coreclr/jit/inline.h index f505657553b5cd..e89986e7d85d0f 100644 --- a/src/coreclr/jit/inline.h +++ b/src/coreclr/jit/inline.h @@ -667,7 +667,7 @@ struct InlineInfo return numberOfGcRefLocals > 0; } - bool thisDereferencedFirst; + bool thisDereferencedFirst; #ifdef FEATURE_SIMD bool hasSIMDTypeArgLocalOrReturn; diff --git a/src/coreclr/jit/lclmorph.cpp b/src/coreclr/jit/lclmorph.cpp index 648e9a8f8af048..b63a0631924311 100644 --- a/src/coreclr/jit/lclmorph.cpp +++ b/src/coreclr/jit/lclmorph.cpp @@ -692,7 +692,8 @@ class LocalAddressVisitor final : public GenTreeVisitor { if (varTypeIsStruct(varDsc) && varDsc->lvIsTemp) { - if ((callTree != nullptr) && callTree->gtArgs.HasRetBuffer() && (val.Node() == callTree->gtArgs.GetRetBufferArg()->GetNode())) + if ((callTree != nullptr) && callTree->gtArgs.HasRetBuffer() && + (val.Node() == callTree->gtArgs.GetRetBufferArg()->GetNode())) { assert(!exposeParentLcl); diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 6f64447689ea18..e740f69bbf9d21 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1238,16 +1238,17 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, CallArg* callArg, const unsigned slotNumber = callArg->AbiInfo.ByteOffset / TARGET_POINTER_SIZE; const bool putInIncomingArgArea = call->IsFastTailCall(); - putArg = new (comp, GT_PUTARG_STK) - GenTreePutArgStk(GT_PUTARG_STK, TYP_VOID, arg, callArg->AbiInfo.ByteOffset, + putArg = + new (comp, GT_PUTARG_STK) GenTreePutArgStk(GT_PUTARG_STK, TYP_VOID, arg, callArg->AbiInfo.ByteOffset, #if defined(DEBUG_ARG_SLOTS) && defined(FEATURE_PUT_STRUCT_ARG_STK) - callArg->AbiInfo.GetStackByteSize(), slotNumber, callArg->AbiInfo.GetStackSlotsNumber(), + callArg->AbiInfo.GetStackByteSize(), slotNumber, + callArg->AbiInfo.GetStackSlotsNumber(), #elif defined(DEBUG_ARG_SLOTS) && !defined(FEATURE_PUT_STRUCT_ARG_STK) - slotNumber, + slotNumber, #elif !defined(DEBUG_ARG_SLOTS) && defined(FEATURE_PUT_STRUCT_ARG_STK) - callArg->AbiInfo.GetStackByteSize(), + callArg->AbiInfo.GetStackByteSize(), #endif - call, putInIncomingArgArea); + call, putInIncomingArgArea); #ifdef FEATURE_PUT_STRUCT_ARG_STK // If the ArgTabEntry indicates that this arg is a struct @@ -1348,7 +1349,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, CallArg* callArg, void Lowering::LowerArg(GenTreeCall* call, CallArg* callArg, bool late) { GenTree** ppArg = late ? &callArg->LateNodeRef() : &callArg->NodeRef(); - GenTree* arg = *ppArg; + GenTree* arg = *ppArg; assert(arg != nullptr); JITDUMP("lowering arg : "); @@ -1415,7 +1416,7 @@ void Lowering::LowerArg(GenTreeCall* call, CallArg* callArg, bool late) BlockRange().InsertAfter(arg, bitcast); *ppArg = arg = bitcast; - type = TYP_LONG; + type = TYP_LONG; } #endif // defined(TARGET_X86) #endif // defined(FEATURE_SIMD) @@ -2355,11 +2356,12 @@ void Lowering::LowerCFGCall(GenTreeCall* call) assert(gotUse); useOfTar.ReplaceWith(regNode); - GenTreeCall* validate = comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID); + GenTreeCall* validate = comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID); // Add the call to the validator. Use a placeholder for the target while we // morph, sequence and lower, to avoid redoing that for the actual target. GenTree* targetPlaceholder = comp->gtNewZeroConNode(callTarget->TypeGet()); - CallArg* targetArg = validate->gtArgs.PushFront(comp, targetPlaceholder, WellKnownArg::ValidateIndirectCallTarget); + CallArg* targetArg = + validate->gtArgs.PushFront(comp, targetPlaceholder, WellKnownArg::ValidateIndirectCallTarget); comp->fgMorphTree(validate); @@ -2407,7 +2409,7 @@ void Lowering::LowerCFGCall(GenTreeCall* call) // Now insert the call target as an extra argument. // GenTree* placeHolder = comp->gtNewArgPlaceHolderNode(callTarget->TypeGet(), NO_CLASS_HANDLE); - CallArg* targetArg = call->gtArgs.PushBack(comp, placeHolder, WellKnownArg::DispatchIndirectCallTarget); + CallArg* targetArg = call->gtArgs.PushBack(comp, placeHolder, WellKnownArg::DispatchIndirectCallTarget); placeHolder->gtFlags |= GTF_LATE_ARG; targetArg->SetLateNode(callTarget); @@ -2421,11 +2423,11 @@ void Lowering::LowerCFGCall(GenTreeCall* call) LowerArg(call, targetArg, true /* late */); // Finally update the call to be a helper call - call->gtCallType = CT_HELPER; + call->gtCallType = CT_HELPER; call->gtCallMethHnd = Compiler::eeFindHelper(CORINFO_HELP_DISPATCH_INDIRECT_CALL); call->gtFlags &= ~GTF_CALL_VIRT_KIND_MASK; #ifdef FEATURE_READYTORUN - call->gtEntryPoint.addr = nullptr; + call->gtEntryPoint.addr = nullptr; call->gtEntryPoint.accessType = IAT_VALUE; #endif @@ -4528,10 +4530,11 @@ void Lowering::InsertPInvokeCallProlog(GenTreeCall* call) // On x86 targets, PInvoke calls need the size of the stack args in InlinedCallFrame.m_Datum. // This is because the callee pops stack arguments, and we need to keep track of this during stack // walking - const unsigned numStkArgBytes = call->gtArgs.OutgoingArgsStackSize(); - GenTree* stackBytes = comp->gtNewIconNode(numStkArgBytes, TYP_INT); + const unsigned numStkArgBytes = call->gtArgs.OutgoingArgsStackSize(); + GenTree* stackBytes = comp->gtNewIconNode(numStkArgBytes, TYP_INT); // Insert call to CORINFO_HELP_JIT_PINVOKE_BEGIN - GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, frameAddr, stackBytes); + GenTree* helperCall = + comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, frameAddr, stackBytes); #else GenTree* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_BEGIN, TYP_VOID, frameAddr); #endif @@ -4692,8 +4695,7 @@ void Lowering::InsertPInvokeCallEpilog(GenTreeCall* call) #endif // DEBUG // Insert call to CORINFO_HELP_JIT_PINVOKE_END - GenTreeCall* helperCall = - comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_END, TYP_VOID, frameAddr); + GenTreeCall* helperCall = comp->gtNewHelperCallNode(CORINFO_HELP_JIT_PINVOKE_END, TYP_VOID, frameAddr); comp->fgMorphTree(helperCall); BlockRange().InsertAfter(call, LIR::SeqTree(comp, helperCall)); diff --git a/src/coreclr/jit/lsraarmarch.cpp b/src/coreclr/jit/lsraarmarch.cpp index 5137d71d70a085..92d777cc6e667e 100644 --- a/src/coreclr/jit/lsraarmarch.cpp +++ b/src/coreclr/jit/lsraarmarch.cpp @@ -250,10 +250,10 @@ int LinearScan::BuildCall(GenTreeCall* call) for (LateArg arg : call->gtArgs.LateArgs()) { CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetNode(); #ifdef DEBUG - regNumber argReg = abiInfo.GetRegNum(); + regNumber argReg = abiInfo.GetRegNum(); #endif if (argNode->gtOper == GT_PUTARG_STK) diff --git a/src/coreclr/jit/lsraxarch.cpp b/src/coreclr/jit/lsraxarch.cpp index 6bb2f1537dbe31..b3c624fc5ced2d 100644 --- a/src/coreclr/jit/lsraxarch.cpp +++ b/src/coreclr/jit/lsraxarch.cpp @@ -1122,7 +1122,7 @@ int LinearScan::BuildCall(GenTreeCall* call) // // Note that this property is statically checked by LinearScan::CheckBlock. CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetNode(); // Each register argument corresponds to one source. if (argNode->OperIsPutArgReg()) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 18ebd491400d38..c7d4bf8b0264b4 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -575,23 +575,40 @@ const char* getWellKnownArgName(WellKnownArg arg) { switch (arg) { - case WellKnownArg::None: return "None"; - case WellKnownArg::ThisPointer: return "ThisPointer"; - case WellKnownArg::VarArgsCookie: return "VarArgsCookie"; - case WellKnownArg::InstParam: return "InstParam"; - case WellKnownArg::RetBuffer: return "RetBuffer"; - case WellKnownArg::PInvokeFrame: return "PInvokeFrame"; - case WellKnownArg::SecretStubParam: return "SecretStubParam"; - case WellKnownArg::WrapperDelegateCell: return "WrapperDelegateCell"; - case WellKnownArg::ShiftLow: return "ShiftLow"; - case WellKnownArg::ShiftHigh: return "ShiftHigh"; - case WellKnownArg::VirtualStubCell: return "VirtualStubCell"; - case WellKnownArg::PInvokeCookie: return "PInvokeCookie"; - case WellKnownArg::PInvokeTarget: return "PInvokeTarget"; - case WellKnownArg::R2RIndirectionCell: return "R2RIndirectionCell"; - case WellKnownArg::ValidateIndirectCallTarget: return "ValidateIndirectCallTarget"; - case WellKnownArg::DispatchIndirectCallTarget: return "DispatchIndirectCallTarget"; - default: return "N/A"; + case WellKnownArg::None: + return "None"; + case WellKnownArg::ThisPointer: + return "ThisPointer"; + case WellKnownArg::VarArgsCookie: + return "VarArgsCookie"; + case WellKnownArg::InstParam: + return "InstParam"; + case WellKnownArg::RetBuffer: + return "RetBuffer"; + case WellKnownArg::PInvokeFrame: + return "PInvokeFrame"; + case WellKnownArg::SecretStubParam: + return "SecretStubParam"; + case WellKnownArg::WrapperDelegateCell: + return "WrapperDelegateCell"; + case WellKnownArg::ShiftLow: + return "ShiftLow"; + case WellKnownArg::ShiftHigh: + return "ShiftHigh"; + case WellKnownArg::VirtualStubCell: + return "VirtualStubCell"; + case WellKnownArg::PInvokeCookie: + return "PInvokeCookie"; + case WellKnownArg::PInvokeTarget: + return "PInvokeTarget"; + case WellKnownArg::R2RIndirectionCell: + return "R2RIndirectionCell"; + case WellKnownArg::ValidateIndirectCallTarget: + return "ValidateIndirectCallTarget"; + case WellKnownArg::DispatchIndirectCallTarget: + return "DispatchIndirectCallTarget"; + default: + return "N/A"; } } @@ -612,7 +629,8 @@ void CallArg::Dump(Compiler* comp) if (AbiInfo.GetStackByteSize() > 0) { #if defined(DEBUG_ARG_SLOTS) - printf(", numSlots=%u, slotNum=%u, byteSize=%u, byteOffset=%u", AbiInfo.NumSlots, AbiInfo.SlotNum, AbiInfo.ByteSize, AbiInfo.ByteOffset); + printf(", numSlots=%u, slotNum=%u, byteSize=%u, byteOffset=%u", AbiInfo.NumSlots, AbiInfo.SlotNum, + AbiInfo.ByteSize, AbiInfo.ByteOffset); #else printf(", byteSize=%u, byteOffset=%u", AbiInfo.ByteSize, AbiInfo.ByteOffset); @@ -681,7 +699,7 @@ void CallArgs::SplitArg(CallArg* arg, unsigned numRegs, unsigned numSlots, unsig arg->AbiInfo.NumRegs = numRegs; DEBUG_ARG_SLOTS_ONLY(arg->AbiInfo.NumSlots = numSlots;) arg->AbiInfo.ByteOffset = 0; - m_hasStackArgs = true; + m_hasStackArgs = true; } // TODO-Cleanup: structs are aligned to 8 bytes on arm64 apple, so it would work, but pass the precise size. *nextSlotNum += numSlots; @@ -691,7 +709,7 @@ void CallArgs::SplitArg(CallArg* arg, unsigned numRegs, unsigned numSlots, unsig void CallArgs::SetTemp(CallArg* arg, unsigned tmpNum) { arg->m_tmpNum = tmpNum; - arg->m_isTmp = true; + arg->m_isTmp = true; } void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) @@ -864,8 +882,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) // CLANG_FORMAT_COMMENT_ANCHOR; #ifdef TARGET_ARM - bool isMultiRegArg = - (arg.AbiInfo.NumRegs > 0) && (arg.AbiInfo.NumRegs + arg.AbiInfo.GetStackSlotsNumber() > 1); + bool isMultiRegArg = (arg.AbiInfo.NumRegs > 0) && (arg.AbiInfo.NumRegs + arg.AbiInfo.GetStackSlotsNumber() > 1); #else bool isMultiRegArg = (arg.AbiInfo.NumRegs > 1); #endif @@ -1085,8 +1102,8 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // +------------------------------------+ <--- m_lateHead // - unsigned argCount = CountArgs(); - CallArg* table[32]; + unsigned argCount = CountArgs(); + CallArg* table[32]; CallArg** argTable = table; if (argCount > 32) { @@ -1270,9 +1287,9 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) { /* Find the most expensive arg remaining and evaluate it next */ - CallArg* expensiveArg = nullptr; - unsigned expensiveArgIndex = UINT_MAX; - unsigned expensiveArgCost = 0; + CallArg* expensiveArg = nullptr; + unsigned expensiveArgIndex = UINT_MAX; + unsigned expensiveArgCost = 0; // [We use a forward iterator pattern] // @@ -1297,8 +1314,8 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) if (argsRemaining == 1) { // This is the last arg to place - expensiveArgIndex = curInx; - expensiveArg = arg; + expensiveArgIndex = curInx; + expensiveArg = arg; assert(begTab == endTab); break; } @@ -1313,9 +1330,9 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) if (argx->GetCostEx() > expensiveArgCost) { // Remember this arg as the most expensive one that we have yet seen - expensiveArgCost = argx->GetCostEx(); - expensiveArgIndex = curInx; - expensiveArg = arg; + expensiveArgCost = argx->GetCostEx(); + expensiveArgIndex = curInx; + expensiveArg = arg; } } } @@ -1332,7 +1349,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) if (expensiveArgIndex != begTab) { argTable[expensiveArgIndex] = argTable[begTab]; - argTable[begTab] = expensiveArg; + argTable[begTab] = expensiveArg; } begTab++; @@ -1350,7 +1367,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) for (unsigned i = 0; i < argCount; i++) { *tail = argTable[i]; - tail = &(*tail)->LateNextRef(); + tail = &(*tail)->LateNextRef(); } m_argsSorted = true; @@ -1376,7 +1393,7 @@ GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) var_types type = varDsc->TypeGet(); // Create a copy of the temp to go into the late argument list - GenTree* argNode = comp->gtNewLclvNode(tmpVarNum, type); + GenTree* argNode = comp->gtNewLclvNode(tmpVarNum, type); GenTree* addrNode = nullptr; if (varTypeIsStruct(type)) @@ -1431,7 +1448,7 @@ GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) else { var_types addrType = TYP_BYREF; - argNode = comp->gtNewOperNode(GT_ADDR, addrType, argNode); + argNode = comp->gtNewOperNode(GT_ADDR, addrType, argNode); comp->lvaSetVarAddrExposed(tmpVarNum DEBUGARG(AddressExposedReason::ESCAPE_ADDRESS)); addrNode = argNode; @@ -1594,8 +1611,7 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) CORINFO_CLASS_HANDLE clsHnd = comp->lvaGetStruct(tmpVarNum); unsigned structSize = varDsc->lvExactSize; - scalarType = - comp->getPrimitiveTypeForStruct(structSize, clsHnd, m_isVarArgs); + scalarType = comp->getPrimitiveTypeForStruct(structSize, clsHnd, m_isVarArgs); } #endif // TARGET_ARMARCH || defined (UNIX_AMD64_ABI) } @@ -1752,13 +1768,12 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) printf("\n"); } #endif - } void CallArgs::SetNeedsTemp(CallArg* arg) { arg->m_needTmp = true; - m_needsTemps = true; + m_needsTemps = true; } //------------------------------------------------------------------------------ @@ -1845,7 +1860,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) unsigned argIndex = 0; unsigned intArgRegNum = 0; unsigned fltArgRegNum = 0; - unsigned nextSlotNum = INIT_ARG_STACK_SLOT; + unsigned nextSlotNum = INIT_ARG_STACK_SLOT; bool callHasRetBuffArg = HasRetBuffer(); bool callIsVararg = IsVarArgs(); @@ -1869,8 +1884,8 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) JITDUMP("Initializing arg info for %d.%s:\n", call->gtTreeID, GenTree::OpName(call->gtOper)); m_nextStackByteOffset = INIT_ARG_STACK_SLOT * TARGET_POINTER_SIZE; - m_hasRegArgs = false; - m_hasStackArgs = false; + m_hasRegArgs = false; + m_hasStackArgs = false; // At this point, we should not have any late args, as this needs to be done before those are determined. assert(m_lateHead == nullptr); @@ -1953,7 +1968,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) } else #endif // !TARGET_X86 - if (call->gtCallType == CT_INDIRECT && (call->gtCallCookie != nullptr)) + if (call->gtCallType == CT_INDIRECT && (call->gtCallCookie != nullptr)) { assert(!call->IsUnmanaged()); @@ -1964,7 +1979,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) // All architectures pass the cookie in a register. InsertAfterThisOrFirst(comp, arg, WellKnownArg::PInvokeCookie); // put destination into R10/EAX - arg = comp->gtClone(call->gtCallAddr, true); + arg = comp->gtClone(call->gtCallAddr, true); InsertAfterThisOrFirst(comp, arg, WellKnownArg::PInvokeTarget); // finally change this call to a helper call @@ -2132,8 +2147,8 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) { switch (arg.GetWellKnownArg()) { - case WellKnownArg::ThisPointer: - continue; + case WellKnownArg::ThisPointer: + continue; } CORINFO_CLASS_HANDLE argClass; @@ -2147,7 +2162,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) assert((nodeType == sigType) || varTypeIsStruct(sigType) || genTypeSize(nodeType) == genTypeSize(sigType)); - sigArg = comp->info.compCompHnd->getArgNext(sigArg); + sigArg = comp->info.compCompHnd->getArgNext(sigArg); } } } @@ -2430,8 +2445,8 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) // // Figure out if the argument will be passed in a register. // - bool isRegArg = false; - regNumber nonStdRegNum = REG_NA; + bool isRegArg = false; + regNumber nonStdRegNum = REG_NA; if (isRegParamType(genActualType(argx->TypeGet())) #ifdef UNIX_AMD64_ABI @@ -2617,9 +2632,9 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) } #endif // TARGET_ARM - arg.AbiInfo = {}; - arg.AbiInfo.ArgNum = argIndex; - arg.AbiInfo.ArgType = argx->TypeGet(); + arg.AbiInfo = {}; + arg.AbiInfo.ArgNum = argIndex; + arg.AbiInfo.ArgType = argx->TypeGet(); arg.AbiInfo.IsStruct = isStructArg; if (isRegArg) @@ -2676,7 +2691,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) arg.AbiInfo.NumRegs = size; arg.AbiInfo.SetByteSize(byteSize, argAlignBytes, isStructArg, isFloatHfa); #ifdef UNIX_AMD64_ABI - arg.AbiInfo.StructIntRegs = structIntRegs; + arg.AbiInfo.StructIntRegs = structIntRegs; arg.AbiInfo.StructFloatRegs = structFloatRegs; assert(size <= 2); if (size == 2) @@ -2791,7 +2806,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) if (arg.AbiInfo.IsStruct) { arg.AbiInfo.PassedByRef = passStructByRef; - arg.AbiInfo.ArgType = (structBaseType == TYP_UNKNOWN) ? argx->TypeGet() : structBaseType; + arg.AbiInfo.ArgType = (structBaseType == TYP_UNKNOWN) ? argx->TypeGet() : structBaseType; } else { @@ -2801,7 +2816,6 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) argIndex++; } // end foreach argument loop - #ifdef DEBUG #if defined(DEBUG_ARG_SLOTS) @@ -2816,7 +2830,8 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) #ifdef DEBUG if (VERBOSE) { - JITDUMP("Args for call [%06u] %s after DetermineArgABIInformation:\n", comp->dspTreeID(call), GenTree::OpName(call->gtOper)); + JITDUMP("Args for call [%06u] %s after DetermineArgABIInformation:\n", comp->dspTreeID(call), + GenTree::OpName(call->gtOper)); for (CallArg& arg : Args()) { arg.Dump(comp); @@ -2831,7 +2846,8 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) unsigned CallArgs::OutgoingArgsStackSize() const { unsigned aligned = Compiler::GetOutgoingArgByteSize(m_nextStackByteOffset); - return max(aligned, MIN_ARG_AREA_FOR_CALL);; + return max(aligned, MIN_ARG_AREA_FOR_CALL); + ; } unsigned CallArgs::CountArgs() @@ -2917,12 +2933,12 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) bool hasMultiregStructArgs = false; for (CallArg& arg : call->gtArgs.Args()) { - GenTree** parentArgx = &arg.NodeRef(); + GenTree** parentArgx = &arg.NodeRef(); // Morph the arg node, and update the parent and argEntry pointers. - GenTree* argx = *parentArgx; - argx = fgMorphTree(argx); - *parentArgx = argx; + GenTree* argx = *parentArgx; + argx = fgMorphTree(argx); + *parentArgx = argx; if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) { @@ -3036,7 +3052,8 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) { if (isPow2(passingSize)) { - canTransform = (!arg.AbiInfo.IsHfaArg() || (passingSize == genTypeSize(arg.AbiInfo.GetHfaType()))); + canTransform = + (!arg.AbiInfo.IsHfaArg() || (passingSize == genTypeSize(arg.AbiInfo.GetHfaType()))); } #if defined(TARGET_ARM64) || defined(UNIX_AMD64_ABI) @@ -3448,8 +3465,8 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) // The tree from the gtCallLateArgs list is passed to the callee. The fgArgEntry node contains the mapping // between the nodes in both lists. If the arg is not a late arg, the fgArgEntry->node points to itself, // otherwise points to the list in the late args list. - bool isLateArg = (arg.GetNode()->gtFlags & GTF_LATE_ARG) != 0; - GenTree* argx = arg.GetArgNode(); + bool isLateArg = (arg.GetNode()->gtFlags & GTF_LATE_ARG) != 0; + GenTree* argx = arg.GetArgNode(); if (!arg.AbiInfo.IsStruct) { @@ -4238,10 +4255,10 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg, CORI // Structs are always on the stack, and thus never need temps // so we have to put the copy and temp all into one expression. - GenTree* argNode = call->gtArgs.MakeTmpArgNode(this, arg); + GenTree* argNode = call->gtArgs.MakeTmpArgNode(this, arg); // Change the expression to "(tmp=val),tmp" - argNode = gtNewOperNode(GT_COMMA, argNode->TypeGet(), copyBlk, argNode); + argNode = gtNewOperNode(GT_COMMA, argNode->TypeGet(), copyBlk, argNode); #endif // FEATURE_FIXED_OUT_ARGS @@ -6125,7 +6142,6 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason) #endif // DEBUG }; - for (CallArg& arg : callee->gtArgs.Args()) { calleeArgStackSize = roundUp(calleeArgStackSize, arg.AbiInfo.ByteAlignment); @@ -6510,8 +6526,8 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) } else { - JITDUMP(" ... no, call has %u > %u args, alias analysis deemed too costly\n", - argCount, argLimit); + JITDUMP(" ... no, call has %u > %u args, alias analysis deemed too costly\n", argCount, + argLimit); } } } @@ -7346,8 +7362,8 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL { JITDUMP("Moving this pointer into arg list\n"); CallArg* thisArg = call->gtArgs.GetThisArg(); - GenTree* objp = thisArg->GetArgNode(); - GenTree* thisPtr = nullptr; + GenTree* objp = thisArg->GetArgNode(); + GenTree* thisPtr = nullptr; // JIT will need one or two copies of "this" in the following cases: // 1) the call needs null check; @@ -7532,8 +7548,7 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig CORINFO_METHOD_HANDLE callTargetStubHnd, CORINFO_METHOD_HANDLE dispatcherHnd) { - GenTreeCall* callDispatcherNode = - gtNewCallNode(CT_USER_FUNC, dispatcherHnd, TYP_VOID, fgMorphStmt->GetDebugInfo()); + GenTreeCall* callDispatcherNode = gtNewCallNode(CT_USER_FUNC, dispatcherHnd, TYP_VOID, fgMorphStmt->GetDebugInfo()); // The dispatcher has signature // void DispatchTailCalls(void* callersRetAddrSlot, void* callTarget, void* retValue) @@ -7615,7 +7630,7 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig } // Args are (void** callersReturnAddressSlot, void* callTarget, void* retVal) - GenTree* callTarget = new (this, GT_FTN_ADDR) GenTreeFptrVal(TYP_I_IMPL, callTargetStubHnd); + GenTree* callTarget = new (this, GT_FTN_ADDR) GenTreeFptrVal(TYP_I_IMPL, callTargetStubHnd); // Add the caller's return address slot. if (lvaRetAddrVar == BAD_VAR_NUM) @@ -7625,7 +7640,7 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig lvaSetVarAddrExposed(lvaRetAddrVar DEBUGARG(AddressExposedReason::DISPATCH_RET_BUF)); } - GenTree* retAddrSlot = gtNewOperNode(GT_ADDR, TYP_I_IMPL, gtNewLclvNode(lvaRetAddrVar, TYP_I_IMPL)); + GenTree* retAddrSlot = gtNewOperNode(GT_ADDR, TYP_I_IMPL, gtNewLclvNode(lvaRetAddrVar, TYP_I_IMPL)); callDispatcherNode->gtArgs.PushFront(this, retAddrSlot, callTarget, retValArg); @@ -7928,8 +7943,8 @@ void Compiler::fgMorphTailCallViaJitHelper(GenTreeCall* call) CallArg* thisArg = call->gtArgs.GetThisArg(); if (thisArg != nullptr) { - GenTree* thisPtr = nullptr; - GenTree* objp = thisArg->GetNode(); + GenTree* thisPtr = nullptr; + GenTree* objp = thisArg->GetNode(); if ((call->IsDelegateInvoke() || call->IsVirtualVtable()) && !objp->OperIs(GT_LCL_VAR)) { @@ -7998,19 +8013,19 @@ void Compiler::fgMorphTailCallViaJitHelper(GenTreeCall* call) unsigned nOldStkArgsWords = (compArgSize - (codeGen->intRegState.rsCalleeRegArgCount * REGSIZE_BYTES)) / REGSIZE_BYTES; GenTree* arg3Node = gtNewIconNode((ssize_t)nOldStkArgsWords, TYP_I_IMPL); - CallArg* arg3 = call->gtArgs.PushBack(this, arg3Node); + CallArg* arg3 = call->gtArgs.PushBack(this, arg3Node); // Inject a placeholder for the count of outgoing stack arguments that the Lowering phase will generate. // The constant will be replaced. GenTree* arg2Node = gtNewIconNode(9, TYP_I_IMPL); - CallArg* arg2 = call->gtArgs.InsertAfter(this, arg3, arg2Node); + CallArg* arg2 = call->gtArgs.InsertAfter(this, arg3, arg2Node); // Inject a placeholder for the flags. // The constant will be replaced. GenTree* arg1Node = gtNewIconNode(8, TYP_I_IMPL); - CallArg* arg1 = call->gtArgs.InsertAfter(this, arg2, arg1Node); + CallArg* arg1 = call->gtArgs.InsertAfter(this, arg2, arg1Node); // Inject a placeholder for the real call target that the Lowering phase will generate. // The constant will be replaced. GenTree* arg0Node = gtNewIconNode(7, TYP_I_IMPL); - CallArg* arg0 = call->gtArgs.InsertAfter(this, arg1, arg0Node); + CallArg* arg0 = call->gtArgs.InsertAfter(this, arg1, arg0Node); // It is now a varargs tail call. call->gtArgs.SetIsVarArgs(); @@ -8176,8 +8191,8 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa { Statement* paramAssignStmt = fgAssignRecursiveCallArgToCallerParam(earlyArg, &arg, - fgGetArgParameterLclNum(recursiveTailCall, &arg), - block, callDI, tmpAssignmentInsertionPoint, + fgGetArgParameterLclNum(recursiveTailCall, &arg), block, + callDI, tmpAssignmentInsertionPoint, paramAssignmentInsertionPoint); if ((tmpAssignmentInsertionPoint == lastStmt) && (paramAssignStmt != nullptr)) { @@ -8193,14 +8208,14 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa for (LateArg arg : recursiveTailCall->gtArgs.LateArgs()) { // A late argument is an actual argument that needs to be assigned to the corresponding caller's parameter. - GenTree* lateArg = arg.GetNode(); + GenTree* lateArg = arg.GetNode(); // Late-added non-standard args are extra args that are not passed as locals, so skip those if (!arg.GetArg()->IsArgAddedLate()) { Statement* paramAssignStmt = fgAssignRecursiveCallArgToCallerParam(lateArg, arg.GetArg(), - fgGetArgParameterLclNum(recursiveTailCall, arg.GetArg()), - block, callDI, tmpAssignmentInsertionPoint, + fgGetArgParameterLclNum(recursiveTailCall, arg.GetArg()), block, + callDI, tmpAssignmentInsertionPoint, paramAssignmentInsertionPoint); if ((tmpAssignmentInsertionPoint == lastStmt) && (paramAssignStmt != nullptr)) @@ -8311,8 +8326,8 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa // Return Value: // parameter assignment statement if one was inserted; nullptr otherwise. -Statement* Compiler::fgAssignRecursiveCallArgToCallerParam(GenTree* arg, - CallArg* callArg, +Statement* Compiler::fgAssignRecursiveCallArgToCallerParam(GenTree* arg, + CallArg* callArg, unsigned lclParamNum, BasicBlock* block, const DebugInfo& callDI, @@ -8831,11 +8846,14 @@ GenTree* Compiler::fgMorphConst(GenTree* tree) if (helper == CORINFO_HELP_STRCNS_CURRENT_MODULE) { - tree = gtNewHelperCallNode(helper, TYP_REF, gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT)); + tree = gtNewHelperCallNode(helper, TYP_REF, + gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT)); } else { - tree = gtNewHelperCallNode(helper, TYP_REF, gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT), gtNewIconEmbScpHndNode(tree->AsStrCon()->gtScpHnd)); + tree = gtNewHelperCallNode(helper, TYP_REF, + gtNewIconNode(RidFromToken(tree->AsStrCon()->gtSconCPX), TYP_INT), + gtNewIconEmbScpHndNode(tree->AsStrCon()->gtScpHnd)); } return fgMorphTree(tree); @@ -15977,8 +15995,7 @@ GenTree* Compiler::fgInitThisClass() { GenTree* methHndTree = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL); methHndTree->gtFlags |= GTF_VAR_CONTEXT; - return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, TYP_VOID, - gtNewIconNode(0), methHndTree); + return gtNewHelperCallNode(CORINFO_HELP_INITINSTCLASS, TYP_VOID, gtNewIconNode(0), methHndTree); } default: diff --git a/src/coreclr/jit/patchpoint.cpp b/src/coreclr/jit/patchpoint.cpp index 8c14eba1b5c2f0..d1478c51c31239 100644 --- a/src/coreclr/jit/patchpoint.cpp +++ b/src/coreclr/jit/patchpoint.cpp @@ -176,10 +176,11 @@ class PatchpointTransformer // Fill in helper block // // call PPHelper(&ppCounter, ilOffset) - GenTree* ilOffsetNode = compiler->gtNewIconNode(ilOffset, TYP_INT); - GenTree* ppCounterRef = compiler->gtNewLclvNode(ppCounterLclNum, TYP_INT); - GenTree* ppCounterAddr = compiler->gtNewOperNode(GT_ADDR, TYP_I_IMPL, ppCounterRef); - GenTreeCall* helperCall = compiler->gtNewHelperCallNode(CORINFO_HELP_PATCHPOINT, TYP_VOID, ppCounterAddr, ilOffsetNode); + GenTree* ilOffsetNode = compiler->gtNewIconNode(ilOffset, TYP_INT); + GenTree* ppCounterRef = compiler->gtNewLclvNode(ppCounterLclNum, TYP_INT); + GenTree* ppCounterAddr = compiler->gtNewOperNode(GT_ADDR, TYP_I_IMPL, ppCounterRef); + GenTreeCall* helperCall = + compiler->gtNewHelperCallNode(CORINFO_HELP_PATCHPOINT, TYP_VOID, ppCounterAddr, ilOffsetNode); compiler->fgNewStmtAtEnd(helperBlock, helperCall); } @@ -238,8 +239,8 @@ class PatchpointTransformer // // call PartialCompilationPatchpointHelper(ilOffset) // - GenTree* ilOffsetNode = compiler->gtNewIconNode(ilOffset, TYP_INT); - GenTreeCall* helperCall = + GenTree* ilOffsetNode = compiler->gtNewIconNode(ilOffset, TYP_INT); + GenTreeCall* helperCall = compiler->gtNewHelperCallNode(CORINFO_HELP_PARTIAL_COMPILATION_PATCHPOINT, TYP_VOID, ilOffsetNode); compiler->fgNewStmtAtEnd(block, helperCall); diff --git a/src/coreclr/jit/stacklevelsetter.cpp b/src/coreclr/jit/stacklevelsetter.cpp index 363629e40f9623..d1297ab2ca11c0 100644 --- a/src/coreclr/jit/stacklevelsetter.cpp +++ b/src/coreclr/jit/stacklevelsetter.cpp @@ -237,12 +237,12 @@ void StackLevelSetter::SetThrowHelperBlock(SpecialCodeKind kind, BasicBlock* blo // the number of stack slots in stack arguments for the call. unsigned StackLevelSetter::PopArgumentsFromCall(GenTreeCall* call) { - unsigned usedStackSlotsCount = 0; + unsigned usedStackSlotsCount = 0; if (call->gtArgs.HasStackArgs()) { for (CallArg& arg : call->gtArgs.Args()) { - const unsigned slotCount = arg.AbiInfo.GetStackSlotsNumber(); + const unsigned slotCount = arg.AbiInfo.GetStackSlotsNumber(); if (slotCount != 0) { GenTree* node = arg.GetArgNode(); diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index c67cbc407af761..0a46f4934fe182 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -9776,9 +9776,9 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN { unsigned nArgs = ValueNumStore::VNFuncArity(vnf); assert(vnf != VNF_Boundary); - CallArgs* args = &call->gtArgs; - bool generateUniqueVN = false; - bool useEntryPointAddrAsArg0 = false; + CallArgs* args = &call->gtArgs; + bool generateUniqueVN = false; + bool useEntryPointAddrAsArg0 = false; switch (vnf) { @@ -9791,7 +9791,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_JitNewArr: { - generateUniqueVN = true; + generateUniqueVN = true; // TODO-ARGS: Should this really be early arg? ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetArgByIndex(1)->GetNode()->gtVNPair); From e6d9776e5b98a5233008db8e97ce82afb3f24e43 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 17:46:46 +0200 Subject: [PATCH 03/52] Value number arg fix --- src/coreclr/jit/valuenum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 0a46f4934fe182..1308539a3ebc0c 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -9954,7 +9954,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN } else { - ValueNumPair vnp2wx = curArg->GetNode()->gtVNPair; + ValueNumPair vnp2wx = curArg->GetArgNode()->gtVNPair; ValueNumPair vnp2; ValueNumPair vnp2x; vnStore->VNPUnpackExc(vnp2wx, &vnp2, &vnp2x); From 3b83e3c9845f4e82dc687fb3728dd53d6661200e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 17:49:53 +0200 Subject: [PATCH 04/52] Undo clang-format change --- src/coreclr/jit/gentree.h | 74 +++++++++------------------------------ 1 file changed, 16 insertions(+), 58 deletions(-) diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 2d219244cef9f9..35fcadadf60395 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4270,65 +4270,23 @@ class CallArg CallArg(const CallArg&) = delete; CallArg& operator=(CallArg&) = delete; - // clang format off - GenTree*& NodeRef() - { - return m_node; - } - GenTree* GetNode() - { - return m_node; - } - void SetNode(GenTree* node) - { - m_node = node; - } - GenTree*& LateNodeRef() - { - return m_lateNode; - } - GenTree* GetLateNode() - { - return m_lateNode; - } - void SetLateNode(GenTree* lateNode) - { - m_lateNode = lateNode; - } - CallArg*& NextRef() - { - return m_next; - } - CallArg* GetNext() - { - return m_next; - } - void SetNext(CallArg* next) - { - m_next = next; - } - CallArg*& LateNextRef() - { - return m_lateNext; - } - CallArg* GetLateNext() - { - return m_lateNext; - } - void SetLateNext(CallArg* lateNext) - { - m_lateNext = lateNext; - } - WellKnownArg GetWellKnownArg() - { - return m_wellKnownArg; - } + // clang-format off + GenTree*& NodeRef() { return m_node; } + GenTree* GetNode() { return m_node; } + void SetNode(GenTree* node) { m_node = node; } + GenTree*& LateNodeRef() { return m_lateNode; } + GenTree* GetLateNode() { return m_lateNode; } + void SetLateNode(GenTree* lateNode) { m_lateNode = lateNode; } + CallArg*& NextRef() { return m_next; } + CallArg* GetNext() { return m_next; } + void SetNext(CallArg* next) { m_next = next; } + CallArg*& LateNextRef() { return m_lateNext; } + CallArg* GetLateNext() { return m_lateNext; } + void SetLateNext(CallArg* lateNext) { m_lateNext = lateNext; } + WellKnownArg GetWellKnownArg() { return m_wellKnownArg; } // TODO-ARGS: Remove - bool IsTemp() - { - return m_isTmp; - } - // clang format on + bool IsTemp() { return m_isTmp; } + // clang-format on // Get the real argument node, i.e. not a setup or placeholder node. // This is the same as GetNode() until morph. From 5fd50ed151dbaf97829da38698c91cebf33a6258 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 17:54:10 +0200 Subject: [PATCH 05/52] Reorder --- src/coreclr/jit/compiler.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index d54e71b1f39682..723a61771791c9 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -1017,8 +1017,8 @@ inline GenTreeCall* Compiler::gtNewHelperCallNode( if (arg1 != nullptr) { - result->gtFlags |= arg1->gtFlags & GTF_ALL_EFFECT; CallArg* lastArg = result->gtArgs.PushFront(this, arg1); + result->gtFlags |= arg1->gtFlags & GTF_ALL_EFFECT; if (arg2 != nullptr) { lastArg = result->gtArgs.InsertAfter(this, lastArg, arg2); From 80e413691561244b571b690ab139f9786e5c4f1e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 17:54:45 +0200 Subject: [PATCH 06/52] Use helper --- src/coreclr/jit/compiler.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 723a61771791c9..7dcee065a3a1ba 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -1051,9 +1051,7 @@ inline GenTreeCall* Compiler::gtNewRuntimeLookupHelperCallNode(CORINFO_RUNTIME_L void* compileTimeHandle) { GenTree* argNode = gtNewIconEmbHndNode(pRuntimeLookup->signature, nullptr, GTF_ICON_GLOBAL_PTR, compileTimeHandle); - GenTreeCall* call = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL); - call->gtArgs.PushFront(this, ctxTree, argNode); - + GenTreeCall* call = gtNewHelperCallNode(pRuntimeLookup->helper, TYP_I_IMPL, ctxTree, argNode); return call; } From eb938a5e1085106c854df8932293c7a720320263 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 18:20:30 +0200 Subject: [PATCH 07/52] Fix build --- src/coreclr/jit/flowgraph.cpp | 9 ++++++--- src/coreclr/jit/gentree.cpp | 6 ++++++ src/coreclr/jit/importer.cpp | 2 ++ src/coreclr/jit/morph.cpp | 5 ++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 9177708e1515ed..da77d70f3d65b0 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -870,8 +870,7 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo opModuleIDArg = gtNewIconNode((size_t)moduleID, TYP_I_IMPL); } - GenTreeCall* result = gtNewHelperCallNode(helper, type); - CallArg* opModuleIDCallArg = result->gtArgs.PushFront(this, opModuleIDArg); + GenTreeCall* result; if (bNeedClassID) { if (pclsID) @@ -883,7 +882,11 @@ GenTreeCall* Compiler::fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfo opClassIDArg = gtNewIconNode(clsID, TYP_INT); } - result->gtArgs.InsertAfter(this, opModuleIDCallArg, opClassIDArg); + result = gtNewHelperCallNode(helper, type, opModuleIDArg, opClassIDArg); + } + else + { + result = gtNewHelperCallNode(helper, type, opModuleIDArg); } result->gtFlags |= callFlags; diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 4093cc71f1a757..9dc8ac36cb3212 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1355,6 +1355,8 @@ void CallArgs::AddedWellKnownArg(WellKnownArg arg) case WellKnownArg::RetBuffer: m_hasRetBuffer = true; break; + default: + break; } } @@ -1370,6 +1372,8 @@ void CallArgs::RemovedWellKnownArg(WellKnownArg arg) assert(FindWellKnownArg(arg) == nullptr); m_hasRetBuffer = false; break; + default: + break; } } @@ -1440,6 +1444,8 @@ regNumber CallArgs::GetCustomRegister(Compiler* comp, CorInfoCallConvExtension c case WellKnownArg::DispatchIndirectCallTarget: return REG_DISPATCH_INDIRECT_CALL_ADDR; #endif + default: + break; } return REG_NA; diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 3b9cd8f380e9bf..fb45c06a595c44 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -19554,6 +19554,8 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) case WellKnownArg::InstParam: // These do not appear in the signature; do not include them continue; + default: + break; } GenTree* actualArg = gtFoldExpr(arg.GetNode()); diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index c7d4bf8b0264b4..1d39b6226f5596 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -2145,10 +2145,9 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) CORINFO_ARG_LIST_HANDLE sigArg = sig->args; for (CallArg& arg : call->gtArgs.Args()) { - switch (arg.GetWellKnownArg()) + if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) { - case WellKnownArg::ThisPointer: - continue; + continue; } CORINFO_CLASS_HANDLE argClass; From 53e9e3c4a85db7f50b6b8aa0dabe430f569591c1 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 19:05:00 +0200 Subject: [PATCH 08/52] Increase space before nodes to fit call arg names --- src/coreclr/jit/gentree.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 9dc8ac36cb3212..ad137e638c5df8 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -9717,7 +9717,7 @@ void Compiler::gtDispNode(GenTree* tree, IndentStack* indentStack, _In_ _In_opt_ { bool printFlags = true; // always true.. - int msgLength = 25; + int msgLength = 35; GenTree* prev; @@ -12001,7 +12001,7 @@ void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr * } // 60 spaces for alignment - printf("%-50s", ""); + printf("%-60s", ""); #if FEATURE_SET_FLAGS // additional flag enlarges the flag field by one character printf(" "); From 922f9d8826ff1832169b84863a6bdccf01fe9657 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 19:16:42 +0200 Subject: [PATCH 09/52] Rename memory kind, fix Unix x86 build, remove occurences of fgArgInfo --- src/coreclr/jit/codegenxarch.cpp | 12 ++++++------ src/coreclr/jit/compiler.h | 1 - src/coreclr/jit/compmemkind.h | 3 +-- src/coreclr/jit/gentree.cpp | 8 ++++---- src/coreclr/jit/gentree.h | 12 ++++++++++++ src/coreclr/jit/importer.cpp | 2 +- src/coreclr/jit/morph.cpp | 9 +++++---- src/coreclr/jit/stacklevelsetter.cpp | 4 ++-- 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 51f9fdb5253e01..cbc0714796d0c7 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -7547,17 +7547,17 @@ void CodeGen::genAlignStackBeforeCall(GenTreeCall* call) #if defined(UNIX_X86_ABI) // Have we aligned the stack yet? - if (!call->fgArgInfo->IsStkAlignmentDone()) + if (!call->gtArgs.IsStkAlignmentDone()) { // We haven't done any stack alignment yet for this call. We might need to create // an alignment adjustment, even if this function itself doesn't have any stack args. // This can happen if this function call is part of a nested call sequence, and the outer // call has already pushed some arguments. - unsigned stkLevel = genStackLevel + call->fgArgInfo->GetStkSizeBytes(); - call->fgArgInfo->ComputeStackAlignment(stkLevel); + unsigned stkLevel = genStackLevel + call->gtArgs.GetStkSizeBytes(); + call->gtArgs.ComputeStackAlignment(stkLevel); - unsigned padStkAlign = call->fgArgInfo->GetStkAlign(); + unsigned padStkAlign = call->gtArgs.GetStkAlign(); if (padStkAlign != 0) { // Now generate the alignment @@ -7566,7 +7566,7 @@ void CodeGen::genAlignStackBeforeCall(GenTreeCall* call) AddNestedAlignment(padStkAlign); } - call->fgArgInfo->SetStkAlignmentDone(); + call->gtArgs.SetStkAlignmentDone(); } #endif // UNIX_X86_ABI @@ -7589,7 +7589,7 @@ void CodeGen::genRemoveAlignmentAfterCall(GenTreeCall* call, unsigned bias) #if defined(TARGET_X86) #if defined(UNIX_X86_ABI) // Put back the stack pointer if there was any padding for stack alignment - unsigned padStkAlign = call->fgArgInfo->GetStkAlign(); + unsigned padStkAlign = call->gtArgs.GetStkAlign(); unsigned padStkAdjust = padStkAlign + bias; if (padStkAdjust != 0) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 96b4c85fae008c..9c06609c275c76 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -1813,7 +1813,6 @@ class Compiler friend class UnwindEpilogInfo; friend class JitTimer; friend class LinearScan; - friend class fgArgInfo; friend class Rationalizer; friend class Phase; friend class Lowering; diff --git a/src/coreclr/jit/compmemkind.h b/src/coreclr/jit/compmemkind.h index 969b0c3dc2a7b5..f1b4fb04e9433b 100644 --- a/src/coreclr/jit/compmemkind.h +++ b/src/coreclr/jit/compmemkind.h @@ -15,8 +15,7 @@ CompMemKindMacro(ASTNode) CompMemKindMacro(InstDesc) CompMemKindMacro(ImpStack) CompMemKindMacro(BasicBlock) -CompMemKindMacro(fgArgInfo) -CompMemKindMacro(fgArgInfoPtrArr) +CompMemKindMacro(CallArgs) CompMemKindMacro(FlowList) CompMemKindMacro(TreeStatementList) CompMemKindMacro(SiScope) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index ad137e638c5df8..4cb019ddd18338 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1458,7 +1458,7 @@ bool CallArgs::IsNonStandard(Compiler* comp, GenTreeCall* call, CallArg* arg) CallArg* CallArgs::PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) { - CallArg* arg = new (comp, CMK_fgArgInfo) CallArg(wellKnownArg); + CallArg* arg = new (comp, CMK_CallArgs) CallArg(wellKnownArg); arg->SetNode(node); arg->SetNext(m_head); m_head = arg; @@ -1474,7 +1474,7 @@ CallArg* CallArgs::PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnow slot = &(*slot)->NextRef(); } - *slot = new (comp, CMK_fgArgInfo) CallArg(wellKnownArg); + *slot = new (comp, CMK_CallArgs) CallArg(wellKnownArg); (*slot)->SetNode(node); AddedWellKnownArg(wellKnownArg); return *slot; @@ -1496,7 +1496,7 @@ CallArg* CallArgs::InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, Wel assert(found && "Could not find arg to insert after in argument list"); #endif - CallArg* newArg = new (comp, CMK_fgArgInfo) CallArg(wellKnownArg); + CallArg* newArg = new (comp, CMK_CallArgs) CallArg(wellKnownArg); newArg->SetNode(arg); newArg->SetNext(after->GetNext()); after->SetNext(newArg); @@ -8351,7 +8351,7 @@ void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc co CallArg** tail = &m_head; for (CallArg& arg : other->Args()) { - CallArg* carg = new (comp, CMK_fgArgInfo) CallArg(arg.GetWellKnownArg()); + CallArg* carg = new (comp, CMK_CallArgs) CallArg(arg.GetWellKnownArg()); carg->m_node = arg.m_node != nullptr ? copyNode(arg.m_node) : nullptr; carg->m_lateNode = arg.m_lateNode != nullptr ? copyNode(arg.m_lateNode) : nullptr; carg->m_needTmp = arg.m_needTmp; diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 35fcadadf60395..c54b8d575d7d41 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4440,6 +4440,18 @@ class CallArgs bool HasRegArgs() const { return m_hasRegArgs; } bool HasStackArgs() const { return m_hasStackArgs; } bool NeedsTemps() const { return m_needsTemps; } + +#ifdef UNIX_X86_ABI + void ComputeStackAlignment(unsigned curStackLevelInBytes) + { + m_padStkAlign = AlignmentPad(curStackLevelInBytes, STACK_ALIGN); + } + unsigned GetStkAlign() const { return m_padStkAlign; } + unsigned GetStkSizeBytes() { return m_stkSizeBytes; } + void SetStkSizeBytes(unsigned bytes) { m_stkSizeBytes = bytes; } + bool IsStkAlignmentDone() const { return m_alignmentDone; } + void SetStkAlignmentDone() { m_alignmentDone = true; } +#endif // clang-format on unsigned OutgoingArgsStackSize() const; diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index fb45c06a595c44..e4cc5fc1bd3cb9 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -920,7 +920,7 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a assert(!varTypeIsStruct(nodeArgType)); // Some ABI require precise size information for call arguments less than target pointer size, // for example arm64 OSX. Create a special node to keep this information until morph - // consumes it into `fgArgInfo`. + // consumes it into `CallArgs`. GenTree* putArgType = gtNewOperNode(GT_PUTARG_TYPE, jitSigType, arg.GetNode()); arg.SetNode(putArgType); } diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 1d39b6226f5596..49f4357243bb82 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -1107,7 +1107,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) CallArg** argTable = table; if (argCount > 32) { - argTable = new (comp, CMK_fgArgInfo) CallArg*[argCount]; + argTable = new (comp, CMK_CallArgs) CallArg*[argCount]; } argCount = 0; @@ -2872,8 +2872,9 @@ unsigned CallArgs::CountArgs() // node itself is re-created. // // Notes: -// This calls fgInitArgInfo to create the 'fgArgInfo' for the call. -// If it has already been created, that method will simply return. +// This calls CallArgs::DetermineArgABIInformation to determine ABI +// information for the call. If it has already been determined, that method +// will simply return. // // This method changes the state of the call node. It uses the existence // of gtCallLateArgs (the late arguments list) to determine if it has @@ -2924,7 +2925,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) // First we morph the argument subtrees ('this' pointer, arguments, etc.). // During the first call to fgMorphArgs we also record the - // information about late arguments we have in 'fgArgInfo'. + // information about late arguments in CallArgs. // This information is used later to contruct the late args // Note that this name is a bit of a misnomer - it indicates that there are struct args diff --git a/src/coreclr/jit/stacklevelsetter.cpp b/src/coreclr/jit/stacklevelsetter.cpp index d1297ab2ca11c0..461f7dd2141a7b 100644 --- a/src/coreclr/jit/stacklevelsetter.cpp +++ b/src/coreclr/jit/stacklevelsetter.cpp @@ -12,7 +12,7 @@ StackLevelSetter::StackLevelSetter(Compiler* compiler) : Phase(compiler, PHASE_STACK_LEVEL_SETTER) , currentStackLevel(0) , maxStackLevel(0) - , memAllocator(compiler->getAllocator(CMK_fgArgInfoPtrArr)) + , memAllocator(compiler->getAllocator(CMK_CallArgs)) , putArgNumSlots(memAllocator) #if !FEATURE_FIXED_OUT_ARGS , framePointerRequired(compiler->codeGen->isFramePointerRequired()) @@ -105,7 +105,7 @@ void StackLevelSetter::ProcessBlock(BasicBlock* block) GenTreeCall* call = node->AsCall(); unsigned usedStackSlotsCount = PopArgumentsFromCall(call); #if defined(UNIX_X86_ABI) - call->fgArgInfo->SetStkSizeBytes(usedStackSlotsCount * TARGET_POINTER_SIZE); + call->gtArgs.SetStkSizeBytes(usedStackSlotsCount * TARGET_POINTER_SIZE); #endif // UNIX_X86_ABI } } From c360a4fdb7d02afbee715f85ef0e3c22257d41ec Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 19:20:37 +0200 Subject: [PATCH 10/52] Remove some more mentions of outdated names --- src/coreclr/jit/compiler.h | 2 +- src/coreclr/jit/lclvars.cpp | 2 +- src/coreclr/jit/lower.cpp | 2 +- src/coreclr/jit/morph.cpp | 13 ++++--------- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 9c06609c275c76..cb8106676dabff 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -132,7 +132,7 @@ const int BAD_STK_OFFS = 0xBAADF00D; // for LclVarDsc::lvStkOffs #endif //------------------------------------------------------------------------ -// HFA info shared by LclVarDsc and fgArgTabEntry +// HFA info shared by LclVarDsc and CallArgABIInformation //------------------------------------------------------------------------ inline bool IsHfa(CorInfoHFAElemType kind) { diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index ea3b0684c39d0a..b685658f7346c9 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -2674,7 +2674,7 @@ void Compiler::lvaSetVarDoNotEnregister(unsigned varNum DEBUGARG(DoNotEnregister // Returns true if this local var is a multireg struct. // TODO-Throughput: This does a lookup on the class handle, and in the outgoing arg context -// this information is already available on the fgArgTabEntry, and shouldn't need to be +// this information is already available on the CallArgABIInformation, and shouldn't need to be // recomputed. // bool Compiler::lvaIsMultiregStruct(LclVarDsc* varDsc, bool isVarArg) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index e740f69bbf9d21..ee0e673838eb03 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1050,7 +1050,7 @@ void Lowering::ReplaceArgWithPutArgOrBitcast(GenTree** argSlot, GenTree* putArgO // Arguments: // call - the call whose arg is being rewritten. // arg - the arg being rewritten. -// info - the fgArgTabEntry information for the argument. +// callArg - the CallArg for the argument. // type - the type of the argument. // // Return Value: diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 49f4357243bb82..711a8068add987 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -2989,7 +2989,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) unsigned structSize = 0; // Struct arguments may be morphed into a node that is not a struct type. - // In such case the fgArgTabEntry keeps track of whether the original node (before morphing) + // In such case the CallArgABIInformation keeps track of whether the original node (before morphing) // was a struct and the struct classification. bool isStructArg = arg.AbiInfo.IsStruct; @@ -3460,11 +3460,6 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) for (CallArg& arg : call->gtArgs.Args()) { - // For late arguments the arg tree that is overridden is in the gtCallLateArgs list. - // For such late args the gtCallArgList contains the setup arg node (evaluating the arg.) - // The tree from the gtCallLateArgs list is passed to the callee. The fgArgEntry node contains the mapping - // between the nodes in both lists. If the arg is not a late arg, the fgArgEntry->node points to itself, - // otherwise points to the list in the late args list. bool isLateArg = (arg.GetNode()->gtFlags & GTF_LATE_ARG) != 0; GenTree* argx = arg.GetArgNode(); @@ -8078,9 +8073,9 @@ GenTree* Compiler::fgGetStubAddrArg(GenTreeCall* call) // corresponds to the argument to a recursive call. // // Notes: -// Due to non-standard args this is not just fgArgTabEntry::argNum. -// For example, in R2R compilations we will have added a non-standard -// arg for the R2R indirection cell. +// Due to non-standard args this is not just the index of the argument in +// the arg list. For example, in R2R compilations we will have added a +// non-standard arg for the R2R indirection cell. // // Arguments: // arg - the arg From 44e22cce7f036de83ec8eb4b61166b5002edc94b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 20:01:49 +0200 Subject: [PATCH 11/52] Fix assert on macOS arm64 --- src/coreclr/jit/morph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 711a8068add987..48b2216a857a06 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -2774,7 +2774,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) { nextSlotNum = roundUp(nextSlotNum, argAlignBytes / TARGET_POINTER_SIZE); } - assert(m_nextStackByteOffset / TARGET_POINTER_SIZE == nextSlotNum); + DEBUG_ARG_SLOTS_ASSERT(m_nextStackByteOffset / TARGET_POINTER_SIZE == nextSlotNum); arg.AbiInfo.SlotNum = nextSlotNum; nextSlotNum += size; From 421f21f2f941b7739030568ee2c96f8d0bed269b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 20:57:09 +0200 Subject: [PATCH 12/52] Fixes for NativeAOT --- src/coreclr/jit/flowgraph.cpp | 11 ++++++----- src/coreclr/jit/gentree.cpp | 11 +++++++++++ src/coreclr/jit/gentree.h | 1 + src/coreclr/jit/lower.cpp | 24 +++++++++++++----------- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index da77d70f3d65b0..c15167ec28e8a0 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1137,8 +1137,6 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID); - GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); CORINFO_LOOKUP pLookup; @@ -1147,7 +1145,8 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, if (!pLookup.lookupKind.needsRuntimeLookup) { entryPoint = pLookup.constLookup; - call->gtArgs.PushFront(this, thisPointer, targetObjPointers); + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, + targetObjPointers); } else { @@ -1157,8 +1156,11 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, &genericLookup); GenTree* ctxTree = getRuntimeContextTree(pLookup.lookupKind.runtimeLookupKind); call->gtArgs.PushFront(this, thisPointer, targetObjPointers, ctxTree); + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, + targetObjPointers, ctxTree); entryPoint = genericLookup; } + call->setEntryPoint(entryPoint); } else @@ -1173,8 +1175,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); - call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID); - call->gtArgs.PushFront(this, thisPointer, targetObjPointers); + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, targetObjPointers); CORINFO_LOOKUP entryPoint; info.compCompHnd->getReadyToRunDelegateCtorHelper(ldftnToken, clsHnd, &entryPoint); diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 4cb019ddd18338..7b4513964a6e00 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1537,6 +1537,17 @@ CallArg* CallArgs::InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKno } } +void CallArgs::PushLateBack(CallArg* arg) +{ + CallArg** slot = &m_lateHead; + while (*slot != nullptr) + { + slot = &(*slot)->LateNextRef(); + } + + *slot = arg; +} + bool CallArgs::Remove(CallArg* arg) { CallArg** slot = &m_head; diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index c54b8d575d7d41..4a005b63f84293 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4401,6 +4401,7 @@ class CallArgs CallArg* InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, WellKnownArg wellKnownArg = WellKnownArg::None); CallArg* InsertInstParam(Compiler* comp, GenTree* value); CallArg* InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); + void PushLateBack(CallArg* node); bool Remove(CallArg* arg); void Clear(); diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index ee0e673838eb03..c18c83b662830f 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -2356,12 +2356,11 @@ void Lowering::LowerCFGCall(GenTreeCall* call) assert(gotUse); useOfTar.ReplaceWith(regNode); - GenTreeCall* validate = comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID); // Add the call to the validator. Use a placeholder for the target while we // morph, sequence and lower, to avoid redoing that for the actual target. - GenTree* targetPlaceholder = comp->gtNewZeroConNode(callTarget->TypeGet()); - CallArg* targetArg = - validate->gtArgs.PushFront(comp, targetPlaceholder, WellKnownArg::ValidateIndirectCallTarget); + GenTree* targetPlaceholder = comp->gtNewZeroConNode(callTarget->TypeGet()); + GenTreeCall* validate = + comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID, targetPlaceholder); comp->fgMorphTree(validate); @@ -2393,13 +2392,13 @@ void Lowering::LowerCFGCall(GenTreeCall* call) assert(node->OperIsPutArg() || node->OperIsFieldList()); MoveCFGCallArg(call, node); } + } - node = arg.GetLateNode(); - if (node != nullptr) - { - assert(node->OperIsPutArg() || node->OperIsFieldList()); - MoveCFGCallArg(call, node); - } + for (LateArg arg : call->gtArgs.LateArgs()) + { + GenTree* node = arg.GetNode(); + assert(node->OperIsPutArg() || node->OperIsFieldList()); + MoveCFGCallArg(call, node); } break; } @@ -2412,8 +2411,11 @@ void Lowering::LowerCFGCall(GenTreeCall* call) CallArg* targetArg = call->gtArgs.PushBack(comp, placeHolder, WellKnownArg::DispatchIndirectCallTarget); placeHolder->gtFlags |= GTF_LATE_ARG; targetArg->SetLateNode(callTarget); + call->gtArgs.PushLateBack(targetArg); - // Set up ABI information for this call. + // Set up ABI information for this arg. + targetArg->AbiInfo.ArgNum = call->gtArgs.CountArgs() - 1; + targetArg->AbiInfo.ArgType = callTarget->TypeGet(); targetArg->AbiInfo.SetRegNum(0, REG_DISPATCH_INDIRECT_CALL_ADDR); targetArg->AbiInfo.NumRegs = 1; targetArg->AbiInfo.SetByteSize(TARGET_POINTER_SIZE, TARGET_POINTER_SIZE, false, false); From ece3b59587a97efa42faf227375e4ba35477baf8 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 21:00:35 +0200 Subject: [PATCH 13/52] Another fix --- src/coreclr/jit/flowgraph.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index c15167ec28e8a0..7ffdb364da5da3 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1155,7 +1155,6 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, info.compCompHnd->getReadyToRunHelper(ldftnToken, &pLookup.lookupKind, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, &genericLookup); GenTree* ctxTree = getRuntimeContextTree(pLookup.lookupKind.runtimeLookupKind); - call->gtArgs.PushFront(this, thisPointer, targetObjPointers, ctxTree); call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, targetObjPointers, ctxTree); entryPoint = genericLookup; From 51c7454308d9b262a4626a21f691b9511fb001fc Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 21:22:59 +0200 Subject: [PATCH 14/52] Run jit-format --- src/coreclr/jit/flowgraph.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 7ffdb364da5da3..8b406b01e94148 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1155,7 +1155,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, info.compCompHnd->getReadyToRunHelper(ldftnToken, &pLookup.lookupKind, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, &genericLookup); GenTree* ctxTree = getRuntimeContextTree(pLookup.lookupKind.runtimeLookupKind); - call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, targetObjPointers, ctxTree); entryPoint = genericLookup; } From 820650c793b6d338af8cc4c9984e6dd35dba84fc Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 21:50:46 +0200 Subject: [PATCH 15/52] Small cleanup --- src/coreclr/jit/importer.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index e4cc5fc1bd3cb9..dd47575562fb01 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3300,12 +3300,9 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) return nullptr; } - CallArg* tokenArg = &*newArrayCall->AsCall()->gtArgs.Args().begin(); - assert(tokenArg != nullptr); - CallArg* numArgsArg = tokenArg->GetNext(); - assert(numArgsArg != nullptr); - CallArg* argsArg = numArgsArg->GetNext(); - assert(argsArg != nullptr); + assert(newArrayCall->AsCall()->gtArgs.CountArgs() == 3); + GenTree* numArgsArg = newArrayCall->AsCall()->gtArgs.GetArgByIndex(1)->GetArgNode(); + GenTree* argsArg = newArrayCall->AsCall()->gtArgs.GetArgByIndex(2)->GetArgNode(); // // The number of arguments should be a constant between 1 and 64. The rank can't be 0 @@ -3313,13 +3310,13 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) // be at most 64 arguments - 32 lengths and 32 lower bounds. // - if ((!numArgsArg->GetNode()->IsCnsIntOrI()) || (numArgsArg->GetNode()->AsIntCon()->IconValue() < 1) || - (numArgsArg->GetNode()->AsIntCon()->IconValue() > 64)) + if ((!numArgsArg->IsCnsIntOrI()) || (numArgsArg->AsIntCon()->IconValue() < 1) || + (numArgsArg->AsIntCon()->IconValue() > 64)) { return nullptr; } - unsigned numArgs = static_cast(numArgsArg->GetNode()->AsIntCon()->IconValue()); + unsigned numArgs = static_cast(numArgsArg->AsIntCon()->IconValue()); bool lowerBoundsSpecified; if (numArgs == rank * 2) @@ -3383,7 +3380,7 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) unsigned argIndex = 0; GenTree* comma; - for (comma = argsArg->GetNode(); Match::IsComma(comma); comma = comma->gtGetOp2()) + for (comma = argsArg; Match::IsComma(comma); comma = comma->gtGetOp2()) { if (lowerBoundsSpecified) { From 7235c6436e600dccda8e5c2f4047068e96ddfade Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 21:55:37 +0200 Subject: [PATCH 16/52] Another small cleanup --- src/coreclr/jit/compiler.hpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 7dcee065a3a1ba..ac554b9187d9b4 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -1015,20 +1015,22 @@ inline GenTreeCall* Compiler::gtNewHelperCallNode( result->gtInlineObservation = InlineObservation::CALLSITE_IS_CALL_TO_HELPER; #endif + if (arg3 != nullptr) + { + result->gtArgs.PushFront(this, arg3); + result->gtFlags |= arg3->gtFlags & GTF_ALL_EFFECT; + } + + if (arg2 != nullptr) + { + result->gtArgs.PushFront(this, arg2); + result->gtFlags |= arg2->gtFlags & GTF_ALL_EFFECT; + } + if (arg1 != nullptr) { - CallArg* lastArg = result->gtArgs.PushFront(this, arg1); + result->gtArgs.PushFront(this, arg1); result->gtFlags |= arg1->gtFlags & GTF_ALL_EFFECT; - if (arg2 != nullptr) - { - lastArg = result->gtArgs.InsertAfter(this, lastArg, arg2); - result->gtFlags |= arg2->gtFlags & GTF_ALL_EFFECT; - if (arg3 != nullptr) - { - result->gtArgs.InsertAfter(this, lastArg, arg3); - result->gtFlags |= arg3->gtFlags & GTF_ALL_EFFECT; - } - } } return result; From a3370838dfefeaa167a739811ca009c969335c51 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 21:58:10 +0200 Subject: [PATCH 17/52] More cleanup --- src/coreclr/jit/flowgraph.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 8b406b01e94148..5d8197135d9248 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1573,9 +1573,7 @@ GenTree* Compiler::fgGetCritSectOfStaticMethod() noway_assert(tree); // tree should now contain the CORINFO_CLASS_HANDLE for the exact class. // Given the class handle, get the pointer to the Monitor. - GenTreeCall* call = gtNewHelperCallNode(CORINFO_HELP_GETSYNCFROMCLASSHANDLE, TYP_I_IMPL); - call->gtArgs.PushFront(this, tree); - tree = call; + tree = gtNewHelperCallNode(CORINFO_HELP_GETSYNCFROMCLASSHANDLE, TYP_I_IMPL, tree); } noway_assert(tree); From 12819b08b1b1d392a155d6fa2abfbf23dff1694a Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 22:06:51 +0200 Subject: [PATCH 18/52] Cleanup --- src/coreclr/jit/gentree.cpp | 13 +------------ src/coreclr/jit/morph.cpp | 4 ++-- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 7b4513964a6e00..1103c269cd62e2 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1793,7 +1793,7 @@ bool GenTreeCall::TreatAsShouldGetRetBufArg(Compiler* compiler) const } else { - assert(!"Unexpected JIT helper in TreatAsHasRetBufArg"); + assert(!"Unexpected JIT helper in TreatAsShouldGetRetBufArg"); } } return false; @@ -1849,17 +1849,6 @@ void GenTreeCall::ReplaceCallOperand(GenTree** useEdge, GenTree* replacement) } } -//------------------------------------------------------------------------- -// AreArgsComplete: Determine if this GT_CALL node's arguments have been processed. -// -// Return Value: -// Returns true if fgMorphArgs has processed the arguments. -// -bool GenTreeCall::AreArgsComplete() const -{ - return gtArgs.AreArgsComplete(); -} - //-------------------------------------------------------------------------- // Equals: Check if 2 CALL nodes are equal. // diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 48b2216a857a06..b4159ff0f93294 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -2908,7 +2908,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) DEBUG_ARG_SLOTS_ONLY(unsigned argSlots = 0;) - bool reMorphing = call->AreArgsComplete(); + bool reMorphing = call->gtArgs.AreArgsComplete(); call->gtArgs.DetermineArgABIInformation(this, call); JITDUMP("%sMorphing args for %d.%s:\n", (reMorphing) ? "Re" : "", call->gtTreeID, GenTree::OpName(call->gtOper)); @@ -6080,7 +6080,7 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason) } #endif - assert(!callee->AreArgsComplete()); + assert(!callee->gtArgs.AreArgsComplete()); callee->gtArgs.DetermineArgABIInformation(this, callee); From 053cf9fc8996e1caa4bdfb721db97ec584cce6f5 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 22:07:28 +0200 Subject: [PATCH 19/52] Remove some commented code --- src/coreclr/jit/gentree.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 1103c269cd62e2..3de45b58a3e6f2 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -12041,11 +12041,6 @@ void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr * if (nodeIsCall) { GenTreeCall* call = node->AsCall(); - // if ((call->gtCallThisArg != nullptr) && (operand == call->gtCallThisArg->GetNode())) - //{ - // sprintf_s(buf, sizeof(buf), "this in %s", compRegVarName(REG_ARG_0)); - // displayOperand(operand, buf, operandArc, indentStack, prefixIndent); - //} if (operand == call->gtCallAddr) { displayOperand(operand, "calli tgt", operandArc, indentStack, prefixIndent); From b5ab4447e9869dabefab7ae2abad9d2c31659024 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 22:09:19 +0200 Subject: [PATCH 20/52] Cleanup --- src/coreclr/jit/gentree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 3de45b58a3e6f2..ebb896ef59d668 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -13269,7 +13269,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions // In R2R expansions the handle may not be an explicit operand to the helper, // so we can't remove the box. - if (newobjCall->gtArgs.Args().begin() == newobjCall->gtArgs.Args().end()) + if (newobjCall->gtArgs.IsEmpty()) { assert(newobjCall->IsHelperCall(this, CORINFO_HELP_READYTORUN_NEW)); JITDUMP(" bailing; newobj via R2R helper\n"); From 6e228d3105aa272e449ee81201081a1428ce8cf7 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 22:14:08 +0200 Subject: [PATCH 21/52] Remove unnecessary ctor call --- src/coreclr/jit/gentree.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 4a005b63f84293..c0e6711a46f138 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -5232,11 +5232,11 @@ struct GenTreeCall final : public GenTree static bool Equals(GenTreeCall* c1, GenTreeCall* c2); - GenTreeCall(var_types type) : GenTree(GT_CALL, type), gtArgs() + GenTreeCall(var_types type) : GenTree(GT_CALL, type) { } #if DEBUGGABLE_GENTREE - GenTreeCall() : GenTree(), gtArgs() + GenTreeCall() : GenTree() { } #endif From 42bd8c124f1204f5f6f5870497973db83654c34e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 28 Mar 2022 22:14:49 +0200 Subject: [PATCH 22/52] Remove unused declaration --- src/coreclr/jit/gentree.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index c0e6711a46f138..90ec717d6b6580 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -5273,8 +5273,6 @@ struct GenTreeCall final : public GenTree return lclRetBufArgNode; } } - - void SetLclRetBufArg(CallArg* retBufArg); }; struct GenTreeCmpXchg : public GenTree From dbf30a8f423fb29a7b2f1ea4a9dfd5e742ca893e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 29 Mar 2022 00:17:01 +0200 Subject: [PATCH 23/52] Fix a comment --- src/coreclr/jit/importer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index dd47575562fb01..c2a2a7035da0ec 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -19549,7 +19549,7 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) break; case WellKnownArg::RetBuffer: case WellKnownArg::InstParam: - // These do not appear in the signature; do not include them + // These do not appear in the table of inline arg info; do not include them continue; default: break; From a353013b6aa00b26bbe1d891982a61c94e49c64b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 29 Mar 2022 10:33:26 +0200 Subject: [PATCH 24/52] Fix CFG validator --- src/coreclr/jit/lower.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index c18c83b662830f..99b01bd4dcb26e 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -2360,7 +2360,8 @@ void Lowering::LowerCFGCall(GenTreeCall* call) // morph, sequence and lower, to avoid redoing that for the actual target. GenTree* targetPlaceholder = comp->gtNewZeroConNode(callTarget->TypeGet()); GenTreeCall* validate = - comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID, targetPlaceholder); + comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID); + validate->gtArgs.PushFront(comp, targetPlaceholder, WellKnownArg::ValidateIndirectCallTarget); comp->fgMorphTree(validate); From 0cf3fc7bdcf01759aa7d8c9dd8f590d23099daf8 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 29 Mar 2022 10:46:59 +0200 Subject: [PATCH 25/52] Run jit-format --- src/coreclr/jit/lower.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 99b01bd4dcb26e..8d7d9d46b912b2 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -2359,8 +2359,7 @@ void Lowering::LowerCFGCall(GenTreeCall* call) // Add the call to the validator. Use a placeholder for the target while we // morph, sequence and lower, to avoid redoing that for the actual target. GenTree* targetPlaceholder = comp->gtNewZeroConNode(callTarget->TypeGet()); - GenTreeCall* validate = - comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID); + GenTreeCall* validate = comp->gtNewHelperCallNode(CORINFO_HELP_VALIDATE_INDIRECT_CALL, TYP_VOID); validate->gtArgs.PushFront(comp, targetPlaceholder, WellKnownArg::ValidateIndirectCallTarget); comp->fgMorphTree(validate); From 3d2261c0e485326d673ffa06686e1bc5b8f12269 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 30 Mar 2022 12:02:57 +0200 Subject: [PATCH 26/52] Remove unnecessary Clear method --- src/coreclr/jit/gentree.cpp | 39 ++++++++++++++++--------------------- src/coreclr/jit/gentree.h | 1 - 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index ebb896ef59d668..0c10da4b134298 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1234,8 +1234,24 @@ void CallArg::CheckIsStruct() #endif CallArgs::CallArgs() + : m_head(nullptr) + , m_lateHead(nullptr) + , m_nextStackByteOffset(0) + , m_hasThisPointer(false) + , m_hasRetBuffer(false) + , m_isVarArgs(false) + , m_abiInformationDetermined(false) + , m_hasRegArgs(false) + , m_hasStackArgs(false) + , m_argsComplete(false) + , m_argsSorted(false) + , m_needsTemps(false) +#ifdef UNIX_X86_ABI + , m_stkSizeBytes(0) + , m_padStkAlign(0) + , m_alignmentDone(false) +#endif { - Clear(); } CallArg* CallArgs::FindByNode(GenTree* node) @@ -1566,27 +1582,6 @@ bool CallArgs::Remove(CallArg* arg) return false; } -void CallArgs::Clear() -{ - m_head = nullptr; - m_lateHead = nullptr; - m_nextStackByteOffset = 0; - m_hasThisPointer = false; - m_hasRetBuffer = false; - m_isVarArgs = false; - m_abiInformationDetermined = false; - m_hasRegArgs = false; - m_hasStackArgs = false; - m_argsComplete = false; - m_argsSorted = false; - m_needsTemps = false; -#ifdef UNIX_X86_ABI - m_stkSizeBytes = 0; - m_padStkAlign = 0; - m_alignmentDone = false; -#endif -} - //--------------------------------------------------------------- // GetOtherRegMask: Get the reg mask of gtOtherRegs of call node // diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 90ec717d6b6580..69683a5e673ec5 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4403,7 +4403,6 @@ class CallArgs CallArg* InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); void PushLateBack(CallArg* node); bool Remove(CallArg* arg); - void Clear(); template void InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc copyFunc); From fe0f942e42124a36278b70a21e75cb0512217815 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 30 Mar 2022 12:18:02 +0200 Subject: [PATCH 27/52] Rename CallArg::*Node* -> CallArg::*EarlyNode* --- src/coreclr/jit/codegenxarch.cpp | 2 +- src/coreclr/jit/compiler.h | 2 +- src/coreclr/jit/compiler.hpp | 2 +- src/coreclr/jit/fgdiagnostic.cpp | 2 +- src/coreclr/jit/fgprofile.cpp | 6 +- src/coreclr/jit/flowgraph.cpp | 16 ++-- src/coreclr/jit/forwardsub.cpp | 2 +- src/coreclr/jit/gentree.cpp | 46 +++++------ src/coreclr/jit/gentree.h | 16 ++-- src/coreclr/jit/gschecks.cpp | 2 +- src/coreclr/jit/importer.cpp | 72 +++++++++--------- src/coreclr/jit/importer_vectorization.cpp | 2 +- src/coreclr/jit/indirectcalltransformer.cpp | 18 ++--- src/coreclr/jit/lclmorph.cpp | 4 +- src/coreclr/jit/lower.cpp | 26 +++---- src/coreclr/jit/lowerxarch.cpp | 4 +- src/coreclr/jit/lsraarmarch.cpp | 2 +- src/coreclr/jit/morph.cpp | 84 ++++++++++----------- src/coreclr/jit/valuenum.cpp | 14 ++-- 19 files changed, 161 insertions(+), 161 deletions(-) diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index cbc0714796d0c7..86c22ab91379f6 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -5378,7 +5378,7 @@ void CodeGen::genCall(GenTreeCall* call) target_ssize_t stackArgBytes = 0; for (CallArg& arg : call->gtArgs.Args()) { - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetEarlyNode(); if (argNode->OperIs(GT_PUTARG_STK) && ((argNode->gtFlags & GTF_LATE_ARG) == 0)) { GenTree* source = argNode->AsPutArgStk()->gtGetOp1(); diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index cb8106676dabff..c5bcd08bd621eb 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -10874,7 +10874,7 @@ class GenTreeVisitor for (CallArg& arg : call->gtArgs.Args()) { - result = WalkTree(&arg.NodeRef(), call); + result = WalkTree(&arg.EarlyNodeRef(), call); if (result == fgWalkResult::WALK_ABORT) { return result; diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index ac554b9187d9b4..b0ce1e36121ace 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -4375,7 +4375,7 @@ void GenTree::VisitOperands(TVisitor visitor) for (CallArg& arg : call->gtArgs.Args()) { - if (visitor(arg.GetNode()) == VisitResult::Abort) + if (visitor(arg.GetEarlyNode()) == VisitResult::Abort) { return; } diff --git a/src/coreclr/jit/fgdiagnostic.cpp b/src/coreclr/jit/fgdiagnostic.cpp index 4061f396e05153..8575a06745d9e6 100644 --- a/src/coreclr/jit/fgdiagnostic.cpp +++ b/src/coreclr/jit/fgdiagnostic.cpp @@ -3033,7 +3033,7 @@ void Compiler::fgDebugCheckFlags(GenTree* tree) { // TODO-Cleanup: this is a patch for a violation in our GT_ASG propagation. // see https://github.com/dotnet/runtime/issues/13758 - actualFlags |= arg.GetNode()->gtFlags & GTF_ASG; + actualFlags |= arg.GetEarlyNode()->gtFlags & GTF_ASG; if (arg.GetLateNode() != nullptr) { actualFlags |= arg.GetLateNode()->gtFlags & GTF_ASG; diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp index 61118821f839ee..a63d12682276f4 100644 --- a/src/coreclr/jit/fgprofile.cpp +++ b/src/coreclr/jit/fgprofile.cpp @@ -1571,7 +1571,7 @@ class ClassProbeInserter objUse = call->gtArgs.GetThisArg(); } - assert(objUse->GetNode()->TypeIs(TYP_REF)); + assert(objUse->GetEarlyNode()->TypeIs(TYP_REF)); // Grab a temp to hold the 'this' object as it will be used three times // @@ -1588,12 +1588,12 @@ class ClassProbeInserter GenTree* const tmpNode2 = compiler->gtNewLclvNode(tmpNum, TYP_REF); GenTree* const callCommaNode = compiler->gtNewOperNode(GT_COMMA, TYP_REF, helperCallNode, tmpNode2); GenTree* const tmpNode3 = compiler->gtNewLclvNode(tmpNum, TYP_REF); - GenTree* const asgNode = compiler->gtNewOperNode(GT_ASG, TYP_REF, tmpNode3, objUse->GetNode()); + GenTree* const asgNode = compiler->gtNewOperNode(GT_ASG, TYP_REF, tmpNode3, objUse->GetEarlyNode()); GenTree* const asgCommaNode = compiler->gtNewOperNode(GT_COMMA, TYP_REF, asgNode, callCommaNode); // Update the call // - objUse->SetNode(asgCommaNode); + objUse->SetEarlyNode(asgCommaNode); JITDUMP("Modified call is now\n"); DISPTREE(call); diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 5d8197135d9248..f9df518a196eaf 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1052,7 +1052,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, CORINFO_CLASS_HANDLE clsHnd = info.compCompHnd->getMethodClass(methHnd); assert(call->gtArgs.CountArgs() == 3); - GenTree* targetMethod = call->gtArgs.GetArgByIndex(2)->GetNode(); + GenTree* targetMethod = call->gtArgs.GetArgByIndex(2)->GetEarlyNode(); noway_assert(targetMethod->TypeGet() == TYP_I_IMPL); genTreeOps oper = targetMethod->OperGet(); CORINFO_METHOD_HANDLE targetMethodHnd = nullptr; @@ -1066,7 +1066,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, else if (oper == GT_CALL && targetMethod->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_VIRTUAL_FUNC_PTR)) { assert(targetMethod->AsCall()->gtArgs.CountArgs() == 3); - GenTree* handleNode = targetMethod->AsCall()->gtArgs.GetArgByIndex(2)->GetNode(); + GenTree* handleNode = targetMethod->AsCall()->gtArgs.GetArgByIndex(2)->GetEarlyNode(); if (handleNode->OperGet() == GT_CNS_INT) { @@ -1105,7 +1105,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, GenTreeCall* runtimeLookupCall = qmarkNode->AsOp()->gtOp2->AsOp()->gtOp1->AsCall(); // This could be any of CORINFO_HELP_RUNTIMEHANDLE_(METHOD|CLASS)(_LOG?) - GenTree* tokenNode = runtimeLookupCall->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* tokenNode = runtimeLookupCall->gtArgs.GetArgByIndex(1)->GetEarlyNode(); noway_assert(tokenNode->OperGet() == GT_CNS_INT); targetMethodHnd = CORINFO_METHOD_HANDLE(tokenNode->AsIntCon()->gtCompileTimeHandle); } @@ -1137,8 +1137,8 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); + GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); CORINFO_LOOKUP pLookup; CORINFO_CONST_LOOKUP entryPoint; info.compCompHnd->getReadyToRunDelegateCtorHelper(ldftnToken, clsHnd, &pLookup); @@ -1172,8 +1172,8 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); + GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, targetObjPointers); CORINFO_LOOKUP entryPoint; @@ -3971,7 +3971,7 @@ void Compiler::fgSetTreeSeqHelper(GenTree* tree, bool isLIR) for (CallArg& arg : tree->AsCall()->gtArgs.Args()) { - fgSetTreeSeqHelper(arg.GetNode(), isLIR); + fgSetTreeSeqHelper(arg.GetEarlyNode(), isLIR); } for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) diff --git a/src/coreclr/jit/forwardsub.cpp b/src/coreclr/jit/forwardsub.cpp index 3620204491bde1..935070cd3ba516 100644 --- a/src/coreclr/jit/forwardsub.cpp +++ b/src/coreclr/jit/forwardsub.cpp @@ -288,7 +288,7 @@ class ForwardSubVisitor final : public GenTreeVisitor for (CallArg& arg : m_callAncestor->gtArgs.Args()) { - m_useFlags |= (arg.GetNode()->gtFlags & GTF_GLOB_EFFECT); + m_useFlags |= (arg.GetEarlyNode()->gtFlags & GTF_GLOB_EFFECT); } if (oldUseFlags != m_useFlags) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 0c10da4b134298..b934fbf76e74fa 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1259,7 +1259,7 @@ CallArg* CallArgs::FindByNode(GenTree* node) assert(node != nullptr); for (CallArg& arg : Args()) { - if ((arg.GetNode() == node) || (arg.GetLateNode() == node)) + if ((arg.GetEarlyNode() == node) || (arg.GetLateNode() == node)) { return &arg; } @@ -1475,7 +1475,7 @@ bool CallArgs::IsNonStandard(Compiler* comp, GenTreeCall* call, CallArg* arg) CallArg* CallArgs::PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) { CallArg* arg = new (comp, CMK_CallArgs) CallArg(wellKnownArg); - arg->SetNode(node); + arg->SetEarlyNode(node); arg->SetNext(m_head); m_head = arg; AddedWellKnownArg(wellKnownArg); @@ -1491,7 +1491,7 @@ CallArg* CallArgs::PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnow } *slot = new (comp, CMK_CallArgs) CallArg(wellKnownArg); - (*slot)->SetNode(node); + (*slot)->SetEarlyNode(node); AddedWellKnownArg(wellKnownArg); return *slot; } @@ -1513,7 +1513,7 @@ CallArg* CallArgs::InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, Wel #endif CallArg* newArg = new (comp, CMK_CallArgs) CallArg(wellKnownArg); - newArg->SetNode(arg); + newArg->SetEarlyNode(arg); newArg->SetNext(after->GetNext()); after->SetNext(newArg); AddedWellKnownArg(wellKnownArg); @@ -1898,7 +1898,7 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) { - if (!Compare(i1->GetNode(), i2->GetNode())) + if (!Compare(i1->GetEarlyNode(), i2->GetEarlyNode())) { return false; } @@ -1960,7 +1960,7 @@ void CallArgs::ResetArgABIInformation() if ((*link)->IsArgAddedLate()) { JITDUMP("Removing arg %s [%06u] to prepare for re-morphing call\n", - getWellKnownArgName((*link)->GetWellKnownArg()), Compiler::dspTreeID((*link)->GetNode())); + getWellKnownArgName((*link)->GetWellKnownArg()), Compiler::dspTreeID((*link)->GetEarlyNode())); *link = (*link)->GetNext(); } @@ -2737,7 +2737,7 @@ unsigned Compiler::gtHashValue(GenTree* tree) case GT_CALL: for (CallArg& arg : tree->AsCall()->gtArgs.Args()) { - hash = genTreeHashAdd(hash, gtHashValue(arg.GetNode())); + hash = genTreeHashAdd(hash, gtHashValue(arg.GetEarlyNode())); } if (tree->AsCall()->gtCallType == CT_INDIRECT) @@ -3106,7 +3106,7 @@ unsigned Compiler::gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCo { for (CallArg& arg : args->Args()) { - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetEarlyNode(); unsigned argLevel = gtSetEvalOrder(argNode); if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) @@ -5757,9 +5757,9 @@ bool GenTree::TryGetUse(GenTree* operand, GenTree*** pUse) } for (CallArg& arg : call->gtArgs.Args()) { - if (arg.GetNode() == operand) + if (arg.GetEarlyNode() == operand) { - *pUse = &arg.NodeRef(); + *pUse = &arg.EarlyNodeRef(); return true; } if (arg.GetLateNode() == operand) @@ -8347,7 +8347,7 @@ void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc co for (CallArg& arg : other->Args()) { CallArg* carg = new (comp, CMK_CallArgs) CallArg(arg.GetWellKnownArg()); - carg->m_node = arg.m_node != nullptr ? copyNode(arg.m_node) : nullptr; + carg->m_earlyNode = arg.m_earlyNode != nullptr ? copyNode(arg.m_earlyNode) : nullptr; carg->m_lateNode = arg.m_lateNode != nullptr ? copyNode(arg.m_lateNode) : nullptr; carg->m_needTmp = arg.m_needTmp; carg->m_needPlace = arg.m_needPlace; @@ -9220,7 +9220,7 @@ void GenTreeUseEdgeIterator::AdvanceCall() if (m_statePtr != nullptr) { CallArg* arg = static_cast(m_statePtr); - m_edge = &arg->NodeRef(); + m_edge = &arg->EarlyNodeRef(); m_statePtr = arg->GetNext(); return; } @@ -11869,11 +11869,11 @@ void Compiler::gtDispArgList(GenTreeCall* call, GenTree* lastCallOperand, Indent for (CallArg& arg : call->gtArgs.Args()) { - if (!arg.GetNode()->IsNothingNode() && !arg.GetNode()->IsArgPlaceHolderNode()) + if (!arg.GetEarlyNode()->IsNothingNode() && !arg.GetEarlyNode()->IsArgPlaceHolderNode()) { char buf[256]; gtGetArgMsg(call, &arg, buf, sizeof(buf)); - gtDispChild(arg.GetNode(), indentStack, (arg.GetNode() == lastCallOperand) ? IIArcBottom : IIArc, buf, + gtDispChild(arg.GetEarlyNode(), indentStack, (arg.GetEarlyNode() == lastCallOperand) ? IIArcBottom : IIArc, buf, false); } } @@ -12053,7 +12053,7 @@ void Compiler::gtDispLIRNode(GenTree* node, const char* prefixMsg /* = nullptr * CallArg* curArg = call->gtArgs.FindByNode(operand); assert(curArg); - if (operand == curArg->GetNode()) + if (operand == curArg->GetEarlyNode()) { gtGetArgMsg(call, curArg, buf, sizeof(buf)); } @@ -12234,8 +12234,8 @@ GenTree* Compiler::gtFoldExprCall(GenTreeCall* call) { case NI_System_Enum_HasFlag: { - GenTree* thisOp = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* flagOp = call->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* thisOp = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); + GenTree* flagOp = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); GenTree* result = gtOptimizeEnumHasFlag(thisOp, flagOp); if (result != nullptr) @@ -12249,8 +12249,8 @@ GenTree* Compiler::gtFoldExprCall(GenTreeCall* call) case NI_System_Type_op_Inequality: { noway_assert(call->TypeGet() == TYP_INT); - GenTree* op1 = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* op2 = call->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* op1 = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); + GenTree* op2 = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); // If either operand is known to be a RuntimeType, this can be folded GenTree* result = gtFoldTypeEqualityCall(ni == NI_System_Type_op_Equality, op1, op2); @@ -12492,8 +12492,8 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) JITDUMP("Optimizing compare of types-from-handles to instead compare handles\n"); assert((tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.CountArgs() == 1) && (tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.CountArgs() == 1)); - GenTree* op1ClassFromHandle = tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* op2ClassFromHandle = tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* op1ClassFromHandle = tree->AsOp()->gtGetOp1()->AsCall()->gtArgs.GetArgByIndex(0)->GetEarlyNode(); + GenTree* op2ClassFromHandle = tree->AsOp()->gtGetOp2()->AsCall()->gtArgs.GetArgByIndex(0)->GetEarlyNode(); CORINFO_CLASS_HANDLE cls1Hnd = NO_CLASS_HANDLE; CORINFO_CLASS_HANDLE cls2Hnd = NO_CLASS_HANDLE; @@ -13152,7 +13152,7 @@ GenTree* Compiler::gtFoldBoxNullable(GenTree* tree) JITDUMP("\nAttempting to optimize BOX_NULLABLE(&x) %s null [%06u]\n", GenTree::OpName(oper), dspTreeID(tree)); // Get the address of the struct being boxed - GenTree* const arg = call->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* const arg = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); if (arg->OperIs(GT_ADDR) && ((arg->gtFlags & GTF_LATE_ARG) == 0)) { @@ -15169,7 +15169,7 @@ bool Compiler::gtNodeHasSideEffects(GenTree* tree, GenTreeFlags flags) { // I'm a little worried that args that assign to temps that are late args will look like // side effects...but better to be conservative for now. - if (gtTreeHasSideEffects(arg.GetNode(), flags)) + if (gtTreeHasSideEffects(arg.GetEarlyNode(), flags)) { return true; } diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 69683a5e673ec5..12264783c4b179 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4232,7 +4232,7 @@ class CallArg { friend class CallArgs; - GenTree* m_node; + GenTree* m_earlyNode; GenTree* m_lateNode; CallArg* m_next; CallArg* m_lateNext; @@ -4254,7 +4254,7 @@ class CallArg CallArgABIInformation AbiInfo; CallArg(WellKnownArg specialArgKind) - : m_node(nullptr) + : m_earlyNode(nullptr) , m_lateNode(nullptr) , m_next(nullptr) , m_lateNext(nullptr) @@ -4271,9 +4271,9 @@ class CallArg CallArg& operator=(CallArg&) = delete; // clang-format off - GenTree*& NodeRef() { return m_node; } - GenTree* GetNode() { return m_node; } - void SetNode(GenTree* node) { m_node = node; } + GenTree*& EarlyNodeRef() { return m_earlyNode; } + GenTree* GetEarlyNode() { return m_earlyNode; } + void SetEarlyNode(GenTree* node) { m_earlyNode = node; } GenTree*& LateNodeRef() { return m_lateNode; } GenTree* GetLateNode() { return m_lateNode; } void SetLateNode(GenTree* lateNode) { m_lateNode = lateNode; } @@ -4289,10 +4289,10 @@ class CallArg // clang-format on // Get the real argument node, i.e. not a setup or placeholder node. - // This is the same as GetNode() until morph. + // This is the same as GetEarlyNode() until morph. GenTree* GetArgNode() { - return m_lateNode == nullptr ? m_node : m_lateNode; + return m_lateNode == nullptr ? m_earlyNode : m_lateNode; } bool IsArgAddedLate() const; @@ -5248,7 +5248,7 @@ struct GenTreeCall final : public GenTree } CallArg* retBufArg = gtArgs.GetRetBufferArg(); - GenTree* lclRetBufArgNode = retBufArg->GetNode(); + GenTree* lclRetBufArgNode = retBufArg->GetEarlyNode(); if (lclRetBufArgNode->IsArgPlaceHolderNode()) { lclRetBufArgNode = retBufArg->GetLateNode(); diff --git a/src/coreclr/jit/gschecks.cpp b/src/coreclr/jit/gschecks.cpp index 80089d4f238432..dc8eadbde95313 100644 --- a/src/coreclr/jit/gschecks.cpp +++ b/src/coreclr/jit/gschecks.cpp @@ -196,7 +196,7 @@ Compiler::fgWalkResult Compiler::gsMarkPtrsAndAssignGroups(GenTree** pTree, fgWa newState.isUnderIndir = true; } - comp->fgWalkTreePre(&arg.NodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); + comp->fgWalkTreePre(&arg.EarlyNodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); } for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) { diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index c2a2a7035da0ec..1063c878307b9f 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -881,23 +881,23 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a var_types jitSigType = JITtype2varType(corType); - if (!impCheckImplicitArgumentCoercion(jitSigType, arg.GetNode()->TypeGet())) + if (!impCheckImplicitArgumentCoercion(jitSigType, arg.GetEarlyNode()->TypeGet())) { BADCODE("the call argument has a type that can't be implicitly converted to the signature type"); } // insert implied casts (from float to double or double to float) - if ((jitSigType == TYP_DOUBLE) && (arg.GetNode()->TypeGet() == TYP_FLOAT)) + if ((jitSigType == TYP_DOUBLE) && (arg.GetEarlyNode()->TypeGet() == TYP_FLOAT)) { - arg.SetNode(gtNewCastNode(TYP_DOUBLE, arg.GetNode(), false, TYP_DOUBLE)); + arg.SetEarlyNode(gtNewCastNode(TYP_DOUBLE, arg.GetEarlyNode(), false, TYP_DOUBLE)); } - else if ((jitSigType == TYP_FLOAT) && (arg.GetNode()->TypeGet() == TYP_DOUBLE)) + else if ((jitSigType == TYP_FLOAT) && (arg.GetEarlyNode()->TypeGet() == TYP_DOUBLE)) { - arg.SetNode(gtNewCastNode(TYP_FLOAT, arg.GetNode(), false, TYP_FLOAT)); + arg.SetEarlyNode(gtNewCastNode(TYP_FLOAT, arg.GetEarlyNode(), false, TYP_FLOAT)); } // insert any widening or narrowing casts for backwards compatibility - arg.SetNode(impImplicitIorI4Cast(arg.GetNode(), jitSigType)); + arg.SetEarlyNode(impImplicitIorI4Cast(arg.GetEarlyNode(), jitSigType)); if (corType != CORINFO_TYPE_CLASS && corType != CORINFO_TYPE_BYREF && corType != CORINFO_TYPE_PTR && corType != CORINFO_TYPE_VAR) @@ -914,15 +914,15 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a } } - const var_types nodeArgType = arg.GetNode()->TypeGet(); + const var_types nodeArgType = arg.GetEarlyNode()->TypeGet(); if (!varTypeIsStruct(jitSigType) && genTypeSize(nodeArgType) != genTypeSize(jitSigType)) { assert(!varTypeIsStruct(nodeArgType)); // Some ABI require precise size information for call arguments less than target pointer size, // for example arm64 OSX. Create a special node to keep this information until morph // consumes it into `CallArgs`. - GenTree* putArgType = gtNewOperNode(GT_PUTARG_TYPE, jitSigType, arg.GetNode()); - arg.SetNode(putArgType); + GenTree* putArgType = gtNewOperNode(GT_PUTARG_TYPE, jitSigType, arg.GetEarlyNode()); + arg.SetEarlyNode(putArgType); } sigArgs = info.compCompHnd->getArgNext(sigArgs); @@ -3201,7 +3201,7 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) } // Strip helper call away - fieldTokenNode = fieldTokenNode->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); + fieldTokenNode = fieldTokenNode->AsCall()->gtArgs.GetArgByIndex(0)->GetEarlyNode(); if (fieldTokenNode->gtOper == GT_IND) { @@ -4125,7 +4125,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, } assert(op1->AsCall()->gtArgs.CountArgs() == 1); op1 = gtNewHelperCallNode(typeHandleHelper, TYP_REF, - op1->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); + op1->AsCall()->gtArgs.GetArgByIndex(0)->GetEarlyNode()); op1->gtType = TYP_REF; retNode = op1; } @@ -4217,7 +4217,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, { assert(call->gtArgs.CountArgs() == 1); CORINFO_CLASS_HANDLE hClass = - gtGetHelperArgClassHandle(call->gtArgs.GetArgByIndex(0)->GetNode()); + gtGetHelperArgClassHandle(call->gtArgs.GetArgByIndex(0)->GetEarlyNode()); if (hClass != NO_CLASS_HANDLE) { retNode = @@ -4784,9 +4784,9 @@ GenTree* Compiler::impTypeIsAssignable(GenTree* typeTo, GenTree* typeFrom) { assert((typeTo->AsCall()->gtArgs.CountArgs() == 1) && (typeFrom->AsCall()->gtArgs.CountArgs() == 1)); CORINFO_CLASS_HANDLE hClassTo = - gtGetHelperArgClassHandle(typeTo->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); + gtGetHelperArgClassHandle(typeTo->AsCall()->gtArgs.GetArgByIndex(0)->GetEarlyNode()); CORINFO_CLASS_HANDLE hClassFrom = - gtGetHelperArgClassHandle(typeFrom->AsCall()->gtArgs.GetArgByIndex(0)->GetNode()); + gtGetHelperArgClassHandle(typeFrom->AsCall()->gtArgs.GetArgByIndex(0)->GetEarlyNode()); if (hClassTo == NO_CLASS_HANDLE || hClassFrom == NO_CLASS_HANDLE) { @@ -7471,7 +7471,7 @@ void Compiler::impImportNewObjArray(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORI for (CallArg& arg : node->AsCall()->gtArgs.Args()) { - node->gtFlags |= arg.GetNode()->gtFlags & GTF_GLOB_EFFECT; + node->gtFlags |= arg.GetEarlyNode()->gtFlags & GTF_GLOB_EFFECT; } node->AsCall()->compileTimeHelperArgumentHandle = (CORINFO_GENERIC_HANDLE)pResolvedToken->hClass; @@ -7908,14 +7908,14 @@ void Compiler::impPopArgsForUnmanagedCall(GenTreeCall* call, CORINFO_SIG_INFO* s if (call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) { - GenTree* thisPtr = call->gtArgs.Args().begin()->GetNode(); + GenTree* thisPtr = call->gtArgs.Args().begin()->GetEarlyNode(); impBashVarAddrsToI(thisPtr); assert(thisPtr->TypeGet() == TYP_I_IMPL || thisPtr->TypeGet() == TYP_BYREF); } for (CallArg& arg : call->gtArgs.Args()) { - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetEarlyNode(); call->gtFlags |= argNode->gtFlags & GTF_GLOB_EFFECT; // We should not be passing gc typed args to an unmanaged call. @@ -9461,7 +9461,7 @@ var_types Compiler::impImportCall(OPCODE opcode, for (CallArg& arg : call->AsCall()->gtArgs.Args()) { - call->gtFlags |= arg.GetNode()->gtFlags & GTF_GLOB_EFFECT; + call->gtFlags |= arg.GetEarlyNode()->gtFlags & GTF_GLOB_EFFECT; } //------------------------------------------------------------------------- @@ -9758,7 +9758,7 @@ var_types Compiler::impImportCall(OPCODE opcode, if (compIsForInlining() && opcode == CEE_CALLVIRT) { assert(call->AsCall()->gtArgs.HasThisPointer()); - GenTree* callObj = call->AsCall()->gtArgs.GetThisArg()->GetNode(); + GenTree* callObj = call->AsCall()->gtArgs.GetThisArg()->GetEarlyNode(); if ((call->AsCall()->IsVirtual() || (call->gtFlags & GTF_CALL_NULLCHECK)) && impInlineIsGuaranteedThisDerefBeforeAnySideEffects(nullptr, &call->AsCall()->gtArgs, callObj, @@ -17337,7 +17337,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) #endif // defined(TARGET_ARM64) { assert(iciCall->gtArgs.HasRetBuffer()); - GenTree* dest = gtCloneExpr(iciCall->gtArgs.GetRetBufferArg()->GetNode()); + GenTree* dest = gtCloneExpr(iciCall->gtArgs.GetRetBufferArg()->GetEarlyNode()); // spill temp only exists if there are multiple return points if (fgNeedReturnSpillTemp()) { @@ -18933,7 +18933,7 @@ void Compiler::impMakeDiscretionaryInlineObservations(InlineInfo* pInlineInfo, I CORINFO_CLASS_HANDLE sigClass; CorInfoType corType = strip(info.compCompHnd->getArgType(&sig, sigArg, &sigClass)); - GenTree* argNode = argUse == nullptr ? nullptr : argUse->GetNode()->gtSkipPutArgType(); + GenTree* argNode = argUse == nullptr ? nullptr : argUse->GetEarlyNode()->gtSkipPutArgType(); if (corType == CORINFO_TYPE_CLASS) { @@ -19555,7 +19555,7 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) break; } - GenTree* actualArg = gtFoldExpr(arg.GetNode()); + GenTree* actualArg = gtFoldExpr(arg.GetEarlyNode()); impInlineRecordArgInfo(pInlineInfo, actualArg, ilArgCnt, inlineResult); if (inlineResult->IsFailure()) @@ -19595,7 +19595,7 @@ void Compiler::impInlineInitVars(InlineInfo* pInlineInfo) var_types sigType = ((clsAttr & CORINFO_FLG_VALUECLASS) != 0) ? TYP_BYREF : TYP_REF; lclVarInfo[0].lclTypeInfo = sigType; - GenTree* thisArgNode = thisArg->GetNode(); + GenTree* thisArgNode = thisArg->GetEarlyNode(); assert(varTypeIsGC(thisArgNode->TypeGet()) || // "this" is managed ((thisArgNode->TypeGet() == TYP_I_IMPL) && // "this" is unmgd but the method's class doesnt care @@ -20236,7 +20236,7 @@ bool Compiler::impInlineIsGuaranteedThisDerefBeforeAnySideEffects(GenTree* ad { for (CallArg& arg : additionalCallArgs->Args()) { - if (GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS(arg.GetNode()->gtFlags)) + if (GTF_GLOBALLY_VISIBLE_SIDE_EFFECTS(arg.GetEarlyNode()->gtFlags)) { return false; } @@ -20889,7 +20889,7 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // See what we know about the type of 'this' in the call. assert(call->gtArgs.HasThisPointer()); CallArg* thisArg = call->gtArgs.GetThisArg(); - GenTree* thisObj = thisArg->GetNode()->gtEffectiveVal(false); + GenTree* thisObj = thisArg->GetEarlyNode()->gtEffectiveVal(false); bool isExact = false; bool objIsNonNull = false; CORINFO_CLASS_HANDLE objClass = gtGetClassHandle(thisObj, &isExact, &objIsNonNull); @@ -21252,8 +21252,8 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, JITDUMP("Success! invoking unboxed entry point on local copy, and passing method table " "arg\n"); // TODO-CallArgs-REVIEW: Might discard commas otherwise? - assert(thisObj == thisArg->GetNode()); - thisArg->SetNode(localCopyThis); + assert(thisObj == thisArg->GetEarlyNode()); + thisArg->SetEarlyNode(localCopyThis); call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; call->gtArgs.InsertInstParam(this, methodTableArg); @@ -21289,9 +21289,9 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, if (localCopyThis != nullptr) { JITDUMP("Success! invoking unboxed entry point on local copy\n"); - assert(thisObj == thisArg->GetNode()); + assert(thisObj == thisArg->GetEarlyNode()); // TODO-CallArgs-REVIEW: Might discard commas otherwise? - thisArg->SetNode(localCopyThis); + thisArg->SetEarlyNode(localCopyThis); call->gtCallMethHnd = unboxedEntryMethod; call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; derivedMethod = unboxedEntryMethod; @@ -21336,7 +21336,7 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // Get the method table from the boxed object. // // TODO-CallArgs-REVIEW: Use thisObj here? Differs by gtEffectiveVal. - GenTree* const clonedThisArg = gtClone(thisArg->GetNode()); + GenTree* const clonedThisArg = gtClone(thisArg->GetEarlyNode()); if (clonedThisArg == nullptr) { @@ -21353,10 +21353,10 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, // GenTree* const payloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); GenTree* const boxPayload = - gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); + gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetEarlyNode(), payloadOffset); - assert(thisObj == thisArg->GetNode()); - thisArg->SetNode(boxPayload); + assert(thisObj == thisArg->GetEarlyNode()); + thisArg->SetEarlyNode(boxPayload); call->gtCallMethHnd = unboxedEntryMethod; call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; @@ -21377,9 +21377,9 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, JITDUMP("revising call to invoke unboxed entry\n"); GenTree* const payloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); - GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetNode(), payloadOffset); + GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetEarlyNode(), payloadOffset); - thisArg->SetNode(boxPayload); + thisArg->SetEarlyNode(boxPayload); call->gtCallMethHnd = unboxedEntryMethod; call->gtCallMoreFlags |= GTF_CALL_M_UNBOXED; derivedMethod = unboxedEntryMethod; @@ -21535,7 +21535,7 @@ class SpillRetExprHelper { for (CallArg& arg : call->gtArgs.Args()) { - comp->fgWalkTreePre(&arg.NodeRef(), SpillRetExprVisitor, this); + comp->fgWalkTreePre(&arg.EarlyNodeRef(), SpillRetExprVisitor, this); } // TODO-ARGS-REVIEW: Different order of this and rest of args diff --git a/src/coreclr/jit/importer_vectorization.cpp b/src/coreclr/jit/importer_vectorization.cpp index 9efa2602cdecd1..a9584e854d9daa 100644 --- a/src/coreclr/jit/importer_vectorization.cpp +++ b/src/coreclr/jit/importer_vectorization.cpp @@ -575,7 +575,7 @@ GenTreeStrCon* Compiler::impGetStrConFromSpan(GenTree* span) if ((ni == NI_System_MemoryExtensions_AsSpan) || (ni == NI_System_String_op_Implicit)) { assert(argCall->gtArgs.CountArgs() == 1); - GenTree* arg = argCall->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* arg = argCall->gtArgs.GetArgByIndex(0)->GetEarlyNode(); if (arg->OperIs(GT_CNS_STR)) { return arg->AsStrCon(); diff --git a/src/coreclr/jit/indirectcalltransformer.cpp b/src/coreclr/jit/indirectcalltransformer.cpp index ccfddc8b6d370d..6fc0d1a27c72c5 100644 --- a/src/coreclr/jit/indirectcalltransformer.cpp +++ b/src/coreclr/jit/indirectcalltransformer.cpp @@ -539,7 +539,7 @@ class IndirectCallTransformer checkBlock->bbJumpKind = BBJ_COND; // Fetch method table from object arg to call. - GenTree* thisTree = compiler->gtCloneExpr(origCall->gtArgs.GetThisArg()->GetNode()); + GenTree* thisTree = compiler->gtCloneExpr(origCall->gtArgs.GetThisArg()->GetEarlyNode()); // Create temp for this if the tree is costly. if (!thisTree->IsLocal()) @@ -554,7 +554,7 @@ class IndirectCallTransformer // Propagate the new this to the call. Must be a new expr as the call // will live on in the else block and thisTree is used below. - origCall->gtArgs.GetThisArg()->SetNode(compiler->gtNewLclvNode(thisTempNum, TYP_REF)); + origCall->gtArgs.GetThisArg()->SetEarlyNode(compiler->gtNewLclvNode(thisTempNum, TYP_REF)); } // Remember the current last statement. If we're doing a chained GDV, we'll clone/copy @@ -684,14 +684,14 @@ class IndirectCallTransformer // copy 'this' to temp with exact type. const unsigned thisTemp = compiler->lvaGrabTemp(false DEBUGARG("guarded devirt this exact temp")); - GenTree* clonedObj = compiler->gtCloneExpr(origCall->gtArgs.GetThisArg()->GetNode()); + GenTree* clonedObj = compiler->gtCloneExpr(origCall->gtArgs.GetThisArg()->GetEarlyNode()); GenTree* assign = compiler->gtNewTempAssign(thisTemp, clonedObj); compiler->lvaSetClass(thisTemp, clsHnd, true); compiler->fgNewStmtAtEnd(thenBlock, assign); // Clone call. Note we must use the special candidate helper. GenTreeCall* call = compiler->gtCloneCandidateCall(origCall); - call->gtArgs.GetThisArg()->SetNode(compiler->gtNewLclvNode(thisTemp, TYP_REF)); + call->gtArgs.GetThisArg()->SetEarlyNode(compiler->gtNewLclvNode(thisTemp, TYP_REF)); call->SetIsGuarded(); JITDUMP("Direct call [%06u] in block " FMT_BB "\n", compiler->dspTreeID(call), thenBlock->bbNum); @@ -1106,14 +1106,14 @@ class IndirectCallTransformer // The first argument is the handle now. checkBlock = CreateAndInsertBasicBlock(BBJ_COND, currBlock); - assert(sizeCheck->GetNode()->OperIs(GT_LE)); - GenTree* sizeJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, sizeCheck->GetNode()); + assert(sizeCheck->GetEarlyNode()->OperIs(GT_LE)); + GenTree* sizeJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, sizeCheck->GetEarlyNode()); Statement* sizeJmpStmt = compiler->fgNewStmtFromTree(sizeJmpTree, stmt->GetDebugInfo()); compiler->fgInsertStmtAtEnd(checkBlock, sizeJmpStmt); checkBlock2 = CreateAndInsertBasicBlock(BBJ_COND, checkBlock); - assert(nullCheck->GetNode()->OperIs(GT_EQ)); - GenTree* nullJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, nullCheck->GetNode()); + assert(nullCheck->GetEarlyNode()->OperIs(GT_EQ)); + GenTree* nullJmpTree = compiler->gtNewOperNode(GT_JTRUE, TYP_VOID, nullCheck->GetEarlyNode()); Statement* nullJmpStmt = compiler->fgNewStmtFromTree(nullJmpTree, stmt->GetDebugInfo()); compiler->fgInsertStmtAtEnd(checkBlock2, nullJmpStmt); } @@ -1130,7 +1130,7 @@ class IndirectCallTransformer // The first argument is the real first argument for the call now. origCall->gtArgs.Remove(resultHandle); - GenTree* asg = compiler->gtNewTempAssign(resultLclNum, resultHandle->GetNode()); + GenTree* asg = compiler->gtNewTempAssign(resultLclNum, resultHandle->GetEarlyNode()); Statement* asgStmt = compiler->gtNewStmt(asg, stmt->GetDebugInfo()); compiler->fgInsertStmtAtEnd(thenBlock, asgStmt); } diff --git a/src/coreclr/jit/lclmorph.cpp b/src/coreclr/jit/lclmorph.cpp index b63a0631924311..f123e246454167 100644 --- a/src/coreclr/jit/lclmorph.cpp +++ b/src/coreclr/jit/lclmorph.cpp @@ -684,7 +684,7 @@ class LocalAddressVisitor final : public GenTreeVisitor // mark the entire struct as address exposed results in CQ regressions. GenTreeCall* callTree = user->IsCall() ? user->AsCall() : nullptr; bool isThisArg = (callTree != nullptr) && callTree->gtArgs.HasThisPointer() && - (val.Node() == callTree->gtArgs.GetThisArg()->GetNode()); + (val.Node() == callTree->gtArgs.GetThisArg()->GetEarlyNode()); bool exposeParentLcl = varDsc->lvIsStructField && !isThisArg; bool hasHiddenStructArg = false; @@ -693,7 +693,7 @@ class LocalAddressVisitor final : public GenTreeVisitor if (varTypeIsStruct(varDsc) && varDsc->lvIsTemp) { if ((callTree != nullptr) && callTree->gtArgs.HasRetBuffer() && - (val.Node() == callTree->gtArgs.GetRetBufferArg()->GetNode())) + (val.Node() == callTree->gtArgs.GetRetBufferArg()->GetEarlyNode())) { assert(!exposeParentLcl); diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 8d7d9d46b912b2..1c8afcbebbb916 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1348,7 +1348,7 @@ GenTree* Lowering::NewPutArg(GenTreeCall* call, GenTree* arg, CallArg* callArg, // void Lowering::LowerArg(GenTreeCall* call, CallArg* callArg, bool late) { - GenTree** ppArg = late ? &callArg->LateNodeRef() : &callArg->NodeRef(); + GenTree** ppArg = late ? &callArg->LateNodeRef() : &callArg->EarlyNodeRef(); GenTree* arg = *ppArg; assert(arg != nullptr); @@ -1804,12 +1804,12 @@ void Lowering::InsertProfTailCallHook(GenTreeCall* call, GenTree* insertionPoint { for (CallArg& arg : call->gtArgs.Args()) { - assert(!arg.GetNode()->OperIs(GT_PUTARG_REG)); // We don't expect to see these in gtCallArgs + assert(!arg.GetEarlyNode()->OperIs(GT_PUTARG_REG)); // We don't expect to see these in gtCallArgs - if (arg.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetEarlyNode()->OperIs(GT_PUTARG_STK)) { // found it - insertionPoint = arg.GetNode(); + insertionPoint = arg.GetEarlyNode(); break; } } @@ -1913,9 +1913,9 @@ void Lowering::LowerFastTailCall(GenTreeCall* call) for (CallArg& arg : call->gtArgs.Args()) { - if (arg.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetEarlyNode()->OperIs(GT_PUTARG_STK)) { - putargs.Push(arg.GetNode()); + putargs.Push(arg.GetEarlyNode()); } } @@ -2227,7 +2227,7 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar // arg 0 == callTarget. CallArg* argEntry = call->gtArgs.GetArgByIndex(numArgs - 1); assert(argEntry != nullptr); - GenTree* arg0 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); + GenTree* arg0 = argEntry->GetEarlyNode()->AsPutArgStk()->gtGetOp1(); ContainCheckRange(callTargetRange); BlockRange().InsertAfter(arg0, std::move(callTargetRange)); @@ -2237,12 +2237,12 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar assert(isClosed); BlockRange().Remove(std::move(secondArgRange)); - argEntry->GetNode()->AsPutArgStk()->gtOp1 = callTarget; + argEntry->GetEarlyNode()->AsPutArgStk()->gtOp1 = callTarget; // arg 1 == flags argEntry = call->gtArgs.GetArgByIndex(numArgs - 2); assert(argEntry != nullptr); - GenTree* arg1 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); + GenTree* arg1 = argEntry->GetEarlyNode()->AsPutArgStk()->gtGetOp1(); assert(arg1->gtOper == GT_CNS_INT); ssize_t tailCallHelperFlags = 1 | // always restore EDI,ESI,EBX @@ -2252,7 +2252,7 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar // arg 2 == numberOfNewStackArgsWords argEntry = call->gtArgs.GetArgByIndex(numArgs - 3); assert(argEntry != nullptr); - GenTree* arg2 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); + GenTree* arg2 = argEntry->GetEarlyNode()->AsPutArgStk()->gtGetOp1(); assert(arg2->gtOper == GT_CNS_INT); arg2->AsIntCon()->gtIconVal = nNewStkArgsWords; @@ -2261,7 +2261,7 @@ GenTree* Lowering::LowerTailCallViaJitHelper(GenTreeCall* call, GenTree* callTar // arg 3 == numberOfOldStackArgsWords argEntry = call->gtArgs.GetArgByIndex(numArgs - 4); assert(argEntry != nullptr); - GenTree* arg3 = argEntry->GetNode()->AsPutArgStk()->gtGetOp1(); + GenTree* arg3 = argEntry->GetEarlyNode()->AsPutArgStk()->gtGetOp1(); assert(arg3->gtOper == GT_CNS_INT); #endif // DEBUG @@ -2385,7 +2385,7 @@ void Lowering::LowerCFGCall(GenTreeCall* call) // Finally move all GT_PUTARG_* nodes for (CallArg& arg : call->gtArgs.Args()) { - GenTree* node = arg.GetNode(); + GenTree* node = arg.GetEarlyNode(); // Non-value nodes in early args are setup nodes for late args. if (node->IsValue()) { @@ -6455,7 +6455,7 @@ void Lowering::CheckCall(GenTreeCall* call) { for (CallArg& arg : call->gtArgs.Args()) { - CheckCallArg(arg.GetNode()); + CheckCallArg(arg.GetEarlyNode()); } for (LateArg arg : call->gtArgs.LateArgs()) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 0c790562ec886e..39efed9f2c093e 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -4539,9 +4539,9 @@ void Lowering::ContainCheckCallOperands(GenTreeCall* call) for (CallArg& arg : call->gtArgs.Args()) { - if (arg.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetEarlyNode()->OperIs(GT_PUTARG_STK)) { - LowerPutArgStk(arg.GetNode()->AsPutArgStk()); + LowerPutArgStk(arg.GetEarlyNode()->AsPutArgStk()); } } diff --git a/src/coreclr/jit/lsraarmarch.cpp b/src/coreclr/jit/lsraarmarch.cpp index 92d777cc6e667e..ac20af28d5e7b7 100644 --- a/src/coreclr/jit/lsraarmarch.cpp +++ b/src/coreclr/jit/lsraarmarch.cpp @@ -336,7 +336,7 @@ int LinearScan::BuildCall(GenTreeCall* call) for (CallArg& arg : call->gtArgs.Args()) { - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetEarlyNode(); // Skip arguments that have been moved to the Late Arg list if ((argNode->gtFlags & GTF_LATE_ARG) == 0) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index b4159ff0f93294..fb47fab6d6cae0 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -120,7 +120,7 @@ GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTree* arg for (CallArg& arg : tree->AsCall()->gtArgs.Args()) { - tree->gtFlags |= (arg.GetNode()->gtFlags & GTF_ALL_EFFECT); + tree->gtFlags |= (arg.GetEarlyNode()->gtFlags & GTF_ALL_EFFECT); } // Perform the morphing @@ -615,7 +615,7 @@ const char* getWellKnownArgName(WellKnownArg arg) void CallArg::Dump(Compiler* comp) { printf("CallArg[arg %u", AbiInfo.ArgNum); - printf(" [%06u].%s", comp->dspTreeID(GetArgNode()), GenTree::OpName(GetNode()->OperGet())); + printf(" [%06u].%s", comp->dspTreeID(GetArgNode()), GenTree::OpName(GetEarlyNode()->OperGet())); printf(" %s", varTypeName(AbiInfo.ArgType)); printf(" (%s)", AbiInfo.PassedByRef ? "By ref" : "By value"); if (AbiInfo.GetRegNum() != REG_STK) @@ -725,7 +725,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) for (CallArg& arg : Args()) { - GenTree* argx = arg.GetNode(); + GenTree* argx = arg.GetEarlyNode(); if (arg.AbiInfo.GetRegNum() == REG_STK) { @@ -789,7 +789,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) break; } - if (!prevArg.GetNode()->IsInvariant()) + if (!prevArg.GetEarlyNode()->IsInvariant()) { SetNeedsTemp(&prevArg); } @@ -854,7 +854,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) // For all previous arguments, if they have any GTF_ALL_EFFECT // we require that they be evaluated into a temp - if ((prevArg.GetNode()->gtFlags & GTF_ALL_EFFECT) != 0) + if ((prevArg.GetEarlyNode()->gtFlags & GTF_ALL_EFFECT) != 0) { SetNeedsTemp(&prevArg); } @@ -997,7 +997,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) { for (CallArg& arg : Args()) { - GenTree* argx = arg.GetNode(); + GenTree* argx = arg.GetEarlyNode(); // Examine the register args that are currently not marked needTmp // @@ -1061,7 +1061,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) for (CallArg& arg : Args()) { - if ((arg.GetNode()->gtFlags & GTF_ALL_EFFECT) != 0) + if ((arg.GetEarlyNode()->gtFlags & GTF_ALL_EFFECT) != 0) { SetNeedsTemp(&arg); } @@ -1144,7 +1144,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (!arg->m_processed) { - GenTree* argx = arg->GetNode(); + GenTree* argx = arg->GetEarlyNode(); // put constants at the end of the table // @@ -1181,7 +1181,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (!arg->m_processed) { - GenTree* argx = arg->GetNode(); + GenTree* argx = arg->GetEarlyNode(); // put calls at the beginning of the table // @@ -1257,7 +1257,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (!arg->m_processed) { - GenTree* argx = arg->GetNode(); + GenTree* argx = arg->GetEarlyNode(); if ((argx->gtOper == GT_LCL_VAR) || (argx->gtOper == GT_LCL_FLD)) { @@ -1301,7 +1301,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (!arg->m_processed) { - GenTree* argx = arg->GetNode(); + GenTree* argx = arg->GetEarlyNode(); // We should have already handled these kinds of args assert(argx->gtOper != GT_LCL_VAR); @@ -1508,7 +1508,7 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) CallArg& arg = *lateArg.GetArg(); assert(arg.GetLateNode() == nullptr); - GenTree* argx = arg.GetNode(); + GenTree* argx = arg.GetEarlyNode(); GenTree* setupArg = nullptr; GenTree* defArg; @@ -1732,8 +1732,8 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) if (setupArg != nullptr) { - noway_assert(arg.GetNode() == argx); - arg.SetNode(setupArg); + noway_assert(arg.GetEarlyNode() == argx); + arg.SetEarlyNode(setupArg); } arg.SetLateNode(defArg); @@ -1922,13 +1922,13 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) assert(thisArg != nullptr); GenTree* cloned; - if (thisArg->GetNode()->OperIsLocal()) + if (thisArg->GetEarlyNode()->OperIsLocal()) { - cloned = comp->gtClone(thisArg->GetNode(), true); + cloned = comp->gtClone(thisArg->GetEarlyNode(), true); } else { - cloned = comp->fgInsertCommaFormTemp(&thisArg->NodeRef()); + cloned = comp->fgInsertCommaFormTemp(&thisArg->EarlyNodeRef()); call->gtFlags |= GTF_ASG; } noway_assert(cloned != nullptr); @@ -2051,9 +2051,9 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) if (call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) { - noway_assert(call->gtArgs.GetArgByIndex(0)->GetNode()->TypeGet() == TYP_I_IMPL || - call->gtArgs.GetArgByIndex(0)->GetNode()->TypeGet() == TYP_BYREF || - call->gtArgs.GetArgByIndex(0)->GetNode()->gtOper == + noway_assert(call->gtArgs.GetArgByIndex(0)->GetEarlyNode()->TypeGet() == TYP_I_IMPL || + call->gtArgs.GetArgByIndex(0)->GetEarlyNode()->TypeGet() == TYP_BYREF || + call->gtArgs.GetArgByIndex(0)->GetEarlyNode()->gtOper == GT_NOP); // the arg was already morphed to a register (fgMorph called twice) maxRegArgs = 1; } @@ -2154,7 +2154,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) const CorInfoType corType = strip(comp->info.compCompHnd->getArgType(sig, sigArg, &argClass)); const var_types sigType = JITtype2varType(corType); - const GenTree* nodeArg = arg.GetNode(); + const GenTree* nodeArg = arg.GetEarlyNode(); assert(nodeArg != nullptr); const var_types nodeType = nodeArg->TypeGet(); @@ -2169,7 +2169,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) for (CallArg& arg : Args()) { - GenTree* argx = arg.GetNode()->gtSkipPutArgType(); + GenTree* argx = arg.GetEarlyNode()->gtSkipPutArgType(); // Change the node to TYP_I_IMPL so we don't report GC info // NOTE: We deferred this from the importer because of the inliner. @@ -2387,7 +2387,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) if (isStructArg) { - assert(argx == arg.GetNode()); + assert(argx == arg.GetEarlyNode()); assert(structSize != 0); Compiler::structPassingKind howToPassStruct; @@ -2423,8 +2423,8 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) } } - const var_types argType = arg.GetNode()->TypeGet(); - if (arg.GetNode()->OperIs(GT_PUTARG_TYPE)) + const var_types argType = arg.GetEarlyNode()->TypeGet(); + if (arg.GetEarlyNode()->OperIs(GT_PUTARG_TYPE)) { byteSize = genTypeSize(argType); } @@ -2933,7 +2933,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) bool hasMultiregStructArgs = false; for (CallArg& arg : call->gtArgs.Args()) { - GenTree** parentArgx = &arg.NodeRef(); + GenTree** parentArgx = &arg.EarlyNodeRef(); // Morph the arg node, and update the parent and argEntry pointers. GenTree* argx = *parentArgx; @@ -3298,7 +3298,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) GenTree* asg = gtNewOperNode(GT_COMMA, TYP_VOID, asgPtrSlot, asgTypeSlot); // Change the expression to "(tmp=val)" - arg.SetNode(asg); + arg.SetEarlyNode(asg); call->gtArgs.SetTemp(&arg, tmp); lvaSetVarAddrExposed(tmp DEBUGARG(AddressExposedReason::TOO_CONSERVATIVE)); @@ -3339,7 +3339,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) GenTreeLclVarCommon* lcl = lclNode->AsLclVarCommon(); LclVarDsc* varDsc = lvaGetDesc(lcl); GenTreeFieldList* fieldList = new (this, GT_FIELD_LIST) GenTreeFieldList(); - arg.SetNode(fieldList); + arg.SetEarlyNode(fieldList); for (unsigned fieldLclNum = varDsc->lvFieldLclStart; fieldLclNum < varDsc->lvFieldLclStart + varDsc->lvFieldCnt; ++fieldLclNum) @@ -3365,7 +3365,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) } #endif // TARGET_X86 - flagsSummary |= arg.GetNode()->gtFlags; + flagsSummary |= arg.GetEarlyNode()->gtFlags; } // end foreach argument loop @@ -3460,7 +3460,7 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) for (CallArg& arg : call->gtArgs.Args()) { - bool isLateArg = (arg.GetNode()->gtFlags & GTF_LATE_ARG) != 0; + bool isLateArg = (arg.GetEarlyNode()->gtFlags & GTF_LATE_ARG) != 0; GenTree* argx = arg.GetArgNode(); if (!arg.AbiInfo.IsStruct) @@ -3515,7 +3515,7 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) } else { - arg.SetNode(newArgx); + arg.SetEarlyNode(newArgx); } } } @@ -4131,7 +4131,7 @@ GenTreeFieldList* Compiler::fgMorphLclArgToFieldlist(GenTreeLclVarCommon* lcl) // void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg, CORINFO_CLASS_HANDLE copyBlkClass) { - GenTree* argx = arg->GetNode(); + GenTree* argx = arg->GetEarlyNode(); noway_assert(argx->gtOper != GT_MKREFANY); // If we're optimizing, see if we can avoid making a copy. @@ -4169,7 +4169,7 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg, CORI ((totalAppearances == 1) && call->IsNoReturn()) || // ((totalAppearances == 1) && !fgMightHaveLoop())) { - arg->SetNode(lcl); + arg->SetEarlyNode(lcl); JITDUMP("did not need to make outgoing copy for last use of implicit byref V%2d\n", varNum); return; } @@ -4257,7 +4257,7 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg, CORI #endif // FEATURE_FIXED_OUT_ARGS - arg->SetNode(argNode); + arg->SetEarlyNode(argNode); } #ifdef TARGET_ARM @@ -6326,12 +6326,12 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) if (varDsc->lvPromoted) { JITDUMP("Arg [%06u] is promoted implicit byref V%02u, so no tail call\n", - dspTreeID(arg.GetNode()), lclNum); + dspTreeID(arg.GetEarlyNode()), lclNum); } else { JITDUMP("Arg [%06u] is unpromoted implicit byref V%02u, seeing if we can still tail call\n", - dspTreeID(arg.GetNode()), lclNum); + dspTreeID(arg.GetEarlyNode()), lclNum); // We have to worry about introducing aliases if we bypass copying // the struct at the call. We'll do some limited analysis to see if we @@ -6792,7 +6792,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) if (call->gtArgs.HasThisPointer()) { - var_types thisArgType = call->gtArgs.GetThisArg()->GetNode()->TypeGet(); + var_types thisArgType = call->gtArgs.GetThisArg()->GetEarlyNode()->TypeGet(); if (thisArgType != TYP_REF) { flags |= CORINFO_TAILCALL_THIS_ARG_IS_BYREF; @@ -6866,7 +6866,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) call->ClearExpandedEarly(); } else if ((tailCallResult == TAILCALL_OPTIMIZED) && - ((call->gtArgs.GetThisArg()->GetNode()->gtFlags & GTF_SIDE_EFFECT) != 0)) + ((call->gtArgs.GetThisArg()->GetEarlyNode()->gtFlags & GTF_SIDE_EFFECT) != 0)) { // We generate better code when we expand this late in lower instead. // @@ -7556,7 +7556,7 @@ GenTree* Compiler::fgCreateCallDispatcherAndGetResult(GenTreeCall* orig if (origCall->gtArgs.HasRetBuffer()) { JITDUMP("Transferring retbuf\n"); - GenTree* retBufArg = origCall->gtArgs.GetRetBufferArg()->GetNode(); + GenTree* retBufArg = origCall->gtArgs.GetRetBufferArg()->GetEarlyNode(); assert(info.compRetBuffArg != BAD_VAR_NUM); assert(retBufArg->OperIsLocal()); @@ -7939,7 +7939,7 @@ void Compiler::fgMorphTailCallViaJitHelper(GenTreeCall* call) if (thisArg != nullptr) { GenTree* thisPtr = nullptr; - GenTree* objp = thisArg->GetNode(); + GenTree* objp = thisArg->GetEarlyNode(); if ((call->IsDelegateInvoke() || call->IsVirtualVtable()) && !objp->OperIs(GT_LCL_VAR)) { @@ -8169,7 +8169,7 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa // below has the correct second argument. for (CallArg& arg : recursiveTailCall->gtArgs.Args()) { - GenTree* earlyArg = arg.GetNode(); + GenTree* earlyArg = arg.GetEarlyNode(); if (!earlyArg->IsNothingNode() && !earlyArg->IsArgPlaceHolderNode()) { if ((earlyArg->gtFlags & GTF_LATE_ARG) != 0) @@ -8589,7 +8589,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) GenTreeOp* argSetup = nullptr; for (CallArg& arg : call->gtArgs.Args()) { - GenTree* const argNode = arg.GetNode(); + GenTree* const argNode = arg.GetEarlyNode(); if (argNode->OperGet() != GT_ASG) { continue; diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 1308539a3ebc0c..9caaf0236289d3 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -9793,7 +9793,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN { generateUniqueVN = true; // TODO-ARGS: Should this really be early arg? - ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetArgByIndex(1)->GetNode()->gtVNPair); + ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetArgByIndex(1)->GetEarlyNode()->gtVNPair); // The New Array helper may throw an overflow exception vnpExc = vnStore->VNPExcSetSingleton(vnStore->VNPairForFunc(TYP_REF, VNF_NewArrOverflowExc, vnp1)); @@ -9830,7 +9830,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_JitReadyToRunNewArr: { generateUniqueVN = true; - ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetArgByIndex(0)->GetNode()->gtVNPair); + ValueNumPair vnp1 = vnStore->VNPNormalPair(args->GetArgByIndex(0)->GetEarlyNode()->gtVNPair); // The New Array helper may throw an overflow exception vnpExc = vnStore->VNPExcSetSingleton(vnStore->VNPairForFunc(TYP_REF, VNF_NewArrOverflowExc, vnp1)); @@ -9871,7 +9871,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN if (call->IsR2RRelativeIndir()) { #ifdef DEBUG - assert(args->GetArgByIndex(0)->GetNode()->OperGet() == GT_ARGPLACE); + assert(args->GetArgByIndex(0)->GetEarlyNode()->OperGet() == GT_ARGPLACE); // Find the corresponding late arg. GenTree* indirectCellAddress = args->GetArgByIndex(0)->GetArgNode(); @@ -9988,17 +9988,17 @@ void Compiler::fgValueNumberCall(GenTreeCall* call) for (LateArg lateArg : call->gtArgs.LateArgs()) { CallArg* arg = lateArg.GetArg(); - if (arg->GetNode()->OperIs(GT_ARGPLACE)) + if (arg->GetEarlyNode()->OperIs(GT_ARGPLACE)) { assert(lateArg.GetNode()->gtVNPair.BothDefined()); - arg->GetNode()->gtVNPair = lateArg.GetNode()->gtVNPair; + arg->GetEarlyNode()->gtVNPair = lateArg.GetNode()->gtVNPair; #ifdef DEBUG if (verbose) { printf("VN of ARGPLACE tree "); - Compiler::printTreeID(arg->GetNode()); + Compiler::printTreeID(arg->GetEarlyNode()); printf(" updated to "); - vnpPrint(arg->GetNode()->gtVNPair, 1); + vnpPrint(arg->GetEarlyNode()->gtVNPair, 1); printf("\n"); } #endif From 0fa91b95a1085fec49fc2b663ff2a1c4de4d29b5 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 30 Mar 2022 12:30:07 +0200 Subject: [PATCH 28/52] Remove LateArg --- src/coreclr/jit/codegenarmarch.cpp | 6 +- src/coreclr/jit/codegenxarch.cpp | 6 +- src/coreclr/jit/compiler.h | 4 +- src/coreclr/jit/compiler.hpp | 4 +- src/coreclr/jit/flowgraph.cpp | 4 +- src/coreclr/jit/gentree.cpp | 54 +++++++++--------- src/coreclr/jit/gentree.h | 88 +++--------------------------- src/coreclr/jit/gschecks.cpp | 4 +- src/coreclr/jit/lower.cpp | 24 ++++---- src/coreclr/jit/lowerxarch.cpp | 6 +- src/coreclr/jit/lsraarmarch.cpp | 6 +- src/coreclr/jit/lsraxarch.cpp | 10 ++-- src/coreclr/jit/morph.cpp | 25 ++++----- src/coreclr/jit/valuenum.cpp | 13 ++--- 14 files changed, 91 insertions(+), 163 deletions(-) diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index bf1a4308b71ce8..b26f8b9199ed44 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -3120,10 +3120,10 @@ void CodeGen::genCodeForInitBlkHelper(GenTreeBlk* initBlkNode) void CodeGen::genCall(GenTreeCall* call) { // Consume all the arg regs - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + CallArgABIInformation& abiInfo = arg.AbiInfo; + GenTree* argNode = arg.GetLateNode(); // GT_RELOAD/GT_COPY use the child node argNode = argNode->gtSkipReloadOrCopy(); diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 86c22ab91379f6..0d12b74b8aab84 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -5322,10 +5322,10 @@ void CodeGen::genCall(GenTreeCall* call) } // Consume all the arg regs - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + CallArgABIInformation& abiInfo = arg.AbiInfo; + GenTree* argNode = arg.GetLateNode(); if (abiInfo.GetRegNum() == REG_STK) { diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index c5bcd08bd621eb..15fd4aa74a44ee 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -10881,9 +10881,9 @@ class GenTreeVisitor } } - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - result = WalkTree(&arg.NodeRef(), call); + result = WalkTree(&arg.LateNodeRef(), call); if (result == fgWalkResult::WALK_ABORT) { return result; diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index b0ce1e36121ace..31f13fdfc30af5 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -4381,9 +4381,9 @@ void GenTree::VisitOperands(TVisitor visitor) } } - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - if (visitor(arg.GetNode()) == VisitResult::Abort) + if (visitor(arg.GetLateNode()) == VisitResult::Abort) { return; } diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index f9df518a196eaf..ef7c2050bc6c2a 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -3974,9 +3974,9 @@ void Compiler::fgSetTreeSeqHelper(GenTree* tree, bool isLIR) fgSetTreeSeqHelper(arg.GetEarlyNode(), isLIR); } - for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) + for (CallArg& arg : tree->AsCall()->gtArgs.LateArgs()) { - fgSetTreeSeqHelper(arg.GetNode(), isLIR); + fgSetTreeSeqHelper(arg.GetLateNode(), isLIR); } if ((tree->AsCall()->gtCallType == CT_INDIRECT) && (tree->AsCall()->gtCallCookie != nullptr)) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index b934fbf76e74fa..07d750a70d7531 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1891,10 +1891,10 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) } { - auto i1 = c1->gtArgs.Args().begin(); - auto end1 = c1->gtArgs.Args().end(); - auto i2 = c2->gtArgs.Args().begin(); - auto end2 = c2->gtArgs.Args().end(); + CallArgs::ArgIterator i1 = c1->gtArgs.Args().begin(); + CallArgs::ArgIterator end1 = c1->gtArgs.Args().end(); + CallArgs::ArgIterator i2 = c2->gtArgs.Args().begin(); + CallArgs::ArgIterator end2 = c2->gtArgs.Args().end(); for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) { @@ -1911,14 +1911,14 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) } { - auto i1 = c1->gtArgs.LateArgs().begin(); - auto end1 = c1->gtArgs.LateArgs().end(); - auto i2 = c2->gtArgs.LateArgs().begin(); - auto end2 = c2->gtArgs.LateArgs().end(); + CallArgs::LateArgIterator i1 = c1->gtArgs.LateArgs().begin(); + CallArgs::LateArgIterator end1 = c1->gtArgs.LateArgs().end(); + CallArgs::LateArgIterator i2 = c2->gtArgs.LateArgs().begin(); + CallArgs::LateArgIterator end2 = c2->gtArgs.LateArgs().end(); for (; (i1 != end1) && (i2 != end2); ++i1, ++i2) { - if (!Compare(i1.GetNode(), i2.GetNode())) + if (!Compare(i1->GetLateNode(), i2->GetLateNode())) { return false; } @@ -2751,9 +2751,9 @@ unsigned Compiler::gtHashValue(GenTree* tree) hash = genTreeHashAdd(hash, tree->AsCall()->gtCallMethHnd); } - for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) + for (CallArg& arg : tree->AsCall()->gtArgs.LateArgs()) { - hash = genTreeHashAdd(hash, gtHashValue(arg.GetNode())); + hash = genTreeHashAdd(hash, gtHashValue(arg.GetLateNode())); } break; @@ -3095,29 +3095,29 @@ unsigned Compiler::gtSetCallArgsOrder(CallArgs* args, bool lateArgs, int* callCo if (lateArgs) { - for (LateArg arg : args->LateArgs()) + for (CallArg& arg : args->LateArgs()) { - GenTree* argNode = arg.GetNode(); - unsigned argLevel = gtSetEvalOrder(argNode); - update(argNode, argLevel); + GenTree* node = arg.GetLateNode(); + unsigned level = gtSetEvalOrder(node); + update(node, level); } } else { for (CallArg& arg : args->Args()) { - GenTree* argNode = arg.GetEarlyNode(); - unsigned argLevel = gtSetEvalOrder(argNode); + GenTree* node = arg.GetEarlyNode(); + unsigned level = gtSetEvalOrder(node); if (arg.GetWellKnownArg() == WellKnownArg::ThisPointer) { // TODO-ARGS: Quirk to match old costs assigned to 'this' - costEx += argNode->GetCostEx(); - costSz += argNode->GetCostSz() + 1; + costEx += node->GetCostEx(); + costSz += node->GetCostSz() + 1; } else { - update(argNode, argLevel); + update(node, level); } } } @@ -8361,11 +8361,11 @@ void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc co // Now copy late pointers. Note that these may not come in order. tail = &m_lateHead; - for (LateArg arg : other->LateArgs()) + for (CallArg& arg : other->LateArgs()) { CallArg* it = m_head; CallArg* otherIt = other->m_head; - while (otherIt != arg.GetArg()) + while (otherIt != &arg) { assert(it != nullptr && otherIt != nullptr); it = it->m_next; @@ -9224,7 +9224,7 @@ void GenTreeUseEdgeIterator::AdvanceCall() m_statePtr = arg->GetNext(); return; } - m_statePtr = call->gtArgs.LateArgs().begin().GetArg(); + m_statePtr = &*call->gtArgs.LateArgs().begin(); m_advance = &GenTreeUseEdgeIterator::AdvanceCall; FALLTHROUGH; @@ -11548,11 +11548,11 @@ void Compiler::gtDispTree(GenTree* tree, (call->gtControlExpr == lastChild) ? IIArcBottom : IIArc, "control expr", topOnly); } - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - IndentInfo arcType = (arg.GetArg()->GetLateNext() == nullptr) ? IIArcBottom : IIArc; - gtGetLateArgMsg(call, arg.GetArg(), buf, sizeof(buf)); - gtDispChild(arg.GetNode(), indentStack, arcType, buf, topOnly); + IndentInfo arcType = (arg.GetLateNext() == nullptr) ? IIArcBottom : IIArc; + gtGetLateArgMsg(call, &arg, buf, sizeof(buf)); + gtDispChild(arg.GetLateNode(), indentStack, arcType, buf, topOnly); } } } diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 12264783c4b179..47e902f593b920 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4310,34 +4310,6 @@ class CallArg #endif }; -// Used in iterator to avoid pitfall with accessing early arg when iterating -// late args. -class LateArg -{ - CallArg* m_arg; - -public: - explicit LateArg(CallArg* arg) : m_arg(arg) - { - } - CallArg* GetArg() - { - return m_arg; - } - GenTree* GetNode() - { - return m_arg->GetLateNode(); - } - void SetNode(GenTree* node) - { - m_arg->SetLateNode(node); - } - GenTree*& NodeRef() - { - return m_arg->LateNodeRef(); - } -}; - class CallArgs { CallArg* m_head; @@ -4458,6 +4430,7 @@ class CallArgs unsigned CountArgs(); + template class CallArgIterator { CallArg* m_arg; @@ -4484,7 +4457,7 @@ class CallArgs CallArgIterator& operator++() { - m_arg = m_arg->GetNext(); + m_arg = (m_arg->*Next)(); return *this; } @@ -4499,60 +4472,17 @@ class CallArgs } }; - IteratorPair Args() - { - return IteratorPair(CallArgIterator(m_head), CallArgIterator(nullptr)); - } + using ArgIterator = CallArgIterator<&CallArg::GetNext>; + using LateArgIterator = CallArgIterator<&CallArg::GetLateNext>; - class LateArgsIterator + IteratorPair Args() { - CallArg* m_arg; - - public: - explicit LateArgsIterator(CallArg* arg) : m_arg(arg) - { - } - - LateArg operator*() const - { - return LateArg(m_arg); - } - - CallArg* GetArg() const - { - return m_arg; - } - - GenTree* GetNode() const - { - return m_arg->GetLateNode(); - } - - GenTree*& NodeRef() - { - return m_arg->LateNodeRef(); - } - - LateArgsIterator& operator++() - { - m_arg = m_arg->GetLateNext(); - return *this; - } - - bool operator==(const LateArgsIterator& i) const - { - return m_arg == i.m_arg; - } - - bool operator!=(const LateArgsIterator& i) const - { - return m_arg != i.m_arg; - } - }; + return IteratorPair(ArgIterator(m_head), ArgIterator(nullptr)); + } - IteratorPair LateArgs() + IteratorPair LateArgs() { - return IteratorPair(LateArgsIterator(m_lateHead), LateArgsIterator(nullptr)); + return IteratorPair(LateArgIterator(m_lateHead), LateArgIterator(nullptr)); } }; diff --git a/src/coreclr/jit/gschecks.cpp b/src/coreclr/jit/gschecks.cpp index dc8eadbde95313..7bff614acce17e 100644 --- a/src/coreclr/jit/gschecks.cpp +++ b/src/coreclr/jit/gschecks.cpp @@ -198,9 +198,9 @@ Compiler::fgWalkResult Compiler::gsMarkPtrsAndAssignGroups(GenTree** pTree, fgWa comp->fgWalkTreePre(&arg.EarlyNodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); } - for (LateArg arg : tree->AsCall()->gtArgs.LateArgs()) + for (CallArg& arg : tree->AsCall()->gtArgs.LateArgs()) { - comp->fgWalkTreePre(&arg.NodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); + comp->fgWalkTreePre(&arg.LateNodeRef(), gsMarkPtrsAndAssignGroups, (void*)&newState); } if (tree->AsCall()->gtCallType == CT_INDIRECT) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 1c8afcbebbb916..27d1c9b5dd8fb2 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1594,9 +1594,9 @@ void Lowering::LowerArgsForCall(GenTreeCall* call) } JITDUMP("\nlate:\n======\n"); - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - LowerArg(call, arg.GetArg(), true); + LowerArg(call, &arg, true); } } @@ -1816,12 +1816,12 @@ void Lowering::InsertProfTailCallHook(GenTreeCall* call, GenTree* insertionPoint if (insertionPoint == nullptr) { - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - if (arg.GetNode()->OperIs(GT_PUTARG_REG, GT_PUTARG_STK)) + if (arg.GetLateNode()->OperIs(GT_PUTARG_REG, GT_PUTARG_STK)) { // found it - insertionPoint = arg.GetNode(); + insertionPoint = arg.GetLateNode(); break; } } @@ -1919,11 +1919,11 @@ void Lowering::LowerFastTailCall(GenTreeCall* call) } } - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - if (arg.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetLateNode()->OperIs(GT_PUTARG_STK)) { - putargs.Push(arg.GetNode()); + putargs.Push(arg.GetLateNode()); } } @@ -2394,9 +2394,9 @@ void Lowering::LowerCFGCall(GenTreeCall* call) } } - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - GenTree* node = arg.GetNode(); + GenTree* node = arg.GetLateNode(); assert(node->OperIsPutArg() || node->OperIsFieldList()); MoveCFGCallArg(call, node); } @@ -6458,9 +6458,9 @@ void Lowering::CheckCall(GenTreeCall* call) CheckCallArg(arg.GetEarlyNode()); } - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - CheckCallArg(arg.GetNode()); + CheckCallArg(arg.GetLateNode()); } } diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 39efed9f2c093e..924dc74288ac18 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -4545,11 +4545,11 @@ void Lowering::ContainCheckCallOperands(GenTreeCall* call) } } - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - if (arg.GetNode()->OperIs(GT_PUTARG_STK)) + if (arg.GetLateNode()->OperIs(GT_PUTARG_STK)) { - LowerPutArgStk(arg.GetNode()->AsPutArgStk()); + LowerPutArgStk(arg.GetLateNode()->AsPutArgStk()); } } } diff --git a/src/coreclr/jit/lsraarmarch.cpp b/src/coreclr/jit/lsraarmarch.cpp index ac20af28d5e7b7..0abcf59287978e 100644 --- a/src/coreclr/jit/lsraarmarch.cpp +++ b/src/coreclr/jit/lsraarmarch.cpp @@ -247,10 +247,10 @@ int LinearScan::BuildCall(GenTreeCall* call) // Each register argument corresponds to one source. bool callHasFloatRegArgs = false; - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + CallArgABIInformation& abiInfo = arg.AbiInfo; + GenTree* argNode = arg.GetLateNode(); #ifdef DEBUG regNumber argReg = abiInfo.GetRegNum(); diff --git a/src/coreclr/jit/lsraxarch.cpp b/src/coreclr/jit/lsraxarch.cpp index b3c624fc5ced2d..80c38af89e2de0 100644 --- a/src/coreclr/jit/lsraxarch.cpp +++ b/src/coreclr/jit/lsraxarch.cpp @@ -1092,9 +1092,9 @@ int LinearScan::BuildCall(GenTreeCall* call) // First, determine internal registers. // We will need one for any float arguments to a varArgs call. - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - GenTree* argNode = arg.GetNode(); + GenTree* argNode = arg.GetLateNode(); if (argNode->OperIsPutArgReg()) { HandleFloatVarArgs(call, argNode, &callHasFloatRegArgs); @@ -1110,7 +1110,7 @@ int LinearScan::BuildCall(GenTreeCall* call) } // Now, count reg args - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { // By this point, lowering has ensured that all call arguments are one of the following: // - an arg setup store @@ -1121,8 +1121,8 @@ int LinearScan::BuildCall(GenTreeCall* call) // - a put arg // // Note that this property is statically checked by LinearScan::CheckBlock. - CallArgABIInformation& abiInfo = arg.GetArg()->AbiInfo; - GenTree* argNode = arg.GetNode(); + CallArgABIInformation& abiInfo = arg.AbiInfo; + GenTree* argNode = arg.GetLateNode(); // Each register argument corresponds to one source. if (argNode->OperIsPutArgReg()) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index fb47fab6d6cae0..c2d35837c11183 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -1503,9 +1503,8 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) unsigned regArgInx = 0; // Now go through the argument table and perform the necessary evaluation into temps. // SortArgs stored the sorted result in the late list. - for (LateArg lateArg : LateArgs()) + for (CallArg& arg : LateArgs()) { - CallArg& arg = *lateArg.GetArg(); assert(arg.GetLateNode() == nullptr); GenTree* argx = arg.GetEarlyNode(); @@ -1758,11 +1757,11 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) if (comp->verbose) { printf("\nShuffled argument table: "); - for (LateArg arg : LateArgs()) + for (CallArg& arg : LateArgs()) { - if (arg.GetArg()->AbiInfo.GetRegNum() != REG_STK) + if (arg.AbiInfo.GetRegNum() != REG_STK) { - printf("%s ", getRegName(arg.GetArg()->AbiInfo.GetRegNum())); + printf("%s ", getRegName(arg.AbiInfo.GetRegNum())); } } printf("\n"); @@ -2916,10 +2915,10 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) // If we are remorphing, process the late arguments (which were determined by a previous caller). if (reMorphing) { - for (LateArg arg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - arg.SetNode(fgMorphTree(arg.GetNode())); - flagsSummary |= arg.GetNode()->gtFlags; + arg.SetLateNode(fgMorphTree(arg.GetLateNode())); + flagsSummary |= arg.GetLateNode()->gtFlags; } } @@ -8200,16 +8199,16 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa } // Process late args. - for (LateArg arg : recursiveTailCall->gtArgs.LateArgs()) + for (CallArg& arg : recursiveTailCall->gtArgs.LateArgs()) { // A late argument is an actual argument that needs to be assigned to the corresponding caller's parameter. - GenTree* lateArg = arg.GetNode(); + GenTree* lateArg = arg.GetLateNode(); // Late-added non-standard args are extra args that are not passed as locals, so skip those - if (!arg.GetArg()->IsArgAddedLate()) + if (!arg.IsArgAddedLate()) { Statement* paramAssignStmt = - fgAssignRecursiveCallArgToCallerParam(lateArg, arg.GetArg(), - fgGetArgParameterLclNum(recursiveTailCall, arg.GetArg()), block, + fgAssignRecursiveCallArgToCallerParam(lateArg, &arg, + fgGetArgParameterLclNum(recursiveTailCall, &arg), block, callDI, tmpAssignmentInsertionPoint, paramAssignmentInsertionPoint); diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 9caaf0236289d3..8dec997d4ff1d2 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -9985,20 +9985,19 @@ void Compiler::fgValueNumberCall(GenTreeCall* call) // First: do value numbering of any argument placeholder nodes in the argument list // (by transferring from the VN of the late arg that they are standing in for...) - for (LateArg lateArg : call->gtArgs.LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - CallArg* arg = lateArg.GetArg(); - if (arg->GetEarlyNode()->OperIs(GT_ARGPLACE)) + if (arg.GetEarlyNode()->OperIs(GT_ARGPLACE)) { - assert(lateArg.GetNode()->gtVNPair.BothDefined()); - arg->GetEarlyNode()->gtVNPair = lateArg.GetNode()->gtVNPair; + assert(arg.GetLateNode()->gtVNPair.BothDefined()); + arg.GetEarlyNode()->gtVNPair = arg.GetLateNode()->gtVNPair; #ifdef DEBUG if (verbose) { printf("VN of ARGPLACE tree "); - Compiler::printTreeID(arg->GetEarlyNode()); + Compiler::printTreeID(arg.GetEarlyNode()); printf(" updated to "); - vnpPrint(arg->GetEarlyNode()->gtVNPair, 1); + vnpPrint(arg.GetEarlyNode()->gtVNPair, 1); printf("\n"); } #endif From db1902fef0b4f5d1e52f9f89aa03f6cb6e614088 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 30 Mar 2022 12:36:54 +0200 Subject: [PATCH 29/52] Rename CallArg::GetArgNode -> CallArg::GetNode --- src/coreclr/jit/assertionprop.cpp | 12 ++++----- src/coreclr/jit/compiler.cpp | 2 +- src/coreclr/jit/earlyprop.cpp | 4 +-- src/coreclr/jit/gentree.cpp | 20 +++++++-------- src/coreclr/jit/gentree.h | 3 ++- src/coreclr/jit/importer.cpp | 14 +++++----- src/coreclr/jit/lower.cpp | 10 ++++---- src/coreclr/jit/morph.cpp | 38 ++++++++++++++-------------- src/coreclr/jit/stacklevelsetter.cpp | 2 +- src/coreclr/jit/valuenum.cpp | 10 ++++---- 10 files changed, 58 insertions(+), 57 deletions(-) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 0b22ff406345fd..26a8e2c011f822 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -2548,8 +2548,8 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree) (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFCLASS)) || (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ISINSTANCEOFANY))) { - GenTree* objectNode = call->gtArgs.GetArgByIndex(1)->GetArgNode(); - GenTree* methodTableNode = call->gtArgs.GetArgByIndex(0)->GetArgNode(); + GenTree* objectNode = call->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* methodTableNode = call->gtArgs.GetArgByIndex(0)->GetNode(); assert(objectNode->TypeGet() == TYP_REF); assert(methodTableNode->TypeGet() == TYP_I_IMPL); @@ -2696,7 +2696,7 @@ void Compiler::optAssertionGen(GenTree* tree) if (call->NeedsNullCheck() || (call->IsVirtual() && !call->IsTailCall())) { // Retrieve the 'this' arg. - GenTree* thisArg = call->gtArgs.GetThisArg()->GetArgNode(); + GenTree* thisArg = call->gtArgs.GetThisArg()->GetNode(); assert(thisArg != nullptr); assertionInfo = optCreateAssertion(thisArg, nullptr, OAK_NOT_EQUAL); } @@ -4495,7 +4495,7 @@ GenTree* Compiler::optNonNullAssertionProp_Call(ASSERT_VALARG_TP assertions, Gen { return nullptr; } - GenTree* op1 = call->gtArgs.GetThisArg()->GetArgNode(); + GenTree* op1 = call->gtArgs.GetThisArg()->GetNode(); noway_assert(op1 != nullptr); if (op1->gtOper != GT_LCL_VAR) { @@ -4554,13 +4554,13 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTANY) || call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_CHKCASTCLASS_SPECIAL)) { - GenTree* arg1 = call->gtArgs.GetArgByIndex(1)->GetArgNode(); + GenTree* arg1 = call->gtArgs.GetArgByIndex(1)->GetNode(); if (arg1->gtOper != GT_LCL_VAR) { return nullptr; } - GenTree* arg2 = call->gtArgs.GetArgByIndex(0)->GetArgNode(); + GenTree* arg2 = call->gtArgs.GetArgByIndex(0)->GetNode(); unsigned index = optAssertionIsSubtype(arg1, arg2, assertions); if (index != NO_ASSERTION_INDEX) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index fdafbbf38e91be..8c8d3ba8724ca0 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -7455,7 +7455,7 @@ Compiler::NodeToIntMap* Compiler::FindReachableNodesInNodeTestData() unsigned i = 0; for (CallArg& arg : call->gtArgs.Args()) { - GenTree* argNode = arg.GetArgNode(); + GenTree* argNode = arg.GetNode(); if (GetNodeTestData()->Lookup(argNode, &tlAndN)) { reachable->Set(argNode, 0); diff --git a/src/coreclr/jit/earlyprop.cpp b/src/coreclr/jit/earlyprop.cpp index e1401f1d3469a0..39af99358f8a04 100644 --- a/src/coreclr/jit/earlyprop.cpp +++ b/src/coreclr/jit/earlyprop.cpp @@ -58,7 +58,7 @@ GenTree* Compiler::getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBloc call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_NEWARR_1_ALIGN8)) { // This is an array allocation site. Grab the array length node. - arrayLength = call->gtArgs.GetArgByIndex(1)->GetArgNode(); + arrayLength = call->gtArgs.GetArgByIndex(1)->GetNode(); } else if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_READYTORUN_NEWARR_1)) { @@ -67,7 +67,7 @@ GenTree* Compiler::getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBloc // as that's always the length. See DetermineABIArgInformation for where the handle is inserted. for (CallArg& arg : call->gtArgs.Args()) { - arrayLength = arg.GetArgNode(); + arrayLength = arg.GetNode(); } } #ifdef DEBUG diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 07d750a70d7531..93c9ebea973eae 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1204,7 +1204,7 @@ bool CallArg::IsArgAddedLate() const #ifdef DEBUG void CallArg::CheckIsStruct() { - GenTree* node = GetArgNode(); + GenTree* node = GetNode(); if (AbiInfo.IsStruct) { if (!varTypeIsStruct(node) && !node->OperIs(GT_FIELD_LIST)) @@ -1839,7 +1839,7 @@ void GenTreeCall::ReplaceCallOperand(GenTree** useEdge, GenTree* replacement) else { assert((replacement->gtFlags & GTF_LATE_ARG) == 0); - assert(gtArgs.FindByNode(replacement)->GetArgNode() == replacement); + assert(gtArgs.FindByNode(replacement)->GetNode() == replacement); } } } @@ -12570,7 +12570,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) } else { - arg1 = op1->AsCall()->gtArgs.GetThisArg()->GetArgNode(); + arg1 = op1->AsCall()->gtArgs.GetThisArg()->GetNode(); } arg1 = gtNewMethodTableLookup(arg1); @@ -12583,7 +12583,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) } else { - arg2 = op2->AsCall()->gtArgs.GetThisArg()->GetArgNode(); + arg2 = op2->AsCall()->gtArgs.GetThisArg()->GetNode(); } arg2 = gtNewMethodTableLookup(arg2); @@ -12615,7 +12615,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) GenTree* const opOther = (op1Kind == TPK_Handle) ? op2 : op1; // Tunnel through the handle operand to get at the class handle involved. - GenTree* const opHandleArgument = opHandle->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); + GenTree* const opHandleArgument = opHandle->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); CORINFO_CLASS_HANDLE clsHnd = gtGetHelperArgClassHandle(opHandleArgument); // If we couldn't find the class handle, give up. @@ -12650,7 +12650,7 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree) } else { - objOp = opOther->AsCall()->gtArgs.GetThisArg()->GetArgNode(); + objOp = opOther->AsCall()->gtArgs.GetThisArg()->GetNode(); } bool pIsExact = false; @@ -13271,7 +13271,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions return nullptr; } - boxTypeHandle = newobjCall->gtArgs.GetArgByIndex(0)->GetArgNode(); + boxTypeHandle = newobjCall->gtArgs.GetArgByIndex(0)->GetNode(); } else { @@ -17126,7 +17126,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b NamedIntrinsic ni = lookupNamedIntrinsic(call->gtCallMethHnd); if ((ni == NI_System_Array_Clone) || (ni == NI_System_Object_MemberwiseClone)) { - objClass = gtGetClassHandle(call->gtArgs.GetThisArg()->GetArgNode(), pIsExact, pIsNonNull); + objClass = gtGetClassHandle(call->gtArgs.GetThisArg()->GetNode(), pIsExact, pIsNonNull); break; } @@ -17392,7 +17392,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetHelperCallClassHandle(GenTreeCall* call, boo case CORINFO_HELP_ISINSTANCEOFANY: { // Fetch the class handle from the helper call arglist - GenTree* typeArg = call->gtArgs.GetArgByIndex(0)->GetArgNode(); + GenTree* typeArg = call->gtArgs.GetArgByIndex(0)->GetNode(); CORINFO_CLASS_HANDLE castHnd = gtGetHelperArgClassHandle(typeArg); // We generally assume the type being cast to is the best type @@ -17418,7 +17418,7 @@ CORINFO_CLASS_HANDLE Compiler::gtGetHelperCallClassHandle(GenTreeCall* call, boo // type from the value being cast instead. if (castHnd == nullptr) { - GenTree* valueArg = call->gtArgs.GetArgByIndex(1)->GetArgNode(); + GenTree* valueArg = call->gtArgs.GetArgByIndex(1)->GetNode(); castHnd = gtGetClassHandle(valueArg, pIsExact, pIsNonNull); } diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 47e902f593b920..7e1f97abfeeeb6 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4290,7 +4290,8 @@ class CallArg // Get the real argument node, i.e. not a setup or placeholder node. // This is the same as GetEarlyNode() until morph. - GenTree* GetArgNode() + // After lowering, this is a PUTARG_* node. + GenTree* GetNode() { return m_lateNode == nullptr ? m_earlyNode : m_lateNode; } diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 1063c878307b9f..2d85410e68438f 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3301,8 +3301,8 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) } assert(newArrayCall->AsCall()->gtArgs.CountArgs() == 3); - GenTree* numArgsArg = newArrayCall->AsCall()->gtArgs.GetArgByIndex(1)->GetArgNode(); - GenTree* argsArg = newArrayCall->AsCall()->gtArgs.GetArgByIndex(2)->GetArgNode(); + GenTree* numArgsArg = newArrayCall->AsCall()->gtArgs.GetArgByIndex(1)->GetNode(); + GenTree* argsArg = newArrayCall->AsCall()->gtArgs.GetArgByIndex(2)->GetNode(); // // The number of arguments should be a constant between 1 and 64. The rank can't be 0 @@ -3440,13 +3440,13 @@ GenTree* Compiler::impInitializeArrayIntrinsic(CORINFO_SIG_INFO* sig) if (newArrayCall->AsCall()->gtCallMethHnd == eeFindHelper(CORINFO_HELP_READYTORUN_NEWARR_1)) { // Array length is 1st argument for readytorun helper - arrayLengthNode = newArrayCall->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); + arrayLengthNode = newArrayCall->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); } else #endif { // Array length is 2nd argument for regular helper - arrayLengthNode = newArrayCall->AsCall()->gtArgs.GetArgByIndex(1)->GetArgNode(); + arrayLengthNode = newArrayCall->AsCall()->gtArgs.GetArgByIndex(1)->GetNode(); } // @@ -3554,7 +3554,7 @@ GenTree* Compiler::impCreateSpanIntrinsic(CORINFO_SIG_INFO* sig) } // Strip helper call away - fieldTokenNode = fieldTokenNode->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); + fieldTokenNode = fieldTokenNode->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); if (fieldTokenNode->gtOper == GT_IND) { fieldTokenNode = fieldTokenNode->AsOp()->gtOp1; @@ -4098,7 +4098,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis, // Get native TypeHandle argument to old helper assert(op1->AsCall()->gtArgs.CountArgs() == 1); - op1 = op1->AsCall()->gtArgs.GetArgByIndex(0)->GetArgNode(); + op1 = op1->AsCall()->gtArgs.GetArgByIndex(0)->GetNode(); retNode = op1; } // Call the regular function. @@ -18900,7 +18900,7 @@ void Compiler::impMakeDiscretionaryInlineObservations(InlineInfo* pInlineInfo, I // Check if the callee has the same 'this' as the root. if (pInlineInfo != nullptr) { - GenTree* thisArg = pInlineInfo->iciCall->AsCall()->gtArgs.GetThisArg()->GetArgNode(); + GenTree* thisArg = pInlineInfo->iciCall->AsCall()->gtArgs.GetThisArg()->GetNode(); assert(thisArg); bool isSameThis = impIsThis(thisArg); inlineResult->NoteBool(InlineObservation::CALLSITE_IS_SAME_THIS, isSameThis); diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 27d1c9b5dd8fb2..40b43ee3186bbd 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -4099,11 +4099,11 @@ GenTree* Lowering::LowerDelegateInvoke(GenTreeCall* call) GenTree* thisArgNode; if (call->IsTailCallViaJitHelper()) { - thisArgNode = call->gtArgs.GetArgByIndex(0)->GetArgNode(); + thisArgNode = call->gtArgs.GetArgByIndex(0)->GetNode(); } else { - thisArgNode = call->gtArgs.GetThisArg()->GetArgNode(); + thisArgNode = call->gtArgs.GetThisArg()->GetNode(); } assert(thisArgNode != nullptr); @@ -4906,8 +4906,8 @@ GenTree* Lowering::LowerVirtualVtableCall(GenTreeCall* call) assert(call->gtArgs.HasThisPointer()); CallArg* thisArg = call->gtArgs.GetThisArg(); // get a reference to the thisPtr being passed - assert(thisArg->GetArgNode()->OperIs(GT_PUTARG_REG)); - GenTree* thisPtr = thisArg->GetArgNode()->AsUnOp()->gtGetOp1(); + assert(thisArg->GetNode()->OperIs(GT_PUTARG_REG)); + GenTree* thisPtr = thisArg->GetNode()->AsUnOp()->gtGetOp1(); // If what we are passing as the thisptr is not already a local, make a new local to place it in // because we will be creating expressions based on it. @@ -4924,7 +4924,7 @@ GenTree* Lowering::LowerVirtualVtableCall(GenTreeCall* call) vtableCallTemp = comp->lvaGrabTemp(true DEBUGARG("virtual vtable call")); } - LIR::Use thisPtrUse(BlockRange(), &thisArg->GetArgNode()->AsUnOp()->gtOp1, thisArg->GetArgNode()); + LIR::Use thisPtrUse(BlockRange(), &thisArg->GetNode()->AsUnOp()->gtOp1, thisArg->GetNode()); ReplaceWithLclVar(thisPtrUse, vtableCallTemp); lclNum = vtableCallTemp; diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index c2d35837c11183..f484b696014755 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -615,7 +615,7 @@ const char* getWellKnownArgName(WellKnownArg arg) void CallArg::Dump(Compiler* comp) { printf("CallArg[arg %u", AbiInfo.ArgNum); - printf(" [%06u].%s", comp->dspTreeID(GetArgNode()), GenTree::OpName(GetEarlyNode()->OperGet())); + printf(" [%06u].%s", comp->dspTreeID(GetNode()), GenTree::OpName(GetEarlyNode()->OperGet())); printf(" %s", varTypeName(AbiInfo.ArgType)); printf(" (%s)", AbiInfo.PassedByRef ? "By ref" : "By value"); if (AbiInfo.GetRegNum() != REG_STK) @@ -3275,7 +3275,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) GenTreeFieldList* fieldList = new (this, GT_FIELD_LIST) GenTreeFieldList(); fieldList->AddField(this, argx->AsOp()->gtGetOp1(), OFFSETOF__CORINFO_TypedReference__dataPtr, TYP_BYREF); fieldList->AddField(this, argx->AsOp()->gtGetOp2(), OFFSETOF__CORINFO_TypedReference__type, TYP_I_IMPL); - arg.SetNode(fieldList); + arg.SetEarlyNode(fieldList); #else // !TARGET_X86 // Get a new temp @@ -3460,7 +3460,7 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) for (CallArg& arg : call->gtArgs.Args()) { bool isLateArg = (arg.GetEarlyNode()->gtFlags & GTF_LATE_ARG) != 0; - GenTree* argx = arg.GetArgNode(); + GenTree* argx = arg.GetNode(); if (!arg.AbiInfo.IsStruct) { @@ -3555,7 +3555,7 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) // GenTree* Compiler::fgMorphMultiregStructArg(CallArg* arg) { - GenTree* argNode = arg->GetArgNode(); + GenTree* argNode = arg->GetNode(); assert(varTypeIsStruct(argNode->TypeGet())); #if !defined(TARGET_ARMARCH) && !defined(UNIX_AMD64_ABI) @@ -6312,7 +6312,7 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) if (opts.OptimizationEnabled()) { // First, see if this arg is an implicit byref param. - GenTreeLclVar* const lcl = arg.GetArgNode()->IsImplicitByrefParameterValue(this); + GenTreeLclVar* const lcl = arg.GetNode()->IsImplicitByrefParameterValue(this); if (lcl != nullptr) { @@ -6377,20 +6377,20 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) continue; } - JITDUMP("... checking other arg [%06u]...\n", dspTreeID(arg2.GetArgNode())); - DISPTREE(arg2.GetArgNode()); + JITDUMP("... checking other arg [%06u]...\n", dspTreeID(arg2.GetNode())); + DISPTREE(arg2.GetNode()); // Do we pass 'lcl' more than once to the callee? if (arg2.AbiInfo.IsStruct && arg2.AbiInfo.PassedByRef) { GenTreeLclVarCommon* const lcl2 = - arg2.GetArgNode()->IsImplicitByrefParameterValue(this); + arg2.GetNode()->IsImplicitByrefParameterValue(this); if ((lcl2 != nullptr) && (lclNum == lcl2->GetLclNum())) { // not copying would introduce aliased implicit byref structs // in the callee ... we can't optimize. - interferingArg = arg2.GetArgNode(); + interferingArg = arg2.GetNode(); break; } else @@ -6431,7 +6431,7 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) bool hasExposure = false; // See if there is any way arg could refer to a parameter struct. - GenTree* arg2Node = arg2.GetArgNode(); + GenTree* arg2Node = arg2.GetNode(); if (arg2Node->OperIs(GT_LCL_VAR)) { GenTreeLclVarCommon* arg2LclNode = arg2Node->AsLclVarCommon(); @@ -6496,14 +6496,14 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) if (hasExposure) { - interferingArg = arg2.GetArgNode(); + interferingArg = arg2.GetNode(); break; } } else { JITDUMP("...arg is not a byref or implicit byref (%s)\n", - varTypeName(arg2.GetArgNode()->TypeGet())); + varTypeName(arg2.GetNode()->TypeGet())); } } @@ -6636,7 +6636,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) { noway_assert(call->TypeGet() == TYP_VOID); noway_assert(call->gtArgs.HasRetBuffer()); - GenTree* retValBuf = call->gtArgs.GetRetBufferArg()->GetArgNode(); + GenTree* retValBuf = call->gtArgs.GetRetBufferArg()->GetNode(); if (retValBuf->gtOper != GT_LCL_VAR || retValBuf->AsLclVarCommon()->GetLclNum() != info.compRetBuffArg) { failTailCall("Need to copy return buffer"); @@ -7356,7 +7356,7 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL { JITDUMP("Moving this pointer into arg list\n"); CallArg* thisArg = call->gtArgs.GetThisArg(); - GenTree* objp = thisArg->GetArgNode(); + GenTree* objp = thisArg->GetNode(); GenTree* thisPtr = nullptr; // JIT will need one or two copies of "this" in the following cases: @@ -8472,7 +8472,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) // Transform it into a null check. assert(call->gtArgs.CountArgs() >= 1); - GenTree* thisPtr = call->gtArgs.GetArgByIndex(0)->GetArgNode(); + GenTree* thisPtr = call->gtArgs.GetArgByIndex(0)->GetNode(); GenTree* nullCheck = gtNewNullCheck(thisPtr, compCurBB); @@ -8575,13 +8575,13 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_ARRADDR_ST))) { assert(call->gtArgs.CountArgs() == 3); - GenTree* value = call->gtArgs.GetArgByIndex(2)->GetArgNode(); + GenTree* value = call->gtArgs.GetArgByIndex(2)->GetNode(); if (value->IsIntegralConst(0)) { assert(value->OperGet() == GT_CNS_INT); - GenTree* arr = call->gtArgs.GetArgByIndex(0)->GetArgNode(); - GenTree* index = call->gtArgs.GetArgByIndex(1)->GetArgNode(); + GenTree* arr = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* index = call->gtArgs.GetArgByIndex(1)->GetNode(); // Either or both of the array and index arguments may have been spilled to temps by `fgMorphArgs`. Copy // the spill trees as well if necessary. @@ -8680,7 +8680,7 @@ GenTree* Compiler::fgExpandVirtualVtableCallTarget(GenTreeCall* call) assert(call->gtArgs.HasThisPointer()); // get a reference to the thisPtr being passed - GenTree* thisPtr = call->gtArgs.GetThisArg()->GetArgNode(); + GenTree* thisPtr = call->gtArgs.GetThisArg()->GetNode(); // fgMorphArgs must enforce this invariant by creating a temp // diff --git a/src/coreclr/jit/stacklevelsetter.cpp b/src/coreclr/jit/stacklevelsetter.cpp index 461f7dd2141a7b..decbec79de4d40 100644 --- a/src/coreclr/jit/stacklevelsetter.cpp +++ b/src/coreclr/jit/stacklevelsetter.cpp @@ -245,7 +245,7 @@ unsigned StackLevelSetter::PopArgumentsFromCall(GenTreeCall* call) const unsigned slotCount = arg.AbiInfo.GetStackSlotsNumber(); if (slotCount != 0) { - GenTree* node = arg.GetArgNode(); + GenTree* node = arg.GetNode(); assert(node->OperIsPutArgStkOrSplit()); GenTreePutArgStk* putArg = node->AsPutArgStk(); diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 8dec997d4ff1d2..dcb34bd65f6b55 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -9874,7 +9874,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN assert(args->GetArgByIndex(0)->GetEarlyNode()->OperGet() == GT_ARGPLACE); // Find the corresponding late arg. - GenTree* indirectCellAddress = args->GetArgByIndex(0)->GetArgNode(); + GenTree* indirectCellAddress = args->GetArgByIndex(0)->GetNode(); assert(indirectCellAddress->IsCnsIntOrI() && indirectCellAddress->GetRegNum() == REG_R2R_INDIRECT_PARAM); #endif // DEBUG @@ -9912,7 +9912,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN #endif // FEATURE_READYTORUN { assert(!useEntryPointAddrAsArg0); - ValueNumPair vnp0wx = curArg->GetArgNode()->gtVNPair; + ValueNumPair vnp0wx = curArg->GetNode()->gtVNPair; vnStore->VNPUnpackExc(vnp0wx, &vnp0, &vnp0x); // Also include in the argument exception sets @@ -9934,7 +9934,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN else { // Has at least two arguments. - ValueNumPair vnp1wx = curArg->GetArgNode()->gtVNPair; + ValueNumPair vnp1wx = curArg->GetNode()->gtVNPair; ValueNumPair vnp1; ValueNumPair vnp1x; vnStore->VNPUnpackExc(vnp1wx, &vnp1, &vnp1x); @@ -9954,7 +9954,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN } else { - ValueNumPair vnp2wx = curArg->GetArgNode()->gtVNPair; + ValueNumPair vnp2wx = curArg->GetNode()->gtVNPair; ValueNumPair vnp2; ValueNumPair vnp2x; vnStore->VNPUnpackExc(vnp2wx, &vnp2, &vnp2x); @@ -10121,7 +10121,7 @@ void Compiler::fgValueNumberCastHelper(GenTreeCall* call) unreached(); } - ValueNumPair argVNP = call->gtArgs.GetArgByIndex(0)->GetArgNode()->gtVNPair; + ValueNumPair argVNP = call->gtArgs.GetArgByIndex(0)->GetNode()->gtVNPair; ValueNumPair castVNP = vnStore->VNPairForCast(argVNP, castToType, castFromType, srcIsUnsigned, hasOverflowCheck); call->SetVNs(castVNP); From 9875a51265ea94e8af10ceeb7d348c05b2dd7211 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 30 Mar 2022 12:37:46 +0200 Subject: [PATCH 30/52] Run jit-format --- src/coreclr/jit/gentree.cpp | 4 ++-- src/coreclr/jit/gentree.h | 4 ++-- src/coreclr/jit/importer.cpp | 3 ++- src/coreclr/jit/morph.cpp | 5 ++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 93c9ebea973eae..5d44e0ca69bf82 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -11873,8 +11873,8 @@ void Compiler::gtDispArgList(GenTreeCall* call, GenTree* lastCallOperand, Indent { char buf[256]; gtGetArgMsg(call, &arg, buf, sizeof(buf)); - gtDispChild(arg.GetEarlyNode(), indentStack, (arg.GetEarlyNode() == lastCallOperand) ? IIArcBottom : IIArc, buf, - false); + gtDispChild(arg.GetEarlyNode(), indentStack, (arg.GetEarlyNode() == lastCallOperand) ? IIArcBottom : IIArc, + buf, false); } } } diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 7e1f97abfeeeb6..bc56568bc0f196 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4431,7 +4431,7 @@ class CallArgs unsigned CountArgs(); - template + template class CallArgIterator { CallArg* m_arg; @@ -4473,7 +4473,7 @@ class CallArgs } }; - using ArgIterator = CallArgIterator<&CallArg::GetNext>; + using ArgIterator = CallArgIterator<&CallArg::GetNext>; using LateArgIterator = CallArgIterator<&CallArg::GetLateNext>; IteratorPair Args() diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 2d85410e68438f..b568d851d7d09a 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -21377,7 +21377,8 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call, JITDUMP("revising call to invoke unboxed entry\n"); GenTree* const payloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); - GenTree* const boxPayload = gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetEarlyNode(), payloadOffset); + GenTree* const boxPayload = + gtNewOperNode(GT_ADD, TYP_BYREF, thisArg->GetEarlyNode(), payloadOffset); thisArg->SetEarlyNode(boxPayload); call->gtCallMethHnd = unboxedEntryMethod; diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index f484b696014755..860435c6a1e98f 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -8207,9 +8207,8 @@ void Compiler::fgMorphRecursiveFastTailCallIntoLoop(BasicBlock* block, GenTreeCa if (!arg.IsArgAddedLate()) { Statement* paramAssignStmt = - fgAssignRecursiveCallArgToCallerParam(lateArg, &arg, - fgGetArgParameterLclNum(recursiveTailCall, &arg), block, - callDI, tmpAssignmentInsertionPoint, + fgAssignRecursiveCallArgToCallerParam(lateArg, &arg, fgGetArgParameterLclNum(recursiveTailCall, &arg), + block, callDI, tmpAssignmentInsertionPoint, paramAssignmentInsertionPoint); if ((tmpAssignmentInsertionPoint == lastStmt) && (paramAssignStmt != nullptr)) From c1e50ad3948c2d3ffb2de6a294898b78da3154fb Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 30 Mar 2022 15:34:19 +0200 Subject: [PATCH 31/52] Fix build --- src/coreclr/jit/gentree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index bc56568bc0f196..3c5b2641d1ddff 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4431,7 +4431,7 @@ class CallArgs unsigned CountArgs(); - template + template class CallArgIterator { CallArg* m_arg; From bf82eee4875b9564cd2870a112ab9eb85b24ae61 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 30 Mar 2022 21:15:32 +0200 Subject: [PATCH 32/52] Fix unix x86 build --- src/coreclr/jit/gentree.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 5d44e0ca69bf82..836f9627eed132 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1237,6 +1237,10 @@ CallArgs::CallArgs() : m_head(nullptr) , m_lateHead(nullptr) , m_nextStackByteOffset(0) +#ifdef UNIX_X86_ABI + , m_stkSizeBytes(0) + , m_padStkAlign(0) +#endif , m_hasThisPointer(false) , m_hasRetBuffer(false) , m_isVarArgs(false) @@ -1247,8 +1251,6 @@ CallArgs::CallArgs() , m_argsSorted(false) , m_needsTemps(false) #ifdef UNIX_X86_ABI - , m_stkSizeBytes(0) - , m_padStkAlign(0) , m_alignmentDone(false) #endif { From a9af455b1199a55e8aeac8ba060acf06f6965f94 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 14:58:00 +0200 Subject: [PATCH 33/52] Small simplification using new function --- src/coreclr/jit/codegencommon.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index befb8b8bf77591..f4924fe3bcfe8f 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6452,18 +6452,8 @@ regNumber CodeGen::getCallIndirectionCellReg(GenTreeCall* call) } #ifdef DEBUG - regNumber foundReg = REG_NA; - for (CallArg& arg : call->gtArgs.Args()) - { - WellKnownArg kind = arg.GetWellKnownArg(); - if ((kind == WellKnownArg::R2RIndirectionCell) || (kind == WellKnownArg::VirtualStubCell)) - { - foundReg = arg.AbiInfo.GetRegNum(); - break; - } - } - - assert(foundReg == result); + CallArg* indirCellArg = call->gtArgs.FindWellKnownArg(call->GetIndirectionCellArgKind()); + assert((indirCellArg != nullptr) && (indirCellArg->AbiInfo.GetRegNum() == result)); #endif return result; From 00ccc70677e3d6a6b91e27fd39e7d3dbce92b0c7 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 16:21:09 +0200 Subject: [PATCH 34/52] Small cleanup --- src/coreclr/jit/compiler.h | 2 -- src/coreclr/jit/decomposelongs.cpp | 6 +++--- src/coreclr/jit/flowgraph.cpp | 13 +++++-------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 7d5a88b29a1234..65ca0613bf940e 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -2584,8 +2584,6 @@ class Compiler var_types gtTypeForNullCheck(GenTree* tree); void gtChangeOperToNullCheck(GenTree* tree, BasicBlock* block); - void gtChangeCallToHelperCall(GenTreeCall* call, CorInfoHelpFunc func); - GenTreeOp* gtNewAssignNode(GenTree* dst, GenTree* src); GenTree* gtNewTempAssign(unsigned tmp, diff --git a/src/coreclr/jit/decomposelongs.cpp b/src/coreclr/jit/decomposelongs.cpp index 76bb3f95601100..3c42b9a5bdcac9 100644 --- a/src/coreclr/jit/decomposelongs.cpp +++ b/src/coreclr/jit/decomposelongs.cpp @@ -1356,9 +1356,9 @@ GenTree* DecomposeLongs::DecomposeShift(LIR::Use& use) } GenTreeCall* call = m_compiler->gtNewHelperCallNode(helper, TYP_LONG); - call->gtArgs.PushBack(m_compiler, loOp1, WellKnownArg::ShiftLow); - call->gtArgs.PushBack(m_compiler, hiOp1, WellKnownArg::ShiftHigh); - call->gtArgs.PushBack(m_compiler, shiftByOp); + call->gtArgs.PushFront(m_compiler, shiftByOp); + call->gtArgs.PushFront(m_compiler, hiOp1, WellKnownArg::ShiftHigh); + call->gtArgs.PushFront(m_compiler, loOp1, WellKnownArg::ShiftLow); call->gtFlags |= shift->gtFlags & GTF_ALL_EFFECT; if (shift->IsUnusedValue()) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 17a3a36b619a03..73447ea5b851e9 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1144,14 +1144,13 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); CORINFO_LOOKUP pLookup; - CORINFO_CONST_LOOKUP entryPoint; info.compCompHnd->getReadyToRunDelegateCtorHelper(&ldftnToken->m_token, ldftnToken->m_tokenConstraint, clsHnd, &pLookup); if (!pLookup.lookupKind.needsRuntimeLookup) { - entryPoint = pLookup.constLookup; call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, targetObjPointers); + call->setEntryPoint(pLookup.constLookup); } else { @@ -1162,10 +1161,9 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, GenTree* ctxTree = getRuntimeContextTree(pLookup.lookupKind.runtimeLookupKind); call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, targetObjPointers, ctxTree); - entryPoint = genericLookup; + call->setEntryPoint(genericLookup); } - call->setEntryPoint(entryPoint); } else { @@ -1560,12 +1558,11 @@ GenTree* Compiler::fgGetCritSectOfStaticMethod() case CORINFO_LOOKUP_METHODPARAM: { // In this case, the hidden param is the method handle. - GenTree* arg = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL); - arg->gtFlags |= GTF_VAR_CONTEXT; + tree = gtNewLclvNode(info.compTypeCtxtArg, TYP_I_IMPL); + tree->gtFlags |= GTF_VAR_CONTEXT; // Call helper CORINFO_HELP_GETCLASSFROMMETHODPARAM to get the class handle // from the method handle. - tree = gtNewHelperCallNode(CORINFO_HELP_GETCLASSFROMMETHODPARAM, TYP_I_IMPL); - tree->AsCall()->gtArgs.PushFront(this, arg); + tree = gtNewHelperCallNode(CORINFO_HELP_GETCLASSFROMMETHODPARAM, TYP_I_IMPL, tree); break; } From b3f28518fbfc35bc2533894423c640ec13632916 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 16:21:17 +0200 Subject: [PATCH 35/52] Write some documentation --- src/coreclr/jit/gentree.cpp | 274 ++++++++++++++++++++++++++++++++++-- src/coreclr/jit/gentree.h | 6 +- 2 files changed, 264 insertions(+), 16 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index ece74076653443..98c3590c811e44 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -963,6 +963,9 @@ void GenTreeFieldList::InsertFieldLIR( m_uses.InsertUse(insertAfter, new (compiler, CMK_ASTNode) Use(node, offset, type)); } +//--------------------------------------------------------------- +// IsHfaArg: Is this arg considered a homogeneous floating-point aggregate? +// bool CallArgABIInformation::IsHfaArg() const { if (GlobalJitOptions::compFeatureHfa) @@ -975,6 +978,9 @@ bool CallArgABIInformation::IsHfaArg() const } } +//--------------------------------------------------------------- +// IsHfaRegArg: Is this an HFA argument passed in registers? +// bool CallArgABIInformation::IsHfaRegArg() const { if (GlobalJitOptions::compFeatureHfa) @@ -987,6 +993,9 @@ bool CallArgABIInformation::IsHfaRegArg() const } } +//--------------------------------------------------------------- +// GetHfaType: Get the type of each element of the HFA arg. +// var_types CallArgABIInformation::GetHfaType() const { if (GlobalJitOptions::compFeatureHfa) @@ -999,6 +1008,20 @@ var_types CallArgABIInformation::GetHfaType() const } } +//--------------------------------------------------------------- +// SetHfaType: Set the type of each element of the HFA arg. +// +// Arguments: +// type - The new type for each element +// hfaSlots - How many registers are used by the HFA. +// +// Remarks: +// This can only be called after the passing mode of the argument (registers +// or stack) has been determined. When passing HFAs of doubles on ARM it is +// expected that `hfaSlots` refers to the number of float registers used, +// i.e. twice the number of doubles being passed. This function will convert +// that into double registers and set `NumRegs` appropriately. +// void CallArgABIInformation::SetHfaType(var_types type, unsigned hfaSlots) { if (GlobalJitOptions::compFeatureHfa) @@ -1046,9 +1069,23 @@ void CallArgABIInformation::SetHfaType(var_types type, unsigned hfaSlots) } } +//--------------------------------------------------------------- +// SetByteSize: Set information related to this argument's size and alignment. +// +// Arguments: +// byteSize - The size in bytes of the argument. +// byteAlignment - The alignment in bytes of the argument. +// isStruct - Whether this arg is a struct. +// isFloatHfa - Whether this is a float HFA. +// +// Remarks: +// This function will determine how the argument size needs to be rounded. On +// most ABIs all arguments are rounded to stack pointer size, but macOS arm64 +// ABI is an exception as it allows packing some small arguments into the +// same stack slot. +// void CallArgABIInformation::SetByteSize(unsigned byteSize, unsigned byteAlignment, bool isStruct, bool isFloatHfa) { - ByteAlignment = byteAlignment; unsigned roundedByteSize; if (compMacOsArm64Abi()) { @@ -1081,9 +1118,20 @@ void CallArgABIInformation::SetByteSize(unsigned byteSize, unsigned byteAlignmen } #endif ByteSize = roundedByteSize; + ByteAlignment = byteAlignment; } #ifdef DEBUG_ARG_SLOTS +//--------------------------------------------------------------- +// GetSlotCount: Get the number of slots used by this argument. +// +// Returns: +// The number of slots, in terms of registers and whole stack slots. +// +// Remarks: +// Note that a slot may not necessarily be TARGET_POINTER_SIZE in size. +// For example, a SIMD16 may be passed in a single register where this +// function will return 1. unsigned CallArgABIInformation::GetSlotCount() const { if (IsBackFilled) @@ -1103,6 +1151,18 @@ unsigned CallArgABIInformation::GetSlotCount() const return NumSlots + NumRegs; } +//--------------------------------------------------------------- +// GetSize: Get the size of the argument normalized to TARGET_POINTER_SIZE +// stack slots. +// +// Returns: +// The size of the argument, normalized to TARGET_POINTER_SIZE stack slots. +// +// Remarks: +// Unlike GetSlotCount() this function applies normalization and returns the +// answer in terms of TARGET_POINTER_SIZE slots. +// For example, a SIMD16 argument passed in a single register will return 2 +// on ARM64. unsigned CallArgABIInformation::GetSize() const { unsigned size = GetSlotCount(); @@ -1138,6 +1198,15 @@ unsigned CallArgABIInformation::GetSize() const } #endif +//--------------------------------------------------------------- +// SetMultiRegsNumw: Set the registers for a multi-reg arg using 'sequential' registers. +// +// Remarks: +// This assumes that `NumRegs` and the first reg num has already been set and +// determines how many sequential registers are necessary to pass the +// argument. +// Note that on ARM the registers set may skip odd float registers if the arg +// is a HFA of doubles, since double and float registers overlap. void CallArgABIInformation::SetMultiRegNums() { #if FEATURE_MULTIREG_ARGS && !defined(UNIX_AMD64_ABI) @@ -1164,6 +1233,14 @@ void CallArgABIInformation::SetMultiRegNums() #endif // FEATURE_MULTIREG_ARGS && !defined(UNIX_AMD64_ABI) } +//--------------------------------------------------------------- +// GetStackByteSize: Get the number of stack bytes used to pass this argument. +// +// Returns: +// For pure register arguments, this returns 0. +// For pure stack arguments, this returns ByteSize. +// For split arguments the return value is between 0 and ByteSize. +// unsigned CallArgABIInformation::GetStackByteSize() const { if (!IsSplit() && NumRegs > 0) @@ -1178,6 +1255,15 @@ unsigned CallArgABIInformation::GetStackByteSize() const return stackByteSize; } +//--------------------------------------------------------------- +// IsArgAddedLate: Check if this is an argument that is added late, by +// `DetermineArgABIInformation`. +// +// Remarks: +// These arguments must be removed if ABI information needs to be +// reclassified by calling `DetermineArgABIInformation` as otherwise they +// will be readded. See `CallArgs::ResetArgABIInformation`. +// bool CallArg::IsArgAddedLate() const { switch (m_wellKnownArg) @@ -1194,6 +1280,9 @@ bool CallArg::IsArgAddedLate() const } #ifdef DEBUG +//--------------------------------------------------------------- +// CheckIsStruct: Verify that the struct ABI information is consistent with the IR node. +// void CallArg::CheckIsStruct() { GenTree* node = GetNode(); @@ -1248,6 +1337,9 @@ CallArgs::CallArgs() { } +//--------------------------------------------------------------- +// FindByNode: Find the argument containing the specified early or late node. +// CallArg* CallArgs::FindByNode(GenTree* node) { assert(node != nullptr); @@ -1262,6 +1354,13 @@ CallArg* CallArgs::FindByNode(GenTree* node) return nullptr; } +//--------------------------------------------------------------- +// FindWellKnownArg: Find a specific well-known argument. +// +// Remarks: +// For the 'this' arg or the return buffer arg there are more efficient +// alternatives available in `GetThisArg` and `GetRetBufferArg`. +// CallArg* CallArgs::FindWellKnownArg(WellKnownArg arg) { assert(arg != WellKnownArg::None); @@ -1276,6 +1375,13 @@ CallArg* CallArgs::FindWellKnownArg(WellKnownArg arg) return nullptr; } +//--------------------------------------------------------------- +// GetThisArg: Get the this-pointer argument. +// +// Remarks: +// This is only the managed 'this' arg. We consider the 'this' pointer for +// unmanaged instance calling conventions as normal (non-this) arguments. +// CallArg* CallArgs::GetThisArg() { if (!HasThisPointer()) @@ -1290,6 +1396,20 @@ CallArg* CallArgs::GetThisArg() return result; } +//--------------------------------------------------------------- +// GetRetBufferArg: Get the return buffer arg. +// +// Remarks: +// This is the actual (per-ABI) return buffer argument. On some ABIs this +// argument has special treatment. Notably on standard ARM64 calling +// convention it is passed in x8 (see `CallArgs::GetCustomRegister` for the +// exact conditions). +// +// Some jit helpers may have "out buffers" that are _not_ classified as the +// ret buffer. These are normal arguments that function similarly to ret +// buffers, but they do not have the special ABI treatment of ret buffers. +// See `GenTreeCall::TreatAsShouldGetRetBufArg` for more details. +// CallArg* CallArgs::GetRetBufferArg() { if (!HasRetBuffer()) @@ -1302,17 +1422,24 @@ CallArg* CallArgs::GetRetBufferArg() return result; } +//--------------------------------------------------------------- +// GetArgByIndex: Get an argument with the specified index. +// CallArg* CallArgs::GetArgByIndex(unsigned index) { CallArg* cur = m_head; - for (unsigned i = 0; i < index && cur != nullptr; i++) + for (unsigned i = 0; i < index; i++) { + assert(cur != nullptr); cur = cur->GetNext(); } return cur; } +//--------------------------------------------------------------- +// GetIndex: Get the index for the specified argument. +// unsigned CallArgs::GetIndex(CallArg* arg) { unsigned i = 0; @@ -1330,6 +1457,17 @@ unsigned CallArgs::GetIndex(CallArg* arg) return (unsigned)-1; } +//--------------------------------------------------------------- +// Reverse: Reverse the specified subrange of arguments. +// +// Parameters: +// index - The index of the sublist to reverse. +// count - The length of the sublist to reverse. +// +// Remarks: +// This function is used for x86 stdcall/cdecl that passes arguments in the +// opposite order of the managed calling convention. +// void CallArgs::Reverse(unsigned index, unsigned count) { CallArg** headSlot = &m_head; @@ -1355,6 +1493,12 @@ void CallArgs::Reverse(unsigned index, unsigned count) } } +//--------------------------------------------------------------- +// AddedWellKnownArg: Record details when a well known arg was added. +// +// Remarks: +// This is used to improve performance of some common argument lookups. +// void CallArgs::AddedWellKnownArg(WellKnownArg arg) { switch (arg) @@ -1370,6 +1514,9 @@ void CallArgs::AddedWellKnownArg(WellKnownArg arg) } } +//--------------------------------------------------------------- +// RemovedWellKnownArg: Record details when a well known arg was removed. +// void CallArgs::RemovedWellKnownArg(WellKnownArg arg) { switch (arg) @@ -1387,6 +1534,25 @@ void CallArgs::RemovedWellKnownArg(WellKnownArg arg) } } +//--------------------------------------------------------------- +// GetCustomRegister: Get the custom, non-standard register assignment for an argument. +// +// Parameters: +// comp - The compiler. +// cc - The calling convention. +// arg - The kind of argument. +// +// Returns: +// The custom register assignment, or REG_NA if this is a normally treated +// argument. +// +// Remarks: +// Many JIT helpers have custom calling conventions in order to improve +// performance. The pattern in those cases is to add a WellKnownArg for the +// arguments that are passed specially and teach this function how to pass +// them. Note that we only support passing such arguments in custom registers +// and generally never on stack. +// regNumber CallArgs::GetCustomRegister(Compiler* comp, CorInfoCallConvExtension cc, WellKnownArg arg) { switch (arg) @@ -1411,8 +1577,7 @@ regNumber CallArgs::GetCustomRegister(Compiler* comp, CorInfoCallConvExtension c #endif #if defined(TARGET_X86) // The x86 shift helpers have custom calling conventions and expect the lo - // part of the long to be in EAX and the hi part to be in EDX. This sets - // the argument registers up correctly. + // part of the long to be in EAX and the hi part to be in EDX. case WellKnownArg::ShiftLow: return REG_LNGARG_LO; case WellKnownArg::ShiftHigh: @@ -1461,11 +1626,26 @@ regNumber CallArgs::GetCustomRegister(Compiler* comp, CorInfoCallConvExtension c return REG_NA; } +//--------------------------------------------------------------- +// IsNonStandard: Check if an argument is passed with a non-standard calling +// convention. +// bool CallArgs::IsNonStandard(Compiler* comp, GenTreeCall* call, CallArg* arg) { return GetCustomRegister(comp, call->GetUnmanagedCallConv(), arg->GetWellKnownArg()) != REG_NA; } +//--------------------------------------------------------------- +// PushFront: Create a new argument at the front of the argument list. +// +// Parameters: +// comp - The compiler. +// node - The IR node for the argument. +// wellKnownArg - The kind of argument, if special. +// +// Returns: +// The created representative for the argument. +// CallArg* CallArgs::PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) { CallArg* arg = new (comp, CMK_CallArgs) CallArg(wellKnownArg); @@ -1476,6 +1656,17 @@ CallArg* CallArgs::PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKno return arg; } +//--------------------------------------------------------------- +// PushBack: Create a new argument at the back of the argument list. +// +// Parameters: +// comp - The compiler. +// node - The IR node for the argument. +// wellKnownArg - The kind of argument, if special. +// +// Returns: +// The created representative for the argument. +// CallArg* CallArgs::PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) { CallArg** slot = &m_head; @@ -1490,7 +1681,19 @@ CallArg* CallArgs::PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnow return *slot; } -CallArg* CallArgs::InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, WellKnownArg wellKnownArg) +//--------------------------------------------------------------- +// InsertAfter: Create a new argument after another argument. +// +// Parameters: +// comp - The compiler. +// after - The existing argument to insert the new argument after. +// node - The IR node for the argument. +// wellKnownArg - The kind of argument, if special. +// +// Returns: +// The created representative for the argument. +// +CallArg* CallArgs::InsertAfter(Compiler* comp, CallArg* after, GenTree* node, WellKnownArg wellKnownArg) { #ifdef DEBUG bool found = false; @@ -1507,33 +1710,61 @@ CallArg* CallArgs::InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, Wel #endif CallArg* newArg = new (comp, CMK_CallArgs) CallArg(wellKnownArg); - newArg->SetEarlyNode(arg); + newArg->SetEarlyNode(node); newArg->SetNext(after->GetNext()); after->SetNext(newArg); AddedWellKnownArg(wellKnownArg); return newArg; } -CallArg* CallArgs::InsertInstParam(Compiler* comp, GenTree* arg) +//--------------------------------------------------------------- +// InsertInstParam: Insert an instantiation parameter/generic context argument. +// +// Parameters: +// comp - The compiler. +// node - The IR node for the instantiation parameter. +// +// Returns: +// The created representative for the argument. +// +// Remarks: +// The instantiation parameter is a normal parameter, but its position in the +// arg list depends on a few factors. It is inserted at the end on x86 and on +// other platforms must always come after the ret-buffer and the 'this' +// argument. +// +CallArg* CallArgs::InsertInstParam(Compiler* comp, GenTree* node) { if (Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) { CallArg* retBufferArg = GetRetBufferArg(); if (retBufferArg != nullptr) { - return InsertAfter(comp, retBufferArg, arg, WellKnownArg::InstParam); + return InsertAfter(comp, retBufferArg, node, WellKnownArg::InstParam); } else { - return InsertAfterThisOrFirst(comp, arg, WellKnownArg::InstParam); + return InsertAfterThisOrFirst(comp, node, WellKnownArg::InstParam); } } else { - return PushBack(comp, arg, WellKnownArg::InstParam); + return PushBack(comp, node, WellKnownArg::InstParam); } } +//--------------------------------------------------------------- +// InsertAfterThisOrFirst: Insert an argument after 'this' if the call has a +// 'this' argument, or otherwise first. +// +// Parameters: +// comp - The compiler. +// node - The IR node for the argument. +// wellKnownArg - The kind of argument, if special. +// +// Returns: +// The created representative for the argument. +// CallArg* CallArgs::InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg) { CallArg* thisArg = GetThisArg(); @@ -1547,6 +1778,12 @@ CallArg* CallArgs::InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKno } } +//--------------------------------------------------------------- +// PushLateBack: Insert an argument at the end of the 'late' argument list. +// +// Remarks: +// This function should only be used if adding arguments after the call has +// already been morphed. void CallArgs::PushLateBack(CallArg* arg) { CallArg** slot = &m_lateHead; @@ -1558,8 +1795,19 @@ void CallArgs::PushLateBack(CallArg* arg) *slot = arg; } +//--------------------------------------------------------------- +// Remove: Remove an argument from the argument list. +// +// Remarks: +// This function cannot be used after morph. It will also invalidate ABI +// information, so it is expected that `CallArgs::DetermineArgABIInformation` +// was not called yet or that `CallArgs::ResetArgABIInformation` has been +// called prior to this. +// bool CallArgs::Remove(CallArg* arg) { + assert(!m_abiInformationDetermined && !m_argsComplete); + CallArg** slot = &m_head; while (*slot != nullptr) { @@ -1944,9 +2192,9 @@ void CallArgs::ResetArgABIInformation() // IR so it doesn't get added again. CallArg** link = &m_head; - // We cannot handle this being called after fgMorphArgs, only - // CallArgs::DetermineArgABIInformation. - assert(m_lateHead == nullptr); + // We cannot handle this being called after fgMorphArgs, only between + // CallArgs::DetermineArgABIInformation and finishing args. + assert(!m_argsComplete); while ((*link) != nullptr) { diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 3f4584d01f6920..a9dfdb7cecf8e0 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4356,10 +4356,10 @@ class CallArgs // Create a new call argument at the beginning of the list. CallArg* PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); CallArg* PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); - CallArg* InsertAfter(Compiler* comp, CallArg* after, GenTree* arg, WellKnownArg wellKnownArg = WellKnownArg::None); - CallArg* InsertInstParam(Compiler* comp, GenTree* value); + CallArg* InsertAfter(Compiler* comp, CallArg* after, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); + CallArg* InsertInstParam(Compiler* comp, GenTree* node); CallArg* InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); - void PushLateBack(CallArg* node); + void PushLateBack(CallArg* arg); bool Remove(CallArg* arg); template From cd40bf87b35f3dbaca0ae10c6d8e665f1b5acdd5 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 16:49:50 +0200 Subject: [PATCH 36/52] Small fix for potential incompatibility Behavior was different for unmanaged thiscall without any args. --- src/coreclr/jit/importer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 337c874491f2e9..a7ffcd0f911be7 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -1262,7 +1262,14 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, } #else - srcCall->gtArgs.InsertAfter(this, &*srcCall->gtArgs.Args().begin(), destAddr, wellKnownArgType); + if (srcCall->gtArgs.Args().begin() == srcCall->gtArgs.Args().end()) + { + srcCall->gtArgs.PushFront(this, destAddr, wellKnownArgType); + } + else + { + srcCall->gtArgs.InsertAfter(this, &*srcCall->gtArgs.Args().begin(), destAddr, wellKnownArgType); + } #endif } else From bd11beaa14c9e2b855571ee757bd6cf7e29737a2 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 18:26:56 +0200 Subject: [PATCH 37/52] Small cleanups and improve documentation --- src/coreclr/jit/compiler.h | 6 +- src/coreclr/jit/gentree.cpp | 46 +++++++++-- src/coreclr/jit/gentree.h | 5 -- src/coreclr/jit/importer.cpp | 53 ++++++------- src/coreclr/jit/lower.cpp | 5 +- src/coreclr/jit/morph.cpp | 134 ++++++++++++++++++++++---------- src/coreclr/jit/objectalloc.cpp | 2 +- src/coreclr/jit/rationalize.cpp | 13 ++-- 8 files changed, 173 insertions(+), 91 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 65ca0613bf940e..fe1905d037ad70 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -3828,8 +3828,8 @@ class Compiler GenTreeCall* impReadyToRunHelperToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken, CorInfoHelpFunc helper, var_types type, - GenTree* arg1 = nullptr, - CORINFO_LOOKUP_KIND* pGenericLookupKind = nullptr); + CORINFO_LOOKUP_KIND* pGenericLookupKind = nullptr, + GenTree* arg1 = nullptr); bool impIsCastHelperEligibleForClassProbe(GenTree* tree); bool impIsCastHelperMayHaveProfileData(CorInfoHelpFunc helper); @@ -5557,7 +5557,7 @@ class Compiler GenTree* fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* oper); GenTree* fgMorphIntoHelperCall( - GenTree* tree, int helper, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr, bool morphArgs = true); + GenTree* tree, int helper, bool morphArgs, GenTree* arg1 = nullptr, GenTree* arg2 = nullptr); GenTree* fgMorphStackArgForVarArgs(unsigned lclNum, var_types varType, unsigned lclOffs); diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 98c3590c811e44..b561b6e626c709 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1264,6 +1264,10 @@ unsigned CallArgABIInformation::GetStackByteSize() const // reclassified by calling `DetermineArgABIInformation` as otherwise they // will be readded. See `CallArgs::ResetArgABIInformation`. // +// Note that the 'late' here is separate from CallArg::GetLateNode and +// friends. Late here refers to this being an argument that is added by morph +// instead of the importer. +// bool CallArg::IsArgAddedLate() const { switch (m_wellKnownArg) @@ -2180,6 +2184,15 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) return true; } +//-------------------------------------------------------------------------- +// ResetArgABIInformation: Reset ABI information classified for arguments, +// removing late-added arguments. +// +// Remarks: +// This function can be called between `CallArgs::DetermineArgABIInformation` +// and actually finishing the morphing of arguments. It cannot be called once +// the arguments have finished morphing. +// void CallArgs::ResetArgABIInformation() { if (!IsAbiInformationDetermined()) @@ -8554,8 +8567,15 @@ GenTree* Compiler::gtCloneExpr( return copy; } -// Copy all information from the specified CallArgs, making these argument lists equivalent. -// Nodes are cloned using the specified function. +//------------------------------------------------------------------------ +// InternalCopyFrom: +// Copy all information from the specified `CallArgs`, making these argument +// lists equivalent. Nodes are cloned using the specified function. +// +// Remarks: +// This function should not be used directly. Instead, use `gtCloneExpr` on +// the call node. +// template void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc copyNode) { @@ -8572,8 +8592,8 @@ void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc co m_argsSorted = other->m_argsSorted; m_needsTemps = other->m_needsTemps; - // Unix x86 flags related to stack alignment intentionally not copied as it - // depends on where the call will be inserted. + // Unix x86 flags related to stack alignment intentionally not copied as + // they depend on where the call will be inserted. CallArg** tail = &m_head; for (CallArg& arg : other->Args()) @@ -11891,6 +11911,9 @@ void Compiler::gtDispTree(GenTree* tree, } } +//------------------------------------------------------------------------ +// gtGetWellKnownArgNameForArgMsg: Get a short descriptor of a well-known arg kind. +// const char* Compiler::gtGetWellKnownArgNameForArgMsg(WellKnownArg arg) { switch (arg) @@ -11929,6 +11952,13 @@ const char* Compiler::gtGetWellKnownArgNameForArgMsg(WellKnownArg arg) } } +//------------------------------------------------------------------------ +// gtPrintArgPrefix: Print a description of an argument into the specified buffer. +// +// Remarks: +// For well-known arguments this prints a human-readable description. +// Otherwise it prints e.g. "arg3". +// void Compiler::gtPrintArgPrefix(GenTreeCall* call, CallArg* arg, char** bufp, unsigned* bufLength) { int prefLen; @@ -12011,10 +12041,10 @@ void Compiler::gtGetArgMsg(GenTreeCall* call, CallArg* arg, char* bufp, unsigned // gtGetLateArgMsg: Construct a message about the given argument // // Arguments: -// call - The call for which 'arg' is an argument -// arg - The argument for which a message should be constructed -// bufp - A pointer to the buffer into which the message is written -// bufLength - The length of the buffer pointed to by bufp +// call - The call for which 'arg' is an argument +// arg - The argument for which a message should be constructed +// bufp - A pointer to the buffer into which the message is written +// bufLength - The length of the buffer pointed to by bufp // // Return Value: // No return value, but bufp is written. diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index a9dfdb7cecf8e0..15c19480f21725 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4269,7 +4269,6 @@ class CallArg CallArg* GetLateNext() { return m_lateNext; } void SetLateNext(CallArg* lateNext) { m_lateNext = lateNext; } WellKnownArg GetWellKnownArg() { return m_wellKnownArg; } - // TODO-ARGS: Remove bool IsTemp() { return m_isTmp; } // clang-format on @@ -4353,7 +4352,6 @@ class CallArgs // Reverse the args from [index..index + count) in place. void Reverse(unsigned index, unsigned count); - // Create a new call argument at the beginning of the list. CallArg* PushFront(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); CallArg* PushBack(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); CallArg* InsertAfter(Compiler* comp, CallArg* after, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); @@ -4373,9 +4371,6 @@ class CallArgs } void ResetArgABIInformation(); - // Determine argument ABI information. - // TODO-ARGS: This is equivalent to old fgInitArgInfo and thus may add arguments. - // Refactor this to be idempotent. void DetermineArgABIInformation(Compiler* comp, GenTreeCall* call); void ArgsComplete(Compiler* comp, GenTreeCall* call); diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index a7ffcd0f911be7..23a59e2ec90186 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -799,10 +799,20 @@ void Compiler::impAssignTempGen(unsigned tmpNum, /***************************************************************************** * - * Pop the given number of values from the stack and return a list node with - * their values. */ - +//------------------------------------------------------------------------ +// impPopCallArgs: +// Pop the given number of values from the stack and return a list node with +// their values. +// +// Parameters: +// count - The number of arguments to pop +// sig - Signature used to figure out classes the runtime must load, and +// also to record exact receiving argument types that may be needed for ABI +// purposes later. +// Can be nullptr for certain helpers. +// argList - The `CallArgs` to pop argument into. +// void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList) { assert(sig == nullptr || count == sig->numArgs); @@ -852,7 +862,7 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a #endif } - /* NOTE: we defer bashing the type for I_IMPL to fgMorphArgs */ + // NOTE: we defer bashing the type for I_IMPL to fgMorphArg argList->PushFront(this, temp); } @@ -1223,10 +1233,10 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, if (callConvIsInstanceMethodCallConv(srcCall->GetUnmanagedCallConv())) { #ifdef TARGET_X86 - // The argument list has already been reversed making it - // complicated to figure out where the retbuffer should be - // inserted. There are several cases. - + // The argument list has already been reversed. Insert the + // return buffer as the second-to-last node so it will be + // pushed on to the stack after the user args but before + // the native this arg as required by the native ABI. if (srcCall->gtArgs.Args().begin() == srcCall->gtArgs.Args().end()) { // Empty arg list @@ -1360,7 +1370,7 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, if (call->ShouldGetRetBufArg()) { - // insert the return value buffer into the argument list as first byref parameter + // insert the return value buffer into the argument list as first byref parameter after 'this' call->gtArgs.InsertAfterThisOrFirst(this, destAddr, WellKnownArg::RetBuffer); // now returns void, not a struct @@ -2097,8 +2107,8 @@ GenTreeCall* Compiler::impReadyToRunHelperToTree( CORINFO_RESOLVED_TOKEN* pResolvedToken, CorInfoHelpFunc helper, var_types type, - GenTree* arg1, - CORINFO_LOOKUP_KIND* pGenericLookupKind /* =NULL. Only used with generics */) + CORINFO_LOOKUP_KIND* pGenericLookupKind, + GenTree* arg1) { CORINFO_CONST_LOOKUP lookup; if (!info.compCompHnd->getReadyToRunHelper(pResolvedToken, pGenericLookupKind, helper, &lookup)) @@ -2218,7 +2228,7 @@ GenTree* Compiler::impRuntimeLookupToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken if (opts.IsReadyToRun()) { return impReadyToRunHelperToTree(pResolvedToken, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, TYP_I_IMPL, - ctxTree, &pLookup->lookupKind); + &pLookup->lookupKind, ctxTree); } #endif return gtNewRuntimeLookupHelperCallNode(pRuntimeLookup, ctxTree, compileTimeHandle); @@ -6827,7 +6837,7 @@ GenTree* Compiler::impImportLdvirtftn(GenTree* thisPtr, GenTree* ctxTree = getRuntimeContextTree(pCallInfo->codePointerLookup.lookupKind.runtimeLookupKind); return impReadyToRunHelperToTree(pResolvedToken, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, TYP_I_IMPL, - ctxTree, &pCallInfo->codePointerLookup.lookupKind); + &pCallInfo->codePointerLookup.lookupKind, ctxTree); } } #endif @@ -7477,11 +7487,6 @@ void Compiler::impImportNewObjArray(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORI node = gtNewHelperCallNode(CORINFO_HELP_NEW_MDARR, TYP_REF, classHandle, gtNewIconNode(pCallInfo->sig.numArgs), node); - for (CallArg& arg : node->AsCall()->gtArgs.Args()) - { - node->gtFlags |= arg.GetEarlyNode()->gtFlags & GTF_GLOB_EFFECT; - } - node->AsCall()->compileTimeHelperArgumentHandle = (CORINFO_GENERIC_HANDLE)pResolvedToken->hClass; // Remember that this basic block contains 'new' of a md array @@ -7916,7 +7921,7 @@ void Compiler::impPopArgsForUnmanagedCall(GenTreeCall* call, CORINFO_SIG_INFO* s if (call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) { - GenTree* thisPtr = call->gtArgs.Args().begin()->GetEarlyNode(); + GenTree* thisPtr = call->gtArgs.GetArgByIndex(0)->GetNode(); impBashVarAddrsToI(thisPtr); assert(thisPtr->TypeGet() == TYP_I_IMPL || thisPtr->TypeGet() == TYP_BYREF); } @@ -8980,8 +8985,6 @@ var_types Compiler::impImportCall(OPCODE opcode, assert(fptr != nullptr); call->AsCall()->gtArgs.PushFront(this, thisPtrCopy, WellKnownArg::ThisPointer); - thisPtr = nullptr; // can't reuse it - thisPtrCopy = nullptr; // Now make an indirect call through the function pointer @@ -15784,7 +15787,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) #ifdef FEATURE_READYTORUN if (opts.IsReadyToRun()) { - op1 = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_NEWARR_1, TYP_REF, op2); + op1 = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_NEWARR_1, TYP_REF, nullptr, op2); usingReadyToRunHelper = (op1 != nullptr); if (!usingReadyToRunHelper) @@ -15977,7 +15980,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) { GenTreeCall* opLookup = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_ISINSTANCEOF, TYP_REF, - op1); + nullptr, op1); usingReadyToRunHelper = (opLookup != nullptr); op1 = (usingReadyToRunHelper ? opLookup : op1); @@ -16496,7 +16499,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) if (opts.IsReadyToRun()) { GenTreeCall* opLookup = - impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_CHKCAST, TYP_REF, op1); + impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_CHKCAST, TYP_REF, nullptr, op1); usingReadyToRunHelper = (opLookup != nullptr); op1 = (usingReadyToRunHelper ? opLookup : op1); @@ -21613,8 +21616,6 @@ class SpillRetExprHelper { comp->fgWalkTreePre(&arg.EarlyNodeRef(), SpillRetExprVisitor, this); } - - // TODO-ARGS-REVIEW: Different order of this and rest of args } private: diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 1d809f4dec8422..dce652eb008224 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -1804,7 +1804,7 @@ void Lowering::InsertProfTailCallHook(GenTreeCall* call, GenTree* insertionPoint { for (CallArg& arg : call->gtArgs.Args()) { - assert(!arg.GetEarlyNode()->OperIs(GT_PUTARG_REG)); // We don't expect to see these in gtCallArgs + assert(!arg.GetEarlyNode()->OperIs(GT_PUTARG_REG)); // We don't expect to see these in early args if (arg.GetEarlyNode()->OperIs(GT_PUTARG_STK)) { @@ -4354,11 +4354,10 @@ void Lowering::InsertPInvokeMethodProlog() // Call runtime helper to fill in our InlinedCallFrame and push it on the Frame list: // TCB = CORINFO_HELP_INIT_PINVOKE_FRAME(&symFrameStart, secretArg); - // for x86, don't pass the secretArg. - CLANG_FORMAT_COMMENT_ANCHOR; GenTreeCall* call = comp->gtNewHelperCallNode(CORINFO_HELP_INIT_PINVOKE_FRAME, TYP_I_IMPL); call->gtArgs.PushBack(comp, frameAddr, WellKnownArg::PInvokeFrame); + // for x86/arm32 don't pass the secretArg. #if !defined(TARGET_X86) && !defined(TARGET_ARM) call->gtArgs.PushBack(comp, PhysReg(REG_SECRET_STUB_PARAM), WellKnownArg::SecretStubParam); #endif diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index a09e48e28a44a3..1c9148c0320a0d 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -46,7 +46,7 @@ GenTree* Compiler::fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* ope noway_assert(tree->AsCast()->CastOp() == oper); noway_assert(tree->gtOper == GT_CAST); } - result = fgMorphIntoHelperCall(tree, helper, oper); + result = fgMorphIntoHelperCall(tree, helper, true, oper); assert(result == tree); return result; } @@ -57,12 +57,13 @@ GenTree* Compiler::fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* ope * the given argument list. */ -GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTree* arg1, GenTree* arg2, bool morphArgs) +GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, bool morphArgs, GenTree* arg1, GenTree* arg2) { // The helper call ought to be semantically equivalent to the original node, so preserve its VN. tree->ChangeOper(GT_CALL, GenTree::PRESERVE_VN); GenTreeCall* call = tree->AsCall(); + // Args are cleared by ChangeOper above call->gtCallType = CT_HELPER; call->gtReturnType = tree->TypeGet(); call->gtCallMethHnd = eeFindHelper(helper); @@ -99,28 +100,26 @@ GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, GenTree* arg #endif // !TARGET_64BIT #endif // FEATURE_MULTIREG_RET - if (tree->OperMayThrow(this)) + if (call->OperMayThrow(this)) { - tree->gtFlags |= GTF_EXCEPT; + call->gtFlags |= GTF_EXCEPT; } else { - tree->gtFlags &= ~GTF_EXCEPT; + call->gtFlags &= ~GTF_EXCEPT; } - tree->gtFlags |= GTF_CALL; + call->gtFlags |= GTF_CALL; - if (arg1 != nullptr) + if (arg2 != nullptr) { - CallArg* carg1 = tree->AsCall()->gtArgs.PushFront(this, arg1); - if (arg2 != nullptr) - { - tree->AsCall()->gtArgs.InsertAfter(this, carg1, arg2); - } + call->gtArgs.PushFront(this, arg2); + call->gtFlags |= arg2->gtFlags & GTF_ALL_EFFECT; } - for (CallArg& arg : tree->AsCall()->gtArgs.Args()) + if (arg1 != nullptr) { - tree->gtFlags |= (arg.GetEarlyNode()->gtFlags & GTF_ALL_EFFECT); + call->gtArgs.PushFront(this, arg1); + call->gtFlags |= arg1->gtFlags & GTF_ALL_EFFECT; } // Perform the morphing @@ -571,6 +570,10 @@ GenTree* Compiler::fgMorphExpandCast(GenTreeCast* tree) } #ifdef DEBUG + +//------------------------------------------------------------------------ +// getWellKnownArgName: Get a string representation of a WellKnownArg. +// const char* getWellKnownArgName(WellKnownArg arg) { switch (arg) @@ -612,6 +615,9 @@ const char* getWellKnownArgName(WellKnownArg arg) } } +//------------------------------------------------------------------------ +// Dump: Dump information about a CallArg to jitstdout. +// void CallArg::Dump(Compiler* comp) { printf("CallArg[arg %u", AbiInfo.ArgNum); @@ -681,6 +687,17 @@ void CallArg::Dump(Compiler* comp) } #endif +//------------------------------------------------------------------------ +// SplitArg: +// Record that the arg will be split over registers and stack, increasing the +// current stack usage. +// +// Parameters: +// arg - The argument. +// numRegs - The number of registers that will be used. +// numSlots - The number of stack slots that will be used. +// nextSlotNum - Pointer to current stack slot, used for debugging purposes. +// void CallArgs::SplitArg(CallArg* arg, unsigned numRegs, unsigned numSlots, unsigned* nextSlotNum) { assert(numRegs > 0); @@ -706,12 +723,18 @@ void CallArgs::SplitArg(CallArg* arg, unsigned numRegs, unsigned numSlots, unsig m_nextStackByteOffset += numSlots * TARGET_POINTER_SIZE; } +//------------------------------------------------------------------------ +// SetTemp: Set that the specified argument was evaluated into a temp. +// void CallArgs::SetTemp(CallArg* arg, unsigned tmpNum) { arg->m_tmpNum = tmpNum; arg->m_isTmp = true; } +//------------------------------------------------------------------------ +// ArgsComplete: Make final decisions on which arguments to evaluate into temporaries. +// void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) { bool hasStructRegArg = false; @@ -1071,6 +1094,9 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) m_argsComplete = true; } +//------------------------------------------------------------------------ +// SortArgs: Sort arguments into a better passing order. +// void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) { assert(m_argsComplete); @@ -1374,17 +1400,13 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) } //------------------------------------------------------------------------------ -// fgMakeTmpArgNode : This function creates a tmp var only if needed. -// We need this to be done in order to enforce ordering -// of the evaluation of arguments. -// -// Arguments: -// comp -// arg +// MakeTmpArgNode: +// Create a temp for an argument if needed. We usually need this to be done +// in order to enforce ordering of the evaluation of arguments. // // Return Value: // the newly created temp var tree. - +// GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) { unsigned tmpVarNum = arg->m_tmpNum; @@ -1496,6 +1518,32 @@ GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) return argNode; } +//------------------------------------------------------------------------------ +// EvalArgsToTemps: Handle arguments that were marked as requiring temps. +// +// Remarks: +// This is the main function responsible for assigning late nodes in arguments. +// After this function we may have the following shapes of early and late +// nodes in arguments: +// 1. Early: GT_ASG, Late: GT_LCL_VAR. +// When the argument needs to be evaluated early because it has side +// effects it will be assigned to a temp in the early node and passed as +// the local in the late node. This can happen for both register and +// stack args. +// +// 2. Early: GT_ARGPLACE, Late: +// All arguments that are placed in registers need to appear as a late +// node. Some stack arguments may also require this pattern, for example +// if a later argument trashes the outgoing arg area by requiring a +// call. +// If the argument does not otherwise need to be evaluated into a temp +// (because it does not have side effects), we create just a placeholder +// GT_ARGPLACE for the early list and move it into the late list. +// +// 3. Early: , Late: no node +// Arguments that are passed on stack and that do not need early +// evaluation do not require any late node. +// void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) { assert(m_argsSorted); @@ -1769,6 +1817,9 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) #endif } +//------------------------------------------------------------------------------ +// SetNeedsTemp: Set the specified argument as requiring evaluation into a temp. +// void CallArgs::SetNeedsTemp(CallArg* arg) { arg->m_needTmp = true; @@ -1853,6 +1904,9 @@ GenTree* Compiler::fgInsertCommaFormTemp(GenTree** ppTree, CORINFO_CLASS_HANDLE return new (this, GT_LCL_VAR) GenTreeLclVar(GT_LCL_VAR, subTree->TypeGet(), lclNum); } +// Determine argument ABI information. +// TODO-ARGS: This is equivalent to old fgInitArgInfo and thus may add arguments. +// Refactor this to be idempotent. void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) { assert(&call->gtArgs == this); @@ -2875,28 +2929,28 @@ unsigned CallArgs::CountArgs() // information for the call. If it has already been determined, that method // will simply return. // -// This method changes the state of the call node. It uses the existence -// of gtCallLateArgs (the late arguments list) to determine if it has -// already done the first round of morphing. +// This method changes the state of the call node. It may be called even +// after it has already done the first round of morphing. // // The first time it is called (i.e. during global morphing), this method // computes the "late arguments". This is when it determines which arguments // need to be evaluated to temps prior to the main argument setup, and which // can be directly evaluated into the argument location. It also creates a -// second argument list (gtCallLateArgs) that does the final placement of the +// second argument list (the late args) that does the final placement of the // arguments, e.g. into registers or onto the stack. // -// The "non-late arguments", aka the gtCallArgs, are doing the in-order -// evaluation of the arguments that might have side-effects, such as embedded -// assignments, calls or possible throws. In these cases, it and earlier -// arguments must be evaluated to temps. +// The "non-late arguments", are doing the in-order evaluation of the +// arguments that might have side-effects, such as embedded assignments, +// calls or possible throws. In these cases, it and earlier arguments must +// be evaluated to temps. // // On targets with a fixed outgoing argument area (FEATURE_FIXED_OUT_ARGS), // if we have any nested calls, we need to defer the copying of the argument -// into the fixed argument area until after the call. If the argument did not -// otherwise need to be computed into a temp, it is moved to gtCallLateArgs and -// replaced in the "early" arg list (gtCallArgs) with a placeholder node. - +// into the fixed argument area until after the call. If the argument did +// not otherwise need to be computed into a temp, it is moved to late +// argument and replaced in the "early" arg list with a placeholder node. +// Also see `CallArgs::EvalArgsToTemps`. +// #ifdef _PREFAST_ #pragma warning(push) #pragma warning(disable : 21000) // Suppress PREFast warning about overly large function @@ -3533,11 +3587,11 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) // morph the argument as needed to be passed correctly. // // Arguments: -// arg - The argument +// arg - The argument containing a struct node. // // Notes: -// The arg must be a GT_OBJ or GT_LCL_VAR or GT_LCL_FLD of TYP_STRUCT. -// If 'arg' is a lclVar passed on the stack, we will ensure that any lclVars that must be on the +// The arg node must be a GT_OBJ or GT_LCL_VAR or GT_LCL_FLD of TYP_STRUCT. +// If arg node is a lclVar passed on the stack, we will ensure that any lclVars that must be on the // stack are marked as doNotEnregister, and then we return. // // If it is passed by register, we mutate the argument into the GT_FIELD_LIST form @@ -10692,7 +10746,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) } } - return fgMorphIntoHelperCall(tree, helper, op1, op2); + return fgMorphIntoHelperCall(tree, helper, true, op1, op2); case GT_RETURN: if (!tree->TypeIs(TYP_VOID)) @@ -15801,8 +15855,8 @@ GenTree* Compiler::fgInitThisClass() // CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE with a zeroed out resolvedToken means "get the static // base of the class that owns the method being compiled". If we're in this method, it means we're not // inlining and there's no ambiguity. - return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, TYP_BYREF, - ctxTree, &kind); + return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, TYP_BYREF, &kind, + ctxTree); } #endif diff --git a/src/coreclr/jit/objectalloc.cpp b/src/coreclr/jit/objectalloc.cpp index 4dfbc03616912f..c0300dcc9639ce 100644 --- a/src/coreclr/jit/objectalloc.cpp +++ b/src/coreclr/jit/objectalloc.cpp @@ -464,7 +464,7 @@ GenTree* ObjectAllocator::MorphAllocObjNodeIntoHelperCall(GenTreeAllocObj* alloc #endif const bool morphArgs = false; - GenTree* helperCall = comp->fgMorphIntoHelperCall(allocObj, allocObj->gtNewHelper, arg, nullptr, morphArgs); + GenTree* helperCall = comp->fgMorphIntoHelperCall(allocObj, allocObj->gtNewHelper, morphArgs, arg); if (helperHasSideEffects) { helperCall->AsCall()->gtCallMoreFlags |= GTF_CALL_M_ALLOC_SIDE_EFFECTS; diff --git a/src/coreclr/jit/rationalize.cpp b/src/coreclr/jit/rationalize.cpp index 3b32f88a4e55bd..095529cc785658 100644 --- a/src/coreclr/jit/rationalize.cpp +++ b/src/coreclr/jit/rationalize.cpp @@ -209,13 +209,16 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use, // Create the call node GenTreeCall* call = comp->gtNewCallNode(CT_USER_FUNC, callHnd, tree->gtType); + if (arg2 != nullptr) + { + call->gtArgs.PushFront(comp, arg2); + call->gtFlags |= arg2->gtFlags & GTF_ALL_EFFECT; + } + if (arg1 != nullptr) { - CallArg* carg1 = call->gtArgs.PushFront(comp, arg1); - if (arg2 != nullptr) - { - call->gtArgs.InsertAfter(comp, carg1, arg2); - } + call->gtArgs.PushFront(comp, arg1); + call->gtFlags |= arg1->gtFlags & GTF_ALL_EFFECT; } #if DEBUG From 997cade420584f51ce69a0e700bb6d68d1795258 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 18:27:24 +0200 Subject: [PATCH 38/52] Run jit-format --- src/coreclr/jit/flowgraph.cpp | 9 ++++----- src/coreclr/jit/gentree.cpp | 4 ++-- src/coreclr/jit/importer.cpp | 20 ++++++++++---------- src/coreclr/jit/lower.cpp | 2 +- src/coreclr/jit/morph.cpp | 8 ++++---- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 73447ea5b851e9..636f86bf417926 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1141,14 +1141,14 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); - GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); - CORINFO_LOOKUP pLookup; + GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); + GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); + CORINFO_LOOKUP pLookup; info.compCompHnd->getReadyToRunDelegateCtorHelper(&ldftnToken->m_token, ldftnToken->m_tokenConstraint, clsHnd, &pLookup); if (!pLookup.lookupKind.needsRuntimeLookup) { - call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, + call = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, TYP_VOID, thisPointer, targetObjPointers); call->setEntryPoint(pLookup.constLookup); } @@ -1163,7 +1163,6 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, targetObjPointers, ctxTree); call->setEntryPoint(genericLookup); } - } else { diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index b561b6e626c709..ad799d11bef5f4 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1117,7 +1117,7 @@ void CallArgABIInformation::SetByteSize(unsigned byteSize, unsigned byteAlignmen assert(roundedByteSize == GetSlotCount() * TARGET_POINTER_SIZE); } #endif - ByteSize = roundedByteSize; + ByteSize = roundedByteSize; ByteAlignment = byteAlignment; } @@ -1157,7 +1157,7 @@ unsigned CallArgABIInformation::GetSlotCount() const // // Returns: // The size of the argument, normalized to TARGET_POINTER_SIZE stack slots. -// +// // Remarks: // Unlike GetSlotCount() this function applies normalization and returns the // answer in terms of TARGET_POINTER_SIZE slots. diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 23a59e2ec90186..445d1e7c4ddd5a 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -2103,12 +2103,11 @@ bool Compiler::impIsCastHelperMayHaveProfileData(CorInfoHelpFunc helper) return false; } -GenTreeCall* Compiler::impReadyToRunHelperToTree( - CORINFO_RESOLVED_TOKEN* pResolvedToken, - CorInfoHelpFunc helper, - var_types type, - CORINFO_LOOKUP_KIND* pGenericLookupKind, - GenTree* arg1) +GenTreeCall* Compiler::impReadyToRunHelperToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken, + CorInfoHelpFunc helper, + var_types type, + CORINFO_LOOKUP_KIND* pGenericLookupKind, + GenTree* arg1) { CORINFO_CONST_LOOKUP lookup; if (!info.compCompHnd->getReadyToRunHelper(pResolvedToken, pGenericLookupKind, helper, &lookup)) @@ -11705,8 +11704,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // const CorInfoHelpFunc specialHelper = CORINFO_HELP_CHKCASTCLASS_SPECIAL; - condTrue = - gtNewHelperCallNode(specialHelper, TYP_REF, partialExpand ? op2 : op2Var, gtClone(op1)); + condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, partialExpand ? op2 : op2Var, gtClone(op1)); } else if (partialExpand) { @@ -15787,7 +15785,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) #ifdef FEATURE_READYTORUN if (opts.IsReadyToRun()) { - op1 = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_NEWARR_1, TYP_REF, nullptr, op2); + op1 = impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_NEWARR_1, TYP_REF, nullptr, + op2); usingReadyToRunHelper = (op1 != nullptr); if (!usingReadyToRunHelper) @@ -16499,7 +16498,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) if (opts.IsReadyToRun()) { GenTreeCall* opLookup = - impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_CHKCAST, TYP_REF, nullptr, op1); + impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_CHKCAST, TYP_REF, nullptr, + op1); usingReadyToRunHelper = (opLookup != nullptr); op1 = (usingReadyToRunHelper ? opLookup : op1); diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index dce652eb008224..7ddace4c0f508e 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -4357,7 +4357,7 @@ void Lowering::InsertPInvokeMethodProlog() GenTreeCall* call = comp->gtNewHelperCallNode(CORINFO_HELP_INIT_PINVOKE_FRAME, TYP_I_IMPL); call->gtArgs.PushBack(comp, frameAddr, WellKnownArg::PInvokeFrame); - // for x86/arm32 don't pass the secretArg. +// for x86/arm32 don't pass the secretArg. #if !defined(TARGET_X86) && !defined(TARGET_ARM) call->gtArgs.PushBack(comp, PhysReg(REG_SECRET_STUB_PARAM), WellKnownArg::SecretStubParam); #endif diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 1c9148c0320a0d..ba0cc5f6c77ac9 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -62,7 +62,7 @@ GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, bool morphAr // The helper call ought to be semantically equivalent to the original node, so preserve its VN. tree->ChangeOper(GT_CALL, GenTree::PRESERVE_VN); - GenTreeCall* call = tree->AsCall(); + GenTreeCall* call = tree->AsCall(); // Args are cleared by ChangeOper above call->gtCallType = CT_HELPER; call->gtReturnType = tree->TypeGet(); @@ -2950,7 +2950,7 @@ unsigned CallArgs::CountArgs() // not otherwise need to be computed into a temp, it is moved to late // argument and replaced in the "early" arg list with a placeholder node. // Also see `CallArgs::EvalArgsToTemps`. -// +// #ifdef _PREFAST_ #pragma warning(push) #pragma warning(disable : 21000) // Suppress PREFast warning about overly large function @@ -15855,8 +15855,8 @@ GenTree* Compiler::fgInitThisClass() // CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE with a zeroed out resolvedToken means "get the static // base of the class that owns the method being compiled". If we're in this method, it means we're not // inlining and there's no ambiguity. - return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, TYP_BYREF, &kind, - ctxTree); + return impReadyToRunHelperToTree(&resolvedToken, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, TYP_BYREF, + &kind, ctxTree); } #endif From 6fb43d1c9b169d658f3c29d6df7244ecab100948 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 20:47:05 +0200 Subject: [PATCH 39/52] Assertion fix --- src/coreclr/jit/gentree.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index ad799d11bef5f4..9828c8e3c88e95 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1107,8 +1107,8 @@ void CallArgABIInformation::SetByteSize(unsigned byteSize, unsigned byteAlignmen #if !defined(TARGET_ARM) // Arm32 could have a struct with 8 byte alignment // which rounded size % 8 is not 0. - assert(ByteAlignment != 0); - assert(roundedByteSize % ByteAlignment == 0); + assert(byteAlignment != 0); + assert(roundedByteSize % byteAlignment == 0); #endif // TARGET_ARM #if defined(DEBUG_ARG_SLOTS) From 6dae1f6933b1b7e9e01d7e2276b09ec4e098d700 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 21:42:54 +0200 Subject: [PATCH 40/52] Fix for reordered parameters --- src/coreclr/jit/importer.cpp | 2 +- src/coreclr/jit/morph.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 445d1e7c4ddd5a..54a157c7491571 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -862,7 +862,7 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a #endif } - // NOTE: we defer bashing the type for I_IMPL to fgMorphArg + // NOTE: we defer bashing the type for I_IMPL to fgMorphArgs argList->PushFront(this, temp); } diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index ba0cc5f6c77ac9..650c247836f3b4 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -46,7 +46,7 @@ GenTree* Compiler::fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* ope noway_assert(tree->AsCast()->CastOp() == oper); noway_assert(tree->gtOper == GT_CAST); } - result = fgMorphIntoHelperCall(tree, helper, true, oper); + result = fgMorphIntoHelperCall(tree, helper, true /* morphArgs */, oper); assert(result == tree); return result; } @@ -10746,7 +10746,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) } } - return fgMorphIntoHelperCall(tree, helper, true, op1, op2); + return fgMorphIntoHelperCall(tree, helper, true /* morphArgs */, op1, op2); case GT_RETURN: if (!tree->TypeIs(TYP_VOID)) @@ -10876,9 +10876,9 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) switch (tree->TypeGet()) { case TYP_DOUBLE: - return fgMorphIntoHelperCall(tree, CORINFO_HELP_DBLROUND, op1); + return fgMorphIntoHelperCall(tree, CORINFO_HELP_DBLROUND, true /* morphArgs */, op1); case TYP_FLOAT: - return fgMorphIntoHelperCall(tree, CORINFO_HELP_FLTROUND, op1); + return fgMorphIntoHelperCall(tree, CORINFO_HELP_FLTROUND, true /* morphArgs */, op1); default: unreached(); } From 9a3eefff7be05bb80ddd1ea5147058fd4f22114b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 3 Apr 2022 23:06:02 +0200 Subject: [PATCH 41/52] Fix silly mistake --- src/coreclr/jit/codegencommon.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index f4924fe3bcfe8f..4746eb13971436 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6452,8 +6452,11 @@ regNumber CodeGen::getCallIndirectionCellReg(GenTreeCall* call) } #ifdef DEBUG - CallArg* indirCellArg = call->gtArgs.FindWellKnownArg(call->GetIndirectionCellArgKind()); - assert((indirCellArg != nullptr) && (indirCellArg->AbiInfo.GetRegNum() == result)); + if (call->GetIndirectionCellArgKind() != WellKnownArg::None) + { + CallArg* indirCellArg = call->gtArgs.FindWellKnownArg(call->GetIndirectionCellArgKind()); + assert((indirCellArg != nullptr) && (indirCellArg->AbiInfo.GetRegNum() == result)); + } #endif return result; From 51061a472e76d48adcea682d8b3ffadb98218d24 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 10 Apr 2022 01:32:40 +0200 Subject: [PATCH 42/52] Fix build --- src/coreclr/jit/earlyprop.cpp | 54 ----------------------------------- src/coreclr/jit/gentree.cpp | 23 +++++++-------- src/coreclr/jit/morph.cpp | 6 ++-- 3 files changed, 14 insertions(+), 69 deletions(-) diff --git a/src/coreclr/jit/earlyprop.cpp b/src/coreclr/jit/earlyprop.cpp index 2de267e6ad542e..2424e89b2878cc 100644 --- a/src/coreclr/jit/earlyprop.cpp +++ b/src/coreclr/jit/earlyprop.cpp @@ -29,60 +29,6 @@ bool Compiler::optDoEarlyPropForBlock(BasicBlock* block) return bbHasArrayRef || bbHasNullCheck; } -//------------------------------------------------------------------------------ -// getArrayLengthFromAllocation: Return the array length for an array allocation -// helper call. -// -// Arguments: -// tree - The array allocation helper call. -// block - tree's basic block. -// -// Return Value: -// Return the array length node. - -GenTree* Compiler::getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBlock* block)) -{ - assert(tree != nullptr); - - GenTree* arrayLength = nullptr; - - if (tree->OperGet() == GT_CALL) - { - GenTreeCall* call = tree->AsCall(); - - if (call->gtCallType == CT_HELPER) - { - if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_NEWARR_1_DIRECT) || - call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_NEWARR_1_OBJ) || - call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_NEWARR_1_VC) || - call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_NEWARR_1_ALIGN8)) - { - // This is an array allocation site. Grab the array length node. - arrayLength = call->gtArgs.GetArgByIndex(1)->GetNode(); - } - else if (call->gtCallMethHnd == eeFindHelper(CORINFO_HELP_READYTORUN_NEWARR_1)) - { - // On arm when compiling on certain platforms for ready to run, a handle will be - // inserted before the length. To handle this case, we will grab the last argument - // as that's always the length. See DetermineABIArgInformation for where the handle is inserted. - for (CallArg& arg : call->gtArgs.Args()) - { - arrayLength = arg.GetNode(); - } - } -#ifdef DEBUG - if (arrayLength != nullptr) - { - optCheckFlagsAreSet(OMF_HAS_NEWARRAY, "OMF_HAS_NEWARRAY", BBF_HAS_NEWARRAY, "BBF_HAS_NEWARRAY", tree, - block); - } -#endif - } - } - - return arrayLength; -} - #ifdef DEBUG //----------------------------------------------------------------------------- // optCheckFlagsAreSet: Check that the method flag and the basic block flag are set. diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 02deb9227bce97..d8e4fdd1a726c5 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1900,12 +1900,6 @@ GenTree* Compiler::getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBloc if (tree->OperGet() == GT_CALL) { GenTreeCall* call = tree->AsCall(); - if (call->fgArgInfo == nullptr) - { - // Currently this function is only profitable during the late stages - // so we avoid complicating below code to access the early args. - return nullptr; - } if (call->gtCallType == CT_HELPER) { @@ -1917,17 +1911,22 @@ GenTree* Compiler::getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBloc case CORINFO_HELP_NEWARR_1_ALIGN8: { // This is an array allocation site. Grab the array length node. - arrayLength = gtArgEntryByArgNum(call, 1)->GetNode(); + arrayLength = call->gtArgs.GetArgByIndex(1)->GetNode(); break; } case CORINFO_HELP_READYTORUN_NEWARR_1: { - // On arm when compiling on certain platforms for ready to run, a handle will be - // inserted before the length. To handle this case, we will grab the last argument - // as that's always the length. See fgInitArgInfo for where the handle is inserted. - int arrLenArgNum = call->fgArgInfo->ArgCount() - 1; - arrayLength = gtArgEntryByArgNum(call, arrLenArgNum)->GetNode(); + // On arm when compiling on certain platforms for ready to + // run, a handle will be inserted before the length. To + // handle this case, we will grab the last argument as + // that's always the length. See + // CallArgs::DetermineArgABIInformation for where the + // handle is inserted. + for (CallArg& arg : call->gtArgs.Args()) + { + arrayLength = arg.GetNode(); + } break; } diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index dee94c9f43e504..4e50dc8aa9c57a 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -2460,9 +2460,9 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) assert(argx == arg.GetEarlyNode()); assert(structSize != 0); - structPassingKind howToPassStruct; + Compiler::structPassingKind howToPassStruct; structBaseType = comp->getArgTypeForStruct(objClass, &howToPassStruct, callIsVararg, structSize); - passStructByRef = (howToPassStruct == SPK_ByReference); + passStructByRef = (howToPassStruct == Compiler::SPK_ByReference); #if defined(TARGET_LOONGARCH64) if (!passStructByRef) { @@ -2499,7 +2499,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) byteSize = TARGET_POINTER_SIZE; } #else - if (howToPassStruct == SPK_ByReference) + if (howToPassStruct == Compiler::SPK_ByReference) { byteSize = TARGET_POINTER_SIZE; } From b79f2f7d966d1784af4d5ef8d4dae9f3c52b9268 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 10 Apr 2022 20:56:13 +0200 Subject: [PATCH 43/52] Fix LA64 --- src/coreclr/jit/codegenloongarch64.cpp | 29 +++++++-------- src/coreclr/jit/gentree.h | 9 +++++ src/coreclr/jit/lsraloongarch64.cpp | 29 ++++++--------- src/coreclr/jit/morph.cpp | 51 ++++++++++++++------------ 4 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/coreclr/jit/codegenloongarch64.cpp b/src/coreclr/jit/codegenloongarch64.cpp index afe5b0b95d5bd9..938ff59f23bf3a 100644 --- a/src/coreclr/jit/codegenloongarch64.cpp +++ b/src/coreclr/jit/codegenloongarch64.cpp @@ -5774,9 +5774,9 @@ void CodeGen::genPutArgStk(GenTreePutArgStk* treeNode) unsigned argOffsetOut = treeNode->getArgOffset(); #ifdef DEBUG - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(treeNode->gtCall, treeNode); - assert(curArgTabEntry != nullptr); - DEBUG_ARG_SLOTS_ASSERT(argOffsetOut == (curArgTabEntry->slotNum * TARGET_POINTER_SIZE)); + CallArg* callArg = treeNode->gtCall->gtArgs.FindByNode(treeNode); + assert(callArg != nullptr); + DEBUG_ARG_SLOTS_ASSERT(argOffsetOut == (callArg->AbiInfo.SlotNum * TARGET_POINTER_SIZE)); #endif // DEBUG // Whether to setup stk arg in incoming or out-going arg area? @@ -7112,17 +7112,15 @@ void CodeGen::genCodeForLoadOffset(instruction ins, emitAttr size, regNumber dst void CodeGen::genCall(GenTreeCall* call) { // Consume all the arg regs - for (GenTreeCall::Use& use : call->LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - GenTree* argNode = use.GetNode(); - - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, argNode); - assert(curArgTabEntry); + CallArgABIInformation& abiInfo = arg.AbiInfo; + GenTree* argNode = arg.GetLateNode(); // GT_RELOAD/GT_COPY use the child node argNode = argNode->gtSkipReloadOrCopy(); - if (curArgTabEntry->GetRegNum() == REG_STK) + if (abiInfo.GetRegNum() == REG_STK) { continue; } @@ -7130,7 +7128,7 @@ void CodeGen::genCall(GenTreeCall* call) // Deal with multi register passed struct args. if (argNode->OperGet() == GT_FIELD_LIST) { - regNumber argReg = curArgTabEntry->GetRegNum(); + regNumber argReg = abiInfo.GetRegNum(); for (GenTreeFieldList::Use& use : argNode->AsFieldList()->Uses()) { GenTree* putArgRegNode = use.GetNode(); @@ -7143,13 +7141,13 @@ void CodeGen::genCall(GenTreeCall* call) argReg = genRegArgNext(argReg); } } - else if (curArgTabEntry->IsSplit()) + else if (abiInfo.IsSplit()) { NYI("unimplemented on LOONGARCH64 yet"); } else { - regNumber argReg = curArgTabEntry->GetRegNum(); + regNumber argReg = abiInfo.GetRegNum(); genConsumeReg(argNode); var_types dstType = emitter::isFloatReg(argReg) ? TYP_DOUBLE : TYP_I_IMPL; inst_Mov(dstType, argReg, argNode->GetRegNum(), /* canSkip */ true); @@ -7350,12 +7348,11 @@ void CodeGen::genCallInstruction(GenTreeCall* call) trashedByEpilog |= genRegMask(REG_GSCOOKIE_TMP_1); } - for (unsigned i = 0; i < call->fgArgInfo->ArgCount(); i++) + for (CallArg& arg : call->gtArgs.Args()) { - fgArgTabEntry* entry = call->fgArgInfo->GetArgEntry(i); - for (unsigned j = 0; j < entry->numRegs; j++) + for (unsigned j = 0; j < arg.AbiInfo.NumRegs; j++) { - regNumber reg = entry->GetRegNum(j); + regNumber reg = arg.AbiInfo.GetRegNum(j); if ((trashedByEpilog & genRegMask(reg)) != 0) { JITDUMP("Tail call node:\n"); diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 4c683351153398..6753b0cdc96fe0 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4024,6 +4024,9 @@ struct CallArgABIInformation , StructIntRegs(0) , StructFloatRegs(0) #endif +#ifdef TARGET_LOONGARCH64 + , StructFloatFieldType() +#endif #ifdef DEBUG_ARG_SLOTS , SlotNum(0) , NumSlots(0) @@ -4069,6 +4072,12 @@ struct CallArgABIInformation unsigned StructFloatRegs; SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR StructDesc; #endif // UNIX_AMD64_ABI +#ifdef TARGET_LOONGARCH64 + // For LoongArch64's ABI, the struct which has float field(s) and no more than two fields + // may be passed by float register(s). + // e.g `struct {int a; float b;}` passed by an integer register and a float register. + var_types StructFloatFieldType[2]; +#endif #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 diff --git a/src/coreclr/jit/lsraloongarch64.cpp b/src/coreclr/jit/lsraloongarch64.cpp index 2f259f7efffbdd..74303dbd9d0080 100644 --- a/src/coreclr/jit/lsraloongarch64.cpp +++ b/src/coreclr/jit/lsraloongarch64.cpp @@ -850,22 +850,19 @@ int LinearScan::BuildCall(GenTreeCall* call) // Each register argument corresponds to one source. bool callHasFloatRegArgs = false; - for (GenTreeCall::Use& arg : call->LateArgs()) + for (CallArg& arg : call->gtArgs.LateArgs()) { - GenTree* argNode = arg.GetNode(); + CallArgABIInformation& abiInfo = arg.AbiInfo; + GenTree* argNode = arg.GetLateNode(); #ifdef DEBUG - // During Build, we only use the ArgTabEntry for validation, - // as getting it is rather expensive. - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, argNode); - regNumber argReg = curArgTabEntry->GetRegNum(); - assert(curArgTabEntry != nullptr); + regNumber argReg = abiInfo.GetRegNum(); #endif if (argNode->gtOper == GT_PUTARG_STK) { // late arg that is not passed in a register - assert(curArgTabEntry->GetRegNum() == REG_STK); + assert(abiInfo.GetRegNum() == REG_STK); // These should never be contained. assert(!argNode->isContained()); continue; @@ -921,27 +918,25 @@ int LinearScan::BuildCall(GenTreeCall* call) // because the code generator doesn't actually consider it live, // so it can't be spilled. - for (GenTreeCall::Use& use : call->Args()) + for (CallArg& arg : call->gtArgs.Args()) { - GenTree* arg = use.GetNode(); + GenTree* argNode = arg.GetEarlyNode(); // Skip arguments that have been moved to the Late Arg list - if ((arg->gtFlags & GTF_LATE_ARG) == 0) + if ((argNode->gtFlags & GTF_LATE_ARG) == 0) { - fgArgTabEntry* curArgTabEntry = compiler->gtArgEntryByNode(call, arg); - assert(curArgTabEntry != nullptr); #if FEATURE_ARG_SPLIT // PUTARG_SPLIT nodes must be in the gtCallLateArgs list, since they // define registers used by the call. - assert(arg->OperGet() != GT_PUTARG_SPLIT); + assert(argNode->OperGet() != GT_PUTARG_SPLIT); #endif // FEATURE_ARG_SPLIT - if (arg->gtOper == GT_PUTARG_STK) + if (argNode->gtOper == GT_PUTARG_STK) { - assert(curArgTabEntry->GetRegNum() == REG_STK); + assert(arg.AbiInfo.GetRegNum() == REG_STK); } else { - assert(!arg->IsValue() || arg->IsUnusedValue()); + assert(!argNode->IsValue() || argNode->IsUnusedValue()); } } } diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 4e50dc8aa9c57a..8d75056896010c 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -1659,7 +1659,7 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) // two FP registers). // TODO-LoongArch64: fix "getPrimitiveTypeForStruct" or use the ABI information in // the arg entry instead of calling it here. - if ((lclVarType == TYP_STRUCT) && (curArgTabEntry->numRegs == 1)) + if ((lclVarType == TYP_STRUCT) && (arg.AbiInfo.NumRegs == 1)) #else if (lclVarType == TYP_STRUCT) #endif @@ -2466,12 +2466,12 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) #if defined(TARGET_LOONGARCH64) if (!passStructByRef) { - assert((howToPassStruct == SPK_ByValue) || (howToPassStruct == SPK_PrimitiveType)); + assert((howToPassStruct == Compiler::SPK_ByValue) || (howToPassStruct == Compiler::SPK_PrimitiveType)); floatFieldFlags = comp->info.compCompHnd->getLoongArch64PassStructInRegisterFlags(objClass); passUsingFloatRegs = (floatFieldFlags & STRUCT_HAS_FLOAT_FIELDS_MASK) ? true : false; - compFloatingPointUsed |= passUsingFloatRegs; + comp->compFloatingPointUsed |= passUsingFloatRegs; if ((floatFieldFlags & (STRUCT_HAS_FLOAT_FIELDS_MASK ^ STRUCT_FLOAT_FIELD_ONLY_ONE)) != 0) { @@ -2855,10 +2855,8 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) : genMapIntRegArgNumToRegNum(intArgRegNum); } -#ifdef TARGET_AMD64 -#ifndef UNIX_AMD64_ABI +#ifdef WINDOWS_AMD64_ABI assert(size == 1); -#endif #endif // This is a register argument @@ -2869,19 +2867,24 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) #ifdef UNIX_AMD64_ABI arg.AbiInfo.StructIntRegs = structIntRegs; arg.AbiInfo.StructFloatRegs = structFloatRegs; - assert(size <= 2); - if (size == 2) - { - arg.AbiInfo.SetRegNum(1, nextOtherRegNum); - } if (isStructArg) { arg.AbiInfo.StructDesc.CopyFrom(structDesc); } +#endif + +#if defined(UNIX_AMD64_ABI) || defined(TARGET_LOONGARCH64) + assert(size <= 2); + + if (size == 2) + { + arg.AbiInfo.SetRegNum(1, nextOtherRegNum); + } INDEBUG(arg.CheckIsStruct()); #endif + arg.AbiInfo.IsBackFilled = isBackFilled; // Set up the next intArgRegNum and fltArgRegNum values. @@ -2889,7 +2892,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) { #if defined(TARGET_LOONGARCH64) // Increment intArgRegNum by 'size' registers - if (!isNonStandard) + if (nonStdRegNum == REG_NA) { if ((size > 1) && ((intArgRegNum + 1) == maxRegArgs) && (nextOtherRegNum == REG_STK)) { @@ -2912,7 +2915,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) { structBaseType = structSize == 8 ? TYP_DOUBLE : TYP_FLOAT; fltArgRegNum += 1; - newArgEntry->structFloatFieldType[0] = structBaseType; + arg.AbiInfo.StructFloatFieldType[0] = structBaseType; } else if ((floatFieldFlags & (STRUCT_FLOAT_FIELD_FIRST | STRUCT_FLOAT_FIELD_SECOND)) != 0) { @@ -2920,25 +2923,25 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) intArgRegNum += 1; if ((floatFieldFlags & STRUCT_FLOAT_FIELD_FIRST) != 0) { - newArgEntry->structFloatFieldType[0] = + arg.AbiInfo.StructFloatFieldType[0] = (floatFieldFlags & STRUCT_FIRST_FIELD_SIZE_IS8) ? TYP_DOUBLE : TYP_FLOAT; - newArgEntry->structFloatFieldType[1] = + arg.AbiInfo.StructFloatFieldType[1] = (floatFieldFlags & STRUCT_SECOND_FIELD_SIZE_IS8) ? TYP_LONG : TYP_INT; } else { - newArgEntry->structFloatFieldType[0] = + arg.AbiInfo.StructFloatFieldType[0] = (floatFieldFlags & STRUCT_FIRST_FIELD_SIZE_IS8) ? TYP_LONG : TYP_INT; - newArgEntry->structFloatFieldType[1] = + arg.AbiInfo.StructFloatFieldType[1] = (floatFieldFlags & STRUCT_SECOND_FIELD_SIZE_IS8) ? TYP_DOUBLE : TYP_FLOAT; } } else if ((floatFieldFlags & STRUCT_FLOAT_FIELD_ONLY_TWO) != 0) { fltArgRegNum += 2; - newArgEntry->structFloatFieldType[0] = + arg.AbiInfo.StructFloatFieldType[0] = (floatFieldFlags & STRUCT_FIRST_FIELD_SIZE_IS8) ? TYP_DOUBLE : TYP_FLOAT; - newArgEntry->structFloatFieldType[1] = + arg.AbiInfo.StructFloatFieldType[1] = (floatFieldFlags & STRUCT_SECOND_FIELD_SIZE_IS8) ? TYP_DOUBLE : TYP_FLOAT; } } @@ -3271,7 +3274,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) // For LoongArch64 the struct {float a; float b;} can be passed by two float registers. DEBUG_ARG_SLOTS_ASSERT((size == roundupSize / TARGET_POINTER_SIZE) || ((structBaseType == TYP_STRUCT) && (originalSize == TARGET_POINTER_SIZE) && - (size == 2) && (size == argEntry->numRegs))); + (size == 2) && (size == arg.AbiInfo.NumRegs))); #else // Check to see if we can transform this into load of a primitive type. // 'size' must be the number of pointer sized items @@ -3923,7 +3926,7 @@ GenTree* Compiler::fgMorphMultiregStructArg(CallArg* arg) // For LoongArch64's ABI, the struct which size is TARGET_POINTER_SIZE // may be passed by two registers. // e.g `struct {int a; float b;}` passed by an integer register and a float register. - if (fgEntryPtr->numRegs == 2) + if (arg->AbiInfo.NumRegs == 2) { elemCount = 2; } @@ -3939,10 +3942,10 @@ GenTree* Compiler::fgMorphMultiregStructArg(CallArg* arg) } else #elif defined(TARGET_LOONGARCH64) - if (varTypeIsFloating(fgEntryPtr->structFloatFieldType[inx]) || - (genTypeSize(fgEntryPtr->structFloatFieldType[inx]) == 4)) + if (varTypeIsFloating(arg->AbiInfo.StructFloatFieldType[inx]) || + (genTypeSize(arg->AbiInfo.StructFloatFieldType[inx]) == 4)) { - type[inx] = fgEntryPtr->structFloatFieldType[inx]; + type[inx] = arg->AbiInfo.StructFloatFieldType[inx]; } else #endif // TARGET_LOONGARCH64 From c08c4f17fa75c988cebebc51fa37efeaac597f8b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 10 Apr 2022 21:15:55 +0200 Subject: [PATCH 44/52] Minor formatting changes --- src/coreclr/jit/morph.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 8d75056896010c..f0a473ecc93016 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -611,9 +611,9 @@ const char* getWellKnownArgName(WellKnownArg arg) return "ValidateIndirectCallTarget"; case WellKnownArg::DispatchIndirectCallTarget: return "DispatchIndirectCallTarget"; - default: - return "N/A"; } + + return "N/A"; } //------------------------------------------------------------------------ @@ -1527,19 +1527,19 @@ GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) // After this function we may have the following shapes of early and late // nodes in arguments: // 1. Early: GT_ASG, Late: GT_LCL_VAR. -// When the argument needs to be evaluated early because it has side -// effects it will be assigned to a temp in the early node and passed as -// the local in the late node. This can happen for both register and -// stack args. +// When the argument needs to be evaluated early (e.g. because it has +// side effects, or because it is a struct copy that requires it) it +// will be assigned to a temp in the early node and passed as the local +// in the late node. This can happen for both register and stack args. // // 2. Early: GT_ARGPLACE, Late: // All arguments that are placed in registers need to appear as a late // node. Some stack arguments may also require this pattern, for example // if a later argument trashes the outgoing arg area by requiring a // call. -// If the argument does not otherwise need to be evaluated into a temp -// (because it does not have side effects), we create just a placeholder -// GT_ARGPLACE for the early list and move it into the late list. +// If the argument does not otherwise need to be evaluated into a temp , +// we create just a placeholder GT_ARGPLACE for the early list and move +// it into the late list. // // 3. Early: , Late: no node // Arguments that are passed on stack and that do not need early @@ -2102,10 +2102,14 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) // Add in this arg if (HasThisPointer()) + { maxRegArgs++; + } // Add in the ret buff arg if (callHasRetBuffArg) + { maxRegArgs++; + } } #endif // UNIX_X86_ABI @@ -3084,7 +3088,6 @@ unsigned CallArgs::OutgoingArgsStackSize() const { unsigned aligned = Compiler::GetOutgoingArgByteSize(m_nextStackByteOffset); return max(aligned, MIN_ARG_AREA_FOR_CALL); - ; } unsigned CallArgs::CountArgs() From e5e0e15912d8fc478d6fc0958200bc8ba9245558 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 10 Apr 2022 21:21:07 +0200 Subject: [PATCH 45/52] Rename DetermineArgABIInformation and friends Make it more clear that this actually adds arguments and modifies IR. --- src/coreclr/jit/gentree.cpp | 20 ++++++++++---------- src/coreclr/jit/gentree.h | 4 ++-- src/coreclr/jit/morph.cpp | 30 ++++++++++++++++++------------ 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index d8e4fdd1a726c5..ac106132c6e57e 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1262,7 +1262,7 @@ unsigned CallArgABIInformation::GetStackByteSize() const // Remarks: // These arguments must be removed if ABI information needs to be // reclassified by calling `DetermineArgABIInformation` as otherwise they -// will be readded. See `CallArgs::ResetArgABIInformation`. +// will be readded. See `CallArgs::ResetFinalArgsAndABIInfo`. // // Note that the 'late' here is separate from CallArg::GetLateNode and // friends. Late here refers to this being an argument that is added by morph @@ -1804,8 +1804,8 @@ void CallArgs::PushLateBack(CallArg* arg) // // Remarks: // This function cannot be used after morph. It will also invalidate ABI -// information, so it is expected that `CallArgs::DetermineArgABIInformation` -// was not called yet or that `CallArgs::ResetArgABIInformation` has been +// information, so it is expected that `CallArgs::AddFinalArgsAndDetermineABIInfo` +// was not called yet or that `CallArgs::ResetFinalArgsAndABIInfo` has been // called prior to this. // bool CallArgs::Remove(CallArg* arg) @@ -1921,7 +1921,7 @@ GenTree* Compiler::getArrayLengthFromAllocation(GenTree* tree DEBUGARG(BasicBloc // run, a handle will be inserted before the length. To // handle this case, we will grab the last argument as // that's always the length. See - // CallArgs::DetermineArgABIInformation for where the + // CallArgs::AddFinalArgsAndDetermineABIInfo for where the // handle is inserted. for (CallArg& arg : call->gtArgs.Args()) { @@ -2271,33 +2271,33 @@ bool GenTreeCall::Equals(GenTreeCall* c1, GenTreeCall* c2) } //-------------------------------------------------------------------------- -// ResetArgABIInformation: Reset ABI information classified for arguments, +// ResetFinalArgsAndABIInfo: Reset ABI information classified for arguments, // removing late-added arguments. // // Remarks: -// This function can be called between `CallArgs::DetermineArgABIInformation` +// This function can be called between `CallArgs::AddFinalArgsAndDetermineABIInfo` // and actually finishing the morphing of arguments. It cannot be called once // the arguments have finished morphing. // -void CallArgs::ResetArgABIInformation() +void CallArgs::ResetFinalArgsAndABIInfo() { if (!IsAbiInformationDetermined()) { return; } - // `CallArgs::DetermineArgABIInformation` not only sets up arg info, it + // `CallArgs::AddFinalArgsAndDetermineABIInfo` not only sets up arg info, it // also adds non-standard args to the IR, and we need to remove that extra // IR so it doesn't get added again. CallArg** link = &m_head; // We cannot handle this being called after fgMorphArgs, only between - // CallArgs::DetermineArgABIInformation and finishing args. + // CallArgs::AddFinalArgsAndDetermineABIInfo and finishing args. assert(!m_argsComplete); while ((*link) != nullptr) { - // Check if this is an argument added by DetermineArgABIInformation. + // Check if this is an argument added by AddFinalArgsAndDetermineABIInfo. if ((*link)->IsArgAddedLate()) { JITDUMP("Removing arg %s [%06u] to prepare for re-morphing call\n", diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 6753b0cdc96fe0..53e86436954fea 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4379,8 +4379,8 @@ class CallArgs PushFront(comp, node); } - void ResetArgABIInformation(); - void DetermineArgABIInformation(Compiler* comp, GenTreeCall* call); + void ResetFinalArgsAndABIInfo(); + void AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call); void ArgsComplete(Compiler* comp, GenTreeCall* call); void SortArgs(Compiler* comp, GenTreeCall* call); diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index f0a473ecc93016..2be3b9336f4609 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -1915,10 +1915,16 @@ GenTree* Compiler::fgInsertCommaFormTemp(GenTree** ppTree, CORINFO_CLASS_HANDLE return new (this, GT_LCL_VAR) GenTreeLclVar(GT_LCL_VAR, subTree->TypeGet(), lclNum); } -// Determine argument ABI information. -// TODO-ARGS: This is equivalent to old fgInitArgInfo and thus may add arguments. -// Refactor this to be idempotent. -void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) +// AddFinalArgsAndDetermineABIInfo: +// Add final arguments and determine the argument ABI information. +// +// Remarks: +// This adds the final "non-standard" arguments to the call and categorizes +// all the ABI information required for downstream JIT phases. This function +// modifies IR by adding certain non-standard arguments. For more information +// see CallArg::IsArgAddedLate and CallArgs::ResetFinalArgsAndABIInfo. +// +void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call) { assert(&call->gtArgs == this); unsigned argIndex = 0; @@ -3071,7 +3077,7 @@ void CallArgs::DetermineArgABIInformation(Compiler* comp, GenTreeCall* call) #ifdef DEBUG if (VERBOSE) { - JITDUMP("Args for call [%06u] %s after DetermineArgABIInformation:\n", comp->dspTreeID(call), + JITDUMP("Args for call [%06u] %s after AddFinalArgsAndDetermineABIInfo:\n", comp->dspTreeID(call), GenTree::OpName(call->gtOper)); for (CallArg& arg : Args()) { @@ -3113,7 +3119,7 @@ unsigned CallArgs::CountArgs() // node itself is re-created. // // Notes: -// This calls CallArgs::DetermineArgABIInformation to determine ABI +// This calls CallArgs::AddFinalArgsAndDetermineABIInfo to determine ABI // information for the call. If it has already been determined, that method // will simply return. // @@ -3151,7 +3157,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) bool reMorphing = call->gtArgs.AreArgsComplete(); - call->gtArgs.DetermineArgABIInformation(this, call); + call->gtArgs.AddFinalArgsAndDetermineABIInfo(this, call); JITDUMP("%sMorphing args for %d.%s:\n", (reMorphing) ? "Re" : "", call->gtTreeID, GenTree::OpName(call->gtOper)); // If we are remorphing, process the late arguments (which were determined by a previous caller). @@ -6263,7 +6269,7 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason) assert(!callee->gtArgs.AreArgsComplete()); - callee->gtArgs.DetermineArgABIInformation(this, callee); + callee->gtArgs.AddFinalArgsAndDetermineABIInfo(this, callee); unsigned calleeArgStackSize = 0; unsigned callerArgStackSize = info.compArgStackSize; @@ -7105,7 +7111,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) #ifdef TARGET_XARCH // We have already computed arg info to make the fast tailcall decision, but on X64 we now // have to pass the indirection cell, so redo arg info. - call->gtArgs.ResetArgABIInformation(); + call->gtArgs.ResetFinalArgsAndABIInfo(); #endif } @@ -7365,7 +7371,7 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call) // Force re-evaluating the argInfo. fgMorphTailCallViaJitHelper will modify the // argument list, invalidating the argInfo. - call->gtArgs.ResetArgABIInformation(); + call->gtArgs.ResetFinalArgsAndABIInfo(); } // Tail call via JIT helper: The VM can't use return address hijacking @@ -7515,7 +7521,7 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL // for non-standard args that we must get rid of. Get rid of that IR here // and do this first as it will 'expose' the retbuf as the first arg, which // we rely upon in fgCreateCallDispatcherAndGetResult. - call->gtArgs.ResetArgABIInformation(); + call->gtArgs.ResetFinalArgsAndABIInfo(); GenTree* callDispatcherAndGetResult = fgCreateCallDispatcherAndGetResult(call, help.hCallTarget, help.hDispatcher); @@ -8602,7 +8608,7 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) // ret temp // Force re-evaluating the argInfo as the return argument has changed. - call->gtArgs.ResetArgABIInformation(); + call->gtArgs.ResetFinalArgsAndABIInfo(); // Create a new temp. unsigned tmpNum = From 64c0ec123b7ba0d5311e35e38d11940c833776bc Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sun, 10 Apr 2022 21:23:13 +0200 Subject: [PATCH 46/52] Run jit-format --- src/coreclr/jit/codegenloongarch64.cpp | 2 +- src/coreclr/jit/emit.cpp | 2 +- src/coreclr/jit/lsraloongarch64.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/codegenloongarch64.cpp b/src/coreclr/jit/codegenloongarch64.cpp index 938ff59f23bf3a..7c731d68835793 100644 --- a/src/coreclr/jit/codegenloongarch64.cpp +++ b/src/coreclr/jit/codegenloongarch64.cpp @@ -7115,7 +7115,7 @@ void CodeGen::genCall(GenTreeCall* call) for (CallArg& arg : call->gtArgs.LateArgs()) { CallArgABIInformation& abiInfo = arg.AbiInfo; - GenTree* argNode = arg.GetLateNode(); + GenTree* argNode = arg.GetLateNode(); // GT_RELOAD/GT_COPY use the child node argNode = argNode->gtSkipReloadOrCopy(); diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index d342815d7b3bf9..dd17b6febd6109 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -8717,7 +8717,7 @@ cnsval_ssize_t emitter::emitGetInsSC(instrDesc* id) int adr = emitComp->lvaFrameAddress(varNum, &FPbased); int dsp = adr + offs; if (id->idIns() == INS_sub) - dsp = -dsp; + dsp = -dsp; #endif return dsp; } diff --git a/src/coreclr/jit/lsraloongarch64.cpp b/src/coreclr/jit/lsraloongarch64.cpp index 74303dbd9d0080..59fe99ddb678f8 100644 --- a/src/coreclr/jit/lsraloongarch64.cpp +++ b/src/coreclr/jit/lsraloongarch64.cpp @@ -853,10 +853,10 @@ int LinearScan::BuildCall(GenTreeCall* call) for (CallArg& arg : call->gtArgs.LateArgs()) { CallArgABIInformation& abiInfo = arg.AbiInfo; - GenTree* argNode = arg.GetLateNode(); + GenTree* argNode = arg.GetLateNode(); #ifdef DEBUG - regNumber argReg = abiInfo.GetRegNum(); + regNumber argReg = abiInfo.GetRegNum(); #endif if (argNode->gtOper == GT_PUTARG_STK) From 9b4003de71ec5c222d617df2885a226fbd1d28de Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 11 Apr 2022 14:28:29 +0200 Subject: [PATCH 47/52] Small documentation clean up --- docs/design/coreclr/jit/jit-call-morphing.md | 69 ++++++++++--------- docs/design/coreclr/jit/struct-abi.md | 3 +- src/coreclr/jit/compiler.h | 1 - src/coreclr/jit/morph.cpp | 23 +++---- .../JitBlue/Runtime_49078/Runtime_49078.cs | 6 +- 5 files changed, 52 insertions(+), 50 deletions(-) diff --git a/docs/design/coreclr/jit/jit-call-morphing.md b/docs/design/coreclr/jit/jit-call-morphing.md index 5c99ac2939125d..e39b2edf70d88c 100644 --- a/docs/design/coreclr/jit/jit-call-morphing.md +++ b/docs/design/coreclr/jit/jit-call-morphing.md @@ -43,18 +43,21 @@ call site and is created by the Importer when it sees a call in the IL. It is a used for internal calls that the JIT needs such as helper calls. Every `GT_CALL` node should have a `GTF_CALL` flag set on it. Nodes that may be implemented using a function call also should have the `GTF_CALL` flag set on them. The arguments for a single call -site are held by three fields in the `GenTreeCall`: `gtCallObjp`, `gtCallArgs`, and -`gtCallLateArgs`. The first one, `gtCallObjp`, contains the instance pointer ("this" -pointer) when you are calling a method that takes an instance pointer, otherwise it is -null. The `gtCallArgs` contains all of the normal arguments in a null terminated `GT_LIST` -format. When the `GenTreeCall` is first created the `gtCallLateArgs` is null and is -set up later when we call `fgMorphArgs()` during the global Morph of all nodes. To -accurately record and track all of the information about call site arguments we create -a `fgArgInfo` that records information and decisions that we make about how each argument -for this call site is handled. It has a dynamically sized array member `argTable` that -contains details about each argument. This per-argument information is contained in the -`fgArgTabEntry` struct. - +site are encapsulated in the `CallArgs` class. Every call has an instance of this class +in `GenTreeCall::gtArgs`. `CallArgs` contains two linked list of arguments: the "normal" +linked list, which can be enumerated via `CallArgs::Args`, and the "late" linked list, +enumerated via `CallArgs::LateArgs`. + +The normal linked list is a linked list of `CallArg` structures, in normal argument +order. When the `GenTreeCall` is first created the late args list is empty and is +set up later when we call `fgMorphArgs()` during the global Morph of all nodes. The short +explanation of why we need two lists is that we may need to force the correct evaluation +order of arguments and also architecture-specific ways of passing some arguments. See +below and the documentation of `fgMorphArgs` and `AddFinalArgsAndDetermineABIInfo` for +more information about late args. + +In addition to containing IR nodes, each `CallArg` entry also contains information about +how it was evaluated and ABI information describing how to pass it. `FEATURE_FIXED_OUT_ARGS` ----------------- @@ -77,9 +80,9 @@ calls for x86 but do not allow them for the other architectures. Rules for when Arguments must be evaluated into temp LclVars ----------------- -During the first Morph phase known as global Morph we call `fgArgInfo::ArgsComplete()` -after we have completed building the `argTable` for `fgArgInfo` struct. This method -applies the following rules: +During the first Morph phase known as global Morph we call `CallArgs::ArgsComplete()` +after we have completed determining ABI information for each arg. This method applies +the following rules: 1. When an argument is marked as containing an assignment using `GTF_ASG`, then we force all previous non-constant arguments to be evaluated into temps. This is very @@ -93,7 +96,7 @@ we force that argument and any previous argument that is marked with any of the area is marked as needing a placeholder temp using `needPlace`. 3. We force any arguments that use `localloc` to be evaluated into temps. 4. We mark any address taken locals with the `GTF_GLOB_REF` flag. For two special -cases we call `EvalToTmp()` and set up the temp in `fgMorphArgs`. `EvalToTmp` +cases we call `SetNeedsTemp()` and set up the temp in `fgMorphArgs`. `SetNeedsTemp` records the tmpNum used and sets `isTmp` so that we handle it like the other temps. The special cases are for `GT_MKREFANY` and for a `TYP_STRUCT` argument passed by value when we can't optimize away the extra copy. @@ -104,7 +107,7 @@ Rules use to determine the order of argument evaluation After calling `ArgsComplete()` the `SortArgs()` method is called to determine the optimal way to evaluate the arguments. This sorting controls the order that we place -the nodes in the `gtCallLateArgs` list. +the nodes in the late argument list. 1. We iterate over the arguments and move any constant arguments to be evaluated last and remove them from further consideration by marking them as processed. @@ -123,35 +126,35 @@ Evaluating Args into new LclVar temps and the creation of the LateArgs After calling `SortArgs()`, the `EvalArgsToTemps()` method is called to create the temp assignments and to populate the LateArgs list. -Arguments that are marked with `needTmp == true`. +For arguments that are marked as needing a temp: ----------------- 1. We create an assignment using `gtNewTempAssign`. This assignment replaces -the original argument in the `gtCallArgs` list. After we create the assignment -the argument is marked as `isTmp`. The new assignment is marked with the +the original argument in the early argument list. After we create the assignment +the argument is marked with `m_isTmp = true`. The new assignment is marked with the `GTF_LATE_ARG` flag. -2. Arguments that are already marked with `isTmp` are treated similarly as +2. Arguments that are already marked with `m_isTmp` are treated similarly as above except we don't create an assignment for them. -3. A `TYP_STRUCT` argument passed by value will have `isTmp` set to true +3. A `TYP_STRUCT` argument passed by value will have `m_isTmp` set to true and will use a `GT_COPYBLK` or a `GT_COPYOBJ` to perform the assignment of the temp. 4. The assignment node or the CopyBlock node is referred to as `arg1 SETUP` in the JitDump. -Argument that are marked with `needTmp == false`. +For arguments that are marked as not needing a temp: ----------------- 1. If this is an argument that is passed in a register, then the existing -node is moved to the `gtCallLateArgs` list and a new `GT_ARGPLACE` (placeholder) -node replaces it in the `gtArgList` list. -2. Additionally, if `needPlace` is true (only for `FEATURE_FIXED_OUT_ARGS`) -then the existing node is moved to the `gtCallLateArgs` list and a new -`GT_ARGPLACE` (placeholder) node replaces it in the `gtArgList` list. -3. Otherwise the argument is left in the `gtCallArgs` and it will be -evaluated into the outgoing arg area or pushed on the stack. +node is moved to the late argument list and a new `GT_ARGPLACE` (placeholder) +node replaces it in the early argument list. +2. Additionally, if `m_needPlace` is true (only for `FEATURE_FIXED_OUT_ARGS`) +then the existing node is moved to the late argument list and a new +`GT_ARGPLACE` (placeholder) node replaces it in the `early argument list. +3. Otherwise the argument is left in the early argument and it will be +evaluated directly into the outgoing arg area or pushed on the stack. After the Call node is fully morphed the LateArgs list will contain the arguments -passed in registers as well as additional ones for `needPlace` marked +passed in registers as well as additional ones for `m_needPlace` marked arguments whenever we have a nested call for a stack based argument. -When `needTmp` is true the LateArg will be a LclVar that was created -to evaluate the arg (single-def/single-use). When `needTmp` is false +When `m_needTmp` is true the LateArg will be a LclVar that was created +to evaluate the arg (single-def/single-use). When `m_needTmp` is false the LateArg can be an arbitrary expression tree. diff --git a/docs/design/coreclr/jit/struct-abi.md b/docs/design/coreclr/jit/struct-abi.md index 29530eeeec8189..efd299c5111e4b 100644 --- a/docs/design/coreclr/jit/struct-abi.md +++ b/docs/design/coreclr/jit/struct-abi.md @@ -50,7 +50,8 @@ when it comes to the handling of structs (aka value types). High-Level Proposed Design -------------------------- -This is a preliminary design, and is likely to change as the implementation proceeds: +Note that much of the below work has already been carried out and further refactoring has replaced the side `fgArgInfo` table with `CallArgs`. +The plan here is intended to provide some historical context and may not completely reflect JIT sources. First, the `fgArgInfo` is extended to contain all the information needed to determine how an argument is passed. Ideally, most of the `#ifdef`s relating to ABI differences diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index b764c25b780892..45452a1b5426bf 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -5613,7 +5613,6 @@ class Compiler GenTree* fgMorphArrayIndex(GenTree* tree); GenTree* fgMorphExpandCast(GenTreeCast* tree); GenTreeFieldList* fgMorphLclArgToFieldlist(GenTreeLclVarCommon* lcl); - void fgInitArgInfo(GenTreeCall* call); GenTreeCall* fgMorphArgs(GenTreeCall* call); void fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg, CORINFO_CLASS_HANDLE copyBlkClass); diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 2be3b9336f4609..d8747808819303 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -2384,7 +2384,7 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call structSize = comp->info.compCompHnd->getClassSize(objClass); break; default: - BADCODE("illegal argument tree in fgInitArgInfo"); + BADCODE("illegal argument tree: cannot determine size for ABI handling"); break; } } @@ -3255,7 +3255,7 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) } else { - // We have a BADCODE assert for this in fgInitArgInfo. + // We have a BADCODE assert for this in AddFinalArgsAndDetermineABIInfo. assert(argObj->OperIs(GT_LCL_VAR)); originalSize = lvaGetDesc(argObj->AsLclVarCommon())->lvExactSize; } @@ -6154,9 +6154,9 @@ void Compiler::fgMorphCallInlineHelper(GenTreeCall* call, InlineResult* result, // This function is target specific and each target will make the fastTailCall // decision differently. See the notes below. // -// This function calls fgInitArgInfo() to initialize the arg info table, which -// is used to analyze the argument. This function can alter the call arguments -// by adding argument IR nodes for non-standard arguments. +// This function calls AddFinalArgsAndDetermineABIInfo to initialize the ABI +// info, which is used to analyze the argument. This function can alter the +// call arguments by adding argument IR nodes for non-standard arguments. // // Windows Amd64: // A fast tail call can be made whenever the number of callee arguments @@ -6608,7 +6608,7 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) // an implicit byref parameter should be TYP_BYREF, as these parameters could // refer to boxed heap locations (say if the method is invoked by reflection) // but there are some stack only structs (like typed references) where - // the importer/runtime code uses TYP_I_IMPL, and fgInitArgInfo will + // the importer/runtime code uses TYP_I_IMPL, and AddFinalArgsAndDetermineABIInfo will // transiently retype all simple address-of implicit parameter args as // TYP_I_IMPL. // @@ -7515,12 +7515,11 @@ GenTree* Compiler::fgMorphTailCallViaHelpers(GenTreeCall* call, CORINFO_TAILCALL // can't do that in an assert. // assert(!fgCanFastTailCall(call, nullptr)); - // We might or might not have called fgInitArgInfo before this point: in - // builds with FEATURE_FASTTAILCALL we will have called it when checking if - // we could do a fast tailcall, so it is possible we have added extra IR - // for non-standard args that we must get rid of. Get rid of that IR here - // and do this first as it will 'expose' the retbuf as the first arg, which - // we rely upon in fgCreateCallDispatcherAndGetResult. + // We might or might not have called AddFinalArgsAndDetermineABIInfo before + // this point: in builds with FEATURE_FASTTAILCALL we will have called it + // when checking if we could do a fast tailcall, so it is possible we have + // added extra IR for non-standard args that we must get rid of. Get rid of + // the extra arguments here. call->gtArgs.ResetFinalArgsAndABIInfo(); GenTree* callDispatcherAndGetResult = fgCreateCallDispatcherAndGetResult(call, help.hCallTarget, help.hDispatcher); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_49078/Runtime_49078.cs b/src/tests/JIT/Regression/JitBlue/Runtime_49078/Runtime_49078.cs index 1bbbc9cdb903a5..c27db42296dd6b 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_49078/Runtime_49078.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_49078/Runtime_49078.cs @@ -12,14 +12,14 @@ // the originally added arg as a "normal" arg that shouldn't be there. // // So, in summary, for a call A->B, to see this failure, we need: -// +// // 1. The call is considered a potential tailcall (by the importer) -// 2. The call requires non-standard arguments that add call argument IR in fgInitArgInfo() +// 2. The call requires non-standard arguments that add call argument IR in AddFinalArgsAndDetermineABIInfo // (e.g., VSD call -- in this case, a generic interface call) // 3. We reject the tailcall in fgMorphPotentialTailCall() (e.g., not enough incoming arg stack space in A // to store B's outgoing args), in this case because the first arg is a large struct. We can't reject // it earlier, due to things like address exposed locals -- we must get far enough through the checks -// to have called fgInitArgInfo() to add the extra non-standard arg. +// to have called AddFinalArgsAndDetermineABIInfo to add the extra non-standard arg. // 4. B returns a struct in multiple registers (e.g., a 16-byte struct in Linux x64 ABI) namespace GitHub_49078 From b19086939e17062ce684690a6de93ecc3888c289 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 11 Apr 2022 14:30:47 +0200 Subject: [PATCH 48/52] Reformat --- src/coreclr/jit/morph.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index d8747808819303..7e585efc0fd9a6 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -6608,8 +6608,8 @@ bool Compiler::fgCallHasMustCopyByrefParameter(GenTreeCall* callee) // an implicit byref parameter should be TYP_BYREF, as these parameters could // refer to boxed heap locations (say if the method is invoked by reflection) // but there are some stack only structs (like typed references) where - // the importer/runtime code uses TYP_I_IMPL, and AddFinalArgsAndDetermineABIInfo will - // transiently retype all simple address-of implicit parameter args as + // the importer/runtime code uses TYP_I_IMPL, and AddFinalArgsAndDetermineABIInfo + // will transiently retype all simple address-of implicit parameter args as // TYP_I_IMPL. // if ((arg2.AbiInfo.ArgType == TYP_BYREF) || (arg2.AbiInfo.ArgType == TYP_I_IMPL)) From ff7534693d650dec44753b7c5d45ca00c14b49b1 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 13 Apr 2022 21:45:53 +0200 Subject: [PATCH 49/52] Address feedback, propagate arg flags properly --- src/coreclr/jit/compiler.h | 4 ++-- src/coreclr/jit/flowgraph.cpp | 3 ++- src/coreclr/jit/gentree.cpp | 17 ++++++------- src/coreclr/jit/gentree.h | 12 +++++----- src/coreclr/jit/importer.cpp | 45 ++++++++++++++++------------------- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 45452a1b5426bf..2c6eb8c47d1930 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -3894,11 +3894,11 @@ class Compiler ((opcode >= CEE_STLOC_0) && (opcode <= CEE_STLOC_3))); } - void impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList); + void impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, GenTreeCall* call); bool impCheckImplicitArgumentCoercion(var_types sigType, var_types nodeType) const; - void impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList, unsigned skipReverseCount = 0); + void impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, GenTreeCall* call, unsigned skipReverseCount = 0); //---------------- Spilling the importer stack ---------------------------- diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 636f86bf417926..761912d6c2b69d 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -1055,6 +1055,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, CORINFO_METHOD_HANDLE methHnd = call->gtCallMethHnd; CORINFO_CLASS_HANDLE clsHnd = info.compCompHnd->getMethodClass(methHnd); + assert(call->gtArgs.HasThisPointer()); assert(call->gtArgs.CountArgs() == 3); GenTree* targetMethod = call->gtArgs.GetArgByIndex(2)->GetEarlyNode(); noway_assert(targetMethod->TypeGet() == TYP_I_IMPL); @@ -1141,7 +1142,7 @@ GenTree* Compiler::fgOptimizeDelegateConstructor(GenTreeCall* call, { JITDUMP("optimized\n"); - GenTree* thisPointer = call->gtArgs.GetArgByIndex(0)->GetEarlyNode(); + GenTree* thisPointer = call->gtArgs.GetThisArg()->GetEarlyNode(); GenTree* targetObjPointers = call->gtArgs.GetArgByIndex(1)->GetEarlyNode(); CORINFO_LOOKUP pLookup; info.compCompHnd->getReadyToRunDelegateCtorHelper(&ldftnToken->m_token, ldftnToken->m_tokenConstraint, diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index ac106132c6e57e..f08a55107e9be2 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1412,7 +1412,7 @@ CallArg* CallArgs::GetThisArg() // Some jit helpers may have "out buffers" that are _not_ classified as the // ret buffer. These are normal arguments that function similarly to ret // buffers, but they do not have the special ABI treatment of ret buffers. -// See `GenTreeCall::TreatAsShouldGetRetBufArg` for more details. +// See `GenTreeCall::TreatAsShouldHaveRetBufArg` for more details. // CallArg* CallArgs::GetRetBufferArg() { @@ -1788,6 +1788,7 @@ CallArg* CallArgs::InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKno // Remarks: // This function should only be used if adding arguments after the call has // already been morphed. +// void CallArgs::PushLateBack(CallArg* arg) { CallArg** slot = &m_lateHead; @@ -1808,7 +1809,7 @@ void CallArgs::PushLateBack(CallArg* arg) // was not called yet or that `CallArgs::ResetFinalArgsAndABIInfo` has been // called prior to this. // -bool CallArgs::Remove(CallArg* arg) +void CallArgs::Remove(CallArg* arg) { assert(!m_abiInformationDetermined && !m_argsComplete); @@ -1819,13 +1820,13 @@ bool CallArgs::Remove(CallArg* arg) { *slot = arg->GetNext(); RemovedWellKnownArg(arg->GetWellKnownArg()); - return true; + return; } slot = &(*slot)->NextRef(); } - return false; + assert(!"Did not find arg to remove in CallArgs::Remove"); } //--------------------------------------------------------------- @@ -2073,7 +2074,7 @@ int GenTreeCall::GetNonStandardAddedArgCount(Compiler* compiler) const } //------------------------------------------------------------------------- -// TreatAsShouldGetRetBufArg: +// TreatAsShouldHaveRetBufArg: // // Arguments: // compiler, the compiler instance so that we can call eeGetHelperNum @@ -2093,9 +2094,9 @@ int GenTreeCall::GetNonStandardAddedArgCount(Compiler* compiler) const // aren't actually defined to return a struct, so they don't expect // their RetBuf to be passed in x8, instead they expect it in x0. // -bool GenTreeCall::TreatAsShouldGetRetBufArg(Compiler* compiler) const +bool GenTreeCall::TreatAsShouldHaveRetBufArg(Compiler* compiler) const { - if (ShouldGetRetBufArg()) + if (ShouldHaveRetBufArg()) { return true; } @@ -2120,7 +2121,7 @@ bool GenTreeCall::TreatAsShouldGetRetBufArg(Compiler* compiler) const } else { - assert(!"Unexpected JIT helper in TreatAsShouldGetRetBufArg"); + assert(!"Unexpected JIT helper in TreatAsShouldHaveRetBufArg"); } } return false; diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 53e86436954fea..411b40365ec054 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4367,7 +4367,7 @@ class CallArgs CallArg* InsertInstParam(Compiler* comp, GenTree* node); CallArg* InsertAfterThisOrFirst(Compiler* comp, GenTree* node, WellKnownArg wellKnownArg = WellKnownArg::None); void PushLateBack(CallArg* arg); - bool Remove(CallArg* arg); + void Remove(CallArg* arg); template void InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc copyFunc); @@ -4738,13 +4738,13 @@ struct GenTreeCall final : public GenTree // Returns true if the ABI dictates that this call should get a ret buf // arg. This may be out of sync with gtArgs.HasRetBuffer during import // until we actually create the ret buffer. - bool ShouldGetRetBufArg() const + bool ShouldHaveRetBufArg() const { return (gtCallMoreFlags & GTF_CALL_M_RETBUFFARG) != 0; } //------------------------------------------------------------------------- - // TreatAsShouldGetRetBufArg: + // TreatAsShouldHaveRetBufArg: // // Arguments: // compiler, the compiler instance so that we can call eeGetHelperNum @@ -4757,10 +4757,10 @@ struct GenTreeCall final : public GenTree // // Notes: // On ARM64 marking the method with the GTF_CALL_M_RETBUFFARG flag - // will make ShouldGetRetBufArg() return true, but will also force the + // will make ShouldHaveRetBufArg() return true, but will also force the // use of register x8 to pass the RetBuf argument. // - bool TreatAsShouldGetRetBufArg(Compiler* compiler) const; + bool TreatAsShouldHaveRetBufArg(Compiler* compiler) const; //----------------------------------------------------------------------------------------- // HasMultiRegRetVal: whether the call node returns its value in multiple return registers. @@ -4785,7 +4785,7 @@ struct GenTreeCall final : public GenTree } #endif - if (!varTypeIsStruct(gtType) || ShouldGetRetBufArg()) + if (!varTypeIsStruct(gtType) || ShouldHaveRetBufArg()) { return false; } diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 7a9e80d32caa2c..ea52a038e1f6b8 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -811,12 +811,12 @@ void Compiler::impAssignTempGen(unsigned tmpNum, // also to record exact receiving argument types that may be needed for ABI // purposes later. // Can be nullptr for certain helpers. -// argList - The `CallArgs` to pop argument into. +// call - The call to pop arguments into. // -void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* argList) +void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, GenTreeCall* call) { assert(sig == nullptr || count == sig->numArgs); - assert(argList->IsEmpty()); + assert(call->gtArgs.IsEmpty()); while (count--) { @@ -863,7 +863,8 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a } // NOTE: we defer bashing the type for I_IMPL to fgMorphArgs - argList->PushFront(this, temp); + call->gtArgs.PushFront(this, temp); + call->gtFlags |= temp->gtFlags & GTF_GLOB_EFFECT; } if (sig != nullptr) @@ -881,7 +882,7 @@ void Compiler::impPopCallArgs(unsigned count, CORINFO_SIG_INFO* sig, CallArgs* a CORINFO_ARG_LIST_HANDLE sigArgs = sig->args; unsigned index = 0; - for (CallArg& arg : argList->Args()) + for (CallArg& arg : call->gtArgs.Args()) { if (index >= sig->numArgs) break; @@ -1057,14 +1058,14 @@ bool Compiler::impCheckImplicitArgumentCoercion(var_types sigType, var_types nod void Compiler::impPopReverseCallArgs(unsigned count, CORINFO_SIG_INFO* sig, - CallArgs* argList, + GenTreeCall* call, unsigned skipReverseCount) { assert(skipReverseCount <= count); - impPopCallArgs(count, sig, argList); + impPopCallArgs(count, sig, call); - argList->Reverse(skipReverseCount, count - skipReverseCount); + call->gtArgs.Reverse(skipReverseCount, count - skipReverseCount); } //------------------------------------------------------------------------ @@ -1214,7 +1215,7 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, if (src->gtOper == GT_CALL) { GenTreeCall* srcCall = src->AsCall(); - if (srcCall->TreatAsShouldGetRetBufArg(this)) + if (srcCall->TreatAsShouldHaveRetBufArg(this)) { // Case of call returning a struct via hidden retbuf arg CLANG_FORMAT_COMMENT_ANCHOR; @@ -1224,7 +1225,7 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, // not be marked as the ret buff arg since it always follow the // normal ABI for parameters. WellKnownArg wellKnownArgType = - srcCall->ShouldGetRetBufArg() ? WellKnownArg::RetBuffer : WellKnownArg::None; + srcCall->ShouldHaveRetBufArg() ? WellKnownArg::RetBuffer : WellKnownArg::None; #if !defined(TARGET_ARM) // Unmanaged instance methods on Windows or Unix X86 need the retbuf arg after the first (this) parameter @@ -1368,7 +1369,7 @@ GenTree* Compiler::impAssignStructPtr(GenTree* destAddr, GenTreeCall* call = src->AsRetExpr()->gtInlineCandidate->AsCall(); noway_assert(call->gtOper == GT_CALL); - if (call->ShouldGetRetBufArg()) + if (call->ShouldHaveRetBufArg()) { // insert the return value buffer into the argument list as first byref parameter after 'this' call->gtArgs.InsertAfterThisOrFirst(this, destAddr, WellKnownArg::RetBuffer); @@ -7265,7 +7266,7 @@ void Compiler::impImportAndPushBox(CORINFO_RESOLVED_TOKEN* pResolvedToken) { GenTreeCall* const call = exprToBox->AsRetExpr()->gtInlineCandidate->AsCall(); - if (call->ShouldGetRetBufArg()) + if (call->ShouldHaveRetBufArg()) { JITDUMP("Must insert newobj stmts for box before call [%06u]\n", dspTreeID(call)); @@ -7922,7 +7923,7 @@ void Compiler::impPopArgsForUnmanagedCall(GenTreeCall* call, CORINFO_SIG_INFO* s /* The argument list is now "clean" - no out-of-order side effects * Pop the argument list in reverse order */ - impPopReverseCallArgs(sig->numArgs, sig, &call->gtArgs, sig->numArgs - argsToReverse); + impPopReverseCallArgs(sig->numArgs, sig, call, sig->numArgs - argsToReverse); if (call->gtCallMoreFlags & GTF_CALL_M_UNMGD_THISCALL) { @@ -7934,7 +7935,6 @@ void Compiler::impPopArgsForUnmanagedCall(GenTreeCall* call, CORINFO_SIG_INFO* s for (CallArg& arg : call->gtArgs.Args()) { GenTree* argNode = arg.GetEarlyNode(); - call->gtFlags |= argNode->gtFlags & GTF_GLOB_EFFECT; // We should not be passing gc typed args to an unmanaged call. if (varTypeIsGC(argNode->TypeGet())) @@ -8975,7 +8975,7 @@ var_types Compiler::impImportCall(OPCODE opcode, // take the call now.... call = gtNewIndCallNode(nullptr, callRetTyp, di); - impPopCallArgs(sig->numArgs, sig, &call->AsCall()->gtArgs); + impPopCallArgs(sig->numArgs, sig, call->AsCall()); GenTree* thisPtr = impPopStack().val; thisPtr = impTransformThis(thisPtr, pConstrainedResolvedToken, callInfo->thisTransform); @@ -9463,7 +9463,7 @@ var_types Compiler::impImportCall(OPCODE opcode, //------------------------------------------------------------------------- // The main group of arguments - impPopCallArgs(sig->numArgs, sig, &call->AsCall()->gtArgs); + impPopCallArgs(sig->numArgs, sig, call->AsCall()); if (extraArg != nullptr) { if (Target::g_tgtArgOrder == Target::ARG_ORDER_R2L) @@ -9474,11 +9474,8 @@ var_types Compiler::impImportCall(OPCODE opcode, { call->AsCall()->gtArgs.PushBack(this, extraArg, extraArgKind); } - } - for (CallArg& arg : call->AsCall()->gtArgs.Args()) - { - call->gtFlags |= arg.GetEarlyNode()->gtFlags & GTF_GLOB_EFFECT; + call->gtFlags |= extraArg->gtFlags & GTF_GLOB_EFFECT; } //------------------------------------------------------------------------- @@ -10353,7 +10350,7 @@ GenTree* Compiler::impFixupStructReturnType(GenTree* op, #endif // FEATURE_MULTIREG_RET && (TARGET_ARM64 || TARGET_LOONGARCH64) - if (!op->IsCall() || !op->AsCall()->TreatAsShouldGetRetBufArg(this)) + if (!op->IsCall() || !op->AsCall()->TreatAsShouldHaveRetBufArg(this)) { // Don't retype `struct` as a primitive type in `ret` instruction. return op; @@ -13215,7 +13212,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) // Else call a helper function to do the assignment op1 = gtNewHelperCallNode(CORINFO_HELP_ARRADDR_ST, TYP_VOID); - impPopCallArgs(3, nullptr, &op1->AsCall()->gtArgs); + impPopCallArgs(3, nullptr, op1->AsCall()); goto SPILL_APPEND; case CEE_STELEM_I1: @@ -17376,7 +17373,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) if (retRegCount != 0) { - assert(!iciCall->ShouldGetRetBufArg()); + assert(!iciCall->ShouldHaveRetBufArg()); assert(retRegCount >= 2); if (fgNeedReturnSpillTemp()) { @@ -17400,7 +17397,7 @@ bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode) if (retRegCount != 0) { - assert(!iciCall->ShouldGetRetBufArg()); + assert(!iciCall->ShouldHaveRetBufArg()); assert(retRegCount == MAX_RET_REG_COUNT); if (fgNeedReturnSpillTemp()) { From c53434c7bd0c9f44b606ea466d5ba224fbc3cd53 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 13 Apr 2022 22:07:03 +0200 Subject: [PATCH 50/52] Minor change and rerun failing CI --- src/coreclr/jit/morph.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 7e585efc0fd9a6..a7756c8adcdb98 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -740,12 +740,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) { bool hasStructRegArg = false; - unsigned argCount = 0; - - for (CallArg& arg : Args()) - { - argCount++; - } + unsigned argCount = CountArgs(); for (CallArg& arg : Args()) { @@ -766,7 +761,7 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) else if (arg.AbiInfo.IsSplit()) { hasStructRegArg = true; - assert(m_hasStackArgs == true); + assert(m_hasStackArgs); } #endif // FEATURE_ARG_SPLIT else // we have a register argument, next we look for a struct type. @@ -1537,13 +1532,13 @@ GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) // node. Some stack arguments may also require this pattern, for example // if a later argument trashes the outgoing arg area by requiring a // call. -// If the argument does not otherwise need to be evaluated into a temp , +// If the argument does not otherwise need to be evaluated into a temp, // we create just a placeholder GT_ARGPLACE for the early list and move // it into the late list. // // 3. Early: , Late: no node -// Arguments that are passed on stack and that do not need early -// evaluation do not require any late node. +// Arguments that are passed on stack and that do not need an explicit +// assignment in the early node list do not require any late node. // void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) { From 8e38f26fafa588c37995769850a570e33a2c9617 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 14 Apr 2022 21:51:57 +0200 Subject: [PATCH 51/52] Address feedback --- src/coreclr/jit/gentree.cpp | 2 - src/coreclr/jit/gentree.h | 3 +- src/coreclr/jit/morph.cpp | 143 ++++++++++++++++++++---------------- 3 files changed, 79 insertions(+), 69 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index f08a55107e9be2..90b01ad16af626 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1333,7 +1333,6 @@ CallArgs::CallArgs() , m_hasRegArgs(false) , m_hasStackArgs(false) , m_argsComplete(false) - , m_argsSorted(false) , m_needsTemps(false) #ifdef UNIX_X86_ABI , m_alignmentDone(false) @@ -8716,7 +8715,6 @@ void CallArgs::InternalCopyFrom(Compiler* comp, CallArgs* other, CopyNodeFunc co m_hasRegArgs = other->m_hasRegArgs; m_hasStackArgs = other->m_hasStackArgs; m_argsComplete = other->m_argsComplete; - m_argsSorted = other->m_argsSorted; m_needsTemps = other->m_needsTemps; // Unix x86 flags related to stack alignment intentionally not copied as diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 411b40365ec054..41d4c0eaea07ae 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4328,7 +4328,6 @@ class CallArgs // True if we have one or more stack arguments. bool m_hasStackArgs : 1; bool m_argsComplete : 1; - bool m_argsSorted : 1; // One or more arguments must be copied to a temp by EvalArgsToTemps. bool m_needsTemps : 1; #ifdef UNIX_X86_ABI @@ -4383,7 +4382,7 @@ class CallArgs void AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call); void ArgsComplete(Compiler* comp, GenTreeCall* call); - void SortArgs(Compiler* comp, GenTreeCall* call); + void SortArgs(Compiler* comp, GenTreeCall* call, CallArg** sortedArgs); void EvalArgsToTemps(Compiler* comp, GenTreeCall* call); void SetNeedsTemp(CallArg* arg); bool IsNonStandard(Compiler* comp, GenTreeCall* call, CallArg* arg); diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index a7756c8adcdb98..8979de34e9ab8e 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -57,6 +57,20 @@ GenTree* Compiler::fgMorphCastIntoHelper(GenTree* tree, int helper, GenTree* ope * the given argument list. */ +//------------------------------------------------------------------------ +// fgMorphIntoHelperCall: +// Morph a node into a helper call, specifying up to two args and whether to +// call fgMorphArgs after. +// +// Parameters: +// tree - The node that is changed. This must be a large node. +// helper - The helper. +// morphArgs - Whether to call fgMorphArgs after adding the args. +// arg1, arg2 - Optional arguments to add to the call. +// +// Return value: +// The call (which is the same as `tree`). +// GenTree* Compiler::fgMorphIntoHelperCall(GenTree* tree, int helper, bool morphArgs, GenTree* arg1, GenTree* arg2) { // The helper call ought to be semantically equivalent to the original node, so preserve its VN. @@ -1093,7 +1107,13 @@ void CallArgs::ArgsComplete(Compiler* comp, GenTreeCall* call) //------------------------------------------------------------------------ // SortArgs: Sort arguments into a better passing order. // -void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) +// Parameters: +// comp - The compiler object. +// call - The call that contains this CallArgs instance. +// sortedArgs - A table of at least `CountArgs()` entries where the sorted +// arguments are written into. +// +void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call, CallArg** sortedArgs) { assert(m_argsComplete); @@ -1111,31 +1131,23 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // more complex arguments before the simpler arguments. We use the late // list to keep the sorted result at this point, and the ordering ends up // looking like: - // +------------------------------------+ <--- end + // +------------------------------------+ <--- end of sortedArgs // | constants | // +------------------------------------+ // | local var / local field | // +------------------------------------+ // | remaining arguments sorted by cost | // +------------------------------------+ - // | temps (argTable[].needTmp = true) | + // | temps (CallArg::m_needTmp == true) | // +------------------------------------+ // | args with calls (GTF_CALL) | - // +------------------------------------+ <--- m_lateHead + // +------------------------------------+ <--- start of sortedArgs // - unsigned argCount = CountArgs(); - CallArg* table[32]; - CallArg** argTable = table; - if (argCount > 32) - { - argTable = new (comp, CMK_CallArgs) CallArg*[argCount]; - } - - argCount = 0; + unsigned argCount = 0; for (CallArg& arg : Args()) { - argTable[argCount++] = &arg; + sortedArgs[argCount++] = &arg; } // Set the beginning and end for the new argument table @@ -1153,7 +1165,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) { curInx--; - CallArg* arg = argTable[curInx]; + CallArg* arg = sortedArgs[curInx]; if (arg->AbiInfo.GetRegNum() != REG_STK) { @@ -1180,8 +1192,8 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (curInx != endTab) { - argTable[curInx] = argTable[endTab]; - argTable[endTab] = arg; + sortedArgs[curInx] = sortedArgs[endTab]; + sortedArgs[endTab] = arg; } endTab--; @@ -1197,7 +1209,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // for (curInx = begTab; curInx <= endTab; curInx++) { - CallArg* arg = argTable[curInx]; + CallArg* arg = sortedArgs[curInx]; // Skip any already processed args // @@ -1215,8 +1227,8 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (curInx != begTab) { - argTable[curInx] = argTable[begTab]; - argTable[begTab] = arg; + sortedArgs[curInx] = sortedArgs[begTab]; + sortedArgs[begTab] = arg; } begTab++; @@ -1237,7 +1249,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // for (curInx = begTab; curInx <= endTab; curInx++) { - CallArg* arg = argTable[curInx]; + CallArg* arg = sortedArgs[curInx]; // Skip any already processed args // @@ -1251,8 +1263,8 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (curInx != begTab) { - argTable[curInx] = argTable[begTab]; - argTable[begTab] = arg; + sortedArgs[curInx] = sortedArgs[begTab]; + sortedArgs[begTab] = arg; } begTab++; @@ -1273,7 +1285,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) { curInx--; - CallArg* arg = argTable[curInx]; + CallArg* arg = sortedArgs[curInx]; // Skip any already processed args // @@ -1291,8 +1303,8 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (curInx != endTab) { - argTable[curInx] = argTable[endTab]; - argTable[endTab] = arg; + sortedArgs[curInx] = sortedArgs[endTab]; + sortedArgs[endTab] = arg; } endTab--; @@ -1317,7 +1329,7 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // for (curInx = begTab; curInx <= endTab; curInx++) { - CallArg* arg = argTable[curInx]; + CallArg* arg = sortedArgs[curInx]; // Skip any already processed args // @@ -1370,8 +1382,8 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // if (expensiveArgIndex != begTab) { - argTable[expensiveArgIndex] = argTable[begTab]; - argTable[begTab] = expensiveArg; + sortedArgs[expensiveArgIndex] = sortedArgs[begTab]; + sortedArgs[begTab] = expensiveArg; } begTab++; @@ -1384,15 +1396,6 @@ void CallArgs::SortArgs(Compiler* comp, GenTreeCall* call) // and regArgsRemaining should be zero assert(begTab == (endTab + 1)); assert(argsRemaining == 0); - - CallArg** tail = &m_lateHead; - for (unsigned i = 0; i < argCount; i++) - { - *tail = argTable[i]; - tail = &(*tail)->LateNextRef(); - } - - m_argsSorted = true; } //------------------------------------------------------------------------------ @@ -1542,13 +1545,18 @@ GenTree* CallArgs::MakeTmpArgNode(Compiler* comp, CallArg* arg) // void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) { - assert(m_argsSorted); + CallArg* inlineTable[32]; + size_t numArgs = call->gtArgs.CountArgs(); + CallArg** sortedArgs = + numArgs <= ARRAY_SIZE(inlineTable) ? inlineTable : new (comp, CMK_CallArgs) CallArg*[numArgs]; + SortArgs(comp, call, sortedArgs); unsigned regArgInx = 0; - // Now go through the argument table and perform the necessary evaluation into temps. - // SortArgs stored the sorted result in the late list. - for (CallArg& arg : LateArgs()) + // Now go through the sorted argument table and perform the necessary evaluation into temps. + CallArg** lateTail = &m_lateHead; + for (size_t i = 0; i < numArgs; i++) { + CallArg& arg = *(sortedArgs[i]); assert(arg.GetLateNode() == nullptr); GenTree* argx = arg.GetEarlyNode(); @@ -1557,7 +1565,7 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) #if !FEATURE_FIXED_OUT_ARGS // Only ever set for FEATURE_FIXED_OUT_ARGS - assert(arg.m_needPlace == false); + assert(!arg.m_needPlace); // On x86 and other archs that use push instructions to pass arguments: // Only the register arguments need to be replaced with placeholder nodes. @@ -1790,21 +1798,8 @@ void CallArgs::EvalArgsToTemps(Compiler* comp, GenTreeCall* call) } arg.SetLateNode(defArg); - } - - // We used the late list to store sorted nodes. However not all arg may - // need to get late nodes, so unlink the arguments that do not. - CallArg** link = &m_lateHead; - while (*link != nullptr) - { - if ((*link)->GetLateNode() == nullptr) - { - *link = (*link)->GetLateNext(); - } - else - { - link = &(*link)->LateNextRef(); - } + *lateTail = &arg; + lateTail = &arg.LateNextRef(); } #ifdef DEBUG @@ -1910,6 +1905,7 @@ GenTree* Compiler::fgInsertCommaFormTemp(GenTree** ppTree, CORINFO_CLASS_HANDLE return new (this, GT_LCL_VAR) GenTreeLclVar(GT_LCL_VAR, subTree->TypeGet(), lclNum); } +//------------------------------------------------------------------------ // AddFinalArgsAndDetermineABIInfo: // Add final arguments and determine the argument ABI information. // @@ -3085,12 +3081,23 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call m_abiInformationDetermined = true; } +//------------------------------------------------------------------------ +// OutgoingArgsStackSize: +// Compute the number of bytes allocated on the stack for arguments to this call. +// +// Remarks: +// Note that even with no arguments, some ABIs may still allocate stack +// space, which will be returned by this function. +// unsigned CallArgs::OutgoingArgsStackSize() const { unsigned aligned = Compiler::GetOutgoingArgByteSize(m_nextStackByteOffset); return max(aligned, MIN_ARG_AREA_FOR_CALL); } +//------------------------------------------------------------------------ +// CountArgs: Count the number of arguments. +// unsigned CallArgs::CountArgs() { unsigned numArgs = 0; @@ -3187,9 +3194,18 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) // We may want to force 'this' into a temp because we want to use // it to expand the call target in morph so that CSE can pick it // up. - if (!reMorphing && call->IsExpandedEarly() && call->IsVirtualVtable() && !argx->OperIsLocal()) + if (call->IsExpandedEarly() && call->IsVirtualVtable() && !argx->OperIsLocal()) { - call->gtArgs.SetNeedsTemp(&arg); + if (!reMorphing) + { + call->gtArgs.SetNeedsTemp(&arg); + } + else + { + // Should have been converted to a temp the first time + // around. + assert(arg.IsTemp()); + } } } @@ -3656,8 +3672,6 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) if (!reMorphing && (call->gtArgs.HasRegArgs() || call->gtArgs.NeedsTemps())) { // Do the 'defer or eval to temp' analysis. - - call->gtArgs.SortArgs(this, call); call->gtArgs.EvalArgsToTemps(this, call); } @@ -3757,7 +3771,6 @@ void Compiler::fgMorphMultiregStructArgs(GenTreeCall* call) // Did we replace 'argx' with a new tree? if (newArgx != argx) { - // link the new arg node into either the late arg list or the gtCallArgs list if (isLateArg) { arg.SetLateNode(newArgx); @@ -8653,9 +8666,9 @@ GenTree* Compiler::fgMorphCall(GenTreeCall* call) // Transform it into a null check. assert(call->gtArgs.CountArgs() >= 1); - GenTree* thisPtr = call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* objPtr = call->gtArgs.GetArgByIndex(0)->GetNode(); - GenTree* nullCheck = gtNewNullCheck(thisPtr, compCurBB); + GenTree* nullCheck = gtNewNullCheck(objPtr, compCurBB); return fgMorphTree(nullCheck); } From 722c5d70e20ebe2aaec4b44fb488900f465d4a0e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Fri, 15 Apr 2022 02:27:58 +0200 Subject: [PATCH 52/52] Revert check for this needing temp on early expanded calls The early arg could be a local that was optimized to a constant later --- src/coreclr/jit/morph.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 8979de34e9ab8e..68864e3cc3ef06 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -3194,18 +3194,9 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call) // We may want to force 'this' into a temp because we want to use // it to expand the call target in morph so that CSE can pick it // up. - if (call->IsExpandedEarly() && call->IsVirtualVtable() && !argx->OperIsLocal()) + if (!reMorphing && call->IsExpandedEarly() && call->IsVirtualVtable() && !argx->OperIsLocal()) { - if (!reMorphing) - { - call->gtArgs.SetNeedsTemp(&arg); - } - else - { - // Should have been converted to a temp the first time - // around. - assert(arg.IsTemp()); - } + call->gtArgs.SetNeedsTemp(&arg); } }