LLVM 17.0.0git
BasicBlockSectionsProfileReader.h
Go to the documentation of this file.
1//===-- BasicBlockSectionsProfileReader.h - BB sections profile reader pass ==//
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// This pass creates the basic block cluster info by reading the basic block
10// sections profile. The cluster info will be used by the basic-block-sections
11// pass to arrange basic blocks in their sections.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_BASICBLOCKSECTIONSPROFILEREADER_H
16#define LLVM_CODEGEN_BASICBLOCKSECTIONSPROFILEREADER_H
17
18#include "llvm/ADT/SmallSet.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/StringRef.h"
23#include "llvm/Pass.h"
24#include "llvm/Support/Error.h"
27
28using namespace llvm;
29
30namespace llvm {
31
32// The cluster information for a machine basic block.
34 // Unique ID for this basic block.
35 unsigned BBID;
36 // Cluster ID this basic block belongs to.
37 unsigned ClusterID;
38 // Position of basic block within the cluster.
40};
41
43
45public:
46 static char ID;
47
49 : ImmutablePass(ID), MBuf(Buf) {
52 };
53
57 }
58
59 StringRef getPassName() const override {
60 return "Basic Block Sections Profile Reader";
61 }
62
63 // Returns true if basic block sections profile exist for function \p
64 // FuncName.
65 bool isFunctionHot(StringRef FuncName) const;
66
67 // Returns a pair with first element representing whether basic block sections
68 // profile exist for the function \p FuncName, and the second element
69 // representing the basic block sections profile (cluster info) for this
70 // function. If the first element is true and the second element is empty, it
71 // means unique basic block sections are desired for all basic blocks of the
72 // function.
73 std::pair<bool, SmallVector<BBClusterInfo>>
75
76 /// Read profiles of basic blocks if available here.
77 void initializePass() override;
78
79private:
80 StringRef getAliasName(StringRef FuncName) const {
81 auto R = FuncAliasMap.find(FuncName);
82 return R == FuncAliasMap.end() ? FuncName : R->second;
83 }
84
85 // This contains the basic-block-sections profile.
86 const MemoryBuffer *MBuf = nullptr;
87
88 // This encapsulates the BB cluster information for the whole program.
89 //
90 // For every function name, it contains the cluster information for (all or
91 // some of) its basic blocks. The cluster information for every basic block
92 // includes its cluster ID along with the position of the basic block in that
93 // cluster.
94 ProgramBBClusterInfoMapTy ProgramBBClusterInfo;
95
96 // Some functions have alias names. We use this map to find the main alias
97 // name for which we have mapping in ProgramBBClusterInfo.
98 StringMap<StringRef> FuncAliasMap;
99};
100
101// Creates a BasicBlockSectionsProfileReader pass to parse the basic block
102// sections profile. \p Buf is a memory buffer that contains the list of
103// functions and basic block ids to selectively enable basic block sections.
106
107} // namespace llvm
108#endif // LLVM_CODEGEN_BASICBLOCKSECTIONSPROFILEREADER_H
This file defines the StringMap class.
This file defines the SmallSet class.
This file defines the SmallVector class.
bool isFunctionHot(StringRef FuncName) const
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
std::pair< bool, SmallVector< BBClusterInfo > > getBBClusterInfoForFunction(StringRef FuncName) const
void initializePass() override
Read profiles of basic blocks if available here.
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:282
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:51
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeBasicBlockSectionsProfileReaderPass(PassRegistry &)
ImmutablePass * createBasicBlockSectionsProfileReaderPass(const MemoryBuffer *Buf)