[StaticDataLayout] Factor out a helper function for section prefix eligibility and use it in both optimizer and codegen (#162348)
This change introduces new helper functions to check if a global
variable is eligible for section prefix annotation.
This shared logic is used by both MemProfUse and StaticDataSplitter to
avoid annotating ineligible variables.
This is the 2nd patch as a split of
https://github.com/llvm/llvm-project/pull/155337