diff options
author | Guozhi Wei <carrot@google.com> | 2020-12-14 12:48:55 -0800 |
---|---|---|
committer | Guozhi Wei <carrot@google.com> | 2020-12-14 12:48:55 -0800 |
commit | d50d7c37a159802c89454a6c53c0ec2e7949d84a (patch) | |
tree | c1ff889ad893963dfabd17ca4c9abc6ca0072693 /llvm/lib/CodeGen/MachineBlockPlacement.cpp | |
parent | f5fe8493e5acfd70da61993cd370816978b9ef85 (diff) | |
download | llvm-d50d7c37a159802c89454a6c53c0ec2e7949d84a.zip llvm-d50d7c37a159802c89454a6c53c0ec2e7949d84a.tar.gz llvm-d50d7c37a159802c89454a6c53c0ec2e7949d84a.tar.bz2 |
[MBP] Prevent rotating a chain contains entry block
The entry block should always be the first BB in a function.
So we should not rotate a chain contains the entry block.
Differential Revision: https://reviews.llvm.org/D92882
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBlockPlacement.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index bd46408..42586cb 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -2306,6 +2306,10 @@ void MachineBlockPlacement::rotateLoop(BlockChain &LoopChain, if (Bottom == ExitingBB) return; + // The entry block should always be the first BB in a function. + if (Top->isEntryBlock()) + return; + bool ViableTopFallthrough = hasViableTopFallthrough(Top, LoopBlockSet); // If the header has viable fallthrough, check whether the current loop @@ -2380,6 +2384,11 @@ void MachineBlockPlacement::rotateLoopWithProfile( BlockChain &LoopChain, const MachineLoop &L, const BlockFilterSet &LoopBlockSet) { auto RotationPos = LoopChain.end(); + MachineBasicBlock *ChainHeaderBB = *LoopChain.begin(); + + // The entry block should always be the first BB in a function. + if (ChainHeaderBB->isEntryBlock()) + return; BlockFrequency SmallestRotationCost = BlockFrequency::getMaxFrequency(); @@ -2398,7 +2407,6 @@ void MachineBlockPlacement::rotateLoopWithProfile( // chain head is not the loop header. As we only consider natural loops with // single header, this computation can be done only once. BlockFrequency HeaderFallThroughCost(0); - MachineBasicBlock *ChainHeaderBB = *LoopChain.begin(); for (auto *Pred : ChainHeaderBB->predecessors()) { BlockChain *PredChain = BlockToChain[Pred]; if (!LoopBlockSet.count(Pred) && |