EdgeBundles.h revision 221345
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" 21218885Sdim#include "llvm/CodeGen/MachineFunctionPass.h" 22218885Sdim 23218885Sdimnamespace llvm { 24218885Sdim 25218885Sdimclass EdgeBundles : public MachineFunctionPass { 26218885Sdim const MachineFunction *MF; 27218885Sdim 28218885Sdim /// EC - Each edge bundle is an equivalence class. The keys are: 29218885Sdim /// 2*BB->getNumber() -> Ingoing bundle. 30218885Sdim /// 2*BB->getNumber()+1 -> Outgoing bundle. 31218885Sdim IntEqClasses EC; 32218885Sdim 33221345Sdim /// Blocks - Map each bundle to a list of basic block numbers. 34221345Sdim SmallVector<SmallVector<unsigned, 8>, 4> Blocks; 35221345Sdim 36218885Sdimpublic: 37218885Sdim static char ID; 38218885Sdim EdgeBundles() : MachineFunctionPass(ID) {} 39218885Sdim 40218885Sdim /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true) 41218885Sdim /// bundle number for basic block #N 42218885Sdim unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; } 43218885Sdim 44218885Sdim /// getNumBundles - Return the total number of bundles in the CFG. 45218885Sdim unsigned getNumBundles() const { return EC.getNumClasses(); } 46218885Sdim 47221345Sdim /// getBlocks - Return an array of blocks that are connected to Bundle. 48221345Sdim ArrayRef<unsigned> getBlocks(unsigned Bundle) { return Blocks[Bundle]; } 49221345Sdim 50218885Sdim /// getMachineFunction - Return the last machine function computed. 51218885Sdim const MachineFunction *getMachineFunction() const { return MF; } 52218885Sdim 53218885Sdim /// view - Visualize the annotated bipartite CFG with Graphviz. 54218885Sdim void view() const; 55218885Sdim 56218885Sdimprivate: 57218885Sdim virtual bool runOnMachineFunction(MachineFunction&); 58218885Sdim virtual void getAnalysisUsage(AnalysisUsage&) const; 59218885Sdim}; 60218885Sdim 61218885Sdim/// Specialize WriteGraph, the standard implementation won't work. 62218885Sdimraw_ostream &WriteGraph(raw_ostream &O, const EdgeBundles &G, 63218885Sdim bool ShortNames = false, 64218885Sdim const std::string &Title = ""); 65218885Sdim 66218885Sdim} // end namespace llvm 67218885Sdim 68218885Sdim#endif 69