Skip to content

Commit f912c30

Browse files
committed
fix datarace
1 parent 9bb5af8 commit f912c30

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
649649
CmdArgs.push_back(Args.MakeArgString(
650650
Twine("--instrument-cold-function-only-path=") + Path));
651651
CmdArgs.push_back("-mllvm");
652+
CmdArgs.push_back("--pgo-instrument-cold-function-only");
653+
CmdArgs.push_back("-mllvm");
652654
CmdArgs.push_back("--pgo-function-entry-coverage");
653655
}
654656

clang/test/Driver/fprofile-generate-cold-function-coverage.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang -### -c -fprofile-generate-cold-function-coverage %s 2>&1 | FileCheck %s
22
// CHECK: "--instrument-cold-function-only-path=default_%m.profraw"
33
// CHECK: "--pgo-function-entry-coverage"
4+
// CHECK: "--pgo-instrument-cold-function-only"
45
// CHECK-NOT: "-fprofile-instrument"
56
// CHECK-NOT: "-fprofile-instrument-path=
67

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ static cl::opt<bool> UseLoopVersioningLICM(
298298

299299
static cl::opt<std::string> InstrumentColdFuncOnlyPath(
300300
"instrument-cold-function-only-path", cl::init(""),
301-
cl::desc("File path for cold function only instrumentation"), cl::Hidden);
301+
cl::desc("File path for cold function only instrumentation(requires use "
302+
"with --pgo-instrument-cold-function-only)"),
303+
cl::Hidden);
302304

303305
extern cl::opt<std::string> UseCtxProfile;
304306
extern cl::opt<bool> PGOInstrumentColdFunctionOnly;
@@ -1188,10 +1190,13 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11881190
const bool IsCtxProfUse =
11891191
!UseCtxProfile.empty() && Phase == ThinOrFullLTOPhase::ThinLTOPreLink;
11901192

1191-
// Enable cold function coverage instrumentation if
1192-
// InstrumentColdFuncOnlyPath is provided.
1193-
const bool IsColdFuncOnlyInstrGen = PGOInstrumentColdFunctionOnly =
1194-
IsPGOPreLink && !InstrumentColdFuncOnlyPath.empty();
1193+
assert(
1194+
(InstrumentColdFuncOnlyPath.empty() || PGOInstrumentColdFunctionOnly) &&
1195+
"--instrument-cold-function-only-path is provided but "
1196+
"--pgo-instrument-cold-function-only is not enabled");
1197+
const bool IsColdFuncOnlyInstrGen = PGOInstrumentColdFunctionOnly &&
1198+
IsPGOPreLink &&
1199+
!InstrumentColdFuncOnlyPath.empty();
11951200

11961201
if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse || IsCtxProfGen ||
11971202
IsCtxProfUse || IsColdFuncOnlyInstrGen)

0 commit comments

Comments
 (0)