[llvm-branch-commits] [llvm] [StaticDataLayout] Factor out a helper function for section prefix eligibility and use it in both optimizer and codegen (PR #162348)
Mingming Liu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Oct 7 14:45:30 PDT 2025
================
@@ -6,6 +6,43 @@
#include "llvm/ProfileData/InstrProf.h"
using namespace llvm;
+
+namespace llvm {
+namespace memprof {
+// Returns true iff the global variable has custom section either by
+// __attribute__((section("name")))
+// (https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate)
+// or #pragma clang section directives
+// (https://clang.llvm.org/docs/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section).
+static bool hasExplicitSectionName(const GlobalVariable &GVar) {
+ if (GVar.hasSection())
+ return true;
+
+ auto Attrs = GVar.getAttributes();
+ if (Attrs.hasAttribute("bss-section") || Attrs.hasAttribute("data-section") ||
+ Attrs.hasAttribute("relro-section") ||
+ Attrs.hasAttribute("rodata-section"))
+ return true;
+ return false;
+}
+
+AnnotationKind getAnnotationKind(const GlobalVariable &GV) {
+ if (GV.isDeclarationForLinker())
+ return AnnotationKind::DeclForLinker;
+ StringRef Name = GV.getName();
+ if (Name.starts_with("llvm."))
----------------
mingmingl-llvm wrote:
ah sorry, you are correct.
This is from another similar call site [1] and this PR means to cover that one. Updated the PR.
[1] https://github.com/llvm/llvm-project/blob/30b9ef8088c35d86fbdffebe0ba8cdcea1afe6eb/llvm/lib/CodeGen/StaticDataSplitter.cpp#L133-L137
https://github.com/llvm/llvm-project/pull/162348
More information about the llvm-branch-commits
mailing list