From 6ebccad34c826cbd4c8805c559f2361a4492a0f7 Mon Sep 17 00:00:00 2001
From: Prakalp Srivastava <psrivas2@illinois.edu>
Date: Sat, 12 Mar 2016 10:34:08 -0600
Subject: [PATCH] Added code to remove function attributes of the generated ptx
 kernel function as the target dependent attributes are not required and break
 the compilation through PTX backend. This fixed tpacf compilation bug

---
 .../lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
index f3a32a9828..768742b53e 100644
--- a/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+++ b/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
@@ -233,6 +233,7 @@ public:
     changeDataLayout(KernelM);
     changeTargetTriple(KernelM);
 
+
     DEBUG(errs() << KernelM);
 
   }
@@ -958,6 +959,8 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
 
     F_nvptx = CloneFunction(F, VMap, true);
 
+
+
     // Insert the cloned function into the kernels module
     KernelM.getFunctionList().push_back(F_nvptx);
 
@@ -972,8 +975,13 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
   } else {
     errs() << "WARNING: Visiting a node for which code already generated!\n";
   }
-  
+ 
+  // Transform  the function to void and remove all target dependent attributes
+  // from the function
   transformFunctionToVoid(F_nvptx);
+  DEBUG(errs() << "Removing all attributes from Kernel Function and adding nounwind\n");
+  F_nvptx->removeAttributes(AttributeSet::FunctionIndex, F_nvptx->getAttributes().getFnAttributes());
+  F_nvptx->addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
 
   //FIXME: For now, assume only one allocation node
   kernel->AllocationNode = NULL;
@@ -1348,7 +1356,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
       }
       break;
       default:
-        assert(false && "Unknown VISC Intrinsic!");
+        llvm_unreachable("Unknown VISC Intrinsic!");
         break;
       }
 
-- 
GitLab