diff options
author | Dehao Chen <dehao@google.com> | 2016-02-22 22:14:14 +0000 |
---|---|---|
committer | Dehao Chen <dehao@google.com> | 2016-02-22 22:14:14 +0000 |
commit | c5f76f73474499012b9559e917ec2368b659618a (patch) | |
tree | 276b18aedfce76a058ea6cfcea03b513337958de /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | 9b4880e7ecafafcbd8ca749f5985df31340e075f (diff) | |
download | llvm-c5f76f73474499012b9559e917ec2368b659618a.zip llvm-c5f76f73474499012b9559e917ec2368b659618a.tar.gz llvm-c5f76f73474499012b9559e917ec2368b659618a.tar.bz2 |
Add prefix based function layout when profile is available.
Summary: If a function is hot, put it in text.hot section.
Reviewers: davidxl
Subscribers: eraman, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D17460
llvm-svn: 261582
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 81b429a8..624eaec 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -34,6 +34,7 @@ #include "llvm/MC/MCSymbolELF.h" #include "llvm/MC/MCValue.h" #include "llvm/ProfileData/InstrProf.h" +#include "llvm/ProfileData/ProfileCommon.h" #include "llvm/Support/COFF.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/ELF.h" @@ -244,6 +245,11 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) { return ".data.rel.ro"; } +static cl::opt<bool> GroupFunctionsByHotness( + "group-functions-by-hotness", + llvm::cl::desc("Partition hot/cold functions by sections prefix"), + cl::init(false)); + static MCSectionELF * selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV, SectionKind Kind, Mangler &Mang, @@ -294,6 +300,16 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV, Name = getSectionPrefixForGlobal(Kind); } + if (GroupFunctionsByHotness) { + if (const Function *F = dyn_cast<Function>(GV)) { + if (ProfileSummary::isFunctionHot(F)) { + Name += getHotSectionPrefix(); + } else if (ProfileSummary::isFunctionUnlikely(F)) { + Name += getUnlikelySectionPrefix(); + } + } + } + if (EmitUniqueSection && UniqueSectionNames) { Name.push_back('.'); TM.getNameWithPrefix(Name, GV, Mang, true); |