Add option for extra queries for SuperPmi (#35411)
authorCarol Eidt <carol.eidt@microsoft.com>
Tue, 28 Apr 2020 21:39:07 +0000 (14:39 -0700)
committerGitHub <noreply@github.com>
Tue, 28 Apr 2020 21:39:07 +0000 (14:39 -0700)
* 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
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/jitconfigvalues.h
src/coreclr/src/jit/lclvars.cpp

index 1c7f2f22a76f420e7ba3543dbc3305f47cb5b333..f6116c80fd6f9c73f6c1c9cb8168b0169f219ded 100755 (executable)
@@ -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"
index 268a304b967ca9a2ab61d76df0028b9ebd22864e..b39f2d5494f7b744936387f284162d5402c36ce8 100644 (file)
@@ -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)
     {
index 3648de5053d1c22418462527e60ede0f09694310..ae91156a4a299197b4c13b4bde23d24bb3032540 100644 (file)
@@ -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)
index 00d34fe5fe2ecd4e182f292e652eb8fd6dba8c1a..f65a06283d79ed2fff4fc219073e61d223b777ac 100644 (file)
@@ -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