Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -186,6 +186,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,8 +107,8 @@ EnableFastISel(false), UseInitArray(false), DisableIntegratedAS(false), RelaxELFRelocations(false), FunctionSections(false), DataSections(false), - UniqueSectionNames(true), TrapUnreachable(false), EmulatedTLS(false), - EnableIPRA(false) {} + UniqueSectionNames(true), ReorderFunctions(true), + TrapUnreachable(false), EmulatedTLS(false), EnableIPRA(false) {} /// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// option is specified on the command line, and should enable debugging @@ -206,6 +206,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 @@ -302,13 +302,17 @@ LI = &getAnalysis().getLoopInfo(); OptSize = F.optForSize(); - if (ProfileGuidedSectionPrefix) { - ProfileSummaryInfo *PSI = - getAnalysis().getPSI(); - if (PSI->isFunctionHotInCallGraph(&F)) - F.setSectionPrefix(".hot"); - else if (PSI->isFunctionColdInCallGraph(&F)) - F.setSectionPrefix(".unlikely"); + bool AddProfileGuidedSectionPrefix = + (!TM || ProfileGuidedSectionPrefix.getNumOccurrences()) + ? ProfileGuidedSectionPrefix + : TM->getReorderFunctions(); + if (AddProfileGuidedSectionPrefix) { + if (auto *PSI = getAnalysis().getPSI()) { + if (PSI->isFunctionHotInCallGraph(&F)) + F.setSectionPrefix(".hot"); + else if (PSI->isFunctionColdInCallGraph(&F)) + F.setSectionPrefix(".unlikely"); + } } /// This optimization identifies DIV instructions that can be