[llvm] r307236 - Simplify InstrProfRecord tests, eliminating named temporaries in favor of braced init args

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 5 22:19:17 PDT 2017


Author: dblaikie
Date: Wed Jul  5 22:19:17 2017
New Revision: 307236

URL: http://llvm.org/viewvc/llvm-project?rev=307236&view=rev
Log:
Simplify InstrProfRecord tests, eliminating named temporaries in favor of braced init args

This will also simplify an API transition and class renaming coming
soon.

Modified:
    llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
    llvm/trunk/unittests/ProfileData/InstrProfTest.cpp

Modified: llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=307236&r1=307235&r2=307236&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp Wed Jul  5 22:19:17 2017
@@ -309,8 +309,7 @@ TEST_P(CoverageMappingTest, correct_dese
 }
 
 TEST_P(CoverageMappingTest, load_coverage_for_more_than_two_files) {
-  InstrProfRecord Record("func", 0x1234, {0});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {0}}));
 
   const char *FileNames[] = {"bar", "baz", "foo"};
   static const unsigned N = array_lengthof(FileNames);
@@ -331,18 +330,15 @@ TEST_P(CoverageMappingTest, load_coverag
 }
 
 TEST_P(CoverageMappingTest, load_coverage_with_bogus_function_name) {
-  InstrProfRecord RecordFunc1("", 0x1234, {10});
-  NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
+  NoError(ProfileWriter.addRecord({"", 0x1234, {10}}));
   startFunction("", 0x1234);
   addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
   ErrorEquals(coveragemap_error::malformed, loadCoverageMapping());
 }
 
 TEST_P(CoverageMappingTest, load_coverage_for_several_functions) {
-  InstrProfRecord RecordFunc1("func1", 0x1234, {10});
-  NoError(ProfileWriter.addRecord(std::move(RecordFunc1)));
-  InstrProfRecord RecordFunc2("func2", 0x2345, {20});
-  NoError(ProfileWriter.addRecord(std::move(RecordFunc2)));
+  NoError(ProfileWriter.addRecord({"func1", 0x1234, {10}}));
+  NoError(ProfileWriter.addRecord({"func2", 0x2345, {20}}));
 
   startFunction("func1", 0x1234);
   addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5);
@@ -386,8 +382,7 @@ TEST_P(CoverageMappingTest, expansion_ge
 }
 
 TEST_P(CoverageMappingTest, basic_coverage_iteration) {
-  InstrProfRecord Record("func", 0x1234, {30, 20, 10, 0});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {30, 20, 10, 0}}));
 
   startFunction("func", 0x1234);
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -435,8 +430,7 @@ TEST_P(CoverageMappingTest, uncovered_fu
 }
 
 TEST_P(CoverageMappingTest, combine_regions) {
-  InstrProfRecord Record("func", 0x1234, {10, 20, 30});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20, 30}}));
 
   startFunction("func", 0x1234);
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -454,8 +448,7 @@ TEST_P(CoverageMappingTest, combine_regi
 }
 
 TEST_P(CoverageMappingTest, restore_combined_counter_after_nested_region) {
-  InstrProfRecord Record("func", 0x1234, {10, 20, 40});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20, 40}}));
 
   startFunction("func", 0x1234);
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -475,10 +468,8 @@ TEST_P(CoverageMappingTest, restore_comb
 // If CodeRegions and ExpansionRegions cover the same area,
 // only counts of CodeRegions should be used.
 TEST_P(CoverageMappingTest, dont_combine_expansions) {
-  InstrProfRecord Record1("func", 0x1234, {10, 20});
-  InstrProfRecord Record2("func", 0x1234, {0, 0});
-  NoError(ProfileWriter.addRecord(std::move(Record1)));
-  NoError(ProfileWriter.addRecord(std::move(Record2)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {10, 20}}));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {0, 0}}));
 
   startFunction("func", 0x1234);
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -498,8 +489,7 @@ TEST_P(CoverageMappingTest, dont_combine
 
 // If an area is covered only by ExpansionRegions, they should be combinated.
 TEST_P(CoverageMappingTest, combine_expansions) {
-  InstrProfRecord Record("func", 0x1234, {2, 3, 7});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {2, 3, 7}}));
 
   startFunction("func", 0x1234);
   addCMR(Counter::getCounter(1), "include1", 1, 1, 1, 10);
@@ -520,8 +510,7 @@ TEST_P(CoverageMappingTest, combine_expa
 }
 
 TEST_P(CoverageMappingTest, strip_filename_prefix) {
-  InstrProfRecord Record("file1:func", 0x1234, {0});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"file1:func", 0x1234, {0}}));
 
   startFunction("file1:func", 0x1234);
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
@@ -535,8 +524,7 @@ TEST_P(CoverageMappingTest, strip_filena
 }
 
 TEST_P(CoverageMappingTest, strip_unknown_filename_prefix) {
-  InstrProfRecord Record("<unknown>:func", 0x1234, {0});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"<unknown>:func", 0x1234, {0}}));
 
   startFunction("<unknown>:func", 0x1234);
   addCMR(Counter::getCounter(0), "", 1, 1, 9, 9);
@@ -550,10 +538,8 @@ TEST_P(CoverageMappingTest, strip_unknow
 }
 
 TEST_P(CoverageMappingTest, dont_detect_false_instantiations) {
-  InstrProfRecord Record1("foo", 0x1234, {10});
-  InstrProfRecord Record2("bar", 0x2345, {20});
-  NoError(ProfileWriter.addRecord(std::move(Record1)));
-  NoError(ProfileWriter.addRecord(std::move(Record2)));
+  NoError(ProfileWriter.addRecord({"foo", 0x1234, {10}}));
+  NoError(ProfileWriter.addRecord({"bar", 0x2345, {20}}));
 
   startFunction("foo", 0x1234);
   addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
@@ -571,8 +557,7 @@ TEST_P(CoverageMappingTest, dont_detect_
 }
 
 TEST_P(CoverageMappingTest, load_coverage_for_expanded_file) {
-  InstrProfRecord Record("func", 0x1234, {10});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {10}}));
 
   startFunction("func", 0x1234);
   addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
@@ -588,8 +573,7 @@ TEST_P(CoverageMappingTest, load_coverag
 }
 
 TEST_P(CoverageMappingTest, skip_duplicate_function_record) {
-  InstrProfRecord Record("func", 0x1234, {1});
-  NoError(ProfileWriter.addRecord(std::move(Record)));
+  NoError(ProfileWriter.addRecord({"func", 0x1234, {1}}));
 
   startFunction("func", 0x1234);
   addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);

Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=307236&r1=307235&r2=307236&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Wed Jul  5 22:19:17 2017
@@ -70,8 +70,7 @@ TEST_P(MaybeSparseInstrProfTest, write_a
 }
 
 TEST_P(MaybeSparseInstrProfTest, write_and_read_one_function) {
-  InstrProfRecord Record("foo", 0x1234, {1, 2, 3, 4});
-  NoError(Writer.addRecord(std::move(Record)));
+  NoError(Writer.addRecord({"foo", 0x1234, {1, 2, 3, 4}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -88,10 +87,8 @@ TEST_P(MaybeSparseInstrProfTest, write_a
 }
 
 TEST_P(MaybeSparseInstrProfTest, get_instr_prof_record) {
-  InstrProfRecord Record1("foo", 0x1234, {1, 2});
-  InstrProfRecord Record2("foo", 0x1235, {3, 4});
-  NoError(Writer.addRecord(std::move(Record1)));
-  NoError(Writer.addRecord(std::move(Record2)));
+  NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}));
+  NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -115,10 +112,8 @@ TEST_P(MaybeSparseInstrProfTest, get_ins
 }
 
 TEST_P(MaybeSparseInstrProfTest, get_function_counts) {
-  InstrProfRecord Record1("foo", 0x1234, {1, 2});
-  InstrProfRecord Record2("foo", 0x1235, {3, 4});
-  NoError(Writer.addRecord(std::move(Record1)));
-  NoError(Writer.addRecord(std::move(Record2)));
+  NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}));
+  NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -142,17 +137,14 @@ TEST_P(MaybeSparseInstrProfTest, get_fun
 
 // Profile data is copied from general.proftext
 TEST_F(InstrProfTest, get_profile_summary) {
-  InstrProfRecord Record1("func1", 0x1234, {97531});
-  InstrProfRecord Record2("func2", 0x1234, {0, 0});
-  InstrProfRecord Record3("func3", 0x1234,
-                          {2305843009213693952, 1152921504606846976,
-                           576460752303423488, 288230376151711744,
-                           144115188075855872, 72057594037927936});
-  InstrProfRecord Record4("func4", 0x1234, {0});
-  NoError(Writer.addRecord(std::move(Record1)));
-  NoError(Writer.addRecord(std::move(Record2)));
-  NoError(Writer.addRecord(std::move(Record3)));
-  NoError(Writer.addRecord(std::move(Record4)));
+  NoError(Writer.addRecord({"func1", 0x1234, {97531}}));
+  NoError(Writer.addRecord({"func2", 0x1234, {0, 0}}));
+  NoError(Writer.addRecord(
+      {"func3",
+       0x1234,
+       {2305843009213693952, 1152921504606846976, 576460752303423488,
+        288230376151711744, 144115188075855872, 72057594037927936}}));
+  NoError(Writer.addRecord({"func4", 0x1234, {0}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -203,12 +195,10 @@ TEST_F(InstrProfTest, get_profile_summar
 }
 
 TEST_F(InstrProfTest, test_writer_merge) {
-  InstrProfRecord Record1("func1", 0x1234, {42});
-  NoError(Writer.addRecord(std::move(Record1)));
+  NoError(Writer.addRecord({"func1", 0x1234, {42}}));
 
   InstrProfWriter Writer2;
-  InstrProfRecord Record2("func2", 0x1234, {0, 0});
-  NoError(Writer2.addRecord(std::move(Record2)));
+  NoError(Writer2.addRecord({"func2", 0x1234, {0, 0}}));
 
   NoError(Writer.mergeRecordsFromWriter(std::move(Writer2)));
 
@@ -236,9 +226,6 @@ static const char callee6[] = "callee6";
 
 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
   InstrProfRecord Record1("caller", 0x1234, {1, 2});
-  InstrProfRecord Record2("callee1", 0x1235, {3, 4});
-  InstrProfRecord Record3("callee2", 0x1235, {3, 4});
-  InstrProfRecord Record4("callee3", 0x1235, {3, 4});
 
   // 4 value sites.
   Record1.reserveSites(IPVK_IndirectCallTarget, 4);
@@ -253,9 +240,9 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
   Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
 
   NoError(Writer.addRecord(std::move(Record1)));
-  NoError(Writer.addRecord(std::move(Record2)));
-  NoError(Writer.addRecord(std::move(Record3)));
-  NoError(Writer.addRecord(std::move(Record4)));
+  NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -379,9 +366,6 @@ TEST_P(MaybeSparseInstrProfTest, annotat
 
 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
   InstrProfRecord Record1("caller", 0x1234, {1, 2});
-  InstrProfRecord Record2("callee1", 0x1235, {3, 4});
-  InstrProfRecord Record3("callee2", 0x1235, {3, 4});
-  InstrProfRecord Record4("callee3", 0x1235, {3, 4});
 
   // 4 value sites.
   Record1.reserveSites(IPVK_IndirectCallTarget, 4);
@@ -396,9 +380,9 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
   Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
 
   NoError(Writer.addRecord(std::move(Record1), 10));
-  NoError(Writer.addRecord(std::move(Record2)));
-  NoError(Writer.addRecord(std::move(Record3)));
-  NoError(Writer.addRecord(std::move(Record4)));
+  NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -425,9 +409,6 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
 
 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_big_endian) {
   InstrProfRecord Record1("caller", 0x1234, {1, 2});
-  InstrProfRecord Record2("callee1", 0x1235, {3, 4});
-  InstrProfRecord Record3("callee2", 0x1235, {3, 4});
-  InstrProfRecord Record4("callee3", 0x1235, {3, 4});
 
   // 4 value sites.
   Record1.reserveSites(IPVK_IndirectCallTarget, 4);
@@ -442,9 +423,9 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
   Record1.addValueData(IPVK_IndirectCallTarget, 3, VD3, 1, nullptr);
 
   NoError(Writer.addRecord(std::move(Record1)));
-  NoError(Writer.addRecord(std::move(Record2)));
-  NoError(Writer.addRecord(std::move(Record3)));
-  NoError(Writer.addRecord(std::move(Record4)));
+  NoError(Writer.addRecord({"callee1", 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({"callee2", 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({"callee3", 0x1235, {3, 4}}));
 
   // Set big endian output.
   Writer.setValueProfDataEndianness(support::big);
@@ -477,11 +458,6 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
   static const char caller[] = "caller";
   InstrProfRecord Record11(caller, 0x1234, {1, 2});
   InstrProfRecord Record12(caller, 0x1234, {1, 2});
-  InstrProfRecord Record2(callee1, 0x1235, {3, 4});
-  InstrProfRecord Record3(callee2, 0x1235, {3, 4});
-  InstrProfRecord Record4(callee3, 0x1235, {3, 4});
-  InstrProfRecord Record5(callee3, 0x1235, {3, 4});
-  InstrProfRecord Record6(callee4, 0x1235, {3, 5});
 
   // 5 value sites.
   Record11.reserveSites(IPVK_IndirectCallTarget, 5);
@@ -529,11 +505,11 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
   // Merge profile data.
   NoError(Writer.addRecord(std::move(Record12)));
 
-  NoError(Writer.addRecord(std::move(Record2)));
-  NoError(Writer.addRecord(std::move(Record3)));
-  NoError(Writer.addRecord(std::move(Record4)));
-  NoError(Writer.addRecord(std::move(Record5)));
-  NoError(Writer.addRecord(std::move(Record6)));
+  NoError(Writer.addRecord({callee1, 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({callee2, 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({callee3, 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({callee3, 0x1235, {3, 4}}));
+  NoError(Writer.addRecord({callee4, 0x1235, {3, 5}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -588,19 +564,16 @@ TEST_P(MaybeSparseInstrProfTest, get_ica
 
   const uint64_t Max = std::numeric_limits<uint64_t>::max();
 
-  InstrProfRecord Record1("foo", 0x1234, {1});
-  auto Result1 = Writer.addRecord(std::move(Record1));
+  auto Result1 = Writer.addRecord({"foo", 0x1234, {1}});
   ASSERT_EQ(InstrProfError::take(std::move(Result1)),
             instrprof_error::success);
 
   // Verify counter overflow.
-  InstrProfRecord Record2("foo", 0x1234, {Max});
-  auto Result2 = Writer.addRecord(std::move(Record2));
+  auto Result2 = Writer.addRecord({"foo", 0x1234, {Max}});
   ASSERT_EQ(InstrProfError::take(std::move(Result2)),
             instrprof_error::counter_overflow);
 
-  InstrProfRecord Record3(bar, 0x9012, {8});
-  auto Result3 = Writer.addRecord(std::move(Record3));
+  auto Result3 = Writer.addRecord({bar, 0x9012, {8}});
   ASSERT_EQ(InstrProfError::take(std::move(Result3)),
             instrprof_error::success);
 
@@ -817,12 +790,9 @@ TEST_P(MaybeSparseInstrProfTest, value_p
 }
 
 TEST_P(MaybeSparseInstrProfTest, get_max_function_count) {
-  InstrProfRecord Record1("foo", 0x1234, {1ULL << 31, 2});
-  InstrProfRecord Record2("bar", 0, {1ULL << 63});
-  InstrProfRecord Record3("baz", 0x5678, {0, 0, 0, 0});
-  NoError(Writer.addRecord(std::move(Record1)));
-  NoError(Writer.addRecord(std::move(Record2)));
-  NoError(Writer.addRecord(std::move(Record3)));
+  NoError(Writer.addRecord({"foo", 0x1234, {1ULL << 31, 2}}));
+  NoError(Writer.addRecord({"bar", 0, {1ULL << 63}}));
+  NoError(Writer.addRecord({"baz", 0x5678, {0, 0, 0, 0}}));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -830,10 +800,8 @@ TEST_P(MaybeSparseInstrProfTest, get_max
 }
 
 TEST_P(MaybeSparseInstrProfTest, get_weighted_function_counts) {
-  InstrProfRecord Record1("foo", 0x1234, {1, 2});
-  InstrProfRecord Record2("foo", 0x1235, {3, 4});
-  NoError(Writer.addRecord(std::move(Record1), 3));
-  NoError(Writer.addRecord(std::move(Record2), 5));
+  NoError(Writer.addRecord({"foo", 0x1234, {1, 2}}, 3));
+  NoError(Writer.addRecord({"foo", 0x1235, {3, 4}}, 5));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 
@@ -1015,13 +983,10 @@ TEST_P(MaybeSparseInstrProfTest, instr_p
 }
 
 TEST_F(SparseInstrProfTest, preserve_no_records) {
-  InstrProfRecord Record1("foo", 0x1234, {0});
-  InstrProfRecord Record2("bar", 0x4321, {0, 0});
-  InstrProfRecord Record3("bar", 0x4321, {0, 0, 0});
+  NoError(Writer.addRecord({"foo", 0x1234, {0}}));
+  NoError(Writer.addRecord({"bar", 0x4321, {0, 0}}));
+  NoError(Writer.addRecord({"bar", 0x4321, {0, 0, 0}}));
 
-  NoError(Writer.addRecord(std::move(Record1)));
-  NoError(Writer.addRecord(std::move(Record2)));
-  NoError(Writer.addRecord(std::move(Record3)));
   auto Profile = Writer.writeBuffer();
   readProfile(std::move(Profile));
 




More information about the llvm-commits mailing list