diff options
author | Cong Hou <congh@google.com> | 2015-08-05 22:01:20 +0000 |
---|---|---|
committer | Cong Hou <congh@google.com> | 2015-08-05 22:01:20 +0000 |
commit | 36e7e52aa4f8d79c898d74f93711c4a0c78e253f (patch) | |
tree | 2adf8ae761c69bf9271220f2371bf51410f463f5 /llvm/lib/CodeGen/MachineBasicBlock.cpp | |
parent | 758f3f542af978ec48745a01c998ccbbc7a7a077 (diff) | |
download | llvm-36e7e52aa4f8d79c898d74f93711c4a0c78e253f.zip llvm-36e7e52aa4f8d79c898d74f93711c4a0c78e253f.tar.gz llvm-36e7e52aa4f8d79c898d74f93711c4a0c78e253f.tar.bz2 |
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
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index 5d3f7eb..e2f381e 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -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 |