[2/7] backend: Move ASM printing to a helper function.

Submitted by Manasi Navare on Aug. 12, 2015, 5:54 a.m.

Details

Message ID 1439358860-6874-3-git-send-email-manasi.d.navare@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Manasi Navare Aug. 12, 2015, 5:54 a.m.
From: Laura Ekstrand <laura.d.ekstrand@intel.com>

This prepares the compiler to dump assembly to an arbitrary file.

Signed-off-by: Manasi Navare <manasi.d.navare@intel.com>
Signed-off-by: Laura Ekstrand <laura.d.ekstrand@intel.com>
---
 backend/src/backend/gen_context.cpp | 62 ++++++++++++++++++++-----------------
 backend/src/backend/gen_context.hpp |  3 ++
 2 files changed, 36 insertions(+), 29 deletions(-)

Patch hide | download patch | download mbox

diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp
index e16b0a9..9ca4d7e 100644
--- a/backend/src/backend/gen_context.cpp
+++ b/backend/src/backend/gen_context.cpp
@@ -2291,35 +2291,9 @@  namespace gbe
     genKernel->insnNum = p->store.size();
     genKernel->insns = GBE_NEW_ARRAY_NO_ARG(GenInstruction, genKernel->insnNum);
     std::memcpy(genKernel->insns, &p->store[0], genKernel->insnNum * sizeof(GenInstruction));
-    if (OCL_OUTPUT_ASM) {
-      std::cout << genKernel->getName() << "'s disassemble begin:" << std::endl;
-      ir::LabelIndex curLabel = (ir::LabelIndex)0;
-      GenCompactInstruction * pCom = NULL;
-      GenInstruction insn[2];
-      std::cout << "  L0:" << std::endl;
-      for (uint32_t insnID = 0; insnID < genKernel->insnNum; ) {
-        if (labelPos.find((ir::LabelIndex)(curLabel + 1))->second == insnID &&
-            curLabel < this->getFunction().labelNum()) {
-          std::cout << "  L" << curLabel + 1 << ":" << std::endl;
-          curLabel = (ir::LabelIndex)(curLabel + 1);
-          while(labelPos.find((ir::LabelIndex)(curLabel + 1))->second == insnID) {
-            std::cout << "  L" << curLabel + 1 << ":" << std::endl;
-            curLabel = (ir::LabelIndex)(curLabel + 1);
-          }
-        }
-        std::cout << "    (" << std::setw(8) << insnID << ")  ";
-        pCom = (GenCompactInstruction*)&p->store[insnID];
-        if(pCom->bits1.cmpt_control == 1) {
-          decompactInstruction(pCom, &insn);
-          gen_disasm(stdout, &insn, deviceID, 1);
-          insnID++;
-        } else {
-          gen_disasm(stdout, &p->store[insnID], deviceID, 0);
-          insnID = insnID + 2;
-        }
-      }
-      std::cout << genKernel->getName() << "'s disassemble end." << std::endl;
-    }
+    if (OCL_OUTPUT_ASM)
+      outputAssembly(std::cout, genKernel);
+
     return true;
   }
 
@@ -2327,5 +2301,35 @@  namespace gbe
     return GBE_NEW(GenKernel, name, deviceID);
   }
 
+  void GenContext::outputAssembly(std::ostream& out, GenKernel* genKernel) {
+    out << genKernel->getName() << "'s disassemble begin:" << std::endl;
+    ir::LabelIndex curLabel = (ir::LabelIndex)0;
+    GenCompactInstruction * pCom = NULL;
+    GenInstruction insn[2];
+    out << "  L0:" << std::endl;
+    for (uint32_t insnID = 0; insnID < genKernel->insnNum; ) {
+      if (labelPos.find((ir::LabelIndex)(curLabel + 1))->second == insnID &&
+          curLabel < this->getFunction().labelNum()) {
+        out << "  L" << curLabel + 1 << ":" << std::endl;
+        curLabel = (ir::LabelIndex)(curLabel + 1);
+        while(labelPos.find((ir::LabelIndex)(curLabel + 1))->second == insnID) {
+          out << "  L" << curLabel + 1 << ":" << std::endl;
+          curLabel = (ir::LabelIndex)(curLabel + 1);
+        }
+      }
+      out << "    (" << std::setw(8) << insnID << ")  ";
+      pCom = (GenCompactInstruction*)&p->store[insnID];
+      if(pCom->bits1.cmpt_control == 1) {
+        decompactInstruction(pCom, &insn);
+        gen_disasm(stdout, &insn, deviceID, 1);
+        insnID++;
+      } else {
+        gen_disasm(stdout, &p->store[insnID], deviceID, 0);
+        insnID = insnID + 2;
+      }
+    }
+    out << genKernel->getName() << "'s disassemble end." << std::endl;
+  }
+
 } /* namespace gbe */
 
diff --git a/backend/src/backend/gen_context.hpp b/backend/src/backend/gen_context.hpp
index 69fe513..29ec6d0 100644
--- a/backend/src/backend/gen_context.hpp
+++ b/backend/src/backend/gen_context.hpp
@@ -43,6 +43,7 @@  namespace gbe
   class SelectionInstruction; // Pre-RA Gen instruction
   class SelectionReg;         // Pre-RA Gen register
   class GenRegister;
+  class GenKernel;
   typedef enum {
     NO_ERROR,
     REGISTER_ALLOCATION_FAIL,
@@ -219,6 +220,8 @@  namespace gbe
     uint32_t regSpillTick;
     /*! Build the curbe patch list for the given kernel */
     void buildPatchList(void);
+    /* Helper for printing the assembly */
+    void outputAssembly(std::ostream& out, GenKernel* genKernel);
     /*! Calc the group's slm offset from R0.0, to work around HSW SLM bug*/
     virtual void emitSLMOffset(void) { };
     /*! new selection of device */