From 57a931b11e9ecff42bf75d2e451370af904c0992 Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Tue, 28 Apr 2020 14:39:07 -0700 Subject: [PATCH] Add option for extra queries for SuperPmi (#35411) * Add option for extra queries for SuperPmi This adds an option to do extra queries for struct fields and types to make it easier to test and diff struct promotion enhancements, but we could consider adding other queries in future. --- src/coreclr/scripts/superpmi.py | 1 + src/coreclr/src/jit/compiler.h | 2 ++ src/coreclr/src/jit/jitconfigvalues.h | 4 ++++ src/coreclr/src/jit/lclvars.cpp | 42 +++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/src/coreclr/scripts/superpmi.py b/src/coreclr/scripts/superpmi.py index 1c7f2f2..f6116c8 100755 --- a/src/coreclr/scripts/superpmi.py +++ b/src/coreclr/scripts/superpmi.py @@ -589,6 +589,7 @@ class SuperPMICollect: env_copy["SuperPMIShimPath"] = self.jit_path env_copy["COMPlus_AltJit"] = "*" env_copy["COMPlus_AltJitName"] = self.collection_shim_name + env_copy["COMPlus_EnableExtraSuperPmiQueries"] = "1" if self.coreclr_args.use_zapdisable: env_copy["COMPlus_ZapDisable"] = "1" diff --git a/src/coreclr/src/jit/compiler.h b/src/coreclr/src/jit/compiler.h index 268a304..b39f2d5 100644 --- a/src/coreclr/src/jit/compiler.h +++ b/src/coreclr/src/jit/compiler.h @@ -2095,6 +2095,8 @@ public: bool shouldUseVerboseSsa(); bool treesBeforeAfterMorph; // If true, print trees before/after morphing (paired by an intra-compilation id: int morphNum; // This counts the the trees that have been morphed, allowing us to label each uniquely. + bool doExtraSuperPmiQueries; + void makeExtraStructQueries(CORINFO_CLASS_HANDLE structHandle, int level); // Make queries recursively 'level' deep. const char* VarNameToStr(VarName name) { diff --git a/src/coreclr/src/jit/jitconfigvalues.h b/src/coreclr/src/jit/jitconfigvalues.h index 3648de5..ae91156 100644 --- a/src/coreclr/src/jit/jitconfigvalues.h +++ b/src/coreclr/src/jit/jitconfigvalues.h @@ -361,6 +361,10 @@ CONFIG_INTEGER(JitMeasureNowayAssert, W("JitMeasureNowayAssert"), 0) // Set to 1 CONFIG_STRING(JitMeasureNowayAssertFile, W("JitMeasureNowayAssertFile")) // Set to file to write noway_assert usage to a file (if not // set: stdout). Only valid if MEASURE_NOWAY is defined. +#if defined(DEBUG) +CONFIG_INTEGER(EnableExtraSuperPmiQueries, W("EnableExtraSuperPmiQueries"), 0) // Make extra queries to somewhat + // future-proof SuperPmi method contexts. +#endif // DEBUG #if defined(DEBUG) || defined(INLINE_DATA) CONFIG_INTEGER(JitInlineDumpData, W("JitInlineDumpData"), 0) diff --git a/src/coreclr/src/jit/lclvars.cpp b/src/coreclr/src/jit/lclvars.cpp index 00d34fe..f65a062 100644 --- a/src/coreclr/src/jit/lclvars.cpp +++ b/src/coreclr/src/jit/lclvars.cpp @@ -2671,7 +2671,49 @@ void Compiler::lvaSetStruct(unsigned varNum, CORINFO_CLASS_HANDLE typeHnd, bool compGSReorderStackLayout = true; varDsc->lvIsUnsafeBuffer = true; } +#ifdef DEBUG + if (JitConfig.EnableExtraSuperPmiQueries()) + { + makeExtraStructQueries(typeHnd, 2); + } +#endif // DEBUG +} + +#ifdef DEBUG +//------------------------------------------------------------------------ +// makeExtraStructQueries: Query the information for the given struct handle. +// +// Arguments: +// structHandle -- The handle for the struct type we're querying. +// level -- How many more levels to recurse. +// +void Compiler::makeExtraStructQueries(CORINFO_CLASS_HANDLE structHandle, int level) +{ + if (level <= 0) + { + return; + } + assert(structHandle != NO_CLASS_HANDLE); + (void)typGetObjLayout(structHandle); + unsigned fieldCnt = info.compCompHnd->getClassNumInstanceFields(structHandle); + for (unsigned int i = 0; i < fieldCnt; i++) + { + CORINFO_FIELD_HANDLE fieldHandle = info.compCompHnd->getFieldInClass(structHandle, i); + unsigned fldOffset = info.compCompHnd->getFieldOffset(fieldHandle); + CORINFO_CLASS_HANDLE fieldClassHandle = NO_CLASS_HANDLE; + CorInfoType fieldCorType = info.compCompHnd->getFieldType(fieldHandle, &fieldClassHandle); + var_types fieldVarType = JITtype2varType(fieldCorType); + if (fieldClassHandle != NO_CLASS_HANDLE) + { + if (varTypeIsStruct(fieldVarType)) + { + fieldVarType = impNormStructType(fieldClassHandle); + makeExtraStructQueries(fieldClassHandle, level - 1); + } + } + } } +#endif // DEBUG //------------------------------------------------------------------------ // lvaSetStructUsedAsVarArg: update hfa information for vararg struct args -- 2.7.4