diff --git a/src/coreclr/clrdefinitions.cmake b/src/coreclr/clrdefinitions.cmake index a1491f5b5a728c..60b79850f53ffd 100644 --- a/src/coreclr/clrdefinitions.cmake +++ b/src/coreclr/clrdefinitions.cmake @@ -184,7 +184,10 @@ if (FEATURE_TIERED_COMPILATION) add_compile_definitions(FEATURE_TIERED_COMPILATION) endif(FEATURE_TIERED_COMPILATION) -add_compile_definitions(FEATURE_PGO) +if (FEATURE_PGO) + add_compile_definitions(FEATURE_PGO) +endif(FEATURE_PGO) + if (CLR_CMAKE_TARGET_ARCH_AMD64) # Enable the AMD64 Unix struct passing JIT-EE interface for all AMD64 platforms, to enable altjit. add_definitions(-DUNIX_AMD64_ABI_ITF) diff --git a/src/coreclr/clrfeatures.cmake b/src/coreclr/clrfeatures.cmake index 7b87cefead0c25..c92f7697a7a048 100644 --- a/src/coreclr/clrfeatures.cmake +++ b/src/coreclr/clrfeatures.cmake @@ -10,6 +10,7 @@ endif() if (FEATURE_DYNAMIC_CODE_COMPILED) set(FEATURE_TIERED_COMPILATION 1) set(FEATURE_REJIT 1) + set(FEATURE_PGO 1) endif() # On desktop, if dynamic code compiled is false, we still enable static linking so we don't have to add platform manifest entries diff --git a/src/coreclr/inc/jithelpers.h b/src/coreclr/inc/jithelpers.h index 4ea275c055a02f..17d3f193197887 100644 --- a/src/coreclr/inc/jithelpers.h +++ b/src/coreclr/inc/jithelpers.h @@ -329,6 +329,7 @@ JITHELPER(CORINFO_HELP_PATCHPOINT, JIT_Patchpoint, METHOD__NIL) JITHELPER(CORINFO_HELP_PATCHPOINT_FORCED, JIT_PatchpointForced, METHOD__NIL) +#ifdef FEATURE_PGO JITHELPER(CORINFO_HELP_CLASSPROFILE32, JIT_ClassProfile32, METHOD__NIL) JITHELPER(CORINFO_HELP_CLASSPROFILE64, JIT_ClassProfile64, METHOD__NIL) JITHELPER(CORINFO_HELP_DELEGATEPROFILE32, JIT_DelegateProfile32, METHOD__NIL) @@ -339,6 +340,18 @@ JITHELPER(CORINFO_HELP_COUNTPROFILE64, JIT_CountProfile64, METHOD__NIL) JITHELPER(CORINFO_HELP_VALUEPROFILE32, JIT_ValueProfile32, METHOD__NIL) JITHELPER(CORINFO_HELP_VALUEPROFILE64, JIT_ValueProfile64, METHOD__NIL) +#else + JITHELPER(CORINFO_HELP_CLASSPROFILE32, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_CLASSPROFILE64, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_DELEGATEPROFILE32, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_DELEGATEPROFILE64, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_VTABLEPROFILE32, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_VTABLEPROFILE64, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_COUNTPROFILE32, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_COUNTPROFILE64, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_VALUEPROFILE32, NULL, METHOD__NIL) + JITHELPER(CORINFO_HELP_VALUEPROFILE64, NULL, METHOD__NIL) +#endif #if defined(TARGET_AMD64) || defined(TARGET_ARM64) JITHELPER(CORINFO_HELP_VALIDATE_INDIRECT_CALL, JIT_ValidateIndirectCall, METHOD__NIL) diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp index 328c99bb96516d..952824661b77fa 100644 --- a/src/coreclr/vm/jithelpers.cpp +++ b/src/coreclr/vm/jithelpers.cpp @@ -1776,6 +1776,8 @@ HCIMPLEND #endif // FEATURE_ON_STACK_REPLACEMENT +#ifdef FEATURE_PGO + static unsigned HandleHistogramProfileRand() { // Generate a random number (xorshift32) @@ -2179,6 +2181,8 @@ HCIMPL1(void, JIT_CountProfile64, volatile LONG64* pCounter) } HCIMPLEND +#endif // FEATURE_PGO + //======================================================================== // // INTEROP HELPERS diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 0724c7ac359723..0a84f65bfb707c 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -12717,10 +12717,15 @@ HRESULT CEEJitInfo::getPgoInstrumentationResults( } CONTRACTL_END; HRESULT hr = E_FAIL; + *pSchema = NULL; *pCountSchemaItems = 0; *pInstrumentationData = NULL; *pPgoSource = PgoSource::Unknown; +#ifdef FEATURE_PGO *pDynamicPgo = g_pConfig->TieredPGO(); +#else + *pDynamicPgo = false; +#endif JIT_TO_EE_TRANSITION(); diff --git a/src/coreclr/vm/pgo.cpp b/src/coreclr/vm/pgo.cpp index d91ed7dfea521f..2df6bbf5fa5e47 100644 --- a/src/coreclr/vm/pgo.cpp +++ b/src/coreclr/vm/pgo.cpp @@ -1230,9 +1230,29 @@ HRESULT PgoManager::allocPgoInstrumentationBySchema(MethodDesc* pMD, ICorJitInfo // Stub version for !FEATURE_PGO builds // -HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, NewArrayHolder *pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData) +HRESULT PgoManager::getPgoInstrumentationResultsFromR2RFormat(ReadyToRunInfo *pReadyToRunInfo, + Module* pModule, + ReadyToRunLoadedImage* pNativeImage, + BYTE* pR2RFormatData, + size_t pR2RFormatDataMaxSize, + BYTE** pAllocatedData, + ICorJitInfo::PgoInstrumentationSchema** ppSchema, + UINT32 *pCountSchemaItems, + BYTE**pInstrumentationData) { *pAllocatedData = NULL; + *ppSchema = NULL; + *pCountSchemaItems = 0; + *pInstrumentationData = NULL; + return E_NOTIMPL; +} + +// Stub version for !FEATURE_PGO builds +// +HRESULT PgoManager::getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource) +{ + *pAllocatedData = NULL; + *ppSchema = NULL; *pCountSchemaItems = 0; *pInstrumentationData = NULL; return E_NOTIMPL; @@ -1244,7 +1264,7 @@ void PgoManager::VerifyAddress(void* address) // Stub version for !FEATURE_PGO builds // -void PgoManager::CreatePgoManager(PgoManager** ppMgr, bool loaderAllocator) +void PgoManager::CreatePgoManager(PgoManager* volatile* ppMgr, bool loaderAllocator) { *ppMgr = NULL; } diff --git a/src/coreclr/vm/pgo.h b/src/coreclr/vm/pgo.h index 8a487dc315b407..1eb45603ee8097 100644 --- a/src/coreclr/vm/pgo.h +++ b/src/coreclr/vm/pgo.h @@ -23,7 +23,7 @@ class PgoManager public: - static HRESULT getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedDatapAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource); + static HRESULT getPgoInstrumentationResults(MethodDesc* pMD, BYTE **pAllocatedData, ICorJitInfo::PgoInstrumentationSchema** ppSchema, UINT32 *pCountSchemaItems, BYTE**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource); static HRESULT allocPgoInstrumentationBySchema(MethodDesc* pMD, ICorJitInfo::PgoInstrumentationSchema* pSchema, UINT32 countSchemaItems, BYTE** pInstrumentationData); static HRESULT getPgoInstrumentationResultsFromR2RFormat(ReadyToRunInfo *pReadyToRunInfo, Module* pModule, diff --git a/src/coreclr/vm/tieredcompilation.cpp b/src/coreclr/vm/tieredcompilation.cpp index 08a020f6932a70..3a77393aae4371 100644 --- a/src/coreclr/vm/tieredcompilation.cpp +++ b/src/coreclr/vm/tieredcompilation.cpp @@ -1049,6 +1049,7 @@ CORJIT_FLAGS TieredCompilationManager::GetJitFlags(PrepareCodeConfig *config) case NativeCodeVersion::OptimizationTier0: if (g_pConfig->TieredCompilation_QuickJit()) { +#ifdef FEATURE_PGO if (g_pConfig->TieredPGO() && g_pConfig->TieredPGO_InstrumentOnlyHotCode()) { // If we plan to only instrument hot code we have to make an exception @@ -1057,6 +1058,7 @@ CORJIT_FLAGS TieredCompilationManager::GetJitFlags(PrepareCodeConfig *config) // if current method has loops and is eligible for OSR. flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR_IF_LOOPS); } +#endif flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER0); break; }