llvm.org GIT mirror llvm / 59a9dab
Add MachineBlockFrequency analysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135352 91177308-0d34-0410-b5e6-96231b3b80d8 Jakub Staszak 9 years ago
5 changed file(s) with 121 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/ADT/DenseMap.h"
1818 #include "llvm/ADT/PostOrderIterator.h"
1919 #include "llvm/CodeGen/MachineBasicBlock.h"
20 #include "llvm/CodeGen/MachineFunction.h"
2021 #include "llvm/Support/BranchProbability.h"
2122 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/raw_ostream.h"
2224 #include
2325 #include
2426 #include
2729
2830
2931 class BlockFrequency;
32 class MachineBlockFrequency;
33
3034 /// BlockFrequencyImpl implements block frequency algorithm for IR and
3135 /// Machine Instructions. Algorithm starts with value 1024 (START_FREQ)
3236 /// for the entry block and then propagates frequencies using branch weights
5256 std::string getBlockName(MachineBasicBlock *MBB) const {
5357 std::stringstream ss;
5458 ss << "BB#" << MBB->getNumber();
55 const BasicBlock *BB = MBB->getBasicBlock();
56
57 if (BB)
59
60 if (const BasicBlock *BB = MBB->getBasicBlock())
5861 ss << " derived from LLVM BB " << BB->getNameStr();
5962
6063 return ss.str();
260263 }
261264
262265 friend class BlockFrequency;
266 friend class MachineBlockFrequency;
263267
264268 void doFunction(FunctionT *fn, BlockProbInfoT *bpi) {
265269 Fn = fn;
0 //====----- MachineBlockFrequency.h - MachineBlock Frequency Analysis ----====//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Loops should be simplified before this analysis.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCY_H
14 #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCY_H
15
16 #include "llvm/CodeGen/MachineFunctionPass.h"
17 #include
18
19 namespace llvm {
20
21 class MachineBranchProbabilityInfo;
22 template
23 class BlockFrequencyImpl;
24
25 /// MachineBlockFrequency pass uses BlockFrequencyImpl implementation to estimate
26 /// machine basic block frequencies.
27 class MachineBlockFrequency : public MachineFunctionPass {
28
29 BlockFrequencyImpl *MBFI;
30
31 public:
32 static char ID;
33
34 MachineBlockFrequency();
35
36 ~MachineBlockFrequency();
37
38 void getAnalysisUsage(AnalysisUsage &AU) const;
39
40 bool runOnMachineFunction(MachineFunction &F);
41
42 /// getblockFreq - Return block frequency. Never return 0, value must be
43 /// positive. Please note that initial frequency is equal to 1024. It means
44 /// that we should not rely on the value itself, but only on the comparison to
45 /// the other block frequencies. We do this to avoid using of the floating
46 /// points.
47 uint32_t getBlockFreq(MachineBasicBlock *MBB);
48 };
49
50 }
51
52 #endif
144144 void initializeLowerInvokePass(PassRegistry&);
145145 void initializeLowerSetJmpPass(PassRegistry&);
146146 void initializeLowerSwitchPass(PassRegistry&);
147 void initializeMachineBlockFrequencyPass(PassRegistry&);
147148 void initializeMachineBranchProbabilityInfoPass(PassRegistry&);
148149 void initializeMachineCSEPass(PassRegistry&);
149150 void initializeMachineDominatorTreePass(PassRegistry&);
3232 LocalStackSlotAllocation.cpp
3333 LowerSubregs.cpp
3434 MachineBasicBlock.cpp
35 MachineBlockFrequency.cpp
3536 MachineBranchProbabilityInfo.cpp
3637 MachineCSE.cpp
3738 MachineDominators.cpp
0 //====----- MachineBlockFrequency.cpp - Machine Block Frequency Analysis ----====//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Loops should be simplified before this analysis.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/InitializePasses.h"
14 #include "llvm/Analysis/BlockFrequencyImpl.h"
15 #include "llvm/CodeGen/MachineBlockFrequency.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
18
19 using namespace llvm;
20
21 INITIALIZE_PASS_BEGIN(MachineBlockFrequency, "machine-block-freq",
22 "Machine Block Frequency Analysis", true, true)
23 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
24 INITIALIZE_PASS_END(MachineBlockFrequency, "machine-block-freq",
25 "Machine Block Frequency Analysis", true, true)
26
27 char MachineBlockFrequency::ID = 0;
28
29
30 MachineBlockFrequency::MachineBlockFrequency() : MachineFunctionPass(ID) {
31 initializeMachineBlockFrequencyPass(*PassRegistry::getPassRegistry());
32 MBFI = new BlockFrequencyImpl
33 MachineBranchProbabilityInfo>();
34 }
35
36 MachineBlockFrequency::~MachineBlockFrequency() {
37 delete MBFI;
38 }
39
40 void MachineBlockFrequency::getAnalysisUsage(AnalysisUsage &AU) const {
41 AU.addRequired();
42 AU.setPreservesAll();
43 }
44
45 bool MachineBlockFrequency::runOnMachineFunction(MachineFunction &F) {
46 MachineBranchProbabilityInfo &MBPI = getAnalysis();
47 MBFI->doFunction(&F, &MBPI);
48 return false;
49 }
50
51 /// getblockFreq - Return block frequency. Never return 0, value must be
52 /// positive. Please note that initial frequency is equal to 1024. It means that
53 /// we should not rely on the value itself, but only on the comparison to the
54 /// other block frequencies. We do this to avoid using of floating points.
55 ///
56 uint32_t MachineBlockFrequency::getBlockFreq(MachineBasicBlock *MBB) {
57 return MBFI->getBlockFreq(MBB);
58 }