From: David Neto Date: Thu, 13 Oct 2016 20:22:04 +0000 (-0400) Subject: Make friendly number-based names for OpConstant X-Git-Tag: upstream/2018.6~1009 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c935253c91c687ff3fe42bf9197b81c0b64bfa34;p=platform%2Fupstream%2FSPIRV-Tools.git Make friendly number-based names for OpConstant For example: %int_42 = OpConstant %int 42 %int_n42 = OpConstant %int -42 %float_3_14 = OpConstant %float 3.14 --- diff --git a/source/name_mapper.cpp b/source/name_mapper.cpp index df632e1..43412a3 100644 --- a/source/name_mapper.cpp +++ b/source/name_mapper.cpp @@ -25,6 +25,8 @@ #include "spirv-tools/libspirv.h" #include "spirv/1.1/spirv.h" +#include "parsed_operand.h" + namespace { // Converts a uint32_t to its string decimal representation. @@ -287,6 +289,16 @@ spv_result_t FriendlyNameMapper::ParseInstruction( // are a struct and then give the raw Id number. SaveName(result_id, std::string("_struct_") + to_string(result_id)); break; + case SpvOpConstant: { + std::ostringstream value; + EmitNumericLiteral(&value, inst, inst.operands[2]); + auto value_str = value.str(); + // Use 'n' to signify negative. Other invalid characters will be mapped + // to underscore. + for (auto& c : value_str) + if (c == '-') c = 'n'; + SaveName(result_id, NameForId(inst.type_id) + "_" + value_str); + } break; default: // If this instruction otherwise defines an Id, then save a mapping for // it. This is needed to ensure uniqueness in there is an OpName with diff --git a/source/name_mapper.h b/source/name_mapper.h index 89eb93e..12078b6 100644 --- a/source/name_mapper.h +++ b/source/name_mapper.h @@ -57,6 +57,7 @@ NameMapper GetTrivialNameMapper(); // - A struct type maps to "_struct_" followed by the raw Id number. That's // pretty simplistic, but workable. // - A built-in variable maps to its GLSL variable name. +// - Numeric literals in OpConstant map to a human-friendly name. class FriendlyNameMapper { public: // Construct a friendly name mapper, and determine friendly names for each diff --git a/test/binary_to_text_test.cpp b/test/binary_to_text_test.cpp index 9b97b3d..09d1abd 100644 --- a/test/binary_to_text_test.cpp +++ b/test/binary_to_text_test.cpp @@ -435,7 +435,7 @@ OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450 %uint = OpTypeInt 32 0 %_struct_2 = OpTypeStruct %uint %3 %4 %5 %6 %7 %8 %9 %10 -%11 = OpConstant %uint 42 +%uint_42 = OpConstant %uint 42 )"; EXPECT_THAT(EncodeAndDecodeSuccessfully( input, SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES), diff --git a/test/name_mapper_test.cpp b/test/name_mapper_test.cpp index 6c7755b..c201198 100644 --- a/test/name_mapper_test.cpp +++ b/test/name_mapper_test.cpp @@ -282,4 +282,57 @@ INSTANTIATE_TEST_CASE_P(DebugNameOverridesBuiltin, FriendlyNameTest, "%1 = OpVariable %2 Input", 1, "foo"}}), ); +INSTANTIATE_TEST_CASE_P( + SimpleIntegralConstants, FriendlyNameTest, + ::testing::ValuesIn(std::vector{ + {"%1 = OpTypeInt 32 0 %2 = OpConstant %1 0", 2, "uint_0"}, + {"%1 = OpTypeInt 32 0 %2 = OpConstant %1 1", 2, "uint_1"}, + {"%1 = OpTypeInt 32 0 %2 = OpConstant %1 2", 2, "uint_2"}, + {"%1 = OpTypeInt 32 0 %2 = OpConstant %1 9", 2, "uint_9"}, + {"%1 = OpTypeInt 32 0 %2 = OpConstant %1 42", 2, "uint_42"}, + {"%1 = OpTypeInt 32 1 %2 = OpConstant %1 0", 2, "int_0"}, + {"%1 = OpTypeInt 32 1 %2 = OpConstant %1 1", 2, "int_1"}, + {"%1 = OpTypeInt 32 1 %2 = OpConstant %1 2", 2, "int_2"}, + {"%1 = OpTypeInt 32 1 %2 = OpConstant %1 9", 2, "int_9"}, + {"%1 = OpTypeInt 32 1 %2 = OpConstant %1 42", 2, "int_42"}, + {"%1 = OpTypeInt 32 1 %2 = OpConstant %1 -42", 2, "int_n42"}, + // Exotic bit widths + {"%1 = OpTypeInt 33 0 %2 = OpConstant %1 0", 2, "u33_0"}, + {"%1 = OpTypeInt 33 1 %2 = OpConstant %1 10", 2, "i33_10"}, + {"%1 = OpTypeInt 33 1 %2 = OpConstant %1 -19", 2, "i33_n19"}, + }), ); + +INSTANTIATE_TEST_CASE_P( + SimpleFloatConstants, FriendlyNameTest, + ::testing::ValuesIn(std::vector{ + {"%1 = OpTypeFloat 16\n%2 = OpConstant %1 0x1.ff4p+16", 2, + "half_0x1_ff4p_16"}, + {"%1 = OpTypeFloat 16\n%2 = OpConstant %1 -0x1.d2cp-10", 2, + "half_n0x1_d2cpn10"}, + // 32-bit floats + {"%1 = OpTypeFloat 32\n%2 = OpConstant %1 -3.275", 2, "float_n3_275"}, + {"%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1.8p+128", 2, + "float_0x1_8p_128"}, // NaN + {"%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1.0002p+128", 2, + "float_n0x1_0002p_128"}, // NaN + {"%1 = OpTypeFloat 32\n%2 = OpConstant %1 0x1p+128", 2, + "float_0x1p_128"}, // Inf + {"%1 = OpTypeFloat 32\n%2 = OpConstant %1 -0x1p+128", 2, + "float_n0x1p_128"}, // -Inf + // 64-bit floats + {"%1 = OpTypeFloat 64\n%2 = OpConstant %1 -3.275", 2, "double_n3_275"}, + {"%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1.ffffffffffffap-1023", 2, + "double_0x1_ffffffffffffapn1023"}, // small normal + {"%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1.ffffffffffffap-1023", 2, + "double_n0x1_ffffffffffffapn1023"}, + {"%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1.8p+1024", 2, + "double_0x1_8p_1024"}, // NaN + {"%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1.0002p+1024", 2, + "double_n0x1_0002p_1024"}, // NaN + {"%1 = OpTypeFloat 64\n%2 = OpConstant %1 0x1p+1024", 2, + "double_0x1p_1024"}, // Inf + {"%1 = OpTypeFloat 64\n%2 = OpConstant %1 -0x1p+1024", 2, + "double_n0x1p_1024"}, // -Inf + }), ); + } // anonymous namespace diff --git a/test/opt/eliminate_dead_const_test.cpp b/test/opt/eliminate_dead_const_test.cpp index 490132c..92247e0 100644 --- a/test/opt/eliminate_dead_const_test.cpp +++ b/test/opt/eliminate_dead_const_test.cpp @@ -98,16 +98,16 @@ TEST_F(EliminateDeadConstantBasicTest, BasicNoneDeadConstants) { "%14 = OpConstantFalse %bool", "%int = OpTypeInt 32 1", "%_ptr_Function_int = OpTypePointer Function %int", - "%17 = OpConstant %int 1", + "%int_1 = OpConstant %int 1", "%uint = OpTypeInt 32 0", "%_ptr_Function_uint = OpTypePointer Function %uint", - "%20 = OpConstant %uint 2", + "%uint_2 = OpConstant %uint 2", "%float = OpTypeFloat 32", "%_ptr_Function_float = OpTypePointer Function %float", - "%23 = OpConstant %float 3.14", + "%float_3_14 = OpConstant %float 3.14", "%double = OpTypeFloat 64", "%_ptr_Function_double = OpTypePointer Function %double", - "%26 = OpConstant %double 3.14159265358979", + "%double_3_14159265358979 = OpConstant %double 3.14159265358979", "%main = OpFunction %void None %10", "%27 = OpLabel", "%btv = OpVariable %_ptr_Function_bool Function", @@ -118,10 +118,10 @@ TEST_F(EliminateDeadConstantBasicTest, BasicNoneDeadConstants) { "%dv = OpVariable %_ptr_Function_double Function", "OpStore %btv %13", "OpStore %bfv %14", - "OpStore %iv %17", - "OpStore %uv %20", - "OpStore %fv %23", - "OpStore %dv %26", + "OpStore %iv %int_1", + "OpStore %uv %uint_2", + "OpStore %fv %float_3_14", + "OpStore %dv %double_3_14159265358979", "OpReturn", "OpFunctionEnd", // clang-format on diff --git a/test/opt/fold_spec_const_op_composite_test.cpp b/test/opt/fold_spec_const_op_composite_test.cpp index b84bf26..b9afeee 100644 --- a/test/opt/fold_spec_const_op_composite_test.cpp +++ b/test/opt/fold_spec_const_op_composite_test.cpp @@ -483,15 +483,15 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%59 = OpConstant %int 1", - "%60 = OpConstant %int 1", - "%spec_int_one_vec = OpConstantComposite %v2int %59 %60", - "%62 = OpConstant %int 0", - "%63 = OpConstant %int 0", - "%spec_int_zero_vec = OpConstantComposite %v2int %62 %63", - "%65 = OpConstant %int 0", - "%66 = OpConstant %int 0", - "%spec_int_from_null = OpConstantComposite %v2int %65 %66", + "%int_1 = OpConstant %int 1", + "%int_1_0 = OpConstant %int 1", + "%spec_int_one_vec = OpConstantComposite %v2int %int_1 %int_1_0", + "%int_0 = OpConstant %int 0", + "%int_0_0 = OpConstant %int 0", + "%spec_int_zero_vec = OpConstantComposite %v2int %int_0 %int_0_0", + "%int_0_1 = OpConstant %int 0", + "%int_0_2 = OpConstant %int 0", + "%spec_int_from_null = OpConstantComposite %v2int %int_0_1 %int_0_2", }, }, @@ -505,15 +505,15 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%59 = OpConstant %int 1", - "%60 = OpConstant %int 1", - "%spec_int_one_vec = OpConstantComposite %v2int %59 %60", - "%62 = OpConstant %int 0", - "%63 = OpConstant %int 0", - "%spec_int_zero_vec = OpConstantComposite %v2int %62 %63", - "%65 = OpConstant %int 0", - "%66 = OpConstant %int 0", - "%spec_int_from_null = OpConstantComposite %v2int %65 %66", + "%int_1 = OpConstant %int 1", + "%int_1_0 = OpConstant %int 1", + "%spec_int_one_vec = OpConstantComposite %v2int %int_1 %int_1_0", + "%int_0 = OpConstant %int 0", + "%int_0_0 = OpConstant %int 0", + "%spec_int_zero_vec = OpConstantComposite %v2int %int_0 %int_0_0", + "%int_0_1 = OpConstant %int 0", + "%int_0_2 = OpConstant %int 0", + "%spec_int_from_null = OpConstantComposite %v2int %int_0_1 %int_0_2", }, }, @@ -527,15 +527,15 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%59 = OpConstant %uint 1", - "%60 = OpConstant %uint 1", - "%spec_uint_one_vec = OpConstantComposite %v2uint %59 %60", - "%62 = OpConstant %uint 0", - "%63 = OpConstant %uint 0", - "%spec_uint_zero_vec = OpConstantComposite %v2uint %62 %63", - "%65 = OpConstant %uint 0", - "%66 = OpConstant %uint 0", - "%spec_uint_from_null = OpConstantComposite %v2uint %65 %66", + "%uint_1 = OpConstant %uint 1", + "%uint_1_0 = OpConstant %uint 1", + "%spec_uint_one_vec = OpConstantComposite %v2uint %uint_1 %uint_1_0", + "%uint_0 = OpConstant %uint 0", + "%uint_0_0 = OpConstant %uint 0", + "%spec_uint_zero_vec = OpConstantComposite %v2uint %uint_0 %uint_0_0", + "%uint_0_1 = OpConstant %uint 0", + "%uint_0_2 = OpConstant %uint 0", + "%spec_uint_from_null = OpConstantComposite %v2uint %uint_0_1 %uint_0_2", }, }, @@ -549,15 +549,15 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%59 = OpConstant %uint 1", - "%60 = OpConstant %uint 1", - "%spec_uint_one_vec = OpConstantComposite %v2uint %59 %60", - "%62 = OpConstant %uint 0", - "%63 = OpConstant %uint 0", - "%spec_uint_zero_vec = OpConstantComposite %v2uint %62 %63", - "%65 = OpConstant %uint 0", - "%66 = OpConstant %uint 0", - "%spec_uint_from_null = OpConstantComposite %v2uint %65 %66", + "%uint_1 = OpConstant %uint 1", + "%uint_1_0 = OpConstant %uint 1", + "%spec_uint_one_vec = OpConstantComposite %v2uint %uint_1 %uint_1_0", + "%uint_0 = OpConstant %uint 0", + "%uint_0_0 = OpConstant %uint 0", + "%spec_uint_zero_vec = OpConstantComposite %v2uint %uint_0 %uint_0_0", + "%uint_0_1 = OpConstant %uint 0", + "%uint_0_2 = OpConstant %uint 0", + "%spec_uint_from_null = OpConstantComposite %v2uint %uint_0_1 %uint_0_2", }, }, // clang-format on @@ -834,15 +834,15 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%59 = OpConstant %int -1", - "%60 = OpConstant %int -1", - "%v2int_minus_1 = OpConstantComposite %v2int %59 %60", - "%62 = OpConstant %int -2", - "%63 = OpConstant %int -2", - "%v2int_minus_2 = OpConstantComposite %v2int %62 %63", - "%65 = OpConstant %int 0", - "%66 = OpConstant %int 0", - "%v2int_neg_null = OpConstantComposite %v2int %65 %66", + "%int_n1 = OpConstant %int -1", + "%int_n1_0 = OpConstant %int -1", + "%v2int_minus_1 = OpConstantComposite %v2int %int_n1 %int_n1_0", + "%int_n2 = OpConstant %int -2", + "%int_n2_0 = OpConstant %int -2", + "%v2int_minus_2 = OpConstantComposite %v2int %int_n2 %int_n2_0", + "%int_0 = OpConstant %int 0", + "%int_0_0 = OpConstant %int 0", + "%v2int_neg_null = OpConstantComposite %v2int %int_0 %int_0_0", }, }, // vector integer (including null vetors) add, sub, div, mul @@ -863,37 +863,37 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%66 = OpConstant %int 5", - "%67 = OpConstant %int 5", - "%spec_v2int_iadd = OpConstantComposite %v2int %66 %67", - "%69 = OpConstant %int -4", - "%70 = OpConstant %int -4", - "%spec_v2int_isub = OpConstantComposite %v2int %69 %70", - "%72 = OpConstant %int -2", - "%73 = OpConstant %int -2", - "%spec_v2int_sdiv = OpConstantComposite %v2int %72 %73", - "%75 = OpConstant %int -6", - "%76 = OpConstant %int -6", - "%spec_v2int_imul = OpConstantComposite %v2int %75 %76", - "%78 = OpConstant %int -6", - "%79 = OpConstant %int -6", - "%spec_v2int_iadd_null = OpConstantComposite %v2int %78 %79", + "%int_5 = OpConstant %int 5", + "%int_5_0 = OpConstant %int 5", + "%spec_v2int_iadd = OpConstantComposite %v2int %int_5 %int_5_0", + "%int_n4 = OpConstant %int -4", + "%int_n4_0 = OpConstant %int -4", + "%spec_v2int_isub = OpConstantComposite %v2int %int_n4 %int_n4_0", + "%int_n2 = OpConstant %int -2", + "%int_n2_0 = OpConstant %int -2", + "%spec_v2int_sdiv = OpConstantComposite %v2int %int_n2 %int_n2_0", + "%int_n6 = OpConstant %int -6", + "%int_n6_0 = OpConstant %int -6", + "%spec_v2int_imul = OpConstantComposite %v2int %int_n6 %int_n6_0", + "%int_n6_1 = OpConstant %int -6", + "%int_n6_2 = OpConstant %int -6", + "%spec_v2int_iadd_null = OpConstantComposite %v2int %int_n6_1 %int_n6_2", - "%81 = OpConstant %uint 5", - "%82 = OpConstant %uint 5", - "%spec_v2uint_iadd = OpConstantComposite %v2uint %81 %82", - "%84 = OpConstant %uint 4294967292", - "%85 = OpConstant %uint 4294967292", - "%spec_v2uint_isub = OpConstantComposite %v2uint %84 %85", - "%87 = OpConstant %uint 1431655764", - "%88 = OpConstant %uint 1431655764", - "%spec_v2uint_udiv = OpConstantComposite %v2uint %87 %88", - "%90 = OpConstant %uint 2863311528", - "%91 = OpConstant %uint 2863311528", - "%spec_v2uint_imul = OpConstantComposite %v2uint %90 %91", - "%93 = OpConstant %uint 2863311528", - "%94 = OpConstant %uint 2863311528", - "%spec_v2uint_isub_null = OpConstantComposite %v2uint %93 %94", + "%uint_5 = OpConstant %uint 5", + "%uint_5_0 = OpConstant %uint 5", + "%spec_v2uint_iadd = OpConstantComposite %v2uint %uint_5 %uint_5_0", + "%uint_4294967292 = OpConstant %uint 4294967292", + "%uint_4294967292_0 = OpConstant %uint 4294967292", + "%spec_v2uint_isub = OpConstantComposite %v2uint %uint_4294967292 %uint_4294967292_0", + "%uint_1431655764 = OpConstant %uint 1431655764", + "%uint_1431655764_0 = OpConstant %uint 1431655764", + "%spec_v2uint_udiv = OpConstantComposite %v2uint %uint_1431655764 %uint_1431655764_0", + "%uint_2863311528 = OpConstant %uint 2863311528", + "%uint_2863311528_0 = OpConstant %uint 2863311528", + "%spec_v2uint_imul = OpConstantComposite %v2uint %uint_2863311528 %uint_2863311528_0", + "%uint_2863311528_1 = OpConstant %uint 2863311528", + "%uint_2863311528_2 = OpConstant %uint 2863311528", + "%spec_v2uint_isub_null = OpConstantComposite %v2uint %uint_2863311528_1 %uint_2863311528_2", }, }, // vector integer rem, mod @@ -936,35 +936,35 @@ INSTANTIATE_TEST_CASE_P( "%v2int_minus_3 = OpConstantComposite %v2int %int_minus_3 %int_minus_3", // srem - "%73 = OpConstant %int 1", - "%74 = OpConstant %int 1", - "%7_srem_3 = OpConstantComposite %v2int %73 %74", - "%76 = OpConstant %int -1", - "%77 = OpConstant %int -1", - "%minus_7_srem_3 = OpConstantComposite %v2int %76 %77", - "%79 = OpConstant %int 1", - "%80 = OpConstant %int 1", - "%7_srem_minus_3 = OpConstantComposite %v2int %79 %80", - "%82 = OpConstant %int -1", - "%83 = OpConstant %int -1", - "%minus_7_srem_minus_3 = OpConstantComposite %v2int %82 %83", + "%int_1 = OpConstant %int 1", + "%int_1_0 = OpConstant %int 1", + "%7_srem_3 = OpConstantComposite %v2int %int_1 %int_1_0", + "%int_n1 = OpConstant %int -1", + "%int_n1_0 = OpConstant %int -1", + "%minus_7_srem_3 = OpConstantComposite %v2int %int_n1 %int_n1_0", + "%int_1_1 = OpConstant %int 1", + "%int_1_2 = OpConstant %int 1", + "%7_srem_minus_3 = OpConstantComposite %v2int %int_1_1 %int_1_2", + "%int_n1_1 = OpConstant %int -1", + "%int_n1_2 = OpConstant %int -1", + "%minus_7_srem_minus_3 = OpConstantComposite %v2int %int_n1_1 %int_n1_2", // smod - "%85 = OpConstant %int 1", - "%86 = OpConstant %int 1", - "%7_smod_3 = OpConstantComposite %v2int %85 %86", - "%88 = OpConstant %int 2", - "%89 = OpConstant %int 2", - "%minus_7_smod_3 = OpConstantComposite %v2int %88 %89", - "%91 = OpConstant %int -2", - "%92 = OpConstant %int -2", - "%7_smod_minus_3 = OpConstantComposite %v2int %91 %92", - "%94 = OpConstant %int -1", - "%95 = OpConstant %int -1", - "%minus_7_smod_minus_3 = OpConstantComposite %v2int %94 %95", + "%int_1_3 = OpConstant %int 1", + "%int_1_4 = OpConstant %int 1", + "%7_smod_3 = OpConstantComposite %v2int %int_1_3 %int_1_4", + "%int_2 = OpConstant %int 2", + "%int_2_0 = OpConstant %int 2", + "%minus_7_smod_3 = OpConstantComposite %v2int %int_2 %int_2_0", + "%int_n2 = OpConstant %int -2", + "%int_n2_0 = OpConstant %int -2", + "%7_smod_minus_3 = OpConstantComposite %v2int %int_n2 %int_n2_0", + "%int_n1_3 = OpConstant %int -1", + "%int_n1_4 = OpConstant %int -1", + "%minus_7_smod_minus_3 = OpConstantComposite %v2int %int_n1_3 %int_n1_4", // umod - "%97 = OpConstant %uint 1", - "%98 = OpConstant %uint 1", - "%7_umod_3 = OpConstantComposite %v2uint %97 %98", + "%uint_1 = OpConstant %uint 1", + "%uint_1_0 = OpConstant %uint 1", + "%7_umod_3 = OpConstantComposite %v2uint %uint_1 %uint_1_0", }, }, // vector integer bitwise, shift @@ -983,27 +983,27 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%64 = OpConstant %int 2", - "%65 = OpConstant %int 2", - "%xor_1_3 = OpConstantComposite %v2int %64 %65", - "%67 = OpConstant %int 0", - "%68 = OpConstant %int 0", - "%and_1_2 = OpConstantComposite %v2int %67 %68", - "%70 = OpConstant %int 3", - "%71 = OpConstant %int 3", - "%or_1_2 = OpConstantComposite %v2int %70 %71", + "%int_2 = OpConstant %int 2", + "%int_2_0 = OpConstant %int 2", + "%xor_1_3 = OpConstantComposite %v2int %int_2 %int_2_0", + "%int_0 = OpConstant %int 0", + "%int_0_0 = OpConstant %int 0", + "%and_1_2 = OpConstantComposite %v2int %int_0 %int_0_0", + "%int_3 = OpConstant %int 3", + "%int_3_0 = OpConstant %int 3", + "%or_1_2 = OpConstantComposite %v2int %int_3 %int_3_0", "%unsigned_31 = OpConstant %uint 31", "%v2unsigned_31 = OpConstantComposite %v2uint %unsigned_31 %unsigned_31", - "%73 = OpConstant %uint 2147483648", - "%74 = OpConstant %uint 2147483648", - "%unsigned_left_shift_max = OpConstantComposite %v2uint %73 %74", - "%76 = OpConstant %uint 1", - "%77 = OpConstant %uint 1", - "%unsigned_right_shift_logical = OpConstantComposite %v2uint %76 %77", - "%79 = OpConstant %int -1", - "%80 = OpConstant %int -1", - "%signed_right_shift_arithmetic = OpConstantComposite %v2int %79 %80", + "%uint_2147483648 = OpConstant %uint 2147483648", + "%uint_2147483648_0 = OpConstant %uint 2147483648", + "%unsigned_left_shift_max = OpConstantComposite %v2uint %uint_2147483648 %uint_2147483648_0", + "%uint_1 = OpConstant %uint 1", + "%uint_1_0 = OpConstant %uint 1", + "%unsigned_right_shift_logical = OpConstantComposite %v2uint %uint_1 %uint_1_0", + "%int_n1 = OpConstant %int -1", + "%int_n1_0 = OpConstant %int -1", + "%signed_right_shift_arithmetic = OpConstantComposite %v2int %int_n1 %int_n1_0", }, }, // Skip folding if any vector operands or components of the operands @@ -1375,9 +1375,9 @@ INSTANTIATE_TEST_CASE_P( "%spec_int_19 = OpConstant %int -1", "%spec_int_20 = OpConstant %int 101", "%used_vec_a = OpConstantComposite %v2int %spec_int_18 %spec_int_19", - "%104 = OpConstant %int 10201", - "%105 = OpConstant %int 1", - "%used_vec_b = OpConstantComposite %v2int %104 %105", + "%int_10201 = OpConstant %int 10201", + "%int_1 = OpConstant %int 1", + "%used_vec_b = OpConstantComposite %v2int %int_10201 %int_1", "%spec_int_21 = OpConstant %int 10201", "%array = OpConstantComposite %type_arr_int_4 %spec_int_20 %spec_int_20 %spec_int_21 %spec_int_21", "%spec_int_22 = OpSpecConstant %int 123", diff --git a/test/opt/freeze_spec_const_test.cpp b/test/opt/freeze_spec_const_test.cpp index 6c09493..0fd0fe4 100644 --- a/test/opt/freeze_spec_const_test.cpp +++ b/test/opt/freeze_spec_const_test.cpp @@ -51,13 +51,13 @@ INSTANTIATE_TEST_CASE_P( // Type declaration, original spec constant definition, expected frozen // spec constants. {"%int = OpTypeInt 32 1", "%2 = OpSpecConstant %int 1", - "%2 = OpConstant %int 1"}, + "%int_1 = OpConstant %int 1"}, {"%uint = OpTypeInt 32 0", "%2 = OpSpecConstant %uint 1", - "%2 = OpConstant %uint 1"}, + "%uint_1 = OpConstant %uint 1"}, {"%float = OpTypeFloat 32", "%2 = OpSpecConstant %float 3.14", - "%2 = OpConstant %float 3.14"}, + "%float_3_14 = OpConstant %float 3.14"}, {"%double = OpTypeFloat 64", "%2 = OpSpecConstant %double 3.1415926", - "%2 = OpConstant %double 3.1415926"}, + "%double_3_1415926 = OpConstant %double 3.1415926"}, {"%bool = OpTypeBool", "%2 = OpSpecConstantTrue %bool", "%2 = OpConstantTrue %bool"}, {"%bool = OpTypeBool", "%2 = OpSpecConstantFalse %bool", @@ -103,12 +103,16 @@ TEST_F(FreezeSpecConstantValueRemoveDecorationTest, std::string expected_disassembly = SelectiveJoin(text, [](const char* line) { return std::string(line).find("SpecId") != std::string::npos; }); - std::vector> opcode_replacement_pairs = { - {" OpSpecConstant ", " OpConstant "}, + std::vector> replacement_pairs = { + {"%3 = OpSpecConstant %int 3", "%int_3 = OpConstant %int 3"}, + {"%4 = OpSpecConstant %float 3.14", + "%float_3_14 = OpConstant %float 3.14"}, + {"%5 = OpSpecConstant %double 3.14159265358979", + "%double_3_14159265358979 = OpConstant %double 3.14159265358979"}, {" OpSpecConstantTrue ", " OpConstantTrue "}, {" OpSpecConstantFalse ", " OpConstantFalse "}, }; - for (auto& p : opcode_replacement_pairs) { + for (auto& p : replacement_pairs) { EXPECT_TRUE(FindAndReplace(&expected_disassembly, p.first, p.second)) << "text:\n" << expected_disassembly << "\n" diff --git a/test/opt/ir_loader_test.cpp b/test/opt/ir_loader_test.cpp index 854115a..4e40e70 100644 --- a/test/opt/ir_loader_test.cpp +++ b/test/opt/ir_loader_test.cpp @@ -61,14 +61,14 @@ TEST(IrBuilder, RoundTrip) { "%int = OpTypeInt 32 1\n" "%_ptr_Function_int = OpTypePointer Function %int\n" "%12 = OpTypeFunction %int %_ptr_Function_int %_ptr_Function_int\n" - "%13 = OpConstant %int 1\n" - "%14 = OpConstant %int 2\n" + "%int_1 = OpConstant %int 1\n" + "%int_2 = OpConstant %int 2\n" "%main = OpFunction %void None %9\n" "%15 = OpLabel\n" "%param = OpVariable %_ptr_Function_int Function\n" "%param_0 = OpVariable %_ptr_Function_int Function\n" - "OpStore %param %13\n" - "OpStore %param_0 %14\n" + "OpStore %param %int_1\n" + "OpStore %param_0 %int_2\n" "%16 = OpFunctionCall %int %add_i1_i1_ %param %param_0\n" "OpReturn\n" "OpFunctionEnd\n" @@ -159,15 +159,15 @@ TEST(IrBuilder, LocalGlobalVariables) { "%12 = OpTypeFunction %float\n" "%_ptr_Private_float = OpTypePointer Private %float\n" "%gv1 = OpVariable %_ptr_Private_float Private\n" - "%14 = OpConstant %float 10\n" + "%float_10 = OpConstant %float 10\n" "%gv2 = OpVariable %_ptr_Private_float Private\n" - "%15 = OpConstant %float 100\n" + "%float_100 = OpConstant %float 100\n" "%_ptr_Function_float = OpTypePointer Function %float\n" "%main = OpFunction %void None %10\n" "%17 = OpLabel\n" "%lv1_0 = OpVariable %_ptr_Function_float Function\n" - "OpStore %gv1 %14\n" - "OpStore %gv2 %15\n" + "OpStore %gv1 %float_10\n" + "OpStore %gv2 %float_100\n" "%18 = OpLoad %float %gv1\n" "%19 = OpLoad %float %gv2\n" "%20 = OpFSub %float %18 %19\n" @@ -204,7 +204,7 @@ TEST(IrBuilder, OpUndefOutsideFunction) { "%uint = OpTypeInt 32 0\n" "%float = OpTypeFloat 32\n" "%4 = OpUndef %int\n" - "%5 = OpConstant %int 10\n" + "%int_10 = OpConstant %int 10\n" "%6 = OpUndef %uint\n" "%bool = OpTypeBool\n" "%8 = OpUndef %float\n" diff --git a/test/opt/set_spec_const_default_value_test.cpp b/test/opt/set_spec_const_default_value_test.cpp index 0d4a1d2..a6eaab9 100644 --- a/test/opt/set_spec_const_default_value_test.cpp +++ b/test/opt/set_spec_const_default_value_test.cpp @@ -473,13 +473,13 @@ INSTANTIATE_TEST_CASE_P( // code "OpDecorate %1 SpecId 100\n" "%int = OpTypeInt 32 1\n" - "%1 = OpConstant %int 101\n", + "%int_101 = OpConstant %int 101\n", // default values SpecIdToValueStrMap{{100, "0x7fffffff"}}, // expected "OpDecorate %1 SpecId 100\n" "%int = OpTypeInt 32 1\n" - "%1 = OpConstant %int 101\n", + "%int_101 = OpConstant %int 101\n", }, // 3. Do nothing when SpecId decoration is not attached to a // OpSpecConstant{|True|False} instruction. @@ -527,7 +527,7 @@ INSTANTIATE_TEST_CASE_P( "%1 = OpDecorationGroup\n" "OpGroupDecorate %1 %2\n" "%int = OpTypeInt 32 1\n" - "%2 = OpConstant %int 100\n", + "%int_100 = OpConstant %int 100\n", // default values SpecIdToValueStrMap{{100, "0xffffffff"}}, // expected @@ -535,7 +535,7 @@ INSTANTIATE_TEST_CASE_P( "%1 = OpDecorationGroup\n" "OpGroupDecorate %1 %2\n" "%int = OpTypeInt 32 1\n" - "%2 = OpConstant %int 100\n", + "%int_100 = OpConstant %int 100\n", }, }));