/** * Check if it is an exit operation. If it is, return true. <br> * For conditional exits, checks if the inputs are literals. If yes, tries to resolve the exit. If * exit can be resolved and is an exit, returns true. Otherwise, returns false and operation is * ignored. <br> * For conditional exits which cannot be resolved, false is returned and the conditional exit * table is updated with the input data (check if from live-in or fu coordinate) and the address. * <br> * For all other operations, returns false. * * @param operation * @return */ private boolean processExitOperation(Operation operation) { OperationName opName = operation.getOperation(); // Check if exit if (opName == OperationName.exit) { // System.out.println("exit:"+operation); return true; } // Check if NOT conditional exit if (!IfmUtils.isConditionalExit(opName)) { // System.out.println("Not conditional:"+operation); return false; } // Is conditional exit // System.out.println("conditional:"+operation); // Check if first input is literal Operand firstOperand = operation.getInput(InputIndex.firstOperand); boolean isLiteral = firstOperand.getOpType() == Operand.OpType.literal; if (isLiteral) { int result = Optimizations.computeLiteral(opName, firstOperand.getValueAsIntegerLiteral(), 0); // If 1, exit if (result == 1) { return true; } else { return false; } } // Is not literal // Check current producers table to check if we can find the register Operand operand = currentProducers.get(firstOperand.getValue()); Operand jumpAddress = operation.getInput(InputIndex.secondOperand); // Update table if (operand != null) { conditionalExit.put(operand, jumpAddress); } else { conditionalExit.put(firstOperand, jumpAddress); } // The register was read. Some processing here? // TODO return false; }
/** * @param operation * @return true if it is a move operation. False otherwise. */ public boolean processMoveOperation(Operation operation) { // Check if it is a move operation boolean isMove = operation.getOperation() == OperationName.move; if (!isMove) { return false; } // Update literals table String registerName = operation.getOutput(OutputIndex.firstResult).getValue(); Operand literal = operation.getInput(InputIndex.firstOperand); literalsTable.put(registerName, literal); // Remove register from current producers, if it is there currentProducers.remove(registerName); return true; }