Skip to content

Commit

Permalink
[NativeAOT] Do not emit safe point for TLS_GET_ADDR calls into native…
Browse files Browse the repository at this point in the history
… runtime. (dotnet#102237)

* Do not emit safe point for TLS_GET_ADDR calls into native runtime.

* formatting

* renamed parameter to `noSafePoint`, added comments.

* clang formatting, bane of my existence
VSadov authored May 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent dafaf4a commit 13d753c
Showing 14 changed files with 60 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
@@ -490,7 +490,8 @@ class CodeGen final : public CodeGenInterface
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
const DebugInfo& di,
regNumber base,
bool isJump);
bool isJump,
bool noSafePoint = false);
// clang-format on

// clang-format off
5 changes: 4 additions & 1 deletion src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
@@ -3599,6 +3599,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
// We just need to emit "call reg" in this case.
//
assert(genIsValidIntReg(target->GetRegNum()));
bool noSafePoint = false;

#ifdef TARGET_ARM64
bool isTlsHandleTarget =
@@ -3612,6 +3613,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
GenTreeIntCon* iconNode = target->AsIntCon();
methHnd = (CORINFO_METHOD_HANDLE)iconNode->gtIconVal;
retSize = EA_SET_FLG(retSize, EA_CNS_TLSGD_RELOC);
noSafePoint = true;

// For NativeAOT, linux/arm64, linker wants the following pattern, so we will generate
// it as part of the call. Generating individual instructions is tricky to get it
@@ -3647,7 +3649,8 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
di,
target->GetRegNum(),
call->IsFastTailCall());
call->IsFastTailCall(),
noSafePoint);

#ifdef TARGET_ARM64
if (isTlsHandleTarget)
6 changes: 4 additions & 2 deletions src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
@@ -2246,6 +2246,7 @@ void CodeGen::genTransferRegGCState(regNumber dst, regNumber src)
// pass in 'addr' for a relative call or 'base' for a indirect register call
// methHnd - optional, only used for pretty printing
// retSize - emitter type of return for GC purposes, should be EA_BYREF, EA_GCREF, or EA_PTRSIZE(not GC)
// noSafePoint - force not making this call a safe point in partially interruptible code
//
// clang-format off
void CodeGen::genEmitCall(int callType,
@@ -2257,7 +2258,8 @@ void CodeGen::genEmitCall(int callType,
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
const DebugInfo& di,
regNumber base,
bool isJump)
bool isJump,
bool noSafePoint)
{
#if !defined(TARGET_X86)
int argSize = 0;
@@ -2277,7 +2279,7 @@ void CodeGen::genEmitCall(int callType,
gcInfo.gcVarPtrSetCur,
gcInfo.gcRegGCrefSetCur,
gcInfo.gcRegByrefSetCur,
di, base, REG_NA, 0, 0, isJump);
di, base, REG_NA, 0, 0, isJump, noSafePoint);
}
// clang-format on

3 changes: 2 additions & 1 deletion src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
@@ -6434,7 +6434,8 @@ void CodeGen::genCallInstruction(GenTreeCall* call X86_ARG(target_ssize_t stackA
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
di,
target->GetRegNum(),
call->IsFastTailCall());
call->IsFastTailCall(),
true); // noSafePoint
// clang-format on
}
}
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitarm.cpp
Original file line number Diff line number Diff line change
@@ -4660,6 +4660,8 @@ void emitter::emitIns_J_R(instruction ins, emitAttr attr, BasicBlock* dst, regNu
*
* For ARM xreg, xmul and disp are never used and should always be 0/REG_NA.
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
* Please consult the "debugger team notification" comment in genFnProlog().
*/

@@ -4677,7 +4679,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

@@ -4769,7 +4772,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
13 changes: 7 additions & 6 deletions src/coreclr/jit/emitarm.h
Original file line number Diff line number Diff line change
@@ -330,12 +330,13 @@ void emitIns_Call(EmitCallType callType,
VARSET_VALARG_TP ptrVars,
regMaskTP gcrefRegs,
regMaskTP byrefRegs,
const DebugInfo& di = DebugInfo(),
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
const DebugInfo& di = DebugInfo(),
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false,
bool noSafePoint = false);

/*****************************************************************************
*
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
@@ -8977,6 +8977,8 @@ void emitter::emitIns_J(instruction ins, BasicBlock* dst, int instrCount)
*
* For ARM xreg, xmul and disp are never used and should always be 0/REG_NA.
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
* Please consult the "debugger team notification" comment in genFnProlog().
*/

@@ -8995,7 +8997,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

@@ -9089,7 +9092,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
3 changes: 2 additions & 1 deletion src/coreclr/jit/emitarm64.h
Original file line number Diff line number Diff line change
@@ -1745,7 +1745,8 @@ void emitIns_Call(EmitCallType callType,
regNumber xreg,
unsigned xmul,
ssize_t disp,
bool isJump);
bool isJump,
bool noSafePoint = false);

BYTE* emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i);
unsigned emitOutputCall(insGroup* ig, BYTE* dst, instrDesc* i, code_t code);
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitloongarch64.cpp
Original file line number Diff line number Diff line change
@@ -2375,6 +2375,8 @@ void emitter::emitIns_I_la(emitAttr size, regNumber reg, ssize_t imm)
*
* For LOONGARCH xreg, xmul and disp are never used and should always be 0/REG_NA.
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
* Please consult the "debugger team notification" comment in genFnProlog().
*/

@@ -2392,7 +2394,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

@@ -2489,7 +2492,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
11 changes: 6 additions & 5 deletions src/coreclr/jit/emitloongarch64.h
Original file line number Diff line number Diff line change
@@ -345,11 +345,12 @@ void emitIns_Call(EmitCallType callType,
regMaskTP gcrefRegs,
regMaskTP byrefRegs,
const DebugInfo& di,
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false,
bool noSafePoint = false);

unsigned emitOutputCall(insGroup* ig, BYTE* dst, instrDesc* id, code_t code);

7 changes: 5 additions & 2 deletions src/coreclr/jit/emitriscv64.cpp
Original file line number Diff line number Diff line change
@@ -1287,6 +1287,8 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
* If callType is one of these emitCallTypes, addr has to be NULL.
* EC_INDIR_R : "call ireg".
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
*/

void emitter::emitIns_Call(EmitCallType callType,
@@ -1303,7 +1305,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

@@ -1400,7 +1403,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
11 changes: 6 additions & 5 deletions src/coreclr/jit/emitriscv64.h
Original file line number Diff line number Diff line change
@@ -331,11 +331,12 @@ void emitIns_Call(EmitCallType callType,
regMaskTP gcrefRegs,
regMaskTP byrefRegs,
const DebugInfo& di,
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false,
bool noSafePoint = false);

unsigned emitOutputCall(const insGroup* ig, BYTE* dst, instrDesc* id, code_t code);

7 changes: 5 additions & 2 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
@@ -9646,6 +9646,8 @@ void emitter::emitAdjustStackDepth(instruction ins, ssize_t val)
* EC_INDIR_C : "call clsVar<disp>" (eg. call [clsVarAddr])
* EC_INDIR_ARD : "call [ireg+xreg*xmul+disp]"
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
*/

// clang-format off
@@ -9664,7 +9666,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg,
unsigned xmul,
ssize_t disp,
bool isJump)
bool isJump,
bool noSafePoint)
// clang-format on
{
/* Sanity check the arguments depending on callType */
@@ -9790,7 +9793,7 @@ void emitter::emitIns_Call(EmitCallType callType,
id->idIns(ins);

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

UNATIVE_OFFSET sz;

3 changes: 2 additions & 1 deletion src/coreclr/jit/emitxarch.h
Original file line number Diff line number Diff line change
@@ -1017,7 +1017,8 @@ void emitIns_Call(EmitCallType callType,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
bool isJump = false,
bool noSafePoint = false);
// clang-format on

#ifdef TARGET_AMD64

0 comments on commit 13d753c

Please sign in to comment.