1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

[llvm] Add -bbsections-cold-text-prefix to emit cold clusters to a different section.

This change adds an option to basic block sections to allow cold
clusters to be assigned a custom text prefix. With a custom prefix such
as ".text.split." (D87840), lld can place them in a separate output section.
The benefits are -

* Empirically shown to improve icache and itlb metrics by 3-5%
(absolute) compared to placing split parts in .text.unlikely.
* Mitigates against poor profiles, eg samplePGO profiles used with the
machine function splitter. Optimizations such as hugepage remapping can
make different decisions at the section granularity.
* Enables section granularity hotness monitoring (checking on the
decisions made during compilation vs sample data from production).

Differential Revision: https://reviews.llvm.org/D87813
This commit is contained in:
Snehasish Kumar 2020-09-16 21:40:00 -07:00
parent 7b42f2f140
commit 74d368792a
4 changed files with 31 additions and 16 deletions

View File

@ -10,9 +10,12 @@
#define LLVM_CODEGEN_BASICBLOCKSECTIONUTILS_H
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
namespace llvm {
extern cl::opt<std::string> BBSectionsColdTextPrefix;
class MachineFunction;
class MachineBasicBlock;

View File

@ -79,6 +79,15 @@ using llvm::StringMap;
using llvm::StringRef;
using namespace llvm;
// Placing the cold clusters in a separate section mitigates against poor
// profiles and allows optimizations such as hugepage mapping to be applied at a
// section granularity. Where necessary, users should set this to ".text.split."
// which is recognized by lld via the `-z keep-text-section-prefix` flag.
cl::opt<std::string> llvm::BBSectionsColdTextPrefix(
"bbsections-cold-text-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.

View File

@ -21,6 +21,7 @@
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/CodeGen/BasicBlockSectionUtils.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
@ -833,7 +834,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
// name, or a unique ID for the section.
SmallString<128> Name;
if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
Name += ".text.unlikely.";
Name += BBSectionsColdTextPrefix;
Name += MBB.getParent()->getName();
} else if (MBB.getSectionID() == MBBSectionID::ExceptionSectionID) {
Name += ".text.eh.";

View File

@ -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-text-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,9 @@ declare i32 @_Z3foov() #1
; LINUX-SECTIONS-NOT: .section .text._Z3bazb._Z3bazb.2,"ax",@progbits,unique
; LINUX-SECTIONS: .LBB0_2:
; LINUX-SECTIONS: .size _Z3bazb, .Lfunc_end{{[0-9]}}-_Z3bazb
; LINUX-SPLIT: .section .text.split._Z3bazb,"ax",@progbits
; LINUX-SPLIT-NEXT: _Z3bazb.cold:
; LINUX-SPLIT-NEXT: callq _Z3barv
; LINUX-SPLIT: .LBB0_2:
; LINUX-SPLIT: .LBB_END0_2: