Пример #1
0
  private void deallocateNonLiveVars(Line line, RegAllocContext context, int nMaxRegisters) {
    // De-allocate non-live variables
    for (int i = 0; i < nMaxRegisters - 1; i++) {
      String strReg = "$t" + i;

      // See if it is live in the next instruction.

      // Get the variable the register is mapped to
      String strVar = context.regMap.get(strReg);

      // If it is not live...
      if (null != strVar && !line.getLiveSet().contains(strVar)) {
        // Remove mapping from old variable to register
        context.regMap.put(strReg, "");
        context.variableLocs.put(strVar, "m");
      }
    }
  }
Пример #2
0
  public boolean calculateLiveIN() {
    boolean bChanges = false;

    mapRegistersToVariables();

    // The last lastLive set is a copy of liveOUT
    LiveSet lastLive = new LiveSet(getLiveOut());

    for (int i = getLines().getNumItems() - 1; i >= 0; i--) {
      Line line = getLines().getItemAtIndex(i);

      // Copy the last live set
      line.getLiveSet().copy(lastLive);

      if (Line.Type.INSTRUCTION == line.getType()) {
        Instruction instr = (Instruction) line;

        Argument arg2 = instr.getArgument2();

        // If this is a SW instruction, then remove the
        // target variable from the live set
        if (0 == instr.getInstruction().compareTo("sw")) {
          // Remove the mapping to the variable
          line.getLiveSet().remove(arg2.getName());

          // See if Argument1 is mapped to a variable
          if (instr.getMapRegToValue().containsKey(instr.getArgument1().getName())) {
            String strVal = instr.getMapRegToValue().get(instr.getArgument1().getName());

            // Mark the variable as live
            line.getLiveSet().add(strVal);
          }
        }
        // If this is a LW instruction, then add the loaded
        // variable to the live set
        else if (0 == instr.getInstruction().compareTo("lw")
            || 0 == instr.getInstruction().compareTo("li")) {
          line.getLiveSet().add(arg2.getName());
        } else if (!instr.getIsJump()
            && 0 != instr.getInstruction().compareTo("syscall")
            && 0 != instr.getInstruction().compareTo("move")
            && 0 != instr.getInstruction().compareTo("li")) {
          // See if Argument2 is mapped to a variable
          if (instr.getMapRegToValue().containsKey(instr.getArgument2().getName())) {
            String strVal = instr.getMapRegToValue().get(instr.getArgument2().getName());

            // Mark the variable as live
            line.getLiveSet().add(strVal);
          }

          // See if Argument3 is mapped to a variable
          if (instr.getMapRegToValue().containsKey(instr.getArgument3().getName())) {
            String strVal = instr.getMapRegToValue().get(instr.getArgument3().getName());

            // Mark the variable as live
            line.getLiveSet().add(strVal);
          }
        } else if (0 == instr.getInstruction().compareTo("move")) {
          // See if Argument2 is mapped to a variable
          if (instr.getMapRegToValue().containsKey(instr.getArgument2().getName())) {
            String strVal = instr.getMapRegToValue().get(instr.getArgument2().getName());

            // Mark the variable as live
            line.getLiveSet().add(strVal);
          }
        }
      }

      lastLive = line.getLiveSet();
    }

    getLiveIn().copy(lastLive);

    return bChanges;
  }