forked from OSchip/llvm-project
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
This commit is contained in:
parent
6f7aa074ad
commit
4ac4e15582
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<DominatorTree>();
|
||||
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());
|
||||
|
|
Loading…
Reference in New Issue