Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions llvm/include/llvm/IR/GlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ class GlobalObject : public GlobalValue {
/// appropriate default object file section.
LLVM_ABI void setSection(StringRef S);

/// If existing prefix is different from \p Prefix, set it to \p Prefix. If \p
/// Prefix is empty, the set clears the existing metadata. Returns true if
/// section prefix changed and false otherwise.
LLVM_ABI bool setSectionPrefix(StringRef Prefix);
/// Set the section prefix for this global object.
LLVM_ABI void setSectionPrefix(StringRef Prefix);

/// Get the section prefix for this global object.
LLVM_ABI std::optional<StringRef> getSectionPrefix() const;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,23 +583,23 @@ bool CodeGenPrepare::_run(Function &F) {
// if requested.
if (BBSectionsGuidedSectionPrefix && BBSectionsProfileReader &&
BBSectionsProfileReader->isFunctionHot(F.getName())) {
EverMadeChange |= F.setSectionPrefix("hot");
F.setSectionPrefix("hot");
} else if (ProfileGuidedSectionPrefix) {
// The hot attribute overwrites profile count based hotness while profile
// counts based hotness overwrite the cold attribute.
// This is a conservative behabvior.
if (F.hasFnAttribute(Attribute::Hot) ||
PSI->isFunctionHotInCallGraph(&F, *BFI))
EverMadeChange |= F.setSectionPrefix("hot");
F.setSectionPrefix("hot");
// If PSI shows this function is not hot, we will placed the function
// into unlikely section if (1) PSI shows this is a cold function, or
// (2) the function has a attribute of cold.
else if (PSI->isFunctionColdInCallGraph(&F, *BFI) ||
F.hasFnAttribute(Attribute::Cold))
EverMadeChange |= F.setSectionPrefix("unlikely");
F.setSectionPrefix("unlikely");
else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() &&
PSI->isFunctionHotnessUnknown(F))
EverMadeChange |= F.setSectionPrefix("unknown");
F.setSectionPrefix("unknown");
}

/// This optimization identifies DIV instructions that can be
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/StaticDataAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ bool StaticDataAnnotator::runOnModule(Module &M) {
if (SectionPrefix.empty())
continue;

Changed |= GV.setSectionPrefix(SectionPrefix);
GV.setSectionPrefix(SectionPrefix);
Changed = true;
}

return Changed;
Expand Down
14 changes: 1 addition & 13 deletions llvm/lib/IR/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,10 @@ void GlobalObject::setSection(StringRef S) {
setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
}

bool GlobalObject::setSectionPrefix(StringRef Prefix) {
StringRef ExistingPrefix;
if (std::optional<StringRef> MaybePrefix = getSectionPrefix())
ExistingPrefix = *MaybePrefix;

if (ExistingPrefix == Prefix)
return false;

if (Prefix.empty()) {
setMetadata(LLVMContext::MD_section_prefix, nullptr);
return true;
}
void GlobalObject::setSectionPrefix(StringRef Prefix) {
MDBuilder MDB(getContext());
setMetadata(LLVMContext::MD_section_prefix,
MDB.createGlobalObjectSectionPrefix(Prefix));
return true;
}

std::optional<StringRef> GlobalObject::getSectionPrefix() const {
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,13 @@ bool MemProfUsePass::annotateGlobalVariables(
// So we just print out the static data section prefix in LLVM_DEBUG.
if (Record && Record->AccessCount > 0) {
++NumOfMemProfHotGlobalVars;
Changed |= GVar.setSectionPrefix("hot");
GVar.setSectionPrefix("hot");
Changed = true;
LLVM_DEBUG(dbgs() << "Global variable " << Name
<< " is annotated as hot\n");
} else if (DataAccessProf->isKnownColdSymbol(Name)) {
++NumOfMemProfColdGlobalVars;
Changed |= GVar.setSectionPrefix("unlikely");
GVar.setSectionPrefix("unlikely");
Changed = true;
LLVM_DEBUG(dbgs() << "Global variable " << Name
<< " is annotated as unlikely\n");
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ add_llvm_unittest(IRTests
DominatorTreeBatchUpdatesTest.cpp
DroppedVariableStatsIRTest.cpp
FunctionTest.cpp
GlobalObjectTest.cpp
PassBuilderCallbacksTest.cpp
IRBuilderTest.cpp
InstructionsTest.cpp
Expand Down
80 changes: 0 additions & 80 deletions llvm/unittests/IR/GlobalObjectTest.cpp

This file was deleted.

Loading