MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / GetFunctionInstructionCount

Function GetFunctionInstructionCount

test/reduce/reducer_test.cpp:563–574  ·  view source on GitHub ↗

Computes an instruction count for each function in the module represented by |binary|.

Source from the content-addressed store, hash-verified

561// Computes an instruction count for each function in the module represented by
562// |binary|.
563std::unordered_map<uint32_t, uint32_t> GetFunctionInstructionCount(
564 const std::vector<uint32_t>& binary) {
565 std::unique_ptr<opt::IRContext> context =
566 BuildModule(kEnv, kMessageConsumer, binary.data(), binary.size());
567 assert(context != nullptr && "Failed to build module.");
568 std::unordered_map<uint32_t, uint32_t> result;
569 for (auto& function : *context->module()) {
570 uint32_t& count = result[function.result_id()] = 0;
571 function.ForEachInst([&count](opt::Instruction*) { count++; });
572 }
573 return result;
574}
575
576TEST(ReducerTest, SingleFunctionReduction) {
577 Reducer reducer(kEnv);

Callers 1

TESTFunction · 0.85

Calls 6

BuildModuleFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45
moduleMethod · 0.45
result_idMethod · 0.45
ForEachInstMethod · 0.45

Tested by

no test coverage detected