summaryrefslogtreecommitdiff
path: root/downstream_patches/llvm-vect-metric.diff
diff options
context:
space:
mode:
Diffstat (limited to 'downstream_patches/llvm-vect-metric.diff')
-rw-r--r--downstream_patches/llvm-vect-metric.diff57
1 files changed, 57 insertions, 0 deletions
diff --git a/downstream_patches/llvm-vect-metric.diff b/downstream_patches/llvm-vect-metric.diff
new file mode 100644
index 00000000..574fd8a8
--- /dev/null
+++ b/downstream_patches/llvm-vect-metric.diff
@@ -0,0 +1,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);
+ }