Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 01326b3

Browse files
author
Sergey Andreenko
committed
fix r2r relative indirection for arm.
1 parent c4943e0 commit 01326b3

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

src/jit/lower.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3173,13 +3173,48 @@ GenTree* Lowering::LowerDirectCall(GenTreeCall* call)
31733173

31743174
#ifdef FEATURE_READYTORUN_COMPILER
31753175
#if defined(_TARGET_ARMARCH_)
3176-
// For arm64, we dispatch code same as VSD using X11 for indirection cell address,
3176+
// For arm, we dispatch code same as VSD using X11 for indirection cell address,
31773177
// which ZapIndirectHelperThunk expects.
31783178
if (call->IsR2RRelativeIndir())
31793179
{
31803180
cellAddr->gtRegNum = REG_R2R_INDIRECT_PARAM;
31813181
indir->gtRegNum = REG_JUMP_THUNK_PARAM;
3182+
3183+
GenTreeIntCon* indirectCellAddress = nullptr;
3184+
3185+
for (GenTreeArgList* args = call->gtCallArgs; args; args = args->Rest())
3186+
{
3187+
GenTree* arg = args->Current();
3188+
if (arg->gtRegNum == REG_R2R_INDIRECT_PARAM)
3189+
{
3190+
GenTree* putArgValue = arg->AsOp()->gtOp.gtOp1;
3191+
if (putArgValue->IsIconHandle(GTF_ICON_FTN_ADDR))
3192+
{
3193+
assert(indirectCellAddress == nullptr);
3194+
indirectCellAddress = putArgValue->AsIntCon();
3195+
}
3196+
}
3197+
}
3198+
3199+
for (GenTreeArgList* args = call->gtCallLateArgs; args; args = args->Rest())
3200+
{
3201+
GenTree* arg = args->Current();
3202+
if (arg->gtRegNum == REG_R2R_INDIRECT_PARAM)
3203+
{
3204+
GenTree* putArgValue = arg->AsOp()->gtOp.gtOp1;
3205+
if (putArgValue->IsIconHandle(GTF_ICON_FTN_ADDR))
3206+
{
3207+
assert(indirectCellAddress == nullptr);
3208+
indirectCellAddress = putArgValue->AsIntCon();
3209+
}
3210+
}
3211+
}
3212+
assert(indirectCellAddress != nullptr);
3213+
indirectCellAddress->gtIconVal = (size_t)addr;
31823214
}
3215+
#else
3216+
// x64/x86 uses an encoding trick - it assumes the call is dispatched like call[addr],
3217+
// do not need to do anything for them.
31833218
#endif
31843219
#endif
31853220
result = indir;

src/jit/morph.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,6 +3134,24 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
31343134
call->gtCallType = CT_HELPER;
31353135
call->gtCallMethHnd = eeFindHelper(CORINFO_HELP_PINVOKE_CALLI);
31363136
}
3137+
#ifdef FEATURE_READYTORUN_COMPILER
3138+
#ifdef _TARGET_ARMARCH_
3139+
// For arm, we dispatch code same as VSD using virtualStubParamInfo->GetReg()
3140+
// for indirection cell address, which ZapIndirectHelperThunk expects.
3141+
if (call->IsR2RRelativeIndir())
3142+
{
3143+
// Create a placeholder for the real value, that will be added in lower.
3144+
GenTree* indirectCellAddress = gtNewIconHandleNode(0, GTF_ICON_FTN_ADDR);
3145+
indirectCellAddress->gtRegNum = REG_R2R_INDIRECT_PARAM;
3146+
// And push the stub address onto the list of arguments
3147+
call->gtCallArgs = gtNewListNode(indirectCellAddress, call->gtCallArgs);
3148+
3149+
numArgs++;
3150+
nonStandardArgs.Add(indirectCellAddress, indirectCellAddress->gtRegNum);
3151+
}
3152+
3153+
#endif // _TARGET_ARMARCH_
3154+
#endif // FEATURE_READYTORUN_COMPILER
31373155
#endif // !defined(LEGACY_BACKEND)
31383156

31393157
// Allocate the fgArgInfo for the call node;
@@ -8099,6 +8117,10 @@ GenTree* Compiler::fgGetStubAddrArg(GenTreeCall* call)
80998117
}
81008118
assert(stubAddrArg != nullptr);
81018119
stubAddrArg->gtRegNum = virtualStubParamInfo->GetReg();
8120+
if (verbose)
8121+
{
8122+
printf("fgGetStubAddrArg for call %d : %d\n", call->gtTreeID, stubAddrArg->gtTreeID);
8123+
}
81028124
return stubAddrArg;
81038125
}
81048126

src/jit/rationalize.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ void Rationalizer::RewriteNodeAsCall(GenTree** use,
160160
assert(JITtype2varType(sig.retType) == tree->gtType);
161161
#endif // DEBUG
162162

163-
call = comp->fgMorphArgs(call);
164-
// Determine if this call has changed any codegen requirements.
165-
comp->fgCheckArgCnt();
166-
167163
#ifdef FEATURE_READYTORUN_COMPILER
168164
call->gtCall.setEntryPoint(entryPoint);
169165
#endif
170166

167+
call = comp->fgMorphArgs(call);
168+
// Determine if this call has changed any codegen requirements.
169+
comp->fgCheckArgCnt();
170+
171171
// Replace "tree" with "call"
172172
if (parents.Height() > 1)
173173
{

0 commit comments

Comments
 (0)