diff options
author | Snehasish Kumar <snehasishk@google.com> | 2021-02-09 14:13:47 -0800 |
---|---|---|
committer | Snehasish Kumar <snehasishk@google.com> | 2021-02-11 11:23:43 -0800 |
commit | 2c7077e67dc77834607c877ad6e8caa6e33ae238 (patch) | |
tree | 636cc4f92e4582045da2943093aee64dd8241349 /llvm/lib/CodeGen/MachineFunctionSplitter.cpp | |
parent | 97dbab879700fa51abe5f090ea31bfbed3483701 (diff) | |
download | llvm-2c7077e67dc77834607c877ad6e8caa6e33ae238.zip llvm-2c7077e67dc77834607c877ad6e8caa6e33ae238.tar.gz llvm-2c7077e67dc77834607c877ad6e8caa6e33ae238.tar.bz2 |
[CodeGen] Split out cold exception handling pads.
Support for splitting exception handling pads was added in D73739. This
change updates the code to split out exception handling pads if profile
information indicates that they are cold. For a given function with
multiple landind pads, if one of them is hot they are all retained as
part of the hot code section.
Differential Revision: https://reviews.llvm.org/D96372
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunctionSplitter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunctionSplitter.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp index 483809a..294e3c2 100644 --- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp +++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp @@ -23,6 +23,7 @@ // https://groups.google.com/d/msg/llvm-dev/RUegaMg-iqc/wFAVxa6fCgAJ //===----------------------------------------------------------------------===// +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/CodeGen/BasicBlockSectionUtils.h" @@ -77,7 +78,7 @@ public: }; } // end anonymous namespace -static bool isColdBlock(MachineBasicBlock &MBB, +static bool isColdBlock(const MachineBasicBlock &MBB, const MachineBlockFrequencyInfo *MBFI, ProfileSummaryInfo *PSI) { Optional<uint64_t> Count = MBFI->getBlockProfileCount(&MBB); @@ -121,16 +122,28 @@ bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) { auto *MBFI = &getAnalysis<MachineBlockFrequencyInfo>(); auto *PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(); + SmallVector<MachineBasicBlock *, 2> LandingPads; for (auto &MBB : MF) { - // FIXME: We retain the entry block and conservatively keep all landing pad - // blocks as part of the original function. Once D73739 is submitted, we can - // improve the handling of ehpads. - if ((MBB.pred_empty() || MBB.isEHPad())) + if (MBB.isEntryBlock()) continue; - if (isColdBlock(MBB, MBFI, PSI)) + + if (MBB.isEHPad()) + LandingPads.push_back(&MBB); + else if (isColdBlock(MBB, MBFI, PSI)) MBB.setSectionID(MBBSectionID::ColdSectionID); } + // We only split out eh pads if all of them are cold. + bool HasHotLandingPads = false; + for (const MachineBasicBlock *LP : LandingPads) { + if (!isColdBlock(*LP, MBFI, PSI)) + HasHotLandingPads = true; + } + if (!HasHotLandingPads) { + for (MachineBasicBlock *LP : LandingPads) + LP->setSectionID(MBBSectionID::ColdSectionID); + } + auto Comparator = [](const MachineBasicBlock &X, const MachineBasicBlock &Y) { return X.getSectionID().Type < Y.getSectionID().Type; }; |