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

Function TEST

test/opt/def_use_test.cpp:1205–1318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1203// clang-format on
1204
1205TEST(DefUseTest, OpSwitch) {
1206 // Because disassembler has basic type check for OpSwitch's selector, we
1207 // cannot use the DisassembleInst() in the above. Thus, this special spotcheck
1208 // test case.
1209
1210 const char original_text[] =
1211 // int64 f(int64 v) {
1212 // switch (v) {
1213 // case 1: break;
1214 // case -4294967296: break;
1215 // case 9223372036854775807: break;
1216 // default: break;
1217 // }
1218 // return v;
1219 // }
1220 " %1 = OpTypeInt 64 1 "
1221 " %3 = OpTypePointer Input %1 "
1222 " %2 = OpFunction %1 None %3 " // %3 is int64(int64)*
1223 " %4 = OpFunctionParameter %1 "
1224 " %5 = OpLabel "
1225 " %6 = OpLoad %1 %4 " // selector value
1226 " OpSelectionMerge %7 None "
1227 " OpSwitch %6 %8 "
1228 " 1 %9 " // 1
1229 " -4294967296 %10 " // -2^32
1230 " 9223372036854775807 %11 " // 2^63-1
1231 " %8 = OpLabel " // default
1232 " OpBranch %7 "
1233 " %9 = OpLabel "
1234 " OpBranch %7 "
1235 "%10 = OpLabel "
1236 " OpBranch %7 "
1237 "%11 = OpLabel "
1238 " OpBranch %7 "
1239 " %7 = OpLabel "
1240 " OpReturnValue %6 "
1241 " OpFunctionEnd";
1242
1243 std::unique_ptr<IRContext> context =
1244 BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, original_text,
1245 SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1246 ASSERT_NE(nullptr, context);
1247
1248 // Force a re-build of def-use manager.
1249 context->InvalidateAnalyses(IRContext::Analysis::kAnalysisDefUse);
1250 (void)context->get_def_use_mgr();
1251
1252 // Do a bunch replacements.
1253 context->ReplaceAllUsesWith(11, 7); // to existing id
1254 context->ReplaceAllUsesWith(10, 11); // to existing id
1255 context->ReplaceAllUsesWith(9, 10); // to existing id
1256
1257 // clang-format off
1258 const char modified_text[] =
1259 "%1 = OpTypeInt 64 1\n"
1260 "%3 = OpTypePointer Input %1\n"
1261 "%2 = OpFunction %1 None %3\n" // %3 is int64(int64)*
1262 "%4 = OpFunctionParameter %1\n"

Callers

nothing calls this directly

Calls 15

DisassembleModuleFunction · 0.85
CheckDefFunction · 0.85
NumUsesFunction · 0.85
GetUseOpcodesFunction · 0.85
CheckUseFunction · 0.85
InvalidateAnalysesMethod · 0.80
ReplaceAllUsesWithMethod · 0.80
backMethod · 0.80
AnalyzeInstDefUseMethod · 0.80
SetIdBoundMethod · 0.80
getMethod · 0.80
BuildModuleFunction · 0.70

Tested by

no test coverage detected