Skip to content

Commit 13d753c

Browse files
authored
[NativeAOT] Do not emit safe point for TLS_GET_ADDR calls into native runtime. (#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
1 parent dafaf4a commit 13d753c

14 files changed

+60
-33
lines changed

src/coreclr/jit/codegen.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ class CodeGen final : public CodeGenInterface
490490
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
491491
const DebugInfo& di,
492492
regNumber base,
493-
bool isJump);
493+
bool isJump,
494+
bool noSafePoint = false);
494495
// clang-format on
495496

496497
// clang-format off

src/coreclr/jit/codegenarmarch.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3599,6 +3599,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
35993599
// We just need to emit "call reg" in this case.
36003600
//
36013601
assert(genIsValidIntReg(target->GetRegNum()));
3602+
bool noSafePoint = false;
36023603

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

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

36523655
#ifdef TARGET_ARM64
36533656
if (isTlsHandleTarget)

src/coreclr/jit/codegenlinear.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,7 @@ void CodeGen::genTransferRegGCState(regNumber dst, regNumber src)
22462246
// pass in 'addr' for a relative call or 'base' for a indirect register call
22472247
// methHnd - optional, only used for pretty printing
22482248
// retSize - emitter type of return for GC purposes, should be EA_BYREF, EA_GCREF, or EA_PTRSIZE(not GC)
2249+
// noSafePoint - force not making this call a safe point in partially interruptible code
22492250
//
22502251
// clang-format off
22512252
void CodeGen::genEmitCall(int callType,
@@ -2257,7 +2258,8 @@ void CodeGen::genEmitCall(int callType,
22572258
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
22582259
const DebugInfo& di,
22592260
regNumber base,
2260-
bool isJump)
2261+
bool isJump,
2262+
bool noSafePoint)
22612263
{
22622264
#if !defined(TARGET_X86)
22632265
int argSize = 0;
@@ -2277,7 +2279,7 @@ void CodeGen::genEmitCall(int callType,
22772279
gcInfo.gcVarPtrSetCur,
22782280
gcInfo.gcRegGCrefSetCur,
22792281
gcInfo.gcRegByrefSetCur,
2280-
di, base, REG_NA, 0, 0, isJump);
2282+
di, base, REG_NA, 0, 0, isJump, noSafePoint);
22812283
}
22822284
// clang-format on
22832285

src/coreclr/jit/codegenxarch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6434,7 +6434,8 @@ void CodeGen::genCallInstruction(GenTreeCall* call X86_ARG(target_ssize_t stackA
64346434
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
64356435
di,
64366436
target->GetRegNum(),
6437-
call->IsFastTailCall());
6437+
call->IsFastTailCall(),
6438+
true); // noSafePoint
64386439
// clang-format on
64396440
}
64406441
}

src/coreclr/jit/emitarm.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,6 +4660,8 @@ void emitter::emitIns_J_R(instruction ins, emitAttr attr, BasicBlock* dst, regNu
46604660
*
46614661
* For ARM xreg, xmul and disp are never used and should always be 0/REG_NA.
46624662
*
4663+
* noSafePoint - force not making this call a safe point in partially interruptible code
4664+
*
46634665
* Please consult the "debugger team notification" comment in genFnProlog().
46644666
*/
46654667

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

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

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

47744777
/* Set the instruction - special case jumping a function */
47754778
instruction ins;

src/coreclr/jit/emitarm.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,13 @@ void emitIns_Call(EmitCallType callType,
330330
VARSET_VALARG_TP ptrVars,
331331
regMaskTP gcrefRegs,
332332
regMaskTP byrefRegs,
333-
const DebugInfo& di = DebugInfo(),
334-
regNumber ireg = REG_NA,
335-
regNumber xreg = REG_NA,
336-
unsigned xmul = 0,
337-
ssize_t disp = 0,
338-
bool isJump = false);
333+
const DebugInfo& di = DebugInfo(),
334+
regNumber ireg = REG_NA,
335+
regNumber xreg = REG_NA,
336+
unsigned xmul = 0,
337+
ssize_t disp = 0,
338+
bool isJump = false,
339+
bool noSafePoint = false);
339340

340341
/*****************************************************************************
341342
*

src/coreclr/jit/emitarm64.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8977,6 +8977,8 @@ void emitter::emitIns_J(instruction ins, BasicBlock* dst, int instrCount)
89778977
*
89788978
* For ARM xreg, xmul and disp are never used and should always be 0/REG_NA.
89798979
*
8980+
* noSafePoint - force not making this call a safe point in partially interruptible code
8981+
*
89808982
* Please consult the "debugger team notification" comment in genFnProlog().
89818983
*/
89828984

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

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

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

90949097
/* Set the instruction - special case jumping a function */
90959098
instruction ins;

src/coreclr/jit/emitarm64.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,8 @@ void emitIns_Call(EmitCallType callType,
17451745
regNumber xreg,
17461746
unsigned xmul,
17471747
ssize_t disp,
1748-
bool isJump);
1748+
bool isJump,
1749+
bool noSafePoint = false);
17491750

17501751
BYTE* emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i);
17511752
unsigned emitOutputCall(insGroup* ig, BYTE* dst, instrDesc* i, code_t code);

src/coreclr/jit/emitloongarch64.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,8 @@ void emitter::emitIns_I_la(emitAttr size, regNumber reg, ssize_t imm)
23752375
*
23762376
* For LOONGARCH xreg, xmul and disp are never used and should always be 0/REG_NA.
23772377
*
2378+
* noSafePoint - force not making this call a safe point in partially interruptible code
2379+
*
23782380
* Please consult the "debugger team notification" comment in genFnProlog().
23792381
*/
23802382

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

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

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

24942497
/* Set the instruction - special case jumping a function */
24952498
instruction ins;

src/coreclr/jit/emitloongarch64.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,12 @@ void emitIns_Call(EmitCallType callType,
345345
regMaskTP gcrefRegs,
346346
regMaskTP byrefRegs,
347347
const DebugInfo& di,
348-
regNumber ireg = REG_NA,
349-
regNumber xreg = REG_NA,
350-
unsigned xmul = 0,
351-
ssize_t disp = 0,
352-
bool isJump = false);
348+
regNumber ireg = REG_NA,
349+
regNumber xreg = REG_NA,
350+
unsigned xmul = 0,
351+
ssize_t disp = 0,
352+
bool isJump = false,
353+
bool noSafePoint = false);
353354

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

src/coreclr/jit/emitriscv64.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
12871287
* If callType is one of these emitCallTypes, addr has to be NULL.
12881288
* EC_INDIR_R : "call ireg".
12891289
*
1290+
* noSafePoint - force not making this call a safe point in partially interruptible code
1291+
*
12901292
*/
12911293

12921294
void emitter::emitIns_Call(EmitCallType callType,
@@ -1303,7 +1305,8 @@ void emitter::emitIns_Call(EmitCallType callType,
13031305
regNumber xreg /* = REG_NA */,
13041306
unsigned xmul /* = 0 */,
13051307
ssize_t disp /* = 0 */,
1306-
bool isJump /* = false */)
1308+
bool isJump /* = false */,
1309+
bool noSafePoint /* = false */)
13071310
{
13081311
/* Sanity check the arguments depending on callType */
13091312

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

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

14051408
/* Set the instruction - special case jumping a function */
14061409
instruction ins;

src/coreclr/jit/emitriscv64.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,12 @@ void emitIns_Call(EmitCallType callType,
331331
regMaskTP gcrefRegs,
332332
regMaskTP byrefRegs,
333333
const DebugInfo& di,
334-
regNumber ireg = REG_NA,
335-
regNumber xreg = REG_NA,
336-
unsigned xmul = 0,
337-
ssize_t disp = 0,
338-
bool isJump = false);
334+
regNumber ireg = REG_NA,
335+
regNumber xreg = REG_NA,
336+
unsigned xmul = 0,
337+
ssize_t disp = 0,
338+
bool isJump = false,
339+
bool noSafePoint = false);
339340

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

src/coreclr/jit/emitxarch.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9646,6 +9646,8 @@ void emitter::emitAdjustStackDepth(instruction ins, ssize_t val)
96469646
* EC_INDIR_C : "call clsVar<disp>" (eg. call [clsVarAddr])
96479647
* EC_INDIR_ARD : "call [ireg+xreg*xmul+disp]"
96489648
*
9649+
* noSafePoint - force not making this call a safe point in partially interruptible code
9650+
*
96499651
*/
96509652

96519653
// clang-format off
@@ -9664,7 +9666,8 @@ void emitter::emitIns_Call(EmitCallType callType,
96649666
regNumber xreg,
96659667
unsigned xmul,
96669668
ssize_t disp,
9667-
bool isJump)
9669+
bool isJump,
9670+
bool noSafePoint)
96689671
// clang-format on
96699672
{
96709673
/* Sanity check the arguments depending on callType */
@@ -9790,7 +9793,7 @@ void emitter::emitIns_Call(EmitCallType callType,
97909793
id->idIns(ins);
97919794

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

97959798
UNATIVE_OFFSET sz;
97969799

src/coreclr/jit/emitxarch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,8 @@ void emitIns_Call(EmitCallType callType,
10171017
regNumber xreg = REG_NA,
10181018
unsigned xmul = 0,
10191019
ssize_t disp = 0,
1020-
bool isJump = false);
1020+
bool isJump = false,
1021+
bool noSafePoint = false);
10211022
// clang-format on
10221023

10231024
#ifdef TARGET_AMD64

0 commit comments

Comments
 (0)