Skip to content

Commit

Permalink
util: Make with_snapshots an interface with two provided implementa…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
lkorenc committed May 7, 2024
1 parent 97e8479 commit 1fd3c29
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions include/vast/Util/Pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ namespace vast {
using output_stream_ptr = std::shared_ptr< llvm::raw_pwrite_stream >;
using passes_t = std::vector< llvm::StringRef >;

passes_t snapshot_at;
std::string file_prefix;

with_snapshots(const passes_t &snapshot_at, llvm::StringRef file_prefix)
: snapshot_at(snapshot_at),
file_prefix(file_prefix.str())
with_snapshots(llvm::StringRef file_prefix)
: file_prefix(file_prefix.str())
{}

// We return `shared_ptr` in case we may want to keep the stream open for longer
Expand All @@ -104,9 +102,7 @@ namespace vast {
return std::move(os);
}

bool should_snapshot(mlir::Pass *pass) const {
return std::ranges::count(snapshot_at, pass->getArgument());
}
virtual bool should_snapshot(mlir::Pass *pass) const = 0;

void runAfterPass(mlir::Pass *pass, operation op) override {
if (!should_snapshot(pass))
Expand All @@ -117,6 +113,30 @@ namespace vast {
}
};

struct snapshot_at_passes : with_snapshots {
using base = with_snapshots;

passes_t snapshot_at;

template< typename ... Args >
snapshot_at_passes(const passes_t &snapshot_at, Args && ... args)
: base(std::forward< Args >(args)...), snapshot_at(snapshot_at)
{}

virtual bool should_snapshot(mlir::Pass *pass) const override {
return std::ranges::count(snapshot_at, pass->getArgument());
}
};

struct snapshot_all : with_snapshots {
using base = with_snapshots;
using base::base;

bool should_snapshot(mlir::Pass *) const override {
return true;
}
};


using pipeline_step_builder = std::function< pipeline_step_ptr(void) >;

Expand Down

0 comments on commit 1fd3c29

Please sign in to comment.