-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
96 lines (70 loc) · 3.46 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
NAME
optimizer - Write your own Perl optimizer, in Perl
SYNOPSIS
# Use Perl's default optimizer
use optimizer 'C';
# Use a Perl implementation of the default optimizer
use optimizer 'perl';
# Use an extension of the default optimizer
use optimizer extend => sub {
warn "goto considered harmful" if $_[0]-1>name eq "goto"
}
# Use a simple optimizer with callbacks for each op
use optimizer callback => sub { .. }
# Completely implement your own optimizre
use optimizer mine => sub { ... }
# use the standard optimizer with an extra callback
# this is the most compatible optimizer version
use optimizer 'extend-c' => sub { print $_[0]->name() };
# don't provide a peep optimizer, rather get a callback
# after we are finished with every code block
use optimizer 'sub-detect' => sub { print $_[0]->name() };
no optimizer; # Use the simplest working optimizer
DESCRIPTION
This module allows you to replace the default Perl optree optimizer,
"peep", with a Perl function of your own devising.
It requires a Perl patched with the patch supplied with the module
distribution; this patch allows the optimizer to be pluggable and
replaceable with a C function pointer. This module provides the glue
between the C function and a Perl subroutine. It is hoped that the patch
will be integrated into the Perl core at some point soon. This patch is
integrated as of perl 5.8.
Your optimizer subroutine will be handed a "B::OP"-derived object
representing the first (NOT the root) op in the program. You are
expected to be fluent with the "B" module to know what to do with this.
You can use "B::Generate" to fiddle around with the optree you are
given, while traversing it in execution order.
If you choose complete control over your optimizer, you must assign
sequence numbers to operations. This can be done via the
"optimizer::op_seqmax_inc" function, which supplies a new incremented
sequence number. Do something like this:
while ($$op) {
$op->seq(optimizer::op_seqmax_inc);
... more optimizations ...
$op = $op->next;
last unless $op->can("next"); # Shouldn't get here
}
The "callback" option to this module will essentially do the above,
calling your given subroutine with each op.
If you just want to use this function to get a callback after every code
block is compiled so you can do any arbitrary work on it use the
"sub-detect" option, you will be passed LEAVE* ops after the standard
peep optimizer has been run, this minimises the risk for bugs as we use
the standard one. The op tree you are handed is also stable so you are
free to work on it. This is usefull if you are limited by "CHECK" and
"INIT" blocks as this works with string eval and "require" aswell. Only
one callback per package is allowed.
STATUS
relocatetopad() fails with threaded perls.
5.10 Changes
Since Perl 5.10 there are no op_seqmax and op_seq numbers in CORE
anymore, so we add a package global op_seqmax for the op-tree numbering,
for $B::OP::seq also. This is not thread-safe.
AUTHOR
Simon Cozens, C<[email protected]>
Extended functionality and current maintainer:
Arthur Bergman, C<[email protected]>
5.10 support by Reini Urban:
Reini Urban, C<[email protected]>
SEE ALSO
B::Generate, optimize