File tree 3 files changed +21
-5
lines changed
3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,16 @@ bool BlockCoverage::AppendCoverage(const std::string &S) {
42
42
bool BlockCoverage::AppendCoverage (std::istream &IN) {
43
43
std::string L;
44
44
while (std::getline (IN, L, ' \n ' )) {
45
- if (L.empty () || L[ 0 ] != ' C ' )
46
- continue ; // Ignore non-coverage lines.
45
+ if (L.empty ())
46
+ continue ;
47
47
std::stringstream SS (L.c_str () + 1 );
48
48
size_t FunctionId = 0 ;
49
49
SS >> FunctionId;
50
+ if (L[0 ] == ' F' ) {
51
+ FunctionsWithDFT.insert (FunctionId);
52
+ continue ;
53
+ }
54
+ if (L[0 ] != ' C' ) continue ;
50
55
Vector<uint32_t > CoveredBlocks;
51
56
while (true ) {
52
57
uint32_t BB = 0 ;
@@ -87,9 +92,12 @@ Vector<double> BlockCoverage::FunctionWeights(size_t NumFunctions) const {
87
92
auto Counters = It.second ;
88
93
assert (FunctionID < NumFunctions);
89
94
auto &Weight = Res[FunctionID];
90
- Weight = 1000 .; // this function is covered.
95
+ // Give higher weight if the function has a DFT.
96
+ Weight = FunctionsWithDFT.count (FunctionID) ? 1000 . : 1 ;
97
+ // Give higher weight to functions with less frequently seen basic blocks.
91
98
Weight /= SmallestNonZeroCounter (Counters);
92
- Weight *= NumberOfUncoveredBlocks (Counters) + 1 ; // make sure it's not 0.
99
+ // Give higher weight to functions with the most uncovered basic blocks.
100
+ Weight *= NumberOfUncoveredBlocks (Counters) + 1 ;
93
101
}
94
102
return Res;
95
103
}
Original file line number Diff line number Diff line change @@ -107,6 +107,8 @@ class BlockCoverage {
107
107
// Function ID => vector of counters.
108
108
// Each counter represents how many input files trigger the given basic block.
109
109
std::unordered_map<size_t , CoverageVector> Functions;
110
+ // Functions that have DFT entry.
111
+ std::unordered_set<size_t > FunctionsWithDFT;
110
112
};
111
113
112
114
class DataFlowTrace {
Original file line number Diff line number Diff line change @@ -840,11 +840,17 @@ TEST(DFT, FunctionWeights) {
840
840
Weights = Cov.FunctionWeights (2 );
841
841
EXPECT_GT (Weights[0 ], Weights[1 ]);
842
842
843
- // A function with more uncovered bclocks gets more weight.
843
+ // A function with more uncovered blocks gets more weight.
844
844
Cov.clear ();
845
845
EXPECT_TRUE (Cov.AppendCoverage (" C0 1 2 3 5\n C1 2 4\n " ));
846
846
Weights = Cov.FunctionWeights (2 );
847
847
EXPECT_GT (Weights[1 ], Weights[0 ]);
848
+
849
+ // A function with DFT gets more weight than the function w/o DFT.
850
+ Cov.clear ();
851
+ EXPECT_TRUE (Cov.AppendCoverage (" F1 111\n C0 3\n C1 1 2 3\n " ));
852
+ Weights = Cov.FunctionWeights (2 );
853
+ EXPECT_GT (Weights[1 ], Weights[0 ]);
848
854
}
849
855
850
856
You can’t perform that action at this time.
0 commit comments