0x7CFE / llst

LLVM powered Little Smalltalk.
Other
93 stars 10 forks source link

Optimize binary operators #76

Open 0x7CFE opened 9 years ago

0x7CFE commented 9 years ago

Binary operators such as + or * may be endoded in two ways.

Consider the following method:

increment: arg
    ^arg + 1

One way is to encode it using standard message passing:

PushArgument 1
PustConstant 1
MarkArguments 2
SendMessage +
DoSpecial stackReturn

Other way is to use SendBinary opcode:

PushArgument 1
PustConstant 1
SendBinary +
DoSpecial stackReturn

In case of JIT VM second version will be much faster because we omit argument array creation and may perform addition using native instructions.

Even if method bytecodes contain the first version we still may perform an optimization because method graph is available during JIT compilation phase. All we need to do is to seek for SendMessage instructions that have matching selector literal and replace it with corresponding SendBinary. MarkArguments should be eliminated too.