Address review comments from https://github.com/KhronosGroup/SPIRV-Tools/pull/985.
authorDiego Novillo <dnovillo@google.com>
Thu, 4 Jan 2018 18:20:18 +0000 (13:20 -0500)
committerDiego Novillo <dnovillo@google.com>
Thu, 4 Jan 2018 18:20:49 +0000 (13:20 -0500)
source/opt/aggressive_dead_code_elim_pass.cpp
source/opt/propagator.h

index 101649b..efc34b5 100644 (file)
@@ -381,7 +381,12 @@ bool AggressiveDCEPass::AggressiveDCE(ir::Function* func) {
   for (auto bi = structuredOrder.begin(); bi != structuredOrder.end(); ++bi) {
     for (auto ii = (*bi)->begin(); ii != (*bi)->end(); ++ii) {
       if (IsLive(&*ii)) continue;
-      if (ii->IsBranch() &&
+      // TODO(greg-lunarg
+      // https://github.com/KhronosGroup/SPIRV-Tools/issues/1021) This should be
+      // using ii->IsBranch(), but this code does not handle OpSwitch
+      // instructions yet.
+      if ((ii->opcode() == SpvOpBranch ||
+           ii->opcode() == SpvOpBranchConditional) &&
           !IsStructuredIfOrLoopHeader(*bi, nullptr, nullptr, nullptr))
         continue;
       dead_insts_.insert(&*ii);
index 0c9d18a..7e7dfc2 100644 (file)
@@ -30,8 +30,10 @@ namespace opt {
 
 // Represents a CFG control edge.
 struct Edge {
-  explicit Edge(ir::BasicBlock* b1, ir::BasicBlock* b2)
-      : source(b1), dest(b2) {}
+  Edge(ir::BasicBlock* b1, ir::BasicBlock* b2) : source(b1), dest(b2) {
+    assert(source && "CFG edges cannot have a null source block.");
+    assert(dest && "CFG edges cannot have a null destination block.");
+  }
   ir::BasicBlock* source;
   ir::BasicBlock* dest;
   bool operator<(const Edge& o) const {