void XlateTableRec::EquateData(){ for (int lt = 1; lt <= 255; lt++) if (dat[lt] != 0) HandleSub(dat[lt]->n); for (lt = 0; lt < HighLowSize; lt++){ UNCH llt = LowerCharList[lt]; UNCH ult = UpperCharList[lt]; if ((dat[llt] != 0) && (dat[ult] == 0)) dat[ult] = new XlateEntryData(ult,dat[llt]); else if ((dat[ult] != 0) && (dat[llt] == 0)) dat[llt] = new XlateEntryData(llt,dat[ult]); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Operand* Peephole::SimplifyBinary(Opcode opcode, Operand* opA, Operand* opB, Block* block, FloatMode mode, bool constMoveAllowed) { // This is used by code that does expression reassociation. switch(opcode) { case Instr_Add: return HandleAdd(opA, opB, block, constMoveAllowed); case Instr_Sub: return HandleSub(opA, opB, block); case Instr_Mul: return HandleMul(opA, opB, block, constMoveAllowed); case Instr_Div: return HandleDiv(opA, opB, block, false); case Instr_Udiv: return HandleUdiv(opA, opB, block); case Instr_Fadd: return HandleFadd(opA, opB, mode); case Instr_Fsub: return HandleFsub(opA, opB, mode); case Instr_Fmul: return HandleFmul(opA, opB, mode); case Instr_Fdiv: return HandleFdiv(opA, opB, mode); case Instr_And: return HandleAnd(opA, opB, block, constMoveAllowed); case Instr_Or: return HandleOr(opA, opB, block, constMoveAllowed); case Instr_Xor: return HandleXor(opA, opB, block, constMoveAllowed); } return nullptr; }
void HandleSub(XlateEntryData * xp){ XlateEntryData* p = xp; UNCH /* boolean */ ccol[256]; memset(ccol, FALSE, 256); // for (int oc = 0; oc <= 255; oc++) ccol[oc] = FALSE; while (p != 0){ccol[p->c] = TRUE; p = p->f;} p = xp; while (p != 0) { UNCH * upos = ustrchr(UpperCharList, p->c), * lpos = ustrchr(LowerCharList, p->c), ox; if ((upos != 0) || (lpos != 0)) { if (upos != 0) ox = *upos; else ox = *lpos; } if (!ccol[ox]){ XlateEntryData* np = new XlateEntryData(ox, p); p->f = np; p = np; if (p->n != 0) HandleSub(p->n); } p = p->f; } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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; }