1218885Sdim//===-------- EdgeBundles.h - Bundles of CFG edges --------------*- c++ -*-===// 2218885Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6218885Sdim// 7218885Sdim//===----------------------------------------------------------------------===// 8218885Sdim// 9218885Sdim// The EdgeBundles analysis forms equivalence classes of CFG edges such that all 10218885Sdim// edges leaving a machine basic block are in the same bundle, and all edges 11218885Sdim// leaving a basic block are in the same bundle. 12218885Sdim// 13218885Sdim//===----------------------------------------------------------------------===// 14218885Sdim 15218885Sdim#ifndef LLVM_CODEGEN_EDGEBUNDLES_H 16218885Sdim#define LLVM_CODEGEN_EDGEBUNDLES_H 17218885Sdim 18221345Sdim#include "llvm/ADT/ArrayRef.h" 19218885Sdim#include "llvm/ADT/IntEqClasses.h" 20234353Sdim#include "llvm/ADT/Twine.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. 48239462Sdim ArrayRef<unsigned> getBlocks(unsigned Bundle) const { 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: 57276479Sdim bool runOnMachineFunction(MachineFunction&) override; 58276479Sdim void getAnalysisUsage(AnalysisUsage&) const override; 59218885Sdim}; 60218885Sdim 61218885Sdim} // end namespace llvm 62218885Sdim 63218885Sdim#endif 64