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

Function TEST

test/reduce/remove_function_test.cpp:36–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36TEST(RemoveFunctionTest, BasicCheck) {
37 std::string shader = R"(
38 OpCapability Shader
39 %1 = OpExtInstImport "GLSL.std.450"
40 OpMemoryModel Logical GLSL450
41 OpEntryPoint Fragment %4 "main"
42 OpExecutionMode %4 OriginUpperLeft
43 OpSource ESSL 310
44 %2 = OpTypeVoid
45 %3 = OpTypeFunction %2
46 %4 = OpFunction %2 None %3
47 %5 = OpLabel
48 OpReturn
49 OpFunctionEnd
50 %6 = OpFunction %2 None %3
51 %7 = OpLabel
52 OpReturn
53 OpFunctionEnd
54 %8 = OpFunction %2 None %3
55 %9 = OpLabel
56 %10 = OpFunctionCall %2 %6
57 OpReturn
58 OpFunctionEnd
59 )";
60
61 const auto env = SPV_ENV_UNIVERSAL_1_3;
62 const auto consumer = nullptr;
63 const auto context =
64 BuildModule(env, consumer, shader, kReduceAssembleOption);
65
66 ASSERT_EQ(3, count_functions(context.get()));
67
68 auto ops =
69 RemoveFunctionReductionOpportunityFinder().GetAvailableOpportunities(
70 context.get(), 0);
71 ASSERT_EQ(1, ops.size());
72
73 ASSERT_TRUE(ops[0]->PreconditionHolds());
74 ops[0]->TryToApply();
75
76 ASSERT_EQ(2, count_functions(context.get()));
77
78 std::string after_first = R"(
79 OpCapability Shader
80 %1 = OpExtInstImport "GLSL.std.450"
81 OpMemoryModel Logical GLSL450
82 OpEntryPoint Fragment %4 "main"
83 OpExecutionMode %4 OriginUpperLeft
84 OpSource ESSL 310
85 %2 = OpTypeVoid
86 %3 = OpTypeFunction %2
87 %4 = OpFunction %2 None %3
88 %5 = OpLabel
89 OpReturn
90 OpFunctionEnd
91 %6 = OpFunction %2 None %3
92 %7 = OpLabel
93 OpReturn

Callers

nothing calls this directly

Calls 9

count_functionsFunction · 0.85
CheckEqualFunction · 0.85
getMethod · 0.80
TryToApplyMethod · 0.80
BuildModuleFunction · 0.50
sizeMethod · 0.45
PreconditionHoldsMethod · 0.45

Tested by

no test coverage detected