Skip to content

Commit

Permalink
pre prep phase
Browse files Browse the repository at this point in the history
  • Loading branch information
NeuralCoder3 committed Sep 14, 2022
1 parent 3c43b33 commit c55b74f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dialects/tool/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace thorin;
extern "C" THORIN_EXPORT thorin::DialectInfo thorin_get_dialect_info() {
return {"tool",
[](thorin::PipelineBuilder& builder) {
builder.extend_codegen_prep_phase([](PassMan& man) { man.add<thorin::tool::SetFilter>(); });
builder.extend_opt_prep_phase2([](PassMan& man) { man.add<thorin::tool::SetFilter>(); });
},
nullptr, [](Normalizers& normalizers) { tool::register_normalizers(normalizers); }};
}
4 changes: 3 additions & 1 deletion thorin/pass/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ namespace thorin {

void optimize(World& world, PipelineBuilder& builder) {
Pipeline pipe(world);
pipe.add<PassManPhase>(builder.opt_prep_phase1(world));
pipe.add<Scalerize>();
pipe.add<EtaRed>();
pipe.add<TailRecElim>();
pipe.add<PassManPhase>(builder.opt_prep_phase2(world));
pipe.add<PassManPhase>(builder.opt_phase(world));
pipe.add<LamSpec>();
pipe.add<PassManPhase>(builder.codegen_prep_phase(world));
pipe.add<PassManPhase>(builder.opt_phase2(world));
// pipe.add<PassManPhase>(builder.opt_phase2(world));
pipe.run();
}

Expand Down
24 changes: 24 additions & 0 deletions thorin/pass/pipelinebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ void PipelineBuilder::extend_codegen_prep_phase(std::function<void(PassMan&)> ex
codegen_prep_phase_extensions_.push_back(extension);
}

void PipelineBuilder::extend_opt_prep_phase1(std::function<void(PassMan&)> extension) {
opt_prep_phase1_extensions_.push_back(extension);
}

void PipelineBuilder::extend_opt_prep_phase2(std::function<void(PassMan&)> extension) {
opt_prep_phase2_extensions_.push_back(extension);
}

std::unique_ptr<PassMan> PipelineBuilder::opt_phase2(World& world) {
auto man = std::make_unique<PassMan>(world);

Expand Down Expand Up @@ -61,4 +69,20 @@ std::unique_ptr<PassMan> PipelineBuilder::codegen_prep_phase(World& world) {
return man;
}

std::unique_ptr<PassMan> PipelineBuilder::opt_prep_phase1(World& world) {
auto man = std::make_unique<PassMan>(world);

for (const auto& ext : opt_prep_phase1_extensions_) ext(*man);

return man;
}

std::unique_ptr<PassMan> PipelineBuilder::opt_prep_phase2(World& world) {
auto man = std::make_unique<PassMan>(world);

for (const auto& ext : opt_prep_phase2_extensions_) ext(*man);

return man;
}

} // namespace thorin
6 changes: 6 additions & 0 deletions thorin/pass/pipelinebuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ class PipelineBuilder {

void extend_opt_phase(std::function<void(PassMan&)>);
void extend_codegen_prep_phase(std::function<void(PassMan&)>);
void extend_opt_prep_phase1(std::function<void(PassMan&)>);
void extend_opt_prep_phase2(std::function<void(PassMan&)>);

std::unique_ptr<PassMan> opt_phase(World& world);
std::unique_ptr<PassMan> opt_phase2(World& world);
std::unique_ptr<PassMan> codegen_prep_phase(World& world);
std::unique_ptr<PassMan> opt_prep_phase1(World& world);
std::unique_ptr<PassMan> opt_prep_phase2(World& world);

private:
std::vector<std::function<void(PassMan&)>> opt_phase_extensions_;
std::vector<std::function<void(PassMan&)>> codegen_prep_phase_extensions_;
std::vector<std::function<void(PassMan&)>> opt_prep_phase1_extensions_;
std::vector<std::function<void(PassMan&)>> opt_prep_phase2_extensions_;
};

} // namespace thorin

0 comments on commit c55b74f

Please sign in to comment.