EdgeBundles.h revision 234353
1218885Sdim//===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===//
2218885Sdim//
3218885Sdim//                     The LLVM Compiler Infrastructure
4218885Sdim//
5218885Sdim// This file is distributed under the University of Illinois Open Source
6218885Sdim// License. See LICENSE.TXT for details.
7218885Sdim//
8218885Sdim//===----------------------------------------------------------------------===//
9218885Sdim//
10218885Sdim// The EdgeBundles analysis forms equivalence classes of CFG edges such that all
11218885Sdim// edges leaving a machine basic block are in the same bundle, and all edges
12218885Sdim// leaving a basic block are in the same bundle.
13218885Sdim//
14218885Sdim//===----------------------------------------------------------------------===//
15218885Sdim
16218885Sdim#ifndef LLVM_CODEGEN_EDGEBUNDLES_H
17218885Sdim#define LLVM_CODEGEN_EDGEBUNDLES_H
18218885Sdim
19221345Sdim#include "llvm/ADT/ArrayRef.h"
20218885Sdim#include "llvm/ADT/IntEqClasses.h"
21234353Sdim#include "llvm/ADT/Twine.h"
22218885Sdim#include "llvm/CodeGen/MachineFunctionPass.h"
23218885Sdim
24218885Sdimnamespace llvm {
25218885Sdim
26218885Sdimclass EdgeBundles : public MachineFunctionPass {
27218885Sdim  const MachineFunction *MF;
28218885Sdim
29218885Sdim  /// EC - Each edge bundle is an equivalence class. The keys are:
30218885Sdim  ///   2*BB->getNumber()   -> Ingoing bundle.
31218885Sdim  ///   2*BB->getNumber()+1 -> Outgoing bundle.
32218885Sdim  IntEqClasses EC;
33218885Sdim
34221345Sdim  /// Blocks - Map each bundle to a list of basic block numbers.
35221345Sdim  SmallVector<SmallVector<unsigned, 8>, 4> Blocks;
36221345Sdim
37218885Sdimpublic:
38218885Sdim  static char ID;
39218885Sdim  EdgeBundles() : MachineFunctionPass(ID) {}
40218885Sdim
41218885Sdim  /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
42218885Sdim  /// bundle number for basic block #N
43218885Sdim  unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
44218885Sdim
45218885Sdim  /// getNumBundles - Return the total number of bundles in the CFG.
46218885Sdim  unsigned getNumBundles() const { return EC.getNumClasses(); }
47218885Sdim
48221345Sdim  /// getBlocks - Return an array of blocks that are connected to Bundle.
49221345Sdim  ArrayRef<unsigned> getBlocks(unsigned Bundle) { return Blocks[Bundle]; }
50221345Sdim
51218885Sdim  /// getMachineFunction - Return the last machine function computed.
52218885Sdim  const MachineFunction *getMachineFunction() const { return MF; }
53218885Sdim
54218885Sdim  /// view - Visualize the annotated bipartite CFG with Graphviz.
55218885Sdim  void view() const;
56218885Sdim
57218885Sdimprivate:
58218885Sdim  virtual bool runOnMachineFunction(MachineFunction&);
59218885Sdim  virtual void getAnalysisUsage(AnalysisUsage&) const;
60218885Sdim};
61218885Sdim
62218885Sdim/// Specialize WriteGraph, the standard implementation won't work.
63218885Sdimraw_ostream &WriteGraph(raw_ostream &O, const EdgeBundles &G,
64218885Sdim                        bool ShortNames = false,
65234353Sdim                        const Twine &Title = "");
66218885Sdim
67218885Sdim} // end namespace llvm
68218885Sdim
69218885Sdim#endif
70