diff options
author | Jakub Staszak <jstaszak@apple.com> | 2011-07-16 20:23:20 +0000 |
---|---|---|
committer | Jakub Staszak <jstaszak@apple.com> | 2011-07-16 20:23:20 +0000 |
commit | 59a9dab4d8650d3408efa431907183e13b91867b (patch) | |
tree | bad690f0a6da03f945b9b610f063ade7110027b9 /include | |
parent | 91ddfc4723f5857e0124192d71e625a7926cbc70 (diff) | |
download | llvm-59a9dab4d8650d3408efa431907183e13b91867b.tar.gz llvm-59a9dab4d8650d3408efa431907183e13b91867b.tar.bz2 llvm-59a9dab4d8650d3408efa431907183e13b91867b.tar.xz |
Add MachineBlockFrequency analysis.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Analysis/BlockFrequencyImpl.h | 8 | ||||
-rw-r--r-- | include/llvm/CodeGen/MachineBlockFrequency.h | 53 | ||||
-rw-r--r-- | include/llvm/InitializePasses.h | 1 |
3 files changed, 60 insertions, 2 deletions
diff --git a/include/llvm/Analysis/BlockFrequencyImpl.h b/include/llvm/Analysis/BlockFrequencyImpl.h index cef375f10e..6580fd1e4a 100644 --- a/include/llvm/Analysis/BlockFrequencyImpl.h +++ b/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/include/llvm/CodeGen/MachineBlockFrequency.h b/include/llvm/CodeGen/MachineBlockFrequency.h new file mode 100644 index 0000000000..25bf1f08dc --- /dev/null +++ b/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/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index 5462eb8e77..4caf8f1b46 100644 --- a/include/llvm/InitializePasses.h +++ b/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&); |