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())

0 commit comments

Comments
 (0)