Remove cfg_ field from SSAPropagator class - NFC.
authorDiego Novillo <dnovillo@google.com>
Mon, 4 Dec 2017 20:28:21 +0000 (15:28 -0500)
committerDiego Novillo <dnovillo@google.com>
Mon, 4 Dec 2017 20:28:21 +0000 (15:28 -0500)
When I moved the CFG into IRContext
(https://github.com/KhronosGroup/SPIRV-Tools/pull/1019), I forgot to
update SSAPropagator to stop requiring one.

Fixed with this patch.

source/opt/propagator.cpp
source/opt/propagator.h
test/opt/propagator_test.cpp

index 907f41f..18c89cf 100644 (file)
@@ -21,7 +21,7 @@ void SSAPropagator::AddControlEdge(const Edge& edge) {
   ir::BasicBlock* dest_bb = edge.dest;
 
   // Refuse to add the exit block to the work list.
-  if (dest_bb == cfg_->pseudo_exit_block()) {
+  if (dest_bb == ctx_->cfg()->pseudo_exit_block()) {
     return;
   }
 
@@ -37,7 +37,7 @@ void SSAPropagator::AddControlEdge(const Edge& edge) {
 }
 
 void SSAPropagator::AddSSAEdges(uint32_t id) {
-  get_def_use_mgr()->ForEachUser(id, [this](ir::Instruction *instr) {
+  get_def_use_mgr()->ForEachUser(id, [this](ir::Instructioninstr) {
     // If the basic block for |instr| has not been simulated yet, do nothing.
     if (!BlockHasBeenSimulated(ctx_->get_instr_block(instr))) {
       return;
@@ -142,7 +142,7 @@ bool SSAPropagator::Simulate(ir::Instruction* instr) {
 }
 
 bool SSAPropagator::Simulate(ir::BasicBlock* block) {
-  if (block == cfg_->pseudo_exit_block()) {
+  if (block == ctx_->cfg()->pseudo_exit_block()) {
     return false;
   }
 
@@ -179,8 +179,8 @@ void SSAPropagator::Initialize(ir::Function* fn) {
   // Compute predecessor and successor blocks for every block in |fn|'s CFG.
   // TODO(dnovillo): Move this to ir::CFG and always build them. Alternately,
   // move it to IRContext and build CFG preds/succs on-demand.
-  bb_succs_[cfg_->pseudo_entry_block()].push_back(
-      Edge(cfg_->pseudo_entry_block(), fn->entry().get()));
+  bb_succs_[ctx_->cfg()->pseudo_entry_block()].push_back(
+      Edge(ctx_->cfg()->pseudo_entry_block(), fn->entry().get()));
 
   for (auto& block : *fn) {
     block.ForEachSuccessorLabel([this, &block](uint32_t label_id) {
@@ -190,14 +190,15 @@ void SSAPropagator::Initialize(ir::Function* fn) {
       bb_preds_[succ_bb].push_back(Edge(succ_bb, &block));
     });
     if (block.IsReturn()) {
-      bb_succs_[&block].push_back(Edge(&block, cfg_->pseudo_exit_block()));
-      bb_preds_[cfg_->pseudo_exit_block()].push_back(
-          Edge(cfg_->pseudo_exit_block(), &block));
+      bb_succs_[&block].push_back(
+          Edge(&block, ctx_->cfg()->pseudo_exit_block()));
+      bb_preds_[ctx_->cfg()->pseudo_exit_block()].push_back(
+          Edge(ctx_->cfg()->pseudo_exit_block(), &block));
     }
   }
 
   // Add the edges out of the entry block to seed the propagator.
-  const auto& entry_succs = bb_succs_[cfg_->pseudo_entry_block()];
+  const auto& entry_succs = bb_succs_[ctx_->cfg()->pseudo_entry_block()];
   for (const auto& e : entry_succs) {
     AddControlEdge(e);
   }
index 45871b1..2e7eb59 100644 (file)
@@ -22,7 +22,6 @@
 #include <unordered_set>
 #include <vector>
 
-#include "cfg.h"
 #include "ir_context.h"
 #include "module.h"
 
@@ -185,9 +184,8 @@ class SSAPropagator {
   using VisitFunction =
       std::function<PropStatus(ir::Instruction*, ir::BasicBlock**)>;
 
-  SSAPropagator(ir::IRContext* context, ir::CFG* cfg,
-                const VisitFunction& visit_fn)
-      : ctx_(context), cfg_(cfg), visit_fn_(visit_fn) {}
+  SSAPropagator(ir::IRContext* context, const VisitFunction& visit_fn)
+      : ctx_(context), visit_fn_(visit_fn) {}
 
   // Run the propagator on function |fn|. Returns true if changes were made to
   // the function. Otherwise, it returns false.
@@ -253,10 +251,6 @@ class SSAPropagator {
   // IR context to use.
   ir::IRContext* ctx_;
 
-  // CFG to propagate values on. TODO(dnovillo): The CFG should be part of
-  // IRContext.
-  ir::CFG* cfg_;
-
   // Function that visits instructions during simulation. The output of this
   // function is used to determine if the simulated instruction produced a value
   // interesting for propagation. The function is responsible for keeping
index 54294c7..b6cd2c4 100644 (file)
@@ -31,7 +31,6 @@ class PropagatorTest : public testing::Test {
  protected:
   virtual void TearDown() {
     ctx_.reset(nullptr);
-    cfg_.reset(nullptr);
     values_.clear();
     values_vec_.clear();
   }
@@ -40,11 +39,10 @@ class PropagatorTest : public testing::Test {
     ctx_ = BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, input);
     ASSERT_NE(nullptr, ctx_) << "Assembling failed for shader:\n"
                              << input << "\n";
-    cfg_.reset(new ir::CFG(ctx_->module()));
   }
 
   bool Propagate(const opt::SSAPropagator::VisitFunction& visit_fn) {
-    opt::SSAPropagator propagator(ctx_.get(), cfg_.get(), visit_fn);
+    opt::SSAPropagator propagator(ctx_.get(), visit_fn);
     bool retval = false;
     for (auto& fn : *ctx_->module()) {
       retval |= propagator.Run(&fn);
@@ -61,7 +59,6 @@ class PropagatorTest : public testing::Test {
   }
 
   std::unique_ptr<ir::IRContext> ctx_;
-  std::unique_ptr<ir::CFG> cfg_;
   std::map<uint32_t, uint32_t> values_;
   std::vector<uint32_t> values_vec_;
 };