1 //===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_EDGEBUNDLES_H
17 #define LLVM_CODEGEN_EDGEBUNDLES_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/IntEqClasses.h"
21 #include "llvm/ADT/Twine.h"
22 #include "llvm/CodeGen/MachineFunctionPass.h"
26 class EdgeBundles : public MachineFunctionPass {
27 const MachineFunction *MF;
29 /// EC - Each edge bundle is an equivalence class. The keys are:
30 /// 2*BB->getNumber() -> Ingoing bundle.
31 /// 2*BB->getNumber()+1 -> Outgoing bundle.
34 /// Blocks - Map each bundle to a list of basic block numbers.
35 SmallVector<SmallVector<unsigned, 8>, 4> Blocks;
39 EdgeBundles() : MachineFunctionPass(ID) {}
41 /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
42 /// bundle number for basic block #N
43 unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
45 /// getNumBundles - Return the total number of bundles in the CFG.
46 unsigned getNumBundles() const { return EC.getNumClasses(); }
48 /// getBlocks - Return an array of blocks that are connected to Bundle.
49 ArrayRef<unsigned> getBlocks(unsigned Bundle) const { return Blocks[Bundle]; }
51 /// getMachineFunction - Return the last machine function computed.
52 const MachineFunction *getMachineFunction() const { return MF; }
54 /// view - Visualize the annotated bipartite CFG with Graphviz.
58 bool runOnMachineFunction(MachineFunction&) override;
59 void getAnalysisUsage(AnalysisUsage&) const override;
62 } // end namespace llvm