Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin system #146

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5488cc8
Support plugin execution. Very limited capabilities for now.
m-kurtenacker Jan 31, 2023
0e1b609
Support for multiple input arguments.
m-kurtenacker Jul 28, 2022
3f0f38d
Use RTLD_GLOBAL to enable loading dependent plugins.
m-kurtenacker Sep 13, 2022
21e090e
Add plugin dependencies + option to return values from plugin intrins…
m-kurtenacker Sep 30, 2022
eaf6b75
Partial Evaluation between plugin steps.
m-kurtenacker Jan 20, 2023
da72529
Implement world.release to emit anydsl_release calls in backend, similar
m-kurtenacker Jun 23, 2023
5d2c468
Bugfix: llvm 14 needs pointer cast for release.
m-kurtenacker Jun 26, 2023
59aa49f
Fix MSVC build by disabling plugins
stlemme Jun 27, 2023
c706d3a
use proper CMAKE_DL_LIBS variable
stlemme Jun 27, 2023
a3d9092
Support return nullptr in plugins for void returns.
m-kurtenacker Jun 29, 2023
4d5b1b8
pass World and App to plugin function
michael-kenzel Jul 4, 2023
aea8051
Make plugins explicitly return a Def* to avoid UB.
m-kurtenacker Jul 5, 2023
986dc96
Do not const_cast the app node, use rebuild and replace_uses instead.
m-kurtenacker Jul 5, 2023
dd51c17
Gather plugins without copying continuations.
m-kurtenacker Jul 5, 2023
84fe231
Clearification on app nodes and world.cleanup().
m-kurtenacker Jul 5, 2023
c4423a0
Change plugin sorting comparisson to be asymetric.
m-kurtenacker Jul 5, 2023
3d73ba6
Do not build nvvm in debug mode. It produces broken ptx in some cases.
m-kurtenacker Apr 19, 2024
a81f7fc
Support plugin execution. Very limited capabilities for now.
m-kurtenacker Jan 31, 2023
51a0ae0
Support for multiple input arguments.
m-kurtenacker Jul 28, 2022
aa74f03
Use RTLD_GLOBAL to enable loading dependent plugins.
m-kurtenacker Sep 13, 2022
7d37d32
Add plugin dependencies + option to return values from plugin intrins…
m-kurtenacker Sep 30, 2022
4aed9b0
Partial Evaluation between plugin steps.
m-kurtenacker Jan 20, 2023
df0ceac
Implement world.release to emit anydsl_release calls in backend, similar
m-kurtenacker Jun 23, 2023
d4c4e13
Bugfix: llvm 14 needs pointer cast for release.
m-kurtenacker Jun 26, 2023
e6cb977
Fix MSVC build by disabling plugins
stlemme Jun 27, 2023
afb7d63
use proper CMAKE_DL_LIBS variable
stlemme Jun 27, 2023
6c704f0
Support return nullptr in plugins for void returns.
m-kurtenacker Jun 29, 2023
e45ae79
pass World and App to plugin function
michael-kenzel Jul 4, 2023
471d80b
Make plugins explicitly return a Def* to avoid UB.
m-kurtenacker Jul 5, 2023
8455787
Do not const_cast the app node, use rebuild and replace_uses instead.
m-kurtenacker Jul 5, 2023
807592e
Gather plugins without copying continuations.
m-kurtenacker Jul 5, 2023
1eebe0d
Clearification on app nodes and world.cleanup().
m-kurtenacker Jul 5, 2023
0c37e8d
Change plugin sorting comparisson to be asymetric.
m-kurtenacker Jul 5, 2023
d99f07c
Json: Export plugins and plugin dependencies.
m-kurtenacker Jan 20, 2023
968114c
[Json]: Export filters on plugins without dependencies.
m-kurtenacker Jan 20, 2023
20ab0c6
Plugin execution order: total ordering by calculating dependency depth.
m-kurtenacker Sep 4, 2023
4eb19d5
Bugfix Plugins: Work with new semantics for thorin.cleanup.
m-kurtenacker Oct 6, 2023
b44fbe4
Small improvements for internal continuations. Probably still buggy.
m-kurtenacker Nov 21, 2023
b345444
dump_scoped: Dump filters.
m-kurtenacker Nov 21, 2023
3ffeb3b
Fix handling and emission of external globals.
m-kurtenacker Dec 6, 2023
3c25ecc
Small bugfix in PE for multiple stacked run operations.
m-kurtenacker Dec 12, 2023
e3f8e45
Bugfix if no process can be made in plugin execution.
m-kurtenacker Dec 12, 2023
366f6b3
[JSON] Add support for inf and nan floating point.
m-kurtenacker Jan 19, 2024
63498d2
Some small changes to support edge cases created in certain plugins.
m-kurtenacker Feb 13, 2024
f4ef1d3
Allow disabling collored scoped_dump through environment variable.
m-kurtenacker Mar 19, 2024
417d8f3
WIP: evaluate plugins during PE, not after.
m-kurtenacker Mar 19, 2024
f4e655f
Improve plugin dependency management, allow filters with intrinsics.
m-kurtenacker Mar 27, 2024
138b6f4
Exceptions in plugins added back in.
m-kurtenacker Mar 28, 2024
2776537
Added Thorin::cleanup_fix_point as a less intrusive cleanup option.
m-kurtenacker Mar 28, 2024
a4c8aa0
Do not destroy external continuations during PE.
m-kurtenacker Apr 19, 2024
bf48e92
Merge remote-tracking branch 'origin/plugins' into plugins
m-kurtenacker Jun 20, 2024
50f60fd
Merge branch 'master' into plugins
m-kurtenacker Jun 24, 2024
53e3a87
Fix todo flag handling with plugins. Plugins can now return bottom.
m-kurtenacker Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP: evaluate plugins during PE, not after.
This is not very stable for now. Especially the dependency management
can still break at any point. Thorins uses tracking is not very well
maintained, and can't really deal with dependencies that are dropped by
replacing a continuation with a specialized one. This can lead to dead
code being interpreted as a remaining dependency that will only be
removed when the entire world is being rewritten.
  • Loading branch information
m-kurtenacker committed Jun 20, 2024
commit 417d8f365d8dcb1918a53254e594651ecfb76d6f
2 changes: 1 addition & 1 deletion src/thorin/transform/cleanup_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void Cleaner::cleanup_fix_point() {
todo_ |= resolve_loads(world());
rebuild();
//if (!world().is_pe_done())
todo_ |= partial_evaluation(world());
todo_ |= partial_evaluation(thorin_);
//else
// clean_pe_infos();
}
Expand Down
85 changes: 76 additions & 9 deletions src/thorin/transform/partial_evaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ struct HashApp {

class PartialEvaluator {
public:
PartialEvaluator(World& world, bool lower2cff)
: world_(world)
PartialEvaluator(Thorin& thorin, bool lower2cff)
: thorin_(thorin)
, lower2cff_(lower2cff)
, boundary_(Def::gid_counter())
{}

World& world() { return world_; }
World& world() { return thorin_.world(); }
bool run();
void enqueue(Continuation* continuation) {
if (continuation->gid() < 2 * boundary_ && done_.emplace(continuation).second)
Expand All @@ -31,7 +31,7 @@ class PartialEvaluator {
void eat_pe_info(Continuation*);

private:
World& world_;
Thorin& thorin_;
bool lower2cff_;
HashMap<const App*, Continuation*, HashApp> cache_;
ContinuationSet done_;
Expand Down Expand Up @@ -141,6 +141,73 @@ bool PartialEvaluator::run() {
continue;
}

if (callee->intrinsic() == Intrinsic::Plugin) {
if (callee->attributes().depends) {
size_t num_dependend_uses = 0;
for (auto use : callee->attributes().depends->uses()) {
num_dependend_uses += use.def()->num_uses();
}
//std::cerr << "Analyzing " << callee->unique_name() << " with dependency " << callee->attributes().depends->unique_name() << "\n";
//std::cerr << " => has " << num_dependend_uses << " real dependencies\n";
if (num_dependend_uses > 0) {
//Push the next continue so that other plugins get executed.
for (auto arg : body->args()) {
if (auto cont = arg->isa<Continuation>()) {
queue_.push(const_cast<Continuation*>(cont));
}
}
continue;
}
}

ScopesForest forest(world());
CondEval cond_eval(callee, forest, body->args());

//TODO: build specialize here to allow for parameter hiding.
bool fold = false;
for (size_t i = 0, e = body->num_args(); i != e; ++i) {
if (cond_eval.eval(i, lower2cff_)) {
fold = true;
break;
}
}

if (fold) {
std::vector<const Def*> specialize(body->arg(body->num_args() - 1)->as<Continuation>()->num_params());
specialize[0] = body->arg(0);

const auto& p = cache_.emplace(body, nullptr);
const Continuation* target = p.first->second;
// create new specialization if not found in cache
if (p.second) {
world().idef(continuation, "Plugin execute: {}", callee);

auto plugin_function = thorin_.search_plugin_function(callee->name().c_str());
if (!plugin_function) {
world().ELOG("Plugin function not found for: {}", callee->name());
continue;
}

const Def* output = plugin_function(&world(), body);
if (output)
specialize[1] = output;

target = body->arg(body->num_args() - 1)->as<Continuation>();
todo = true;
}
continuation->jump(target, specialize);

if (lower2cff_ && fold) {
// re-examine next iteration:
// maybe the specialization is not top-level anymore which might need further specialization
queue_.push(continuation);
continue;
}
}

continue;
}

if (callee->has_body()) {
// TODO cache the forest and only rebuild it when we need to
ScopesForest forest(world());
Expand All @@ -162,7 +229,7 @@ bool PartialEvaluator::run() {
Continuation*& target = p.first->second;
// create new specialization if not found in cache
if (p.second) {
world_.ddef(continuation, "Specializing call to {}", callee);
world().ddef(continuation, "Specializing call to {}", callee);
target = drop(callee, specialize);
todo = true;
}
Expand Down Expand Up @@ -198,11 +265,11 @@ bool PartialEvaluator::run() {

//------------------------------------------------------------------------------

bool partial_evaluation(World& world, bool lower2cff) {
bool partial_evaluation(Thorin& thorin, bool lower2cff) {
auto name = lower2cff ? "lower2cff" : "partial_evaluation";
world.VLOG("start {}", name);
auto res = PartialEvaluator(world, lower2cff).run();
world.VLOG("end {}", name);
thorin.world().VLOG("start {}", name);
auto res = PartialEvaluator(thorin, lower2cff).run();
thorin.world().VLOG("end {}", name);
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion src/thorin/transform/partial_evaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BetaReducer : public Rewriter {
const Def* rewrite(const Def* odef) override;
};

bool partial_evaluation(World&, bool lower2cff = false);
bool partial_evaluation(Thorin&, bool lower2cff = false);

}

Expand Down
10 changes: 5 additions & 5 deletions src/thorin/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,13 +1320,13 @@ void Thorin::opt() {
}

RUN_PASS(cleanup())
RUN_PASS(while (partial_evaluation(world(), true))); // lower2cff
RUN_PASS(while (partial_evaluation(*this, true))); // lower2cff
RUN_PASS(flatten_tuples(*this))
RUN_PASS(split_slots(*this))
if (plugin_handles.size() > 0) {
RUN_PASS(plugin_execute(*this));
RUN_PASS(cleanup());
}
//if (plugin_handles.size() > 0) {
// RUN_PASS(plugin_execute(*this));
// RUN_PASS(cleanup());
//}
RUN_PASS(closure_conversion(world()))
RUN_PASS(lift_builtins(*this))
RUN_PASS(inliner(*this))
Expand Down