| 34 | } |
| 35 | |
| 36 | TEST(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 |
nothing calls this directly
no test coverage detected