[Alignment][NFC] Support compile time constants
[llvm-core.git] / include / llvm / CodeGen / EdgeBundles.h
blob28cdf54e0575144fc17cdfb5030139ac2dc55073
1 //===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // The EdgeBundles analysis forms equivalence classes of CFG edges such that all
10 // edges leaving a machine basic block are in the same bundle, and all edges
11 // leaving a basic block are in the same bundle.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_EDGEBUNDLES_H
16 #define LLVM_CODEGEN_EDGEBUNDLES_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/IntEqClasses.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/CodeGen/MachineFunctionPass.h"
23 namespace llvm {
25 class EdgeBundles : public MachineFunctionPass {
26 const MachineFunction *MF;
28 /// EC - Each edge bundle is an equivalence class. The keys are:
29 /// 2*BB->getNumber() -> Ingoing bundle.
30 /// 2*BB->getNumber()+1 -> Outgoing bundle.
31 IntEqClasses EC;
33 /// Blocks - Map each bundle to a list of basic block numbers.
34 SmallVector<SmallVector<unsigned, 8>, 4> Blocks;
36 public:
37 static char ID;
38 EdgeBundles() : MachineFunctionPass(ID) {}
40 /// getBundle - Return the ingoing (Out = false) or outgoing (Out = true)
41 /// bundle number for basic block #N
42 unsigned getBundle(unsigned N, bool Out) const { return EC[2 * N + Out]; }
44 /// getNumBundles - Return the total number of bundles in the CFG.
45 unsigned getNumBundles() const { return EC.getNumClasses(); }
47 /// getBlocks - Return an array of blocks that are connected to Bundle.
48 ArrayRef<unsigned> getBlocks(unsigned Bundle) const { return Blocks[Bundle]; }
50 /// getMachineFunction - Return the last machine function computed.
51 const MachineFunction *getMachineFunction() const { return MF; }
53 /// view - Visualize the annotated bipartite CFG with Graphviz.
54 void view() const;
56 private:
57 bool runOnMachineFunction(MachineFunction&) override;
58 void getAnalysisUsage(AnalysisUsage&) const override;
61 } // end namespace llvm
63 #endif