aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ProfileData/InstrProfWriter.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-04-23 16:57:46 -0700
committerStephen Hines <srhines@google.com>2014-04-24 15:53:16 -0700
commit36b56886974eae4f9c5ebc96befd3e7bfe5de338 (patch)
treee6cfb69fbbd937f450eeb83bfb83b9da3b01275a /lib/ProfileData/InstrProfWriter.cpp
parent69a8640022b04415ae9fac62f8ab090601d8f889 (diff)
downloadexternal_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.zip
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.gz
external_llvm-36b56886974eae4f9c5ebc96befd3e7bfe5de338.tar.bz2
Update to LLVM 3.5a.
Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
Diffstat (limited to 'lib/ProfileData/InstrProfWriter.cpp')
-rw-r--r--lib/ProfileData/InstrProfWriter.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/ProfileData/InstrProfWriter.cpp b/lib/ProfileData/InstrProfWriter.cpp
new file mode 100644
index 0000000..3024f96
--- /dev/null
+++ b/lib/ProfileData/InstrProfWriter.cpp
@@ -0,0 +1,60 @@
+//=-- InstrProfWriter.cpp - Instrumented profiling writer -------------------=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains support for writing profiling data for clang's
+// instrumentation based PGO and coverage.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ProfileData/InstrProfWriter.h"
+#include "llvm/Support/Endian.h"
+
+using namespace llvm;
+
+error_code InstrProfWriter::addFunctionCounts(StringRef FunctionName,
+ uint64_t FunctionHash,
+ ArrayRef<uint64_t> Counters) {
+ auto Where = FunctionData.find(FunctionName);
+ if (Where == FunctionData.end()) {
+ // If this is the first time we've seen this function, just add it.
+ auto &Data = FunctionData[FunctionName];
+ Data.Hash = FunctionHash;
+ Data.Counts = Counters;
+ return instrprof_error::success;;
+ }
+
+ auto &Data = Where->getValue();
+ // We can only add to existing functions if they match, so we check the hash
+ // and number of counters.
+ if (Data.Hash != FunctionHash)
+ return instrprof_error::hash_mismatch;
+ if (Data.Counts.size() != Counters.size())
+ return instrprof_error::count_mismatch;
+ // These match, add up the counters.
+ for (size_t I = 0, E = Counters.size(); I < E; ++I) {
+ if (Data.Counts[I] + Counters[I] < Data.Counts[I])
+ return instrprof_error::counter_overflow;
+ Data.Counts[I] += Counters[I];
+ }
+ return instrprof_error::success;
+}
+
+void InstrProfWriter::write(raw_ostream &OS) {
+ // Write out the counts for each function.
+ for (const auto &I : FunctionData) {
+ StringRef Name = I.getKey();
+ uint64_t Hash = I.getValue().Hash;
+ const std::vector<uint64_t> &Counts = I.getValue().Counts;
+
+ OS << Name << "\n" << Hash << "\n" << Counts.size() << "\n";
+ for (uint64_t Count : Counts)
+ OS << Count << "\n";
+ OS << "\n";
+ }
+}