Provide friendly names for true and false
authorDavid Neto <dneto@google.com>
Wed, 11 Jan 2017 21:12:50 +0000 (16:12 -0500)
committerDavid Neto <dneto@google.com>
Wed, 11 Jan 2017 21:33:45 +0000 (16:33 -0500)
source/name_mapper.cpp
test/cpp_interface_test.cpp
test/name_mapper_test.cpp
test/opt/eliminate_dead_const_test.cpp
test/opt/fold_spec_const_op_composite_test.cpp
test/opt/freeze_spec_const_test.cpp

index 43412a3..eaf5e07 100644 (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]);
index 141e7a3..e492a63 100644 (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);
 }
index c201198..61b6ca8 100644 (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
index 92247e0..474a6ea 100644 (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",
index b9afeee..f5fa376 100644 (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",
               },
             },
 
index 0fd0fe4..98c973b 100644 (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))