Skip to content

Commit 3ab7ef2

Browse files
committed
Revert "[MemProf] Use new option/pass for profile feedback and matching"
This reverts commit b4a82b6. Broke AMDGPU OpenMP Offload buildbot
1 parent f0ae3c2 commit 3ab7ef2

File tree

18 files changed

+66
-206
lines changed

18 files changed

+66
-206
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
282282
/// Name of the profile file to use as output for with -fmemory-profile.
283283
std::string MemoryProfileOutput;
284284

285-
/// Name of the profile file to use as input for -fmemory-profile-use.
286-
std::string MemoryProfileUsePath;
287-
288285
/// Name of the profile file to use as input for -fprofile-instr-use
289286
std::string ProfileInstrumentUsePath;
290287

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,10 +1772,6 @@ defm memory_profile : OptInCC1FFlag<"memory-profile", "Enable", "Disable", " hea
17721772
def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
17731773
Group<f_Group>, Flags<[CC1Option]>, MetaVarName<"<directory>">,
17741774
HelpText<"Enable heap memory profiling and dump results into <directory>">;
1775-
def fmemory_profile_use_EQ : Joined<["-"], "fmemory-profile-use=">,
1776-
Group<f_Group>, Flags<[CC1Option, CoreOption]>, MetaVarName<"<pathname>">,
1777-
HelpText<"Use memory profile for profile-guided memory optimization">,
1778-
MarshallingInfoString<CodeGenOpts<"MemoryProfileUsePath">>;
17791775

17801776
// Begin sanitizer flags. These should all be core options exposed in all driver
17811777
// modes.

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -762,37 +762,31 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
762762
PGOOpt = PGOOptions(
763763
CodeGenOpts.InstrProfileOutput.empty() ? getDefaultProfileGenName()
764764
: CodeGenOpts.InstrProfileOutput,
765-
"", "", CodeGenOpts.MemoryProfileUsePath, nullptr, PGOOptions::IRInstr,
766-
PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling);
765+
"", "", nullptr, PGOOptions::IRInstr, PGOOptions::NoCSAction,
766+
CodeGenOpts.DebugInfoForProfiling);
767767
else if (CodeGenOpts.hasProfileIRUse()) {
768768
// -fprofile-use.
769769
auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
770770
: PGOOptions::NoCSAction;
771-
PGOOpt = PGOOptions(
772-
CodeGenOpts.ProfileInstrumentUsePath, "",
773-
CodeGenOpts.ProfileRemappingFile, CodeGenOpts.MemoryProfileUsePath, VFS,
774-
PGOOptions::IRUse, CSAction, CodeGenOpts.DebugInfoForProfiling);
771+
PGOOpt =
772+
PGOOptions(CodeGenOpts.ProfileInstrumentUsePath, "",
773+
CodeGenOpts.ProfileRemappingFile, VFS, PGOOptions::IRUse,
774+
CSAction, CodeGenOpts.DebugInfoForProfiling);
775775
} else if (!CodeGenOpts.SampleProfileFile.empty())
776776
// -fprofile-sample-use
777777
PGOOpt = PGOOptions(
778778
CodeGenOpts.SampleProfileFile, "", CodeGenOpts.ProfileRemappingFile,
779-
CodeGenOpts.MemoryProfileUsePath, VFS, PGOOptions::SampleUse,
780-
PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
781-
CodeGenOpts.PseudoProbeForProfiling);
782-
else if (!CodeGenOpts.MemoryProfileUsePath.empty())
783-
// -fmemory-profile-use (without any of the above options)
784-
PGOOpt = PGOOptions("", "", "", CodeGenOpts.MemoryProfileUsePath, VFS,
785-
PGOOptions::NoAction, PGOOptions::NoCSAction,
786-
CodeGenOpts.DebugInfoForProfiling);
779+
VFS, PGOOptions::SampleUse, PGOOptions::NoCSAction,
780+
CodeGenOpts.DebugInfoForProfiling, CodeGenOpts.PseudoProbeForProfiling);
787781
else if (CodeGenOpts.PseudoProbeForProfiling)
788782
// -fpseudo-probe-for-profiling
789-
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
790-
PGOOptions::NoAction, PGOOptions::NoCSAction,
783+
PGOOpt = PGOOptions("", "", "", nullptr, PGOOptions::NoAction,
784+
PGOOptions::NoCSAction,
791785
CodeGenOpts.DebugInfoForProfiling, true);
792786
else if (CodeGenOpts.DebugInfoForProfiling)
793787
// -fdebug-info-for-profiling
794-
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
795-
PGOOptions::NoAction, PGOOptions::NoCSAction, true);
788+
PGOOpt = PGOOptions("", "", "", nullptr, PGOOptions::NoAction,
789+
PGOOptions::NoCSAction, true);
796790

797791
// Check to see if we want to generate a CS profile.
798792
if (CodeGenOpts.hasProfileCSIRInstr()) {
@@ -814,8 +808,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
814808
CodeGenOpts.InstrProfileOutput.empty()
815809
? getDefaultProfileGenName()
816810
: CodeGenOpts.InstrProfileOutput,
817-
"", /*MemoryProfile=*/"", nullptr, PGOOptions::NoAction,
818-
PGOOptions::CSIRInstr, CodeGenOpts.DebugInfoForProfiling);
811+
"", nullptr, PGOOptions::NoAction, PGOOptions::CSIRInstr,
812+
CodeGenOpts.DebugInfoForProfiling);
819813
}
820814
if (TM)
821815
TM->setPGOOption(PGOOpt);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,18 +4946,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
49464946
!MemProfArg->getOption().matches(options::OPT_fno_memory_profile))
49474947
MemProfArg->render(Args, CmdArgs);
49484948

4949-
if (auto *MemProfUseArg =
4950-
Args.getLastArg(options::OPT_fmemory_profile_use_EQ)) {
4951-
if (MemProfArg)
4952-
D.Diag(diag::err_drv_argument_not_allowed_with)
4953-
<< MemProfUseArg->getAsString(Args) << MemProfArg->getAsString(Args);
4954-
if (auto *PGOInstrArg = Args.getLastArg(options::OPT_fprofile_generate,
4955-
options::OPT_fprofile_generate_EQ))
4956-
D.Diag(diag::err_drv_argument_not_allowed_with)
4957-
<< MemProfUseArg->getAsString(Args) << PGOInstrArg->getAsString(Args);
4958-
MemProfUseArg->render(Args, CmdArgs);
4959-
}
4960-
49614949
// Embed-bitcode option.
49624950
// Only white-listed flags below are allowed to be embedded.
49634951
if (C.getDriver().embedBitcodeInObject() && !IsUsingLTO &&

clang/test/CodeGen/memprof.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
// Profile use:
1818
// Ensure Pass PGOInstrumentationUse is invoked with the memprof-only profile.
19-
// RUN: %clang_cc1 -O2 -fmemory-profile-use=%t.memprofdata %s -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=USE
20-
// USE: Running pass: MemProfUsePass on [module]
19+
// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t.memprofdata %s -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=USE
20+
// USE: Running pass: PGOInstrumentationUse on [module]
2121

2222
char *foo() {
2323
return new char[10];

clang/test/Driver/fmemprof.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,3 @@
88
// DIR: ld{{.*}}libclang_rt.memprof{{.*}}libclang_rt.memprof_cxx
99
// OFF-NOT: "-fmemory-profile"
1010
// OFF-NOT: libclang_rt.memprof
11-
12-
// RUN: %clangxx -target x86_64-linux-gnu -fmemory-profile-use=foo %s -### 2>&1 | FileCheck %s --check-prefix=USE
13-
// USE: "-cc1" {{.*}} "-fmemory-profile-use=foo"
14-
15-
// RUN: %clangxx -target x86_64-linux-gnu -fmemory-profile -fmemory-profile-use=foo %s -### 2>&1 | FileCheck %s --check-prefix=CONFLICTWITHMEMPROFINSTR
16-
// CONFLICTWITHMEMPROFINSTR: error: invalid argument '-fmemory-profile-use=foo' not allowed with '-fmemory-profile'
17-
18-
// RUN: %clangxx -target x86_64-linux-gnu -fprofile-generate -fmemory-profile-use=foo %s -### 2>&1 | FileCheck %s --check-prefix=CONFLICTWITHPGOINSTR
19-
// CONFLICTWITHPGOINSTR: error: invalid argument '-fmemory-profile-use=foo' not allowed with '-fprofile-generate'

llvm/include/llvm/Support/PGOOptions.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct PGOOptions {
2828
enum PGOAction { NoAction, IRInstr, IRUse, SampleUse };
2929
enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
3030
PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
31-
std::string ProfileRemappingFile, std::string MemoryProfile,
31+
std::string ProfileRemappingFile,
3232
IntrusiveRefCntPtr<vfs::FileSystem> FS,
3333
PGOAction Action = NoAction, CSPGOAction CSAction = NoCSAction,
3434
bool DebugInfoForProfiling = false,
@@ -40,7 +40,6 @@ struct PGOOptions {
4040
std::string ProfileFile;
4141
std::string CSProfileGenFile;
4242
std::string ProfileRemappingFile;
43-
std::string MemoryProfile;
4443
PGOAction Action;
4544
CSPGOAction CSAction;
4645
bool DebugInfoForProfiling;

llvm/include/llvm/Transforms/Instrumentation/MemProfiler.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
1313
#define LLVM_TRANSFORMS_INSTRUMENTATION_MEMPROFILER_H
1414

15-
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1615
#include "llvm/IR/PassManager.h"
1716

1817
namespace llvm {
@@ -21,10 +20,6 @@ class FunctionPass;
2120
class Module;
2221
class ModulePass;
2322

24-
namespace vfs {
25-
class FileSystem;
26-
} // namespace vfs
27-
2823
/// Public interface to the memory profiler pass for instrumenting code to
2924
/// profile memory accesses.
3025
///
@@ -48,16 +43,12 @@ class ModuleMemProfilerPass : public PassInfoMixin<ModuleMemProfilerPass> {
4843
static bool isRequired() { return true; }
4944
};
5045

51-
class MemProfUsePass : public PassInfoMixin<MemProfUsePass> {
52-
public:
53-
explicit MemProfUsePass(std::string MemoryProfileFile,
54-
IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
55-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
56-
57-
private:
58-
std::string MemoryProfileFileName;
59-
IntrusiveRefCntPtr<vfs::FileSystem> FS;
60-
};
46+
// TODO: Remove this declaration and make readMemprof static once the matching
47+
// is moved into its own pass.
48+
class IndexedInstrProfReader;
49+
class TargetLibraryInfo;
50+
void readMemprof(Module &M, Function &F, IndexedInstrProfReader *MemProfReader,
51+
const TargetLibraryInfo &TLI);
6152

6253
} // namespace llvm
6354

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,20 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
236236
auto FS = vfs::getRealFileSystem();
237237
std::optional<PGOOptions> PGOOpt;
238238
if (!Conf.SampleProfile.empty())
239-
PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping,
240-
/*MemoryProfile=*/"", FS, PGOOptions::SampleUse,
241-
PGOOptions::NoCSAction, true);
239+
PGOOpt = PGOOptions(Conf.SampleProfile, "", Conf.ProfileRemapping, FS,
240+
PGOOptions::SampleUse, PGOOptions::NoCSAction, true);
242241
else if (Conf.RunCSIRInstr) {
243-
PGOOpt = PGOOptions("", Conf.CSIRProfile, Conf.ProfileRemapping,
244-
/*MemoryProfile=*/"", FS, PGOOptions::IRUse,
245-
PGOOptions::CSIRInstr, Conf.AddFSDiscriminator);
242+
PGOOpt = PGOOptions("", Conf.CSIRProfile, Conf.ProfileRemapping, FS,
243+
PGOOptions::IRUse, PGOOptions::CSIRInstr,
244+
Conf.AddFSDiscriminator);
246245
} else if (!Conf.CSIRProfile.empty()) {
247-
PGOOpt = PGOOptions(Conf.CSIRProfile, "", Conf.ProfileRemapping,
248-
/*MemoryProfile=*/"", FS, PGOOptions::IRUse,
249-
PGOOptions::CSIRUse, Conf.AddFSDiscriminator);
246+
PGOOpt = PGOOptions(Conf.CSIRProfile, "", Conf.ProfileRemapping, FS,
247+
PGOOptions::IRUse, PGOOptions::CSIRUse,
248+
Conf.AddFSDiscriminator);
250249
NoPGOWarnMismatch = !Conf.PGOWarnMismatch;
251250
} else if (Conf.AddFSDiscriminator) {
252-
PGOOpt = PGOOptions("", "", "", /*MemoryProfile=*/"", nullptr,
253-
PGOOptions::NoAction, PGOOptions::NoCSAction, true);
251+
PGOOpt = PGOOptions("", "", "", nullptr, PGOOptions::NoAction,
252+
PGOOptions::NoCSAction, true);
254253
}
255254
TM->setPGOOption(PGOOpt);
256255

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,23 +1071,6 @@ Expected<bool> parseMemorySSAPrinterPassOptions(StringRef Params) {
10711071
"MemorySSAPrinterPass");
10721072
}
10731073

1074-
Expected<std::string> parseMemProfUsePassOptions(StringRef Params) {
1075-
std::string Result;
1076-
while (!Params.empty()) {
1077-
StringRef ParamName;
1078-
std::tie(ParamName, Params) = Params.split(';');
1079-
1080-
if (ParamName.consume_front("profile-filename=")) {
1081-
Result = ParamName.str();
1082-
} else {
1083-
return make_error<StringError>(
1084-
formatv("invalid MemProfUse pass parameter '{0}' ", ParamName).str(),
1085-
inconvertibleErrorCode());
1086-
}
1087-
}
1088-
return Result;
1089-
}
1090-
10911074
} // namespace
10921075

10931076
/// Tests whether a pass name starts with a valid prefix for a default pipeline

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,10 +1102,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11021102
PGOOpt->CSAction == PGOOptions::CSIRInstr)
11031103
MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile));
11041104

1105-
if (PGOOpt && Phase != ThinOrFullLTOPhase::ThinLTOPostLink &&
1106-
!PGOOpt->MemoryProfile.empty())
1107-
MPM.addPass(MemProfUsePass(PGOOpt->MemoryProfile, PGOOpt->FS));
1108-
11091105
// Synthesize function entry counts for non-PGO compilation.
11101106
if (EnableSyntheticCounts && !PGOOpt)
11111107
MPM.addPass(SyntheticCountsPropagation());

llvm/lib/Passes/PassRegistry.def

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,6 @@ MODULE_PASS_WITH_PARAMS("embed-bitcode",
183183
},
184184
parseEmbedBitcodePassOptions,
185185
"thinlto;emit-summary")
186-
MODULE_PASS_WITH_PARAMS("memprof-use",
187-
"MemProfUsePass",
188-
[](std::string Opts) {
189-
return MemProfUsePass(Opts);
190-
},
191-
parseMemProfUsePassOptions,
192-
"profile-filename=S")
193186
#undef MODULE_PASS_WITH_PARAMS
194187

195188
#ifndef CGSCC_ANALYSIS

llvm/lib/Support/PGOOptions.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ using namespace llvm;
1313

1414
PGOOptions::PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
1515
std::string ProfileRemappingFile,
16-
std::string MemoryProfile,
1716
IntrusiveRefCntPtr<vfs::FileSystem> FS, PGOAction Action,
1817
CSPGOAction CSAction, bool DebugInfoForProfiling,
1918
bool PseudoProbeForProfiling)
2019
: ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
21-
ProfileRemappingFile(ProfileRemappingFile), MemoryProfile(MemoryProfile),
22-
Action(Action), CSAction(CSAction),
20+
ProfileRemappingFile(ProfileRemappingFile), Action(Action),
21+
CSAction(CSAction),
2322
DebugInfoForProfiling(DebugInfoForProfiling ||
2423
(Action == SampleUse && !PseudoProbeForProfiling)),
2524
PseudoProbeForProfiling(PseudoProbeForProfiling), FS(std::move(FS)) {
@@ -37,18 +36,13 @@ PGOOptions::PGOOptions(std::string ProfileFile, std::string CSProfileGenFile,
3736
// a profile.
3837
assert(this->CSAction != CSIRUse || this->Action == IRUse);
3938

40-
// Cannot optimize with MemProf profile during IR instrumentation.
41-
assert(this->MemoryProfile.empty() || this->Action != PGOOptions::IRInstr);
42-
43-
// If neither Action nor CSAction nor MemoryProfile are set,
44-
// DebugInfoForProfiling or PseudoProbeForProfiling needs to be true.
39+
// If neither Action nor CSAction, DebugInfoForProfiling or
40+
// PseudoProbeForProfiling needs to be true.
4541
assert(this->Action != NoAction || this->CSAction != NoCSAction ||
46-
!this->MemoryProfile.empty() || this->DebugInfoForProfiling ||
47-
this->PseudoProbeForProfiling);
42+
this->DebugInfoForProfiling || this->PseudoProbeForProfiling);
4843

4944
// If we need to use the profile, the VFS cannot be nullptr.
50-
assert(this->FS || !(this->Action == IRUse || this->CSAction == CSIRUse ||
51-
!this->MemoryProfile.empty()));
45+
assert(this->FS || !(this->Action == IRUse || this->CSAction == CSIRUse));
5246
}
5347

5448
PGOOptions::PGOOptions(const PGOOptions &) = default;

llvm/lib/Transforms/Instrumentation/MemProfiler.cpp

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "llvm/Support/CommandLine.h"
3939
#include "llvm/Support/Debug.h"
4040
#include "llvm/Support/HashBuilder.h"
41-
#include "llvm/Support/VirtualFileSystem.h"
4241
#include "llvm/TargetParser/Triple.h"
4342
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
4443
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -674,9 +673,9 @@ stackFrameIncludesInlinedCallStack(ArrayRef<Frame> ProfileCallStack,
674673
return InlCallStackIter == InlinedCallStack.end();
675674
}
676675

677-
static void readMemprof(Module &M, Function &F,
678-
IndexedInstrProfReader *MemProfReader,
679-
const TargetLibraryInfo &TLI) {
676+
void llvm::readMemprof(Module &M, Function &F,
677+
IndexedInstrProfReader *MemProfReader,
678+
const TargetLibraryInfo &TLI) {
680679
auto &Ctx = M.getContext();
681680

682681
auto FuncName = getPGOFuncName(F);
@@ -866,49 +865,3 @@ static void readMemprof(Module &M, Function &F,
866865
}
867866
}
868867
}
869-
870-
MemProfUsePass::MemProfUsePass(std::string MemoryProfileFile,
871-
IntrusiveRefCntPtr<vfs::FileSystem> FS)
872-
: MemoryProfileFileName(MemoryProfileFile), FS(FS) {
873-
if (!FS)
874-
this->FS = vfs::getRealFileSystem();
875-
}
876-
877-
PreservedAnalyses MemProfUsePass::run(Module &M, ModuleAnalysisManager &AM) {
878-
LLVM_DEBUG(dbgs() << "Read in memory profile:");
879-
auto &Ctx = M.getContext();
880-
auto ReaderOrErr = IndexedInstrProfReader::create(MemoryProfileFileName, *FS);
881-
if (Error E = ReaderOrErr.takeError()) {
882-
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) {
883-
Ctx.diagnose(
884-
DiagnosticInfoPGOProfile(MemoryProfileFileName.data(), EI.message()));
885-
});
886-
return PreservedAnalyses::all();
887-
}
888-
889-
std::unique_ptr<IndexedInstrProfReader> MemProfReader =
890-
std::move(ReaderOrErr.get());
891-
if (!MemProfReader) {
892-
Ctx.diagnose(DiagnosticInfoPGOProfile(
893-
MemoryProfileFileName.data(), StringRef("Cannot get MemProfReader")));
894-
return PreservedAnalyses::all();
895-
}
896-
897-
if (!MemProfReader->hasMemoryProfile()) {
898-
Ctx.diagnose(DiagnosticInfoPGOProfile(MemoryProfileFileName.data(),
899-
"Not a memory profile"));
900-
return PreservedAnalyses::all();
901-
}
902-
903-
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
904-
905-
for (auto &F : M) {
906-
if (F.isDeclaration())
907-
continue;
908-
909-
const TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
910-
readMemprof(M, F, MemProfReader.get(), TLI);
911-
}
912-
913-
return PreservedAnalyses::none();
914-
}

0 commit comments

Comments
 (0)