Skip to content

Commit c016430

Browse files
committed
Revert "[PGO] Context sensitive PGO (part 1)"
This reverts commit r354930, it was causing UBSan failures. llvm-svn: 354953
1 parent 2ffa170 commit c016430

File tree

14 files changed

+75
-309
lines changed

14 files changed

+75
-309
lines changed

llvm/include/llvm/InitializePasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ void initializePEIPass(PassRegistry&);
299299
void initializePGOIndirectCallPromotionLegacyPassPass(PassRegistry&);
300300
void initializePGOInstrumentationGenLegacyPassPass(PassRegistry&);
301301
void initializePGOInstrumentationUseLegacyPassPass(PassRegistry&);
302-
void initializePGOInstrumentationGenCreateVarLegacyPassPass(PassRegistry&);
303302
void initializePGOMemOPSizeOptLegacyPassPass(PassRegistry&);
304303
void initializePHIEliminationPass(PassRegistry&);
305304
void initializePartialInlinerLegacyPassPass(PassRegistry&);

llvm/include/llvm/LTO/Config.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ struct Config {
5555
/// Disable entirely the optimizer, including importing for ThinLTO
5656
bool CodeGenOnly = false;
5757

58-
/// Run PGO context sensitive IR instrumentation.
59-
bool RunCSIRInstr = false;
60-
6158
/// If this field is set, the set of passes run in the middle-end optimizer
6259
/// will be the one specified by the string. Only works with the new pass
6360
/// manager as the old one doesn't have this ability.
@@ -76,9 +73,6 @@ struct Config {
7673
/// with this triple.
7774
std::string DefaultTriple;
7875

79-
/// Context Sensitive PGO profile path.
80-
std::string CSIRProfile;
81-
8276
/// Sample PGO profile path.
8377
std::string SampleProfile;
8478

llvm/include/llvm/LinkAllPasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ namespace {
102102
(void) llvm::createGCOVProfilerPass();
103103
(void) llvm::createPGOInstrumentationGenLegacyPass();
104104
(void) llvm::createPGOInstrumentationUseLegacyPass();
105-
(void) llvm::createPGOInstrumentationGenCreateVarLegacyPass();
106105
(void) llvm::createPGOIndirectCallPromotionLegacyPass();
107106
(void) llvm::createPGOMemOPSizeOptLegacyPass();
108107
(void) llvm::createInstrProfilingLegacyPass();

llvm/include/llvm/ProfileData/InstrProf.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -767,20 +767,10 @@ struct NamedInstrProfRecord : InstrProfRecord {
767767
StringRef Name;
768768
uint64_t Hash;
769769

770-
// We reserve this bit as the flag for context sensitive profile record.
771-
static const int CS_FLAG_IN_FUNC_HASH = 60;
772-
773770
NamedInstrProfRecord() = default;
774771
NamedInstrProfRecord(StringRef Name, uint64_t Hash,
775772
std::vector<uint64_t> Counts)
776773
: InstrProfRecord(std::move(Counts)), Name(Name), Hash(Hash) {}
777-
778-
static bool hasCSFlagInHash(uint64_t FuncHash) {
779-
return ((FuncHash >> CS_FLAG_IN_FUNC_HASH) & 1);
780-
}
781-
static void setCSFlagInHash(uint64_t &FuncHash) {
782-
FuncHash |= ((uint64_t)1 << CS_FLAG_IN_FUNC_HASH);
783-
}
784774
};
785775

786776
uint32_t InstrProfRecord::getNumValueKinds() const {
@@ -1014,8 +1004,6 @@ namespace RawInstrProf {
10141004
// from control data struct is changed from raw pointer to Name's MD5 value.
10151005
// Version 4: ValueDataBegin and ValueDataSizes fields are removed from the
10161006
// raw header.
1017-
// Version 5: Bit 60 of FuncHash is reserved for the flag for the context
1018-
// sensitive records.
10191007
const uint64_t Version = INSTR_PROF_RAW_VERSION;
10201008

10211009
template <class IntPtrT> inline uint64_t getMagic();
@@ -1052,10 +1040,6 @@ struct Header {
10521040
void getMemOPSizeRangeFromOption(StringRef Str, int64_t &RangeStart,
10531041
int64_t &RangeLast);
10541042

1055-
// Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
1056-
// aware this is an ir_level profile so it can set the version flag.
1057-
void createIRLevelProfileFlagVar(Module &M, bool IsCS);
1058-
10591043
// Create the variable for the profile file name.
10601044
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput);
10611045

llvm/include/llvm/ProfileData/InstrProfData.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,10 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
635635
* version for other variants of profile. We set the lowest bit of the upper 8
636636
* bits (i.e. bit 56) to 1 to indicate if this is an IR-level instrumentaiton
637637
* generated profile, and 0 if this is a Clang FE generated profile.
638-
* 1 in bit 57 indicates there are context-sensitive records in the profile.
639638
*/
640639
#define VARIANT_MASKS_ALL 0xff00000000000000ULL
641640
#define GET_VERSION(V) ((V) & ~VARIANT_MASKS_ALL)
642641
#define VARIANT_MASK_IR_PROF (0x1ULL << 56)
643-
#define VARIANT_MASK_CSIR_PROF (0x1ULL << 57)
644642
#define INSTR_PROF_RAW_VERSION_VAR __llvm_profile_raw_version
645643
#define INSTR_PROF_PROFILE_RUNTIME_VAR __llvm_profile_runtime
646644

llvm/include/llvm/Transforms/Instrumentation.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,10 @@ struct GCOVOptions {
8787
ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
8888
GCOVOptions::getDefault());
8989

90-
// PGO Instrumention. Parameter IsCS indicates if this is the context senstive
91-
// instrumentation.
92-
ModulePass *createPGOInstrumentationGenLegacyPass(bool IsCS = false);
90+
// PGO Instrumention
91+
ModulePass *createPGOInstrumentationGenLegacyPass();
9392
ModulePass *
94-
createPGOInstrumentationUseLegacyPass(StringRef Filename = StringRef(""),
95-
bool IsCS = false);
96-
ModulePass *createPGOInstrumentationGenCreateVarLegacyPass(
97-
StringRef CSInstrName = StringRef(""));
93+
createPGOInstrumentationUseLegacyPass(StringRef Filename = StringRef(""));
9894
ModulePass *createPGOIndirectCallPromotionLegacyPass(bool InLTO = false,
9995
bool SamplePGO = false);
10096
FunctionPass *createPGOMemOPSizeOptLegacyPass();
@@ -136,19 +132,15 @@ struct InstrProfOptions {
136132
// Use atomic profile counter increments.
137133
bool Atomic = false;
138134

139-
// Use BFI to guide register promotion
140-
bool UseBFIInPromotion = false;
141-
142135
// Name of the profile file to use as output
143136
std::string InstrProfileOutput;
144137

145138
InstrProfOptions() = default;
146139
};
147140

148-
/// Insert frontend instrumentation based profiling. Parameter IsCS indicates if
149-
// this is the context senstive instrumentation.
141+
/// Insert frontend instrumentation based profiling.
150142
ModulePass *createInstrProfilingLegacyPass(
151-
const InstrProfOptions &Options = InstrProfOptions(), bool IsCS = false);
143+
const InstrProfOptions &Options = InstrProfOptions());
152144

153145
FunctionPass *createHWAddressSanitizerPass(bool CompileKernel = false,
154146
bool Recover = false);

llvm/include/llvm/Transforms/Instrumentation/InstrProfiling.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ using LoadStorePair = std::pair<Instruction *, Instruction *>;
3535
class InstrProfiling : public PassInfoMixin<InstrProfiling> {
3636
public:
3737
InstrProfiling() = default;
38-
InstrProfiling(const InstrProfOptions &Options, bool IsCS)
39-
: Options(Options), IsCS(IsCS) {}
38+
InstrProfiling(const InstrProfOptions &Options) : Options(Options) {}
4039

4140
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
4241
bool run(Module &M, const TargetLibraryInfo &TLI);
@@ -61,9 +60,6 @@ class InstrProfiling : public PassInfoMixin<InstrProfiling> {
6160
GlobalVariable *NamesVar;
6261
size_t NamesSize;
6362

64-
// Is this lowering for the context-sensitive instrumentation.
65-
bool IsCS;
66-
6763
// vector of counter load/store pairs to be register promoted.
6864
std::vector<LoadStorePair> PromotionCandidates;
6965

llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "llvm/ADT/ArrayRef.h"
1919
#include "llvm/IR/PassManager.h"
20-
#include "llvm/ProfileData/InstrProf.h"
2120
#include <cstdint>
2221
#include <string>
2322

@@ -27,51 +26,23 @@ class Function;
2726
class Instruction;
2827
class Module;
2928

30-
/// The instrumentation (profile-instr-gen) pass for IR based PGO.
31-
// We use this pass to create COMDAT profile variables for context
32-
// sensitive PGO (CSPGO). The reason to have a pass for this is CSPGO
33-
// can be run after LTO/ThinLTO linking. Lld linker needs to see
34-
// all the COMDAT variables before linking. So we have this pass
35-
// always run before linking for CSPGO.
36-
class PGOInstrumentationGenCreateVar
37-
: public PassInfoMixin<PGOInstrumentationGenCreateVar> {
38-
public:
39-
PGOInstrumentationGenCreateVar(std::string CSInstrName = "")
40-
: CSInstrName(CSInstrName) {}
41-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) {
42-
createProfileFileNameVar(M, CSInstrName);
43-
createIRLevelProfileFlagVar(M, /* IsCS */ true);
44-
return PreservedAnalyses::all();
45-
}
46-
47-
private:
48-
std::string CSInstrName;
49-
};
50-
5129
/// The instrumentation (profile-instr-gen) pass for IR based PGO.
5230
class PGOInstrumentationGen : public PassInfoMixin<PGOInstrumentationGen> {
5331
public:
54-
PGOInstrumentationGen(bool IsCS = false) : IsCS(IsCS) {}
5532
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
56-
57-
private:
58-
// If this is a context sensitive instrumentation.
59-
bool IsCS;
6033
};
6134

6235
/// The profile annotation (profile-instr-use) pass for IR based PGO.
6336
class PGOInstrumentationUse : public PassInfoMixin<PGOInstrumentationUse> {
6437
public:
6538
PGOInstrumentationUse(std::string Filename = "",
66-
std::string RemappingFilename = "", bool IsCS = false);
39+
std::string RemappingFilename = "");
6740

6841
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
6942

7043
private:
7144
std::string ProfileFileName;
7245
std::string ProfileRemappingFileName;
73-
// If this is a context sensitive instrumentation.
74-
bool IsCS;
7546
};
7647

7748
/// The indirect function call promotion pass.

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,7 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
569569
if (!ProfileGenFile.empty())
570570
Options.InstrProfileOutput = ProfileGenFile;
571571
Options.DoCounterPromotion = true;
572-
Options.UseBFIInPromotion = false;
573-
MPM.addPass(InstrProfiling(Options, false));
572+
MPM.addPass(InstrProfiling(Options));
574573
}
575574

576575
if (!ProfileUseFile.empty())

llvm/lib/ProfileData/InstrProf.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,25 +1011,6 @@ void getMemOPSizeRangeFromOption(StringRef MemOPSizeRange, int64_t &RangeStart,
10111011
assert(RangeLast >= RangeStart);
10121012
}
10131013

1014-
// Create a COMDAT variable INSTR_PROF_RAW_VERSION_VAR to make the runtime
1015-
// aware this is an ir_level profile so it can set the version flag.
1016-
void createIRLevelProfileFlagVar(Module &M, bool IsCS) {
1017-
const StringRef VarName(INSTR_PROF_QUOTE(INSTR_PROF_RAW_VERSION_VAR));
1018-
Type *IntTy64 = Type::getInt64Ty(M.getContext());
1019-
uint64_t ProfileVersion = (INSTR_PROF_RAW_VERSION | VARIANT_MASK_IR_PROF);
1020-
if (IsCS)
1021-
ProfileVersion |= VARIANT_MASK_CSIR_PROF;
1022-
auto IRLevelVersionVariable = new GlobalVariable(
1023-
M, IntTy64, true, GlobalValue::WeakAnyLinkage,
1024-
Constant::getIntegerValue(IntTy64, APInt(64, ProfileVersion)), VarName);
1025-
IRLevelVersionVariable->setVisibility(GlobalValue::DefaultVisibility);
1026-
Triple TT(M.getTargetTriple());
1027-
if (TT.supportsCOMDAT()) {
1028-
IRLevelVersionVariable->setLinkage(GlobalValue::ExternalLinkage);
1029-
IRLevelVersionVariable->setComdat(M.getOrInsertComdat(VarName));
1030-
}
1031-
}
1032-
10331014
// Create the variable for the profile file name.
10341015
void createProfileFileNameVar(Module &M, StringRef InstrProfileOutput) {
10351016
if (InstrProfileOutput.empty())

llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/ADT/Triple.h"
2020
#include "llvm/ADT/Twine.h"
21-
#include "llvm/Analysis/BlockFrequencyInfo.h"
22-
#include "llvm/Analysis/BranchProbabilityInfo.h"
2321
#include "llvm/Analysis/LoopInfo.h"
2422
#include "llvm/Analysis/TargetLibraryInfo.h"
2523
#include "llvm/IR/Attributes.h"
@@ -149,8 +147,8 @@ class InstrProfilingLegacyPass : public ModulePass {
149147
static char ID;
150148

151149
InstrProfilingLegacyPass() : ModulePass(ID) {}
152-
InstrProfilingLegacyPass(const InstrProfOptions &Options, bool IsCS)
153-
: ModulePass(ID), InstrProf(Options, IsCS) {}
150+
InstrProfilingLegacyPass(const InstrProfOptions &Options)
151+
: ModulePass(ID), InstrProf(Options) {}
154152

155153
StringRef getPassName() const override {
156154
return "Frontend instrumentation-based coverage lowering";
@@ -234,9 +232,9 @@ class PGOCounterPromoter {
234232
public:
235233
PGOCounterPromoter(
236234
DenseMap<Loop *, SmallVector<LoadStorePair, 8>> &LoopToCands,
237-
Loop &CurLoop, LoopInfo &LI, BlockFrequencyInfo *BFI)
235+
Loop &CurLoop, LoopInfo &LI)
238236
: LoopToCandidates(LoopToCands), ExitBlocks(), InsertPts(), L(CurLoop),
239-
LI(LI), BFI(BFI) {
237+
LI(LI) {
240238

241239
SmallVector<BasicBlock *, 8> LoopExitBlocks;
242240
SmallPtrSet<BasicBlock *, 8> BlockSet;
@@ -265,20 +263,6 @@ class PGOCounterPromoter {
265263
SSAUpdater SSA(&NewPHIs);
266264
Value *InitVal = ConstantInt::get(Cand.first->getType(), 0);
267265

268-
// If BFI is set, we will use it to guide the promotions.
269-
if (BFI) {
270-
auto *BB = Cand.first->getParent();
271-
auto InstrCount = BFI->getBlockProfileCount(BB);
272-
if (!InstrCount)
273-
continue;
274-
auto PreheaderCount = BFI->getBlockProfileCount(L.getLoopPreheader());
275-
// If the average loop trip count is not greater than 1.5, we skip
276-
// promotion.
277-
if (PreheaderCount &&
278-
(PreheaderCount.getValue() * 3) >= (InstrCount.getValue() * 2))
279-
continue;
280-
}
281-
282266
PGOCounterPromoterHelper Promoter(Cand.first, Cand.second, SSA, InitVal,
283267
L.getLoopPreheader(), ExitBlocks,
284268
InsertPts, LoopToCandidates, LI);
@@ -328,11 +312,6 @@ class PGOCounterPromoter {
328312

329313
SmallVector<BasicBlock *, 8> ExitingBlocks;
330314
LP->getExitingBlocks(ExitingBlocks);
331-
332-
// If BFI is set, we do more aggressive promotions based on BFI.
333-
if (BFI)
334-
return (unsigned)-1;
335-
336315
// Not considierered speculative.
337316
if (ExitingBlocks.size() == 1)
338317
return MaxNumOfPromotionsPerLoop;
@@ -364,7 +343,6 @@ class PGOCounterPromoter {
364343
SmallVector<Instruction *, 8> InsertPts;
365344
Loop &L;
366345
LoopInfo &LI;
367-
BlockFrequencyInfo *BFI;
368346
};
369347

370348
} // end anonymous namespace
@@ -387,9 +365,8 @@ INITIALIZE_PASS_END(
387365
"Frontend instrumentation-based coverage lowering.", false, false)
388366

389367
ModulePass *
390-
llvm::createInstrProfilingLegacyPass(const InstrProfOptions &Options,
391-
bool IsCS) {
392-
return new InstrProfilingLegacyPass(Options, IsCS);
368+
llvm::createInstrProfilingLegacyPass(const InstrProfOptions &Options) {
369+
return new InstrProfilingLegacyPass(Options);
393370
}
394371

395372
static InstrProfIncrementInst *castToIncrementInst(Instruction *Instr) {
@@ -438,13 +415,6 @@ void InstrProfiling::promoteCounterLoadStores(Function *F) {
438415
LoopInfo LI(DT);
439416
DenseMap<Loop *, SmallVector<LoadStorePair, 8>> LoopPromotionCandidates;
440417

441-
std::unique_ptr<BlockFrequencyInfo> BFI;
442-
if (Options.UseBFIInPromotion) {
443-
std::unique_ptr<BranchProbabilityInfo> BPI;
444-
BPI.reset(new BranchProbabilityInfo(*F, LI, TLI));
445-
BFI.reset(new BlockFrequencyInfo(*F, *BPI, LI));
446-
}
447-
448418
for (const auto &LoadStore : PromotionCandidates) {
449419
auto *CounterLoad = LoadStore.first;
450420
auto *CounterStore = LoadStore.second;
@@ -460,7 +430,7 @@ void InstrProfiling::promoteCounterLoadStores(Function *F) {
460430
// Do a post-order traversal of the loops so that counter updates can be
461431
// iteratively hoisted outside the loop nest.
462432
for (auto *Loop : llvm::reverse(Loops)) {
463-
PGOCounterPromoter Promoter(LoopPromotionCandidates, *Loop, LI, BFI.get());
433+
PGOCounterPromoter Promoter(LoopPromotionCandidates, *Loop, LI);
464434
Promoter.run(&TotalCountersPromoted);
465435
}
466436
}
@@ -711,6 +681,7 @@ static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT) {
711681
// Don't do this for Darwin. compiler-rt uses linker magic.
712682
if (TT.isOSDarwin())
713683
return false;
684+
714685
// Use linker script magic to get data/cnts/name start/end.
715686
if (TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
716687
TT.isOSFuchsia() || TT.isPS4CPU() || TT.isOSWindows())
@@ -1014,12 +985,8 @@ void InstrProfiling::emitUses() {
1014985
}
1015986

1016987
void InstrProfiling::emitInitialization() {
1017-
// Create ProfileFileName variable. Don't don't this for the
1018-
// context-sensitive instrumentation lowering: This lowering is after
1019-
// LTO/ThinLTO linking. Pass PGOInstrumentationGenCreateVar should
1020-
// have already create the variable before LTO/ThinLTO linking.
1021-
if (!IsCS)
1022-
createProfileFileNameVar(*M, Options.InstrProfileOutput);
988+
// Create variable for profile name.
989+
createProfileFileNameVar(*M, Options.InstrProfileOutput);
1023990
Function *RegisterF = M->getFunction(getInstrProfRegFuncsName());
1024991
if (!RegisterF)
1025992
return;

0 commit comments

Comments
 (0)