aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Analysis
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-04-20 21:19:10 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-04-20 21:19:10 +0000
commitd99dafe2e4a385dd2a6c76da6d8258deb100657b (patch)
treeba60bf957558bd114f25dbff3d4996b5d7a61c82 /include/llvm/Analysis
parent71d5a2540a98c81f5bcaeb48805e0e2881f530ef (diff)
Notes
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r--include/llvm/Analysis/BlockFrequencyInfoImpl.h12
-rw-r--r--include/llvm/Analysis/DominanceFrontierImpl.h8
-rw-r--r--include/llvm/Analysis/LoopInfo.h23
-rw-r--r--include/llvm/Analysis/LoopInfoImpl.h73
-rw-r--r--include/llvm/Analysis/MemoryBuiltins.h5
-rw-r--r--include/llvm/Analysis/ScalarEvolution.h12
6 files changed, 55 insertions, 78 deletions
diff --git a/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/include/llvm/Analysis/BlockFrequencyInfoImpl.h
index e3d81fea49ea..3e05e09900a5 100644
--- a/include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ b/include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -1164,9 +1164,8 @@ template <class BT> struct BlockEdgesAdder {
void operator()(IrreducibleGraph &G, IrreducibleGraph::IrrNode &Irr,
const LoopData *OuterLoop) {
const BlockT *BB = BFI.RPOT[Irr.Node.Index];
- for (auto I = Successor::child_begin(BB), E = Successor::child_end(BB);
- I != E; ++I)
- G.addEdge(Irr, BFI.getNode(*I), OuterLoop);
+ for (const auto Succ : children<const BlockT *>(BB))
+ G.addEdge(Irr, BFI.getNode(Succ), OuterLoop);
}
};
}
@@ -1210,10 +1209,9 @@ BlockFrequencyInfoImpl<BT>::propagateMassToSuccessors(LoopData *OuterLoop,
return false;
} else {
const BlockT *BB = getBlock(Node);
- for (auto SI = Successor::child_begin(BB), SE = Successor::child_end(BB);
- SI != SE; ++SI)
- if (!addToDist(Dist, OuterLoop, Node, getNode(*SI),
- getWeightFromBranchProb(BPI->getEdgeProbability(BB, SI))))
+ for (const auto Succ : children<const BlockT *>(BB))
+ if (!addToDist(Dist, OuterLoop, Node, getNode(Succ),
+ getWeightFromBranchProb(BPI->getEdgeProbability(BB, Succ))))
// Irreducible backedge.
return false;
}
diff --git a/include/llvm/Analysis/DominanceFrontierImpl.h b/include/llvm/Analysis/DominanceFrontierImpl.h
index 629ae3809045..9f8cacc24f2c 100644
--- a/include/llvm/Analysis/DominanceFrontierImpl.h
+++ b/include/llvm/Analysis/DominanceFrontierImpl.h
@@ -174,12 +174,10 @@ ForwardDominanceFrontierBase<BlockT>::calculate(const DomTreeT &DT,
// Visit each block only once.
if (visited.insert(currentBB).second) {
// Loop over CFG successors to calculate DFlocal[currentNode]
- for (auto SI = BlockTraits::child_begin(currentBB),
- SE = BlockTraits::child_end(currentBB);
- SI != SE; ++SI) {
+ for (const auto Succ : children<BlockT *>(currentBB)) {
// Does Node immediately dominate this successor?
- if (DT[*SI]->getIDom() != currentNode)
- S.insert(*SI);
+ if (DT[Succ]->getIDom() != currentNode)
+ S.insert(Succ);
}
}
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h
index 996794b660a9..2fad1737d1c0 100644
--- a/include/llvm/Analysis/LoopInfo.h
+++ b/include/llvm/Analysis/LoopInfo.h
@@ -158,11 +158,8 @@ public:
/// True if terminator in the block can branch to another block that is
/// outside of the current loop.
bool isLoopExiting(const BlockT *BB) const {
- typedef GraphTraits<const BlockT*> BlockTraits;
- for (typename BlockTraits::ChildIteratorType SI =
- BlockTraits::child_begin(BB),
- SE = BlockTraits::child_end(BB); SI != SE; ++SI) {
- if (!contains(*SI))
+ for (const auto Succ : children<const BlockT*>(BB)) {
+ if (!contains(Succ))
return true;
}
return false;
@@ -186,11 +183,8 @@ public:
unsigned NumBackEdges = 0;
BlockT *H = getHeader();
- typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
- for (typename InvBlockTraits::ChildIteratorType I =
- InvBlockTraits::child_begin(H),
- E = InvBlockTraits::child_end(H); I != E; ++I)
- if (contains(*I))
+ for (const auto Pred : children<Inverse<BlockT*> >(H))
+ if (contains(Pred))
++NumBackEdges;
return NumBackEdges;
@@ -249,12 +243,9 @@ public:
/// contains a branch back to the header.
void getLoopLatches(SmallVectorImpl<BlockT *> &LoopLatches) const {
BlockT *H = getHeader();
- typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
- for (typename InvBlockTraits::ChildIteratorType I =
- InvBlockTraits::child_begin(H),
- E = InvBlockTraits::child_end(H); I != E; ++I)
- if (contains(*I))
- LoopLatches.push_back(*I);
+ for (const auto Pred : children<Inverse<BlockT*>>(H))
+ if (contains(Pred))
+ LoopLatches.push_back(Pred);
}
//===--------------------------------------------------------------------===//
diff --git a/include/llvm/Analysis/LoopInfoImpl.h b/include/llvm/Analysis/LoopInfoImpl.h
index 761f8721b54f..6dc0422ce0e9 100644
--- a/include/llvm/Analysis/LoopInfoImpl.h
+++ b/include/llvm/Analysis/LoopInfoImpl.h
@@ -34,14 +34,11 @@ namespace llvm {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitingBlocks(SmallVectorImpl<BlockT *> &ExitingBlocks) const {
- typedef GraphTraits<BlockT*> BlockTraits;
- for (block_iterator BI = block_begin(), BE = block_end(); BI != BE; ++BI)
- for (typename BlockTraits::ChildIteratorType I =
- BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
- I != E; ++I)
- if (!contains(*I)) {
+ for (const auto BB : blocks())
+ for (const auto Succ : children<BlockT*>(BB))
+ if (!contains(Succ)) {
// Not in current loop? It must be an exit block.
- ExitingBlocks.push_back(*BI);
+ ExitingBlocks.push_back(BB);
break;
}
}
@@ -63,14 +60,11 @@ BlockT *LoopBase<BlockT, LoopT>::getExitingBlock() const {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitBlocks(SmallVectorImpl<BlockT*> &ExitBlocks) const {
- typedef GraphTraits<BlockT*> BlockTraits;
- for (block_iterator BI = block_begin(), BE = block_end(); BI != BE; ++BI)
- for (typename BlockTraits::ChildIteratorType I =
- BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
- I != E; ++I)
- if (!contains(*I))
+ for (const auto BB : blocks())
+ for (const auto Succ : children<BlockT*>(BB))
+ if (!contains(Succ))
// Not in current loop? It must be an exit block.
- ExitBlocks.push_back(*I);
+ ExitBlocks.push_back(Succ);
}
/// getExitBlock - If getExitBlocks would return exactly one block,
@@ -88,14 +82,11 @@ BlockT *LoopBase<BlockT, LoopT>::getExitBlock() const {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitEdges(SmallVectorImpl<Edge> &ExitEdges) const {
- typedef GraphTraits<BlockT*> BlockTraits;
- for (block_iterator BI = block_begin(), BE = block_end(); BI != BE; ++BI)
- for (typename BlockTraits::ChildIteratorType I =
- BlockTraits::child_begin(*BI), E = BlockTraits::child_end(*BI);
- I != E; ++I)
- if (!contains(*I))
+ for (const auto BB : blocks())
+ for (const auto Succ : children<BlockT*>(BB))
+ if (!contains(Succ))
// Not in current loop? It must be an exit block.
- ExitEdges.push_back(Edge(*BI, *I));
+ ExitEdges.emplace_back(BB, Succ);
}
/// getLoopPreheader - If there is a preheader for this loop, return it. A
@@ -134,15 +125,11 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPredecessor() const {
// Loop over the predecessors of the header node...
BlockT *Header = getHeader();
- typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
- for (typename InvBlockTraits::ChildIteratorType PI =
- InvBlockTraits::child_begin(Header),
- PE = InvBlockTraits::child_end(Header); PI != PE; ++PI) {
- typename InvBlockTraits::NodeRef N = *PI;
- if (!contains(N)) { // If the block is not in the loop...
- if (Out && Out != N)
+ for (const auto Pred : children<Inverse<BlockT*>>(Header)) {
+ if (!contains(Pred)) { // If the block is not in the loop...
+ if (Out && Out != Pred)
return nullptr; // Multiple predecessors outside the loop
- Out = N;
+ Out = Pred;
}
}
@@ -156,17 +143,11 @@ BlockT *LoopBase<BlockT, LoopT>::getLoopPredecessor() const {
template<class BlockT, class LoopT>
BlockT *LoopBase<BlockT, LoopT>::getLoopLatch() const {
BlockT *Header = getHeader();
- typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
- typename InvBlockTraits::ChildIteratorType PI =
- InvBlockTraits::child_begin(Header);
- typename InvBlockTraits::ChildIteratorType PE =
- InvBlockTraits::child_end(Header);
BlockT *Latch = nullptr;
- for (; PI != PE; ++PI) {
- typename InvBlockTraits::NodeRef N = *PI;
- if (contains(N)) {
+ for (const auto Pred : children<Inverse<BlockT*>>(Header)) {
+ if (contains(Pred)) {
if (Latch) return nullptr;
- Latch = N;
+ Latch = Pred;
}
}
@@ -394,11 +375,9 @@ static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT*> Backedges,
// within this subloop tree itself. Note that a predecessor may directly
// reach another subloop that is not yet discovered to be a subloop of
// this loop, which we must traverse.
- for (typename InvBlockTraits::ChildIteratorType PI =
- InvBlockTraits::child_begin(PredBB),
- PE = InvBlockTraits::child_end(PredBB); PI != PE; ++PI) {
- if (LI->getLoopFor(*PI) != Subloop)
- ReverseCFGWorklist.push_back(*PI);
+ for (const auto Pred : children<Inverse<BlockT*>>(PredBB)) {
+ if (LI->getLoopFor(Pred) != Subloop)
+ ReverseCFGWorklist.push_back(Pred);
}
}
}
@@ -482,13 +461,7 @@ analyze(const DominatorTreeBase<BlockT> &DomTree) {
SmallVector<BlockT *, 4> Backedges;
// Check each predecessor of the potential loop header.
- typedef GraphTraits<Inverse<BlockT*> > InvBlockTraits;
- for (typename InvBlockTraits::ChildIteratorType PI =
- InvBlockTraits::child_begin(Header),
- PE = InvBlockTraits::child_end(Header); PI != PE; ++PI) {
-
- BlockT *Backedge = *PI;
-
+ for (const auto Backedge : children<Inverse<BlockT*>>(Header)) {
// If Header dominates predBB, this is a new loop. Collect the backedges.
if (DomTree.dominates(Header, Backedge)
&& DomTree.isReachableFromEntry(Backedge)) {
diff --git a/include/llvm/Analysis/MemoryBuiltins.h b/include/llvm/Analysis/MemoryBuiltins.h
index c5514316f75f..743faf2b67db 100644
--- a/include/llvm/Analysis/MemoryBuiltins.h
+++ b/include/llvm/Analysis/MemoryBuiltins.h
@@ -54,6 +54,11 @@ bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool LookThroughBitCast = false);
/// \brief Tests if a value is a call or invoke to a library function that
+/// allocates memory similar to malloc or calloc.
+bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
+ bool LookThroughBitCast = false);
+
+/// \brief Tests if a value is a call or invoke to a library function that
/// allocates memory (either malloc, calloc, or strdup like).
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool LookThroughBitCast = false);
diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h
index 9a50de540f2b..91aeae0f728f 100644
--- a/include/llvm/Analysis/ScalarEvolution.h
+++ b/include/llvm/Analysis/ScalarEvolution.h
@@ -1159,8 +1159,20 @@ public:
const SCEV *getConstant(const APInt &Val);
const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false);
const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty);
+
+ typedef SmallDenseMap<std::pair<const SCEV *, Type *>, const SCEV *, 8>
+ ExtendCacheTy;
const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty);
+ const SCEV *getZeroExtendExprCached(const SCEV *Op, Type *Ty,
+ ExtendCacheTy &Cache);
+ const SCEV *getZeroExtendExprImpl(const SCEV *Op, Type *Ty,
+ ExtendCacheTy &Cache);
+
const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty);
+ const SCEV *getSignExtendExprCached(const SCEV *Op, Type *Ty,
+ ExtendCacheTy &Cache);
+ const SCEV *getSignExtendExprImpl(const SCEV *Op, Type *Ty,
+ ExtendCacheTy &Cache);
const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap,