Polly 22.0.0git
CodePreparation.cpp
Go to the documentation of this file.
1//===---- CodePreparation.cpp - Code preparation for Scop Detection -------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// The Polly code preparation pass is executed before SCoP detection. Its
10// currently only splits the entry block of the SCoP to make room for alloc
11// instructions as they are generated during code generation.
12//
13// XXX: In the future, we should remove the need for this pass entirely and
14// instead add this spitting to the code generation pass.
15//
16//===----------------------------------------------------------------------===//
17
20#include "llvm/Analysis/DominanceFrontier.h"
21#include "llvm/Analysis/LoopInfo.h"
22#include "llvm/Analysis/RegionInfo.h"
23#include "llvm/Analysis/ScalarEvolution.h"
24
25using namespace llvm;
26using namespace polly;
27
28static bool runCodePreprationImpl(Function &F, DominatorTree *DT, LoopInfo *LI,
29 RegionInfo *RI) {
30 // Find first non-alloca instruction. Every basic block has a non-alloca
31 // instruction, as every well formed basic block has a terminator.
32 auto &EntryBlock = F.getEntryBlock();
33 BasicBlock::iterator I = EntryBlock.begin();
34 while (isa<AllocaInst>(I))
35 ++I;
36
37 // Abort if not necessary to split
38 if (I->isTerminator() && isa<BranchInst>(I) &&
39 cast<BranchInst>(I)->isUnconditional())
40 return false;
41
42 // splitBlock updates DT, LI and RI.
43 splitEntryBlockForAlloca(&EntryBlock, DT, LI, RI);
44
45 return true;
46}
47
48bool polly::runCodePreparation(Function &F, DominatorTree *DT, LoopInfo *LI,
49 RegionInfo *RI) {
50 return runCodePreprationImpl(F, DT, LI, RI);
51}
static bool runCodePreprationImpl(Function &F, DominatorTree *DT, LoopInfo *LI, RegionInfo *RI)
bool runCodePreparation(llvm::Function &F, llvm::DominatorTree *DT, llvm::LoopInfo *LI, llvm::RegionInfo *RI)
void splitEntryBlockForAlloca(llvm::BasicBlock *EntryBlock, llvm::DominatorTree *DT, llvm::LoopInfo *LI, llvm::RegionInfo *RI)
Split the entry block of a function to store the newly inserted allocations outside of all Scops.