Logo Search packages:      
Sourcecode: ktechlab version File versions  Download package

bool Optimizer::canRemove ( Instruction ins,
const Register reg,
uchar  bitMask = 0xff 
) [protected]

We often need to know whether removing an instruction will affect the future processor state. This function looks are all possible future dependencies of the given register, and returns true if the removal of the instruction will have no critical effect.

Parameters:
bitMask only look at the given bits of the register

Definition at line 477 of file optimizer.cpp.

References generateRegisterDepends(), Instruction::inputState(), Instruction::outputState(), ProcessorState::reg(), RegisterState::unknown(), and RegisterState::value.

Referenced by optimizeInstructions().

{
      // The bits that are depended upon in the future for this register
      uchar depends = generateRegisterDepends( ins, reg );
      
      // Only interested in those bits allowed by the bit mask
      depends &= bitMask;
      
      RegisterState inputState = ins->inputState().reg( reg );
      RegisterState outputState = ins->outputState().reg( reg );
      
      if ( inputState.unknown() & depends )
      {
            // There's at least one bit whose value is depended on, but is not known before this
            // instruction is executed. Therefore, it is not safe to remove this instruction.
            return false;
      }
      
      if ( outputState.unknown() & depends )
      {
            // There's at least one bit whose value is depended on, but is not known after this
            // instruction is executed. Therefore, it is not safe to remove this instruction.
            return false;
      }
                  
      uchar dependsInput = inputState.value & depends;
      uchar dependsOutput = outputState.value & depends;
      if ( dependsInput != dependsOutput )
      {
            // At least one bit whose value is depended upon was changed.
            return false;
      }
      
      return true;
}


Generated by  Doxygen 1.6.0   Back to index