2013-08-12 21:10:23 +00:00
|
|
|
//=- MachineBranchProbabilityInfo.h - Branch Probability Analysis -*- C++ -*-=//
|
2011-06-16 20:22:37 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass is used to evaluate branch probabilties on machine basic blocks.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
|
|
|
|
|
2012-08-20 22:01:38 +00:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Pass.h"
|
2011-06-16 20:22:37 +00:00
|
|
|
#include "llvm/Support/BranchProbability.h"
|
|
|
|
#include <climits>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class MachineBranchProbabilityInfo : public ImmutablePass {
|
2011-12-20 02:50:00 +00:00
|
|
|
virtual void anchor();
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
// Default weight value. Used when we don't have information about the edge.
|
|
|
|
// TODO: DEFAULT_WEIGHT makes sense during static predication, when none of
|
|
|
|
// the successors have a weight yet. But it doesn't make sense when providing
|
|
|
|
// weight to an edge that may have siblings with non-zero weights. This can
|
|
|
|
// be handled various ways, but it's probably fine for an edge with unknown
|
|
|
|
// weight to just "inherit" the non-zero weight of an adjacent successor.
|
|
|
|
static const uint32_t DEFAULT_WEIGHT = 16;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
MachineBranchProbabilityInfo() : ImmutablePass(ID) {
|
|
|
|
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
|
|
|
initializeMachineBranchProbabilityInfoPass(Registry);
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:03 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2011-06-16 20:22:37 +00:00
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return edge weight. If we don't have any informations about it - return
|
|
|
|
// DEFAULT_WEIGHT.
|
2011-12-20 20:03:10 +00:00
|
|
|
uint32_t getEdgeWeight(const MachineBasicBlock *Src,
|
|
|
|
const MachineBasicBlock *Dst) const;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
2012-08-20 22:01:38 +00:00
|
|
|
// Same thing, but using a const_succ_iterator from Src. This is faster when
|
|
|
|
// the iterator is already available.
|
|
|
|
uint32_t getEdgeWeight(const MachineBasicBlock *Src,
|
|
|
|
MachineBasicBlock::const_succ_iterator Dst) const;
|
|
|
|
|
2011-11-14 09:12:57 +00:00
|
|
|
// Get sum of the block successors' weights, potentially scaling them to fit
|
|
|
|
// within 32-bits. If scaling is required, sets Scale based on the necessary
|
|
|
|
// adjustment. Any edge weights used with the sum should be divided by Scale.
|
2011-12-20 20:03:10 +00:00
|
|
|
uint32_t getSumForBlock(const MachineBasicBlock *MBB, uint32_t &Scale) const;
|
2011-11-14 09:12:57 +00:00
|
|
|
|
2011-06-16 20:22:37 +00:00
|
|
|
// A 'Hot' edge is an edge which probability is >= 80%.
|
2014-03-25 18:01:32 +00:00
|
|
|
bool isEdgeHot(const MachineBasicBlock *Src,
|
|
|
|
const MachineBasicBlock *Dst) const;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
// Return a hot successor for the block BB or null if there isn't one.
|
2011-11-14 08:55:59 +00:00
|
|
|
// NB: This routine's complexity is linear on the number of successors.
|
2011-06-16 20:22:37 +00:00
|
|
|
MachineBasicBlock *getHotSucc(MachineBasicBlock *MBB) const;
|
|
|
|
|
|
|
|
// Return a probability as a fraction between 0 (0% probability) and
|
|
|
|
// 1 (100% probability), however the value is never equal to 0, and can be 1
|
2012-09-27 10:14:43 +00:00
|
|
|
// only iff SRC block has only one successor.
|
2011-11-14 06:51:49 +00:00
|
|
|
// NB: This routine's complexity is linear on the number of successors of
|
|
|
|
// Src. Querying sequentially for each successor's probability is a quadratic
|
|
|
|
// query pattern.
|
2014-03-25 18:01:32 +00:00
|
|
|
BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
|
|
|
|
const MachineBasicBlock *Dst) const;
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
// Print value between 0 (0% probability) and 1 (100% probability),
|
2012-09-27 10:14:43 +00:00
|
|
|
// however the value is never equal to 0, and can be 1 only iff SRC block
|
2011-06-16 20:22:37 +00:00
|
|
|
// has only one successor.
|
2014-03-25 18:01:32 +00:00
|
|
|
raw_ostream &printEdgeProbability(raw_ostream &OS,
|
|
|
|
const MachineBasicBlock *Src,
|
|
|
|
const MachineBasicBlock *Dst) const;
|
2011-06-16 20:22:37 +00:00
|
|
|
};
|
|
|
|
|
2015-06-23 09:49:53 +00:00
|
|
|
}
|
2011-06-16 20:22:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|