void equalizeTypes(Value* &Op1, Value* &Op2, bool isSigned, IRBuilder<> Builder){ if (Op1->getType() != Op2->getType()) { if (Op1->getType()->getIntegerBitWidth() > Op2->getType()->getIntegerBitWidth() ) { //expand op2 if (isSigned) Op2 = Builder.CreateSExt(Op2, Op1->getType(), ""); else Op2 = Builder.CreateZExt(Op2, Op1->getType(), ""); } else { //expand op1 if (isSigned) Op1 = Builder.CreateSExt(Op1, Op2->getType(), ""); else Op1 = Builder.CreateZExt(Op1, Op2->getType(), ""); } } }
static std::pair<Value*, Value*> getMul64(IRBuilder<> &Builder, Value *LHS, Value *RHS) { Type *I32Ty = Builder.getInt32Ty(); Type *I64Ty = Builder.getInt64Ty(); Value *LHS_EXT64 = Builder.CreateZExt(LHS, I64Ty); Value *RHS_EXT64 = Builder.CreateZExt(RHS, I64Ty); Value *MUL64 = Builder.CreateMul(LHS_EXT64, RHS_EXT64); Value *Lo = Builder.CreateTrunc(MUL64, I32Ty); Value *Hi = Builder.CreateLShr(MUL64, Builder.getInt64(32)); Hi = Builder.CreateTrunc(Hi, I32Ty); return std::make_pair(Lo, Hi); }