2014-11-24 04:08:18 -05:00
|
|
|
//===- MachineBlockFrequencyInfo.h - MBB Frequency Analysis -*- C++ -*-----===//
|
2011-07-17 11:36:56 -04:00
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2011-10-20 17:10:27 -04:00
|
|
|
#ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
|
|
|
|
|
#define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
|
2011-07-17 11:36:56 -04:00
|
|
|
|
2016-07-23 16:41:05 -04:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2011-07-17 11:36:56 -04:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2011-10-20 17:10:27 -04:00
|
|
|
#include "llvm/Support/BlockFrequency.h"
|
2011-07-17 11:36:56 -04:00
|
|
|
#include <climits>
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
2012-04-14 09:54:10 -04:00
|
|
|
class MachineBasicBlock;
|
2011-07-17 11:36:56 -04:00
|
|
|
class MachineBranchProbabilityInfo;
|
2014-11-24 04:08:18 -05:00
|
|
|
template <class BlockT> class BlockFrequencyInfoImpl;
|
2011-07-17 11:36:56 -04:00
|
|
|
|
2014-11-24 04:08:18 -05:00
|
|
|
/// MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation
|
|
|
|
|
/// to estimate machine basic block frequencies.
|
2011-10-20 17:10:27 -04:00
|
|
|
class MachineBlockFrequencyInfo : public MachineFunctionPass {
|
2014-11-24 04:08:18 -05:00
|
|
|
typedef BlockFrequencyInfoImpl<MachineBasicBlock> ImplType;
|
|
|
|
|
std::unique_ptr<ImplType> MBFI;
|
2011-07-17 11:36:56 -04:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static char ID;
|
|
|
|
|
|
2011-10-20 17:10:27 -04:00
|
|
|
MachineBlockFrequencyInfo();
|
2011-07-17 11:36:56 -04:00
|
|
|
|
2015-05-27 14:44:32 -04:00
|
|
|
~MachineBlockFrequencyInfo() override;
|
2011-07-17 11:36:56 -04:00
|
|
|
|
2014-11-24 04:08:18 -05:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &F) override;
|
2011-07-17 11:36:56 -04:00
|
|
|
|
2014-11-24 04:08:18 -05:00
|
|
|
void releaseMemory() override;
|
2011-07-17 11:36:56 -04:00
|
|
|
|
2011-10-20 17:10:27 -04:00
|
|
|
/// getblockFreq - Return block frequency. Return 0 if we don't have the
|
|
|
|
|
/// information. Please note that initial frequency is equal to 1024. It means
|
2011-07-17 11:36:56 -04:00
|
|
|
/// that we should not rely on the value itself, but only on the comparison to
|
2011-10-20 17:10:27 -04:00
|
|
|
/// the other block frequencies. We do this to avoid using of floating points.
|
|
|
|
|
///
|
2012-04-14 09:54:10 -04:00
|
|
|
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
|
2014-11-24 04:08:18 -05:00
|
|
|
|
2016-07-23 16:41:05 -04:00
|
|
|
Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
|
|
|
|
|
|
2014-11-24 04:08:18 -05:00
|
|
|
const MachineFunction *getFunction() const;
|
2016-07-23 16:41:05 -04:00
|
|
|
const MachineBranchProbabilityInfo *getMBPI() const;
|
2014-11-24 04:08:18 -05:00
|
|
|
void view() const;
|
|
|
|
|
|
|
|
|
|
// Print the block frequency Freq to OS using the current functions entry
|
|
|
|
|
// frequency to convert freq into a relative decimal form.
|
|
|
|
|
raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
|
|
|
|
|
|
|
|
|
|
// Convenience method that attempts to look up the frequency associated with
|
|
|
|
|
// BB and print it to OS.
|
|
|
|
|
raw_ostream &printBlockFreq(raw_ostream &OS,
|
|
|
|
|
const MachineBasicBlock *MBB) const;
|
|
|
|
|
|
|
|
|
|
uint64_t getEntryFreq() const;
|
|
|
|
|
|
2011-07-17 11:36:56 -04:00
|
|
|
};
|
|
|
|
|
|
2015-07-05 10:21:36 -04:00
|
|
|
}
|
2011-07-17 11:36:56 -04:00
|
|
|
|
|
|
|
|
#endif
|