Adds instruction count and summarized variable debug info (#42040)
authorKunal Pathak <Kunal.Pathak@microsoft.com>
Thu, 10 Sep 2020 05:32:50 +0000 (22:32 -0700)
committerGitHub <noreply@github.com>
Thu, 10 Sep 2020 05:32:50 +0000 (22:32 -0700)
* Print instruction count in Jitasm

* Print summarized variable debug info

* Make instrCount a local variable

src/coreclr/src/jit/codegencommon.cpp
src/coreclr/src/jit/ee_il_dll.cpp
src/coreclr/src/jit/emit.cpp
src/coreclr/src/jit/emitpub.h

index 5923e65..04d8f5d 100644 (file)
@@ -2271,6 +2271,7 @@ void CodeGen::genEmitMachineCode()
     GetEmitter()->emitComputeCodeSizes();
 
 #ifdef DEBUG
+    unsigned instrCount;
 
     // Code to test or stress our ability to run a fallback compile.
     // We trigger the fallback here, before asking the VM for any memory,
@@ -2319,7 +2320,7 @@ void CodeGen::genEmitMachineCode()
 
     codeSize = GetEmitter()->emitEndCodeGen(compiler, trackedStackPtrsContig, GetInterruptible(),
                                             IsFullPtrRegMapRequired(), compiler->compHndBBtabCount, &prologSize,
-                                            &epilogSize, codePtr, &coldCodePtr, &consPtr);
+                                            &epilogSize, codePtr, &coldCodePtr, &consPtr DEBUGARG(&instrCount));
 
 #ifdef DEBUG
     assert(compiler->compCodeGenDone == false);
@@ -2339,8 +2340,9 @@ void CodeGen::genEmitMachineCode()
 #ifdef DEBUG
     if (compiler->opts.disAsm || verbose)
     {
-        printf("\n; Total bytes of code %d, prolog size %d, PerfScore %.2f, (MethodHash=%08x) for method %s\n",
-               codeSize, prologSize, compiler->info.compPerfScore, compiler->info.compMethodHash(),
+        printf("\n; Total bytes of code %d, prolog size %d, PerfScore %.2f, instruction count %d (MethodHash=%08x) for "
+               "method %s\n",
+               codeSize, prologSize, compiler->info.compPerfScore, instrCount, compiler->info.compMethodHash(),
                compiler->info.compFullName);
         printf("; ============================================================\n\n");
         printf(""); // in our logic this causes a flush
index 9926c99..8ca40f9 100644 (file)
@@ -805,8 +805,18 @@ void Compiler::eeDispVar(ICorDebugInfo::NativeVarInfo* var)
 // Same parameters as ICorStaticInfo::setVars().
 void Compiler::eeDispVars(CORINFO_METHOD_HANDLE ftn, ULONG32 cVars, ICorDebugInfo::NativeVarInfo* vars)
 {
-    printf("*************** Variable debug info\n");
-    printf("%d live ranges\n", cVars);
+    ALLVARSET_TP uniqueVars(AllVarSetOps::MakeEmpty(this));
+    for (unsigned i = 0; i < cVars; i++)
+    {
+        // ignore "special vars" and out of bounds vars
+        if ((((int)vars[i].varNumber) >= 0) && (vars[i].varNumber < lclMAX_ALLSET_TRACKED))
+        {
+            AllVarSetOps::AddElemD(this, uniqueVars, vars[i].varNumber);
+        }
+    }
+    printf("; Variable debug info: %d live range(s), %d var(s) for method %s\n", cVars,
+           AllVarSetOps::Count(this, uniqueVars), info.compFullName);
+
     for (unsigned i = 0; i < cVars; i++)
     {
         eeDispVar(&vars[i]);
index cfde2d0..30f2c64 100644 (file)
@@ -4470,7 +4470,7 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
                                  unsigned* epilogSize,
                                  void**    codeAddr,
                                  void**    coldCodeAddr,
-                                 void**    consAddr)
+                                 void** consAddr DEBUGARG(unsigned* instrCount))
 {
 #ifdef DEBUG
     if (emitComp->verbose)
@@ -4874,6 +4874,9 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
 
 #define DEFAULT_CODE_BUFFER_INIT 0xcc
 
+#ifdef DEBUG
+    *instrCount = 0;
+#endif
     for (insGroup* ig = emitIGlist; ig != nullptr; ig = ig->igNext)
     {
         assert(!(ig->igFlags & IGF_PLACEHOLDER)); // There better not be any placeholder groups left
@@ -5014,6 +5017,7 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
         {
             printf("\t\t\t\t\t\t;; bbWeight=%s PerfScore %.2f", refCntWtd2str(ig->igWeight), ig->igPerfScore);
         }
+        *instrCount += ig->igInsCnt;
 #endif // DEBUG
 
         emitCurIG = nullptr;
index 3134bf5..f049905 100644 (file)
@@ -32,7 +32,7 @@ unsigned emitEndCodeGen(Compiler* comp,
                         unsigned* epilogSize,
                         void**    codeAddr,
                         void**    coldCodeAddr,
-                        void**    consAddr);
+                        void** consAddr DEBUGARG(unsigned* instrCount));
 
 /************************************************************************/
 /*                      Method prolog and epilog                        */