[llvm] [NFCI][Globals] In GlobalObjects::setSectionPrefix, do conditional update if existing prefix is not equivalent to the new one. Returns whether prefix changed. (PR #158460)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 11:03:57 PDT 2025
================
@@ -289,11 +289,28 @@ void GlobalObject::setSection(StringRef S) {
}
void GlobalObject::setSectionPrefix(StringRef Prefix) {
+ if (Prefix.empty()) {
+ setMetadata(LLVMContext::MD_section_prefix, nullptr);
+ return;
+ }
MDBuilder MDB(getContext());
setMetadata(LLVMContext::MD_section_prefix,
MDB.createGlobalObjectSectionPrefix(Prefix));
}
+bool GlobalObject::updateSectionPrefix(StringRef Prefix) {
+ auto MD = getMetadata(LLVMContext::MD_section_prefix);
----------------
mingmingl-llvm wrote:
Per offline discussion, the question is more about why not changing `setSectionPrefix` in place rather than calling `update` inside `set`. Technically changing `setSectionPrefix` is definitely an option, but I previously choose to add `update` to not affect existing callers. That said, compile-time changes are trivial enough, and all existing use cases also tracks whether a _change_ happens on the IR/MIR, so I just update the PR to change `setSectionPrefix` in place for simplicity. One other notable change is that codegenprepare previously doesn't track function prefix change as `EverMadeChange`, but this patch changes it to be. PTAL, thanks!
https://github.com/llvm/llvm-project/pull/158460
More information about the llvm-commits
mailing list