/** * @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; }
/** * 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; }
/** * Accepts operation to map on the matrix * * @param operation * @return */ private void mapOperation(Operation operation) { Operand[] opInputs = operation.getInputs(); Operand[] opOutputs = operation.getOutputs(); // Fu data Operand[] fuInputs = new Operand[opInputs.length]; // Operand[] fuOutputs = new Operand[opOutputs.length]; // Check inputs for (int i = 0; i < opInputs.length; i++) { if (opInputs[i] == null) { continue; } if (opInputs[i].getOpType() == Operand.OpType.literal) { fuInputs[i] = opInputs[i]; continue; } if (opInputs[i].getOpType() == Operand.OpType.register) { // This can be combine in one class String register = opInputs[i].getValue(); Operand op = null; // Check if literals table has this register op = literalsTable.get(register); // Check if current producers have this register if (op == null) { op = currentProducers.get(register); } if (op == null) { liveIns.add(register); } else { fuInputs[i] = op; } continue; } System.out.println("mapOperation Error: shouldn't be here"); } boolean isMemoryOperation = Memory.isMemoryOperation.contains(operation.getOperation()); int fromLine = 0; // 1 Memory operation per line if (isMemoryOperation) { // Check last line used by memory operation fromLine = lastLineUseByMemoryOperation + 1; } int destinationLine = calculateDestinationLine(fuInputs, fromLine); int destinationCol = matrix.getFirstAvaliableColumn(destinationLine); Fu mappedOp = matrix.mapNewOperation(destinationLine, destinationCol, operation, fuInputs); processOutput(opOutputs, mappedOp.getOutput()); // Add, in the end if (feedDistance > 0) { for (int i = 0; i < fuInputs.length; i++) { Fu newMove = addMoveOperations(destinationLine, fuInputs[i]); if (mappingFailed) { return; } } } // Update memory line /* if(isMemoryOperation) { // Check last line used by memory operation lastLineUseByMemoryOperation = destinationLine; } */ // Scenario 2: parallel loads, serial stores if (Memory.isStore.contains(operation.getOperation())) { lastLineUseByMemoryOperation = destinationLine; } }