From 310b8a93b7e15bc4a07b41a7ff8c6ee2cb45504c Mon Sep 17 00:00:00 2001
From: Akash Kothari <akashk4@tyler.cs.illinois.edu>
Date: Thu, 9 Jan 2020 11:30:17 -0600
Subject: [PATCH] Added assertions about node level for root nodes

---
 hpvm/include/SupportVISC/DFGraph.h        | 6 +++++-
 hpvm/lib/Transforms/BuildDFG/BuildDFG.cpp | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/hpvm/include/SupportVISC/DFGraph.h b/hpvm/include/SupportVISC/DFGraph.h
index a5d7252f40..b74aee8379 100644
--- a/hpvm/include/SupportVISC/DFGraph.h
+++ b/hpvm/include/SupportVISC/DFGraph.h
@@ -315,7 +315,11 @@ public:
 
   bool isRoot() const {
     // It is a root node is it was created from a launch intrinsic
-    return II->getCalledFunction()->getName().equals("llvm.visc.launch");
+    if(II->getCalledFunction()->getName().equals("llvm.visc.launch")) {
+    	assert(Level == 0 && "Root node's level is zero.");
+        return true;
+    }
+    return false;
   }
 
   StructType* getOutputType() const {
diff --git a/hpvm/lib/Transforms/BuildDFG/BuildDFG.cpp b/hpvm/lib/Transforms/BuildDFG/BuildDFG.cpp
index 8d5a5cb0e6..a8cd54914b 100644
--- a/hpvm/lib/Transforms/BuildDFG/BuildDFG.cpp
+++ b/hpvm/lib/Transforms/BuildDFG/BuildDFG.cpp
@@ -71,10 +71,17 @@ bool BuildDFG::runOnModule(Module &M) {
 }
 
 DFInternalNode *BuildDFG::getRoot() const {
+  assert(Root && Root->getLevel() == 0 && "Invalid root node.");
   return Root;
 }
 
 std::vector<DFInternalNode*> &BuildDFG::getRoots() {
+  assert((Roots.size() != 0) && "Number of roots cannot be zero.");
+  
+  // All roots should have the same level
+ for(auto *Node : Roots) 
+   assert(Node->getLevel() == 0 && "Invalid root node.");
+
   return Roots;
 }
 
-- 
GitLab