[llvm] r261582 - Add prefix based function layout when profile is available.

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 18:49:02 PST 2016


On Mon, Feb 22, 2016 at 2:14 PM, Dehao Chen via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: dehao
> Date: Mon Feb 22 16:14:14 2016
> New Revision: 261582
>
> URL: http://llvm.org/viewvc/llvm-project?rev=261582&view=rev
> Log:
> 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
>
> Added:
>     llvm/trunk/test/CodeGen/X86/partition-sections.ll
> Modified:
>     llvm/trunk/include/llvm/ProfileData/ProfileCommon.h
>     llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
>     llvm/trunk/lib/ProfileData/ProfileSummary.cpp
>
> Modified: llvm/trunk/include/llvm/ProfileData/ProfileCommon.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/ProfileCommon.h?rev=261582&r1=261581&r2=261582&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/ProfileData/ProfileCommon.h (original)
> +++ llvm/trunk/include/llvm/ProfileData/ProfileCommon.h Mon Feb 22
> 16:14:14 2016
> @@ -21,6 +21,8 @@
>  #define LLVM_PROFILEDATA_PROFILE_COMMON_H
>
>  namespace llvm {
> +class Function;
> +class Module;
>  namespace IndexedInstrProf {
>  struct Summary;
>  }
> @@ -28,6 +30,8 @@ namespace sampleprof {
>  class FunctionSamples;
>  }
>  struct InstrProfRecord;
> +inline const char *getHotSectionPrefix() { return ".hot"; }
> +inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }
>

Shouldn't this be Suffix instead of Prefix?


>  // The profile summary is one or more (Cutoff, MinCount, NumCounts)
> triplets.
>  // The semantics of counts depend on the type of profile. For
> instrumentation
>  // profile, counts are block counts and for sample profile, counts are
> @@ -66,6 +70,10 @@ protected:
>
>  public:
>    static const int Scale = 1000000;
> +  // \brief Returns true if F is a hot function.
> +  static bool isFunctionHot(const Function *F);
> +  // \brief Returns true if F is unlikley executed.
> +  static bool isFunctionUnlikely(const Function *F);
>    inline std::vector<ProfileSummaryEntry> &getDetailedSummary();
>    void computeDetailedSummary();
>    /// \brief A vector of useful cutoff values for detailed summary.
>
> Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=261582&r1=261581&r2=261582&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
> +++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Mon Feb 22
> 16:14:14 2016
> @@ -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 getSectionPrefixForGlob
>    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
>      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);
>
> Modified: llvm/trunk/lib/ProfileData/ProfileSummary.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/ProfileSummary.cpp?rev=261582&r1=261581&r2=261582&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/ProfileData/ProfileSummary.cpp (original)
> +++ llvm/trunk/lib/ProfileData/ProfileSummary.cpp Mon Feb 22 16:14:14 2016
> @@ -11,6 +11,9 @@
>  //
>
>  //===----------------------------------------------------------------------===//
>
> +#include "llvm/IR/Attributes.h"
> +#include "llvm/IR/Function.h"
> +#include "llvm/IR/Module.h"
>  #include "llvm/ProfileData/InstrProf.h"
>  #include "llvm/ProfileData/ProfileCommon.h"
>  #include "llvm/ProfileData/SampleProf.h"
> @@ -75,6 +78,24 @@ void ProfileSummary::computeDetailedSumm
>    }
>  }
>
> +// Returns true if the function is a hot function.
> +bool ProfileSummary::isFunctionHot(const Function *F) {
> +  // FIXME: update when summary data is stored in module's metadata.
> +  return false;
> +}
> +
> +// Returns true if the function is a cold function.
> +bool ProfileSummary::isFunctionUnlikely(const Function *F) {
> +  if (F->hasFnAttribute(Attribute::Cold)) {
> +    return true;
> +  }
> +  if (!F->getEntryCount()) {
> +    return false;
> +  }
> +  // FIXME: update when summary data is stored in module's metadata.
> +  return (*F->getEntryCount()) == 0;
> +}
> +
>  InstrProfSummary::InstrProfSummary(const IndexedInstrProf::Summary &S)
>      : ProfileSummary(), MaxInternalBlockCount(S.get(
>
>  IndexedInstrProf::Summary::MaxInternalBlockCount)),
>
> Added: llvm/trunk/test/CodeGen/X86/partition-sections.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/partition-sections.ll?rev=261582&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/partition-sections.ll (added)
> +++ llvm/trunk/test/CodeGen/X86/partition-sections.ll Mon Feb 22 16:14:14
> 2016
> @@ -0,0 +1,31 @@
> +; RUN: llc < %s -group-functions-by-hotness=true | FileCheck %s
> -check-prefix=PARTITION
> +; RUN: llc < %s -function-sections -group-functions-by-hotness=false |
> FileCheck %s -check-prefix=NO-PARTITION-FUNCTION-SECTION
> +; RUN: llc < %s -function-sections -group-functions-by-hotness=true |
> FileCheck %s -check-prefix=PARTITION-FUNCTION-SECTION
> +
> +; PARTITION: .text.unlikely
> +; PARTITION: .globl  _Z3foov
> +; NO-PARTITION-FUNCTION-SECTION: .text._Z3foov
> +; PARTITION-FUNCTION-SECTION: .text.unlikely._Z3foov
> +define i32 @_Z3foov() #0 {
> +  ret i32 0
> +}
> +
> +; PARTITION: .globl  _Z3barv
> +; NO-PARTITION-FUNCTION-SECTION: .text._Z3barv
> +; PARTITION-FUNCTION-SECTION: .text.unlikely._Z3barv
> +define i32 @_Z3barv() #1 !prof !0 {
> +  ret i32 1
> +}
> +
> +; PARTITION: .text
> +; PARTITION: .globl  _Z3bazv
> +; NO-PARTITION-FUNCTION-SECTION: .text._Z3bazv
> +; PARTITION-FUNCTION-SECTION: .text._Z3bazv
> +define i32 @_Z3bazv() #1 {
> +  ret i32 2
> +}
> +
> +attributes #0 = { nounwind uwtable cold }
> +attributes #1 = { nounwind uwtable }
> +
> +!0 = !{!"function_entry_count", i64 0}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160222/e80a0d9d/attachment.html>


More information about the llvm-commits mailing list