summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MachineBasicBlock.cpp
diff options
context:
space:
mode:
authorCong Hou <congh@google.com>2015-10-27 17:59:36 +0000
committerCong Hou <congh@google.com>2015-10-27 17:59:36 +0000
commit07eeb8001e0cc9705366ecc63f79ed5f2a5f51fc (patch)
tree1334a821bb7eba1b1a7d3515971326366cce4878 /llvm/lib/CodeGen/MachineBasicBlock.cpp
parentab3215fa115d336c47bbf2e6387f7b72eb9a9a01 (diff)
downloadbcm5719-llvm-07eeb8001e0cc9705366ecc63f79ed5f2a5f51fc.tar.gz
bcm5719-llvm-07eeb8001e0cc9705366ecc63f79ed5f2a5f51fc.zip
Create a new interface addSuccessorWithoutWeight(MBB*) in MBB to add successors when optimization is disabled.
When optimization is disabled, edge weights that are stored in MBB won't be used so that we don't have to store them. Currently, this is done by adding successors with default weight 0, and if all successors have default weights, the weight list will be empty. But that the weight list is empty doesn't mean disabled optimization (as is stated several times in MachineBasicBlock.cpp): it may also mean all successors just have default weights. We should discourage using default weights when adding successors, because it is very easy for users to forget update the correct edge weights instead of using default ones (one exception is that the MBB only has one successor). In order to detect such usages, it is better to differentiate using default weights from the case when optimizations is disabled. In this patch, a new interface addSuccessorWithoutWeight(MBB*) is created for when optimization is disabled. In this case, MBB will try to maintain an empty weight list, but it cannot guarantee this as for many uses of addSuccessor() whether optimization is disabled or not is not checked. But it can guarantee that if optimization is enabled, then the weight list always has the same size of the successor list. Differential revision: http://reviews.llvm.org/D13963 llvm-svn: 251429
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBasicBlock.cpp18
1 files changed, 11 insertions, 7 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);
}
OpenPOWER on IntegriCloud