[01/18] Backend: Refine the CopyDebug template function.

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

Details

Message ID 1450954930-6914-2-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>

This function will be widely used to copy the debug
information between llvm instructions.
In our backend, sometimes we need to append or modify
some instructions, the debug info should also be set
correctly.

Signed-off-by: Junyan He <junyan.he@linux.intel.com>
---
 backend/src/llvm/llvm_gen_backend.hpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/backend/src/llvm/llvm_gen_backend.hpp b/backend/src/llvm/llvm_gen_backend.hpp
index 23688f5..18e6827 100644
--- a/backend/src/llvm/llvm_gen_backend.hpp
+++ b/backend/src/llvm/llvm_gen_backend.hpp
@@ -48,9 +48,12 @@  namespace llvm {
   FunctionPass *createPromoteIntegersPass();
   FunctionPass *createStripAttributesPass();
   // Copy debug information from Original to New, and return New.
-  template <typename T> T *CopyDebug(T *New, llvm::Instruction *Original) {
-    New->setDebugLoc(Original->getDebugLoc());
-   return New;
+  template <typename T> T *CopyDebug(T *New, llvm::Value *Original) {
+    if (dyn_cast<llvm::Instruction>(Original) && dyn_cast<llvm::Instruction>(New)) {
+      dyn_cast<llvm::Instruction>(New)->setDebugLoc(
+          dyn_cast<llvm::Instruction>(Original)->getDebugLoc());
+    }
+    return New;
   }
 }