summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/MachineBasicBlock.cpp18
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/FastISel.cpp25
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp10
3 files changed, 32 insertions, 21 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp
index 9668a09f050..ab865ff8152 100644
--- a/llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -506,15 +506,19 @@ void MachineBasicBlock::updateTerminator() {
}
void MachineBasicBlock::addSuccessor(MachineBasicBlock *Succ, uint32_t Weight) {
-
- // If we see non-zero value for the first time it means we actually use Weight
- // list, so we fill all Weights with 0's.
- if (Weight != 0 && Weights.empty())
- Weights.resize(Successors.size());
-
- if (Weight != 0 || !Weights.empty())
+ // Weight list is either empty (if successor list isn't empty, this means
+ // disabled optimization) or has the same size as successor list.
+ if (!(Weights.empty() && !Successors.empty()))
Weights.push_back(Weight);
+ Successors.push_back(Succ);
+ Succ->addPredecessor(this);
+}
+void MachineBasicBlock::addSuccessorWithoutWeight(MachineBasicBlock *Succ) {
+ // We need to make sure weight list is either empty or has the same size of
+ // successor list. When this function is called, we can safely delete all
+ // weight in the list.
+ Weights.clear();
Successors.push_back(Succ);
Succ->addPredecessor(this);
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index 99f4ef70aed..adc51c55564 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1394,25 +1394,28 @@ void FastISel::fastEmitBranch(MachineBasicBlock *MSucc, DebugLoc DbgLoc) {
TII.InsertBranch(*FuncInfo.MBB, MSucc, nullptr,
SmallVector<MachineOperand, 0>(), DbgLoc);
}
- uint32_t BranchWeight = 0;
- if (FuncInfo.BPI)
- BranchWeight = FuncInfo.BPI->getEdgeWeight(FuncInfo.MBB->getBasicBlock(),
- MSucc->getBasicBlock());
- FuncInfo.MBB->addSuccessor(MSucc, BranchWeight);
+ if (FuncInfo.BPI) {
+ uint32_t BranchWeight = FuncInfo.BPI->getEdgeWeight(
+ FuncInfo.MBB->getBasicBlock(), MSucc->getBasicBlock());
+ FuncInfo.MBB->addSuccessor(MSucc, BranchWeight);
+ } else
+ FuncInfo.MBB->addSuccessorWithoutWeight(MSucc);
}
void FastISel::finishCondBranch(const BasicBlock *BranchBB,
MachineBasicBlock *TrueMBB,
MachineBasicBlock *FalseMBB) {
- uint32_t BranchWeight = 0;
- if (FuncInfo.BPI)
- BranchWeight = FuncInfo.BPI->getEdgeWeight(BranchBB,
- TrueMBB->getBasicBlock());
// Add TrueMBB as successor unless it is equal to the FalseMBB: This can
// happen in degenerate IR and MachineIR forbids to have a block twice in the
// successor/predecessor lists.
- if (TrueMBB != FalseMBB)
- FuncInfo.MBB->addSuccessor(TrueMBB, BranchWeight);
+ if (TrueMBB != FalseMBB) {
+ if (FuncInfo.BPI) {
+ uint32_t BranchWeight =
+ FuncInfo.BPI->getEdgeWeight(BranchBB, TrueMBB->getBasicBlock());
+ FuncInfo.MBB->addSuccessor(TrueMBB, BranchWeight);
+ } else
+ FuncInfo.MBB->addSuccessorWithoutWeight(TrueMBB);
+ }
fastEmitBranch(FalseMBB, DbgLoc);
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 0e5a8f70bce..8d04f47fa96 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1499,9 +1499,13 @@ uint32_t SelectionDAGBuilder::getEdgeWeight(const MachineBasicBlock *Src,
void SelectionDAGBuilder::
addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst,
uint32_t Weight /* = 0 */) {
- if (!Weight)
- Weight = getEdgeWeight(Src, Dst);
- Src->addSuccessor(Dst, Weight);
+ if (!FuncInfo.BPI)
+ Src->addSuccessorWithoutWeight(Dst);
+ else {
+ if (!Weight)
+ Weight = getEdgeWeight(Src, Dst);
+ Src->addSuccessor(Dst, Weight);
+ }
}
OpenPOWER on IntegriCloud