Skip to content

Commit 93cdd1b

Browse files
authoredFeb 12, 2024··
[PGO] Add ability to mark cold functions as optsize/minsize/optnone (#69030)
The performance of cold functions shouldn't matter too much, so if we care about binary sizes, add an option to mark cold functions as optsize/minsize for binary size, or optnone for compile times [1]. Clang patch will be in a future patch. This is intended to replace `shouldOptimizeForSize(Function&, ...)`. We've seen multiple cases where calls to this expensive function, if not careful, can blow up compile times. I will clean up users of that function in a followup patch. Initial version: https://reviews.llvm.org/D149800 [1] https://discourse.llvm.org/t/rfc-new-feature-proposal-de-optimizing-cold-functions-using-pgo-info/56388
1 parent 13d60ce commit 93cdd1b

File tree

13 files changed

+253
-18
lines changed

13 files changed

+253
-18
lines changed
 

‎clang/lib/CodeGen/BackendUtil.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
748748
CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
749749
: CodeGenOpts.InstrProfileOutput,
750750
"", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
751-
PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
751+
PGOOptions::NoCSAction, PGOOptions::ColdFuncOpt::Default,
752+
CodeGenOpts.DebugInfoForProfiling,
752753
/*PseudoProbeForProfiling=*/false, CodeGenOpts.AtomicProfileUpdate);
753754
else if (CodeGenOpts.hasProfileIRUse()) {
754755
// -fprofile-use.
@@ -757,28 +758,32 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
757758
PGOOpt = PGOOptions(
758759
CodeGenOpts.ProfileInstrumentUsePath, "",
759760
CodeGenOpts.ProfileRemappingFile, CodeGenOpts.MemoryProfileUsePath, VFS,
760-
PGOOptions::IRUse, CSAction, CodeGenOpts.DebugInfoForProfiling);
761+
PGOOptions::IRUse, CSAction, PGOOptions::ColdFuncOpt::Default,
762+
CodeGenOpts.DebugInfoForProfiling);
761763
} else if (!CodeGenOpts.SampleProfileFile.empty())
762764
// -fprofile-sample-use
763765
PGOOpt = PGOOptions(
764766
CodeGenOpts.SampleProfileFile, "", CodeGenOpts.ProfileRemappingFile,
765767
CodeGenOpts.MemoryProfileUsePath, VFS, PGOOptions::SampleUse,
766-
PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
767-
CodeGenOpts.PseudoProbeForProfiling);
768+
PGOOptions::NoCSAction, PGOOptions::ColdFuncOpt::Default,
769+
CodeGenOpts.DebugInfoForProfiling, CodeGenOpts.PseudoProbeForProfiling);
768770
else if (!CodeGenOpts.MemoryProfileUsePath.empty())
769771
// -fmemory-profile-use (without any of the above options)
770772
PGOOpt = PGOOptions("", "", "", CodeGenOpts.MemoryProfileUsePath, VFS,
771773
PGOOptions::NoAction, PGOOptions::NoCSAction,
774+
PGOOptions::ColdFuncOpt::Default,
772775
CodeGenOpts.DebugInfoForProfiling);
773776
else if (CodeGenOpts.PseudoProbeForProfiling)
774777
// -fpseudo-probe-for-profiling
775778
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
776779
PGOOptions::NoAction, PGOOptions::NoCSAction,
780+
PGOOptions::ColdFuncOpt::Default,
777781
CodeGenOpts.DebugInfoForProfiling, true);
778782
else if (CodeGenOpts.DebugInfoForProfiling)
779783
// -fdebug-info-for-profiling
780784
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
781-
PGOOptions::NoAction, PGOOptions::NoCSAction, true);
785+
PGOOptions::NoAction, PGOOptions::NoCSAction,
786+
PGOOptions::ColdFuncOpt::Default, true);
782787

783788
// Check to see if we want to generate a CS profile.
784789
if (CodeGenOpts.hasProfileCSIRInstr()) {
@@ -801,7 +806,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
801806
? getDefaultProfileGenName()
802807
: CodeGenOpts.InstrProfileOutput,
803808
"", /*MemoryProfile=*/"", nullptr, PGOOptions::NoAction,
804-
PGOOptions::CSIRInstr, CodeGenOpts.DebugInfoForProfiling);
809+
PGOOptions::CSIRInstr, PGOOptions::ColdFuncOpt::Default,
810+
CodeGenOpts.DebugInfoForProfiling);
805811
}
806812
if (TM)
807813
TM->setPGOOption(PGOOpt);

‎llvm/include/llvm/Support/PGOOptions.h

+3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ class FileSystem;
2727
struct PGOOptions {
2828
enum PGOAction { NoAction, IRInstr, IRUse, SampleUse };
2929
enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
30+
enum class ColdFuncOpt { Default, OptSize, MinSize, OptNone };
3031
PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
3132
std::string ProfileRemappingFile, std::string MemoryProfile,
3233
IntrusiveRefCntPtr<vfs::FileSystem> FS,
3334
PGOAction Action = NoAction, CSPGOAction CSAction = NoCSAction,
35+
ColdFuncOpt ColdType = ColdFuncOpt::Default,
3436
bool DebugInfoForProfiling = false,
3537
bool PseudoProbeForProfiling = false,
3638
bool AtomicCounterUpdate = false);
@@ -44,6 +46,7 @@ struct PGOOptions {
4446
std::string MemoryProfile;
4547
PGOAction Action;
4648
CSPGOAction CSAction;
49+
ColdFuncOpt ColdOptType;
4750
bool DebugInfoForProfiling;
4851
bool PseudoProbeForProfiling;
4952
bool AtomicCounterUpdate;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- PGOForceFunctionAttrs.h - --------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_PGOFORCEFUNCTIONATTRS_H
10+
#define LLVM_TRANSFORMS_INSTRUMENTATION_PGOFORCEFUNCTIONATTRS_H
11+
12+
#include "llvm/IR/PassManager.h"
13+
#include "llvm/Support/PGOOptions.h"
14+
15+
namespace llvm {
16+
17+
struct PGOForceFunctionAttrsPass
18+
: public PassInfoMixin<PGOForceFunctionAttrsPass> {
19+
PGOForceFunctionAttrsPass(PGOOptions::ColdFuncOpt ColdType)
20+
: ColdType(ColdType) {}
21+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
22+
23+
private:
24+
PGOOptions::ColdFuncOpt ColdType;
25+
};
26+
27+
} // namespace llvm
28+
29+
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_PGOFORCEFUNCTIONATTRS_H

‎llvm/lib/LTO/LTOBackend.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,23 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
243243
if (!Conf.SampleProfile.empty())
244244
PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping,
245245
/*MemoryProfile=*/"", FS, PGOOptions::SampleUse,
246-
PGOOptions::NoCSAction, true);
246+
PGOOptions::NoCSAction,
247+
PGOOptions::ColdFuncOpt::Default, true);
247248
else if (Conf.RunCSIRInstr) {
248249
PGOOpt = PGOOptions("", Conf.CSIRProfile, Conf.ProfileRemapping,
249250
/*MemoryProfile=*/"", FS, PGOOptions::IRUse,
250-
PGOOptions::CSIRInstr, Conf.AddFSDiscriminator);
251+
PGOOptions::CSIRInstr, PGOOptions::ColdFuncOpt::Default,
252+
Conf.AddFSDiscriminator);
251253
} else if (!Conf.CSIRProfile.empty()) {
252254
PGOOpt = PGOOptions(Conf.CSIRProfile, "", Conf.ProfileRemapping,
253255
/*MemoryProfile=*/"", FS, PGOOptions::IRUse,
254-
PGOOptions::CSIRUse, Conf.AddFSDiscriminator);
256+
PGOOptions::CSIRUse, PGOOptions::ColdFuncOpt::Default,
257+
Conf.AddFSDiscriminator);
255258
NoPGOWarnMismatch = !Conf.PGOWarnMismatch;
256259
} else if (Conf.AddFSDiscriminator) {
257260
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
258-
PGOOptions::NoAction, PGOOptions::NoCSAction, true);
261+
PGOOptions::NoAction, PGOOptions::NoCSAction,
262+
PGOOptions::ColdFuncOpt::Default, true);
259263
}
260264
TM->setPGOOption(PGOOpt);
261265

‎llvm/lib/Passes/PassBuilder.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
#include "llvm/Transforms/Instrumentation/KCFI.h"
173173
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
174174
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
175+
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"
175176
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
176177
#include "llvm/Transforms/Instrumentation/PoisonChecking.h"
177178
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"

‎llvm/lib/Passes/PassBuilderPipelines.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "llvm/Transforms/Instrumentation/InstrOrderFile.h"
7575
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
7676
#include "llvm/Transforms/Instrumentation/MemProfiler.h"
77+
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"
7778
#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
7879
#include "llvm/Transforms/Scalar/ADCE.h"
7980
#include "llvm/Transforms/Scalar/AlignmentFromAssumptions.h"
@@ -213,6 +214,12 @@ static cl::opt<bool>
213214
cl::desc("Enable DFA jump threading"),
214215
cl::init(false), cl::Hidden);
215216

217+
// TODO: turn on and remove flag
218+
static cl::opt<bool> EnablePGOForceFunctionAttrs(
219+
"enable-pgo-force-function-attrs",
220+
cl::desc("Enable pass to set function attributes based on PGO profiles"),
221+
cl::init(false));
222+
216223
static cl::opt<bool>
217224
EnableHotColdSplit("hot-cold-split",
218225
cl::desc("Enable hot-cold splitting pass"));
@@ -1146,6 +1153,9 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11461153
if (EnableSyntheticCounts && !PGOOpt)
11471154
MPM.addPass(SyntheticCountsPropagation());
11481155

1156+
if (EnablePGOForceFunctionAttrs)
1157+
MPM.addPass(PGOForceFunctionAttrsPass(PGOOpt->ColdOptType));
1158+
11491159
MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/true));
11501160

11511161
if (EnableModuleInliner)

‎llvm/lib/Passes/PassRegistry.def

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ MODULE_PASS("lower-emutls", LowerEmuTLSPass())
8585
MODULE_PASS("lower-global-dtors", LowerGlobalDtorsPass())
8686
MODULE_PASS("lower-ifunc", LowerIFuncPass())
8787
MODULE_PASS("lowertypetests", LowerTypeTestsPass())
88+
MODULE_PASS("pgo-force-function-attrs", PGOForceFunctionAttrsPass(PGOOpt ? PGOOpt->ColdOptType : PGOOptions::ColdFuncOpt::Default))
8889
MODULE_PASS("memprof-context-disambiguation", MemProfContextDisambiguation())
8990
MODULE_PASS("memprof-module", ModuleMemProfilerPass())
9091
MODULE_PASS("mergefunc", MergeFunctionsPass())

‎llvm/lib/Support/PGOOptions.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ PGOOptions::PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
1515
std::string ProfileRemappingFile,
1616
std::string MemoryProfile,
1717
IntrusiveRefCntPtr<vfs::FileSystem> FS, PGOAction Action,
18-
CSPGOAction CSAction, bool DebugInfoForProfiling,
19-
bool PseudoProbeForProfiling, bool AtomicCounterUpdate)
18+
CSPGOAction CSAction, ColdFuncOpt ColdType,
19+
bool DebugInfoForProfiling, bool PseudoProbeForProfiling,
20+
bool AtomicCounterUpdate)
2021
: ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
2122
ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
22-
Action(Action), CSAction(CSAction),
23+
Action(Action), CSAction(CSAction), ColdOptType(ColdType),
2324
DebugInfoForProfiling(DebugInfoForProfiling ||
2425
(Action == SampleUse && !PseudoProbeForProfiling)),
2526
PseudoProbeForProfiling(PseudoProbeForProfiling),

‎llvm/lib/Transforms/Instrumentation/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_llvm_component_library(LLVMInstrumentation
1313
InstrOrderFile.cpp
1414
InstrProfiling.cpp
1515
KCFI.cpp
16+
PGOForceFunctionAttrs.cpp
1617
PGOInstrumentation.cpp
1718
PGOMemOPSizeOpt.cpp
1819
PoisonChecking.cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm/Transforms/Instrumentation/PGOForceFunctionAttrs.h"
10+
#include "llvm/Analysis/BlockFrequencyInfo.h"
11+
#include "llvm/Analysis/ProfileSummaryInfo.h"
12+
#include "llvm/IR/PassManager.h"
13+
#include "llvm/Support/ErrorHandling.h"
14+
15+
using namespace llvm;
16+
17+
static bool shouldRunOnFunction(Function &F, ProfileSummaryInfo &PSI,
18+
FunctionAnalysisManager &FAM) {
19+
if (F.isDeclaration())
20+
return false;
21+
// Respect existing attributes.
22+
if (F.hasOptNone() || F.hasOptSize() || F.hasMinSize())
23+
return false;
24+
if (F.hasFnAttribute(Attribute::Cold))
25+
return true;
26+
if (!PSI.hasProfileSummary())
27+
return false;
28+
BlockFrequencyInfo &BFI = FAM.getResult<BlockFrequencyAnalysis>(F);
29+
return PSI.isFunctionColdInCallGraph(&F, BFI);
30+
}
31+
32+
PreservedAnalyses PGOForceFunctionAttrsPass::run(Module &M,
33+
ModuleAnalysisManager &AM) {
34+
if (ColdType == PGOOptions::ColdFuncOpt::Default)
35+
return PreservedAnalyses::all();
36+
ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);
37+
FunctionAnalysisManager &FAM =
38+
AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
39+
bool MadeChange = false;
40+
for (Function &F : M) {
41+
if (!shouldRunOnFunction(F, PSI, FAM))
42+
continue;
43+
MadeChange = true;
44+
switch (ColdType) {
45+
case PGOOptions::ColdFuncOpt::Default:
46+
llvm_unreachable("bailed out for default above");
47+
break;
48+
case PGOOptions::ColdFuncOpt::OptSize:
49+
F.addFnAttr(Attribute::OptimizeForSize);
50+
break;
51+
case PGOOptions::ColdFuncOpt::MinSize:
52+
F.addFnAttr(Attribute::MinSize);
53+
break;
54+
case PGOOptions::ColdFuncOpt::OptNone:
55+
F.addFnAttr(Attribute::OptimizeNone);
56+
F.addFnAttr(Attribute::NoInline);
57+
break;
58+
}
59+
}
60+
return MadeChange ? PreservedAnalyses::none() : PreservedAnalyses::all();
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
; RUN: opt < %s -passes=pgo-force-function-attrs -pgo-kind=pgo-instr-use-pipeline -S -pgo-cold-func-opt=default | FileCheck %s --check-prefixes=NONE,CHECK
2+
; RUN: opt < %s -passes=pgo-force-function-attrs -pgo-kind=pgo-instr-use-pipeline -S -pgo-cold-func-opt=optsize | FileCheck %s --check-prefixes=OPTSIZE,CHECK
3+
; RUN: opt < %s -passes=pgo-force-function-attrs -pgo-kind=pgo-instr-use-pipeline -S -pgo-cold-func-opt=minsize | FileCheck %s --check-prefixes=MINSIZE,CHECK
4+
; RUN: opt < %s -passes=pgo-force-function-attrs -pgo-kind=pgo-instr-use-pipeline -S -pgo-cold-func-opt=optnone | FileCheck %s --check-prefixes=OPTNONE,CHECK
5+
6+
; Should be no changes without profile data
7+
; RUN: opt < %s -passes=pgo-force-function-attrs -S -pgo-cold-func-opt=minsize | FileCheck %s --check-prefixes=NONE,CHECK
8+
9+
; NONE-NOT: Function Attrs:
10+
; OPTSIZE: Function Attrs: optsize{{$}}
11+
; MINSIZE: Function Attrs: minsize{{$}}
12+
; OPTNONE: Function Attrs: noinline optnone{{$}}
13+
; CHECK: define void @cold()
14+
15+
; CHECK: Function Attrs: optsize{{$}}
16+
; CHECK-NEXT: define void @cold_optsize()
17+
18+
; CHECK: Function Attrs: minsize{{$}}
19+
; CHECK-NEXT: define void @cold_minsize()
20+
21+
; CHECK: Function Attrs: noinline optnone{{$}}
22+
; CHECK-NEXT: define void @cold_optnone()
23+
24+
; NONE: Function Attrs: cold{{$}}
25+
; OPTSIZE: Function Attrs: cold optsize{{$}}
26+
; MINSIZE: Function Attrs: cold minsize{{$}}
27+
; OPTNONE: Function Attrs: cold noinline optnone{{$}}
28+
; CHECK-NEXT: define void @cold_attr()
29+
30+
; CHECK-NOT: Function Attrs: {{.*}}optsize
31+
; CHECK-NOT: Function Attrs: {{.*}}minsize
32+
; CHECK-NOT: Function Attrs: {{.*}}optnone
33+
34+
@s = global i32 0
35+
36+
define void @cold() !prof !27 {
37+
store i32 1, ptr @s, align 4
38+
ret void
39+
}
40+
41+
define void @cold_optsize() optsize !prof !27 {
42+
store i32 1, ptr @s, align 4
43+
ret void
44+
}
45+
46+
define void @cold_minsize() minsize !prof !27 {
47+
store i32 1, ptr @s, align 4
48+
ret void
49+
}
50+
51+
define void @cold_optnone() noinline optnone !prof !27 {
52+
store i32 1, ptr @s, align 4
53+
ret void
54+
}
55+
56+
define void @cold_attr() cold {
57+
store i32 1, ptr @s, align 4
58+
ret void
59+
}
60+
61+
define void @hot() !prof !28 {
62+
%l = load i32, ptr @s, align 4
63+
%add = add nsw i32 %l, 4
64+
store i32 %add, ptr @s, align 4
65+
ret void
66+
}
67+
68+
attributes #0 = { optsize }
69+
attributes #1 = { minsize }
70+
attributes #2 = { noinline optnone }
71+
72+
!llvm.module.flags = !{!0}
73+
74+
!0 = !{i32 1, !"ProfileSummary", !1}
75+
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
76+
!2 = !{!"ProfileFormat", !"InstrProf"}
77+
!3 = !{!"TotalCount", i64 9040}
78+
!4 = !{!"MaxCount", i64 9000}
79+
!5 = !{!"MaxInternalCount", i64 0}
80+
!6 = !{!"MaxFunctionCount", i64 9000}
81+
!7 = !{!"NumCounts", i64 5}
82+
!8 = !{!"NumFunctions", i64 5}
83+
!9 = !{!"DetailedSummary", !10}
84+
!10 = !{!11, !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26}
85+
!11 = !{i32 10000, i64 9000, i32 1}
86+
!12 = !{i32 100000, i64 9000, i32 1}
87+
!13 = !{i32 200000, i64 9000, i32 1}
88+
!14 = !{i32 300000, i64 9000, i32 1}
89+
!15 = !{i32 400000, i64 9000, i32 1}
90+
!16 = !{i32 500000, i64 9000, i32 1}
91+
!17 = !{i32 600000, i64 9000, i32 1}
92+
!18 = !{i32 700000, i64 9000, i32 1}
93+
!19 = !{i32 800000, i64 9000, i32 1}
94+
!20 = !{i32 900000, i64 9000, i32 1}
95+
!21 = !{i32 950000, i64 9000, i32 1}
96+
!22 = !{i32 990000, i64 9000, i32 1}
97+
!23 = !{i32 999000, i64 10, i32 5}
98+
!24 = !{i32 999900, i64 10, i32 5}
99+
!25 = !{i32 999990, i64 10, i32 5}
100+
!26 = !{i32 999999, i64 10, i32 5}
101+
!27 = !{!"function_entry_count", i64 10}
102+
!28 = !{!"function_entry_count", i64 9000}

‎llvm/tools/opt/NewPMDriver.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ static cl::opt<std::string>
202202
cl::desc("Path to the profile remapping file."),
203203
cl::Hidden);
204204

205+
static cl::opt<PGOOptions::ColdFuncOpt> PGOColdFuncAttr(
206+
"pgo-cold-func-opt", cl::init(PGOOptions::ColdFuncOpt::Default), cl::Hidden,
207+
cl::desc(
208+
"Function attribute to apply to cold functions as determined by PGO"),
209+
cl::values(clEnumValN(PGOOptions::ColdFuncOpt::Default, "default",
210+
"Default (no attribute)"),
211+
clEnumValN(PGOOptions::ColdFuncOpt::OptSize, "optsize",
212+
"Mark cold functions with optsize."),
213+
clEnumValN(PGOOptions::ColdFuncOpt::MinSize, "minsize",
214+
"Mark cold functions with minsize."),
215+
clEnumValN(PGOOptions::ColdFuncOpt::OptNone, "optnone",
216+
"Mark cold functions with optnone.")));
217+
205218
static cl::opt<bool> DebugInfoForProfiling(
206219
"debug-info-for-profiling", cl::init(false), cl::Hidden,
207220
cl::desc("Emit special debug info to enable PGO profile generation."));
@@ -341,22 +354,24 @@ bool llvm::runPassPipeline(
341354
switch (PGOKindFlag) {
342355
case InstrGen:
343356
P = PGOOptions(ProfileFile, "", "", MemoryProfileFile, FS,
344-
PGOOptions::IRInstr);
357+
PGOOptions::IRInstr, PGOOptions::NoCSAction,
358+
PGOColdFuncAttr);
345359
break;
346360
case InstrUse:
347361
P = PGOOptions(ProfileFile, "", ProfileRemappingFile, MemoryProfileFile, FS,
348-
PGOOptions::IRUse);
362+
PGOOptions::IRUse, PGOOptions::NoCSAction, PGOColdFuncAttr);
349363
break;
350364
case SampleUse:
351365
P = PGOOptions(ProfileFile, "", ProfileRemappingFile, MemoryProfileFile, FS,
352-
PGOOptions::SampleUse);
366+
PGOOptions::SampleUse, PGOOptions::NoCSAction,
367+
PGOColdFuncAttr);
353368
break;
354369
case NoPGO:
355370
if (DebugInfoForProfiling || PseudoProbeForProfiling ||
356371
!MemoryProfileFile.empty())
357372
P = PGOOptions("", "", "", MemoryProfileFile, FS, PGOOptions::NoAction,
358-
PGOOptions::NoCSAction, DebugInfoForProfiling,
359-
PseudoProbeForProfiling);
373+
PGOOptions::NoCSAction, PGOColdFuncAttr,
374+
DebugInfoForProfiling, PseudoProbeForProfiling);
360375
else
361376
P = std::nullopt;
362377
}

‎llvm/utils/gn/secondary/llvm/lib/Transforms/Instrumentation/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static_library("Instrumentation") {
2323
"InstrProfiling.cpp",
2424
"Instrumentation.cpp",
2525
"KCFI.cpp",
26+
"PGOForceFunctionAttrs.cpp",
2627
"MemProfiler.cpp",
2728
"MemorySanitizer.cpp",
2829
"PGOInstrumentation.cpp",

0 commit comments

Comments
 (0)
Please sign in to comment.