Home | History | Annotate | Download | only in Utils

Lines Matching refs:Builder

29 /// remainder, which will have the sign of the dividend. Builder's insert point
31 /// instruction. This will generate a urem in the process, and Builder's insert
35 IRBuilder<> &Builder) {
40 Shift = Builder.getInt64(63);
43 Shift = Builder.getInt32(31);
58 Value *DividendSign = Builder.CreateAShr(Dividend, Shift);
59 Value *DivisorSign = Builder.CreateAShr(Divisor, Shift);
60 Value *DvdXor = Builder.CreateXor(Dividend, DividendSign);
61 Value *DvsXor = Builder.CreateXor(Divisor, DivisorSign);
62 Value *UDividend = Builder.CreateSub(DvdXor, DividendSign);
63 Value *UDivisor = Builder.CreateSub(DvsXor, DivisorSign);
64 Value *URem = Builder.CreateURem(UDividend, UDivisor);
65 Value *Xored = Builder.CreateXor(URem, DividendSign);
66 Value *SRem = Builder.CreateSub(Xored, DividendSign);
69 Builder.SetInsertPoint(URemInst);
76 /// remainder. Builder's insert point should be pointing where the caller wants
78 /// the process, and Builder's insert point will be pointing at the udiv (if
81 IRBuilder<> &Builder) {
89 Value *Quotient = Builder.CreateUDiv(Dividend, Divisor);
90 Value *Product = Builder.CreateMul(Divisor, Quotient);
91 Value *Remainder = Builder.CreateSub(Dividend, Product);
94 Builder.SetInsertPoint(UDiv);
100 /// towards 0. Builder's insert point should be pointing where the caller wants
102 /// the process, and Builder's insert point will be pointing at the udiv (if
105 IRBuilder<> &Builder) {
112 Shift = Builder.getInt64(63);
115 Shift = Builder.getInt32(31);
131 Value *Tmp = Builder.CreateAShr(Dividend, Shift);
132 Value *Tmp1 = Builder.CreateAShr(Divisor, Shift);
133 Value *Tmp2 = Builder.CreateXor(Tmp, Dividend);
134 Value *U_Dvnd = Builder.CreateSub(Tmp2, Tmp);
135 Value *Tmp3 = Builder.CreateXor(Tmp1, Divisor);
136 Value *U_Dvsr = Builder.CreateSub(Tmp3, Tmp1);
137 Value *Q_Sgn = Builder.CreateXor(Tmp1, Tmp);
138 Value *Q_Mag = Builder.CreateUDiv(U_Dvnd, U_Dvsr);
139 Value *Tmp4 = Builder.CreateXor(Q_Mag, Q_Sgn);
140 Value *Q = Builder.CreateSub(Tmp4, Q_Sgn);
143 Builder.SetInsertPoint(UDiv);
149 /// Returns the quotient, rounded towards 0. Builder's insert point should
152 IRBuilder<> &Builder) {
167 Zero = Builder.getInt64(0);
168 One = Builder.getInt64(1);
170 MSB = Builder.getInt64(63);
173 Zero = Builder.getInt32(0);
174 One = Builder.getInt32(1);
176 MSB = Builder.getInt32(31);
179 ConstantInt *True = Builder.getTrue();
181 BasicBlock *IBB = Builder.GetInsertBlock();
218 BasicBlock *SpecialCases = Builder.GetInsertBlock();
220 BasicBlock *End = SpecialCases->splitBasicBlock(Builder.GetInsertPoint(),
222 BasicBlock *LoopExit = BasicBlock::Create(Builder.getContext(),
224 BasicBlock *DoWhile = BasicBlock::Create(Builder.getContext(),
226 BasicBlock *Preheader = BasicBlock::Create(Builder.getContext(),
228 BasicBlock *BB1 = BasicBlock::Create(Builder.getContext(),
251 Builder.SetInsertPoint(SpecialCases);
252 Value *Ret0_1 = Builder.CreateICmpEQ(Divisor, Zero);
253 Value *Ret0_2 = Builder.CreateICmpEQ(Dividend, Zero);
254 Value *Ret0_3 = Builder.CreateOr(Ret0_1, Ret0_2);
255 Value *Tmp0 = Builder.CreateCall(CTLZ, {Divisor, True});
256 Value *Tmp1 = Builder.CreateCall(CTLZ, {Dividend, True});
257 Value *SR = Builder.CreateSub(Tmp0, Tmp1);
258 Value *Ret0_4 = Builder.CreateICmpUGT(SR, MSB);
259 Value *Ret0 = Builder.CreateOr(Ret0_3, Ret0_4);
260 Value *RetDividend = Builder.CreateICmpEQ(SR, MSB);
261 Value *RetVal = Builder.CreateSelect(Ret0, Zero, Dividend);
262 Value *EarlyRet = Builder.CreateOr(Ret0, RetDividend);
263 Builder.CreateCondBr(EarlyRet, End, BB1);
271 Builder.SetInsertPoint(BB1);
272 Value *SR_1 = Builder.CreateAdd(SR, One);
273 Value *Tmp2 = Builder.CreateSub(MSB, SR);
274 Value *Q = Builder.CreateShl(Dividend, Tmp2);
275 Value *SkipLoop = Builder.CreateICmpEQ(SR_1, Zero);
276 Builder.CreateCondBr(SkipLoop, LoopExit, Preheader);
282 Builder.SetInsertPoint(Preheader);
283 Value *Tmp3 = Builder.CreateLShr(Dividend, SR_1);
284 Value *Tmp4 = Builder.CreateAdd(Divisor, NegOne);
285 Builder.CreateBr(DoWhile);
305 Builder.SetInsertPoint(DoWhile);
306 PHINode *Carry_1 = Builder.CreatePHI(DivTy, 2);
307 PHINode *SR_3 = Builder.CreatePHI(DivTy, 2);
308 PHINode *R_1 = Builder.CreatePHI(DivTy, 2);
309 PHINode *Q_2 = Builder.CreatePHI(DivTy, 2);
310 Value *Tmp5 = Builder.CreateShl(R_1, One);
311 Value *Tmp6 = Builder.CreateLShr(Q_2, MSB);
312 Value *Tmp7 = Builder.CreateOr(Tmp5, Tmp6);
313 Value *Tmp8 = Builder.CreateShl(Q_2, One);
314 Value *Q_1 = Builder.CreateOr(Carry_1, Tmp8);
315 Value *Tmp9 = Builder.CreateSub(Tmp4, Tmp7);
316 Value *Tmp10 = Builder.CreateAShr(Tmp9, MSB);
317 Value *Carry = Builder.CreateAnd(Tmp10, One);
318 Value *Tmp11 = Builder.CreateAnd(Tmp10, Divisor);
319 Value *R = Builder.CreateSub(Tmp7, Tmp11);
320 Value *SR_2 = Builder.CreateAdd(SR_3, NegOne);
321 Value *Tmp12 = Builder.CreateICmpEQ(SR_2, Zero);
322 Builder.CreateCondBr(Tmp12, LoopExit, DoWhile);
330 Builder.SetInsertPoint(LoopExit);
331 PHINode *Carry_2 = Builder.CreatePHI(DivTy, 2);
332 PHINode *Q_3 = Builder.CreatePHI(DivTy, 2);
333 Value *Tmp13 = Builder.CreateShl(Q_3, One);
334 Value *Q_4 = Builder.CreateOr(Carry_2, Tmp13);
335 Builder.CreateBr(End);
340 Builder.SetInsertPoint(End, End->begin());
341 PHINode *Q_5 = Builder.CreatePHI(DivTy, 2);
381 IRBuilder<> Builder(Rem);
391 Rem->getOperand(1), Builder);
394 bool IsInsertPoint = Rem->getIterator() == Builder.GetInsertPoint();
401 // Builder insertion point was unchanged
405 BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
411 Builder);
418 if (BinaryOperator *UDiv = dyn_cast<BinaryOperator>(Builder.GetInsertPoint())) {
439 IRBuilder<> Builder(Div);
450 Div->getOperand(1), Builder);
453 bool IsInsertPoint = Div->getIterator() == Builder.GetInsertPoint();
460 // Builder insertion point was unchanged
464 BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
471 Builder);
504 IRBuilder<> Builder(Rem);
510 Type *Int32Ty = Builder.getInt32Ty();
513 ExtDividend = Builder.CreateSExt(Rem->getOperand(0), Int32Ty);
514 ExtDivisor = Builder.CreateSExt(Rem->getOperand(1), Int32Ty);
515 ExtRem = Builder.CreateSRem(ExtDividend, ExtDivisor);
517 ExtDividend = Builder.CreateZExt(Rem->getOperand(0), Int32Ty);
518 ExtDivisor = Builder.CreateZExt(Rem->getOperand(1), Int32Ty);
519 ExtRem = Builder.CreateURem(ExtDividend, ExtDivisor);
521 Trunc = Builder.CreateTrunc(ExtRem, RemTy);
552 IRBuilder<> Builder(Rem);
558 Type *Int64Ty = Builder.getInt64Ty();
561 ExtDividend = Builder.CreateSExt(Rem->getOperand(0), Int64Ty);
562 ExtDivisor = Builder.CreateSExt(Rem->getOperand(1), Int64Ty);
563 ExtRem = Builder.CreateSRem(ExtDividend, ExtDivisor);
565 ExtDividend = Builder.CreateZExt(Rem->getOperand(0), Int64Ty);
566 ExtDivisor = Builder.CreateZExt(Rem->getOperand(1), Int64Ty);
567 ExtRem = Builder.CreateURem(ExtDividend, ExtDivisor);
569 Trunc = Builder.CreateTrunc(ExtRem, RemTy);
601 IRBuilder<> Builder(Div);
607 Type *Int32Ty = Builder.getInt32Ty();
610 ExtDividend = Builder.CreateSExt(Div->getOperand(0), Int32Ty);
611 ExtDivisor = Builder.CreateSExt(Div->getOperand(1), Int32Ty);
612 ExtDiv = Builder.CreateSDiv(ExtDividend, ExtDivisor);
614 ExtDividend = Builder.CreateZExt(Div->getOperand(0), Int32Ty);
615 ExtDivisor = Builder.CreateZExt(Div->getOperand(1), Int32Ty);
616 ExtDiv = Builder.CreateUDiv(ExtDividend, ExtDivisor);
618 Trunc = Builder.CreateTrunc(ExtDiv, DivTy);
650 IRBuilder<> Builder(Div);
656 Type *Int64Ty = Builder.getInt64Ty();
659 ExtDividend = Builder.CreateSExt(Div->getOperand(0), Int64Ty);
660 ExtDivisor = Builder.CreateSExt(Div->getOperand(1), Int64Ty);
661 ExtDiv = Builder.CreateSDiv(ExtDividend, ExtDivisor);
663 ExtDividend = Builder.CreateZExt(Div->getOperand(0), Int64Ty);
664 ExtDivisor = Builder.CreateZExt(Div->getOperand(1), Int64Ty);
665 ExtDiv = Builder.CreateUDiv(ExtDividend, ExtDivisor);
667 Trunc = Builder.CreateTrunc(ExtDiv, DivTy);