[Beignet] [PATCH 2/3] Backend: Refine the CopyDebug template function.

junyan.he at inbox.com junyan.he at inbox.com
Mon Dec 14 01:44:08 PST 2015


From: Junyan He <junyan.he at 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 at linux.intel.com>
---
 backend/src/llvm/llvm_gen_backend.hpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

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;
   }
 }
 
-- 
1.9.1





More information about the Beignet mailing list