[llvm] r197285 - [block-freq] Add a print method on BlockFrequencyImpl for printing block frequencies and a convenience method for the common case of getting/printing a basic block.
Michael Gottesman
mgottesman at apple.com
Fri Dec 13 15:59:44 PST 2013
Author: mgottesman
Date: Fri Dec 13 17:59:44 2013
New Revision: 197285
URL: http://llvm.org/viewvc/llvm-project?rev=197285&view=rev
Log:
[block-freq] Add a print method on BlockFrequencyImpl for printing block frequencies and a convenience method for the common case of getting/printing a basic block.
BlockFrequencies can only be printed relative to their entry frequency. Thus
since the entry frequency is no longer necessarily a static constant on the
BlockFrequency class and is instead a potentially dynamic value taken from
BlockFrequencyImpl, we must necessarily print it via a method on
BlockFrequencyImpl.
Modified:
llvm/trunk/include/llvm/Analysis/BlockFrequencyImpl.h
Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyImpl.h?rev=197285&r1=197284&r2=197285&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BlockFrequencyImpl.h (original)
+++ llvm/trunk/include/llvm/Analysis/BlockFrequencyImpl.h Fri Dec 13 17:59:44 2013
@@ -343,6 +343,30 @@ public:
void dump() const {
print(dbgs());
}
+
+ // Utility method that looks up the block frequency associated with BB and
+ // prints it to OS.
+ raw_ostream &printBlockFreq(raw_ostream &OS,
+ const BlockT *BB) {
+ return printBlockFreq(OS, getBlockFreq(BB));
+ }
+
+ raw_ostream &printBlockFreq(raw_ostream &OS,
+ const BlockFrequency &Freq) const {
+ // Convert fixed-point number to decimal.
+ uint64_t Frequency = Freq.getFrequency();
+ OS << Frequency / EntryFreq << ".";
+ uint64_t Rem = Frequency % EntryFreq;
+ uint64_t Eps = 1;
+ do {
+ Rem *= 10;
+ Eps *= 10;
+ OS << Rem / EntryFreq;
+ Rem = Rem % EntryFreq;
+ } while (Rem >= Eps/2);
+ return OS;
+ }
+
};
}
More information about the llvm-commits
mailing list