From 08a47b9265599330a13251998b5961064bed4852 Mon Sep 17 00:00:00 2001
From: Hashim Sharif <hsharif3@tyler.cs.illinois.edu>
Date: Thu, 26 Nov 2020 02:26:38 -0600
Subject: [PATCH] Adding support for removing @llvm.visc.node.id calls in
 ClearDFG (conseravtive for correctness)

---
 llvm/lib/Transforms/ClearDFG/ClearDFG.cpp | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp b/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp
index 37f74325a7..84f9bec04f 100644
--- a/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp
+++ b/llvm/lib/Transforms/ClearDFG/ClearDFG.cpp
@@ -59,6 +59,7 @@ private:
 
   //Functions
   void deleteNode(DFNode* N);
+  
 public:
   // Constructor
   TreeTraversal(Module &_M, BuildDFG &_DFG) : M(_M), DFG(_DFG) { }
@@ -88,6 +89,7 @@ public:
 };
 
 bool ClearDFG::runOnModule(Module &M) {
+
   errs() << "\nCLEARDFG PASS\n";
   // Get the BuildDFG Analysis Results:
   // - Dataflow graph
@@ -118,6 +120,19 @@ bool ClearDFG::runOnModule(Module &M) {
   VC->replaceAllUsesWith(UndefValue::get(VC->getType()));
   VC->eraseFromParent();
 
+
+  Function* VN = M.getFunction("llvm.visc.node.id");
+  if (VN != NULL){ // Delete visc.node.id intrinsic calls if they exist
+    for(Value::user_iterator ui = VN->user_begin(), ue = VN->user_end(); ui != ue; ui++) {
+      Instruction* I = dyn_cast<Instruction>(*ui);
+      I->eraseFromParent();
+    }
+    
+    VN->replaceAllUsesWith(UndefValue::get(VN->getType()));
+    VN->eraseFromParent();
+  }
+  
+  
   // Visitor for Code Generation Graph Traversal
   TreeTraversal *Visitor = new TreeTraversal(M, DFG);
 
@@ -125,7 +140,9 @@ bool ClearDFG::runOnModule(Module &M) {
   for (auto rootNode: Roots) {
     Visitor->visit(rootNode);
   }
+  
   delete Visitor;
+
   return true;
 }
 
@@ -149,7 +166,7 @@ void TreeTraversal::deleteNode(DFNode* N) {
 
 char ClearDFG::ID = 0;
 static RegisterPass<ClearDFG> X("clearDFG",
-                                    "Delete all DFG functions for which code has been generated",
-                                    false /* does not modify the CFG */,
-                                    true /* transformation, not just analysis */);
+				"Delete all DFG functions for which code has been generated",
+				false /* does not modify the CFG */,
+				true /* transformation, not just analysis */);
 
-- 
GitLab