LLVM API Documentation

EdgeBundles.h
Go to the documentation of this file.
00001 //===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // The EdgeBundles analysis forms equivalence classes of CFG edges such that all
00011 // edges leaving a machine basic block are in the same bundle, and all edges
00012 // leaving a basic block are in the same bundle.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CODEGEN_EDGEBUNDLES_H
00017 #define LLVM_CODEGEN_EDGEBUNDLES_H
00018 
00019 #include "llvm/ADT/ArrayRef.h"
00020 #include "llvm/ADT/IntEqClasses.h"
00021 #include "llvm/ADT/Twine.h"
00022 #include "llvm/CodeGen/MachineFunctionPass.h"
00023 
00024 namespace llvm {
00025 
00026 class EdgeBundles : public MachineFunctionPass {
00027   const MachineFunction *MF;
00028 
00029   /// EC - Each edge bundle is an equivalence class. The keys are:
00030   ///   2*BB->getNumber()   -> Ingoing bundle.
00031   ///   2*BB->getNumber()+1 -> Outgoing bundle.
00032   IntEqClasses EC;
00033 
00034   /// Blocks - Map each bundle to a list of basic block numbers.
00035   SmallVector<SmallVector<unsigned, 8>, 4> Blocks;
00036 
00037 public:
00038   static char ID;
00039   EdgeBundles() : MachineFunctionPass(ID) {}
00040 
00041   /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
00042   /// bundle number for basic block #N
00043   unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
00044 
00045   /// getNumBundles - Return the total number of bundles in the CFG.
00046   unsigned getNumBundles() const { return EC.getNumClasses(); }
00047 
00048   /// getBlocks - Return an array of blocks that are connected to Bundle.
00049   ArrayRef<unsigned> getBlocks(unsigned Bundle) const { return Blocks[Bundle]; }
00050 
00051   /// getMachineFunction - Return the last machine function computed.
00052   const MachineFunction *getMachineFunction() const { return MF; }
00053 
00054   /// view - Visualize the annotated bipartite CFG with Graphviz.
00055   void view() const;
00056 
00057 private:
00058   bool runOnMachineFunction(MachineFunction&) override;
00059   void getAnalysisUsage(AnalysisUsage&) const override;
00060 };
00061 
00062 } // end namespace llvm
00063 
00064 #endif