Skip to content

Commit c025bdf

Browse files
committed
Revert D83013 "[LPM] Port CGProfilePass from NPM to LPM"
This reverts commit c92a8c0. It breaks builds and has unaddressed review comments.
1 parent 205dc09 commit c025bdf

File tree

17 files changed

+50
-130
lines changed

17 files changed

+50
-130
lines changed

clang/include/clang/Basic/CodeGenOptions.def

+1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables.
252252
CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer.
253253
CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer.
254254
CODEGENOPT(ProfileSampleAccurate, 1, 0) ///< Sample profile is accurate.
255+
CODEGENOPT(CallGraphProfile , 1, 0) ///< Run call graph profile.
255256

256257
/// Attempt to use register sized accesses to bit-fields in structures, when
257258
/// possible.

clang/lib/CodeGen/BackendUtil.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
620620
PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
621621
PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP;
622622
PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop;
623-
PMBuilder.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
624623

625624
PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
626625
// Loop interleaving in the loop vectorizer has historically been set to be
@@ -1145,7 +1144,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
11451144
PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
11461145
PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
11471146
PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
1148-
PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
1147+
PTO.CallGraphProfile = CodeGenOpts.CallGraphProfile;
11491148
PTO.Coroutines = LangOpts.Coroutines;
11501149

11511150
PassInstrumentationCallbacks PIC;
@@ -1563,7 +1562,7 @@ static void runThinLTOBackend(
15631562
Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;
15641563
Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop;
15651564
Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP;
1566-
Conf.PTO.CallGraphProfile = !CGOpts.DisableIntegratedAS;
1565+
Conf.PTO.CallGraphProfile = CGOpts.CallGraphProfile;
15671566

15681567
// Context sensitive profile.
15691568
if (CGOpts.hasProfileCSIRInstr()) {

clang/lib/Frontend/CompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
860860
Opts.RerollLoops = Args.hasArg(OPT_freroll_loops);
861861

862862
Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
863+
Opts.CallGraphProfile = !Opts.DisableIntegratedAS;
863864
Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
864865
Opts.SampleProfileFile =
865866
std::string(Args.getLastArgValue(OPT_fprofile_sample_use_EQ));

llvm/include/llvm/InitializePasses.h

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void initializeCFGViewerLegacyPassPass(PassRegistry&);
103103
void initializeCFIInstrInserterPass(PassRegistry&);
104104
void initializeCFLAndersAAWrapperPassPass(PassRegistry&);
105105
void initializeCFLSteensAAWrapperPassPass(PassRegistry&);
106-
void initializeCGProfileLegacyPassPass(PassRegistry &);
107106
void initializeCallGraphDOTPrinterPass(PassRegistry&);
108107
void initializeCallGraphPrinterLegacyPassPass(PassRegistry&);
109108
void initializeCallGraphViewerPass(PassRegistry&);

llvm/include/llvm/Transforms/IPO.h

-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ ModulePass *createSampleProfileLoaderPass(StringRef Name);
282282
ModulePass *createWriteThinLTOBitcodePass(raw_ostream &Str,
283283
raw_ostream *ThinLinkOS = nullptr);
284284

285-
ModulePass *createCGProfileLegacyPass();
286-
287285
} // End llvm namespace
288286

289287
#endif

llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h

-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ class PassManagerBuilder {
156156

157157
bool DisableTailCalls;
158158
bool DisableUnrollLoops;
159-
bool CallGraphProfile;
160159
bool SLPVectorize;
161160
bool LoopVectorize;
162161
bool LoopsInterleaved;

llvm/include/llvm/Transforms/Instrumentation/CGProfile.h

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ namespace llvm {
1919
class CGProfilePass : public PassInfoMixin<CGProfilePass> {
2020
public:
2121
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
22+
23+
private:
24+
void addModuleFlags(
25+
Module &M,
26+
MapVector<std::pair<Function *, Function *>, uint64_t> &Counts) const;
2227
};
2328
} // end namespace llvm
2429

llvm/lib/Passes/PassBuilder.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ static cl::opt<bool>
248248
EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
249249
cl::desc("Enable control height reduction optimization (CHR)"));
250250

251+
static cl::opt<bool> EnableCallGraphProfile(
252+
"enable-npm-call-graph-profile", cl::init(true), cl::Hidden,
253+
cl::desc("Enable call graph profile pass for the new PM (default = on)"));
254+
251255
/// Flag to enable inline deferral during PGO.
252256
static cl::opt<bool>
253257
EnablePGOInlineDeferral("enable-npm-pgo-inline-deferral", cl::init(true),
@@ -263,7 +267,7 @@ PipelineTuningOptions::PipelineTuningOptions() {
263267
Coroutines = false;
264268
LicmMssaOptCap = SetLicmMssaOptCap;
265269
LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
266-
CallGraphProfile = true;
270+
CallGraphProfile = EnableCallGraphProfile;
267271
}
268272

269273
extern cl::opt<bool> EnableHotColdSplit;

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ PassManagerBuilder::PassManagerBuilder() {
195195
PrepareForThinLTO = EnablePrepareForThinLTO;
196196
PerformThinLTO = EnablePerformThinLTO;
197197
DivergentTarget = false;
198-
CallGraphProfile = true;
199198
}
200199

201200
PassManagerBuilder::~PassManagerBuilder() {
@@ -835,10 +834,6 @@ void PassManagerBuilder::populateModulePassManager(
835834
if (MergeFunctions)
836835
MPM.add(createMergeFunctionsPass());
837836

838-
// Add Module flag "CG Profile" based on Branch Frequency Information.
839-
if (CallGraphProfile)
840-
MPM.add(createCGProfileLegacyPass());
841-
842837
// LoopSink pass sinks instructions hoisted by LICM, which serves as a
843838
// canonicalization pass that enables other optimizations. As a result,
844839
// LoopSink pass needs to be a very late IR pass to avoid undoing LICM

llvm/lib/Transforms/Instrumentation/CGProfile.cpp

+25-79
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,22 @@
1010

1111
#include "llvm/ADT/MapVector.h"
1212
#include "llvm/Analysis/BlockFrequencyInfo.h"
13-
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
1413
#include "llvm/Analysis/TargetTransformInfo.h"
1514
#include "llvm/IR/Constants.h"
1615
#include "llvm/IR/Instructions.h"
1716
#include "llvm/IR/MDBuilder.h"
1817
#include "llvm/IR/PassManager.h"
19-
#include "llvm/InitializePasses.h"
2018
#include "llvm/ProfileData/InstrProf.h"
21-
#include "llvm/Transforms/IPO.h"
2219
#include "llvm/Transforms/Instrumentation.h"
2320

2421
#include <array>
2522

2623
using namespace llvm;
2724

28-
static bool
29-
addModuleFlags(Module &M,
30-
MapVector<std::pair<Function *, Function *>, uint64_t> &Counts) {
31-
if (Counts.empty())
32-
return false;
33-
34-
LLVMContext &Context = M.getContext();
35-
MDBuilder MDB(Context);
36-
std::vector<Metadata *> Nodes;
37-
38-
for (auto E : Counts) {
39-
Metadata *Vals[] = {ValueAsMetadata::get(E.first.first),
40-
ValueAsMetadata::get(E.first.second),
41-
MDB.createConstant(ConstantInt::get(
42-
Type::getInt64Ty(Context), E.second))};
43-
Nodes.push_back(MDNode::get(Context, Vals));
44-
}
45-
46-
M.addModuleFlag(Module::Append, "CG Profile", MDNode::get(Context, Nodes));
47-
return true;
48-
}
49-
50-
static bool
51-
runCGProfilePass(Module &M,
52-
function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
53-
function_ref<TargetTransformInfo &(Function &)> GetTTI) {
25+
PreservedAnalyses CGProfilePass::run(Module &M, ModuleAnalysisManager &MAM) {
5426
MapVector<std::pair<Function *, Function *>, uint64_t> Counts;
27+
FunctionAnalysisManager &FAM =
28+
MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
5529
InstrProfSymtab Symtab;
5630
auto UpdateCounts = [&](TargetTransformInfo &TTI, Function *F,
5731
Function *CalledF, uint64_t NewCount) {
@@ -61,14 +35,14 @@ runCGProfilePass(Module &M,
6135
Count = SaturatingAdd(Count, NewCount);
6236
};
6337
// Ignore error here. Indirect calls are ignored if this fails.
64-
(void)(bool) Symtab.create(M);
38+
(void)(bool)Symtab.create(M);
6539
for (auto &F : M) {
66-
if (F.isDeclaration() || !F.getEntryCount())
40+
if (F.isDeclaration())
6741
continue;
68-
auto &BFI = GetBFI(F);
42+
auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(F);
6943
if (BFI.getEntryFreq() == 0)
7044
continue;
71-
TargetTransformInfo &TTI = GetTTI(F);
45+
TargetTransformInfo &TTI = FAM.getResult<TargetIRAnalysis>(F);
7246
for (auto &BB : F) {
7347
Optional<uint64_t> BBCount = BFI.getBlockProfileCount(&BB);
7448
if (!BBCount)
@@ -95,56 +69,28 @@ runCGProfilePass(Module &M,
9569
}
9670
}
9771

98-
return addModuleFlags(M, Counts);
99-
}
72+
addModuleFlags(M, Counts);
10073

101-
namespace {
102-
struct CGProfileLegacyPass final : public ModulePass {
103-
static char ID;
104-
CGProfileLegacyPass() : ModulePass(ID) {
105-
initializeCGProfileLegacyPassPass(*PassRegistry::getPassRegistry());
106-
}
74+
return PreservedAnalyses::all();
75+
}
10776

108-
void getAnalysisUsage(AnalysisUsage &AU) const override {
109-
AU.setPreservesCFG();
110-
AU.addRequired<LazyBlockFrequencyInfoPass>();
111-
AU.addRequired<TargetTransformInfoWrapperPass>();
112-
}
77+
void CGProfilePass::addModuleFlags(
78+
Module &M,
79+
MapVector<std::pair<Function *, Function *>, uint64_t> &Counts) const {
80+
if (Counts.empty())
81+
return;
11382

114-
bool runOnModule(Module &M) override {
115-
auto GetBFI = [this](Function &F) -> BlockFrequencyInfo & {
116-
return this->getAnalysis<LazyBlockFrequencyInfoPass>(F).getBFI();
117-
};
118-
auto GetTTI = [this](Function &F) -> TargetTransformInfo & {
119-
return this->getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
120-
};
83+
LLVMContext &Context = M.getContext();
84+
MDBuilder MDB(Context);
85+
std::vector<Metadata *> Nodes;
12186

122-
return runCGProfilePass(M, GetBFI, GetTTI);
87+
for (auto E : Counts) {
88+
Metadata *Vals[] = {ValueAsMetadata::get(E.first.first),
89+
ValueAsMetadata::get(E.first.second),
90+
MDB.createConstant(ConstantInt::get(
91+
Type::getInt64Ty(Context), E.second))};
92+
Nodes.push_back(MDNode::get(Context, Vals));
12393
}
124-
};
125-
126-
} // namespace
127-
128-
char CGProfileLegacyPass::ID = 0;
12994

130-
INITIALIZE_PASS(CGProfileLegacyPass, "cg-profile", "Call Graph Profile", false,
131-
false)
132-
133-
ModulePass *llvm::createCGProfileLegacyPass() {
134-
return new CGProfileLegacyPass();
135-
}
136-
137-
PreservedAnalyses CGProfilePass::run(Module &M, ModuleAnalysisManager &MAM) {
138-
FunctionAnalysisManager &FAM =
139-
MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
140-
auto GetBFI = [&FAM](Function &F) -> BlockFrequencyInfo & {
141-
return FAM.getResult<BlockFrequencyAnalysis>(F);
142-
};
143-
auto GetTTI = [&FAM](Function &F) -> TargetTransformInfo & {
144-
return FAM.getResult<TargetIRAnalysis>(F);
145-
};
146-
147-
runCGProfilePass(M, GetBFI, GetTTI);
148-
149-
return PreservedAnalyses::all();
95+
M.addModuleFlag(Module::Append, "CG Profile", MDNode::get(Context, Nodes));
15096
}

llvm/lib/Transforms/Instrumentation/Instrumentation.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ void llvm::initializeInstrumentation(PassRegistry &Registry) {
112112
initializePGOInstrumentationUseLegacyPassPass(Registry);
113113
initializePGOIndirectCallPromotionLegacyPassPass(Registry);
114114
initializePGOMemOPSizeOptLegacyPassPass(Registry);
115-
initializeCGProfileLegacyPassPass(Registry);
116115
initializeInstrOrderFileLegacyPassPass(Registry);
117116
initializeInstrProfilingLegacyPassPass(Registry);
118117
initializeMemorySanitizerLegacyPassPass(Registry);

llvm/test/CodeGen/AMDGPU/opt-pipeline.ll

-18
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,6 @@
276276
; GCN-O1-NEXT: Warn about non-applied transformations
277277
; GCN-O1-NEXT: Alignment from assumptions
278278
; GCN-O1-NEXT: Strip Unused Function Prototypes
279-
; GCN-O1-NEXT: Call Graph Profile
280-
; GCN-O1-NEXT: FunctionPass Manager
281-
; GCN-O1-NEXT: Dominator Tree Construction
282-
; GCN-O1-NEXT: Natural Loop Information
283-
; GCN-O1-NEXT: Lazy Branch Probability Analysis
284-
; GCN-O1-NEXT: Lazy Block Frequency Analysis
285279
; GCN-O1-NEXT: FunctionPass Manager
286280
; GCN-O1-NEXT: Dominator Tree Construction
287281
; GCN-O1-NEXT: Natural Loop Information
@@ -629,12 +623,6 @@
629623
; GCN-O2-NEXT: Strip Unused Function Prototypes
630624
; GCN-O2-NEXT: Dead Global Elimination
631625
; GCN-O2-NEXT: Merge Duplicate Global Constants
632-
; GCN-O2-NEXT: Call Graph Profile
633-
; GCN-O2-NEXT: FunctionPass Manager
634-
; GCN-O2-NEXT: Dominator Tree Construction
635-
; GCN-O2-NEXT: Natural Loop Information
636-
; GCN-O2-NEXT: Lazy Branch Probability Analysis
637-
; GCN-O2-NEXT: Lazy Block Frequency Analysis
638626
; GCN-O2-NEXT: FunctionPass Manager
639627
; GCN-O2-NEXT: Dominator Tree Construction
640628
; GCN-O2-NEXT: Natural Loop Information
@@ -987,12 +975,6 @@
987975
; GCN-O3-NEXT: Strip Unused Function Prototypes
988976
; GCN-O3-NEXT: Dead Global Elimination
989977
; GCN-O3-NEXT: Merge Duplicate Global Constants
990-
; GCN-O3-NEXT: Call Graph Profile
991-
; GCN-O3-NEXT: FunctionPass Manager
992-
; GCN-O3-NEXT: Dominator Tree Construction
993-
; GCN-O3-NEXT: Natural Loop Information
994-
; GCN-O3-NEXT: Lazy Branch Probability Analysis
995-
; GCN-O3-NEXT: Lazy Block Frequency Analysis
996978
; GCN-O3-NEXT: FunctionPass Manager
997979
; GCN-O3-NEXT: Dominator Tree Construction
998980
; GCN-O3-NEXT: Natural Loop Information

llvm/test/Instrumentation/cgprofile.ll

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
; RUN: opt < %s -passes cg-profile -S | FileCheck %s
2-
; RUN: opt < %s -cg-profile -S | FileCheck %s
32

43
declare void @b()
54

llvm/test/Other/new-pm-cgprofile.ll

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: opt -debug-pass-manager -passes='default<O2>' %s 2>&1 |FileCheck %s --check-prefixes=DEFAULT
2+
; RUN: opt -debug-pass-manager -passes='default<O2>' -enable-npm-call-graph-profile=0 %s 2>&1 |FileCheck %s --check-prefixes=OFF
3+
; RUN: opt -debug-pass-manager -passes='default<O2>' -enable-npm-call-graph-profile=1 %s 2>&1 |FileCheck %s --check-prefixes=ON
4+
;
5+
; DEFAULT: Running pass: CGProfilePass
6+
; OFF-NOT: Running pass: CGProfilePass
7+
; ON: Running pass: CGProfilePass
8+
9+
define void @foo() {
10+
ret void
11+
}

llvm/test/Other/opt-O2-pipeline.ll

-6
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,6 @@
280280
; CHECK-NEXT: Strip Unused Function Prototypes
281281
; CHECK-NEXT: Dead Global Elimination
282282
; CHECK-NEXT: Merge Duplicate Global Constants
283-
; CHECK-NEXT: Call Graph Profile
284-
; CHECK-NEXT: FunctionPass Manager
285-
; CHECK-NEXT: Dominator Tree Construction
286-
; CHECK-NEXT: Natural Loop Information
287-
; CHECK-NEXT: Lazy Branch Probability Analysis
288-
; CHECK-NEXT: Lazy Block Frequency Analysis
289283
; CHECK-NEXT: FunctionPass Manager
290284
; CHECK-NEXT: Dominator Tree Construction
291285
; CHECK-NEXT: Natural Loop Information

llvm/test/Other/opt-O3-pipeline.ll

-6
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,6 @@
285285
; CHECK-NEXT: Strip Unused Function Prototypes
286286
; CHECK-NEXT: Dead Global Elimination
287287
; CHECK-NEXT: Merge Duplicate Global Constants
288-
; CHECK-NEXT: Call Graph Profile
289-
; CHECK-NEXT: FunctionPass Manager
290-
; CHECK-NEXT: Dominator Tree Construction
291-
; CHECK-NEXT: Natural Loop Information
292-
; CHECK-NEXT: Lazy Branch Probability Analysis
293-
; CHECK-NEXT: Lazy Block Frequency Analysis
294288
; CHECK-NEXT: FunctionPass Manager
295289
; CHECK-NEXT: Dominator Tree Construction
296290
; CHECK-NEXT: Natural Loop Information

llvm/test/Other/opt-Os-pipeline.ll

-6
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,6 @@
266266
; CHECK-NEXT: Strip Unused Function Prototypes
267267
; CHECK-NEXT: Dead Global Elimination
268268
; CHECK-NEXT: Merge Duplicate Global Constants
269-
; CHECK-NEXT: Call Graph Profile
270-
; CHECK-NEXT: FunctionPass Manager
271-
; CHECK-NEXT: Dominator Tree Construction
272-
; CHECK-NEXT: Natural Loop Information
273-
; CHECK-NEXT: Lazy Branch Probability Analysis
274-
; CHECK-NEXT: Lazy Block Frequency Analysis
275269
; CHECK-NEXT: FunctionPass Manager
276270
; CHECK-NEXT: Dominator Tree Construction
277271
; CHECK-NEXT: Natural Loop Information

0 commit comments

Comments
 (0)