From 4ac4e155822f5070ff354791d469d3cebe0671ae Mon Sep 17 00:00:00 2001 From: Hongbin Zheng Date: Mon, 23 Apr 2012 13:03:56 +0000 Subject: [PATCH] Refactor: Pass the argument 'IRBuilder' and 'AfterBlock' of function 'createLoop' by reference, so that we do not need to type an extra '&' operator when calling the function. llvm-svn: 155349 --- polly/include/polly/LoopGenerators.h | 4 +++- polly/lib/CodeGen/CodeGeneration.cpp | 2 +- polly/lib/CodeGen/LoopGenerators.cpp | 34 +++++++++++++++------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/polly/include/polly/LoopGenerators.h b/polly/include/polly/LoopGenerators.h index b37c55298f36..5611dcd9d0ba 100644 --- a/polly/include/polly/LoopGenerators.h +++ b/polly/include/polly/LoopGenerators.h @@ -36,8 +36,10 @@ using namespace llvm; /// @param Builder The builder used to create the loop. /// @param P A pointer to the pass that uses this function. It is used /// to update analysis information. +/// +/// @return Value* The newly created induction variable for this loop. Value *createLoop(Value *LowerBound, Value *UpperBound, Value *Stride, - IRBuilder<> *Builder, Pass *P, BasicBlock **AfterBlock); + IRBuilder<> &Builder, Pass *P, BasicBlock *&AfterBlock); class OMPGenerator { public: diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp index e0fc8840774a..7edd1361837c 100644 --- a/polly/lib/CodeGen/CodeGeneration.cpp +++ b/polly/lib/CodeGen/CodeGeneration.cpp @@ -1231,7 +1231,7 @@ void ClastStmtCodeGen::codegenForSequential(const clast_for *f) { UpperBound = ExpGen.codegen(f->UB, IntPtrTy); Stride = Builder.getInt(APInt_from_MPZ(f->stride)); - IV = createLoop(LowerBound, UpperBound, Stride, &Builder, P, &AfterBB); + IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, AfterBB); // Add loop iv to symbols. ClastVars[f->iterator] = IV; diff --git a/polly/lib/CodeGen/LoopGenerators.cpp b/polly/lib/CodeGen/LoopGenerators.cpp index 54c188965355..583bbe4d25ac 100644 --- a/polly/lib/CodeGen/LoopGenerators.cpp +++ b/polly/lib/CodeGen/LoopGenerators.cpp @@ -21,23 +21,25 @@ #include "llvm/Transforms/Utils/BasicBlockUtils.h" using namespace llvm; +using namespace polly; -Value *createLoop(Value *LB, Value *UB, Value *Stride, - IRBuilder<> *Builder, Pass *P, BasicBlock **AfterBlock) { +Value *polly::createLoop(Value *LB, Value *UB, Value *Stride, + IRBuilder<> &Builder, Pass *P, + BasicBlock *&AfterBlock) { DominatorTree &DT = P->getAnalysis(); - Function *F = Builder->GetInsertBlock()->getParent(); + Function *F = Builder.GetInsertBlock()->getParent(); LLVMContext &Context = F->getContext(); - BasicBlock *PreheaderBB = Builder->GetInsertBlock(); + BasicBlock *PreheaderBB = Builder.GetInsertBlock(); BasicBlock *HeaderBB = BasicBlock::Create(Context, "polly.loop_header", F); BasicBlock *BodyBB = BasicBlock::Create(Context, "polly.loop_body", F); - BasicBlock *AfterBB = SplitBlock(PreheaderBB, Builder->GetInsertPoint()++, P); + BasicBlock *AfterBB = SplitBlock(PreheaderBB, Builder.GetInsertPoint()++, P); AfterBB->setName("polly.loop_after"); PreheaderBB->getTerminator()->setSuccessor(0, HeaderBB); DT.addNewBlock(HeaderBB, PreheaderBB); - Builder->SetInsertPoint(HeaderBB); + Builder.SetInsertPoint(HeaderBB); // Use the type of upper and lower bound. assert(LB->getType() == UB->getType() @@ -47,26 +49,26 @@ Value *createLoop(Value *LB, Value *UB, Value *Stride, assert(LoopIVType && "UB is not integer?"); // IV - PHINode *IV = Builder->CreatePHI(LoopIVType, 2, "polly.loopiv"); + PHINode *IV = Builder.CreatePHI(LoopIVType, 2, "polly.loopiv"); IV->addIncoming(LB, PreheaderBB); - Stride = Builder->CreateZExtOrBitCast(Stride, LoopIVType); - Value *IncrementedIV = Builder->CreateAdd(IV, Stride, "polly.next_loopiv"); + Stride = Builder.CreateZExtOrBitCast(Stride, LoopIVType); + Value *IncrementedIV = Builder.CreateAdd(IV, Stride, "polly.next_loopiv"); // Exit condition. Value *CMP; - CMP = Builder->CreateICmpSLE(IV, UB); + CMP = Builder.CreateICmpSLE(IV, UB); - Builder->CreateCondBr(CMP, BodyBB, AfterBB); + Builder.CreateCondBr(CMP, BodyBB, AfterBB); DT.addNewBlock(BodyBB, HeaderBB); - Builder->SetInsertPoint(BodyBB); - Builder->CreateBr(HeaderBB); + Builder.SetInsertPoint(BodyBB); + Builder.CreateBr(HeaderBB); IV->addIncoming(IncrementedIV, BodyBB); DT.changeImmediateDominator(AfterBB, HeaderBB); - Builder->SetInsertPoint(BodyBB->begin()); - *AfterBlock = AfterBB; + Builder.SetInsertPoint(BodyBB->begin()); + AfterBlock = AfterBB; return IV; } @@ -284,7 +286,7 @@ Value *OMPGenerator::createSubfunction(Value *Stride, Value *StructData, Builder.CreateBr(CheckNextBB); Builder.SetInsertPoint(--Builder.GetInsertPoint()); - IV = createLoop(LowerBound, UpperBound, Stride, &Builder, P, &AfterBB); + IV = createLoop(LowerBound, UpperBound, Stride, Builder, P, AfterBB); BasicBlock::iterator LoopBody = Builder.GetInsertPoint(); Builder.SetInsertPoint(AfterBB->begin());