#include "source/reduce/remove_block_reduction_opportunity.h"
#include "source/opt/ir_context.h"
namespace spvtools {
namespace reduce {
RemoveBlockReductionOpportunity::RemoveBlockReductionOpportunity(
opt::IRContext* context, opt::Function* function, opt::BasicBlock* block)
: context_(context), function_(function), block_(block) {
assert(block_->begin() != block_->end() &&
context_->get_def_use_mgr()->NumUsers(block_->id()) == 0 &&
"RemoveBlockReductionOpportunity block must have 0 references");
}
bool RemoveBlockReductionOpportunity::PreconditionHolds() {
return true;
}
void RemoveBlockReductionOpportunity::Apply() {
for (auto bi = function_->begin(); bi != function_->end(); ++bi) {
if (bi->id() == block_->id()) {
bi.Erase();
context_->InvalidateAnalysesExceptFor(opt::IRContext::kAnalysisNone);
return;
}
}
assert(false &&
"Unreachable: we should have found a block with the desired id.");
}
}
}