1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 0807d2a7e5a2..da8a7df58ac8 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -149,6 +149,7 @@
#include <string>
#include <tuple>
#include <utility>
+#include <fstream>
using namespace llvm;
@@ -432,6 +433,28 @@ static std::optional<unsigned> getSmallBestKnownTC(ScalarEvolution &SE,
return std::nullopt;
}
+/// Log vect metric to <srcfile>.vect.csv
+static void logVectMetric(Function& F, unsigned loopsVectorizedBefore,
+ unsigned loopsVectorized)
+{
+ auto fname = F.getParent()->getSourceFileName() + ".vect.csv";
+ bool writeHeader = false;
+ std::ifstream tmp_f(fname);
+ if (!tmp_f)
+ writeHeader = true;
+ else
+ tmp_f.close();
+
+ std::ofstream vectStatsFile;
+ vectStatsFile.open(fname, std::ios_base::app);
+ if (writeHeader)
+ vectStatsFile << "symbol,num_vect_loops" << "\n";
+
+ unsigned loopsVectorizedFunc = loopsVectorized - loopsVectorizedBefore;
+ vectStatsFile << F.getName().str() << "," << loopsVectorizedFunc << "\n";
+ vectStatsFile.close();
+}
+
/// Return a vector containing interleaved elements from multiple
/// smaller input vectors.
static Value *interleaveVectors(IRBuilderBase &Builder, ArrayRef<Value *> Vals,
@@ -10360,6 +10383,7 @@ LoopVectorizeResult LoopVectorizePass::runImpl(
LoopsAnalyzed += Worklist.size();
+ unsigned loopsVectorizedBefore = LoopsVectorized.getValue();
// Now walk the identified inner loops.
while (!Worklist.empty()) {
Loop *L = Worklist.pop_back_val();
@@ -10380,6 +10404,7 @@ LoopVectorizeResult LoopVectorizePass::runImpl(
}
}
+ logVectMetric(F, loopsVectorizedBefore, LoopsVectorized.getValue());
// Process each loop nest in the function.
return LoopVectorizeResult(Changed, CFGChanged);
}
|