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

Commit 4efaad6

Browse files
author
Sergey Andreenko
committed
fix r2r relative indirection for arm.
1 parent 56d4922 commit 4efaad6

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

src/jit/lower.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,19 +3175,7 @@ GenTree* Lowering::LowerDirectCall(GenTreeCall* call)
31753175
// a single indirection.
31763176
GenTree* cellAddr = AddrGen(addr);
31773177
GenTree* indir = Ind(cellAddr);
3178-
3179-
#ifdef FEATURE_READYTORUN_COMPILER
3180-
#if defined(_TARGET_ARMARCH_)
3181-
// For arm64, we dispatch code same as VSD using X11 for indirection cell address,
3182-
// which ZapIndirectHelperThunk expects.
3183-
if (call->IsR2RRelativeIndir())
3184-
{
3185-
cellAddr->gtRegNum = REG_R2R_INDIRECT_PARAM;
3186-
indir->gtRegNum = REG_JUMP_THUNK_PARAM;
3187-
}
3188-
#endif
3189-
#endif
3190-
result = indir;
3178+
result = indir;
31913179
break;
31923180
}
31933181

src/jit/morph.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,26 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
31343134
call->gtCallType = CT_HELPER;
31353135
call->gtCallMethHnd = eeFindHelper(CORINFO_HELP_PINVOKE_CALLI);
31363136
}
3137-
#endif // !defined(LEGACY_BACKEND)
3137+
#if FEATURE_READYTORUN_COMPILER && _TARGET_ARMARCH_
3138+
// For arm, we dispatch code same as VSD using virtualStubParamInfo->GetReg()
3139+
// for indirection cell address, which ZapIndirectHelperThunk expects.
3140+
if (call->IsR2RRelativeIndir())
3141+
{
3142+
assert(call->gtEntryPoint.addr != nullptr);
3143+
3144+
size_t addrValue = (size_t)call->gtEntryPoint.addr;
3145+
GenTree* indirectCellAddress = gtNewIconHandleNode(addrValue, GTF_ICON_FTN_ADDR);
3146+
indirectCellAddress->gtRegNum = REG_R2R_INDIRECT_PARAM;
3147+
3148+
// Push the stub address onto the list of arguments.
3149+
call->gtCallArgs = gtNewListNode(indirectCellAddress, call->gtCallArgs);
3150+
3151+
numArgs++;
3152+
nonStandardArgs.Add(indirectCellAddress, indirectCellAddress->gtRegNum);
3153+
}
3154+
3155+
#endif // FEATURE_READYTORUN_COMPILER && _TARGET_ARMARCH_
3156+
#endif // !LEGACY_BACKEND
31383157

31393158
// Allocate the fgArgInfo for the call node;
31403159
//

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
{

src/jit/valuenum.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7411,6 +7411,25 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN
74117411
vnpUniq.SetBoth(vnStore->VNForExpr(compCurBB, call->TypeGet()));
74127412
}
74137413

7414+
#ifdef FEATURE_READYTORUN_COMPILER
7415+
#if defined(_TARGET_ARMARCH_)
7416+
if (call->IsR2RRelativeIndir())
7417+
{
7418+
#ifdef DEBUG
7419+
assert(args->Current()->OperGet() == GT_ARGPLACE);
7420+
7421+
// Find the corresponding late arg.
7422+
GenTree* indirectCellAddress = call->fgArgInfo->GetLateArg(0);
7423+
assert(indirectCellAddress->IsCnsIntOrI() && indirectCellAddress->gtRegNum == REG_R2R_INDIRECT_PARAM);
7424+
#endif // DEBUG
7425+
// For ARM indirectCellAddress is consumed by the call itself, so it should have added as an implicit argument
7426+
// in
7427+
// morph. So we do not need to use EntryPointAddrAsArg0, because arg0 is already an entry point addr.
7428+
useEntryPointAddrAsArg0 = false;
7429+
}
7430+
#endif // _TARGET_ARMARCH_
7431+
#endif // FEATURE_READYTORUN_COMPILER
7432+
74147433
if (nArgs == 0)
74157434
{
74167435
if (generateUniqueVN)
@@ -7452,7 +7471,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN
74527471
vnp0 = ValueNumPair(callAddrVN, callAddrVN);
74537472
}
74547473
else
7455-
#endif
7474+
#endif // FEATURE_READYTORUN_COMPILER
74567475
{
74577476
assert(!useEntryPointAddrAsArg0);
74587477
ValueNumPair vnp0wx = getCurrentArg(0)->gtVNPair;
@@ -7519,6 +7538,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN
75197538
// Add the accumulated exceptions.
75207539
call->gtVNPair = vnStore->VNPWithExc(call->gtVNPair, vnpExc);
75217540
}
7541+
assert(args == nullptr || generateUniqueVN);
75227542
}
75237543

75247544
void Compiler::fgValueNumberCall(GenTreeCall* call)

0 commit comments

Comments
 (0)