reduce: miscellaneous fixes (#2494)
* Fix .gitignore
* Add missing reduction pass: RemoveBlockReductionOpportunityFinder
* Add DumpShader functions in test_reduce for debugging
* Add DumpShader functions in spirv-reduce for debugging
* Fix include style
* Don't use "using namespace"
diff --git a/.gitignore b/.gitignore
index 059b18e..e097bab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,5 +21,5 @@
*~
# C-Lion
-.idea
-cmake-build-debug
\ No newline at end of file
+/.idea/
+/cmake-build-*/
diff --git a/source/reduce/change_operand_reduction_opportunity.cpp b/source/reduce/change_operand_reduction_opportunity.cpp
index 5430d3e..c3f6fd7 100644
--- a/source/reduce/change_operand_reduction_opportunity.cpp
+++ b/source/reduce/change_operand_reduction_opportunity.cpp
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "change_operand_reduction_opportunity.h"
+#include "source/reduce/change_operand_reduction_opportunity.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/change_operand_reduction_opportunity.h b/source/reduce/change_operand_reduction_opportunity.h
index 7e1fc8e..18e6ca1 100644
--- a/source/reduce/change_operand_reduction_opportunity.h
+++ b/source/reduce/change_operand_reduction_opportunity.h
@@ -15,22 +15,20 @@
#ifndef SOURCE_REDUCE_CHANGE_OPERAND_REDUCTION_OPPORTUNITY_H_
#define SOURCE_REDUCE_CHANGE_OPERAND_REDUCTION_OPPORTUNITY_H_
-#include "reduction_opportunity.h"
#include "source/opt/instruction.h"
+#include "source/reduce/reduction_opportunity.h"
#include "spirv-tools/libspirv.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
-
// An opportunity to replace an id operand of an instruction with some other id.
class ChangeOperandReductionOpportunity : public ReductionOpportunity {
public:
// Constructs the opportunity to replace operand |operand_index| of |inst|
// with |new_id|.
- ChangeOperandReductionOpportunity(Instruction* inst, uint32_t operand_index,
- uint32_t new_id)
+ ChangeOperandReductionOpportunity(opt::Instruction* inst,
+ uint32_t operand_index, uint32_t new_id)
: inst_(inst),
operand_index_(operand_index),
original_id_(inst->GetOperand(operand_index).words[0]),
@@ -43,7 +41,7 @@
void Apply() override;
private:
- Instruction* const inst_;
+ opt::Instruction* const inst_;
const uint32_t operand_index_;
const uint32_t original_id_;
const spv_operand_type_t original_type_;
diff --git a/source/reduce/merge_blocks_reduction_opportunity.cpp b/source/reduce/merge_blocks_reduction_opportunity.cpp
index 8de1e09..42c7843 100644
--- a/source/reduce/merge_blocks_reduction_opportunity.cpp
+++ b/source/reduce/merge_blocks_reduction_opportunity.cpp
@@ -12,15 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "merge_blocks_reduction_opportunity.h"
-#include "source/opt/block_merge_util.h"
+#include "source/reduce/merge_blocks_reduction_opportunity.h"
+#include "source/opt/block_merge_util.h"
#include "source/opt/ir_context.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::BasicBlock;
+using opt::Function;
+using opt::IRContext;
MergeBlocksReductionOpportunity::MergeBlocksReductionOpportunity(
IRContext* context, Function* function, BasicBlock* block) {
@@ -48,7 +50,8 @@
"predecessor must be present.");
const uint32_t predecessor_id = predecessors[0];
BasicBlock* predecessor_block = context_->get_instr_block(predecessor_id);
- return blockmergeutil::CanMergeWithSuccessor(context_, predecessor_block);
+ return opt::blockmergeutil::CanMergeWithSuccessor(context_,
+ predecessor_block);
}
void MergeBlocksReductionOpportunity::Apply() {
@@ -65,7 +68,7 @@
// We need an iterator pointing to the predecessor, hence the loop.
for (auto bi = function_->begin(); bi != function_->end(); ++bi) {
if (bi->id() == predecessor_id) {
- blockmergeutil::MergeWithSuccessor(context_, function_, bi);
+ opt::blockmergeutil::MergeWithSuccessor(context_, function_, bi);
// Block merging changes the control flow graph, so invalidate it.
context_->InvalidateAnalysesExceptFor(IRContext::Analysis::kAnalysisNone);
return;
diff --git a/source/reduce/merge_blocks_reduction_opportunity.h b/source/reduce/merge_blocks_reduction_opportunity.h
index aa78f85..5c9180b 100644
--- a/source/reduce/merge_blocks_reduction_opportunity.h
+++ b/source/reduce/merge_blocks_reduction_opportunity.h
@@ -15,9 +15,9 @@
#ifndef SOURCE_REDUCE_MERGE_BLOCKS_REDUCTION_OPPORTUNITY_H_
#define SOURCE_REDUCE_MERGE_BLOCKS_REDUCTION_OPPORTUNITY_H_
-#include "reduction_opportunity.h"
#include "source/opt/basic_block.h"
#include "source/opt/function.h"
+#include "source/reduce/reduction_opportunity.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/merge_blocks_reduction_opportunity_finder.cpp b/source/reduce/merge_blocks_reduction_opportunity_finder.cpp
index 0546e1f..89d6263 100644
--- a/source/reduce/merge_blocks_reduction_opportunity_finder.cpp
+++ b/source/reduce/merge_blocks_reduction_opportunity_finder.cpp
@@ -19,7 +19,7 @@
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::IRContext;
std::string MergeBlocksReductionOpportunityFinder::GetName() const {
return "MergeBlocksReductionOpportunityFinder";
@@ -27,14 +27,14 @@
std::vector<std::unique_ptr<ReductionOpportunity>>
MergeBlocksReductionOpportunityFinder::GetAvailableOpportunities(
- opt::IRContext* context) const {
+ IRContext* context) const {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
// Consider every block in every function.
for (auto& function : *context->module()) {
for (auto& block : function) {
// See whether it is possible to merge this block with its successor.
- if (blockmergeutil::CanMergeWithSuccessor(context, &block)) {
+ if (opt::blockmergeutil::CanMergeWithSuccessor(context, &block)) {
// It is, so record an opportunity to do this.
result.push_back(spvtools::MakeUnique<MergeBlocksReductionOpportunity>(
context, &function, &block));
diff --git a/source/reduce/operand_to_const_reduction_opportunity_finder.cpp b/source/reduce/operand_to_const_reduction_opportunity_finder.cpp
index 97e0b9d..3e0a224 100644
--- a/source/reduce/operand_to_const_reduction_opportunity_finder.cpp
+++ b/source/reduce/operand_to_const_reduction_opportunity_finder.cpp
@@ -20,11 +20,11 @@
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::IRContext;
std::vector<std::unique_ptr<ReductionOpportunity>>
OperandToConstReductionOpportunityFinder::GetAvailableOpportunities(
- opt::IRContext* context) const {
+ IRContext* context) const {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
assert(result.empty());
diff --git a/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.cpp b/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.cpp
index d31acdf..13beb89 100644
--- a/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.cpp
+++ b/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.cpp
@@ -12,18 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "operand_to_dominating_id_reduction_opportunity_finder.h"
-#include "change_operand_reduction_opportunity.h"
+#include "source/reduce/operand_to_dominating_id_reduction_opportunity_finder.h"
+
#include "source/opt/instruction.h"
+#include "source/reduce/change_operand_reduction_opportunity.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::Function;
+using opt::IRContext;
+using opt::Instruction;
std::vector<std::unique_ptr<ReductionOpportunity>>
OperandToDominatingIdReductionOpportunityFinder::GetAvailableOpportunities(
- opt::IRContext* context) const {
+ IRContext* context) const {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
// Go through every instruction in every block, considering it as a potential
@@ -58,9 +61,9 @@
void OperandToDominatingIdReductionOpportunityFinder::
GetOpportunitiesForDominatingInst(
std::vector<std::unique_ptr<ReductionOpportunity>>* opportunities,
- opt::Instruction* candidate_dominator,
- opt::Function::iterator candidate_dominator_block,
- opt::Function* function, opt::IRContext* context) const {
+ Instruction* candidate_dominator,
+ Function::iterator candidate_dominator_block, Function* function,
+ IRContext* context) const {
assert(candidate_dominator->HasResultId());
assert(candidate_dominator->type_id());
auto dominator_analysis = context->GetDominatorAnalysis(function);
diff --git a/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.h b/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.h
index 471c583..7745ff7 100644
--- a/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.h
+++ b/source/reduce/operand_to_dominating_id_reduction_opportunity_finder.h
@@ -15,7 +15,7 @@
#ifndef SOURCE_REDUCE_OPERAND_TO_DOMINATING_ID_REDUCTION_OPPORTUNITY_FINDER_H_
#define SOURCE_REDUCE_OPERAND_TO_DOMINATING_ID_REDUCTION_OPPORTUNITY_FINDER_H_
-#include "reduction_opportunity_finder.h"
+#include "source/reduce/reduction_opportunity_finder.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/operand_to_undef_reduction_opportunity_finder.cpp b/source/reduce/operand_to_undef_reduction_opportunity_finder.cpp
index 516b529..579b7df 100644
--- a/source/reduce/operand_to_undef_reduction_opportunity_finder.cpp
+++ b/source/reduce/operand_to_undef_reduction_opportunity_finder.cpp
@@ -20,7 +20,7 @@
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::IRContext;
std::vector<std::unique_ptr<ReductionOpportunity>>
OperandToUndefReductionOpportunityFinder::GetAvailableOpportunities(
diff --git a/source/reduce/reducer.cpp b/source/reduce/reducer.cpp
index 80c7349..e0fa84b 100644
--- a/source/reduce/reducer.cpp
+++ b/source/reduce/reducer.cpp
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "source/reduce/reducer.h"
+
#include <cassert>
#include <sstream>
@@ -19,6 +21,7 @@
#include "source/reduce/operand_to_const_reduction_opportunity_finder.h"
#include "source/reduce/operand_to_dominating_id_reduction_opportunity_finder.h"
#include "source/reduce/operand_to_undef_reduction_opportunity_finder.h"
+#include "source/reduce/remove_block_reduction_opportunity_finder.h"
#include "source/reduce/remove_function_reduction_opportunity_finder.h"
#include "source/reduce/remove_opname_instruction_reduction_opportunity_finder.h"
#include "source/reduce/remove_selection_reduction_opportunity_finder.h"
@@ -26,8 +29,6 @@
#include "source/reduce/structured_loop_to_selection_reduction_opportunity_finder.h"
#include "source/spirv_reducer_options.h"
-#include "reducer.h"
-
namespace spvtools {
namespace reduce {
@@ -187,6 +188,8 @@
AddReductionPass(
spvtools::MakeUnique<RemoveFunctionReductionOpportunityFinder>());
AddReductionPass(
+ spvtools::MakeUnique<RemoveBlockReductionOpportunityFinder>());
+ AddReductionPass(
spvtools::MakeUnique<RemoveSelectionReductionOpportunityFinder>());
}
diff --git a/source/reduce/reducer.h b/source/reduce/reducer.h
index 81fb0dd..a9b28c3 100644
--- a/source/reduce/reducer.h
+++ b/source/reduce/reducer.h
@@ -18,10 +18,9 @@
#include <functional>
#include <string>
+#include "source/reduce/reduction_pass.h"
#include "spirv-tools/libspirv.hpp"
-#include "reduction_pass.h"
-
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/reduction_opportunity.cpp b/source/reduce/reduction_opportunity.cpp
index f562678..77be784 100644
--- a/source/reduce/reduction_opportunity.cpp
+++ b/source/reduce/reduction_opportunity.cpp
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduction_opportunity.h"
+#include "source/reduce/reduction_opportunity.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/reduction_opportunity_finder.h b/source/reduce/reduction_opportunity_finder.h
index b9f55d5..1837484 100644
--- a/source/reduce/reduction_opportunity_finder.h
+++ b/source/reduce/reduction_opportunity_finder.h
@@ -15,8 +15,8 @@
#ifndef SOURCE_REDUCE_REDUCTION_OPPORTUNITY_FINDER_H_
#define SOURCE_REDUCE_REDUCTION_OPPORTUNITY_FINDER_H_
-#include "reduction_opportunity.h"
#include "source/opt/ir_context.h"
+#include "source/reduce/reduction_opportunity.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/reduction_pass.cpp b/source/reduce/reduction_pass.cpp
index dda752b..2cb986d 100644
--- a/source/reduce/reduction_pass.cpp
+++ b/source/reduce/reduction_pass.cpp
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include <algorithm>
+#include "source/reduce/reduction_pass.h"
-#include "reduction_pass.h"
+#include <algorithm>
#include "source/opt/build_module.h"
diff --git a/source/reduce/reduction_util.cpp b/source/reduce/reduction_util.cpp
index 103d63f..4a6e75a 100644
--- a/source/reduce/reduction_util.cpp
+++ b/source/reduce/reduction_util.cpp
@@ -19,7 +19,8 @@
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::IRContext;
+using opt::Instruction;
uint32_t FindOrCreateGlobalUndef(IRContext* context, uint32_t type_id) {
for (auto& inst : context->module()->types_values()) {
diff --git a/source/reduce/remove_block_reduction_opportunity.cpp b/source/reduce/remove_block_reduction_opportunity.cpp
index 9b952c4..3ad7f72 100644
--- a/source/reduce/remove_block_reduction_opportunity.cpp
+++ b/source/reduce/remove_block_reduction_opportunity.cpp
@@ -12,14 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "remove_block_reduction_opportunity.h"
+#include "source/reduce/remove_block_reduction_opportunity.h"
#include "source/opt/ir_context.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::BasicBlock;
+using opt::Function;
RemoveBlockReductionOpportunity::RemoveBlockReductionOpportunity(
Function* function, BasicBlock* block)
diff --git a/source/reduce/remove_block_reduction_opportunity.h b/source/reduce/remove_block_reduction_opportunity.h
index 45c0c17..4b358ab 100644
--- a/source/reduce/remove_block_reduction_opportunity.h
+++ b/source/reduce/remove_block_reduction_opportunity.h
@@ -15,9 +15,9 @@
#ifndef SOURCE_REDUCE_REMOVE_BLOCK_REDUCTION_OPPORTUNITY_H_
#define SOURCE_REDUCE_REMOVE_BLOCK_REDUCTION_OPPORTUNITY_H_
-#include "reduction_opportunity.h"
#include "source/opt/basic_block.h"
#include "source/opt/function.h"
+#include "source/reduce/reduction_opportunity.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/remove_block_reduction_opportunity_finder.cpp b/source/reduce/remove_block_reduction_opportunity_finder.cpp
index a4ca1f2..a3f873f 100644
--- a/source/reduce/remove_block_reduction_opportunity_finder.cpp
+++ b/source/reduce/remove_block_reduction_opportunity_finder.cpp
@@ -13,12 +13,15 @@
// limitations under the License.
#include "source/reduce/remove_block_reduction_opportunity_finder.h"
+
#include "source/reduce/remove_block_reduction_opportunity.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::Function;
+using opt::IRContext;
+using opt::Instruction;
std::string RemoveBlockReductionOpportunityFinder::GetName() const {
return "RemoveBlockReductionOpportunityFinder";
@@ -26,7 +29,7 @@
std::vector<std::unique_ptr<ReductionOpportunity>>
RemoveBlockReductionOpportunityFinder::GetAvailableOpportunities(
- opt::IRContext* context) const {
+ IRContext* context) const {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
// Consider every block in every function.
@@ -42,8 +45,7 @@
}
bool RemoveBlockReductionOpportunityFinder::IsBlockValidOpportunity(
- opt::IRContext* context, opt::Function& function,
- opt::Function::iterator& bi) {
+ IRContext* context, Function& function, Function::iterator& bi) {
assert(bi != function.end() && "Block iterator was out of bounds");
// Don't remove first block; we don't want to end up with no blocks.
@@ -65,7 +67,7 @@
}
bool RemoveBlockReductionOpportunityFinder::
- BlockInstructionsHaveNoOutsideReferences(opt::IRContext* context,
+ BlockInstructionsHaveNoOutsideReferences(IRContext* context,
const Function::iterator& bi) {
// Get all instructions in block.
std::unordered_set<uint32_t> instructions_in_block;
diff --git a/source/reduce/remove_function_reduction_opportunity.cpp b/source/reduce/remove_function_reduction_opportunity.cpp
index 6ecf61b..ecad670 100644
--- a/source/reduce/remove_function_reduction_opportunity.cpp
+++ b/source/reduce/remove_function_reduction_opportunity.cpp
@@ -12,7 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "remove_function_reduction_opportunity.h"
+#include "source/reduce/remove_function_reduction_opportunity.h"
+
#include "source/opt/eliminate_dead_functions_util.h"
namespace spvtools {
diff --git a/source/reduce/remove_function_reduction_opportunity.h b/source/reduce/remove_function_reduction_opportunity.h
index 483453d..d8c57db 100644
--- a/source/reduce/remove_function_reduction_opportunity.h
+++ b/source/reduce/remove_function_reduction_opportunity.h
@@ -15,8 +15,8 @@
#ifndef SOURCE_REDUCE_REMOVE_FUNCTION_REDUCTION_OPPORTUNITY_H_
#define SOURCE_REDUCE_REMOVE_FUNCTION_REDUCTION_OPPORTUNITY_H_
-#include "reduction_opportunity.h"
#include "source/opt/function.h"
+#include "source/reduce/reduction_opportunity.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/remove_function_reduction_opportunity_finder.cpp b/source/reduce/remove_function_reduction_opportunity_finder.cpp
index f0206fb..1edb973 100644
--- a/source/reduce/remove_function_reduction_opportunity_finder.cpp
+++ b/source/reduce/remove_function_reduction_opportunity_finder.cpp
@@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "remove_function_reduction_opportunity_finder.h"
-#include "remove_function_reduction_opportunity.h"
+#include "source/reduce/remove_function_reduction_opportunity_finder.h"
+
+#include "source/reduce/remove_function_reduction_opportunity.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/remove_instruction_reduction_opportunity.cpp b/source/reduce/remove_instruction_reduction_opportunity.cpp
index 7b7a74e..9ca093b 100644
--- a/source/reduce/remove_instruction_reduction_opportunity.cpp
+++ b/source/reduce/remove_instruction_reduction_opportunity.cpp
@@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "source/opt/ir_context.h"
+#include "source/reduce/remove_instruction_reduction_opportunity.h"
-#include "remove_instruction_reduction_opportunity.h"
+#include "source/opt/ir_context.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/remove_instruction_reduction_opportunity.h b/source/reduce/remove_instruction_reduction_opportunity.h
index e9f442e..07bef50 100644
--- a/source/reduce/remove_instruction_reduction_opportunity.h
+++ b/source/reduce/remove_instruction_reduction_opportunity.h
@@ -15,19 +15,17 @@
#ifndef SOURCE_REDUCE_REMOVE_INSTRUCTION_REDUCTION_OPPORTUNITY_H_
#define SOURCE_REDUCE_REMOVE_INSTRUCTION_REDUCTION_OPPORTUNITY_H_
-#include "reduction_opportunity.h"
#include "source/opt/instruction.h"
+#include "source/reduce/reduction_opportunity.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
-
// An opportunity to remove an instruction from the SPIR-V module.
class RemoveInstructionReductionOpportunity : public ReductionOpportunity {
public:
// Constructs the opportunity to remove |inst|.
- explicit RemoveInstructionReductionOpportunity(Instruction* inst)
+ explicit RemoveInstructionReductionOpportunity(opt::Instruction* inst)
: inst_(inst) {}
// Always returns true, as this opportunity can always be applied.
@@ -37,7 +35,7 @@
void Apply() override;
private:
- Instruction* inst_;
+ opt::Instruction* inst_;
};
} // namespace reduce
diff --git a/source/reduce/remove_opname_instruction_reduction_opportunity_finder.cpp b/source/reduce/remove_opname_instruction_reduction_opportunity_finder.cpp
index fa2d27f..f687d71 100644
--- a/source/reduce/remove_opname_instruction_reduction_opportunity_finder.cpp
+++ b/source/reduce/remove_opname_instruction_reduction_opportunity_finder.cpp
@@ -12,19 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "remove_opname_instruction_reduction_opportunity_finder.h"
-#include "remove_instruction_reduction_opportunity.h"
+#include "source/reduce/remove_opname_instruction_reduction_opportunity_finder.h"
+
#include "source/opcode.h"
#include "source/opt/instruction.h"
+#include "source/reduce/remove_instruction_reduction_opportunity.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::IRContext;
std::vector<std::unique_ptr<ReductionOpportunity>>
RemoveOpNameInstructionReductionOpportunityFinder::GetAvailableOpportunities(
- opt::IRContext* context) const {
+ IRContext* context) const {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
for (auto& inst : context->module()->debugs2()) {
diff --git a/source/reduce/remove_opname_instruction_reduction_opportunity_finder.h b/source/reduce/remove_opname_instruction_reduction_opportunity_finder.h
index 4304226..8b9fd6f 100644
--- a/source/reduce/remove_opname_instruction_reduction_opportunity_finder.h
+++ b/source/reduce/remove_opname_instruction_reduction_opportunity_finder.h
@@ -15,7 +15,7 @@
#ifndef SOURCE_REDUCE_REMOVE_OPNAME_INSTRUCTION_REDUCTION_OPPORTUNITY_FINDER_H_
#define SOURCE_REDUCE_REMOVE_OPNAME_INSTRUCTION_REDUCTION_OPPORTUNITY_FINDER_H_
-#include "reduction_opportunity_finder.h"
+#include "source/reduce/reduction_opportunity_finder.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/remove_selection_reduction_opportunity_finder.cpp b/source/reduce/remove_selection_reduction_opportunity_finder.cpp
index d2994c2..45cf26d 100644
--- a/source/reduce/remove_selection_reduction_opportunity_finder.cpp
+++ b/source/reduce/remove_selection_reduction_opportunity_finder.cpp
@@ -19,7 +19,9 @@
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::BasicBlock;
+using opt::IRContext;
+using opt::Instruction;
namespace {
const uint32_t kMergeNodeIndex = 0;
@@ -32,7 +34,7 @@
std::vector<std::unique_ptr<ReductionOpportunity>>
RemoveSelectionReductionOpportunityFinder::GetAvailableOpportunities(
- opt::IRContext* context) const {
+ IRContext* context) const {
// Get all loop merge and continue blocks so we can check for these later.
std::unordered_set<uint32_t> merge_and_continue_blocks_from_loops;
for (auto& function : *context->module()) {
@@ -71,8 +73,8 @@
}
bool RemoveSelectionReductionOpportunityFinder::CanOpSelectionMergeBeRemoved(
- opt::IRContext* context, const opt::BasicBlock& header_block,
- opt::Instruction* merge_instruction,
+ IRContext* context, const BasicBlock& header_block,
+ Instruction* merge_instruction,
std::unordered_set<uint32_t> merge_and_continue_blocks_from_loops) {
assert(header_block.GetMergeInst() == merge_instruction &&
"CanOpSelectionMergeBeRemoved(...): header block and merge "
diff --git a/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.cpp b/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.cpp
index 03880af..8f32435 100644
--- a/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.cpp
+++ b/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.cpp
@@ -12,19 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "remove_unreferenced_instruction_reduction_opportunity_finder.h"
-#include "remove_instruction_reduction_opportunity.h"
+#include "source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h"
+
#include "source/opcode.h"
#include "source/opt/instruction.h"
+#include "source/reduce/remove_instruction_reduction_opportunity.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::IRContext;
std::vector<std::unique_ptr<ReductionOpportunity>>
RemoveUnreferencedInstructionReductionOpportunityFinder::
- GetAvailableOpportunities(opt::IRContext* context) const {
+ GetAvailableOpportunities(IRContext* context) const {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
for (auto& function : *context->module()) {
diff --git a/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h b/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h
index 1bb2afb..30f460b 100644
--- a/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h
+++ b/source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h
@@ -15,7 +15,7 @@
#ifndef SOURCE_REDUCE_REMOVE_UNREFERENCED_INSTRUCTION_REDUCTION_OPPORTUNITY_FINDER_H_
#define SOURCE_REDUCE_REMOVE_UNREFERENCED_INSTRUCTION_REDUCTION_OPPORTUNITY_FINDER_H_
-#include "reduction_opportunity_finder.h"
+#include "source/reduce/reduction_opportunity_finder.h"
namespace spvtools {
namespace reduce {
diff --git a/source/reduce/structured_loop_to_selection_reduction_opportunity.cpp b/source/reduce/structured_loop_to_selection_reduction_opportunity.cpp
index 8e25837..afc1298 100644
--- a/source/reduce/structured_loop_to_selection_reduction_opportunity.cpp
+++ b/source/reduce/structured_loop_to_selection_reduction_opportunity.cpp
@@ -21,6 +21,11 @@
namespace spvtools {
namespace reduce {
+using opt::BasicBlock;
+using opt::IRContext;
+using opt::Instruction;
+using opt::Operand;
+
namespace {
const uint32_t kMergeNodeIndex = 0;
} // namespace
@@ -208,8 +213,8 @@
// the "else" branch be the merge block.
auto terminator = loop_construct_header_->terminator();
if (terminator->opcode() == SpvOpBranch) {
- analysis::Bool temp;
- const analysis::Bool* bool_type =
+ opt::analysis::Bool temp;
+ const opt::analysis::Bool* bool_type =
context_->get_type_mgr()->GetRegisteredType(&temp)->AsBool();
auto const_mgr = context_->get_constant_mgr();
auto true_const = const_mgr->GetConstant(bool_type, {1});
diff --git a/source/reduce/structured_loop_to_selection_reduction_opportunity.h b/source/reduce/structured_loop_to_selection_reduction_opportunity.h
index 71b0f0e..f6c065b 100644
--- a/source/reduce/structured_loop_to_selection_reduction_opportunity.h
+++ b/source/reduce/structured_loop_to_selection_reduction_opportunity.h
@@ -23,8 +23,6 @@
namespace spvtools {
namespace reduce {
-using namespace opt;
-
// An opportunity to replace a structured loop with a selection.
class StructuredLoopToSelectionReductionOpportunity
: public ReductionOpportunity {
@@ -32,8 +30,8 @@
// Constructs an opportunity from a loop header block and the function that
// encloses it.
explicit StructuredLoopToSelectionReductionOpportunity(
- IRContext* context, BasicBlock* loop_construct_header,
- Function* enclosing_function)
+ opt::IRContext* context, opt::BasicBlock* loop_construct_header,
+ opt::Function* enclosing_function)
: context_(context),
loop_construct_header_(loop_construct_header),
enclosing_function_(enclosing_function) {}
@@ -67,11 +65,12 @@
// Removes any components of |to_block|'s phi instructions relating to
// |from_id|.
void AdaptPhiInstructionsForRemovedEdge(uint32_t from_id,
- BasicBlock* to_block);
+ opt::BasicBlock* to_block);
// Adds components to |to_block|'s phi instructions to account for a new
// incoming edge from |from_id|.
- void AdaptPhiInstructionsForAddedEdge(uint32_t from_id, BasicBlock* to_block);
+ void AdaptPhiInstructionsForAddedEdge(uint32_t from_id,
+ opt::BasicBlock* to_block);
// Turns the OpLoopMerge for the loop into OpSelectionMerge, and adapts the
// following branch instruction accordingly.
@@ -87,9 +86,10 @@
// 2) |def| is an OpVariable
// 3) |use| is part of an OpPhi, with associated incoming block b, and |def|
// dominates b.
- bool DefinitionSufficientlyDominatesUse(Instruction* def, Instruction* use,
+ bool DefinitionSufficientlyDominatesUse(opt::Instruction* def,
+ opt::Instruction* use,
uint32_t use_index,
- BasicBlock& def_block);
+ opt::BasicBlock& def_block);
// Checks whether the global value list has an OpVariable of the given pointer
// type, adding one if not, and returns the id of such an OpVariable.
@@ -105,9 +105,9 @@
// be factored out in due course.
uint32_t FindOrCreateFunctionVariable(uint32_t pointer_type_id);
- IRContext* context_;
- BasicBlock* loop_construct_header_;
- Function* enclosing_function_;
+ opt::IRContext* context_;
+ opt::BasicBlock* loop_construct_header_;
+ opt::Function* enclosing_function_;
};
} // namespace reduce
diff --git a/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.cpp b/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.cpp
index 6d835fc..085b267 100644
--- a/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.cpp
+++ b/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.cpp
@@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "structured_loop_to_selection_reduction_opportunity_finder.h"
-#include "structured_loop_to_selection_reduction_opportunity.h"
+#include "source/reduce/structured_loop_to_selection_reduction_opportunity_finder.h"
+
+#include "source/reduce/structured_loop_to_selection_reduction_opportunity.h"
namespace spvtools {
namespace reduce {
-using namespace opt;
+using opt::IRContext;
namespace {
const uint32_t kMergeNodeIndex = 0;
@@ -27,7 +28,7 @@
std::vector<std::unique_ptr<ReductionOpportunity>>
StructuredLoopToSelectionReductionOpportunityFinder::GetAvailableOpportunities(
- opt::IRContext* context) const {
+ IRContext* context) const {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
std::set<uint32_t> merge_block_ids;
diff --git a/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.h b/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.h
index 4c714ec..d63d434 100644
--- a/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.h
+++ b/source/reduce/structured_loop_to_selection_reduction_opportunity_finder.h
@@ -15,7 +15,7 @@
#ifndef SOURCE_REDUCE_STRUCTURED_LOOP_TO_SELECTION_REDUCTION_OPPORTUNITY_FINDER_H
#define SOURCE_REDUCE_STRUCTURED_LOOP_TO_SELECTION_REDUCTION_OPPORTUNITY_FINDER_H
-#include "reduction_opportunity_finder.h"
+#include "source/reduce/reduction_opportunity_finder.h"
namespace spvtools {
namespace reduce {
diff --git a/test/reduce/merge_blocks_test.cpp b/test/reduce/merge_blocks_test.cpp
index 55b27bd..dfb614e 100644
--- a/test/reduce/merge_blocks_test.cpp
+++ b/test/reduce/merge_blocks_test.cpp
@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
-#include "source/opt/build_module.h"
#include "source/reduce/merge_blocks_reduction_opportunity_finder.h"
+
+#include "source/opt/build_module.h"
#include "source/reduce/reduction_opportunity.h"
+#include "test/reduce/reduce_test_util.h"
namespace spvtools {
namespace reduce {
diff --git a/test/reduce/operand_to_constant_test.cpp b/test/reduce/operand_to_constant_test.cpp
index 15d76ca..b2f67ee 100644
--- a/test/reduce/operand_to_constant_test.cpp
+++ b/test/reduce/operand_to_constant_test.cpp
@@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
-#include "source/opt/build_module.h"
#include "source/reduce/operand_to_const_reduction_opportunity_finder.h"
+#include "source/opt/build_module.h"
+#include "source/reduce/reduction_opportunity.h"
+#include "test/reduce/reduce_test_util.h"
+
namespace spvtools {
namespace reduce {
namespace {
diff --git a/test/reduce/operand_to_dominating_id_test.cpp b/test/reduce/operand_to_dominating_id_test.cpp
index 60bff9b..cd5b2c6 100644
--- a/test/reduce/operand_to_dominating_id_test.cpp
+++ b/test/reduce/operand_to_dominating_id_test.cpp
@@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
-#include "source/opt/build_module.h"
#include "source/reduce/operand_to_dominating_id_reduction_opportunity_finder.h"
+#include "source/opt/build_module.h"
+#include "source/reduce/reduction_opportunity.h"
+#include "test/reduce/reduce_test_util.h"
+
namespace spvtools {
namespace reduce {
namespace {
diff --git a/test/reduce/operand_to_undef_test.cpp b/test/reduce/operand_to_undef_test.cpp
index 3e3079b..fa64bd5 100644
--- a/test/reduce/operand_to_undef_test.cpp
+++ b/test/reduce/operand_to_undef_test.cpp
@@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "source/opt/build_module.h"
#include "source/reduce/operand_to_undef_reduction_opportunity_finder.h"
+
+#include "source/opt/build_module.h"
+#include "source/reduce/reduction_opportunity.h"
#include "test/reduce/reduce_test_util.h"
namespace spvtools {
diff --git a/test/reduce/reduce_test_util.cpp b/test/reduce/reduce_test_util.cpp
index 96fb4ac..0c23411 100644
--- a/test/reduce/reduce_test_util.cpp
+++ b/test/reduce/reduce_test_util.cpp
@@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
+#include "test/reduce/reduce_test_util.h"
#include <iostream>
+#include "tools/io.h"
+
namespace spvtools {
namespace reduce {
@@ -92,5 +94,19 @@
}
}
+void DumpShader(opt::IRContext* context, const char* filename) {
+ std::vector<uint32_t> binary;
+ context->module()->ToBinary(&binary, false);
+ DumpShader(binary, filename);
+}
+
+void DumpShader(const std::vector<uint32_t>& binary, const char* filename) {
+ auto write_file_succeeded =
+ WriteFile(filename, "wb", &binary[0], binary.size());
+ if (!write_file_succeeded) {
+ std::cerr << "Failed to dump shader" << std::endl;
+ }
+}
+
} // namespace reduce
} // namespace spvtools
diff --git a/test/reduce/reduce_test_util.h b/test/reduce/reduce_test_util.h
index 387d995..b9ad12f 100644
--- a/test/reduce/reduce_test_util.h
+++ b/test/reduce/reduce_test_util.h
@@ -16,7 +16,6 @@
#define TEST_REDUCE_REDUCE_TEST_UTIL_H_
#include "gtest/gtest.h"
-
#include "source/opt/ir_context.h"
#include "source/reduce/reduction_opportunity.h"
#include "spirv-tools/libspirv.h"
@@ -63,6 +62,13 @@
void CLIMessageConsumer(spv_message_level_t level, const char*,
const spv_position_t& position, const char* message);
+// Dumps the SPIRV-V module in |context| to file |filename|. Useful for
+// interactive debugging.
+void DumpShader(opt::IRContext* context, const char* filename);
+
+// Dumps |binary| to file |filename|. Useful for interactive debugging.
+void DumpShader(const std::vector<uint32_t>& binary, const char* filename);
+
} // namespace reduce
} // namespace spvtools
diff --git a/test/reduce/reducer_test.cpp b/test/reduce/reducer_test.cpp
index cb169f8..8787733 100644
--- a/test/reduce/reducer_test.cpp
+++ b/test/reduce/reducer_test.cpp
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
+#include "source/reduce/reducer.h"
#include "source/reduce/operand_to_const_reduction_opportunity_finder.h"
-#include "source/reduce/reducer.h"
#include "source/reduce/remove_opname_instruction_reduction_opportunity_finder.h"
#include "source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h"
+#include "test/reduce/reduce_test_util.h"
namespace spvtools {
namespace reduce {
diff --git a/test/reduce/remove_block_test.cpp b/test/reduce/remove_block_test.cpp
index 71508c8..f31cc9d 100644
--- a/test/reduce/remove_block_test.cpp
+++ b/test/reduce/remove_block_test.cpp
@@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
+#include "source/reduce/remove_block_reduction_opportunity_finder.h"
+
#include "source/opt/build_module.h"
#include "source/reduce/reduction_opportunity.h"
-#include "source/reduce/remove_block_reduction_opportunity.h"
-#include "source/reduce/remove_block_reduction_opportunity_finder.h"
+#include "test/reduce/reduce_test_util.h"
namespace spvtools {
namespace reduce {
diff --git a/test/reduce/remove_function_test.cpp b/test/reduce/remove_function_test.cpp
index 6508bc9..576b603 100644
--- a/test/reduce/remove_function_test.cpp
+++ b/test/reduce/remove_function_test.cpp
@@ -12,10 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
+#include "source/reduce/remove_function_reduction_opportunity_finder.h"
+
#include "source/opt/build_module.h"
#include "source/reduce/reduction_opportunity.h"
-#include "source/reduce/remove_function_reduction_opportunity_finder.h"
+#include "test/reduce/reduce_test_util.h"
namespace spvtools {
namespace reduce {
diff --git a/test/reduce/remove_opname_instruction_test.cpp b/test/reduce/remove_opname_instruction_test.cpp
index e74c0f9..9d40cfc 100644
--- a/test/reduce/remove_opname_instruction_test.cpp
+++ b/test/reduce/remove_opname_instruction_test.cpp
@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
+#include "source/reduce/remove_opname_instruction_reduction_opportunity_finder.h"
#include "source/opt/build_module.h"
#include "source/reduce/reduction_opportunity.h"
#include "source/reduce/reduction_pass.h"
-#include "source/reduce/remove_opname_instruction_reduction_opportunity_finder.h"
+#include "test/reduce/reduce_test_util.h"
namespace spvtools {
namespace reduce {
diff --git a/test/reduce/remove_selection_test.cpp b/test/reduce/remove_selection_test.cpp
index 40ac028..f8acd5d 100644
--- a/test/reduce/remove_selection_test.cpp
+++ b/test/reduce/remove_selection_test.cpp
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include "source/reduce/remove_selection_reduction_opportunity_finder.h"
+
#include "source/opt/build_module.h"
#include "source/reduce/reduction_opportunity.h"
-#include "source/reduce/reduction_pass.h"
-#include "source/reduce/remove_selection_reduction_opportunity_finder.h"
#include "test/reduce/reduce_test_util.h"
namespace spvtools {
diff --git a/test/reduce/remove_unreferenced_instruction_test.cpp b/test/reduce/remove_unreferenced_instruction_test.cpp
index 12cd3e2..0babf78 100644
--- a/test/reduce/remove_unreferenced_instruction_test.cpp
+++ b/test/reduce/remove_unreferenced_instruction_test.cpp
@@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
+#include "source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h"
#include "source/opt/build_module.h"
#include "source/reduce/reduction_opportunity.h"
-#include "source/reduce/reduction_pass.h"
-#include "source/reduce/remove_unreferenced_instruction_reduction_opportunity_finder.h"
#include "source/util/make_unique.h"
+#include "test/reduce/reduce_test_util.h"
namespace spvtools {
namespace reduce {
diff --git a/test/reduce/structured_loop_to_selection_test.cpp b/test/reduce/structured_loop_to_selection_test.cpp
index d4f6459..95b5f4f 100644
--- a/test/reduce/structured_loop_to_selection_test.cpp
+++ b/test/reduce/structured_loop_to_selection_test.cpp
@@ -12,10 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
-#include "source/opt/build_module.h"
#include "source/reduce/structured_loop_to_selection_reduction_opportunity_finder.h"
+#include "source/opt/build_module.h"
+#include "source/reduce/reduction_opportunity.h"
+#include "test/reduce/reduce_test_util.h"
+
namespace spvtools {
namespace reduce {
namespace {
diff --git a/test/reduce/validation_during_reduction_test.cpp b/test/reduce/validation_during_reduction_test.cpp
index 863795b..612b657 100644
--- a/test/reduce/validation_during_reduction_test.cpp
+++ b/test/reduce/validation_during_reduction_test.cpp
@@ -12,16 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#include "reduce_test_util.h"
-
#include "source/reduce/reducer.h"
-#include "source/reduce/reduction_pass.h"
+
+#include "source/reduce/reduction_opportunity.h"
#include "source/reduce/remove_instruction_reduction_opportunity.h"
+#include "test/reduce/reduce_test_util.h"
namespace spvtools {
namespace reduce {
namespace {
+using opt::Function;
+using opt::IRContext;
+using opt::Instruction;
+
// A dumb reduction opportunity finder that finds opportunities to remove global
// values regardless of whether they are referenced. This is very likely to make
// the resulting module invalid. We use this to test the reducer's behavior in
@@ -40,7 +44,7 @@
// referenced (directly or indirectly) from elsewhere in the module, each such
// opportunity will make the module invalid.
std::vector<std::unique_ptr<ReductionOpportunity>> GetAvailableOpportunities(
- opt::IRContext* context) const final {
+ IRContext* context) const final {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
for (auto& inst : context->module()->types_values()) {
if (inst.HasResultId()) {
@@ -59,8 +63,8 @@
// limits are enforced.
class OpVariableDuplicatorReductionOpportunity : public ReductionOpportunity {
public:
- OpVariableDuplicatorReductionOpportunity(Function* function_)
- : function_(function_) {}
+ OpVariableDuplicatorReductionOpportunity(Function* function)
+ : function_(function) {}
bool PreconditionHolds() override {
Instruction* first_instruction = &*function_->begin()[0].begin();
@@ -98,7 +102,7 @@
};
std::vector<std::unique_ptr<ReductionOpportunity>> GetAvailableOpportunities(
- opt::IRContext* context) const final {
+ IRContext* context) const final {
std::vector<std::unique_ptr<ReductionOpportunity>> result;
for (auto& function : *context->module()) {
Instruction* first_instruction = &*function.begin()[0].begin();
@@ -446,7 +450,7 @@
// Sets up a Reducer for use in the CheckValidationOptions test; avoids
// repetition.
-void setupReducerForCheckValidationOptions(Reducer* reducer) {
+void SetupReducerForCheckValidationOptions(Reducer* reducer) {
reducer->SetMessageConsumer(NopDiagnostic);
// Say that every module is interesting.
@@ -531,7 +535,7 @@
// always returns true.
{
Reducer reducer(env);
- setupReducerForCheckValidationOptions(&reducer);
+ SetupReducerForCheckValidationOptions(&reducer);
Reducer::ReductionResultStatus status =
reducer.Run(std::vector<uint32_t>(binary_in), &binary_out,
@@ -547,7 +551,7 @@
// test always succeeds, and the finder yields infinite opportunities.
{
Reducer reducer(env);
- setupReducerForCheckValidationOptions(&reducer);
+ SetupReducerForCheckValidationOptions(&reducer);
Reducer::ReductionResultStatus status =
reducer.Run(std::vector<uint32_t>(binary_in), &binary_out,
@@ -565,7 +569,7 @@
// validator limits.
{
Reducer reducer(env);
- setupReducerForCheckValidationOptions(&reducer);
+ SetupReducerForCheckValidationOptions(&reducer);
Reducer::ReductionResultStatus status =
reducer.Run(std::vector<uint32_t>(binary_in), &binary_out,
diff --git a/tools/reduce/reduce.cpp b/tools/reduce/reduce.cpp
index 4c3c2d0..5c78cbf 100644
--- a/tools/reduce/reduce.cpp
+++ b/tools/reduce/reduce.cpp
@@ -18,6 +18,7 @@
#include <functional>
#include "source/opt/build_module.h"
+#include "source/opt/ir_context.h"
#include "source/opt/log.h"
#include "source/reduce/reducer.h"
#include "source/spirv_reducer_options.h"
@@ -25,8 +26,6 @@
#include "tools/io.h"
#include "tools/util/cli_consumer.h"
-using namespace spvtools::reduce;
-
namespace {
using ErrorOrInt = std::pair<std::string, int>;
@@ -200,6 +199,23 @@
} // namespace
+// Dumps |binary| to file |filename|. Useful for interactive debugging.
+void DumpShader(const std::vector<uint32_t>& binary, const char* filename) {
+ auto write_file_succeeded =
+ WriteFile(filename, "wb", &binary[0], binary.size());
+ if (!write_file_succeeded) {
+ std::cerr << "Failed to dump shader" << std::endl;
+ }
+}
+
+// Dumps the SPIRV-V module in |context| to file |filename|. Useful for
+// interactive debugging.
+void DumpShader(spvtools::opt::IRContext* context, const char* filename) {
+ std::vector<uint32_t> binary;
+ context->module()->ToBinary(&binary, false);
+ DumpShader(binary, filename);
+}
+
const auto kDefaultEnvironment = SPV_ENV_UNIVERSAL_1_3;
int main(int argc, const char** argv) {
@@ -223,7 +239,7 @@
return 2;
}
- Reducer reducer(target_env);
+ spvtools::reduce::Reducer reducer(target_env);
reducer.SetInterestingnessFunction(
[interestingness_test](std::vector<uint32_t> binary,
@@ -254,8 +270,8 @@
const auto reduction_status = reducer.Run(std::move(binary_in), &binary_out,
reducer_options, validator_options);
- if (reduction_status ==
- Reducer::ReductionResultStatus::kInitialStateNotInteresting ||
+ if (reduction_status == spvtools::reduce::Reducer::ReductionResultStatus::
+ kInitialStateNotInteresting ||
!WriteFile<uint32_t>("_reduced_final.spv", "wb", binary_out.data(),
binary_out.size())) {
return 1;