Runs UnifyConstantPass on the code built from the given |test_builder|, and checks whether the optimization result matches with the code built from |expected_builder|.
| 103 | // and checks whether the optimization result matches with the code built |
| 104 | // from |expected_builder|. |
| 105 | void Check(const AssemblyBuilder& expected_builder, |
| 106 | const AssemblyBuilder& test_builder) { |
| 107 | // unoptimized code |
| 108 | const std::string original_before_strip = test_builder.GetCode(); |
| 109 | std::string original_without_opnames; |
| 110 | std::unordered_set<std::string> original_opnames; |
| 111 | std::tie(original_without_opnames, original_opnames) = |
| 112 | StripOpNameInstructionsToSet(original_before_strip); |
| 113 | |
| 114 | // expected code |
| 115 | std::string expected_without_opnames; |
| 116 | std::unordered_set<std::string> expected_opnames; |
| 117 | std::tie(expected_without_opnames, expected_opnames) = |
| 118 | StripOpNameInstructionsToSet(expected_builder.GetCode()); |
| 119 | |
| 120 | // optimized code |
| 121 | std::string optimized_before_strip; |
| 122 | auto status = Pass::Status::SuccessWithoutChange; |
| 123 | std::tie(optimized_before_strip, status) = |
| 124 | this->template SinglePassRunAndDisassemble<UnifyConstantPass>( |
| 125 | test_builder.GetCode(), |
| 126 | /* skip_nop = */ true, /* do_validation = */ false); |
| 127 | std::string optimized_without_opnames; |
| 128 | std::unordered_set<std::string> optimized_opnames; |
| 129 | std::tie(optimized_without_opnames, optimized_opnames) = |
| 130 | StripOpNameInstructionsToSet(optimized_before_strip); |
| 131 | |
| 132 | // Flag "status" should be returned correctly. |
| 133 | EXPECT_NE(Pass::Status::Failure, status); |
| 134 | EXPECT_EQ(expected_without_opnames == original_without_opnames, |
| 135 | status == Pass::Status::SuccessWithoutChange); |
| 136 | // Code except OpName instructions should be exactly the same. |
| 137 | EXPECT_EQ(expected_without_opnames, optimized_without_opnames); |
| 138 | // OpName instructions can be in different order, but the content must be |
| 139 | // the same. |
| 140 | EXPECT_EQ(expected_opnames, optimized_opnames); |
| 141 | } |
| 142 | }; |
| 143 | |
| 144 | using UnifyFrontEndConstantSingleTest = |
nothing calls this directly
no test coverage detected