Skip to content

Commit 1db690d

Browse files
committed
Put the * and & next to the variable, rather than the type.
llvm-svn: 164232
1 parent c4149a1 commit 1db690d

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

llvm/lib/Transforms/Utils/IntegerDivision.cpp

+73-73
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ using namespace llvm;
2828
// instruction. This will generate a udiv in the process, and Builder's insert
2929
// point will be pointing at the udiv (if present, i.e. not folded), ready to be
3030
// expanded if the user wishes.
31-
static Value* GenerateSignedDivisionCode(Value* Dividend, Value* Divisor,
32-
IRBuilder<>& Builder) {
31+
static Value *GenerateSignedDivisionCode(Value *Dividend, Value *Divisor,
32+
IRBuilder<> &Builder) {
3333
// Implementation taken from compiler-rt's __divsi3
3434

35-
ConstantInt* ThirtyOne = Builder.getInt32(31);
35+
ConstantInt *ThirtyOne = Builder.getInt32(31);
3636

3737
// ; %tmp = ashr i32 %dividend, 31
3838
// ; %tmp1 = ashr i32 %divisor, 31
@@ -44,18 +44,18 @@ static Value* GenerateSignedDivisionCode(Value* Dividend, Value* Divisor,
4444
// ; %q_mag = udiv i32 %u_dvnd, %u_dvsr
4545
// ; %tmp4 = xor i32 %q_mag, %q_sgn
4646
// ; %q = sub i32 %tmp4, %q_sgn
47-
Value* Tmp = Builder.CreateAShr(Dividend, ThirtyOne);
48-
Value* Tmp1 = Builder.CreateAShr(Divisor, ThirtyOne);
49-
Value* Tmp2 = Builder.CreateXor(Tmp, Dividend);
50-
Value* U_Dvnd = Builder.CreateSub(Tmp2, Tmp);
51-
Value* Tmp3 = Builder.CreateXor(Tmp1, Divisor);
52-
Value* U_Dvsr = Builder.CreateSub(Tmp3, Tmp1);
53-
Value* Q_Sgn = Builder.CreateXor(Tmp1, Tmp);
54-
Value* Q_Mag = Builder.CreateUDiv(U_Dvnd, U_Dvsr);
55-
Value* Tmp4 = Builder.CreateXor(Q_Mag, Q_Sgn);
56-
Value* Q = Builder.CreateSub(Tmp4, Q_Sgn);
47+
Value *Tmp = Builder.CreateAShr(Dividend, ThirtyOne);
48+
Value *Tmp1 = Builder.CreateAShr(Divisor, ThirtyOne);
49+
Value *Tmp2 = Builder.CreateXor(Tmp, Dividend);
50+
Value *U_Dvnd = Builder.CreateSub(Tmp2, Tmp);
51+
Value *Tmp3 = Builder.CreateXor(Tmp1, Divisor);
52+
Value *U_Dvsr = Builder.CreateSub(Tmp3, Tmp1);
53+
Value *Q_Sgn = Builder.CreateXor(Tmp1, Tmp);
54+
Value *Q_Mag = Builder.CreateUDiv(U_Dvnd, U_Dvsr);
55+
Value *Tmp4 = Builder.CreateXor(Q_Mag, Q_Sgn);
56+
Value *Q = Builder.CreateSub(Tmp4, Q_Sgn);
5757

58-
if (Instruction* UDiv = dyn_cast<Instruction>(Q_Mag))
58+
if (Instruction *UDiv = dyn_cast<Instruction>(Q_Mag))
5959
Builder.SetInsertPoint(UDiv);
6060

6161
return Q;
@@ -64,24 +64,24 @@ static Value* GenerateSignedDivisionCode(Value* Dividend, Value* Divisor,
6464
// Generates code to divide two unsigned scalar 32-bit integers. Returns the
6565
// quotient, rounded towards 0. Builder's insert point should be pointing at the
6666
// udiv instruction.
67-
static Value* GenerateUnsignedDivisionCode(Value* Dividend, Value* Divisor,
68-
IRBuilder<>& Builder) {
67+
static Value *GenerateUnsignedDivisionCode(Value *Dividend, Value *Divisor,
68+
IRBuilder<> &Builder) {
6969
// The basic algorithm can be found in the compiler-rt project's
7070
// implementation of __udivsi3.c. Here, we do a lower-level IR based approach
7171
// that's been hand-tuned to lessen the amount of control flow involved.
7272

7373
// Some helper values
74-
IntegerType* I32Ty = Builder.getInt32Ty();
74+
IntegerType *I32Ty = Builder.getInt32Ty();
7575

76-
ConstantInt* Zero = Builder.getInt32(0);
77-
ConstantInt* One = Builder.getInt32(1);
78-
ConstantInt* ThirtyOne = Builder.getInt32(31);
79-
ConstantInt* NegOne = ConstantInt::getSigned(I32Ty, -1);
80-
ConstantInt* True = Builder.getTrue();
76+
ConstantInt *Zero = Builder.getInt32(0);
77+
ConstantInt *One = Builder.getInt32(1);
78+
ConstantInt *ThirtyOne = Builder.getInt32(31);
79+
ConstantInt *NegOne = ConstantInt::getSigned(I32Ty, -1);
80+
ConstantInt *True = Builder.getTrue();
8181

82-
BasicBlock* IBB = Builder.GetInsertBlock();
83-
Function* F = IBB->getParent();
84-
Function* CTLZi32 = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz,
82+
BasicBlock *IBB = Builder.GetInsertBlock();
83+
Function *F = IBB->getParent();
84+
Function *CTLZi32 = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz,
8585
I32Ty);
8686

8787
// Our CFG is going to look like:
@@ -116,17 +116,17 @@ static Value* GenerateUnsignedDivisionCode(Value* Dividend, Value* Divisor,
116116
// | ... |
117117
// | end |
118118
// +-------+
119-
BasicBlock* SpecialCases = Builder.GetInsertBlock();
119+
BasicBlock *SpecialCases = Builder.GetInsertBlock();
120120
SpecialCases->setName(Twine(SpecialCases->getName(), "_udiv-special-cases"));
121-
BasicBlock* End = SpecialCases->splitBasicBlock(Builder.GetInsertPoint(),
121+
BasicBlock *End = SpecialCases->splitBasicBlock(Builder.GetInsertPoint(),
122122
"udiv-end");
123-
BasicBlock* LoopExit = BasicBlock::Create(Builder.getContext(),
123+
BasicBlock *LoopExit = BasicBlock::Create(Builder.getContext(),
124124
"udiv-loop-exit", F, End);
125-
BasicBlock* DoWhile = BasicBlock::Create(Builder.getContext(),
125+
BasicBlock *DoWhile = BasicBlock::Create(Builder.getContext(),
126126
"udiv-do-while", F, End);
127-
BasicBlock* Preheader = BasicBlock::Create(Builder.getContext(),
127+
BasicBlock *Preheader = BasicBlock::Create(Builder.getContext(),
128128
"udiv-preheader", F, End);
129-
BasicBlock* BB1 = BasicBlock::Create(Builder.getContext(),
129+
BasicBlock *BB1 = BasicBlock::Create(Builder.getContext(),
130130
"udiv-bb1", F, End);
131131

132132
// We'll be overwriting the terminator to insert our extra blocks
@@ -148,17 +148,17 @@ static Value* GenerateUnsignedDivisionCode(Value* Dividend, Value* Divisor,
148148
// ; %earlyRet = or i1 %ret0, %retDividend
149149
// ; br i1 %earlyRet, label %end, label %bb1
150150
Builder.SetInsertPoint(SpecialCases);
151-
Value* Ret0_1 = Builder.CreateICmpEQ(Divisor, Zero);
152-
Value* Ret0_2 = Builder.CreateICmpEQ(Dividend, Zero);
153-
Value* Ret0_3 = Builder.CreateOr(Ret0_1, Ret0_2);
154-
Value* Tmp0 = Builder.CreateCall2(CTLZi32, Divisor, True);
155-
Value* Tmp1 = Builder.CreateCall2(CTLZi32, Dividend, True);
156-
Value* SR = Builder.CreateSub(Tmp0, Tmp1);
157-
Value* Ret0_4 = Builder.CreateICmpUGT(SR, ThirtyOne);
158-
Value* Ret0 = Builder.CreateOr(Ret0_3, Ret0_4);
159-
Value* RetDividend = Builder.CreateICmpEQ(SR, ThirtyOne);
160-
Value* RetVal = Builder.CreateSelect(Ret0, Zero, Dividend);
161-
Value* EarlyRet = Builder.CreateOr(Ret0, RetDividend);
151+
Value *Ret0_1 = Builder.CreateICmpEQ(Divisor, Zero);
152+
Value *Ret0_2 = Builder.CreateICmpEQ(Dividend, Zero);
153+
Value *Ret0_3 = Builder.CreateOr(Ret0_1, Ret0_2);
154+
Value *Tmp0 = Builder.CreateCall2(CTLZi32, Divisor, True);
155+
Value *Tmp1 = Builder.CreateCall2(CTLZi32, Dividend, True);
156+
Value *SR = Builder.CreateSub(Tmp0, Tmp1);
157+
Value *Ret0_4 = Builder.CreateICmpUGT(SR, ThirtyOne);
158+
Value *Ret0 = Builder.CreateOr(Ret0_3, Ret0_4);
159+
Value *RetDividend = Builder.CreateICmpEQ(SR, ThirtyOne);
160+
Value *RetVal = Builder.CreateSelect(Ret0, Zero, Dividend);
161+
Value *EarlyRet = Builder.CreateOr(Ret0, RetDividend);
162162
Builder.CreateCondBr(EarlyRet, End, BB1);
163163

164164
// ; bb1: ; preds = %special-cases
@@ -168,19 +168,19 @@ static Value* GenerateUnsignedDivisionCode(Value* Dividend, Value* Divisor,
168168
// ; %skipLoop = icmp eq i32 %sr_1, 0
169169
// ; br i1 %skipLoop, label %loop-exit, label %preheader
170170
Builder.SetInsertPoint(BB1);
171-
Value* SR_1 = Builder.CreateAdd(SR, One);
172-
Value* Tmp2 = Builder.CreateSub(ThirtyOne, SR);
173-
Value* Q = Builder.CreateShl(Dividend, Tmp2);
174-
Value* SkipLoop = Builder.CreateICmpEQ(SR_1, Zero);
171+
Value *SR_1 = Builder.CreateAdd(SR, One);
172+
Value *Tmp2 = Builder.CreateSub(ThirtyOne, SR);
173+
Value *Q = Builder.CreateShl(Dividend, Tmp2);
174+
Value *SkipLoop = Builder.CreateICmpEQ(SR_1, Zero);
175175
Builder.CreateCondBr(SkipLoop, LoopExit, Preheader);
176176

177177
// ; preheader: ; preds = %bb1
178178
// ; %tmp3 = lshr i32 %dividend, %sr_1
179179
// ; %tmp4 = add i32 %divisor, -1
180180
// ; br label %do-while
181181
Builder.SetInsertPoint(Preheader);
182-
Value* Tmp3 = Builder.CreateLShr(Dividend, SR_1);
183-
Value* Tmp4 = Builder.CreateAdd(Divisor, NegOne);
182+
Value *Tmp3 = Builder.CreateLShr(Dividend, SR_1);
183+
Value *Tmp4 = Builder.CreateAdd(Divisor, NegOne);
184184
Builder.CreateBr(DoWhile);
185185

186186
// ; do-while: ; preds = %do-while, %preheader
@@ -202,22 +202,22 @@ static Value* GenerateUnsignedDivisionCode(Value* Dividend, Value* Divisor,
202202
// ; %tmp12 = icmp eq i32 %sr_2, 0
203203
// ; br i1 %tmp12, label %loop-exit, label %do-while
204204
Builder.SetInsertPoint(DoWhile);
205-
PHINode* Carry_1 = Builder.CreatePHI(I32Ty, 2);
206-
PHINode* SR_3 = Builder.CreatePHI(I32Ty, 2);
207-
PHINode* R_1 = Builder.CreatePHI(I32Ty, 2);
208-
PHINode* Q_2 = Builder.CreatePHI(I32Ty, 2);
209-
Value* Tmp5 = Builder.CreateShl(R_1, One);
210-
Value* Tmp6 = Builder.CreateLShr(Q_2, ThirtyOne);
211-
Value* Tmp7 = Builder.CreateOr(Tmp5, Tmp6);
212-
Value* Tmp8 = Builder.CreateShl(Q_2, One);
213-
Value* Q_1 = Builder.CreateOr(Carry_1, Tmp8);
214-
Value* Tmp9 = Builder.CreateSub(Tmp4, Tmp7);
215-
Value* Tmp10 = Builder.CreateAShr(Tmp9, 31);
216-
Value* Carry = Builder.CreateAnd(Tmp10, One);
217-
Value* Tmp11 = Builder.CreateAnd(Tmp10, Divisor);
218-
Value* R = Builder.CreateSub(Tmp7, Tmp11);
219-
Value* SR_2 = Builder.CreateAdd(SR_3, NegOne);
220-
Value* Tmp12 = Builder.CreateICmpEQ(SR_2, Zero);
205+
PHINode *Carry_1 = Builder.CreatePHI(I32Ty, 2);
206+
PHINode *SR_3 = Builder.CreatePHI(I32Ty, 2);
207+
PHINode *R_1 = Builder.CreatePHI(I32Ty, 2);
208+
PHINode *Q_2 = Builder.CreatePHI(I32Ty, 2);
209+
Value *Tmp5 = Builder.CreateShl(R_1, One);
210+
Value *Tmp6 = Builder.CreateLShr(Q_2, ThirtyOne);
211+
Value *Tmp7 = Builder.CreateOr(Tmp5, Tmp6);
212+
Value *Tmp8 = Builder.CreateShl(Q_2, One);
213+
Value *Q_1 = Builder.CreateOr(Carry_1, Tmp8);
214+
Value *Tmp9 = Builder.CreateSub(Tmp4, Tmp7);
215+
Value *Tmp10 = Builder.CreateAShr(Tmp9, 31);
216+
Value *Carry = Builder.CreateAnd(Tmp10, One);
217+
Value *Tmp11 = Builder.CreateAnd(Tmp10, Divisor);
218+
Value *R = Builder.CreateSub(Tmp7, Tmp11);
219+
Value *SR_2 = Builder.CreateAdd(SR_3, NegOne);
220+
Value *Tmp12 = Builder.CreateICmpEQ(SR_2, Zero);
221221
Builder.CreateCondBr(Tmp12, LoopExit, DoWhile);
222222

223223
// ; loop-exit: ; preds = %do-while, %bb1
@@ -227,17 +227,17 @@ static Value* GenerateUnsignedDivisionCode(Value* Dividend, Value* Divisor,
227227
// ; %q_4 = or i32 %carry_2, %tmp13
228228
// ; br label %end
229229
Builder.SetInsertPoint(LoopExit);
230-
PHINode* Carry_2 = Builder.CreatePHI(I32Ty, 2);
231-
PHINode* Q_3 = Builder.CreatePHI(I32Ty, 2);
232-
Value* Tmp13 = Builder.CreateShl(Q_3, One);
233-
Value* Q_4 = Builder.CreateOr(Carry_2, Tmp13);
230+
PHINode *Carry_2 = Builder.CreatePHI(I32Ty, 2);
231+
PHINode *Q_3 = Builder.CreatePHI(I32Ty, 2);
232+
Value *Tmp13 = Builder.CreateShl(Q_3, One);
233+
Value *Q_4 = Builder.CreateOr(Carry_2, Tmp13);
234234
Builder.CreateBr(End);
235235

236236
// ; end: ; preds = %loop-exit, %special-cases
237237
// ; %q_5 = phi i32 [ %q_4, %loop-exit ], [ %retVal, %special-cases ]
238238
// ; ret i32 %q_5
239239
Builder.SetInsertPoint(End, End->begin());
240-
PHINode* Q_5 = Builder.CreatePHI(I32Ty, 2);
240+
PHINode *Q_5 = Builder.CreatePHI(I32Ty, 2);
241241

242242
// Populate the Phis, since all values have now been created. Our Phis were:
243243
// ; %carry_1 = phi i32 [ 0, %preheader ], [ %carry, %do-while ]
@@ -265,7 +265,7 @@ static Value* GenerateUnsignedDivisionCode(Value* Dividend, Value* Divisor,
265265
return Q_5;
266266
}
267267

268-
bool llvm::expandDivision(BinaryOperator* Div) {
268+
bool llvm::expandDivision(BinaryOperator *Div) {
269269
assert((Div->getOpcode() == Instruction::SDiv ||
270270
Div->getOpcode() == Instruction::UDiv) &&
271271
"Trying to expand division from a non-division function");
@@ -278,22 +278,22 @@ bool llvm::expandDivision(BinaryOperator* Div) {
278278
// First prepare the sign if it's a signed division
279279
if (Div->getOpcode() == Instruction::SDiv) {
280280
// Lower the code to unsigned division, and reset Div to point to the udiv.
281-
Value* Quotient = GenerateSignedDivisionCode(Div->getOperand(0),
281+
Value *Quotient = GenerateSignedDivisionCode(Div->getOperand(0),
282282
Div->getOperand(1), Builder);
283283
Div->replaceAllUsesWith(Quotient);
284284
Div->dropAllReferences();
285285
Div->eraseFromParent();
286286

287287
// If we didn't actually generate a udiv instruction, we're done
288-
BinaryOperator* BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
288+
BinaryOperator *BO = dyn_cast<BinaryOperator>(Builder.GetInsertPoint());
289289
if (!BO || BO->getOpcode() != Instruction::UDiv)
290290
return true;
291291

292292
Div = BO;
293293
}
294294

295295
// Insert the unsigned division code
296-
Value* Quotient = GenerateUnsignedDivisionCode(Div->getOperand(0),
296+
Value *Quotient = GenerateUnsignedDivisionCode(Div->getOperand(0),
297297
Div->getOperand(1),
298298
Builder);
299299
Div->replaceAllUsesWith(Quotient);

0 commit comments

Comments
 (0)