Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JIT] Add support to inline the field access of primitive types marked with TLS #82973

Merged
merged 93 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
327b8f6
Add CORINFO_THREAD_LOCAL_FIELD_INFO and getThreadLocalFieldInfo()
kunalspathak Feb 17, 2023
51644e2
Implementation of getThreadLocalFieldInfo()
kunalspathak Feb 17, 2023
8aef324
Change the field types from CORINFO_CONST_LOOKUP to uint32_t
kunalspathak Feb 17, 2023
916482b
Introduce CORINFO_FIELD_STATIC_TLS_MANAGED
kunalspathak Feb 17, 2023
6eaa3d9
Introduce GTF_FLD_TLS_MANAGED
kunalspathak Feb 17, 2023
efbb53d
Introduce eeGetThreadLocalFieldInfo()
kunalspathak Feb 17, 2023
f3fc3a2
Fix the offsetOfThreadStaticBlocks, hardcode threadStaticBlockIndex f…
kunalspathak Feb 22, 2023
ca4caad
Add impThreadLocalFieldAccess()
kunalspathak Feb 22, 2023
8fd9f58
Switch to GS segment register with a TODO
kunalspathak Feb 23, 2023
b0bf47f
Add reverse map `g_threadStaticBlockTypeIDMap` for type -> ID
kunalspathak Feb 23, 2023
3796c73
Fix GS segment register encoding
kunalspathak Feb 25, 2023
50c5e95
Add comment for g_threadStaticBlockTypeIDMap
kunalspathak Feb 25, 2023
8d0c3a9
Add extra parameter for typeIndex in JIT_GetSharedNonGCThreadStaticBase
kunalspathak Feb 25, 2023
45ddb20
Update JIT_GetSharedNonGCThreadStaticBase to add logic for storing ty…
kunalspathak Feb 25, 2023
8ca4999
Fix encoding of gs:[0x58]
kunalspathak Feb 28, 2023
93a70a1
fix some bugs in importer to change size from 4 to 8
kunalspathak Feb 28, 2023
a0e40f0
add some printf in jithelpers
kunalspathak Feb 28, 2023
e6bdd82
To revert
kunalspathak Mar 2, 2023
8548500
Merge remote-tracking branch 'origin/main' into tls
kunalspathak Mar 2, 2023
f3bca52
Update the helper to skip making re-entry for staticBlock
kunalspathak Mar 3, 2023
93702e3
Add impThreadLocalFieldWrite() for store
kunalspathak Mar 3, 2023
a607458
Fix a issue for helper
kunalspathak Mar 3, 2023
c331a68
Use JITDUMP
kunalspathak Mar 3, 2023
a96745f
Merge remote-tracking branch 'origin/main' into tls
kunalspathak Mar 3, 2023
b3e1038
Just enable the optimization for primitive types
kunalspathak Mar 4, 2023
3a20176
Update the JITEE guid
kunalspathak Mar 4, 2023
db09d6f
Fix an assert for volatile variables
kunalspathak Mar 5, 2023
58cdade
Mark helper block as cold block
kunalspathak Mar 5, 2023
a138959
wip
kunalspathak Mar 6, 2023
8d0d6a7
Fix the size of maxThreadStaticBlock
kunalspathak Mar 7, 2023
e372a95
fix a bug to insert the entry in cache
kunalspathak Mar 7, 2023
b273fe6
Add #ifdef for HOST_WINDOWS / TARGET_WINDOWS
kunalspathak Mar 7, 2023
9584257
Dynamic memory allocation for static block array
kunalspathak Mar 7, 2023
d0bbf56
Call InitTypeMap only if host == windows
kunalspathak Mar 7, 2023
6e10e7d
Add CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED
kunalspathak Mar 8, 2023
c5266da
Merge remote-tracking branch 'origin/main' into tls
kunalspathak Mar 24, 2023
360ab8c
Expand the TLS field access in late phase
kunalspathak Mar 28, 2023
3dfb3d2
Move rarely ran block to the end
kunalspathak Mar 28, 2023
0e3daaa
wip
kunalspathak Mar 28, 2023
7f59353
Fix the bug to access the value from fastPath
kunalspathak Mar 28, 2023
e618aee
Remove code from importer
kunalspathak Mar 28, 2023
2b0629d
Cleanup the code
kunalspathak Mar 28, 2023
a4bb8dd
Moved CreateBlockFromTree to fgbasic.cpp
kunalspathak Mar 28, 2023
bad7fb3
Move fgExpandThreadLocalAccess() to flowgraph.cpp
kunalspathak Mar 28, 2023
e094f29
Add getThreadLocalStaticBlocksInfo() method
kunalspathak Mar 28, 2023
7b9de56
Consume getThreadLocalStaticBlocksInfo() method
kunalspathak Mar 28, 2023
781e25e
Updated definition of getThreadLocalFieldInfo()
kunalspathak Mar 29, 2023
f774eb5
Rename CORINFO_THREAD_LOCAL_FIELD_INFO to CORINFO_THREAD_STATIC_BLOCK…
kunalspathak Mar 29, 2023
76cbaa1
Add TARGET_WINDOWS
kunalspathak Mar 29, 2023
097a2d4
Make TARGET_WINDOWS at some definitions
kunalspathak Mar 29, 2023
d718156
Add dummy definition for unix
kunalspathak Mar 29, 2023
20f2e90
jit format
kunalspathak Mar 29, 2023
612187e
Merge remote-tracking branch 'origin/main' into tls
kunalspathak Mar 29, 2023
69f64cf
remote unnecessary code from morph
kunalspathak Mar 29, 2023
5e53c84
Fix an issue on linux, add assert for tls_index != 0
kunalspathak Mar 30, 2023
5f4b971
Convert from TARGET_WINDOWS to HOST_WINDOWS
kunalspathak Mar 30, 2023
8f61268
jit format
kunalspathak Mar 30, 2023
c3b3c83
fix the if-check
kunalspathak Mar 30, 2023
91f6a8a
fix gcc build error
kunalspathak Mar 31, 2023
25c04d5
Added MethodHaveTlsFieldAccess()
kunalspathak Mar 31, 2023
90103a1
Handle the case for '_tls_index == 0'
kunalspathak Mar 31, 2023
90af395
fix a typo
kunalspathak Mar 31, 2023
66f6401
Fix windows/arm64 issue
kunalspathak Mar 31, 2023
3cd2881
fix encoding of teb loading for arm64
kunalspathak Apr 1, 2023
055b9e0
Fix the condition in jitinterface to select correct helper
kunalspathak Apr 3, 2023
c8ed0c6
fix the condition for other helper too
kunalspathak Apr 4, 2023
ab98131
fix the windows/x86 case
kunalspathak Apr 4, 2023
6c9264f
Merge remote-tracking branch 'origin/main' into tls
kunalspathak Apr 4, 2023
d085acd
jit format
kunalspathak Apr 4, 2023
f08fbd3
Use CORINFO_CONST_LOOKUP for _tls_index
kunalspathak Apr 5, 2023
a81c4b9
Move typeIdMap to BaseDomain class
kunalspathak Apr 5, 2023
18e6b46
Introduce useFatPointerDispatch parameter for GetTypeID()
kunalspathak Apr 5, 2023
d23a0b2
jit format
kunalspathak Apr 5, 2023
1aea091
Do not pass classID and moduleID to the new helper
kunalspathak Apr 5, 2023
19bb28a
fix build for non-windows
kunalspathak Apr 5, 2023
7dc2d6e
fix superpmi methods
kunalspathak Apr 5, 2023
2d76689
review feedback
kunalspathak Apr 5, 2023
79e0351
fix linux build errors
kunalspathak Apr 6, 2023
1f2a353
review feedback
kunalspathak Apr 6, 2023
c0de86f
fix weight inherit
kunalspathak Apr 6, 2023
52f98c5
inline JIT_GetNonGCThreadStaticBase_Helper to fix the contract error
kunalspathak Apr 7, 2023
cdd79fd
Remove dead code from helper
kunalspathak Apr 7, 2023
bdc67fe
Add GTF_CALL_M_EXP_TLS_ACCESS to check if we do not revisit the alrea…
kunalspathak Apr 7, 2023
c9858d4
address feedback
kunalspathak Apr 7, 2023
a7d290f
Merge remote-tracking branch 'origin/main' into tls
kunalspathak Apr 8, 2023
4f20569
regenerate the files
kunalspathak Apr 8, 2023
746fd04
Introduce fgExpandHelper and fgExpandHelperForBlock and reuse it for …
kunalspathak Apr 8, 2023
b734406
fix the typo
kunalspathak Apr 9, 2023
c67b085
update the assert for runtimelookup
kunalspathak Apr 10, 2023
fc6bb0c
Merge remote-tracking branch 'origin/main' into tls
kunalspathak Apr 10, 2023
047a6ef
check if we should skip rarely run blocks
kunalspathak Apr 10, 2023
30d19d9
review feedback
kunalspathak Apr 11, 2023
be29dcb
Remove GTF_IND_INVARIANT from `typeIndex` access because it produces …
kunalspathak Apr 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ enum CorInfoHelpFunc
CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR,
CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS,
CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS,
CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED,

/* Debugger */

Expand Down Expand Up @@ -1686,6 +1687,7 @@ enum CORINFO_FIELD_ACCESSOR
CORINFO_FIELD_STATIC_GENERICS_STATIC_HELPER, // static field access using the "generic static" helper (argument is MethodTable *)
CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *)
CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access
CORINFO_FIELD_STATIC_TLS_MANAGED, // managed TLS access
CORINFO_FIELD_STATIC_READYTORUN_HELPER, // static field access using a runtime lookup helper
CORINFO_FIELD_STATIC_RELOCATABLE, // static field access using relocation (used in AOT)
CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero)
Expand Down Expand Up @@ -1725,6 +1727,17 @@ struct CORINFO_FIELD_INFO
CORINFO_CONST_LOOKUP fieldLookup; // Used by Ready-to-Run
};

//----------------------------------------------------------------------------
// getThreadLocalStaticBlocksInfo and CORINFO_THREAD_STATIC_BLOCKS_INFO: The EE instructs the JIT about how to access a thread local field

struct CORINFO_THREAD_STATIC_BLOCKS_INFO
{
CORINFO_CONST_LOOKUP tlsIndex;
uint32_t offsetOfThreadLocalStoragePointer;
uint32_t offsetOfMaxThreadStaticBlocks;
uint32_t offsetOfThreadStaticBlocks;
};

//----------------------------------------------------------------------------
// Exception handling

Expand Down Expand Up @@ -2743,6 +2756,12 @@ class ICorStaticInfo
CORINFO_FIELD_INFO *pResult
) = 0;

virtual uint32_t getThreadLocalFieldInfo (
CORINFO_FIELD_HANDLE field) = 0;

virtual void getThreadLocalStaticBlocksInfo (
CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo) = 0;

// Returns true iff "fldHnd" represents a static field.
virtual bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) = 0;

Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ void getFieldInfo(
CORINFO_ACCESS_FLAGS flags,
CORINFO_FIELD_INFO* pResult) override;

uint32_t getThreadLocalFieldInfo(
CORINFO_FIELD_HANDLE field) override;

void getThreadLocalStaticBlocksInfo(
CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo) override;

bool isFieldStatic(
CORINFO_FIELD_HANDLE fldHnd) override;

Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* 3054e9ba-bcfe-417c-9043-92ccc8738b80 */
0x3054e9ba,
0xbcfe,
0x417c,
{0x90, 0x43, 0x92, 0xcc, 0xc8, 0x73, 0x8b, 0x80}
constexpr GUID JITEEVersionIdentifier = { /* 236d7997-3d71-45f9-b7d7-5241ad89a56f */
0x236d7997,
0x3d71,
0x45f9,
{ 0xb7, 0xd7, 0x52, 0x41, 0xad, 0x89, 0xa5, 0x6f }
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
JITHELPER(CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR, JIT_GetSharedNonGCThreadStaticBase, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS, JIT_GetSharedGCThreadStaticBaseDynamicClass, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS, JIT_GetSharedNonGCThreadStaticBaseDynamicClass, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED, JIT_GetSharedNonGCThreadStaticBaseOptimized, CORINFO_HELP_SIG_REG_ONLY)

// Debugger
JITHELPER(CORINFO_HELP_DBG_IS_JUST_MY_CODE, JIT_DbgIsJustMyCode,CORINFO_HELP_SIG_REG_ONLY)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ set( JIT_SOURCES
hwintrinsic.cpp
hostallocator.cpp
ifconversion.cpp
runtimelookup.cpp
helperexpansion.cpp
indirectcalltransformer.cpp
importercalls.cpp
importer.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/ICorJitInfo_names_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ DEF_CLR_API(getFieldClass)
DEF_CLR_API(getFieldType)
DEF_CLR_API(getFieldOffset)
DEF_CLR_API(getFieldInfo)
DEF_CLR_API(getThreadLocalFieldInfo)
DEF_CLR_API(getThreadLocalStaticBlocksInfo)
DEF_CLR_API(isFieldStatic)
DEF_CLR_API(getArrayOrStringLength)
DEF_CLR_API(getBoundaries)
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,23 @@ void WrapICorJitInfo::getFieldInfo(
API_LEAVE(getFieldInfo);
}

uint32_t WrapICorJitInfo::getThreadLocalFieldInfo(
CORINFO_FIELD_HANDLE field)
{
API_ENTER(getThreadLocalFieldInfo);
uint32_t temp = wrapHnd->getThreadLocalFieldInfo(field);
API_LEAVE(getThreadLocalFieldInfo);
return temp;
}

void WrapICorJitInfo::getThreadLocalStaticBlocksInfo(
CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo)
{
API_ENTER(getThreadLocalStaticBlocksInfo);
wrapHnd->getThreadLocalStaticBlocksInfo(pInfo);
API_LEAVE(getThreadLocalStaticBlocksInfo);
}

bool WrapICorJitInfo::isFieldStatic(
CORINFO_FIELD_HANDLE fldHnd)
{
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5420,8 +5420,13 @@ void CodeGen::genCodeForIndir(GenTreeIndir* tree)
if (addr->IsIconHandle(GTF_ICON_TLS_HDL))
{
noway_assert(EA_ATTR(genTypeSize(targetType)) == EA_PTRSIZE);
#if TARGET_64BIT
emit->emitIns_R_C(ins_Load(TYP_I_IMPL), EA_PTRSIZE, tree->GetRegNum(), FLD_GLOBAL_GS,
(int)addr->AsIntCon()->gtIconVal);
#else
emit->emitIns_R_C(ins_Load(TYP_I_IMPL), EA_PTRSIZE, tree->GetRegNum(), FLD_GLOBAL_FS,
(int)addr->AsIntCon()->gtIconVal);
#endif
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5040,6 +5040,12 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
// Partially inline static initializations
DoPhase(this, PHASE_EXPAND_STATIC_INIT, &Compiler::fgExpandStaticInit);

if (TargetOS::IsWindows)
{
// Currently this is only applicable for Windows
DoPhase(this, PHASE_EXPAND_TLS, &Compiler::fgExpandThreadLocalAccess);
}

// Insert GC Polls
DoPhase(this, PHASE_INSERT_GC_POLLS, &Compiler::fgInsertGCPolls);

Expand Down
28 changes: 25 additions & 3 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4862,7 +4862,7 @@ class Compiler

GenTree* fgInitThisClass();

GenTreeCall* fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfoHelpFunc helper);
GenTreeCall* fgGetStaticsCCtorHelper(CORINFO_CLASS_HANDLE cls, CorInfoHelpFunc helper, uint32_t typeIndex = 0);

GenTreeCall* fgGetSharedCCtor(CORINFO_CLASS_HANDLE cls);

Expand Down Expand Up @@ -5311,11 +5311,21 @@ class Compiler
PhaseStatus StressSplitTree();
void SplitTreesRandomly();
void SplitTreesRemoveCommas();

template <bool (Compiler::*ExpansionFunction)(BasicBlock*, Statement*, GenTreeCall*)>
PhaseStatus fgExpandHelper(bool skipRarelyRunBlocks);

template <bool (Compiler::*ExpansionFunction)(BasicBlock*, Statement*, GenTreeCall*)>
bool fgExpandHelperForBlock(BasicBlock* block);

PhaseStatus fgExpandRuntimeLookups();
bool fgExpandRuntimeLookupsForCall(BasicBlock* block, Statement* stmt, GenTreeCall* call);

PhaseStatus fgExpandThreadLocalAccess();
bool fgExpandThreadLocalAccessForCall(BasicBlock* block, Statement* stmt, GenTreeCall* call);

bool fgExpandStaticInitForBlock(BasicBlock* block);
bool fgExpandStaticInitForCall(BasicBlock* block, Statement* stmt, GenTreeCall* call);
PhaseStatus fgExpandStaticInit();
bool fgExpandStaticInitForCall(BasicBlock* block, Statement* stmt, GenTreeCall* call);

PhaseStatus fgInsertGCPolls();
BasicBlock* fgCreateGCPoll(GCPollType pollType, BasicBlock* block);
Expand Down Expand Up @@ -7039,6 +7049,7 @@ class Compiler
#define OMF_HAS_MDNEWARRAY 0x00002000 // Method contains 'new' of an MD array
#define OMF_HAS_MDARRAYREF 0x00004000 // Method contains multi-dimensional intrinsic array element loads or stores.
#define OMF_HAS_STATIC_INIT 0x00008000 // Method has static initializations we might want to partially inline
#define OMF_HAS_TLS_FIELD 0x00010000 // Method contains TLS field access

// clang-format on

Expand Down Expand Up @@ -7089,6 +7100,16 @@ class Compiler
optMethodFlags |= OMF_HAS_GUARDEDDEVIRT;
}

bool doesMethodHasTlsFieldAccess()
{
return (optMethodFlags & OMF_HAS_TLS_FIELD) != 0;
}

void setMethodHasTlsFieldAccess()
{
optMethodFlags |= OMF_HAS_TLS_FIELD;
}

void pickGDV(GenTreeCall* call,
IL_OFFSET ilOffset,
bool isInterface,
Expand Down Expand Up @@ -7790,6 +7811,7 @@ class Compiler
void eeGetFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_ACCESS_FLAGS flags,
CORINFO_FIELD_INFO* pResult);
uint32_t eeGetThreadLocalFieldInfo(CORINFO_FIELD_HANDLE field);

// Get the flags

Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3635,6 +3635,7 @@ inline bool Compiler::IsSharedStaticHelper(GenTree* tree)
helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE ||
helper == CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR ||
helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR ||
helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED ||
helper == CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS ||
helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS ||
#ifdef FEATURE_READYTORUN
Expand Down Expand Up @@ -3684,12 +3685,12 @@ inline bool Compiler::IsGcSafePoint(GenTreeCall* call)
// Note that we want to have two special FIELD_HANDLES that will both
// be considered non-Data Offset handles
//
// The special values that we use are FLD_GLOBAL_DS and FLD_GLOBAL_FS
// The special values that we use are FLD_GLOBAL_DS, FLD_GLOBAL_FS or FLD_GLOBAL_GS.
//

inline bool jitStaticFldIsGlobAddr(CORINFO_FIELD_HANDLE fldHnd)
{
return (fldHnd == FLD_GLOBAL_DS || fldHnd == FLD_GLOBAL_FS);
return (fldHnd == FLD_GLOBAL_DS || fldHnd == FLD_GLOBAL_FS || fldHnd == FLD_GLOBAL_GS);
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ CompPhaseNameMacro(PHASE_COMPUTE_EDGE_WEIGHTS2, "Compute edge weights (2, f
CompPhaseNameMacro(PHASE_STRESS_SPLIT_TREE, "Stress gtSplitTree", false, -1, false)
CompPhaseNameMacro(PHASE_EXPAND_RTLOOKUPS, "Expand runtime lookups", false, -1, true)
CompPhaseNameMacro(PHASE_EXPAND_STATIC_INIT, "Expand static init", false, -1, true)
CompPhaseNameMacro(PHASE_EXPAND_TLS, "Expand TLS access", false, -1, true)
CompPhaseNameMacro(PHASE_INSERT_GC_POLLS, "Insert GC Polls", false, -1, true)
CompPhaseNameMacro(PHASE_DETERMINE_FIRST_COLD_BLOCK, "Determine first cold block", false, -1, true)
CompPhaseNameMacro(PHASE_RATIONALIZE, "Rationalize IR", false, -1, false)
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/ee_il_dll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void Compiler::eeGetFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken,
info.compCompHnd->getFieldInfo(pResolvedToken, info.compMethodHnd, accessFlags, pResult);
}

FORCEINLINE
uint32_t Compiler::eeGetThreadLocalFieldInfo(CORINFO_FIELD_HANDLE field)
{
return info.compCompHnd->getThreadLocalFieldInfo(field);
}

kunalspathak marked this conversation as resolved.
Show resolved Hide resolved
/*****************************************************************************
*
* VOS info, method sigs, etc
Expand Down
7 changes: 6 additions & 1 deletion src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13804,7 +13804,7 @@ void emitter::emitInsLoadStoreOp(instruction ins, emitAttr attr, regNumber dataR

if (addr->isContained())
{
assert(addr->OperIs(GT_CLS_VAR_ADDR, GT_LCL_ADDR, GT_LEA));
assert(addr->OperIs(GT_CLS_VAR_ADDR, GT_LCL_ADDR, GT_LEA) || (addr->IsIconHandle(GTF_ICON_TLS_HDL)));

int offset = 0;
DWORD lsl = 0;
Expand Down Expand Up @@ -13927,6 +13927,11 @@ void emitter::emitInsLoadStoreOp(instruction ins, emitAttr attr, regNumber dataR
emitIns_R_S(ins, attr, dataReg, lclNum, offset);
}
}
else if (addr->IsIconHandle(GTF_ICON_TLS_HDL))
{
// On Arm64, TEB is in r18, so load from the r18 as base.
emitIns_R_R_I(ins, attr, dataReg, REG_R18, addr->AsIntCon()->IconValue());
}
else if (emitIns_valid_imm_for_ldst_offset(offset, emitTypeSize(indir->TypeGet())))
{
// Then load/store dataReg from/to [memBase + offset]
Expand Down
52 changes: 43 additions & 9 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7260,6 +7260,10 @@ void emitter::emitIns_R_C(instruction ins, emitAttr attr, regNumber reg, CORINFO
{
sz += 1;
}
else if (fldHnd == FLD_GLOBAL_GS)
{
sz += 2; // Needs SIB byte as well.
}
}

id->idCodeSize(sz);
Expand Down Expand Up @@ -7328,7 +7332,7 @@ void emitter::emitIns_C_R(instruction ins, emitAttr attr, CORINFO_FIELD_HANDLE f
}

// Special case: mov reg, fs:[ddd]
if (fldHnd == FLD_GLOBAL_FS)
if ((fldHnd == FLD_GLOBAL_FS) || (fldHnd == FLD_GLOBAL_GS))
{
sz += 1;
}
Expand Down Expand Up @@ -10001,6 +10005,12 @@ void emitter::emitDispClsVar(CORINFO_FIELD_HANDLE fldHnd, ssize_t offs, bool rel
return;
}

if (fldHnd == FLD_GLOBAL_GS)
{
printf("GS:[0x%04X]", (unsigned)offs);
return;
}

if (fldHnd == FLD_GLOBAL_DS)
{
printf("[0x%04X]", (unsigned)offs);
Expand Down Expand Up @@ -13336,11 +13346,16 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
fldh = id->idAddr()->iiaFieldHnd;
offs = emitGetInsDsp(id);

// Special case: mov reg, fs:[ddd]
if (fldh == FLD_GLOBAL_FS)
{
// Special case: mov reg, fs:[ddd]
dst += emitOutputByte(dst, 0x64);
}
else if (fldh == FLD_GLOBAL_GS)
{
// Special case: mov reg, gs:[ddd]
dst += emitOutputByte(dst, 0x65);
}

// Compute VEX/EVEX prefix
// Some of its callers already add EVEX/VEX prefix and then call this routine.
Expand Down Expand Up @@ -13550,6 +13565,11 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
}
}

if (fldh == FLD_GLOBAL_GS)
{
dst += emitOutputByte(dst, 0x25);
}

// Do we have a constant or a static data member?
doff = Compiler::eeGetJitDataOffs(fldh);
if (doff >= 0)
Expand Down Expand Up @@ -13629,12 +13649,18 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
#endif // TARGET_AMD64

#ifdef TARGET_AMD64
// All static field and data section constant accesses should be marked as relocatable
noway_assert(id->idIsDspReloc());
dst += emitOutputLong(dst, 0);
#else // TARGET_X86
if (id->idIsDspReloc())
{
// All static field and data section constant accesses should be marked as relocatable
dst += emitOutputLong(dst, 0);
}
else
{
dst += emitOutputLong(dst, (ssize_t)target);
}
#else
dst += emitOutputLong(dst, (int)(ssize_t)target);
#endif // TARGET_X86
#endif // TARGET_AMD64

if (id->idIsDspReloc())
{
Expand Down Expand Up @@ -16447,8 +16473,16 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp)
code = insEncodeReg3456(id, id->idReg1(), size, code);
}

regcode = (insEncodeReg345(id, id->idReg1(), size, &code) << 8);
dst = emitOutputCV(dst, id, code | regcode | 0x0500);
regcode = (insEncodeReg345(id, id->idReg1(), size, &code) << 8);
CORINFO_FIELD_HANDLE fldh = id->idAddr()->iiaFieldHnd;
if (fldh == FLD_GLOBAL_GS)
{
dst = emitOutputCV(dst, id, code | regcode | 0x0400);
}
else
{
dst = emitOutputCV(dst, id, code | regcode | 0x0500);
}
}

sz = emitSizeOfInsDsc(id);
Expand Down
Loading