diff options
| author | Amara Emerson <amara@apple.com> | 2021-02-24 22:45:25 -0800 |
|---|---|---|
| committer | Amara Emerson <amara@apple.com> | 2021-03-02 12:55:51 -0800 |
| commit | 8a316045ede4f598c22a175875231684ac2fb234 (patch) | |
| tree | 446fb6c063cefa9dbdabf281343aa1a3e009ee9b /llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp | |
| parent | c0f8115c73b758b992f237b531f4b807c0c1c810 (diff) | |
[AArch64][GlobalISel] Enable use of the optsize predicate in the selector.
To do this while supporting the existing functionality in SelectionDAG of using
PGO info, we add the ProfileSummaryInfo and LazyBlockFrequencyInfo analysis
dependencies to the instruction selector pass.
Then, use the predicate to generate constant pool loads for f32 materialization,
if we're targeting optsize/minsize.
Differential Revision: https://reviews.llvm.org/D97732
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp index 5f521ad4a028..75a8f03fcb3f 100644 --- a/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp @@ -11,7 +11,11 @@ #include "llvm/CodeGen/GlobalISel/InstructionSelect.h" #include "llvm/ADT/PostOrderIterator.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/ADT/Twine.h" +#include "llvm/Analysis/BlockFrequencyInfo.h" +#include "llvm/Analysis/LazyBlockFrequencyInfo.h" +#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/CodeGen/GlobalISel/GISelKnownBits.h" #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h" @@ -50,16 +54,29 @@ INITIALIZE_PASS_BEGIN(InstructionSelect, DEBUG_TYPE, false, false) INITIALIZE_PASS_DEPENDENCY(TargetPassConfig) INITIALIZE_PASS_DEPENDENCY(GISelKnownBitsAnalysis) +INITIALIZE_PASS_DEPENDENCY(ProfileSummaryInfoWrapperPass) +INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass) INITIALIZE_PASS_END(InstructionSelect, DEBUG_TYPE, "Select target instructions out of generic instructions", false, false) -InstructionSelect::InstructionSelect() : MachineFunctionPass(ID) { } +InstructionSelect::InstructionSelect(CodeGenOpt::Level OL) + : MachineFunctionPass(ID), OptLevel(OL) {} + +// In order not to crash when calling getAnalysis during testing with -run-pass +// we use the default opt level here instead of None, so that the addRequired() +// calls are made in getAnalysisUsage(). +InstructionSelect::InstructionSelect() + : MachineFunctionPass(ID), OptLevel(CodeGenOpt::Default) {} void InstructionSelect::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<TargetPassConfig>(); - AU.addRequired<GISelKnownBitsAnalysis>(); - AU.addPreserved<GISelKnownBitsAnalysis>(); + if (OptLevel != CodeGenOpt::None) { + AU.addRequired<GISelKnownBitsAnalysis>(); + AU.addPreserved<GISelKnownBitsAnalysis>(); + AU.addRequired<ProfileSummaryInfoWrapperPass>(); + LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU); + } getSelectionDAGFallbackAnalysisUsage(AU); MachineFunctionPass::getAnalysisUsage(AU); } @@ -71,13 +88,26 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) { return false; LLVM_DEBUG(dbgs() << "Selecting function: " << MF.getName() << '\n'); - GISelKnownBits &KB = getAnalysis<GISelKnownBitsAnalysis>().get(MF); const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>(); InstructionSelector *ISel = MF.getSubtarget().getInstructionSelector(); + + CodeGenOpt::Level OldOptLevel = OptLevel; + auto RestoreOptLevel = make_scope_exit([=]() { OptLevel = OldOptLevel; }); + OptLevel = MF.getFunction().hasOptNone() ? CodeGenOpt::None + : MF.getTarget().getOptLevel(); + + GISelKnownBits *KB = nullptr; + if (OptLevel != CodeGenOpt::None) { + KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF); + PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI(); + if (PSI && PSI->hasProfileSummary()) + BFI = &getAnalysis<LazyBlockFrequencyInfoPass>().getBFI(); + } + CodeGenCoverage CoverageInfo; assert(ISel && "Cannot work without InstructionSelector"); - ISel->setupMF(MF, KB, CoverageInfo); + ISel->setupMF(MF, KB, CoverageInfo, PSI, BFI); // An optimization remark emitter. Used to report failures. MachineOptimizationRemarkEmitter MORE(MF, /*MBFI=*/nullptr); @@ -102,6 +132,7 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) { #endif for (MachineBasicBlock *MBB : post_order(&MF)) { + ISel->CurMBB = MBB; if (MBB->empty()) continue; |
