Exemplo n.º 1
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Operand* Peephole::Simplify(Instruction* instr) {
	// Set the insertion point for new instructions; all new instructions
	// after the current one, in the order they are created.
	irGen_.SetInsertionPoint(instr);

    switch(instr->GetOpcode()) {
        case Instr_Add: {
            return PreserveUSO(instr, HandleAdd(instr->GetSourceOp(0), 
                                                instr->GetSourceOp(1),
                                                instr->ParentBlock()));
        }
        case Instr_Sub: {
            return PreserveUSO(instr, HandleSub(instr->GetSourceOp(0),
                                                instr->GetSourceOp(1),
                                                instr->ParentBlock()));
        }
        case Instr_Mul: {
            return PreserveUSO(instr, HandleMul(instr->GetSourceOp(0), 
                               instr->GetSourceOp(1), instr->ParentBlock()));
        }
        case Instr_Div: {
            auto arithInstr = instr->As<ArithmeticInstr>();
            return PreserveUSO(instr, HandleDiv(arithInstr->LeftOp(),
                                                arithInstr->RightOp(),
                                                instr->ParentBlock(),
                                                arithInstr->HasNoRemainder()));
        }
        case Instr_Udiv: {
            return PreserveUSO(instr, HandleUdiv(instr->GetSourceOp(0),
                                                 instr->GetSourceOp(1),
                                                 instr->ParentBlock()));
        }
        case Instr_Mod:  {
            return PreserveUSO(instr, HandleMod(instr->GetSourceOp(0),
                                                instr->GetSourceOp(1),
                                                instr->ParentBlock()));
        }
        case Instr_Umod: {
            return PreserveUSO(instr, HandleUmod(instr->GetSourceOp(0),
                                                 instr->GetSourceOp(1),
                                                 instr->ParentBlock()));
        }
        case Instr_Fadd: {
            auto arithInstr = instr->As<ArithmeticInstr>();
            return HandleFadd(arithInstr->LeftOp(), 
                              arithInstr->RightOp(),
                              arithInstr->GetFPMode());
        }
        case Instr_Fsub: {
            auto arithInstr = instr->As<ArithmeticInstr>();
            return HandleFsub(arithInstr->LeftOp(), 
                              arithInstr->RightOp(),
                              arithInstr->GetFPMode());
        }
        case Instr_Fmul: {
            auto arithInstr = instr->As<ArithmeticInstr>();
            return HandleFmul(arithInstr->LeftOp(), 
                              arithInstr->RightOp(),
                              arithInstr->GetFPMode());
        }
        case Instr_Fdiv: {
            auto arithInstr = instr->As<ArithmeticInstr>();
            return HandleFdiv(arithInstr->LeftOp(), 
                              arithInstr->RightOp(),
                              arithInstr->GetFPMode());
        }

        case Instr_And:  return HandleAnd(instr->GetSourceOp(0), 
                                          instr->GetSourceOp(1),
                                          instr->ParentBlock());
        case Instr_Or:   return HandleOr(instr->GetSourceOp(0), 
                                         instr->GetSourceOp(1),
                                         instr->ParentBlock());
        case Instr_Xor:  return HandleXor(instr->GetSourceOp(0), 
                                          instr->GetSourceOp(1),
                                          instr->ParentBlock());
        case Instr_Shl:  return HandleShl(instr->As<ShlInstr>());
        case Instr_Shr:  return HandleShr(instr->As<ShrInstr>());
        case Instr_Ushr: return HandleUshr(instr->As<UshrInstr>());

        case Instr_Cmp:  return HandleCmp(instr->As<CmpInstr>());
        case Instr_Ucmp: return HandleUcmp(instr->As<UcmpInstr>());
        case Instr_Fcmp: return HandleFcmp(instr->As<FcmpInstr>());

        case Instr_Trunc:  return HandleTrunc(instr->As<TruncInstr>());
        case Instr_Sext:   return HandleSext(instr->As<SextInstr>());
        case Instr_Zext:   return HandleZext(instr->As<ZextInstr>());
        case Instr_Ftrunc: return HandleFtrunc(instr->As<FtruncInstr>());
        case Instr_Fext:   return HandleFext(instr->As<FextInstr>());
        case Instr_Ftoi:   return HandleFtoi(instr->As<FtoiInstr>());
        case Instr_Ftoui:  return HandleFtoui(instr->As<FtouiInstr>());
        case Instr_Itof:   return HandleItof(instr->As<ItofInstr>());
        case Instr_Itop:   return HandleItop(instr->As<ItopInstr>());
        case Instr_Ptoi:   return HandlePtoi(instr->As<PtoiInstr>());
        case Instr_Ptop:   return HandlePtop(instr->As<PtopInstr>());
        case Instr_Uitof:  return HandleUitof(instr->As<UitofInstr>());

        case Instr_Call:     return HandleCall(instr->As<CallInstr>());
        case Instr_Address:  return HandleAddress(instr->As<AddressInstr>());
        case Instr_Index:    return HandleIndex(instr->As<IndexInstr>());
        case Instr_Element:  return HandleElement(instr->As<ElementInstr>());
		case Instr_Load:     return HandleLoad(instr->As<LoadInstr>());
		case Instr_Store:    return HandleStore(instr->As<StoreInstr>());
        case Instr_Question: return HandleQuestion(instr->As<QuestionInstr>());
        case Instr_Phi:      return HandlePhi(instr->As<PhiInstr>());
    }

    // This is an instruction that is not supported.
    return nullptr;
}
Exemplo n.º 2
0
bool HandleBag::isValid(HandleType handle) const
{
    auto idx = HandleIndex(handle);
    auto generation = HandleGeneration(handle);
    return (idx < m_generations.size()) && (m_generations[idx] == generation);
}