Bug 522591 - move reader pipeline from assemble() to compile(), r=gal.
authorGraydon Hoare <graydon@mozilla.com>
Fri, 23 Oct 2009 14:58:10 -0700
changeset 34341 12a4dc9cda5ef671c6b21ab90510d1b51844246c
parent 34340 a9848921a6923f2918de03b7fd4a3010cd0324ef
child 34342 7365cd1f36e8777e35e02443243b4ae95a9cb736
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
bugs522591
milestone1.9.3a1pre
Bug 522591 - move reader pipeline from assemble() to compile(), r=gal.
js/src/nanojit/Assembler.cpp
js/src/nanojit/Assembler.h
js/src/nanojit/LIR.cpp
js/src/nanojit/LIR.h
--- a/js/src/nanojit/Assembler.cpp
+++ b/js/src/nanojit/Assembler.cpp
@@ -47,63 +47,16 @@
 
 #ifdef _MSC_VER
     // disable some specific warnings which are normally useful, but pervasive in the code-gen macros
     #pragma warning(disable:4310) // cast truncates constant value
 #endif
 
 namespace nanojit
 {
-#ifdef NJ_VERBOSE
-    /* A listing filter for LIR, going through backwards.  It merely
-       passes its input to its output, but notes it down too.  When
-       destructed, prints out what went through.  Is intended to be
-       used to print arbitrary intermediate transformation stages of
-       LIR. */
-    class ReverseLister : public LirFilter
-    {
-        Allocator&   _alloc;
-        LirNameMap*  _names;
-        const char*  _title;
-        StringList   _strs;
-        LogControl*  _logc;
-    public:
-        ReverseLister(LirFilter* in, Allocator& alloc,
-                      LirNameMap* names, LogControl* logc, const char* title)
-            : LirFilter(in)
-            , _alloc(alloc)
-            , _names(names)
-            , _title(title)
-            , _strs(alloc)
-            , _logc(logc)
-        { }
-
-        void finish()
-        {
-            _logc->printf("\n");
-            _logc->printf("=== BEGIN %s ===\n", _title);
-            int j = 0;
-            for (Seq<char*>* p = _strs.get(); p != NULL; p = p->tail)
-                _logc->printf("  %02d: %s\n", j++, p->head);
-            _logc->printf("=== END %s ===\n", _title);
-            _logc->printf("\n");
-        }
-
-        LInsp read()
-        {
-            LInsp i = in->read();
-            const char* str = _names->formatIns(i);
-            char* cpy = new (_alloc) char[strlen(str)+1];
-            VMPI_strcpy(cpy, str);
-            _strs.insert(cpy);
-            return i;
-        }
-    };
-#endif
-
     /**
      * Need the following:
      *
      *    - merging paths ( build a graph? ), possibly use external rep to drive codegen
      */
     Assembler::Assembler(CodeAlloc& codeAlloc, Allocator& alloc, AvmCore* core, LogControl* logc)
         : codeList(NULL)
         , alloc(alloc)
@@ -693,66 +646,34 @@ namespace nanojit
         _stats.codeExitStart = _nExitIns-1;
 #endif /* PERFM */
 
         _epilogue = NULL;
 
         nBeginAssembly();
     }
 
-    void Assembler::assemble(Fragment* frag)
+    void Assembler::assemble(Fragment* frag, LirFilter* reader)
     {
         if (error()) return;
         _thisfrag = frag;
 
         // check the fragment is starting out with a sane profiling state
         verbose_only( NanoAssert(frag->nStaticExits == 0); )
         verbose_only( NanoAssert(frag->nCodeBytes == 0); )
         verbose_only( NanoAssert(frag->nExitBytes == 0); )
         verbose_only( NanoAssert(frag->profCount == 0); )
         verbose_only( if (_logc->lcbits & LC_FragProfile)
                           NanoAssert(frag->profFragID > 0);
                       else
                           NanoAssert(frag->profFragID == 0); )
 
-        // Used for debug printing, if needed
-        verbose_only(
-        ReverseLister *pp_init = NULL;
-        ReverseLister *pp_after_sf = NULL;
-        )
-
-        // set up backwards pipeline: assembler -> StackFilter -> LirReader
-        LirReader bufreader(frag->lastIns);
-
-        // Used to construct the pipeline
-        LirFilter* prev = &bufreader;
-
-        // The LIR passes through these filters as listed in this
-        // function, viz, top to bottom.
-
-        // INITIAL PRINTING
-        verbose_only( if (_logc->lcbits & LC_ReadLIR) {
-        pp_init = new (alloc) ReverseLister(prev, alloc, frag->lirbuf->names, _logc,
-                                    "Initial LIR");
-        prev = pp_init;
-        })
-
-        // STACKFILTER
-        StackFilter stackfilter(prev, alloc, frag->lirbuf, frag->lirbuf->sp, frag->lirbuf->rp);
-        prev = &stackfilter;
-
-        verbose_only( if (_logc->lcbits & LC_AfterSF) {
-        pp_after_sf = new (alloc) ReverseLister(prev, alloc, frag->lirbuf->names, _logc,
-                                                "After StackFilter");
-        prev = pp_after_sf;
-        })
-
         _inExit = false;
 
-        gen(prev);
+        gen(reader);
 
         if (!error()) {
             // patch all branches
             NInsMap::Iter iter(_patches);
             while (iter.next()) {
                 NIns* where = iter.key();
                 LIns* targ = iter.value();
                 LabelState *label = _labels.get(targ);
@@ -761,23 +682,16 @@ namespace nanojit
                     nPatchBranch(where,ntarg);
                 }
                 else {
                     setError(UnknownBranch);
                     break;
                 }
             }
         }
-
-        // If we were accumulating debug info in the various ReverseListers,
-        // call finish() to emit whatever contents they have accumulated.
-        verbose_only(
-        if (pp_init)        pp_init->finish();
-        if (pp_after_sf)    pp_after_sf->finish();
-        )
     }
 
     void Assembler::endAssembly(Fragment* frag)
     {
         // don't try to patch code if we are in an error state since we might have partially
         // overwritten the code cache already
         if (error()) {
             // something went wrong, release all allocated code memory
--- a/js/src/nanojit/Assembler.h
+++ b/js/src/nanojit/Assembler.h
@@ -176,17 +176,17 @@ namespace nanojit
 
             #ifdef VTUNE
             avmplus::CodegenLIR *cgen;
             #endif
 
             Assembler(CodeAlloc& codeAlloc, Allocator& alloc, AvmCore* core, LogControl* logc);
 
             void        endAssembly(Fragment* frag);
-            void        assemble(Fragment* frag);
+            void        assemble(Fragment* frag, LirFilter* reader);
             void        beginAssembly(Fragment *frag);
 
             void        releaseRegisters();
             void        patch(GuardRecord *lr);
             void        patch(SideExit *exit);
 #ifdef NANOJIT_IA32
             void        patch(SideExit *exit, SwitchInfo* si);
 #endif
--- a/js/src/nanojit/LIR.cpp
+++ b/js/src/nanojit/LIR.cpp
@@ -89,16 +89,62 @@ namespace nanojit
 #undef OPDEF
 #undef OPDEF64
         NULL
     };
 
     #endif /* NANOJIT_VEBROSE */
 
     // implementation
+#ifdef NJ_VERBOSE
+    /* A listing filter for LIR, going through backwards.  It merely
+       passes its input to its output, but notes it down too.  When
+       destructed, prints out what went through.  Is intended to be
+       used to print arbitrary intermediate transformation stages of
+       LIR. */
+    class ReverseLister : public LirFilter
+    {
+        Allocator&   _alloc;
+        LirNameMap*  _names;
+        const char*  _title;
+        StringList   _strs;
+        LogControl*  _logc;
+    public:
+        ReverseLister(LirFilter* in, Allocator& alloc,
+                      LirNameMap* names, LogControl* logc, const char* title)
+            : LirFilter(in)
+            , _alloc(alloc)
+            , _names(names)
+            , _title(title)
+            , _strs(alloc)
+            , _logc(logc)
+        { }
+
+        void finish()
+        {
+            _logc->printf("\n");
+            _logc->printf("=== BEGIN %s ===\n", _title);
+            int j = 0;
+            for (Seq<char*>* p = _strs.get(); p != NULL; p = p->tail)
+                _logc->printf("  %02d: %s\n", j++, p->head);
+            _logc->printf("=== END %s ===\n", _title);
+            _logc->printf("\n");
+        }
+
+        LInsp read()
+        {
+            LInsp i = in->read();
+            const char* str = _names->formatIns(i);
+            char* cpy = new (_alloc) char[strlen(str)+1];
+            VMPI_strcpy(cpy, str);
+            _strs.insert(cpy);
+            return i;
+        }
+    };
+#endif
 
 #ifdef NJ_PROFILE
     // @todo fixup move to nanojit.h
     #undef counter_value
     #define counter_value(x)        x
 #endif /* NJ_PROFILE */
 
     // LCompressedBuffer
@@ -1915,17 +1961,17 @@ namespace nanojit
             LInsp found = exprs.findcall(ci, argc, args, k);
             if (found)
                 return found;
             return exprs.add(out->insCall(ci, args), k);
         }
         return out->insCall(ci, args);
     }
 
-    void compile(Assembler* assm, Fragment* frag verbose_only(, Allocator& alloc, LabelMap* labels))
+    void compile(Assembler* assm, Fragment* frag, Allocator& alloc verbose_only(, LabelMap* labels))
     {
         verbose_only(
         LogControl *logc = assm->_logc;
         bool anyVerb = (logc->lcbits & 0xFFFF & ~LC_FragProfile) > 0;
         bool asmVerb = (logc->lcbits & 0xFFFF & LC_Assembly) > 0;
         bool liveVerb = (logc->lcbits & 0xFFFF & LC_Liveness) > 0;
         )
 
@@ -1961,17 +2007,58 @@ namespace nanojit
             logc->printf("=== Translating LIR fragments into assembly:\n");
         })
 
         // now the the main trunk
         verbose_only( if (anyVerb) {
             logc->printf("=== -- Compile trunk %s: begin\n",
                          labels->format(frag));
         })
-        assm->assemble(frag);
+        
+        // Used for debug printing, if needed
+        verbose_only(
+        ReverseLister *pp_init = NULL;
+        ReverseLister *pp_after_sf = NULL;
+        )
+
+        // set up backwards pipeline: assembler -> StackFilter -> LirReader
+        LirReader bufreader(frag->lastIns);
+
+        // Used to construct the pipeline
+        LirFilter* prev = &bufreader;
+
+        // The LIR passes through these filters as listed in this
+        // function, viz, top to bottom.
+
+        // INITIAL PRINTING
+        verbose_only( if (assm->_logc->lcbits & LC_ReadLIR) {
+        pp_init = new (alloc) ReverseLister(prev, alloc, frag->lirbuf->names, assm->_logc,
+                                    "Initial LIR");
+        prev = pp_init;
+        })
+
+        // STACKFILTER
+        StackFilter stackfilter(prev, alloc, frag->lirbuf, frag->lirbuf->sp, frag->lirbuf->rp);
+        prev = &stackfilter;
+
+        verbose_only( if (assm->_logc->lcbits & LC_AfterSF) {
+        pp_after_sf = new (alloc) ReverseLister(prev, alloc, frag->lirbuf->names, assm->_logc,
+                                                "After StackFilter");
+        prev = pp_after_sf;
+        })
+        
+        assm->assemble(frag, prev);
+        
+        // If we were accumulating debug info in the various ReverseListers,
+        // call finish() to emit whatever contents they have accumulated.
+        verbose_only(
+        if (pp_init)        pp_init->finish();
+        if (pp_after_sf)    pp_after_sf->finish();
+        )
+        
         verbose_only( if (anyVerb) {
             logc->printf("=== -- Compile trunk %s: end\n",
                          labels->format(frag));
         })
 
         verbose_only(
             if (asmVerb)
                 assm->outputf("## compiling trunk %s",
--- a/js/src/nanojit/LIR.h
+++ b/js/src/nanojit/LIR.h
@@ -1440,17 +1440,17 @@ namespace nanojit
         LInsp read(); // advance to the prior instruction
         LInsp pos() {
             return _i;
         }
     };
 
     class Assembler;
 
-    void compile(Assembler *assm, Fragment *frag verbose_only(, Allocator& alloc, LabelMap*));
+    void compile(Assembler *assm, Fragment *frag, Allocator& alloc verbose_only(, LabelMap*));
     verbose_only(void live(Allocator& alloc, Fragment* frag, LogControl*);)
 
     class StackFilter: public LirFilter
     {
         LirBuffer *lirbuf;
         LInsp sp;
         LInsp rp;
         BitSet spStk;