CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
95 lines
3.4 KiB
C++
95 lines
3.4 KiB
C++
//===- StaticDataAnnotator - Annotate static data's section prefix --------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// To reason about module-wide data hotness in a module granularity, this file
|
|
// implements a module pass StaticDataAnnotator to work coordinately with the
|
|
// StaticDataSplitter pass.
|
|
//
|
|
// The StaticDataSplitter pass is a machine function pass. It analyzes data
|
|
// hotness based on code and adds counters in StaticDataProfileInfo via its
|
|
// wrapper pass StaticDataProfileInfoWrapper.
|
|
// The StaticDataProfileInfoWrapper sits in the middle between the
|
|
// StaticDataSplitter and StaticDataAnnotator passes.
|
|
// The StaticDataAnnotator pass is a module pass. It iterates global variables
|
|
// in the module, looks up counters from StaticDataProfileInfo and sets the
|
|
// section prefix based on profiles.
|
|
//
|
|
// The three-pass structure is implemented for practical reasons, to work around
|
|
// the limitation that a module pass based on legacy pass manager cannot make
|
|
// use of MachineBlockFrequencyInfo analysis. In the future, we can consider
|
|
// porting the StaticDataSplitter pass to a module-pass using the new pass
|
|
// manager framework. That way, analysis are lazily computed as opposed to
|
|
// eagerly scheduled, and a module pass can use MachineBlockFrequencyInfo.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Analysis/ProfileSummaryInfo.h"
|
|
#include "llvm/Analysis/StaticDataProfileInfo.h"
|
|
#include "llvm/CodeGen/Passes.h"
|
|
#include "llvm/IR/Analysis.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/IR/PassManager.h"
|
|
#include "llvm/InitializePasses.h"
|
|
#include "llvm/Pass.h"
|
|
|
|
#define DEBUG_TYPE "static-data-annotator"
|
|
|
|
using namespace llvm;
|
|
|
|
/// A module pass which iterates global variables in the module and annotates
|
|
/// their section prefixes based on profile-driven analysis.
|
|
class StaticDataAnnotator : public ModulePass {
|
|
public:
|
|
static char ID;
|
|
|
|
StaticDataProfileInfo *SDPI = nullptr;
|
|
const ProfileSummaryInfo *PSI = nullptr;
|
|
|
|
StaticDataAnnotator() : ModulePass(ID) {}
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
AU.addRequired<StaticDataProfileInfoWrapperPass>();
|
|
AU.addRequired<ProfileSummaryInfoWrapperPass>();
|
|
AU.setPreservesAll();
|
|
ModulePass::getAnalysisUsage(AU);
|
|
}
|
|
|
|
StringRef getPassName() const override { return "Static Data Annotator"; }
|
|
|
|
bool runOnModule(Module &M) override;
|
|
};
|
|
|
|
bool StaticDataAnnotator::runOnModule(Module &M) {
|
|
SDPI = &getAnalysis<StaticDataProfileInfoWrapperPass>()
|
|
.getStaticDataProfileInfo();
|
|
PSI = &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
|
|
|
|
if (!PSI->hasProfileSummary())
|
|
return false;
|
|
|
|
bool Changed = false;
|
|
for (auto &GV : M.globals()) {
|
|
if (!llvm::memprof::IsAnnotationOK(GV))
|
|
continue;
|
|
|
|
StringRef SectionPrefix = SDPI->getConstantSectionPrefix(&GV, PSI);
|
|
// setSectionPrefix returns true if the section prefix is updated.
|
|
Changed |= GV.setSectionPrefix(SectionPrefix);
|
|
}
|
|
|
|
return Changed;
|
|
}
|
|
|
|
char StaticDataAnnotator::ID = 0;
|
|
|
|
INITIALIZE_PASS(StaticDataAnnotator, DEBUG_TYPE, "Static Data Annotator", false,
|
|
false)
|
|
|
|
ModulePass *llvm::createStaticDataAnnotatorPass() {
|
|
return new StaticDataAnnotator();
|
|
}
|