LLVM 24.0.0git
BasicBlockMatchingAndInference.h
Go to the documentation of this file.
1//===- llvm/CodeGen/BasicBlockMatchingAndInference.h ------------*- 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// Infer weights for all basic blocks using matching and inference.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_BASIC_BLOCK_AND_INFERENCE_H
14#define LLVM_CODEGEN_BASIC_BLOCK_AND_INFERENCE_H
15
19#include <memory>
20
21namespace llvm {
22
23class Module;
24namespace sampleprof {
26} // namespace sampleprof
27
29private:
30 using Edge = std::pair<const MachineBasicBlock *, const MachineBasicBlock *>;
32 using EdgeWeightMap = DenseMap<Edge, uint64_t>;
33 using BlockEdgeMap = DenseMap<const MachineBasicBlock *,
35
36 struct WeightInfo {
37 // Weight of basic blocks.
38 BlockWeightMap BlockWeights;
39 // Weight of edges.
40 EdgeWeightMap EdgeWeights;
41 };
42
43public:
44 static char ID;
47
48 StringRef getPassName() const override {
49 return "Basic Block Matching and Inference";
50 }
51
52 void getAnalysisUsage(AnalysisUsage &AU) const override;
53
54 bool doInitialization(Module &M) override;
55 bool runOnMachineFunction(MachineFunction &F) override;
56 bool doFinalization(Module &M) override;
57
58 std::optional<WeightInfo> getWeightInfo(StringRef FuncName) const;
59
60private:
61 StringMap<WeightInfo> ProgramWeightInfo;
62 // The supplemental sample profile of the current module. Null if no
63 // supplemental sample profile is given or it fails to load.
64 std::unique_ptr<sampleprof::SampleProfileReader> SampleReader;
65
66 void supplementWithSampleProfile(MachineFunction &MF,
67 WeightInfo &MatchWeight);
68
69 WeightInfo initWeightInfoByMatching(MachineFunction &MF);
70 WeightInfo initWeightInfoByBBID(MachineFunction &MF, const CFGProfile &CFG);
71
72 void generateWeightInfoByInference(MachineFunction &MF,
73 WeightInfo &MatchWeight);
74};
75
76} // end namespace llvm
77
78#endif // LLVM_CODEGEN_BASIC_BLOCK_AND_INFERENCE_H
#define LLVM_ABI
Definition Compiler.h:211
Flatten the CFG
#define F(x, y, z)
Definition MD5.cpp:54
This file provides the interface for the profile inference algorithm, profi.
Represent the analysis usage information of a pass.
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This is an optimization pass for GlobalISel generic memory operations.