Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-------- EdgeBundles.h - Bundles of CFG edges --------------*- 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 //
0009 // The EdgeBundles analysis forms equivalence classes of CFG edges such that all
0010 // edges leaving a machine basic block are in the same bundle, and all edges
0011 // entering a machine basic block are in the same bundle.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_CODEGEN_EDGEBUNDLES_H
0016 #define LLVM_CODEGEN_EDGEBUNDLES_H
0017 
0018 #include "llvm/ADT/ArrayRef.h"
0019 #include "llvm/ADT/IntEqClasses.h"
0020 #include "llvm/CodeGen/MachineFunctionPass.h"
0021 #include "llvm/IR/PassManager.h"
0022 
0023 namespace llvm {
0024 class EdgeBundlesWrapperLegacy;
0025 class EdgeBundlesAnalysis;
0026 
0027 class EdgeBundles {
0028   friend class EdgeBundlesWrapperLegacy;
0029   friend class EdgeBundlesAnalysis;
0030 
0031   const MachineFunction *MF = nullptr;
0032 
0033   /// EC - Each edge bundle is an equivalence class. The keys are:
0034   ///   2*BB->getNumber()   -> Ingoing bundle.
0035   ///   2*BB->getNumber()+1 -> Outgoing bundle.
0036   IntEqClasses EC;
0037 
0038   /// Blocks - Map each bundle to a list of basic block numbers.
0039   SmallVector<SmallVector<unsigned, 8>, 4> Blocks;
0040 
0041   void init();
0042   EdgeBundles(MachineFunction &MF);
0043 
0044 public:
0045   /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
0046   /// bundle number for basic block #N
0047   unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
0048 
0049   /// getNumBundles - Return the total number of bundles in the CFG.
0050   unsigned getNumBundles() const { return EC.getNumClasses(); }
0051 
0052   /// getBlocks - Return an array of blocks that are connected to Bundle.
0053   ArrayRef<unsigned> getBlocks(unsigned Bundle) const { return Blocks[Bundle]; }
0054 
0055   /// getMachineFunction - Return the last machine function computed.
0056   const MachineFunction *getMachineFunction() const { return MF; }
0057 
0058   /// view - Visualize the annotated bipartite CFG with Graphviz.
0059   void view() const;
0060 
0061   // Handle invalidation for the new pass manager
0062   bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA,
0063                   MachineFunctionAnalysisManager::Invalidator &Inv);
0064 };
0065 
0066 class EdgeBundlesWrapperLegacy : public MachineFunctionPass {
0067 public:
0068   static char ID;
0069   EdgeBundlesWrapperLegacy() : MachineFunctionPass(ID) {}
0070 
0071   EdgeBundles &getEdgeBundles() { return *Impl; }
0072   const EdgeBundles &getEdgeBundles() const { return *Impl; }
0073 
0074 private:
0075   std::unique_ptr<EdgeBundles> Impl;
0076   bool runOnMachineFunction(MachineFunction &MF) override;
0077   void getAnalysisUsage(AnalysisUsage&) const override;
0078 };
0079 
0080 class EdgeBundlesAnalysis : public AnalysisInfoMixin<EdgeBundlesAnalysis> {
0081   friend AnalysisInfoMixin<EdgeBundlesAnalysis>;
0082   static AnalysisKey Key;
0083 
0084 public:
0085   using Result = EdgeBundles;
0086   EdgeBundles run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
0087 };
0088 
0089 } // end namespace llvm
0090 
0091 #endif