summaryrefslogtreecommitdiffstats
path: root/llvm/include
diff options
context:
space:
mode:
authorJakub Staszak <jstaszak@apple.com>2011-07-16 20:23:20 +0000
committerJakub Staszak <jstaszak@apple.com>2011-07-16 20:23:20 +0000
commit27131171351b8edcf2dbc50c6e27f83185ead4d1 (patch)
tree56827cdefeb08fa14515d5fa27386622ebfbe2f3 /llvm/include
parente492cb41b70ad0a608ec9bf69b7c758fed3931a4 (diff)
downloadbcm5719-llvm-27131171351b8edcf2dbc50c6e27f83185ead4d1.tar.gz
bcm5719-llvm-27131171351b8edcf2dbc50c6e27f83185ead4d1.zip
Add MachineBlockFrequency analysis.
llvm-svn: 135352
Diffstat (limited to 'llvm/include')
-rw-r--r--llvm/include/llvm/Analysis/BlockFrequencyImpl.h8
-rw-r--r--llvm/include/llvm/CodeGen/MachineBlockFrequency.h53
-rw-r--r--llvm/include/llvm/InitializePasses.h1
3 files changed, 60 insertions, 2 deletions
diff --git a/llvm/include/llvm/Analysis/BlockFrequencyImpl.h b/llvm/include/llvm/Analysis/BlockFrequencyImpl.h
index cef375f10e6..6580fd1e4a9 100644
--- a/llvm/include/llvm/Analysis/BlockFrequencyImpl.h
+++ b/llvm/include/llvm/Analysis/BlockFrequencyImpl.h
@@ -18,8 +18,10 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
#include <vector>
#include <sstream>
#include <string>
@@ -28,6 +30,8 @@ namespace llvm {
class BlockFrequency;
+class MachineBlockFrequency;
+
/// BlockFrequencyImpl implements block frequency algorithm for IR and
/// Machine Instructions. Algorithm starts with value 1024 (START_FREQ)
/// for the entry block and then propagates frequencies using branch weights
@@ -53,9 +57,8 @@ class BlockFrequencyImpl {
std::string getBlockName(MachineBasicBlock *MBB) const {
std::stringstream ss;
ss << "BB#" << MBB->getNumber();
- const BasicBlock *BB = MBB->getBasicBlock();
- if (BB)
+ if (const BasicBlock *BB = MBB->getBasicBlock())
ss << " derived from LLVM BB " << BB->getNameStr();
return ss.str();
@@ -261,6 +264,7 @@ class BlockFrequencyImpl {
}
friend class BlockFrequency;
+ friend class MachineBlockFrequency;
void doFunction(FunctionT *fn, BlockProbInfoT *bpi) {
Fn = fn;
diff --git a/llvm/include/llvm/CodeGen/MachineBlockFrequency.h b/llvm/include/llvm/CodeGen/MachineBlockFrequency.h
new file mode 100644
index 00000000000..25bf1f08dc6
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/MachineBlockFrequency.h
@@ -0,0 +1,53 @@
+//====----- MachineBlockFrequency.h - MachineBlock Frequency Analysis ----====//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Loops should be simplified before this analysis.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCY_H
+#define LLVM_CODEGEN_MACHINEBLOCKFREQUENCY_H
+
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include <climits>
+
+namespace llvm {
+
+class MachineBranchProbabilityInfo;
+template<class BlockT, class FunctionT, class BranchProbInfoT>
+class BlockFrequencyImpl;
+
+/// MachineBlockFrequency pass uses BlockFrequencyImpl implementation to estimate
+/// machine basic block frequencies.
+class MachineBlockFrequency : public MachineFunctionPass {
+
+ BlockFrequencyImpl<MachineBasicBlock, MachineFunction, MachineBranchProbabilityInfo> *MBFI;
+
+public:
+ static char ID;
+
+ MachineBlockFrequency();
+
+ ~MachineBlockFrequency();
+
+ void getAnalysisUsage(AnalysisUsage &AU) const;
+
+ bool runOnMachineFunction(MachineFunction &F);
+
+ /// getblockFreq - Return block frequency. Never return 0, value must be
+ /// positive. Please note that initial frequency is equal to 1024. It means
+ /// that we should not rely on the value itself, but only on the comparison to
+ /// the other block frequencies. We do this to avoid using of the floating
+ /// points.
+ uint32_t getBlockFreq(MachineBasicBlock *MBB);
+};
+
+}
+
+#endif
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 5462eb8e77e..4caf8f1b46a 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -145,6 +145,7 @@ void initializeLowerIntrinsicsPass(PassRegistry&);
void initializeLowerInvokePass(PassRegistry&);
void initializeLowerSetJmpPass(PassRegistry&);
void initializeLowerSwitchPass(PassRegistry&);
+void initializeMachineBlockFrequencyPass(PassRegistry&);
void initializeMachineBranchProbabilityInfoPass(PassRegistry&);
void initializeMachineCSEPass(PassRegistry&);
void initializeMachineDominatorTreePass(PassRegistry&);
OpenPOWER on IntegriCloud