From 545a6c1dc3cb6e346cae417fb729a1ebced10fe8 Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 11 Jan 2017 16:12:50 -0500 Subject: [PATCH] Provide friendly names for true and false --- source/name_mapper.cpp | 6 +++++ test/cpp_interface_test.cpp | 2 +- test/name_mapper_test.cpp | 7 +++++ test/opt/eliminate_dead_const_test.cpp | 12 ++++----- test/opt/fold_spec_const_op_composite_test.cpp | 36 +++++++++++++------------- test/opt/freeze_spec_const_test.cpp | 8 +++--- 6 files changed, 42 insertions(+), 29 deletions(-) diff --git a/source/name_mapper.cpp b/source/name_mapper.cpp index 43412a3..eaf5e07 100644 --- a/source/name_mapper.cpp +++ b/source/name_mapper.cpp @@ -289,6 +289,12 @@ 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 SpvOpConstantTrue: + SaveName(result_id, "true"); + break; + case SpvOpConstantFalse: + SaveName(result_id, "false"); + break; case SpvOpConstant: { std::ostringstream value; EmitNumericLiteral(&value, inst, inst.operands[2]); diff --git a/test/cpp_interface_test.cpp b/test/cpp_interface_test.cpp index 141e7a3..e492a63 100644 --- a/test/cpp_interface_test.cpp +++ b/test/cpp_interface_test.cpp @@ -263,7 +263,7 @@ TEST(CppInterface, OptimizeMulitplePasses) { const char* expected_text = "%bool = OpTypeBool\n" - "%1 = OpConstantTrue %bool\n"; + "%true = OpConstantTrue %bool\n"; CheckOptimization(original_text, expected_text, o); } diff --git a/test/name_mapper_test.cpp b/test/name_mapper_test.cpp index c201198..61b6ca8 100644 --- a/test/name_mapper_test.cpp +++ b/test/name_mapper_test.cpp @@ -335,4 +335,11 @@ INSTANTIATE_TEST_CASE_P( "double_n0x1p_1024"}, // -Inf }), ); +INSTANTIATE_TEST_CASE_P( + BooleanConstants, FriendlyNameTest, + ::testing::ValuesIn(std::vector{ + {"%1 = OpTypeBool\n%2 = OpConstantTrue %1", 2, "true"}, + {"%1 = OpTypeBool\n%2 = OpConstantFalse %1", 2, "false"}, + }), ); + } // anonymous namespace diff --git a/test/opt/eliminate_dead_const_test.cpp b/test/opt/eliminate_dead_const_test.cpp index 92247e0..474a6ea 100644 --- a/test/opt/eliminate_dead_const_test.cpp +++ b/test/opt/eliminate_dead_const_test.cpp @@ -40,8 +40,8 @@ TEST_F(EliminateDeadConstantBasicTest, BasicAllDeadConstants) { "%void = OpTypeVoid", "%4 = OpTypeFunction %void", "%bool = OpTypeBool", - "%6 = OpConstantTrue %bool", - "%7 = OpConstantFalse %bool", + "%true = OpConstantTrue %bool", + "%false = OpConstantFalse %bool", "%int = OpTypeInt 32 1", "%9 = OpConstant %int 1", "%uint = OpTypeInt 32 0", @@ -94,8 +94,8 @@ TEST_F(EliminateDeadConstantBasicTest, BasicNoneDeadConstants) { "%10 = OpTypeFunction %void", "%bool = OpTypeBool", "%_ptr_Function_bool = OpTypePointer Function %bool", - "%13 = OpConstantTrue %bool", - "%14 = OpConstantFalse %bool", + "%true = OpConstantTrue %bool", + "%false = OpConstantFalse %bool", "%int = OpTypeInt 32 1", "%_ptr_Function_int = OpTypePointer Function %int", "%int_1 = OpConstant %int 1", @@ -116,8 +116,8 @@ TEST_F(EliminateDeadConstantBasicTest, BasicNoneDeadConstants) { "%uv = OpVariable %_ptr_Function_uint Function", "%fv = OpVariable %_ptr_Function_float Function", "%dv = OpVariable %_ptr_Function_double Function", - "OpStore %btv %13", - "OpStore %bfv %14", + "OpStore %btv %true", + "OpStore %bfv %false", "OpStore %iv %int_1", "OpStore %uv %uint_2", "OpStore %fv %float_3_14", diff --git a/test/opt/fold_spec_const_op_composite_test.cpp b/test/opt/fold_spec_const_op_composite_test.cpp index b9afeee..f5fa376 100644 --- a/test/opt/fold_spec_const_op_composite_test.cpp +++ b/test/opt/fold_spec_const_op_composite_test.cpp @@ -439,15 +439,15 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%59 = OpConstantTrue %bool", - "%60 = OpConstantTrue %bool", - "%spec_bool_t_vec = OpConstantComposite %v2bool %59 %60", - "%62 = OpConstantFalse %bool", - "%63 = OpConstantFalse %bool", - "%spec_bool_f_vec = OpConstantComposite %v2bool %62 %63", - "%65 = OpConstantFalse %bool", - "%66 = OpConstantFalse %bool", - "%spec_bool_from_null = OpConstantComposite %v2bool %65 %66", + "%true = OpConstantTrue %bool", + "%true_0 = OpConstantTrue %bool", + "%spec_bool_t_vec = OpConstantComposite %v2bool %true %true_0", + "%false = OpConstantFalse %bool", + "%false_0 = OpConstantFalse %bool", + "%spec_bool_f_vec = OpConstantComposite %v2bool %false %false_0", + "%false_1 = OpConstantFalse %bool", + "%false_2 = OpConstantFalse %bool", + "%spec_bool_from_null = OpConstantComposite %v2bool %false_1 %false_2", }, }, @@ -461,15 +461,15 @@ INSTANTIATE_TEST_CASE_P( }, // expected { - "%59 = OpConstantTrue %bool", - "%60 = OpConstantTrue %bool", - "%spec_bool_t_vec = OpConstantComposite %v2bool %59 %60", - "%62 = OpConstantFalse %bool", - "%63 = OpConstantFalse %bool", - "%spec_bool_f_vec = OpConstantComposite %v2bool %62 %63", - "%65 = OpConstantFalse %bool", - "%66 = OpConstantFalse %bool", - "%spec_bool_from_null = OpConstantComposite %v2bool %65 %66", + "%true = OpConstantTrue %bool", + "%true_0 = OpConstantTrue %bool", + "%spec_bool_t_vec = OpConstantComposite %v2bool %true %true_0", + "%false = OpConstantFalse %bool", + "%false_0 = OpConstantFalse %bool", + "%spec_bool_f_vec = OpConstantComposite %v2bool %false %false_0", + "%false_1 = OpConstantFalse %bool", + "%false_2 = OpConstantFalse %bool", + "%spec_bool_from_null = OpConstantComposite %v2bool %false_1 %false_2", }, }, diff --git a/test/opt/freeze_spec_const_test.cpp b/test/opt/freeze_spec_const_test.cpp index 0fd0fe4..98c973b 100644 --- a/test/opt/freeze_spec_const_test.cpp +++ b/test/opt/freeze_spec_const_test.cpp @@ -59,9 +59,9 @@ INSTANTIATE_TEST_CASE_P( {"%double = OpTypeFloat 64", "%2 = OpSpecConstant %double 3.1415926", "%double_3_1415926 = OpConstant %double 3.1415926"}, {"%bool = OpTypeBool", "%2 = OpSpecConstantTrue %bool", - "%2 = OpConstantTrue %bool"}, + "%true = OpConstantTrue %bool"}, {"%bool = OpTypeBool", "%2 = OpSpecConstantFalse %bool", - "%2 = OpConstantFalse %bool"}, + "%false = OpConstantFalse %bool"}, }))); using FreezeSpecConstantValueRemoveDecorationTest = PassTest<::testing::Test>; @@ -109,8 +109,8 @@ TEST_F(FreezeSpecConstantValueRemoveDecorationTest, "%float_3_14 = OpConstant %float 3.14"}, {"%5 = OpSpecConstant %double 3.14159265358979", "%double_3_14159265358979 = OpConstant %double 3.14159265358979"}, - {" OpSpecConstantTrue ", " OpConstantTrue "}, - {" OpSpecConstantFalse ", " OpConstantFalse "}, + {"%6 = OpSpecConstantTrue ", "%true = OpConstantTrue "}, + {"%13 = OpSpecConstantFalse ", "%false = OpConstantFalse "}, }; for (auto& p : replacement_pairs) { EXPECT_TRUE(FindAndReplace(&expected_disassembly, p.first, p.second)) -- 2.7.4