LLVM  16.0.0git
ProfDataUtils.h
Go to the documentation of this file.
1 //===- llvm/IR/ProfDataUtils.h - Profiling Metadata Utilities ---*- 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 /// @file
10 /// This file contains the declarations for profiling metadata utility
11 /// functions.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_IR_PROFDATAUTILS_H
16 #define LLVM_IR_PROFDATAUTILS_H
17 
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/IR/Metadata.h"
21 
22 namespace llvm {
23 
24 /// Checks if an Instruction has MD_prof Metadata
25 bool hasProfMD(const Instruction &I);
26 
27 /// Checks if an MDNode contains Branch Weight Metadata
28 bool isBranchWeightMD(const MDNode *ProfileData);
29 
30 /// Checks if an instructions has Branch Weight Metadata
31 ///
32 /// \param I The instruction to check
33 /// \returns True if I has an MD_prof node containing Branch Weights. False
34 /// otherwise.
35 bool hasBranchWeightMD(const Instruction &I);
36 
37 /// Extract branch weights from MD_prof metadata
38 ///
39 /// \param ProfileData A pointer to an MDNode.
40 /// \param [out] Weights An output vector to fill with branch weights
41 /// \returns True if weights were extracted, False otherwise. When false Weights
42 /// will be cleared.
43 bool extractBranchWeights(const MDNode *ProfileData,
44  SmallVectorImpl<uint32_t> &Weights);
45 
46 /// Extract branch weights attatched to an Instruction
47 ///
48 /// \param I The Instruction to extract weights from.
49 /// \param [out] Weights An output vector to fill with branch weights
50 /// \returns True if weights were extracted, False otherwise. When false Weights
51 /// will be cleared.
52 bool extractBranchWeights(const Instruction &I,
53  SmallVectorImpl<uint32_t> &Weights);
54 
55 /// Extract branch weights from a conditional branch or select Instruction.
56 ///
57 /// \param I The instruction to extract branch weights from.
58 /// \param [out] TrueVal will contain the branch weight for the True branch
59 /// \param [out] FalseVal will contain the branch weight for the False branch
60 /// \returns True on success with profile weights filled in. False if no
61 /// metadata or invalid metadata was found.
62 bool extractBranchWeights(const Instruction &I, uint64_t &TrueVal,
64 
65 /// Retrieve the total of all weights from MD_prof data.
66 ///
67 /// \param ProfileData The profile data to extract the total weight from
68 /// \param [out] TotalWeights input variable to fill with total weights
69 /// \returns True on success with profile total weights filled in. False if no
70 /// metadata was found.
71 bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalWeights);
72 
73 } // namespace llvm
74 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::isBranchWeightMD
bool isBranchWeightMD(const MDNode *ProfileData)
Checks if an MDNode contains Branch Weight Metadata.
Definition: ProfDataUtils.cpp:95
Metadata.h
llvm::tgtok::FalseVal
@ FalseVal
Definition: TGLexer.h:62
Twine.h
llvm::hasBranchWeightMD
bool hasBranchWeightMD(const Instruction &I)
Checks if an instructions has Branch Weight Metadata.
Definition: ProfDataUtils.cpp:99
uint64_t
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::hasProfMD
bool hasProfMD(const Instruction &I)
Checks if an Instruction has MD_prof Metadata.
Definition: ProfDataUtils.cpp:91
llvm::extractProfTotalWeight
bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalWeights)
Retrieve the total of all weights from MD_prof data.
Definition: ProfDataUtils.cpp:136
SmallVector.h
llvm::extractBranchWeights
bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
Definition: ProfDataUtils.cpp:104
llvm::tgtok::TrueVal
@ TrueVal
Definition: TGLexer.h:62