Turn the EdgeBundles class into a stand-alone machine CFG analysis pass.
[oota-llvm.git] / include / llvm / CodeGen / EdgeBundles.h
1 //===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // The EdgeBundles analysis forms equivalence classes of CFG edges such that all
11 // edges leaving a machine basic block are in the same bundle, and all edges
12 // leaving a basic block are in the same bundle.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_EDGEBUNDLES_H
17 #define LLVM_CODEGEN_EDGEBUNDLES_H
18
19 #include "llvm/ADT/IntEqClasses.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21
22 namespace llvm {
23
24 class EdgeBundles : public MachineFunctionPass {
25   const MachineFunction *MF;
26
27   /// EC - Each edge bundle is an equivalence class. The keys are:
28   ///   2*BB->getNumber()   -> Ingoing bundle.
29   ///   2*BB->getNumber()+1 -> Outgoing bundle.
30   IntEqClasses EC;
31
32 public:
33   static char ID;
34   EdgeBundles() : MachineFunctionPass(ID) {}
35
36   /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
37   /// bundle number for basic block #N
38   unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
39
40   /// getMachineFunction - Return the last machine function computed.
41   const MachineFunction *getMachineFunction() const { return MF; }
42
43   /// view - Visualize the annotated bipartite CFG with Graphviz.
44   void view() const;
45
46 private:
47   virtual bool runOnMachineFunction(MachineFunction&);
48   virtual void getAnalysisUsage(AnalysisUsage&) const;
49 };
50
51 /// Specialize WriteGraph, the standard implementation won't work.
52 raw_ostream &WriteGraph(raw_ostream &O, const EdgeBundles &G,
53                         bool ShortNames = false,
54                         const std::string &Title = "");
55
56 } // end namespace llvm
57
58 #endif