From 64725c314d90fe64e135f6d7079fb8b0f7e01146 Mon Sep 17 00:00:00 2001 From: Diego Novillo Date: Tue, 17 Nov 2015 19:04:46 +0000 Subject: [PATCH] SamplePGO - Move debug/dump function bodies out of header files. NFC. No point polluting the header declarations with debugging code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253361 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ProfileData/SampleProf.h | 41 +++++++------------------ lib/ProfileData/SampleProf.cpp | 43 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/include/llvm/ProfileData/SampleProf.h b/include/llvm/ProfileData/SampleProf.h index 52cbba396a3..d7596d7b1b7 100644 --- a/include/llvm/ProfileData/SampleProf.h +++ b/include/llvm/ProfileData/SampleProf.h @@ -75,21 +75,14 @@ static inline uint64_t SPVersion() { return 102; } /// (e.g., the two post-increment instructions in "if (p) x++; else y++;"). struct LineLocation { LineLocation(uint32_t L, uint32_t D) : LineOffset(L), Discriminator(D) {} - void print(raw_ostream &OS) const { - OS << LineOffset; - if (Discriminator > 0) - OS << "." << Discriminator; - } - void dump() const { print(dbgs()); } + void print(raw_ostream &OS) const; + void dump() const; uint32_t LineOffset; uint32_t Discriminator; }; -inline raw_ostream &operator<<(raw_ostream &OS, const LineLocation &Loc) { - Loc.print(OS); - return OS; -} +raw_ostream &operator<<(raw_ostream &OS, const LineLocation &Loc); /// Represents the relative location of a callsite. /// @@ -100,19 +93,13 @@ inline raw_ostream &operator<<(raw_ostream &OS, const LineLocation &Loc) { struct CallsiteLocation : public LineLocation { CallsiteLocation(uint32_t L, uint32_t D, StringRef N) : LineLocation(L, D), CalleeName(N) {} - StringRef CalleeName; + void print(raw_ostream &OS) const; + void dump() const; - void print(raw_ostream &OS) const { - LineLocation::print(OS); - OS << ": inlined callee: " << CalleeName; - } - void dump() const { print(dbgs()); } + StringRef CalleeName; }; -inline raw_ostream &operator<<(raw_ostream &OS, const CallsiteLocation &Loc) { - Loc.print(OS); - return OS; -} +raw_ostream &operator<<(raw_ostream &OS, const CallsiteLocation &Loc); } // End namespace sampleprof @@ -218,17 +205,14 @@ public: } void print(raw_ostream &OS, unsigned Indent) const; - void dump() const { print(dbgs(), 0); } + void dump() const; private: uint64_t NumSamples; CallTargetMap CallTargets; }; -inline raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample) { - Sample.print(OS, 0); - return OS; -} +raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample); typedef DenseMap BodySampleMap; class FunctionSamples; @@ -243,7 +227,7 @@ class FunctionSamples { public: FunctionSamples() : TotalSamples(0), TotalHeadSamples(0) {} void print(raw_ostream &OS = dbgs(), unsigned Indent = 0) const; - void dump(void) const { print(); } + void dump() const; void addTotalSamples(uint64_t Num) { TotalSamples += Num; } void addHeadSamples(uint64_t Num) { TotalHeadSamples += Num; } void addBodySamples(uint32_t LineOffset, uint32_t Discriminator, @@ -355,10 +339,7 @@ private: CallsiteSampleMap CallsiteSamples; }; -inline raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS) { - FS.print(OS); - return OS; -} +raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS); } // end namespace sampleprof diff --git a/lib/ProfileData/SampleProf.cpp b/lib/ProfileData/SampleProf.cpp index b3ee61a7b97..3d75d230fb6 100644 --- a/lib/ProfileData/SampleProf.cpp +++ b/lib/ProfileData/SampleProf.cpp @@ -57,6 +57,33 @@ const std::error_category &llvm::sampleprof_category() { return *ErrorCategory; } +void LineLocation::print(raw_ostream &OS) const { + OS << LineOffset; + if (Discriminator > 0) + OS << "." << Discriminator; +} + +raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS, + const LineLocation &Loc) { + Loc.print(OS); + return OS; +} + +void LineLocation::dump() const { print(dbgs()); } + +void CallsiteLocation::print(raw_ostream &OS) const { + LineLocation::print(OS); + OS << ": inlined callee: " << CalleeName; +} + +void CallsiteLocation::dump() const { print(dbgs()); } + +inline raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS, + const CallsiteLocation &Loc) { + Loc.print(OS); + return OS; +} + /// \brief Print the sample record to the stream \p OS indented by \p Indent. void SampleRecord::print(raw_ostream &OS, unsigned Indent) const { OS << NumSamples; @@ -68,6 +95,14 @@ void SampleRecord::print(raw_ostream &OS, unsigned Indent) const { OS << "\n"; } +void SampleRecord::dump() const { print(dbgs(), 0); } + +raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS, + const SampleRecord &Sample) { + Sample.print(OS, 0); + return OS; +} + /// \brief Print the samples collected for a function on stream \p OS. void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const { OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size() @@ -84,3 +119,11 @@ void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const { CS.second.print(OS, Indent + 2); } } + +raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS, + const FunctionSamples &FS) { + FS.print(OS); + return OS; +} + +void FunctionSamples::dump(void) const { print(dbgs(), 0); } -- 2.34.1