Provide friendly names for true and false

This commit is contained in:
David Neto 2017-01-11 16:12:50 -05:00
parent d1868b9361
commit 545a6c1dc3
6 changed files with 42 additions and 29 deletions

View File

@ -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]);

View File

@ -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);
}

View File

@ -335,4 +335,11 @@ INSTANTIATE_TEST_CASE_P(
"double_n0x1p_1024"}, // -Inf
}), );
INSTANTIATE_TEST_CASE_P(
BooleanConstants, FriendlyNameTest,
::testing::ValuesIn(std::vector<NameIdCase>{
{"%1 = OpTypeBool\n%2 = OpConstantTrue %1", 2, "true"},
{"%1 = OpTypeBool\n%2 = OpConstantFalse %1", 2, "false"},
}), );
} // anonymous namespace

View File

@ -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",

View File

@ -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",
},
},

View File

@ -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))