Skip to content

Commit a99e32b

Browse files
Revert "[Polly] Update ScopInliner for NPM (#125427)"
This reverts commit 0b9a7b8. This is causing test failures under LLVM: 1. Other/pass-pipeline-parsing.ll This broke premerge. This was notably not caught by premerge testing on the original PR because the original PR only touches polly, and premerge does not test LLVM when only polly is touched.
1 parent 7bbb03d commit a99e32b

File tree

9 files changed

+71
-184
lines changed

9 files changed

+71
-184
lines changed

polly/docs/ReleaseNotes.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ In Polly |version| the following important changes have been incorporated.
1111
the new features that have recently been committed to our development
1212
branch.
1313

14-
* ScopInliner has been updated for the New Pass Manager.
15-

polly/include/polly/LinkAllPasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct PollyForcePassLinking {
119119

120120
namespace llvm {
121121
void initializeCodePreparationPass(llvm::PassRegistry &);
122-
void initializeScopInlinerWrapperPassPass(llvm::PassRegistry &);
122+
void initializeScopInlinerPass(llvm::PassRegistry &);
123123
void initializeScopDetectionWrapperPassPass(llvm::PassRegistry &);
124124
void initializeScopDetectionPrinterLegacyPassPass(llvm::PassRegistry &);
125125
void initializeScopInfoRegionPassPass(PassRegistry &);

polly/include/polly/ScopInliner.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

polly/lib/Support/PollyPasses.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#ifndef CGSCC_PASS
2-
#define CGSCC_PASS(NAME, CREATE_PASS, PARSER)
3-
#endif
4-
CGSCC_PASS("polly-inline", ScopInlinerPass(), parseNoOptions)
5-
#undef CGSCC_PASS
6-
71
#ifndef FUNCTION_ANALYSIS
82
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS)
93
#endif

polly/lib/Support/RegisterPasses.cpp

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "polly/ScopDetection.h"
3636
#include "polly/ScopGraphPrinter.h"
3737
#include "polly/ScopInfo.h"
38-
#include "polly/ScopInliner.h"
3938
#include "polly/Simplify.h"
4039
#include "polly/Support/DumpFunctionPass.h"
4140
#include "polly/Support/DumpModulePass.h"
@@ -47,13 +46,10 @@
4746
#include "llvm/Passes/PassBuilder.h"
4847
#include "llvm/Passes/PassPlugin.h"
4948
#include "llvm/Support/CommandLine.h"
50-
#include "llvm/Support/Error.h"
5149
#include "llvm/Support/TargetSelect.h"
5250
#include "llvm/Transforms/IPO.h"
5351

54-
using namespace llvm;
5552
namespace cl = llvm::cl;
56-
using namespace polly;
5753

5854
using llvm::FunctionPassManager;
5955
using llvm::OptimizationLevel;
@@ -237,7 +233,7 @@ void initializePollyPasses(llvm::PassRegistry &Registry) {
237233
initializePollyCanonicalizePass(Registry);
238234
initializeScopDetectionWrapperPassPass(Registry);
239235
initializeScopDetectionPrinterLegacyPassPass(Registry);
240-
initializeScopInlinerWrapperPassPass(Registry);
236+
initializeScopInlinerPass(Registry);
241237
initializeScopInfoRegionPassPass(Registry);
242238
initializeScopInfoPrinterLegacyRegionPassPass(Registry);
243239
initializeScopInfoWrapperPassPass(Registry);
@@ -438,16 +434,6 @@ static void buildLatePollyPipeline(FunctionPassManager &PM,
438434
false);
439435
}
440436

441-
static llvm::Expected<std::monostate> parseNoOptions(StringRef Params) {
442-
if (!Params.empty())
443-
return make_error<StringError>(
444-
formatv("'{0}' passed to pass that does not take any options", Params)
445-
.str(),
446-
inconvertibleErrorCode());
447-
448-
return std::monostate{};
449-
}
450-
451437
static OwningScopAnalysisManagerFunctionProxy
452438
createScopAnalyses(FunctionAnalysisManager &FAM,
453439
PassInstrumentationCallbacks *PIC) {
@@ -475,25 +461,6 @@ static void registerFunctionAnalyses(FunctionAnalysisManager &FAM,
475461
FAM.registerPass([&FAM, PIC] { return createScopAnalyses(FAM, PIC); });
476462
}
477463

478-
static llvm::Expected<bool>
479-
parseCGPipeline(StringRef Name, llvm::CGSCCPassManager &CGPM,
480-
PassInstrumentationCallbacks *PIC,
481-
ArrayRef<PassBuilder::PipelineElement> Pipeline) {
482-
assert(Pipeline.empty());
483-
484-
#define CGSCC_PASS(NAME, CREATE_PASS, PARSER) \
485-
if (PassBuilder::checkParametrizedPassName(Name, NAME)) { \
486-
auto Params = PassBuilder::parsePassParameters(PARSER, Name, NAME); \
487-
if (!Params) \
488-
return Params.takeError(); \
489-
CGPM.addPass(CREATE_PASS); \
490-
return true; \
491-
}
492-
#include "PollyPasses.def"
493-
494-
return false;
495-
}
496-
497464
static bool
498465
parseFunctionPipeline(StringRef Name, FunctionPassManager &FPM,
499466
ArrayRef<PassBuilder::PipelineElement> Pipeline) {
@@ -631,12 +598,6 @@ void registerPollyPasses(PassBuilder &PB) {
631598
ArrayRef<PassBuilder::PipelineElement> Pipeline) -> bool {
632599
return parseScopPipeline(Name, FPM, PIC, Pipeline);
633600
});
634-
PB.registerPipelineParsingCallback(
635-
[PIC](StringRef Name, CGSCCPassManager &CGPM,
636-
ArrayRef<PassBuilder::PipelineElement> Pipeline) -> bool {
637-
ExitOnError Err("Unable to parse Polly call graph pass: ");
638-
return Err(parseCGPipeline(Name, CGPM, PIC, Pipeline));
639-
});
640601
PB.registerParseTopLevelPipelineCallback(
641602
[PIC](llvm::ModulePassManager &MPM,
642603
ArrayRef<PassBuilder::PipelineElement> Pipeline) -> bool {

polly/lib/Transform/ScopInliner.cpp

Lines changed: 61 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16-
#include "polly/ScopInliner.h"
16+
#include "polly/LinkAllPasses.h"
1717
#include "polly/ScopDetection.h"
18-
#include "polly/ScopInliner.h"
1918
#include "llvm/Analysis/CallGraph.h"
2019
#include "llvm/Analysis/CallGraphSCCPass.h"
21-
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
22-
#include "llvm/Analysis/RegionInfo.h"
23-
#include "llvm/IR/Dominators.h"
2420
#include "llvm/IR/PassManager.h"
2521
#include "llvm/Passes/PassBuilder.h"
2622
#include "llvm/Transforms/IPO/AlwaysInliner.h"
@@ -32,77 +28,13 @@ using namespace llvm;
3228
using namespace polly;
3329

3430
namespace {
35-
36-
/// Inliner implementation that works with both, LPM (using SCC_t=CallGraph) and
37-
/// NPM (using SCC_t=LazyCallGraph::SCC)
38-
template <typename SCC_t> bool runScopInlinerImpl(Function *F, SCC_t &SCC) {
39-
// We do not try to inline non-trivial SCCs because this would lead to
40-
// "infinite" inlining if we are not careful.
41-
if (SCC.size() > 1)
42-
return false;
43-
assert(SCC.size() == 1 && "found empty SCC");
44-
45-
// If the function is a nullptr, or the function is a declaration.
46-
if (!F)
47-
return false;
48-
if (F->isDeclaration()) {
49-
POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
50-
<< "because it is a declaration.\n");
51-
return false;
52-
}
53-
54-
PassBuilder PB;
55-
// Populate analysis managers and register Polly-specific analyses.
56-
LoopAnalysisManager LAM;
57-
FunctionAnalysisManager FAM;
58-
CGSCCAnalysisManager CGAM;
59-
ModuleAnalysisManager MAM;
60-
PB.registerModuleAnalyses(MAM);
61-
PB.registerCGSCCAnalyses(CGAM);
62-
PB.registerFunctionAnalyses(FAM);
63-
PB.registerLoopAnalyses(LAM);
64-
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
65-
66-
auto &DT = FAM.getResult<DominatorTreeAnalysis>(*F);
67-
auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(*F);
68-
auto &LI = FAM.getResult<LoopAnalysis>(*F);
69-
auto &RI = FAM.getResult<RegionInfoAnalysis>(*F);
70-
auto &AA = FAM.getResult<AAManager>(*F);
71-
auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(*F);
72-
ScopDetection SD(DT, SE, LI, RI, AA, ORE);
73-
SD.detect(*F);
74-
75-
const bool HasScopAsTopLevelRegion =
76-
SD.ValidRegions.contains(RI.getTopLevelRegion());
77-
78-
bool Changed = false;
79-
if (HasScopAsTopLevelRegion) {
80-
POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
81-
<< " has scop as top level region");
82-
F->addFnAttr(llvm::Attribute::AlwaysInline);
83-
84-
ModulePassManager MPM;
85-
MPM.addPass(AlwaysInlinerPass());
86-
Module *M = F->getParent();
87-
assert(M && "Function has illegal module");
88-
PreservedAnalyses PA = MPM.run(*M, MAM);
89-
if (!PA.areAllPreserved())
90-
Changed = true;
91-
} else {
92-
POLLY_DEBUG(dbgs() << F->getName()
93-
<< " does NOT have scop as top level region\n");
94-
}
95-
96-
return Changed;
97-
}
98-
99-
class ScopInlinerWrapperPass final : public CallGraphSCCPass {
31+
class ScopInliner final : public CallGraphSCCPass {
10032
using llvm::Pass::doInitialization;
10133

10234
public:
10335
static char ID;
10436

105-
ScopInlinerWrapperPass() : CallGraphSCCPass(ID) {}
37+
ScopInliner() : CallGraphSCCPass(ID) {}
10638

10739
bool doInitialization(CallGraph &CG) override {
10840
if (!polly::PollyAllowFullFunction) {
@@ -118,48 +50,79 @@ class ScopInlinerWrapperPass final : public CallGraphSCCPass {
11850
}
11951

12052
bool runOnSCC(CallGraphSCC &SCC) override {
53+
// We do not try to inline non-trivial SCCs because this would lead to
54+
// "infinite" inlining if we are not careful.
55+
if (SCC.size() > 1)
56+
return false;
57+
assert(SCC.size() == 1 && "found empty SCC");
12158
Function *F = (*SCC.begin())->getFunction();
122-
return runScopInlinerImpl(F, SCC);
59+
60+
// If the function is a nullptr, or the function is a declaration.
61+
if (!F)
62+
return false;
63+
if (F->isDeclaration()) {
64+
POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
65+
<< "because it is a declaration.\n");
66+
return false;
67+
}
68+
69+
PassBuilder PB;
70+
// Populate analysis managers and register Polly-specific analyses.
71+
LoopAnalysisManager LAM;
72+
FunctionAnalysisManager FAM;
73+
CGSCCAnalysisManager CGAM;
74+
ModuleAnalysisManager MAM;
75+
FAM.registerPass([] { return ScopAnalysis(); });
76+
PB.registerModuleAnalyses(MAM);
77+
PB.registerCGSCCAnalyses(CGAM);
78+
PB.registerFunctionAnalyses(FAM);
79+
PB.registerLoopAnalyses(LAM);
80+
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
81+
82+
RegionInfo &RI = FAM.getResult<RegionInfoAnalysis>(*F);
83+
ScopDetection &SD = FAM.getResult<ScopAnalysis>(*F);
84+
85+
const bool HasScopAsTopLevelRegion =
86+
SD.ValidRegions.contains(RI.getTopLevelRegion());
87+
88+
bool Changed = false;
89+
if (HasScopAsTopLevelRegion) {
90+
POLLY_DEBUG(dbgs() << "Skipping " << F->getName()
91+
<< " has scop as top level region");
92+
F->addFnAttr(llvm::Attribute::AlwaysInline);
93+
94+
ModulePassManager MPM;
95+
MPM.addPass(AlwaysInlinerPass());
96+
Module *M = F->getParent();
97+
assert(M && "Function has illegal module");
98+
PreservedAnalyses PA = MPM.run(*M, MAM);
99+
if (!PA.areAllPreserved())
100+
Changed = true;
101+
} else {
102+
POLLY_DEBUG(dbgs() << F->getName()
103+
<< " does NOT have scop as top level region\n");
104+
}
105+
106+
return Changed;
123107
};
124108

125109
void getAnalysisUsage(AnalysisUsage &AU) const override {
126110
CallGraphSCCPass::getAnalysisUsage(AU);
127111
}
128112
};
129113
} // namespace
130-
char ScopInlinerWrapperPass::ID;
114+
char ScopInliner::ID;
131115

132-
Pass *polly::createScopInlinerWrapperPass() {
133-
ScopInlinerWrapperPass *pass = new ScopInlinerWrapperPass();
116+
Pass *polly::createScopInlinerPass() {
117+
ScopInliner *pass = new ScopInliner();
134118
return pass;
135119
}
136120

137121
INITIALIZE_PASS_BEGIN(
138-
ScopInlinerWrapperPass, "polly-scop-inliner",
122+
ScopInliner, "polly-scop-inliner",
139123
"inline functions based on how much of the function is a scop.", false,
140124
false)
141125
INITIALIZE_PASS_END(
142-
ScopInlinerWrapperPass, "polly-scop-inliner",
126+
ScopInliner, "polly-scop-inliner",
143127
"inline functions based on how much of the function is a scop.", false,
144128
false)
145-
146-
polly::ScopInlinerPass::ScopInlinerPass() {
147-
if (!polly::PollyAllowFullFunction) {
148-
report_fatal_error(
149-
"Aborting from ScopInliner because it only makes sense to run with "
150-
"-polly-allow-full-function. "
151-
"The heurtistic for ScopInliner checks that the full function is a "
152-
"Scop, which happens if and only if polly-allow-full-function is "
153-
" enabled. "
154-
" If not, the entry block is not included in the Scop");
155-
}
156-
}
157-
158-
PreservedAnalyses polly::ScopInlinerPass::run(llvm::LazyCallGraph::SCC &SCC,
159-
llvm::CGSCCAnalysisManager &AM,
160-
llvm::LazyCallGraph &CG,
161-
llvm::CGSCCUpdateResult &UR) {
162-
Function *F = &SCC.begin()->getFunction();
163-
bool Changed = runScopInlinerImpl(F, SCC);
164-
return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all();
165-
}

polly/test/ScopInliner/ignore-declares.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
; RUN: opt %loadNPMPolly -polly-detect-full-functions '-passes=cgscc(polly-inline),function(print<polly-function-scops>)' -disable-output < %s
1+
; RUN: opt %loadPolly -polly-detect-full-functions -polly-scop-inliner \
2+
; RUN: -polly-scops -disable-output < %s
23

34
; Check that we do not crash if there are declares. We should skip function
45
; declarations and not try to query for domtree.

polly/test/ScopInliner/invariant-load-func.ll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
; RUN: opt %loadNPMPolly -polly-detect-full-functions -polly-invariant-load-hoisting '-passes=cgscc(polly-inline),function(print<polly-function-scops>)' -disable-output < %s 2>&1 | FileCheck %s
1+
; RUN: opt %loadNPMPolly -polly-detect-full-functions -polly-scop-inliner \
2+
; RUN: -polly-invariant-load-hoisting '-passes=print<polly-function-scops>' -disable-output < %s | FileCheck %s
23

34
; Check that we inline a function that requires invariant load hoisting
45
; correctly.
56
; CHECK: Max Loop Depth: 2
67

8+
; REQUIRES: pollyacc
9+
710

811
; void to_be_inlined(int A[], int *begin, int *end) {
912
; for(int i = *begin; i < *end; i++) {

polly/test/ScopInliner/simple-inline-loop.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
; RUN: opt %loadNPMPolly -polly-detect-full-functions '-passes=cgscc(polly-inline),function(print<polly-function-scops>)' -disable-output < %s 2>&1 | FileCheck %s
1+
; RUN: opt %loadPolly -polly-detect-full-functions -polly-scop-inliner \
2+
; RUN: -polly-print-scops -disable-output < %s | FileCheck %s
23

34
; Check that we get the 2 nested loops by inlining `to_be_inlined` into
45
; `inline_site`.

0 commit comments

Comments
 (0)