[PATCH] D87813: [llvm][lld] Add an option to emit cold clusters to a different section.

Snehasish Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 10:17:34 PDT 2020


snehasish updated this revision to Diff 292553.
snehasish added a comment.

Drop lld/ELF/Writer.cpp changes.

- Moved the changes to D87840 <https://reviews.llvm.org/D87840>.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87813/new/

https://reviews.llvm.org/D87813

Files:
  llvm/lib/CodeGen/BasicBlockSections.cpp
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/X86/basic-block-sections-cold.ll


Index: llvm/test/CodeGen/X86/basic-block-sections-cold.ll
===================================================================
--- llvm/test/CodeGen/X86/basic-block-sections-cold.ll
+++ llvm/test/CodeGen/X86/basic-block-sections-cold.ll
@@ -2,25 +2,21 @@
 ; Basic block with id 1 and 2 must be in the cold section.
 ; RUN: echo '!_Z3bazb' > %t
 ; RUN: echo '!!0' >> %t
-; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t -unique-basic-block-section-names -bbsections-cold-prefix=".text.split." | FileCheck %s -check-prefix=LINUX-SPLIT
 
-define void @_Z3bazb(i1 zeroext) nounwind {
-  %2 = alloca i8, align 1
-  %3 = zext i1 %0 to i8
-  store i8 %3, i8* %2, align 1
-  %4 = load i8, i8* %2, align 1
-  %5 = trunc i8 %4 to i1
-  br i1 %5, label %6, label %8
+define void @_Z3bazb(i1 zeroext %0) nounwind {
+  br i1 %0, label %2, label %4
 
-6:                                                ; preds = %1
-  %7 = call i32 @_Z3barv()
-  br label %10
+2:                                                ; preds = %1
+  %3 = call i32 @_Z3barv()
+  br label %6
 
-8:                                                ; preds = %1
-  %9 = call i32 @_Z3foov()
-  br label %10
+4:                                                ; preds = %1
+  %5 = call i32 @_Z3foov()
+  br label %6
 
-10:                                               ; preds = %8, %6
+6:                                                ; preds = %2, %4
   ret void
 }
 
@@ -38,3 +34,6 @@
 ; LINUX-SECTIONS-NOT: .section        .text._Z3bazb._Z3bazb.2,"ax", at progbits,unique
 ; LINUX-SECTIONS: .LBB0_2:
 ; LINUX-SECTIONS: .size   _Z3bazb, .Lfunc_end{{[0-9]}}-_Z3bazb
+
+; LINUX-SPLIT: .section	.text.split._Z3bazb,"ax", at progbits
+; LINUX-SPLIT: _Z3bazb.cold:
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -66,6 +66,8 @@
 using namespace llvm;
 using namespace dwarf;
 
+extern cl::opt<std::string> ColdSectionTextPrefix;
+
 static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
                              StringRef &Section) {
   SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
@@ -873,7 +875,7 @@
   // name, or a unique ID for the section.
   SmallString<128> Name;
   if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
-    Name += ".text.unlikely.";
+    Name += ColdSectionTextPrefix;
     Name += MBB.getParent()->getName();
   } else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
     Name += ".text.eh.";
Index: llvm/lib/CodeGen/BasicBlockSections.cpp
===================================================================
--- llvm/lib/CodeGen/BasicBlockSections.cpp
+++ llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -79,6 +79,11 @@
 using llvm::StringRef;
 using namespace llvm;
 
+cl::opt<std::string> ColdSectionTextPrefix(
+    "bbsections-cold-prefix",
+    cl::desc("The text prefix to use for cold basic block clusters."),
+    cl::init(".text.unlikely."), cl::Hidden);
+
 namespace {
 
 // This struct represents the cluster information for a machine basic block.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87813.292553.patch
Type: text/x-patch
Size: 3513 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200917/5d637a5f/attachment.bin>


More information about the llvm-commits mailing list