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

[NativeAOT] Inline TLS access for windows/x64 #89472

Merged
merged 64 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f1c5228
wip
kunalspathak Jul 7, 2023
91ee21f
working model
kunalspathak Jul 10, 2023
fe242f1
wip
kunalspathak Jul 11, 2023
fcf00d2
wip
kunalspathak Jul 21, 2023
f736b2c
working
kunalspathak Jul 25, 2023
6cd92f3
Add helper for tlsIndex
kunalspathak Jul 25, 2023
87c3f25
add methods in superpmi
kunalspathak Jul 25, 2023
fb364a0
revert some local changes
kunalspathak Jul 25, 2023
e9610c6
misc fixes
kunalspathak Jul 25, 2023
86d01a7
Stop emitting TLS access code for windows/x64
kunalspathak Jul 25, 2023
09eaeb4
fix linux build errors
kunalspathak Jul 28, 2023
337c2f4
Do not throw not implemented for windows/x64
kunalspathak Jul 28, 2023
1209465
fix the problem where ThreadStaticBase helper was still getting invoked
kunalspathak Jul 28, 2023
85e1db6
Revert certain changes from JIT method
kunalspathak Jul 28, 2023
a3d3070
Introduce getThreadLocalStaticInfo_ReadyToRun()
kunalspathak Jul 29, 2023
800005d
Consume getThreadLocalStaticInfo_ReadyToRun()
kunalspathak Jul 29, 2023
4766211
Remove getTlsRootInfo() and other methods
kunalspathak Jul 29, 2023
b9adff7
Revert unneeded changes
kunalspathak Jul 29, 2023
9ca78ae
missing gtInitCldHnd initialization
kunalspathak Jul 30, 2023
b142d28
save target address
kunalspathak Jul 30, 2023
79de728
jit format
kunalspathak Jul 30, 2023
25482b9
Merge remote-tracking branch 'origin/main' into tls_nativeaot_winx64
kunalspathak Nov 20, 2023
1fe8103
run thunkgenerator
kunalspathak Nov 20, 2023
7c03b66
resolve merge conflicts
kunalspathak Dec 1, 2023
07c839b
fix issues so the TLS is inlined
kunalspathak Dec 1, 2023
65ceeaa
Rename data structures from *_ReadyToRun to *_NativeAOT
kunalspathak Dec 7, 2023
8af0e6e
Merge remote-tracking branch 'origin/main' into working_tls_nativeaot…
kunalspathak Dec 7, 2023
fc8e2b8
jit format
kunalspathak Dec 7, 2023
d7e7f9d
fix some unit test
kunalspathak Dec 8, 2023
b70ceeb
fix a bug
kunalspathak Dec 8, 2023
f6552f2
fix the weird jump problem
kunalspathak Dec 9, 2023
57893d8
use enclosing type cls handle for VN of static gc/non-gc helper
kunalspathak Dec 10, 2023
1537ecd
fix a bug of resetting the flag
kunalspathak Dec 11, 2023
ab95bb9
useEnclosingTypeOnly from runtime to determine if VN should optimize it
kunalspathak Dec 13, 2023
c9040a2
do not use vnf, but only use useEnclosingTypeAsArg0
kunalspathak Dec 14, 2023
5f76a6c
Use GT_COMMA to add GCStaticBase call next to TLS call
kunalspathak Dec 14, 2023
3d16881
Merge remote-tracking branch 'kp/vn_staticbase' into working_tls_nati…
kunalspathak Dec 14, 2023
daca626
optimize the cctor call
kunalspathak Dec 14, 2023
c7d75ef
Remove lazy ctor generation from tls
kunalspathak Dec 15, 2023
5895ab3
Update jitinterface to not fetch data for lazy ctor
kunalspathak Dec 15, 2023
d53f324
Merge remote-tracking branch 'origin/main' into working_tls_nativeaot…
kunalspathak Dec 15, 2023
571b6df
fix errors after merge
kunalspathak Dec 15, 2023
da95659
fix test build errors
kunalspathak Dec 16, 2023
8679e4b
fix bug in CSE
kunalspathak Dec 16, 2023
0ce7618
Use CORINFO_FLG_FIELD_INITCLASS instead of separate flag
kunalspathak Dec 18, 2023
b38a17c
Use the INITCLASS flag
kunalspathak Dec 18, 2023
1c1092d
Remove useEnclosingTypeOnly
kunalspathak Dec 19, 2023
119e2ae
Add NoCtor
kunalspathak Dec 19, 2023
9cfea39
Use CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR
kunalspathak Dec 19, 2023
2cc3ca1
Minor cleanup
kunalspathak Dec 19, 2023
8389a88
Merge remote-tracking branch 'origin/main' into tls_nativeaot_winx64
kunalspathak Jan 3, 2024
59085d2
Renegenrate thunk
kunalspathak Jan 3, 2024
fa1059f
Add the SetFalseTarget
kunalspathak Jan 4, 2024
63c9fd6
Merge remote-tracking branch 'origin/main' into tls_nativeaot_winx64
kunalspathak Jan 10, 2024
0069167
fix merge conflict resolution
kunalspathak Jan 10, 2024
38bca3b
better handling of GTF_ICON_SECREL_OFFSET
kunalspathak Jan 10, 2024
a5fcc59
review feedback
kunalspathak Jan 10, 2024
ceda478
Disable optimization for minopts
kunalspathak Jan 11, 2024
aba00e2
Add comments around iiaSecRel
kunalspathak Jan 11, 2024
24f88a0
jit format
kunalspathak Jan 11, 2024
65f3900
create emitNewInstrCns()
kunalspathak Jan 11, 2024
5bc0a1a
Expand TLS even if optimization is disabled
kunalspathak Jan 12, 2024
959869a
Track t_inlinedThreadStaticBase
kunalspathak Jan 12, 2024
bff4728
jit format
kunalspathak Jan 13, 2024
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
17 changes: 17 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ enum CorInfoHelpFunc
CORINFO_HELP_READYTORUN_GCSTATIC_BASE, // static gc field access
CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, // static non gc field access
CORINFO_HELP_READYTORUN_THREADSTATIC_BASE,
CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR,
CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE,
CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR,
CORINFO_HELP_READYTORUN_GENERIC_HANDLE,
Expand Down Expand Up @@ -1737,6 +1738,17 @@ struct CORINFO_THREAD_STATIC_BLOCKS_INFO
uint32_t offsetOfGCDataPointer;
};

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

struct CORINFO_THREAD_STATIC_INFO_NATIVEAOT
{
uint32_t offsetOfThreadLocalStoragePointer;
CORINFO_CONST_LOOKUP tlsRootObject;
CORINFO_CONST_LOOKUP tlsIndexObject;
CORINFO_CONST_LOOKUP threadStaticBaseSlow;
};

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

Expand Down Expand Up @@ -2830,6 +2842,10 @@ class ICorStaticInfo
bool isGCType
) = 0;

virtual void getThreadLocalStaticInfo_NativeAOT(
CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo
) = 0;

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

Expand Down Expand Up @@ -3364,6 +3380,7 @@ class ICorDynamicInfo : public ICorStaticInfo
// It would be nicer to use existing IMAGE_REL_XXX constants instead of defining our own here...
#define IMAGE_REL_BASED_REL32 0x10
#define IMAGE_REL_BASED_THUMB_BRANCH24 0x13
#define IMAGE_REL_SECREL 0x104

// The identifier for ARM32-specific PC-relative address
// computation corresponds to the following instruction
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ void getThreadLocalStaticBlocksInfo(
CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo,
bool isGCType) override;

void getThreadLocalStaticInfo_NativeAOT(
CORINFO_THREAD_STATIC_INFO_NATIVEAOT* 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 = { /* a19264d9-82b9-4aa4-833f-ee4b52352d7e */
0xa19264d9,
0x82b9,
0x4aa4,
{0x83, 0x3f, 0xee, 0x4b, 0x52, 0x35, 0x2d, 0x7e}
constexpr GUID JITEEVersionIdentifier = { /* d7bbeb5a-aa7d-43ec-b29e-6f24dd3bca9c */
0xd7bbeb5a,
0xaa7d,
0x43ec,
{0xb2, 0x9e, 0x6f, 0x24, 0xdd, 0x3b, 0xca, 0x9c}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
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 @@ -264,6 +264,7 @@
JITHELPER(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB)
JITHELPER(CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB)
JITHELPER(CORINFO_HELP_READYTORUN_THREADSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB)
JITHELPER(CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB)
JITHELPER(CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE, NULL,CORINFO_HELP_SIG_NO_ALIGN_STUB)
JITHELPER(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB)
JITHELPER(CORINFO_HELP_READYTORUN_GENERIC_HANDLE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_names_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ DEF_CLR_API(getFieldOffset)
DEF_CLR_API(getFieldInfo)
DEF_CLR_API(getThreadLocalFieldInfo)
DEF_CLR_API(getThreadLocalStaticBlocksInfo)
DEF_CLR_API(getThreadLocalStaticInfo_NativeAOT)
DEF_CLR_API(isFieldStatic)
DEF_CLR_API(getArrayOrStringLength)
DEF_CLR_API(getBoundaries)
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,14 @@ void WrapICorJitInfo::getThreadLocalStaticBlocksInfo(
API_LEAVE(getThreadLocalStaticBlocksInfo);
}

void WrapICorJitInfo::getThreadLocalStaticInfo_NativeAOT(
CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo)
{
API_ENTER(getThreadLocalStaticInfo_NativeAOT);
wrapHnd->getThreadLocalStaticInfo_NativeAOT(pInfo);
API_LEAVE(getThreadLocalStaticInfo_NativeAOT);
}

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 @@ -616,6 +616,11 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre
attr = EA_SET_FLG(attr, EA_BYREF_FLG);
}

if (con->IsIconHandle(GTF_ICON_SECREL_OFFSET))
{
attr = EA_SET_FLG(attr, EA_CNS_SEC_RELOC);
}

instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal,
INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags));
regSet.verifyRegUsed(targetReg);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5854,6 +5854,7 @@ class Compiler

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

PhaseStatus fgExpandStaticInit();
bool fgExpandStaticInitForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call);
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3941,6 +3941,7 @@ inline bool Compiler::IsSharedStaticHelper(GenTree* tree)
#ifdef FEATURE_READYTORUN
helper == CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE || helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE ||
helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE || helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE ||
helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR ||
helper == CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE ||
#endif
helper == CORINFO_HELP_CLASSINIT_SHARED_DYNAMICCLASS;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ class emitter
return iiaJmpOffset;
}
#endif // defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)

bool isSecRel;
kunalspathak marked this conversation as resolved.
Show resolved Hide resolved
} _idAddrUnion;

/* Trivial wrappers to return properly typed enums */
Expand Down
15 changes: 14 additions & 1 deletion src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5712,6 +5712,11 @@ void emitter::emitIns_R_I(instruction ins,
id->idDebugOnlyInfo()->idMemCookie = targetHandle;
#endif

if (emitComp->opts.IsReadyToRun() && EA_IS_CNS_SEC_RELOC(attr))
{
id->idAddr()->isSecRel = true;
}

kunalspathak marked this conversation as resolved.
Show resolved Hide resolved
if (isSimdInsAndValInByte)
{
bool includeRexPrefixSize = true;
Expand Down Expand Up @@ -15098,7 +15103,15 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id)

if (id->idIsCnsReloc())
{
emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, IMAGE_REL_BASED_MOFFSET);
if (emitComp->opts.IsReadyToRun() && id->idAddr()->isSecRel)
{
emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, IMAGE_REL_SECREL);
}
else
{
emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val,
IMAGE_REL_BASED_MOFFSET);
}
}

goto DONE;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ enum GenTreeFlags : unsigned int
GTF_ICON_STATIC_BOX_PTR = 0x10000000, // GT_CNS_INT -- constant is an address of the box for a STATIC_IN_HEAP field
GTF_ICON_FIELD_SEQ = 0x11000000, // <--------> -- constant is a FieldSeq* (used only as VNHandle)
GTF_ICON_STATIC_ADDR_PTR = 0x13000000, // GT_CNS_INT -- constant is a pointer to a static base address
GTF_ICON_SECREL_OFFSET = 0x14000000, // GT_CNS_INT -- constant is an offset in a certain section.

// GTF_ICON_REUSE_REG_VAL = 0x00800000 // GT_CNS_INT -- GTF_REUSE_REG_VAL, defined above
GTF_ICON_SIMD_COUNT = 0x00200000, // GT_CNS_INT -- constant is Vector<T>.Count
Expand Down
Loading
Loading