aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/BranchRelaxation.cpp
diff options
context:
space:
mode:
authorZHU Zijia <piggynl@outlook.com>2022-12-02 02:41:04 +0800
committerZHU Zijia <piggynl@outlook.com>2022-12-02 02:42:22 +0800
commit010a8f7a90bf6e6d77f07f0a02dd8a63dfeb32da (patch)
treeb9928f66c74bb8ff9fc9a18a8fd9fa1f53f41b68 /llvm/lib/CodeGen/BranchRelaxation.cpp
parent3adf828a0e96ea18531fe74fa151fa8c087e5a21 (diff)
downloadllvm-010a8f7a90bf6e6d77f07f0a02dd8a63dfeb32da.zip
llvm-010a8f7a90bf6e6d77f07f0a02dd8a63dfeb32da.tar.gz
llvm-010a8f7a90bf6e6d77f07f0a02dd8a63dfeb32da.tar.bz2
[CodeGen] Fix restore blocks' BasicBlock information in branch relaxation
In branch relaxation pass, restore blocks are created and placed before the jump destination if indirect branches are required. For example: foo sd s11, 0(sp) jump .restore, s11 bar bar bar j .dest .restore: ld s11, 0(sp) .dest: baz The BasicBlock information of the restore MachineBasicBlock should be identical to the dest MachineBasicBlock. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D131863
Diffstat (limited to 'llvm/lib/CodeGen/BranchRelaxation.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchRelaxation.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/BranchRelaxation.cpp b/llvm/lib/CodeGen/BranchRelaxation.cpp
index 87d5d05..b243188 100644
--- a/llvm/lib/CodeGen/BranchRelaxation.cpp
+++ b/llvm/lib/CodeGen/BranchRelaxation.cpp
@@ -88,7 +88,9 @@ class BranchRelaxation : public MachineFunctionPass {
bool relaxBranchInstructions();
void scanFunction();
- MachineBasicBlock *createNewBlockAfter(MachineBasicBlock &BB);
+ MachineBasicBlock *createNewBlockAfter(MachineBasicBlock &OrigMBB);
+ MachineBasicBlock *createNewBlockAfter(MachineBasicBlock &OrigMBB,
+ const BasicBlock *BB);
MachineBasicBlock *splitBlockBeforeInstr(MachineInstr &MI,
MachineBasicBlock *DestBB);
@@ -202,12 +204,20 @@ void BranchRelaxation::adjustBlockOffsets(MachineBasicBlock &Start) {
}
}
-/// Insert a new empty basic block and insert it after \BB
-MachineBasicBlock *BranchRelaxation::createNewBlockAfter(MachineBasicBlock &BB) {
+/// Insert a new empty MachineBasicBlock and insert it after \p OrigMBB
+MachineBasicBlock *
+BranchRelaxation::createNewBlockAfter(MachineBasicBlock &OrigBB) {
+ return createNewBlockAfter(OrigBB, OrigBB.getBasicBlock());
+}
+
+/// Insert a new empty MachineBasicBlock with \p BB as its BasicBlock
+/// and insert it after \p OrigMBB
+MachineBasicBlock *
+BranchRelaxation::createNewBlockAfter(MachineBasicBlock &OrigMBB,
+ const BasicBlock *BB) {
// Create a new MBB for the code after the OrigBB.
- MachineBasicBlock *NewBB =
- MF->CreateMachineBasicBlock(BB.getBasicBlock());
- MF->insert(++BB.getIterator(), NewBB);
+ MachineBasicBlock *NewBB = MF->CreateMachineBasicBlock(BB);
+ MF->insert(++OrigMBB.getIterator(), NewBB);
// Insert an entry into BlockInfo to align it properly with the block numbers.
BlockInfo.insert(BlockInfo.begin() + NewBB->getNumber(), BasicBlockInfo());
@@ -482,7 +492,8 @@ bool BranchRelaxation::fixupUnconditionalBranch(MachineInstr &MI) {
// Create the optional restore block and, initially, place it at the end of
// function. That block will be placed later if it's used; otherwise, it will
// be erased.
- MachineBasicBlock *RestoreBB = createNewBlockAfter(MF->back());
+ MachineBasicBlock *RestoreBB = createNewBlockAfter(MF->back(),
+ DestBB->getBasicBlock());
TII->insertIndirectBranch(*BranchBB, *DestBB, *RestoreBB, DL,
DestOffset - SrcOffset, RS.get());