summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/BranchRelaxation.cpp
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2016-11-02 16:18:29 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2016-11-02 16:18:29 +0000
commit44deb7914ef81ee9bffb94a10b0a93edd4ea6acf (patch)
treee8108a80daa6a9453f7adea918cf64234a4c3ba8 /llvm/lib/CodeGen/BranchRelaxation.cpp
parent54286bda2cdf7be9a57582e2d2a79fe40bac1faf (diff)
downloadbcm5719-llvm-44deb7914ef81ee9bffb94a10b0a93edd4ea6acf.tar.gz
bcm5719-llvm-44deb7914ef81ee9bffb94a10b0a93edd4ea6acf.zip
BranchRelaxation: Fix computing indirect branch block size
llvm-svn: 285828
Diffstat (limited to 'llvm/lib/CodeGen/BranchRelaxation.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchRelaxation.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/BranchRelaxation.cpp b/llvm/lib/CodeGen/BranchRelaxation.cpp
index ddf8797d479..244c01c876e 100644
--- a/llvm/lib/CodeGen/BranchRelaxation.cpp
+++ b/llvm/lib/CodeGen/BranchRelaxation.cpp
@@ -78,7 +78,8 @@ class BranchRelaxation : public MachineFunctionPass {
MachineBasicBlock *createNewBlockAfter(MachineBasicBlock &BB);
- MachineBasicBlock *splitBlockBeforeInstr(MachineInstr &MI);
+ MachineBasicBlock *splitBlockBeforeInstr(MachineInstr &MI,
+ MachineBasicBlock *DestBB);
void adjustBlockOffsets(MachineBasicBlock &MBB);
bool isBlockInRange(const MachineInstr &MI, const MachineBasicBlock &BB) const;
@@ -116,6 +117,7 @@ void BranchRelaxation::verify() {
unsigned Num = MBB.getNumber();
assert(BlockInfo[Num].Offset % (1u << Align) == 0);
assert(!Num || BlockInfo[PrevNum].postOffset(MBB) <= BlockInfo[Num].Offset);
+ assert(BlockInfo[Num].Size == computeBlockSize(MBB));
PrevNum = Num;
}
#endif
@@ -205,10 +207,8 @@ MachineBasicBlock *BranchRelaxation::createNewBlockAfter(MachineBasicBlock &BB)
/// Split the basic block containing MI into two blocks, which are joined by
/// an unconditional branch. Update data structures and renumber blocks to
/// account for this change and returns the newly created block.
-/// NOTE: Successor list of the original BB is out of date after this function,
-/// and must be updated by the caller! Other transforms follow using this
-/// utility function, so no point updating now rather than waiting.
-MachineBasicBlock *BranchRelaxation::splitBlockBeforeInstr(MachineInstr &MI) {
+MachineBasicBlock *BranchRelaxation::splitBlockBeforeInstr(MachineInstr &MI,
+ MachineBasicBlock *DestBB) {
MachineBasicBlock *OrigBB = MI.getParent();
// Create a new MBB for the code after the OrigBB.
@@ -228,6 +228,16 @@ MachineBasicBlock *BranchRelaxation::splitBlockBeforeInstr(MachineInstr &MI) {
// Insert an entry into BlockInfo to align it properly with the block numbers.
BlockInfo.insert(BlockInfo.begin() + NewBB->getNumber(), BasicBlockInfo());
+
+ NewBB->transferSuccessors(OrigBB);
+ OrigBB->addSuccessor(NewBB);
+ OrigBB->addSuccessor(DestBB);
+
+ // Cleanup potential unconditional branch to successor block.
+ // Note that updateTerminator may change the size of the blocks.
+ NewBB->updateTerminator();
+ OrigBB->updateTerminator();
+
// Figure out how large the OrigBB is. As the first half of the original
// block, it cannot contain a tablejump. The size includes
// the new jump we added. (It should be possible to do this without
@@ -386,12 +396,9 @@ bool BranchRelaxation::fixupUnconditionalBranch(MachineInstr &MI) {
DebugLoc DL = MI.getDebugLoc();
MI.eraseFromParent();
-
- // insertUnconditonalBranch may have inserted a new block.
- BlockInfo[MBB->getNumber()].Size += TII->insertIndirectBranch(
+ BlockInfo[BranchBB->getNumber()].Size += TII->insertIndirectBranch(
*BranchBB, *DestBB, DL, DestOffset - SrcOffset, RS.get());
- computeBlockSize(*BranchBB);
adjustBlockOffsets(*MBB);
return true;
}
@@ -440,14 +447,7 @@ bool BranchRelaxation::relaxBranchInstructions() {
// analyzable block. Split later terminators into a new block so
// each one will be analyzable.
- MachineBasicBlock *NewBB = splitBlockBeforeInstr(*Next);
- NewBB->transferSuccessors(&MBB);
- MBB.addSuccessor(NewBB);
- MBB.addSuccessor(DestBB);
-
- // Cleanup potential unconditional branch to successor block.
- NewBB->updateTerminator();
- MBB.updateTerminator();
+ splitBlockBeforeInstr(*Next, DestBB);
} else {
fixupConditionalBranch(MI);
++NumConditionalRelaxed;
OpenPOWER on IntegriCloud