Skip to content

Commit 9277bcd

Browse files
Revert "[NFCI][Globals] In GlobalObjects::setSectionPrefix, do conditional update if existing prefix is not equivalent to the new one. Returns whether prefix changed." (#159159)
Reverts #158460 due to buildbot failures
1 parent 20d4e5c commit 9277bcd

File tree

7 files changed

+12
-105
lines changed

7 files changed

+12
-105
lines changed

llvm/include/llvm/IR/GlobalObject.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ class GlobalObject : public GlobalValue {
121121
/// appropriate default object file section.
122122
LLVM_ABI void setSection(StringRef S);
123123

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

129127
/// Get the section prefix for this global object.
130128
LLVM_ABI std::optional<StringRef> getSectionPrefix() const;

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,23 +583,23 @@ bool CodeGenPrepare::_run(Function &F) {
583583
// if requested.
584584
if (BBSectionsGuidedSectionPrefix && BBSectionsProfileReader &&
585585
BBSectionsProfileReader->isFunctionHot(F.getName())) {
586-
EverMadeChange |= F.setSectionPrefix("hot");
586+
F.setSectionPrefix("hot");
587587
} else if (ProfileGuidedSectionPrefix) {
588588
// The hot attribute overwrites profile count based hotness while profile
589589
// counts based hotness overwrite the cold attribute.
590590
// This is a conservative behabvior.
591591
if (F.hasFnAttribute(Attribute::Hot) ||
592592
PSI->isFunctionHotInCallGraph(&F, *BFI))
593-
EverMadeChange |= F.setSectionPrefix("hot");
593+
F.setSectionPrefix("hot");
594594
// If PSI shows this function is not hot, we will placed the function
595595
// into unlikely section if (1) PSI shows this is a cold function, or
596596
// (2) the function has a attribute of cold.
597597
else if (PSI->isFunctionColdInCallGraph(&F, *BFI) ||
598598
F.hasFnAttribute(Attribute::Cold))
599-
EverMadeChange |= F.setSectionPrefix("unlikely");
599+
F.setSectionPrefix("unlikely");
600600
else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() &&
601601
PSI->isFunctionHotnessUnknown(F))
602-
EverMadeChange |= F.setSectionPrefix("unknown");
602+
F.setSectionPrefix("unknown");
603603
}
604604

605605
/// This optimization identifies DIV instructions that can be

llvm/lib/CodeGen/StaticDataAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ bool StaticDataAnnotator::runOnModule(Module &M) {
9191
if (SectionPrefix.empty())
9292
continue;
9393

94-
Changed |= GV.setSectionPrefix(SectionPrefix);
94+
GV.setSectionPrefix(SectionPrefix);
95+
Changed = true;
9596
}
9697

9798
return Changed;

llvm/lib/IR/Globals.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,10 @@ void GlobalObject::setSection(StringRef S) {
288288
setGlobalObjectFlag(HasSectionHashEntryBit, !S.empty());
289289
}
290290

291-
bool GlobalObject::setSectionPrefix(StringRef Prefix) {
292-
StringRef ExistingPrefix;
293-
if (std::optional<StringRef> MaybePrefix = getSectionPrefix())
294-
ExistingPrefix = *MaybePrefix;
295-
296-
if (ExistingPrefix == Prefix)
297-
return false;
298-
299-
if (Prefix.empty()) {
300-
setMetadata(LLVMContext::MD_section_prefix, nullptr);
301-
return true;
302-
}
291+
void GlobalObject::setSectionPrefix(StringRef Prefix) {
303292
MDBuilder MDB(getContext());
304293
setMetadata(LLVMContext::MD_section_prefix,
305294
MDB.createGlobalObjectSectionPrefix(Prefix));
306-
return true;
307295
}
308296

309297
std::optional<StringRef> GlobalObject::getSectionPrefix() const {

llvm/lib/Transforms/Instrumentation/MemProfUse.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,13 @@ bool MemProfUsePass::annotateGlobalVariables(
848848
// So we just print out the static data section prefix in LLVM_DEBUG.
849849
if (Record && Record->AccessCount > 0) {
850850
++NumOfMemProfHotGlobalVars;
851-
Changed |= GVar.setSectionPrefix("hot");
851+
GVar.setSectionPrefix("hot");
852+
Changed = true;
852853
LLVM_DEBUG(dbgs() << "Global variable " << Name
853854
<< " is annotated as hot\n");
854855
} else if (DataAccessProf->isKnownColdSymbol(Name)) {
855856
++NumOfMemProfColdGlobalVars;
856-
Changed |= GVar.setSectionPrefix("unlikely");
857+
GVar.setSectionPrefix("unlikely");
857858
Changed = true;
858859
LLVM_DEBUG(dbgs() << "Global variable " << Name
859860
<< " is annotated as unlikely\n");

llvm/unittests/IR/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ add_llvm_unittest(IRTests
2828
DominatorTreeBatchUpdatesTest.cpp
2929
DroppedVariableStatsIRTest.cpp
3030
FunctionTest.cpp
31-
GlobalObjectTest.cpp
3231
PassBuilderCallbacksTest.cpp
3332
IRBuilderTest.cpp
3433
InstructionsTest.cpp

llvm/unittests/IR/GlobalObjectTest.cpp

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)