[PATCH] D34795: Supporting -f(no)-reorder-functions flag, llvm side change

Taewook Oh via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 18 23:40:41 PDT 2018


twoh updated this revision to Diff 170149.
twoh added a comment.

Rebase. Tests are provided in the clang counterpart (https://reviews.llvm.org/D34796).


Repository:
  rL LLVM

https://reviews.llvm.org/D34795

Files:
  include/llvm/Target/TargetMachine.h
  include/llvm/Target/TargetOptions.h
  lib/CodeGen/CodeGenPrepare.cpp


Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -399,7 +399,11 @@
 
   ProfileSummaryInfo *PSI =
       getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
-  if (ProfileGuidedSectionPrefix) {
+  bool AddProfileGuidedSectionPrefix =
+      (!TM || ProfileGuidedSectionPrefix.getNumOccurrences())
+          ? ProfileGuidedSectionPrefix
+          : TM->getReorderFunctions();
+  if (AddProfileGuidedSectionPrefix) {
     if (PSI->isFunctionHotInCallGraph(&F, *BFI))
       F.setSectionPrefix(".hot");
     else if (PSI->isFunctionColdInCallGraph(&F, *BFI))
Index: include/llvm/Target/TargetOptions.h
===================================================================
--- include/llvm/Target/TargetOptions.h
+++ include/llvm/Target/TargetOptions.h
@@ -107,9 +107,9 @@
           EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
           DisableIntegratedAS(false), RelaxELFRelocations(false),
           FunctionSections(false), DataSections(false),
-          UniqueSectionNames(true), TrapUnreachable(false),
-          NoTrapAfterNoreturn(false), EmulatedTLS(false),
-          ExplicitEmulatedTLS(false), EnableIPRA(false),
+          UniqueSectionNames(true), ReorderFunctions(true),
+          TrapUnreachable(false), NoTrapAfterNoreturn(false),
+          EmulatedTLS(false), ExplicitEmulatedTLS(false), EnableIPRA(false),
           EmitStackSizeSection(false), EnableMachineOutliner(false),
           SupportsDefaultOutlining(false), EmitAddrsig(false) {}
 
@@ -212,6 +212,9 @@
 
     unsigned UniqueSectionNames : 1;
 
+    /// Add section prefix for hot/cold functions.
+    unsigned ReorderFunctions : 1;
+
     /// Emit target-specific trap instruction for 'unreachable' IR instructions.
     unsigned TrapUnreachable : 1;
 
Index: include/llvm/Target/TargetMachine.h
===================================================================
--- include/llvm/Target/TargetMachine.h
+++ include/llvm/Target/TargetMachine.h
@@ -212,6 +212,10 @@
 
   bool getUniqueSectionNames() const { return Options.UniqueSectionNames; }
 
+  /// Return true if profile-guided section prefix that indicates hotness of
+  /// the function should be added, corresponds to -freorder-functions.
+  bool getReorderFunctions() const { return Options.ReorderFunctions; }
+
   /// Return true if data objects should be emitted into their own section,
   /// corresponds to -fdata-sections.
   bool getDataSections() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34795.170149.patch
Type: text/x-patch
Size: 2564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181019/5faeba71/attachment.bin>


More information about the llvm-commits mailing list