[Beignet] [PATCH 2/7] backend: Move ASM printing to a helper function.
Laura Ekstrand
laura.d.ekstrand at intel.com
Mon Jul 27 10:25:12 PDT 2015
This prepares the compiler to dump assembly to an arbitrary file.
---
backend/src/backend/gen_context.cpp | 62 ++++++++++++++++++++-----------------
backend/src/backend/gen_context.hpp | 3 ++
2 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/backend/src/backend/gen_context.cpp b/backend/src/backend/gen_context.cpp
index db27377..594a1eb 100644
--- a/backend/src/backend/gen_context.cpp
+++ b/backend/src/backend/gen_context.cpp
@@ -2287,35 +2287,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;
}
@@ -2323,5 +2297,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 a85657c..d9b0cbe 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,
@@ -218,6 +219,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 */
--
2.1.0
More information about the Beignet
mailing list