[B-brains] tying optimizations to methods
Hesam Samimi
hesam at cs.ucla.edu
Thu Feb 26 18:08:23 PST 2009
I've been experimenting with defining optimizations for goal methods
and action methods.
For goal methods, we would like optimizations to dynamically tell us
which actions to explore.
For action methods, we would like optimizations to dynamically tell
us which method arguments to explore.
I've done an implementation that seems to be a nice way to do this,
without requiring you to modify your action and goal methods.
This is simply attaching methods to the original method via prenamed
arguments:
#actionName_argTypes
#actionName_optimizations
#goalName_optimizations
The solver object knows about these keywords, and applies the
optimization for the method if the object under study understands
the messages above. All objects can return false on messages not
understood, so if solver gets a false from messages above, it
knows the method has not defined optimizations.
E.g.
" original action method "
Allocator assign: reg var: var [ ... ]
" returns arg types of method above
Allocator assign: a var: b _argTypes: c [ ^Array with: Register
with: Variable ]
" returns optimizations for method above: returns a constraint
on arguments
Allocator assign: a var: b _optimization: c [ ^reg = R1 or:
[ reg = R2] ]
" original goal method "
Allocator allocationDone [ ^unallocatedVars size = 0 ]
" optimization for goal above "
Allocator allocation_optimizations
[
" if pred true, explore #assign:var: method, if not explore
#split:to: method..."
^( Array with: ( ( self canAllocate: (unallocatedVars first) )
ifTrue: [ #assign:var: ] ifFalse:
[ #split:to: ] ) )
]
I'm using this scheme to handle optimizations in the register
allocation by puzzle solving program:
http://www.cs.ucla.edu/~hesam/idst/object/examples/john/allocator.st
Regards,
Hesam
More information about the B-brains
mailing list