[llvm] [BasicBlockSections] Split cold parts of custom-section functions. (PR #66731)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 09:40:48 PDT 2023


================
@@ -1038,20 +1038,30 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
   // under the .text.eh prefix. For regular sections, we either use a unique
   // name, or a unique ID for the section.
   SmallString<128> Name;
-  if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
-    Name += BBSectionsColdTextPrefix;
-    Name += MBB.getParent()->getName();
-  } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
-    Name += ".text.eh.";
-    Name += MBB.getParent()->getName();
+  StringRef FunctionSectionName = MBB.getParent()->getSection()->getName();
+  if (!FunctionSectionName.equals(".text") &&
----------------
snehasish wrote:

It's a little easier to read if we drop the not on each, make this an OR clause and move the else part into this block.

Also it would be great to refactor this out into a separate function like `std::string makeSectionName(MachineBasicBlock& MBB ...)` then we could add some unit tests which check the returned string.  What do you think?


https://github.com/llvm/llvm-project/pull/66731


More information about the llvm-commits mailing list