LLVM 23.0.0git
StaticDataAnnotator.cpp
Go to the documentation of this file.
1//===- StaticDataAnnotator - Annotate static data's section prefix --------===//
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// To reason about module-wide data hotness in a module granularity, this file
10// implements a module pass StaticDataAnnotator to work coordinately with the
11// StaticDataSplitter pass.
12//
13// The StaticDataSplitter pass is a machine function pass. It analyzes data
14// hotness based on code and adds counters in StaticDataProfileInfo via its
15// wrapper pass StaticDataProfileInfoWrapper.
16// The StaticDataProfileInfoWrapper sits in the middle between the
17// StaticDataSplitter and StaticDataAnnotator passes.
18// The StaticDataAnnotator pass is a module pass. It iterates global variables
19// in the module, looks up counters from StaticDataProfileInfo and sets the
20// section prefix based on profiles.
21//
22// The three-pass structure is implemented for practical reasons, to work around
23// the limitation that a module pass based on legacy pass manager cannot make
24// use of MachineBlockFrequencyInfo analysis. In the future, we can consider
25// porting the StaticDataSplitter pass to a module-pass using the new pass
26// manager framework. That way, analysis are lazily computed as opposed to
27// eagerly scheduled, and a module pass can use MachineBlockFrequencyInfo.
28//===----------------------------------------------------------------------===//
29
33#include "llvm/CodeGen/Passes.h"
34#include "llvm/IR/Analysis.h"
35#include "llvm/IR/Module.h"
36#include "llvm/IR/PassManager.h"
38#include "llvm/Pass.h"
39
40#define DEBUG_TYPE "static-data-annotator"
41
42using namespace llvm;
43
44/// A module pass which iterates global variables in the module and annotates
45/// their section prefixes based on profile-driven analysis.
47public:
48 static char ID;
49
51
58
59 StringRef getPassName() const override { return "Static Data Annotator"; }
60
61 bool runOnModule(Module &M) override;
62};
63
65 ProfileSummaryInfo *PSI) {
66 if (!PSI || !PSI->hasProfileSummary())
67 return false;
68
69 bool Changed = false;
70 for (auto &GV : M.globals()) {
72 continue;
73
74 StringRef SectionPrefix = SDPI->getConstantSectionPrefix(&GV, PSI);
75 // setSectionPrefix returns true if the section prefix is updated.
76 Changed |= GV.setSectionPrefix(SectionPrefix);
77 }
78
79 return Changed;
80}
81
89
91
98
#define DEBUG_TYPE
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static bool annotateModule(Module &M, StaticDataProfileInfo *SDPI, ProfileSummaryInfo *PSI)
A module pass which iterates global variables in the module and annotates their section prefixes base...
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:255
ModulePass(char &pid)
Definition Pass.h:257
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition Pass.cpp:112
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Analysis providing profile information.
bool hasProfileSummary() const
Returns true if profile summary is available.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
This wraps the StaticDataProfileInfo object as an immutable pass, for a backend pass to operate on.
A class that holds the constants that represent static data and their profile information and provide...
LLVM_ABI StringRef getConstantSectionPrefix(const Constant *C, const ProfileSummaryInfo *PSI) const
Given a constant C, returns a section prefix.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Changed
Pass manager infrastructure for declaring and invalidating analyses.
LLVM_ABI bool IsAnnotationOK(const GlobalVariable &GV)
Returns true if the annotation kind of the global variable GV is AnnotationOK.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI ModulePass * createStaticDataAnnotatorLegacyPass()
createStaticDataAnnotatorPASS - This is a module pass that reads from StaticDataProfileInfoWrapperPas...
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39