[05/18] Backend: Add debug info to the return lower.

Submitted by junyan.he@inbox.com on Dec. 24, 2015, 11:01 a.m.

Details

Message ID 1450954930-6914-6-git-send-email-junyan.he@inbox.com
State New
Headers show
Series "Enable profiling by line number." ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

junyan.he@inbox.com Dec. 24, 2015, 11:01 a.m.
From: Junyan He <junyan.he@linux.intel.com>

Signed-off-by: Junyan He <junyan.he@linux.intel.com>
---
 backend/src/ir/lowering.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/backend/src/ir/lowering.cpp b/backend/src/ir/lowering.cpp
index 535f7e6..1746489 100644
--- a/backend/src/ir/lowering.cpp
+++ b/backend/src/ir/lowering.cpp
@@ -43,12 +43,15 @@  namespace ir {
   };
 
   void ContextReturn::lower(const std::string &functionName) {
+    DebugInfo dgInfo;
     if ((this->fn = unit.getFunction(functionName)) == NULL)
       return;
 
     // Append a new block at the end of the function with a return instruction:
     // the only one we are going to have
     this->bb = &this->fn->getBottomBlock();
+    /* Just use the last instruction's debug info, no matter whether it is RET. */
+    dgInfo = this->fn->getBottomBlock().getLastInstruction()->DBGInfo;
     const LabelIndex index = this->label();
     this->LABEL(index);
     const BasicBlock *lastBlock = this->bb;
@@ -60,13 +63,17 @@  namespace ir {
     }
 
     this->RET();
+    Instruction* retInst = lastBlock->getLastInstruction();
+    retInst->DBGInfo = dgInfo;
 
     // Now traverse all instructions and replace all returns by GOTO index
     fn->foreachInstruction([&](Instruction &insn) {
       if (insn.getParent() == lastBlock) return; // This is the last block
       if (insn.getOpcode() != OP_RET) return;
-      const Instruction bra = ir::BRA(index);
+      Instruction bra = ir::BRA(index);
+      dgInfo = insn.DBGInfo;
       bra.replace(&insn);
+      bra.DBGInfo = dgInfo;
     });
   }