Skip to content

Commit

Permalink
Encapsulate PassManager
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed Mar 8, 2011
1 parent b536820 commit 3a4e1ab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
45 changes: 43 additions & 2 deletions runtime/parrot/library/LLVM/PassManager.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
class LLVM::PassManager is LLVM::Opaque {
method create() {
self.create(%LLVM::F<CreatePassManager>());
# List of available passes
# TODO: Add all of them here.
our %PASS := hash(
ConstantPropagationPass => 1,
InstructionCombiningPass => 1,
PromoteMemoryToRegisterPass => 1,
GVNPass => 1,
CFGSimplificationPass => 1,
FunctionInliningPass => 1,
);

# Optimizations used by default
our @DEFAULT_OPTIMIZATIONS := <
ConstantPropagationPass
InstructionCombiningPass
PromoteMemoryToRegisterPass
GVNPass
CFGSimplificationPass
FunctionInliningPass
>;

method create(:$optimize?) {
my $res := self.new.wrap(%LLVM::F<CreatePassManager>());

if $optimize {
$res.add($_) for @DEFAULT_OPTIMIZATIONS;
}

$res;
}

method DESTROY() {
%LLVM::F<DisposePassManager>(self);
}

method add(Str $name) {
my $m := %LLVM::F{"Add" ~ $name};
pir::die("Unknown pass $name") unless pir::defined($m);
$m(self);
}

method run(LLVM::Module $module) {
%LLVM::F<RunPassManager>(self, $module);
}
}

Expand Down
19 changes: 3 additions & 16 deletions t/library/llvm.t
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,10 @@ $res := $call("Hello from Parrot!\n");
is($res, "Hello from Parrot!\n", "Got same string back");

# Let's optimize it.
my $pass := %LLVM::F<CreatePassManager>();
my $pass := LLVM::PassManager.create(:optimize);
ok(1, "Pass Manager created");
%LLVM::F<AddConstantPropagationPass>($pass);
ok(1, "AddConstantPropagationPass");
%LLVM::F<AddInstructionCombiningPass>($pass);
ok(1, "AddInstructionCombiningPass");
%LLVM::F<AddPromoteMemoryToRegisterPass>($pass);
ok(1, "AddPromoteMemoryToRegisterPass");
%LLVM::F<AddGVNPass>($pass);
ok(1, "AddGVNPass");
%LLVM::F<AddCFGSimplificationPass>($pass);
ok(1, "AddCFGSimplificationPass");

%LLVM::F<AddFunctionInliningPass>($pass);
ok(1, "AddFunctionInliningPass");

%LLVM::F<RunPassManager>($pass, $module);

$pass.run($module);
ok(1, "RunPassManager");

$module.dump();
Expand Down

0 comments on commit 3a4e1ab

Please sign in to comment.