1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-20 02:32:36 +00:00

Fixed multiply to shift. 260/351.

This commit is contained in:
Jesper Gravgaard 2019-05-11 20:14:14 +02:00
parent 3c8845d6a6
commit bd6ece561b

View File

@ -6,14 +6,7 @@ import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.operators.Operators; import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementAssignment; import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.statements.StatementCall;
import dk.camelot64.kickc.model.statements.StatementCallPointer;
import dk.camelot64.kickc.model.symbols.ConstantVar;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypePointer;
import dk.camelot64.kickc.model.types.SymbolTypeProcedure;
import dk.camelot64.kickc.model.values.*; import dk.camelot64.kickc.model.values.*;
import kickass.pass.expressions.expr.Constant;
import java.util.ListIterator; import java.util.ListIterator;
@ -34,7 +27,8 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization {
if(statement instanceof StatementAssignment) { if(statement instanceof StatementAssignment) {
StatementAssignment assignment = (StatementAssignment) statement; StatementAssignment assignment = (StatementAssignment) statement;
if(Operators.MULTIPLY.equals(assignment.getOperator()) || Operators.DIVIDE.equals(assignment.getOperator())) { if(Operators.MULTIPLY.equals(assignment.getOperator()) || Operators.DIVIDE.equals(assignment.getOperator())) {
ConstantLiteral constantLiteral = getConstantLiteral(assignment); if(assignment.getrValue1() instanceof ConstantValue) continue;
ConstantLiteral constantLiteral = getConstantLiteral2(assignment);
if(constantLiteral instanceof ConstantInteger) { if(constantLiteral instanceof ConstantInteger) {
Long constantInt = ((ConstantInteger)constantLiteral).getInteger(); Long constantInt = ((ConstantInteger)constantLiteral).getInteger();
double power2 = Math.log(constantInt) / Math.log(2); double power2 = Math.log(constantInt) / Math.log(2);
@ -72,7 +66,7 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization {
* @param assignment The Assignment * @param assignment The Assignment
* @return The constant literal value for RValue2 (or null) * @return The constant literal value for RValue2 (or null)
*/ */
private ConstantLiteral getConstantLiteral(StatementAssignment assignment) { private ConstantLiteral getConstantLiteral2(StatementAssignment assignment) {
if(assignment.getrValue2() instanceof ConstantValue) { if(assignment.getrValue2() instanceof ConstantValue) {
ConstantValue constantValue = (ConstantValue) assignment.getrValue2(); ConstantValue constantValue = (ConstantValue) assignment.getrValue2();
try { try {