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;
}
}
void SSAPropagator::AddSSAEdges(uint32_t id) {
- get_def_use_mgr()->ForEachUser(id, [this](ir::Instruction *instr) {
+ get_def_use_mgr()->ForEachUser(id, [this](ir::Instruction* instr) {
// If the basic block for |instr| has not been simulated yet, do nothing.
if (!BlockHasBeenSimulated(ctx_->get_instr_block(instr))) {
return;
}
bool SSAPropagator::Simulate(ir::BasicBlock* block) {
- if (block == cfg_->pseudo_exit_block()) {
+ if (block == ctx_->cfg()->pseudo_exit_block()) {
return false;
}
// 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) {
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);
}
#include <unordered_set>
#include <vector>
-#include "cfg.h"
#include "ir_context.h"
#include "module.h"
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.
// 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
protected:
virtual void TearDown() {
ctx_.reset(nullptr);
- cfg_.reset(nullptr);
values_.clear();
values_vec_.clear();
}
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);
}
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_;
};