Skip to content

Commit 102c384

Browse files
authored
Revert "[SandboxVectorizer] Use sbvec-passes flag to create a pipeline of Region passes after BottomUpVec." (llvm#111727)
Reverts llvm#111223 It broke one of the build bots: LLVM Buildbot has detected a new failure on builder flang-aarch64-libcxx running on linaro-flang-aarch64-libcxx while building llvm at step 5 "build-unified-tree". Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/8127
1 parent dc09f96 commit 102c384

File tree

11 files changed

+183
-204
lines changed

11 files changed

+183
-204
lines changed

llvm/include/llvm/SandboxIR/PassManager.h

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#ifndef LLVM_SANDBOXIR_PASSMANAGER_H
1919
#define LLVM_SANDBOXIR_PASSMANAGER_H
2020

21-
#include <memory>
22-
2321
#include "llvm/ADT/DenseMap.h"
2422
#include "llvm/ADT/STLExtras.h"
2523
#include "llvm/SandboxIR/Pass.h"
@@ -34,65 +32,25 @@ template <typename ParentPass, typename ContainedPass>
3432
class PassManager : public ParentPass {
3533
protected:
3634
/// The list of passes that this pass manager will run.
37-
SmallVector<std::unique_ptr<ContainedPass>> Passes;
35+
SmallVector<ContainedPass *> Passes;
3836

3937
PassManager(StringRef Name) : ParentPass(Name) {}
4038
PassManager(const PassManager &) = delete;
41-
PassManager(PassManager &&) = default;
4239
virtual ~PassManager() = default;
4340
PassManager &operator=(const PassManager &) = delete;
4441

4542
public:
4643
/// Adds \p Pass to the pass pipeline.
47-
void addPass(std::unique_ptr<ContainedPass> Pass) {
44+
void addPass(ContainedPass *Pass) {
4845
// TODO: Check that Pass's class type works with this PassManager type.
49-
Passes.push_back(std::move(Pass));
50-
}
51-
52-
using CreatePassFunc =
53-
std::function<std::unique_ptr<ContainedPass>(StringRef)>;
54-
55-
/// Parses \p Pipeline as a comma-separated sequence of pass names and sets
56-
/// the pass pipeline, using \p CreatePass to instantiate passes by name.
57-
///
58-
/// After calling this function, the PassManager contains only the specified
59-
/// pipeline, any previously added passes are cleared.
60-
void setPassPipeline(StringRef Pipeline, CreatePassFunc CreatePass) {
61-
static constexpr const char EndToken = '\0';
62-
static constexpr const char PassDelimToken = ',';
63-
64-
assert(Passes.empty() &&
65-
"setPassPipeline called on a non-empty sandboxir::PassManager");
66-
// Add EndToken to the end to ease parsing.
67-
std::string PipelineStr = std::string(Pipeline) + EndToken;
68-
int FlagBeginIdx = 0;
69-
70-
for (auto [Idx, C] : enumerate(PipelineStr)) {
71-
// Keep moving Idx until we find the end of the pass name.
72-
bool FoundDelim = C == EndToken || C == PassDelimToken;
73-
if (!FoundDelim)
74-
continue;
75-
unsigned Sz = Idx - FlagBeginIdx;
76-
std::string PassName(&PipelineStr[FlagBeginIdx], Sz);
77-
FlagBeginIdx = Idx + 1;
78-
79-
// Get the pass that corresponds to PassName and add it to the pass
80-
// manager.
81-
auto Pass = CreatePass(PassName);
82-
if (Pass == nullptr) {
83-
errs() << "Pass '" << PassName << "' not registered!\n";
84-
exit(1);
85-
}
86-
addPass(std::move(Pass));
87-
}
46+
Passes.push_back(Pass);
8847
}
89-
9048
#ifndef NDEBUG
9149
void print(raw_ostream &OS) const override {
9250
OS << this->getName();
9351
OS << "(";
9452
// TODO: This should call Pass->print(OS) because Pass may be a PM.
95-
interleave(Passes, OS, [&OS](auto &Pass) { OS << Pass->getName(); }, ",");
53+
interleave(Passes, OS, [&OS](auto *Pass) { OS << Pass->getName(); }, ",");
9654
OS << ")";
9755
}
9856
LLVM_DUMP_METHOD void dump() const override {
@@ -121,6 +79,38 @@ class RegionPassManager final : public PassManager<RegionPass, RegionPass> {
12179
bool runOnRegion(Region &R) final;
12280
};
12381

82+
/// Owns the passes and provides an API to get a pass by its name.
83+
class PassRegistry {
84+
SmallVector<std::unique_ptr<Pass>, 8> Passes;
85+
DenseMap<StringRef, Pass *> NameToPassMap;
86+
87+
public:
88+
static constexpr const char PassDelimToken = ',';
89+
PassRegistry() = default;
90+
/// Registers \p PassPtr and takes ownership.
91+
Pass &registerPass(std::unique_ptr<Pass> &&PassPtr) {
92+
auto &PassRef = *PassPtr.get();
93+
NameToPassMap[PassRef.getName()] = &PassRef;
94+
Passes.push_back(std::move(PassPtr));
95+
return PassRef;
96+
}
97+
/// \Returns the pass with name \p Name, or null if not registered.
98+
Pass *getPassByName(StringRef Name) const {
99+
auto It = NameToPassMap.find(Name);
100+
return It != NameToPassMap.end() ? It->second : nullptr;
101+
}
102+
/// Creates a pass pipeline and returns the first pass manager.
103+
FunctionPassManager &parseAndCreatePassPipeline(StringRef Pipeline);
104+
105+
#ifndef NDEBUG
106+
void print(raw_ostream &OS) const {
107+
for (const auto &PassPtr : Passes)
108+
OS << PassPtr->getName() << "\n";
109+
}
110+
LLVM_DUMP_METHOD void dump() const;
111+
#endif
112+
};
113+
124114
} // namespace llvm::sandboxir
125115

126116
#endif // LLVM_SANDBOXIR_PASSMANAGER_H

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,18 @@
1515
#include "llvm/ADT/ArrayRef.h"
1616
#include "llvm/SandboxIR/Constant.h"
1717
#include "llvm/SandboxIR/Pass.h"
18-
#include "llvm/SandboxIR/PassManager.h"
1918
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Legality.h"
2019

2120
namespace llvm::sandboxir {
2221

23-
class RegionPassManager;
24-
2522
class BottomUpVec final : public FunctionPass {
2623
bool Change = false;
2724
LegalityAnalysis Legality;
2825
void vectorizeRec(ArrayRef<Value *> Bndl);
2926
void tryVectorize(ArrayRef<Value *> Seeds);
3027

31-
// The PM containing the pipeline of region passes.
32-
RegionPassManager RPM;
33-
3428
public:
35-
BottomUpVec();
29+
BottomUpVec() : FunctionPass("bottom-up-vec") {}
3630
bool runOnFunction(Function &F) final;
3731
};
3832

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/NullPass.h

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

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H
99
#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SANDBOXVECTORIZER_H
1010

11-
#include <memory>
12-
1311
#include "llvm/IR/PassManager.h"
14-
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.h"
1512

1613
namespace llvm {
1714

@@ -20,13 +17,10 @@ class TargetTransformInfo;
2017
class SandboxVectorizerPass : public PassInfoMixin<SandboxVectorizerPass> {
2118
TargetTransformInfo *TTI = nullptr;
2219

23-
// The main vectorizer pass.
24-
sandboxir::BottomUpVec BottomUpVecPass;
25-
26-
bool runImpl(Function &F);
27-
2820
public:
2921
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
22+
23+
bool runImpl(Function &F);
3024
};
3125

3226
} // namespace llvm

llvm/lib/SandboxIR/PassManager.cpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
#include "llvm/SandboxIR/PassManager.h"
1010

11-
namespace llvm::sandboxir {
11+
using namespace llvm::sandboxir;
1212

1313
bool FunctionPassManager::runOnFunction(Function &F) {
1414
bool Change = false;
15-
for (auto &Pass : Passes) {
15+
for (FunctionPass *Pass : Passes) {
1616
Change |= Pass->runOnFunction(F);
1717
// TODO: run the verifier.
1818
}
@@ -22,12 +22,48 @@ bool FunctionPassManager::runOnFunction(Function &F) {
2222

2323
bool RegionPassManager::runOnRegion(Region &R) {
2424
bool Change = false;
25-
for (auto &Pass : Passes) {
25+
for (RegionPass *Pass : Passes) {
2626
Change |= Pass->runOnRegion(R);
2727
// TODO: run the verifier.
2828
}
2929
// TODO: Check ChangeAll against hashes before/after.
3030
return Change;
3131
}
3232

33-
} // namespace llvm::sandboxir
33+
FunctionPassManager &
34+
PassRegistry::parseAndCreatePassPipeline(StringRef Pipeline) {
35+
static constexpr const char EndToken = '\0';
36+
// Add EndToken to the end to ease parsing.
37+
std::string PipelineStr = std::string(Pipeline) + EndToken;
38+
int FlagBeginIdx = 0;
39+
// Start with a FunctionPassManager.
40+
auto &InitialPM = static_cast<FunctionPassManager &>(
41+
registerPass(std::make_unique<FunctionPassManager>("init-fpm")));
42+
43+
for (auto [Idx, C] : enumerate(PipelineStr)) {
44+
// Keep moving Idx until we find the end of the pass name.
45+
bool FoundDelim = C == EndToken || C == PassDelimToken;
46+
if (!FoundDelim)
47+
continue;
48+
unsigned Sz = Idx - FlagBeginIdx;
49+
std::string PassName(&PipelineStr[FlagBeginIdx], Sz);
50+
FlagBeginIdx = Idx + 1;
51+
52+
// Get the pass that corresponds to PassName and add it to the pass manager.
53+
auto *Pass = getPassByName(PassName);
54+
if (Pass == nullptr) {
55+
errs() << "Pass '" << PassName << "' not registered!\n";
56+
exit(1);
57+
}
58+
// TODO: This is safe for now, but would require proper upcasting once we
59+
// add more Pass sub-classes.
60+
InitialPM.addPass(static_cast<FunctionPass *>(Pass));
61+
}
62+
return InitialPM;
63+
}
64+
#ifndef NDEBUG
65+
void PassRegistry::dump() const {
66+
print(dbgs());
67+
dbgs() << "\n";
68+
}
69+
#endif // NDEBUG

llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/BottomUpVec.cpp

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,10 @@
1010
#include "llvm/ADT/SmallVector.h"
1111
#include "llvm/SandboxIR/Function.h"
1212
#include "llvm/SandboxIR/Instruction.h"
13-
#include "llvm/Support/CommandLine.h"
14-
#include "llvm/Transforms/Vectorize/SandboxVectorizer/Passes/NullPass.h"
1513

16-
namespace llvm::sandboxir {
17-
18-
static cl::opt<bool>
19-
PrintPassPipeline("sbvec-print-pass-pipeline", cl::init(false), cl::Hidden,
20-
cl::desc("Prints the pass pipeline and returns."));
21-
22-
/// A magic string for the default pass pipeline.
23-
static const char *DefaultPipelineMagicStr = "*";
24-
25-
static cl::opt<std::string> UserDefinedPassPipeline(
26-
"sbvec-passes", cl::init(DefaultPipelineMagicStr), cl::Hidden,
27-
cl::desc("Comma-separated list of vectorizer passes. If not set "
28-
"we run the predefined pipeline."));
29-
30-
static std::unique_ptr<RegionPass> createRegionPass(StringRef Name) {
31-
#define REGION_PASS(NAME, CREATE_PASS) \
32-
if (Name == NAME) \
33-
return std::make_unique<decltype(CREATE_PASS)>(CREATE_PASS);
34-
#include "PassRegistry.def"
35-
return nullptr;
36-
}
37-
38-
BottomUpVec::BottomUpVec() : FunctionPass("bottom-up-vec"), RPM("rpm") {
39-
// Create a pipeline to be run on each Region created by BottomUpVec.
40-
if (UserDefinedPassPipeline == DefaultPipelineMagicStr) {
41-
// TODO: Add default passes to RPM.
42-
} else {
43-
// Create the user-defined pipeline.
44-
RPM.setPassPipeline(UserDefinedPassPipeline, createRegionPass);
45-
}
46-
}
14+
using namespace llvm::sandboxir;
4715

16+
namespace llvm::sandboxir {
4817
// TODO: This is a temporary function that returns some seeds.
4918
// Replace this with SeedCollector's function when it lands.
5019
static llvm::SmallVector<Value *, 4> collectSeeds(BasicBlock &BB) {
@@ -65,6 +34,8 @@ static SmallVector<Value *, 4> getOperand(ArrayRef<Value *> Bndl,
6534
return Operands;
6635
}
6736

37+
} // namespace llvm::sandboxir
38+
6839
void BottomUpVec::vectorizeRec(ArrayRef<Value *> Bndl) {
6940
auto LegalityRes = Legality.canVectorize(Bndl);
7041
switch (LegalityRes.getSubclassID()) {
@@ -82,23 +53,14 @@ void BottomUpVec::vectorizeRec(ArrayRef<Value *> Bndl) {
8253
void BottomUpVec::tryVectorize(ArrayRef<Value *> Bndl) { vectorizeRec(Bndl); }
8354

8455
bool BottomUpVec::runOnFunction(Function &F) {
85-
if (PrintPassPipeline) {
86-
RPM.printPipeline(outs());
87-
return false;
88-
}
89-
9056
Change = false;
9157
// TODO: Start from innermost BBs first
9258
for (auto &BB : F) {
9359
// TODO: Replace with proper SeedCollector function.
9460
auto Seeds = collectSeeds(BB);
9561
// TODO: Slice Seeds into smaller chunks.
96-
// TODO: If vectorization succeeds, run the RegionPassManager on the
97-
// resulting region.
9862
if (Seeds.size() >= 2)
9963
tryVectorize(Seeds);
10064
}
10165
return Change;
10266
}
103-
104-
} // namespace llvm::sandboxir

llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/PassRegistry.def

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

0 commit comments

Comments
 (0)