Record whether the weights on out-edges from a MBB are normalized.
1. Create a utility function normalizeEdgeWeights() in MachineBranchProbabilityInfo that normalizes a list of edge weights so that the sum of then can fit in uint32_t. 2. Provide an interface in MachineBasicBlock to normalize its successors' weights. 3. Add a flag in MachineBasicBlock that tracks whether its successors' weights are normalized. 4. Provide an overload of getSumForBlock that accepts a non-const pointer to a MBB so that it can force normalizing this MBB's successors' weights. 5. Update several uses of getSumForBlock() by eliminating the once needed weight scale. Differential Revision: http://reviews.llvm.org/D11442 llvm-svn: 244154
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
||||
#include "llvm/CodeGen/LiveVariables.h"
|
||||
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
||||
#include "llvm/CodeGen/MachineDominators.h"
|
||||
#include "llvm/CodeGen/MachineFunction.h"
|
||||
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||
@@ -39,8 +40,9 @@ using namespace llvm;
|
||||
#define DEBUG_TYPE "codegen"
|
||||
|
||||
MachineBasicBlock::MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb)
|
||||
: BB(bb), Number(-1), xParent(&mf), Alignment(0), IsLandingPad(false),
|
||||
AddressTaken(false), CachedMCSymbol(nullptr) {
|
||||
: BB(bb), Number(-1), AreSuccWeightsNormalized(false), xParent(&mf),
|
||||
Alignment(0), IsLandingPad(false), AddressTaken(false),
|
||||
CachedMCSymbol(nullptr) {
|
||||
Insts.Parent = this;
|
||||
}
|
||||
|
||||
@@ -481,8 +483,10 @@ void MachineBasicBlock::addSuccessor(MachineBasicBlock *succ, uint32_t weight) {
|
||||
if (weight != 0 && Weights.empty())
|
||||
Weights.resize(Successors.size());
|
||||
|
||||
if (weight != 0 || !Weights.empty())
|
||||
if (weight != 0 || !Weights.empty()) {
|
||||
Weights.push_back(weight);
|
||||
AreSuccWeightsNormalized = false;
|
||||
}
|
||||
|
||||
Successors.push_back(succ);
|
||||
succ->addPredecessor(this);
|
||||
@@ -1096,7 +1100,25 @@ uint32_t MachineBasicBlock::getSuccWeight(const_succ_iterator Succ) const {
|
||||
void MachineBasicBlock::setSuccWeight(succ_iterator I, uint32_t weight) {
|
||||
if (Weights.empty())
|
||||
return;
|
||||
*getWeightIterator(I) = weight;
|
||||
auto WeightIter = getWeightIterator(I);
|
||||
uint32_t OldWeight = *WeightIter;
|
||||
*WeightIter = weight;
|
||||
if (weight > OldWeight)
|
||||
AreSuccWeightsNormalized = false;
|
||||
}
|
||||
|
||||
/// Normalize all succesor weights so that the sum of them does not exceed
|
||||
/// UINT32_MAX. Return true if the weights are modified and false otherwise.
|
||||
/// Note that weights that are modified after calling this function are not
|
||||
/// guaranteed to be normalized.
|
||||
bool MachineBasicBlock::normalizeSuccWeights() {
|
||||
if (!AreSuccWeightsNormalized) {
|
||||
uint32_t Scale =
|
||||
MachineBranchProbabilityInfo::normalizeEdgeWeights(Weights);
|
||||
AreSuccWeightsNormalized = true;
|
||||
return Scale != 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// getWeightIterator - Return wight iterator corresonding to the I successor
|
||||
|
||||
Reference in New Issue
Block a user