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: Guarded devirtualization #64497

Merged
merged 40 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
17c3b8c
Initial implementation
EgorBo Jan 29, 2022
e0a25e0
basic getExactClasses impl
EgorBo Jan 29, 2022
ad64be3
Merge branch 'main' of https://github.com/dotnet/runtime into gdv-nat…
EgorBo Feb 25, 2022
9643359
fix merge conflicts
EgorBo Feb 25, 2022
10ed069
fix merge conflicts
EgorBo Feb 25, 2022
84b0b50
fix merge conflicts
EgorBo Feb 25, 2022
ee67913
fix merge conflicts
EgorBo Feb 25, 2022
07f053e
Implement GetImplementingClasses
EgorBo Feb 25, 2022
29c0f93
Merge branch 'main' of https://github.com/dotnet/runtime into gdv-nat…
EgorBo Feb 25, 2022
ec97ddb
Make checks more conservative
EgorBo Feb 25, 2022
0685c07
Another attempt
EgorBo Feb 25, 2022
1439bcc
Merge branch 'main' of github.com:dotnet/runtime into gdv-nativeaot
EgorBo Jul 17, 2022
cda167d
update guid
EgorBo Jul 17, 2022
527b302
Merge branch 'main' of github.com:dotnet/runtime into gdv-nativeaot
EgorBo Jul 18, 2022
0e8adab
Fix importer logic
EgorBo Jul 18, 2022
a1617c6
Update importer.cpp
EgorBo Jul 19, 2022
9ada528
Merge branch 'main' of github.com:dotnet/runtime into gdv-nativeaot
EgorBo Jul 21, 2022
46f84a5
Don't use GDV
EgorBo Jul 21, 2022
f87300f
Clean up
EgorBo Jul 21, 2022
cd4aa36
Refactoring
EgorBo Jul 21, 2022
d9721c0
Clean up
EgorBo Jul 21, 2022
b492373
Update importer.cpp
EgorBo Jul 21, 2022
d83f514
Make things more conservative
MichalStrehovsky Jul 22, 2022
be28832
Clean up
EgorBo Jul 22, 2022
1359e43
Merge branch 'gdv-nativeaot' of github.com:EgorBo/runtime-1 into gdv-…
EgorBo Jul 22, 2022
a73bdef
Clean up
EgorBo Jul 22, 2022
90b8bfa
Clean up
EgorBo Jul 22, 2022
e76b472
IDynamicInterfaceCastable and template type loader cases
MichalStrehovsky Jul 25, 2022
c30f1ee
Address feedback
EgorBo Jul 27, 2022
497b843
ignore types which require runtime lookup
EgorBo Jul 28, 2022
19d6690
Merge branch 'main' into gdv-nativeaot
EgorBo Aug 12, 2022
e19f094
Merge branch 'main' of github.com:dotnet/runtime into gdv-nativeaot
EgorBo Aug 12, 2022
7559015
address feedback
EgorBo Aug 12, 2022
e4eca63
fix build
EgorBo Aug 12, 2022
cb74fc9
Merge branch 'main' into gdv-nativeaot
MichalStrehovsky Aug 12, 2022
d170052
Restore old logic
MichalStrehovsky Aug 12, 2022
6bf87db
One more lost diff
MichalStrehovsky Aug 12, 2022
6728e6a
Merge branch 'main' of github.com:dotnet/runtime into gdv-nativeaot
EgorBo Aug 15, 2022
6cd67e6
add JitEnableExactDevirtualization
EgorBo Aug 15, 2022
292d1d8
fix build
EgorBo Aug 15, 2022
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
9 changes: 9 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,15 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE *vcTypeRet /* OUT */
) = 0;

// Obtains a list of exact classes for a given base type. Returns 0 if the number of
// the exact classes is greater than maxExactClasses or if more types might be loaded
// in future.
virtual int getExactClasses(
CORINFO_CLASS_HANDLE baseType, /* IN */
int maxExactClasses, /* IN */
CORINFO_CLASS_HANDLE* exactClsRet /* OUT */
) = 0;

// If the Arg is a CORINFO_TYPE_CLASS fetch the class handle associated with it
virtual CORINFO_CLASS_HANDLE getArgClass (
CORINFO_SIG_INFO* sig, /* IN */
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ CorInfoTypeWithMod getArgType(
CORINFO_ARG_LIST_HANDLE args,
CORINFO_CLASS_HANDLE* vcTypeRet) override;

int getExactClasses(
CORINFO_CLASS_HANDLE baseType,
int maxExactClasses,
CORINFO_CLASS_HANDLE* exactClsRet) override;

CORINFO_CLASS_HANDLE getArgClass(
CORINFO_SIG_INFO* sig,
CORINFO_ARG_LIST_HANDLE args) 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 = { /* 4efa8fe2-8489-4b61-aac9-b4df74af15b7 */
0x4efa8fe2,
0x8489,
0x4b61,
{0xaa, 0xc9, 0xb4, 0xdf, 0x74, 0xaf, 0x15, 0xb7}
constexpr GUID JITEEVersionIdentifier = { /* 1b9551b8-21f4-4233-9c90-f3eabd6a322b */
0x1b9551b8,
0x21f4,
0x4233,
{0x9c, 0x90, 0xf3, 0xea, 0xbd, 0x6a, 0x32, 0x2b}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ DEF_CLR_API(allocateArray)
DEF_CLR_API(freeArray)
DEF_CLR_API(getArgNext)
DEF_CLR_API(getArgType)
DEF_CLR_API(getExactClasses)
DEF_CLR_API(getArgClass)
DEF_CLR_API(getHFAType)
DEF_CLR_API(GetErrorHRESULT)
Expand Down
11 changes: 11 additions & 0 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,17 @@ CorInfoTypeWithMod WrapICorJitInfo::getArgType(
return temp;
}

int WrapICorJitInfo::getExactClasses(
CORINFO_CLASS_HANDLE baseType,
int maxExactClasses,
CORINFO_CLASS_HANDLE* exactClsRet)
{
API_ENTER(getExactClasses);
int temp = wrapHnd->getExactClasses(baseType, maxExactClasses, exactClsRet);
API_LEAVE(getExactClasses);
return temp;
}

CORINFO_CLASS_HANDLE WrapICorJitInfo::getArgClass(
CORINFO_SIG_INFO* sig,
CORINFO_ARG_LIST_HANDLE args)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17773,6 +17773,16 @@ CORINFO_CLASS_HANDLE Compiler::gtGetClassHandle(GenTree* tree, bool* pIsExact, b
}
}

if ((objClass != NO_CLASS_HANDLE) && !*pIsExact && JitConfig.JitEnableExactDevirtualization())
{
CORINFO_CLASS_HANDLE exactClass;
if (info.compCompHnd->getExactClasses(objClass, 1, &exactClass) == 1)
{
*pIsExact = true;
objClass = exactClass;
}
}

return objClass;
}

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ CONFIG_INTEGER(JitCrossCheckDevirtualizationAndPGO, W("JitCrossCheckDevirtualiza
CONFIG_INTEGER(JitNoteFailedExactDevirtualization, W("JitNoteFailedExactDevirtualization"), 0)
#endif // debug

// Devirtualize virtual calls with getExactClasses (NativeAOT only for now)
CONFIG_INTEGER(JitEnableExactDevirtualization, W("JitEnableExactDevirtualization"), 1)

// Control when Virtual Calls are expanded
CONFIG_INTEGER(JitExpandCallsEarly, W("JitExpandCallsEarly"), 1) // Expand Call targets early (in the global morph
// phase)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3174,6 +3174,16 @@ void Compiler::lvaSetClass(unsigned varNum, CORINFO_CLASS_HANDLE clsHnd, bool is
return;
}

if (clsHnd != NO_CLASS_HANDLE && !isExact && JitConfig.JitEnableExactDevirtualization())
{
CORINFO_CLASS_HANDLE exactClass;
if (info.compCompHnd->getExactClasses(clsHnd, 1, &exactClass) == 1)
{
isExact = true;
clsHnd = exactClass;
}
}

// Else we should have a type handle.
assert(clsHnd != nullptr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ protected virtual MethodDesc ResolveVirtualMethod(MethodDesc declMethod, DefType
/// so it can answer this question.
/// </remarks>
public virtual bool CanConstructType(TypeDesc type) => true;

public virtual TypeDesc[] GetImplementingClasses(TypeDesc type) => null;
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
#endif
}
}
Loading