30 #ifndef LLVM_ANALYSIS_LOOPINFO_H
31 #define LLVM_ANALYSIS_LOOPINFO_H
45 typename std::vector<T*>::iterator
I = std::find(V.begin(), V.end(),
N);
46 assert(I != V.end() &&
"N is not in this list!");
63 template<
class BlockT,
class LoopT>
67 std::vector<LoopT *> SubLoops;
70 std::vector<BlockT*> Blocks;
76 operator=(const
LoopBase<BlockT, LoopT> &) LLVM_DELETED_FUNCTION;
81 for (
size_t i = 0, e = SubLoops.size(); i != e; ++i)
90 for (
const LoopT *CurLoop = ParentLoop; CurLoop;
91 CurLoop = CurLoop->ParentLoop)
95 BlockT *
getHeader()
const {
return Blocks.front(); }
105 if (L ==
this)
return true;
106 if (L == 0)
return false;
107 return contains(L->getParentLoop());
113 return DenseBlockSet.
count(BB);
118 template<
class InstT>
125 const std::vector<LoopT *> &
getSubLoops()
const {
return SubLoops; }
127 typedef typename std::vector<LoopT *>::const_iterator
iterator;
128 typedef typename std::vector<LoopT *>::const_reverse_iterator
134 bool empty()
const {
return SubLoops.empty(); }
138 const std::vector<BlockT*> &
getBlocks()
const {
return Blocks; }
145 return Blocks.size();
153 for (
typename BlockTraits::ChildIteratorType SI =
154 BlockTraits::child_begin(BB),
155 SE = BlockTraits::child_end(BB); SI != SE; ++SI) {
165 unsigned NumBackEdges = 0;
169 for (
typename InvBlockTraits::ChildIteratorType
I =
170 InvBlockTraits::child_begin(H),
171 E = InvBlockTraits::child_end(H);
I != E; ++
I)
206 typedef std::pair<const BlockT*, const BlockT*>
Edge;
253 assert(NewChild->ParentLoop == 0 &&
"NewChild already has a parent!");
254 NewChild->ParentLoop =
static_cast<LoopT *
>(
this);
255 SubLoops.push_back(NewChild);
262 assert(I != SubLoops.end() &&
"Cannot remove end iterator!");
264 assert(Child->ParentLoop ==
this &&
"Child is not a child of this loop!");
265 SubLoops.erase(SubLoops.begin()+(I-
begin()));
266 Child->ParentLoop = 0;
274 Blocks.push_back(BB);
280 std::reverse(Blocks.begin() + from, Blocks.end());
285 Blocks.reserve(size);
292 if (Blocks[0] == BB)
return;
293 for (
unsigned i = 0; ; ++i) {
294 assert(i != Blocks.size() &&
"Loop does not contain BB!");
295 if (Blocks[i] == BB) {
296 Blocks[i] = Blocks[0];
308 DenseBlockSet.
erase(BB);
322 Blocks.push_back(BB);
327 template<
class BlockT,
class LoopT>
335 __extension__
extern template class LoopBase<BasicBlock, Loop>;
359 bool makeLoopInvariant(
Value *V,
bool &Changed,
382 PHINode *getCanonicalInductionVariable()
const;
390 bool isLoopSimplifyForm()
const;
393 bool isSafeToClone()
const;
407 bool isAnnotatedParallel()
const;
415 MDNode *getLoopID()
const;
423 void setLoopID(
MDNode *LoopID)
const;
427 bool hasDedicatedExits()
const;
451 template<
class BlockT,
class LoopT>
454 DenseMap<BlockT *, LoopT *> BBMap;
455 std::vector<LoopT *> TopLevelLoops;
466 for (
typename std::vector<LoopT *>::iterator
I =
467 TopLevelLoops.begin(), E = TopLevelLoops.end();
I != E; ++
I)
471 TopLevelLoops.clear();
477 typedef typename std::vector<LoopT *>::const_iterator
iterator;
478 typedef typename std::vector<LoopT *>::const_reverse_iterator
480 iterator
begin()
const {
return TopLevelLoops.begin(); }
481 iterator
end()
const {
return TopLevelLoops.end(); }
484 bool empty()
const {
return TopLevelLoops.empty(); }
490 return BBMap.lookup(const_cast<BlockT*>(BB));
496 return getLoopFor(BB);
503 const LoopT *L = getLoopFor(BB);
504 return L ? L->getLoopDepth() : 0;
509 const LoopT *L = getLoopFor(BB);
510 return L && L->getHeader() == BB;
517 assert(I !=
end() &&
"Cannot remove end iterator!");
519 assert(L->getParentLoop() == 0 &&
"Not a top-level loop!");
520 TopLevelLoops.erase(TopLevelLoops.begin() + (I-
begin()));
539 typename std::vector<LoopT *>::iterator
I =
540 std::find(TopLevelLoops.begin(), TopLevelLoops.end(), OldLoop);
541 assert(I != TopLevelLoops.end() &&
"Old loop not at top level!");
543 assert(NewLoop->ParentLoop == 0 && OldLoop->ParentLoop == 0 &&
544 "Loops already embedded into a subloop!");
550 assert(New->getParentLoop() == 0 &&
"Loop already in subloop!");
551 TopLevelLoops.push_back(New);
559 if (I != BBMap.
end()) {
560 for (LoopT *L = I->second; L; L = L->getParentLoop())
561 L->removeBlockFromLoop(BB);
570 const LoopT *ParentLoop) {
571 if (SubLoop == 0)
return true;
572 if (SubLoop == ParentLoop)
return false;
573 return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop);
586 __extension__
extern template class LoopInfoBase<BasicBlock, Loop>;
610 inline iterator
end()
const {
return LI.
end(); }
612 inline reverse_iterator
rend()
const {
return LI.
rend(); }
644 virtual void verifyAnalysis()
const;
687 void updateUnloop(
Loop *Unloop);
703 if (!ToLoop)
return true;
unsigned getNumBackEdges() const
LoopInfo::iterator ChildIteratorType
void changeTopLevelLoop(Loop *OldLoop, Loop *NewLoop)
const_iterator end(StringRef path)
Get end iterator over path.
unsigned getLoopDepth(const BlockT *BB) const
static PassRegistry * getPassRegistry()
virtual void releaseMemory()
static bool isLoopInvariant(Value *V, const Loop *L, const DominatorTree *DT)
void removeBlock(BlockT *BB)
LoopT * removeLoop(iterator I)
The main container class for the LLVM Intermediate Representation.
LoopInfoBase< BasicBlock, Loop >::iterator iterator
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const LoopT * operator[](const BlockT *BB) const
std::vector< LoopT * >::const_reverse_iterator reverse_iterator
static bool isNotAlreadyContainedIn(const LoopT *SubLoop, const LoopT *ParentLoop)
bool isLoopExiting(const BlockT *BB) const
void replaceChildLoopWith(LoopT *OldChild, LoopT *NewChild)
const_iterator begin(StringRef path)
Get begin iterator over path.
void changeLoopFor(BlockT *BB, LoopT *L)
LoopT * getParentLoop() const
MDNode - a tuple of other values.
LoopT * getLoopFor(const BlockT *BB) const
BlockT * getExitBlock() const
const std::vector< BlockT * > & getBlocks() const
void initializeLoopInfoPass(PassRegistry &)
reverse_iterator rbegin() const
BlockT * getHeader() const
LoopInfoBase< BlockT, LoopT > * LI
LoopT * removeChildLoop(iterator I)
std::vector< LoopT * >::const_iterator iterator
BlockT * getLoopLatch() const
void getExitEdges(SmallVectorImpl< Edge > &ExitEdges) const
getExitEdges - Return all pairs of (inside_block,outside_block).
void print(raw_ostream &OS, unsigned Depth=0) const
static ChildIteratorType child_begin(NodeType *N)
void getExitingBlocks(SmallVectorImpl< BlockT * > &ExitingBlocks) const
ID
LLVM Calling Convention Representation.
void getExitBlocks(SmallVectorImpl< BlockT * > &ExitBlocks) const
reverse_iterator rbegin() const
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
bool contains(const InstT *Inst) const
void addChildLoop(LoopT *NewChild)
Loop * getLoopFor(const BasicBlock *BB) const
Loop * removeLoop(iterator I)
void verifyLoop() const
verifyLoop - Verify loop structure
std::vector< LoopT * >::const_reverse_iterator reverse_iterator
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
BlockT * getLoopPreheader() const
void setParentLoop(LoopT *L)
setParentLoop is a raw interface for bypassing addChildLoop.
LLVM Basic Block Representation.
void RemoveFromVector(std::vector< T * > &V, T *N)
Instr is a loop (backwards branch).
static ChildIteratorType child_end(NodeType *N)
bool contains(const LoopT *L) const
BlockT * getExitingBlock() const
void addBlockEntry(BlockT *BB)
bool isLoopHeader(BasicBlock *BB) const
bool isLoopHeader(BlockT *BB) const
reverse_iterator rend() const
void removeBlockFromLoop(BlockT *BB)
LoopInfoBase< BasicBlock, Loop >::reverse_iterator reverse_iterator
std::pair< const BlockT *, const BlockT * > Edge
Edge type.
reverse_iterator rend() const
bool contains(const BlockT *BB) const
static NodeType * getEntryNode(const Loop *L)
void addTopLevelLoop(LoopT *New)
static ChildIteratorType child_begin(NodeType *N)
#define LLVM_DELETED_FUNCTION
void reserveBlocks(unsigned size)
reserveBlocks- interface to do reserve() for Blocks
unsigned getLoopDepth(const BasicBlock *BB) const
LoopInfo::iterator ChildIteratorType
std::vector< BlockT * >::const_iterator block_iterator
void verifyLoopNest(DenseSet< const LoopT * > *Loops) const
verifyLoop - Verify loop structure of this loop and all nested loops.
block_iterator block_end() const
static NodeType * getEntryNode(Loop *L)
unsigned getNumBlocks() const
getNumBlocks - Get the number of blocks in this loop in constant time.
void moveToHeader(BlockT *BB)
BlockT * getLoopPredecessor() const
void addTopLevelLoop(Loop *New)
void removeBlock(BasicBlock *BB)
std::vector< LoopT * > & getSubLoopsVector()
void changeLoopFor(BasicBlock *BB, Loop *L)
static ChildIteratorType child_end(NodeType *N)
LLVM Value Representation.
LoopBase()
Loop ctor - This creates an empty loop.
void changeTopLevelLoop(LoopT *OldLoop, LoopT *NewLoop)
const std::vector< LoopT * > & getSubLoops() const
block_iterator block_begin() const
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
std::vector< LoopT * >::const_iterator iterator
reverse_iterator rbegin() const
unsigned getLoopDepth() const
void reverseBlock(unsigned from)
reverseBlocks - interface to reverse Blocks[from, end of loop] in this loop
const Loop * operator[](const BasicBlock *BB) const
LoopInfoBase< BasicBlock, Loop > & getBase()
reverse_iterator rend() const
const BasicBlock * getParent() const