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 { 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: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -399,7 +399,11 @@ ProfileSummaryInfo *PSI = getAnalysis().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))