Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:29

0001 ///===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*--===//
0002 ///
0003 /// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 /// See https://llvm.org/LICENSE.txt for license information.
0005 /// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 ///
0007 ///===---------------------------------------------------------------------===//
0008 /// \file
0009 /// This is an alternative analysis pass to MachineBlockFrequencyInfo.  The
0010 /// difference is that with this pass the block frequencies are not computed
0011 /// when the analysis pass is executed but rather when the BFI result is
0012 /// explicitly requested by the analysis client.
0013 ///
0014 ///===---------------------------------------------------------------------===//
0015 
0016 #ifndef LLVM_CODEGEN_LAZYMACHINEBLOCKFREQUENCYINFO_H
0017 #define LLVM_CODEGEN_LAZYMACHINEBLOCKFREQUENCYINFO_H
0018 
0019 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
0020 #include "llvm/CodeGen/MachineDominators.h"
0021 #include "llvm/CodeGen/MachineFunctionPass.h"
0022 #include "llvm/CodeGen/MachineLoopInfo.h"
0023 
0024 namespace llvm {
0025 /// This is an alternative analysis pass to MachineBlockFrequencyInfo.
0026 /// The difference is that with this pass, the block frequencies are not
0027 /// computed when the analysis pass is executed but rather when the BFI result
0028 /// is explicitly requested by the analysis client.
0029 ///
0030 /// This works by checking querying if MBFI is available and otherwise
0031 /// generating MBFI on the fly.  In this case the passes required for (LI, DT)
0032 /// are also queried before being computed on the fly.
0033 ///
0034 /// Note that it is expected that we wouldn't need this functionality for the
0035 /// new PM since with the new PM, analyses are executed on demand.
0036 
0037 class LazyMachineBlockFrequencyInfoPass : public MachineFunctionPass {
0038 private:
0039   /// If generated on the fly this own the instance.
0040   mutable std::unique_ptr<MachineBlockFrequencyInfo> OwnedMBFI;
0041 
0042   /// If generated on the fly this own the instance.
0043   mutable std::unique_ptr<MachineLoopInfo> OwnedMLI;
0044 
0045   /// If generated on the fly this own the instance.
0046   mutable std::unique_ptr<MachineDominatorTree> OwnedMDT;
0047 
0048   /// The function.
0049   MachineFunction *MF = nullptr;
0050 
0051   /// Calculate MBFI and all other analyses that's not available and
0052   /// required by BFI.
0053   MachineBlockFrequencyInfo &calculateIfNotAvailable() const;
0054 
0055 public:
0056   static char ID;
0057 
0058   LazyMachineBlockFrequencyInfoPass();
0059 
0060   /// Compute and return the block frequencies.
0061   MachineBlockFrequencyInfo &getBFI() { return calculateIfNotAvailable(); }
0062 
0063   /// Compute and return the block frequencies.
0064   const MachineBlockFrequencyInfo &getBFI() const {
0065     return calculateIfNotAvailable();
0066   }
0067 
0068   void getAnalysisUsage(AnalysisUsage &AU) const override;
0069 
0070   bool runOnMachineFunction(MachineFunction &F) override;
0071   void releaseMemory() override;
0072 };
0073 }
0074 #endif