summaryrefslogtreecommitdiffstats
path: root/include/llvm/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r--include/llvm/Analysis/BlockFrequencyImpl.h2
-rw-r--r--include/llvm/Analysis/BlockFrequencyInfo.h2
-rw-r--r--include/llvm/Analysis/CFG.h16
-rw-r--r--include/llvm/Analysis/CFGPrinter.h31
-rw-r--r--include/llvm/Analysis/CallGraph.h73
-rw-r--r--include/llvm/Analysis/DependenceAnalysis.h4
-rw-r--r--include/llvm/Analysis/Dominators.h20
-rw-r--r--include/llvm/Analysis/LoopInfo.h18
-rw-r--r--include/llvm/Analysis/LoopInfoImpl.h41
-rw-r--r--include/llvm/Analysis/LoopPass.h2
-rw-r--r--include/llvm/Analysis/MemoryBuiltins.h21
-rw-r--r--include/llvm/Analysis/Passes.h65
-rw-r--r--include/llvm/Analysis/PathNumbering.h304
-rw-r--r--include/llvm/Analysis/PathProfileInfo.h112
-rw-r--r--include/llvm/Analysis/ProfileDataLoader.h140
-rw-r--r--include/llvm/Analysis/ProfileDataTypes.h39
-rw-r--r--include/llvm/Analysis/ProfileInfo.h247
-rw-r--r--include/llvm/Analysis/ProfileInfoLoader.h81
-rw-r--r--include/llvm/Analysis/ProfileInfoTypes.h52
-rw-r--r--include/llvm/Analysis/RegionPass.h2
-rw-r--r--include/llvm/Analysis/ScalarEvolution.h63
-rw-r--r--include/llvm/Analysis/ScalarEvolutionExpander.h4
-rw-r--r--include/llvm/Analysis/ScalarEvolutionExpressions.h148
-rw-r--r--include/llvm/Analysis/TargetTransformInfo.h53
-rw-r--r--include/llvm/Analysis/ValueTracking.h3
25 files changed, 342 insertions, 1201 deletions
diff --git a/include/llvm/Analysis/BlockFrequencyImpl.h b/include/llvm/Analysis/BlockFrequencyImpl.h
index 5e14d6f..817a441 100644
--- a/include/llvm/Analysis/BlockFrequencyImpl.h
+++ b/include/llvm/Analysis/BlockFrequencyImpl.h
@@ -118,7 +118,7 @@ class BlockFrequencyImpl {
/// isBackedge - Return if edge Src -> Dst is a reachable backedge.
///
- bool isBackedge(BlockT *Src, BlockT *Dst) {
+ bool isBackedge(BlockT *Src, BlockT *Dst) const {
unsigned a = RPO.lookup(Src);
if (!a)
return false;
diff --git a/include/llvm/Analysis/BlockFrequencyInfo.h b/include/llvm/Analysis/BlockFrequencyInfo.h
index 64bd15c..a123d0b 100644
--- a/include/llvm/Analysis/BlockFrequencyInfo.h
+++ b/include/llvm/Analysis/BlockFrequencyInfo.h
@@ -41,6 +41,8 @@ public:
bool runOnFunction(Function &F);
void print(raw_ostream &O, const Module *M) const;
+ const Function *getFunction() const;
+ void view() const;
/// getblockFreq - Return block frequency. Return 0 if we don't have the
/// information. Please note that initial frequency is equal to ENTRY_FREQ. It
diff --git a/include/llvm/Analysis/CFG.h b/include/llvm/Analysis/CFG.h
index 08fdc26..e5683c8 100644
--- a/include/llvm/Analysis/CFG.h
+++ b/include/llvm/Analysis/CFG.h
@@ -49,6 +49,9 @@ unsigned GetSuccessorNumber(BasicBlock *BB, BasicBlock *Succ);
bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum,
bool AllowIdenticalEdges = false);
+/// \brief Determine whether instruction 'To' is reachable from 'From',
+/// returning true if uncertain.
+///
/// Determine whether there is a path from From to To within a single function.
/// Returns false only if we can prove that once 'From' has been executed then
/// 'To' can not be executed. Conservatively returns true.
@@ -62,7 +65,18 @@ bool isCriticalEdge(const TerminatorInst *TI, unsigned SuccNum,
/// on branchy code but not loops, and LI is most useful on code with loops but
/// does not help on branchy code outside loops.
bool isPotentiallyReachable(const Instruction *From, const Instruction *To,
- DominatorTree *DT = 0, LoopInfo *LI = 0);
+ const DominatorTree *DT = 0,
+ const LoopInfo *LI = 0);
+
+/// \brief Determine whether block 'To' is reachable from 'From', returning
+/// true if uncertain.
+///
+/// Determine whether there is a path from From to To within a single function.
+/// Returns false only if we can prove that once 'From' has been reached then
+/// 'To' can not be executed. Conservatively returns true.
+bool isPotentiallyReachable(const BasicBlock *From, const BasicBlock *To,
+ const DominatorTree *DT = 0,
+ const LoopInfo *LI = 0);
} // End llvm namespace
diff --git a/include/llvm/Analysis/CFGPrinter.h b/include/llvm/Analysis/CFGPrinter.h
index fa596c3..39e90eb 100644
--- a/include/llvm/Analysis/CFGPrinter.h
+++ b/include/llvm/Analysis/CFGPrinter.h
@@ -44,8 +44,9 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
return OS.str();
}
- static std::string getCompleteNodeLabel(const BasicBlock *Node,
+ static std::string getCompleteNodeLabel(const BasicBlock *Node,
const Function *) {
+ enum { MaxColumns = 80 };
std::string Str;
raw_string_ostream OS(Str);
@@ -59,16 +60,32 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
// Process string output to make it nicer...
- for (unsigned i = 0; i != OutStr.length(); ++i)
+ unsigned ColNum = 0;
+ unsigned LastSpace = 0;
+ for (unsigned i = 0; i != OutStr.length(); ++i) {
if (OutStr[i] == '\n') { // Left justify
OutStr[i] = '\\';
OutStr.insert(OutStr.begin()+i+1, 'l');
+ ColNum = 0;
+ LastSpace = 0;
} else if (OutStr[i] == ';') { // Delete comments!
unsigned Idx = OutStr.find('\n', i+1); // Find end of line
OutStr.erase(OutStr.begin()+i, OutStr.begin()+Idx);
--i;
+ } else if (ColNum == MaxColumns) { // Wrap lines.
+ if (LastSpace) {
+ OutStr.insert(LastSpace, "\\l...");
+ ColNum = i - LastSpace;
+ LastSpace = 0;
+ i += 3; // The loop will advance 'i' again.
+ }
+ // Else keep trying to find a space.
}
-
+ else
+ ++ColNum;
+ if (OutStr[i] == ' ')
+ LastSpace = i;
+ }
return OutStr;
}
@@ -86,20 +103,20 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
if (const BranchInst *BI = dyn_cast<BranchInst>(Node->getTerminator()))
if (BI->isConditional())
return (I == succ_begin(Node)) ? "T" : "F";
-
+
// Label source of switch edges with the associated value.
if (const SwitchInst *SI = dyn_cast<SwitchInst>(Node->getTerminator())) {
unsigned SuccNo = I.getSuccessorIndex();
if (SuccNo == 0) return "def";
-
+
std::string Str;
raw_string_ostream OS(Str);
SwitchInst::ConstCaseIt Case =
- SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
+ SwitchInst::ConstCaseIt::fromSuccessorIndex(SI, SuccNo);
OS << Case.getCaseValue()->getValue();
return OS.str();
- }
+ }
return "";
}
};
diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h
index 591484d..d00c2ed 100644
--- a/include/llvm/Analysis/CallGraph.h
+++ b/include/llvm/Analysis/CallGraph.h
@@ -69,13 +69,36 @@ class CallGraphNode;
//===----------------------------------------------------------------------===//
// CallGraph class definition
//
-class CallGraph {
-protected:
+class CallGraph : public ModulePass {
Module *Mod; // The module this call graph represents
typedef std::map<const Function *, CallGraphNode *> FunctionMapTy;
FunctionMapTy FunctionMap; // Map from a function to its node
+ // Root is root of the call graph, or the external node if a 'main' function
+ // couldn't be found.
+ //
+ CallGraphNode *Root;
+
+ // ExternalCallingNode - This node has edges to all external functions and
+ // those internal functions that have their address taken.
+ CallGraphNode *ExternalCallingNode;
+
+ // CallsExternalNode - This node has edges to it from all functions making
+ // indirect calls or calling an external function.
+ CallGraphNode *CallsExternalNode;
+
+ /// Replace the function represented by this node by another.
+ /// This does not rescan the body of the function, so it is suitable when
+ /// splicing the body of one function to another while also updating all
+ /// callers from the old function to the new.
+ ///
+ void spliceFunction(const Function *From, const Function *To);
+
+ // Add a function to the call graph, and link the node to all of the functions
+ // that it calls.
+ void addToCallGraph(Function *F);
+
public:
static char ID; // Class identification, replacement for typeinfo
//===---------------------------------------------------------------------
@@ -107,15 +130,14 @@ public:
}
/// Returns the CallGraphNode which is used to represent undetermined calls
- /// into the callgraph. Override this if you want behavioral inheritance.
- virtual CallGraphNode* getExternalCallingNode() const { return 0; }
- virtual CallGraphNode* getCallsExternalNode() const { return 0; }
+ /// into the callgraph.
+ CallGraphNode *getExternalCallingNode() const { return ExternalCallingNode; }
+ CallGraphNode *getCallsExternalNode() const { return CallsExternalNode; }
/// Return the root/main method in the module, or some other root node, such
- /// as the externalcallingnode. Overload these if you behavioral
- /// inheritance.
- virtual CallGraphNode* getRoot() { return 0; }
- virtual const CallGraphNode* getRoot() const { return 0; }
+ /// as the externalcallingnode.
+ CallGraphNode *getRoot() { return Root; }
+ const CallGraphNode *getRoot() const { return Root; }
//===---------------------------------------------------------------------
// Functions to keep a call graph up to date with a function that has been
@@ -129,41 +151,20 @@ public:
/// do this is to dropAllReferences before calling this.
///
Function *removeFunctionFromModule(CallGraphNode *CGN);
- Function *removeFunctionFromModule(Function *F) {
- return removeFunctionFromModule((*this)[F]);
- }
/// getOrInsertFunction - This method is identical to calling operator[], but
/// it will insert a new CallGraphNode for the specified function if one does
/// not already exist.
CallGraphNode *getOrInsertFunction(const Function *F);
- /// spliceFunction - Replace the function represented by this node by another.
- /// This does not rescan the body of the function, so it is suitable when
- /// splicing the body of one function to another while also updating all
- /// callers from the old function to the new.
- ///
- void spliceFunction(const Function *From, const Function *To);
-
- //===---------------------------------------------------------------------
- // Pass infrastructure interface glue code.
- //
-protected:
- CallGraph() {}
-
-public:
- virtual ~CallGraph() { destroy(); }
-
- /// initialize - Call this method before calling other methods,
- /// re/initializes the state of the CallGraph.
- ///
- void initialize(Module &M);
+ CallGraph();
+ virtual ~CallGraph() { releaseMemory(); }
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const;
+ virtual bool runOnModule(Module &M);
+ virtual void releaseMemory();
- void print(raw_ostream &o, Module *) const;
+ void print(raw_ostream &o, const Module *) const;
void dump() const;
-protected:
- // destroy - Release memory for the call graph
- virtual void destroy();
};
//===----------------------------------------------------------------------===//
diff --git a/include/llvm/Analysis/DependenceAnalysis.h b/include/llvm/Analysis/DependenceAnalysis.h
index 8fce2f6..ea8cecf 100644
--- a/include/llvm/Analysis/DependenceAnalysis.h
+++ b/include/llvm/Analysis/DependenceAnalysis.h
@@ -908,6 +908,10 @@ namespace llvm {
/// based on the current constraint.
void updateDirection(Dependence::DVEntry &Level,
const Constraint &CurConstraint) const;
+
+ bool tryDelinearize(const SCEV *SrcSCEV, const SCEV *DstSCEV,
+ SmallVectorImpl<Subscript> &Pair) const;
+
public:
static char ID; // Class identification, replacement for typeinfo
DependenceAnalysis() : FunctionPass(ID) {
diff --git a/include/llvm/Analysis/Dominators.h b/include/llvm/Analysis/Dominators.h
index 81c04bb..3aa0beb 100644
--- a/include/llvm/Analysis/Dominators.h
+++ b/include/llvm/Analysis/Dominators.h
@@ -346,6 +346,20 @@ public:
DomTreeNodeBase<NodeT> *getRootNode() { return RootNode; }
const DomTreeNodeBase<NodeT> *getRootNode() const { return RootNode; }
+ /// Get all nodes dominated by R, including R itself. Return true on success.
+ void getDescendants(NodeT *R, SmallVectorImpl<NodeT *> &Result) const {
+ const DomTreeNodeBase<NodeT> *RN = getNode(R);
+ SmallVector<const DomTreeNodeBase<NodeT> *, 8> WL;
+ WL.push_back(RN);
+ Result.clear();
+
+ while (!WL.empty()) {
+ const DomTreeNodeBase<NodeT> *N = WL.pop_back_val();
+ Result.push_back(N->getBlock());
+ WL.append(N->begin(), N->end());
+ }
+ }
+
/// properlyDominates - Returns true iff A dominates B and A != B.
/// Note that this is not a constant time operation!
///
@@ -755,6 +769,12 @@ public:
return DT->getRootNode();
}
+ /// Get all nodes dominated by R, including R itself. Return true on success.
+ void getDescendants(BasicBlock *R,
+ SmallVectorImpl<BasicBlock *> &Result) const {
+ DT->getDescendants(R, Result);
+ }
+
/// compare - Return false if the other dominator tree matches this
/// dominator tree. Otherwise return true.
inline bool compare(DominatorTree &Other) const {
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h
index 7b3eed7..62f5aca 100644
--- a/include/llvm/Analysis/LoopInfo.h
+++ b/include/llvm/Analysis/LoopInfo.h
@@ -69,6 +69,8 @@ class LoopBase {
// Blocks - The list of blocks in this loop. First entry is the header node.
std::vector<BlockT*> Blocks;
+ SmallPtrSet<const BlockT*, 8> DenseBlockSet;
+
LoopBase(const LoopBase<BlockT, LoopT> &) LLVM_DELETED_FUNCTION;
const LoopBase<BlockT, LoopT>&
operator=(const LoopBase<BlockT, LoopT> &) LLVM_DELETED_FUNCTION;
@@ -108,7 +110,7 @@ public:
/// contains - Return true if the specified basic block is in this loop.
///
bool contains(const BlockT *BB) const {
- return std::find(block_begin(), block_end(), BB) != block_end();
+ return DenseBlockSet.count(BB);
}
/// contains - Return true if the specified instruction is in this loop.
@@ -134,7 +136,6 @@ public:
/// getBlocks - Get a list of the basic blocks which make up this loop.
///
const std::vector<BlockT*> &getBlocks() const { return Blocks; }
- std::vector<BlockT*> &getBlocksVector() { return Blocks; }
typedef typename std::vector<BlockT*>::const_iterator block_iterator;
block_iterator block_begin() const { return Blocks.begin(); }
block_iterator block_end() const { return Blocks.end(); }
@@ -271,6 +272,17 @@ public:
/// transformations should use addBasicBlockToLoop.
void addBlockEntry(BlockT *BB) {
Blocks.push_back(BB);
+ DenseBlockSet.insert(BB);
+ }
+
+ /// reverseBlocks - interface to reverse Blocks[from, end of loop] in this loop
+ void reverseBlock(unsigned from) {
+ std::reverse(Blocks.begin() + from, Blocks.end());
+ }
+
+ /// reserveBlocks- interface to do reserve() for Blocks
+ void reserveBlocks(unsigned size) {
+ Blocks.reserve(size);
}
/// moveToHeader - This method is used to move BB (which must be part of this
@@ -293,6 +305,7 @@ public:
/// the mapping in the LoopInfo class.
void removeBlockFromLoop(BlockT *BB) {
RemoveFromVector(Blocks, BB);
+ DenseBlockSet.erase(BB);
}
/// verifyLoop - Verify loop structure
@@ -307,6 +320,7 @@ protected:
friend class LoopInfoBase<BlockT, LoopT>;
explicit LoopBase(BlockT *BB) : ParentLoop(0) {
Blocks.push_back(BB);
+ DenseBlockSet.insert(BB);
}
};
diff --git a/include/llvm/Analysis/LoopInfoImpl.h b/include/llvm/Analysis/LoopInfoImpl.h
index 5485f3c..c98cb58 100644
--- a/include/llvm/Analysis/LoopInfoImpl.h
+++ b/include/llvm/Analysis/LoopInfoImpl.h
@@ -31,17 +31,12 @@ namespace llvm {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitingBlocks(SmallVectorImpl<BlockT *> &ExitingBlocks) const {
- // Sort the blocks vector so that we can use binary search to do quick
- // lookups.
- SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
- std::sort(LoopBBs.begin(), LoopBBs.end());
-
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 (!std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I)) {
+ if (!contains(*I)) {
// Not in current loop? It must be an exit block.
ExitingBlocks.push_back(*BI);
break;
@@ -65,17 +60,12 @@ BlockT *LoopBase<BlockT, LoopT>::getExitingBlock() const {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitBlocks(SmallVectorImpl<BlockT*> &ExitBlocks) const {
- // Sort the blocks vector so that we can use binary search to do quick
- // lookups.
- SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
- std::sort(LoopBBs.begin(), LoopBBs.end());
-
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 (!std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I))
+ if (!contains(*I))
// Not in current loop? It must be an exit block.
ExitBlocks.push_back(*I);
}
@@ -95,17 +85,12 @@ BlockT *LoopBase<BlockT, LoopT>::getExitBlock() const {
template<class BlockT, class LoopT>
void LoopBase<BlockT, LoopT>::
getExitEdges(SmallVectorImpl<Edge> &ExitEdges) const {
- // Sort the blocks vector so that we can use binary search to do quick
- // lookups.
- SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
- array_pod_sort(LoopBBs.begin(), LoopBBs.end());
-
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 (!std::binary_search(LoopBBs.begin(), LoopBBs.end(), *I))
+ if (!contains(*I))
// Not in current loop? It must be an exit block.
ExitEdges.push_back(Edge(*BI, *I));
}
@@ -210,7 +195,7 @@ addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase<BlockT, LoopT> &LIB) {
// Add the basic block to this loop and all parent loops...
while (L) {
- L->Blocks.push_back(NewBB);
+ L->addBlockEntry(NewBB);
L = L->getParentLoop();
}
}
@@ -250,11 +235,6 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
// Keep track of the number of BBs visited.
unsigned NumVisited = 0;
- // Sort the blocks vector so that we can use binary search to do quick
- // lookups.
- SmallVector<BlockT*, 128> LoopBBs(block_begin(), block_end());
- std::sort(LoopBBs.begin(), LoopBBs.end());
-
// Check the individual blocks.
for ( ; BI != BE; ++BI) {
BlockT *BB = *BI;
@@ -266,7 +246,7 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
for (typename BlockTraits::ChildIteratorType SI =
BlockTraits::child_begin(BB), SE = BlockTraits::child_end(BB);
SI != SE; ++SI)
- if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), *SI)) {
+ if (contains(*SI)) {
HasInsideLoopSuccs = true;
break;
}
@@ -275,7 +255,7 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
InvBlockTraits::child_begin(BB), PE = InvBlockTraits::child_end(BB);
PI != PE; ++PI) {
BlockT *N = *PI;
- if (std::binary_search(LoopBBs.begin(), LoopBBs.end(), N))
+ if (contains(N))
HasInsideLoopPreds = true;
else
OutsideLoopPreds.push_back(N);
@@ -309,7 +289,7 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const {
// Each block in each subloop should be contained within this loop.
for (block_iterator BI = (*I)->block_begin(), BE = (*I)->block_end();
BI != BE; ++BI) {
- assert(std::binary_search(LoopBBs.begin(), LoopBBs.end(), *BI) &&
+ assert(contains(*BI) &&
"Loop does not contain all the blocks of a subloop!");
}
@@ -418,7 +398,7 @@ static void discoverAndMapSubloop(LoopT *L, ArrayRef<BlockT*> Backedges,
}
}
L->getSubLoopsVector().reserve(NumSubloops);
- L->getBlocksVector().reserve(NumBlocks);
+ L->reserveBlocks(NumBlocks);
}
namespace {
@@ -489,15 +469,14 @@ void PopulateLoopsDFS<BlockT, LoopT>::insertIntoLoop(BlockT *Block) {
// For convenience, Blocks and Subloops are inserted in postorder. Reverse
// the lists, except for the loop header, which is always at the beginning.
- std::reverse(Subloop->getBlocksVector().begin()+1,
- Subloop->getBlocksVector().end());
+ Subloop->reverseBlock(1);
std::reverse(Subloop->getSubLoopsVector().begin(),
Subloop->getSubLoopsVector().end());
Subloop = Subloop->getParentLoop();
}
for (; Subloop; Subloop = Subloop->getParentLoop())
- Subloop->getBlocksVector().push_back(Block);
+ Subloop->addBlockEntry(Block);
}
/// Analyze LoopInfo discovers loops during a postorder DominatorTree traversal
diff --git a/include/llvm/Analysis/LoopPass.h b/include/llvm/Analysis/LoopPass.h
index 5767c19..5926610 100644
--- a/include/llvm/Analysis/LoopPass.h
+++ b/include/llvm/Analysis/LoopPass.h
@@ -16,8 +16,8 @@
#define LLVM_ANALYSIS_LOOPPASS_H
#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/IR/LegacyPassManagers.h"
#include "llvm/Pass.h"
-#include "llvm/PassManagers.h"
#include <deque>
namespace llvm {
diff --git a/include/llvm/Analysis/MemoryBuiltins.h b/include/llvm/Analysis/MemoryBuiltins.h
index 0d1ae8c..91224ad 100644
--- a/include/llvm/Analysis/MemoryBuiltins.h
+++ b/include/llvm/Analysis/MemoryBuiltins.h
@@ -64,6 +64,10 @@ bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI,
bool isReallocLikeFn(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 and never returns null (such as operator new).
+bool isOperatorNewLikeFn(const Value *V, const TargetLibraryInfo *TLI,
+ bool LookThroughBitCast = false);
//===----------------------------------------------------------------------===//
// malloc Call Utility Functions.
@@ -81,7 +85,7 @@ static inline CallInst *extractMallocCall(Value *I,
/// isArrayMalloc - Returns the corresponding CallInst if the instruction
/// is a call to malloc whose array size can be determined and the array size
/// is not constant 1. Otherwise, return NULL.
-const CallInst *isArrayMalloc(const Value *I, const DataLayout *TD,
+const CallInst *isArrayMalloc(const Value *I, const DataLayout *DL,
const TargetLibraryInfo *TLI);
/// getMallocType - Returns the PointerType resulting from the malloc call.
@@ -103,7 +107,7 @@ Type *getMallocAllocatedType(const CallInst *CI, const TargetLibraryInfo *TLI);
/// then return that multiple. For non-array mallocs, the multiple is
/// constant 1. Otherwise, return NULL for mallocs whose array size cannot be
/// determined.
-Value *getMallocArraySize(CallInst *CI, const DataLayout *TD,
+Value *getMallocArraySize(CallInst *CI, const DataLayout *DL,
const TargetLibraryInfo *TLI,
bool LookThroughSExt = false);
@@ -143,7 +147,7 @@ static inline CallInst *isFreeCall(Value *I, const TargetLibraryInfo *TLI) {
/// underlying object pointed to by Ptr.
/// If RoundToAlign is true, then Size is rounded up to the aligment of allocas,
/// byval arguments, and global variables.
-bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout *TD,
+bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout *DL,
const TargetLibraryInfo *TLI, bool RoundToAlign = false);
@@ -155,7 +159,7 @@ typedef std::pair<APInt, APInt> SizeOffsetType;
class ObjectSizeOffsetVisitor
: public InstVisitor<ObjectSizeOffsetVisitor, SizeOffsetType> {
- const DataLayout *TD;
+ const DataLayout *DL;
const TargetLibraryInfo *TLI;
bool RoundToAlign;
unsigned IntTyBits;
@@ -169,7 +173,7 @@ class ObjectSizeOffsetVisitor
}
public:
- ObjectSizeOffsetVisitor(const DataLayout *TD, const TargetLibraryInfo *TLI,
+ ObjectSizeOffsetVisitor(const DataLayout *DL, const TargetLibraryInfo *TLI,
LLVMContext &Context, bool RoundToAlign = false);
SizeOffsetType compute(Value *V);
@@ -216,7 +220,7 @@ class ObjectSizeOffsetEvaluator
typedef DenseMap<const Value*, WeakEvalType> CacheMapTy;
typedef SmallPtrSet<const Value*, 8> PtrSetTy;
- const DataLayout *TD;
+ const DataLayout *DL;
const TargetLibraryInfo *TLI;
LLVMContext &Context;
BuilderTy Builder;
@@ -224,6 +228,7 @@ class ObjectSizeOffsetEvaluator
Value *Zero;
CacheMapTy CacheMap;
PtrSetTy SeenVals;
+ bool RoundToAlign;
SizeOffsetEvalType unknown() {
return std::make_pair((Value*)0, (Value*)0);
@@ -231,8 +236,8 @@ class ObjectSizeOffsetEvaluator
SizeOffsetEvalType compute_(Value *V);
public:
- ObjectSizeOffsetEvaluator(const DataLayout *TD, const TargetLibraryInfo *TLI,
- LLVMContext &Context);
+ ObjectSizeOffsetEvaluator(const DataLayout *DL, const TargetLibraryInfo *TLI,
+ LLVMContext &Context, bool RoundToAlign = false);
SizeOffsetEvalType compute(Value *V);
bool knownSize(SizeOffsetEvalType SizeOffset) {
diff --git a/include/llvm/Analysis/Passes.h b/include/llvm/Analysis/Passes.h
index ae11713..a5d098e 100644
--- a/include/llvm/Analysis/Passes.h
+++ b/include/llvm/Analysis/Passes.h
@@ -95,64 +95,6 @@ namespace llvm {
//===--------------------------------------------------------------------===//
//
- // createProfileLoaderPass - This pass loads information from a profile dump
- // file.
- //
- ModulePass *createProfileLoaderPass();
- extern char &ProfileLoaderPassID;
-
- //===--------------------------------------------------------------------===//
- //
- // createProfileMetadataLoaderPass - This pass loads information from a
- // profile dump file and sets branch weight metadata.
- //
- ModulePass *createProfileMetadataLoaderPass();
- extern char &ProfileMetadataLoaderPassID;
-
- //===--------------------------------------------------------------------===//
- //
- // createNoProfileInfoPass - This pass implements the default "no profile".
- //
- ImmutablePass *createNoProfileInfoPass();
-
- //===--------------------------------------------------------------------===//
- //
- // createProfileEstimatorPass - This pass estimates profiling information
- // instead of loading it from a previous run.
- //
- FunctionPass *createProfileEstimatorPass();
- extern char &ProfileEstimatorPassID;
-
- //===--------------------------------------------------------------------===//
- //
- // createProfileVerifierPass - This pass verifies profiling information.
- //
- FunctionPass *createProfileVerifierPass();
-
- //===--------------------------------------------------------------------===//
- //
- // createPathProfileLoaderPass - This pass loads information from a path
- // profile dump file.
- //
- ModulePass *createPathProfileLoaderPass();
- extern char &PathProfileLoaderPassID;
-
- //===--------------------------------------------------------------------===//
- //
- // createNoPathProfileInfoPass - This pass implements the default
- // "no path profile".
- //
- ImmutablePass *createNoPathProfileInfoPass();
-
- //===--------------------------------------------------------------------===//
- //
- // createPathProfileVerifierPass - This pass verifies path profiling
- // information.
- //
- ModulePass *createPathProfileVerifierPass();
-
- //===--------------------------------------------------------------------===//
- //
// createDSAAPass - This pass implements simple context sensitive alias
// analysis.
//
@@ -194,6 +136,13 @@ namespace llvm {
//===--------------------------------------------------------------------===//
//
+ // createDelinearizationPass - This pass implements attempts to restore
+ // multidimensional array indices from linearized expressions.
+ //
+ FunctionPass *createDelinearizationPass();
+
+ //===--------------------------------------------------------------------===//
+ //
// Minor pass prototypes, allowing us to expose them through bugpoint and
// analyze.
FunctionPass *createInstCountPass();
diff --git a/include/llvm/Analysis/PathNumbering.h b/include/llvm/Analysis/PathNumbering.h
deleted file mode 100644
index 400a37d..0000000
--- a/include/llvm/Analysis/PathNumbering.h
+++ /dev/null
@@ -1,304 +0,0 @@
-//===- PathNumbering.h ----------------------------------------*- C++ -*---===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Ball-Larus path numbers uniquely identify paths through a directed acyclic
-// graph (DAG) [Ball96]. For a CFG backedges are removed and replaced by phony
-// edges to obtain a DAG, and thus the unique path numbers [Ball96].
-//
-// The purpose of this analysis is to enumerate the edges in a CFG in order
-// to obtain paths from path numbers in a convenient manner. As described in
-// [Ball96] edges can be enumerated such that given a path number by following
-// the CFG and updating the path number, the path is obtained.
-//
-// [Ball96]
-// T. Ball and J. R. Larus. "Efficient Path Profiling."
-// International Symposium on Microarchitecture, pages 46-57, 1996.
-// http://portal.acm.org/citation.cfm?id=243857
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_PATHNUMBERING_H
-#define LLVM_ANALYSIS_PATHNUMBERING_H
-
-#include "llvm/Analysis/ProfileInfoTypes.h"
-#include "llvm/IR/BasicBlock.h"
-#include "llvm/IR/Instructions.h"
-#include "llvm/Pass.h"
-#include "llvm/Support/CFG.h"
-#include <map>
-#include <stack>
-#include <vector>
-
-namespace llvm {
-class BallLarusNode;
-class BallLarusEdge;
-class BallLarusDag;
-
-// typedefs for storage/ interators of various DAG components
-typedef std::vector<BallLarusNode*> BLNodeVector;
-typedef std::vector<BallLarusNode*>::iterator BLNodeIterator;
-typedef std::vector<BallLarusEdge*> BLEdgeVector;
-typedef std::vector<BallLarusEdge*>::iterator BLEdgeIterator;
-typedef std::map<BasicBlock*, BallLarusNode*> BLBlockNodeMap;
-typedef std::stack<BallLarusNode*> BLNodeStack;
-
-// Represents a basic block with information necessary for the BallLarus
-// algorithms.
-class BallLarusNode {
-public:
- enum NodeColor { WHITE, GRAY, BLACK };
-
- // Constructor: Initializes a new Node for the given BasicBlock
- BallLarusNode(BasicBlock* BB) :
- _basicBlock(BB), _numberPaths(0), _color(WHITE) {
- static unsigned nextUID = 0;
- _uid = nextUID++;
- }
-
- // Returns the basic block for the BallLarusNode
- BasicBlock* getBlock();
-
- // Get/set the number of paths to the exit starting at the node.
- unsigned getNumberPaths();
- void setNumberPaths(unsigned numberPaths);
-
- // Get/set the NodeColor used in graph algorithms.
- NodeColor getColor();
- void setColor(NodeColor color);
-
- // Iterator information for predecessor edges. Includes phony and
- // backedges.
- BLEdgeIterator predBegin();
- BLEdgeIterator predEnd();
- unsigned getNumberPredEdges();
-
- // Iterator information for successor edges. Includes phony and
- // backedges.
- BLEdgeIterator succBegin();
- BLEdgeIterator succEnd();
- unsigned getNumberSuccEdges();
-
- // Add an edge to the predecessor list.
- void addPredEdge(BallLarusEdge* edge);
-
- // Remove an edge from the predecessor list.
- void removePredEdge(BallLarusEdge* edge);
-
- // Add an edge to the successor list.
- void addSuccEdge(BallLarusEdge* edge);
-
- // Remove an edge from the successor list.
- void removeSuccEdge(BallLarusEdge* edge);
-
- // Returns the name of the BasicBlock being represented. If BasicBlock
- // is null then returns "<null>". If BasicBlock has no name, then
- // "<unnamed>" is returned. Intended for use with debug output.
- std::string getName();
-
-private:
- // The corresponding underlying BB.
- BasicBlock* _basicBlock;
-
- // Holds the predecessor edges of this node.
- BLEdgeVector _predEdges;
-
- // Holds the successor edges of this node.
- BLEdgeVector _succEdges;
-
- // The number of paths from the node to the exit.
- unsigned _numberPaths;
-
- // 'Color' used by graph algorithms to mark the node.
- NodeColor _color;
-
- // Unique ID to ensure naming difference with dotgraphs
- unsigned _uid;
-
- // Removes an edge from an edgeVector. Used by removePredEdge and
- // removeSuccEdge.
- void removeEdge(BLEdgeVector& v, BallLarusEdge* e);
-};
-
-// Represents an edge in the Dag. For an edge, v -> w, v is the source, and
-// w is the target.
-class BallLarusEdge {
-public:
- enum EdgeType { NORMAL, BACKEDGE, SPLITEDGE,
- BACKEDGE_PHONY, SPLITEDGE_PHONY, CALLEDGE_PHONY };
-
- // Constructor: Initializes an BallLarusEdge with a source and target.
- BallLarusEdge(BallLarusNode* source, BallLarusNode* target,
- unsigned duplicateNumber)
- : _source(source), _target(target), _weight(0), _edgeType(NORMAL),
- _realEdge(NULL), _duplicateNumber(duplicateNumber) {}
-
- // Returns the source/ target node of this edge.
- BallLarusNode* getSource() const;
- BallLarusNode* getTarget() const;
-
- // Sets the type of the edge.
- EdgeType getType() const;
-
- // Gets the type of the edge.
- void setType(EdgeType type);
-
- // Returns the weight of this edge. Used to decode path numbers to
- // sequences of basic blocks.
- unsigned getWeight();
-
- // Sets the weight of the edge. Used during path numbering.
- void setWeight(unsigned weight);
-
- // Gets/sets the phony edge originating at the root.
- BallLarusEdge* getPhonyRoot();
- void setPhonyRoot(BallLarusEdge* phonyRoot);
-
- // Gets/sets the phony edge terminating at the exit.
- BallLarusEdge* getPhonyExit();
- void setPhonyExit(BallLarusEdge* phonyExit);
-
- // Gets/sets the associated real edge if this is a phony edge.
- BallLarusEdge* getRealEdge();
- void setRealEdge(BallLarusEdge* realEdge);
-
- // Returns the duplicate number of the edge.
- unsigned getDuplicateNumber();
-
-protected:
- // Source node for this edge.
- BallLarusNode* _source;
-
- // Target node for this edge.
- BallLarusNode* _target;
-
-private:
- // Edge weight cooresponding to path number increments before removing
- // increments along a spanning tree. The sum over the edge weights gives
- // the path number.
- unsigned _weight;
-
- // Type to represent for what this edge is intended
- EdgeType _edgeType;
-
- // For backedges and split-edges, the phony edge which is linked to the
- // root node of the DAG. This contains a path number initialization.
- BallLarusEdge* _phonyRoot;
-
- // For backedges and split-edges, the phony edge which is linked to the
- // exit node of the DAG. This contains a path counter increment, and
- // potentially a path number increment.
- BallLarusEdge* _phonyExit;
-
- // If this is a phony edge, _realEdge is a link to the back or split
- // edge. Otherwise, this is null.
- BallLarusEdge* _realEdge;
-
- // An ID to differentiate between those edges which have the same source
- // and destination blocks.
- unsigned _duplicateNumber;
-};
-
-// Represents the Ball Larus DAG for a given Function. Can calculate
-// various properties required for instrumentation or analysis. E.g. the
-// edge weights that determine the path number.
-class BallLarusDag {
-public:
- // Initializes a BallLarusDag from the CFG of a given function. Must
- // call init() after creation, since some initialization requires
- // virtual functions.
- BallLarusDag(Function &F)
- : _root(NULL), _exit(NULL), _function(F) {}
-
- // Initialization that requires virtual functions which are not fully
- // functional in the constructor.
- void init();
-
- // Frees all memory associated with the DAG.
- virtual ~BallLarusDag();
-
- // Calculate the path numbers by assigning edge increments as prescribed
- // in Ball-Larus path profiling.
- void calculatePathNumbers();
-
- // Returns the number of paths for the DAG.
- unsigned getNumberOfPaths();
-
- // Returns the root (i.e. entry) node for the DAG.
- BallLarusNode* getRoot();
-
- // Returns the exit node for the DAG.
- BallLarusNode* getExit();
-
- // Returns the function for the DAG.
- Function& getFunction();
-
- // Clears the node colors.
- void clearColors(BallLarusNode::NodeColor color);
-
-protected:
- // All nodes in the DAG.
- BLNodeVector _nodes;
-
- // All edges in the DAG.
- BLEdgeVector _edges;
-
- // All backedges in the DAG.
- BLEdgeVector _backEdges;
-
- // Allows subclasses to determine which type of Node is created.
- // Override this method to produce subclasses of BallLarusNode if
- // necessary. The destructor of BallLarusDag will call free on each pointer
- // created.
- virtual BallLarusNode* createNode(BasicBlock* BB);
-
- // Allows subclasses to determine which type of Edge is created.
- // Override this method to produce subclasses of BallLarusEdge if
- // necessary. Parameters source and target will have been created by
- // createNode and can be cast to the subclass of BallLarusNode*
- // returned by createNode. The destructor of BallLarusDag will call free
- // on each pointer created.
- virtual BallLarusEdge* createEdge(BallLarusNode* source, BallLarusNode*
- target, unsigned duplicateNumber);
-
- // Proxy to node's constructor. Updates the DAG state.
- BallLarusNode* addNode(BasicBlock* BB);
-
- // Proxy to edge's constructor. Updates the DAG state.
- BallLarusEdge* addEdge(BallLarusNode* source, BallLarusNode* target,
- unsigned duplicateNumber);
-
-private:
- // The root (i.e. entry) node for this DAG.
- BallLarusNode* _root;
-
- // The exit node for this DAG.
- BallLarusNode* _exit;
-
- // The function represented by this DAG.
- Function& _function;
-
- // Processes one node and its imediate edges for building the DAG.
- void buildNode(BLBlockNodeMap& inDag, std::stack<BallLarusNode*>& dfsStack);
-
- // Process an edge in the CFG for DAG building.
- void buildEdge(BLBlockNodeMap& inDag, std::stack<BallLarusNode*>& dfsStack,
- BallLarusNode* currentNode, BasicBlock* succBB,
- unsigned duplicateNumber);
-
- // The weight on each edge is the increment required along any path that
- // contains that edge.
- void calculatePathNumbersFrom(BallLarusNode* node);
-
- // Adds a backedge with its phony edges. Updates the DAG state.
- void addBackedge(BallLarusNode* source, BallLarusNode* target,
- unsigned duplicateCount);
-};
-} // end namespace llvm
-
-#endif
diff --git a/include/llvm/Analysis/PathProfileInfo.h b/include/llvm/Analysis/PathProfileInfo.h
deleted file mode 100644
index 4fce16e..0000000
--- a/include/llvm/Analysis/PathProfileInfo.h
+++ /dev/null
@@ -1,112 +0,0 @@
-//===- PathProfileInfo.h --------------------------------------*- C++ -*---===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file outlines the interface used by optimizers to load path profiles.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_PATHPROFILEINFO_H
-#define LLVM_ANALYSIS_PATHPROFILEINFO_H
-
-#include "llvm/Analysis/PathNumbering.h"
-#include "llvm/IR/BasicBlock.h"
-
-namespace llvm {
-
-class ProfilePath;
-class ProfilePathEdge;
-class PathProfileInfo;
-
-typedef std::vector<ProfilePathEdge> ProfilePathEdgeVector;
-typedef std::vector<ProfilePathEdge>::iterator ProfilePathEdgeIterator;
-
-typedef std::vector<BasicBlock*> ProfilePathBlockVector;
-typedef std::vector<BasicBlock*>::iterator ProfilePathBlockIterator;
-
-typedef std::map<unsigned int,ProfilePath*> ProfilePathMap;
-typedef std::map<unsigned int,ProfilePath*>::iterator ProfilePathIterator;
-
-typedef std::map<Function*,unsigned int> FunctionPathCountMap;
-typedef std::map<Function*,ProfilePathMap> FunctionPathMap;
-typedef std::map<Function*,ProfilePathMap>::iterator FunctionPathIterator;
-
-class ProfilePathEdge {
-public:
- ProfilePathEdge(BasicBlock* source, BasicBlock* target,
- unsigned duplicateNumber);
-
- inline unsigned getDuplicateNumber() { return _duplicateNumber; }
- inline BasicBlock* getSource() { return _source; }
- inline BasicBlock* getTarget() { return _target; }
-
-protected:
- BasicBlock* _source;
- BasicBlock* _target;
- unsigned _duplicateNumber;
-};
-
-class ProfilePath {
-public:
- ProfilePath(unsigned int number, unsigned int count,
- double countStdDev, PathProfileInfo* ppi);
-
- double getFrequency() const;
-
- inline unsigned int getNumber() const { return _number; }
- inline unsigned int getCount() const { return _count; }
- inline double getCountStdDev() const { return _countStdDev; }
-
- ProfilePathEdgeVector* getPathEdges() const;
- ProfilePathBlockVector* getPathBlocks() const;
-
- BasicBlock* getFirstBlockInPath() const;
-
-private:
- unsigned int _number;
- unsigned int _count;
- double _countStdDev;
-
- // double pointer back to the profiling info
- PathProfileInfo* _ppi;
-};
-
-// TODO: overload [] operator for getting path
-// Add: getFunctionCallCount()
-class PathProfileInfo {
- public:
- PathProfileInfo();
- ~PathProfileInfo();
-
- void setCurrentFunction(Function* F);
- Function* getCurrentFunction() const;
- BasicBlock* getCurrentFunctionEntry();
-
- ProfilePath* getPath(unsigned int number);
- unsigned int getPotentialPathCount();
-
- ProfilePathIterator pathBegin();
- ProfilePathIterator pathEnd();
- unsigned int pathsRun();
-
- static char ID; // Pass identification
- std::string argList;
-
-protected:
- FunctionPathMap _functionPaths;
- FunctionPathCountMap _functionPathCounts;
-
-private:
- BallLarusDag* _currentDag;
- Function* _currentFunction;
-
- friend class ProfilePath;
-};
-} // end namespace llvm
-
-#endif
diff --git a/include/llvm/Analysis/ProfileDataLoader.h b/include/llvm/Analysis/ProfileDataLoader.h
deleted file mode 100644
index 90097f7..0000000
--- a/include/llvm/Analysis/ProfileDataLoader.h
+++ /dev/null
@@ -1,140 +0,0 @@
-//===- ProfileDataLoader.h - Load & convert profile info ----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// The ProfileDataLoader class is used to load profiling data from a dump file.
-// The ProfileDataT<FType, BType> class is used to store the mapping of this
-// data to control flow edges.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_PROFILEDATALOADER_H
-#define LLVM_ANALYSIS_PROFILEDATALOADER_H
-
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ErrorHandling.h"
-#include <string>
-
-namespace llvm {
-
-class ModulePass;
-class Function;
-class BasicBlock;
-
-// Helper for dumping edges to dbgs().
-raw_ostream& operator<<(raw_ostream &O, std::pair<const BasicBlock *,
- const BasicBlock *> E);
-
-/// \brief The ProfileDataT<FType, BType> class is used to store the mapping of
-/// profiling data to control flow edges.
-///
-/// An edge is defined by its source and sink basic blocks.
-template<class FType, class BType>
-class ProfileDataT {
-public:
- // The profiling information defines an Edge by its source and sink basic
- // blocks.
- typedef std::pair<const BType*, const BType*> Edge;
-
-private:
- typedef DenseMap<Edge, unsigned> EdgeWeights;
-
- /// \brief Count the number of times a transition between two blocks is
- /// executed.
- ///
- /// As a special case, we also hold an edge from the null BasicBlock to the
- /// entry block to indicate how many times the function was entered.
- DenseMap<const FType*, EdgeWeights> EdgeInformation;
-
-public:
- /// getFunction() - Returns the Function for an Edge.
- static const FType *getFunction(Edge e) {
- // e.first may be NULL
- assert(((!e.first) || (e.first->getParent() == e.second->getParent()))
- && "A ProfileData::Edge can not be between two functions");
- assert(e.second && "A ProfileData::Edge must have a real sink");
- return e.second->getParent();
- }
-
- /// getEdge() - Creates an Edge between two BasicBlocks.
- static Edge getEdge(const BType *Src, const BType *Dest) {
- return Edge(Src, Dest);
- }
-
- /// getEdgeWeight - Return the number of times that a given edge was
- /// executed.
- unsigned getEdgeWeight(Edge e) const {
- const FType *f = getFunction(e);
- assert((EdgeInformation.find(f) != EdgeInformation.end())
- && "No profiling information for function");
- EdgeWeights weights = EdgeInformation.find(f)->second;
-
- assert((weights.find(e) != weights.end())
- && "No profiling information for edge");
- return weights.find(e)->second;
- }
-
- /// addEdgeWeight - Add 'weight' to the already stored execution count for
- /// this edge.
- void addEdgeWeight(Edge e, unsigned weight) {
- EdgeInformation[getFunction(e)][e] += weight;
- }
-};
-
-typedef ProfileDataT<Function, BasicBlock> ProfileData;
-//typedef ProfileDataT<MachineFunction, MachineBasicBlock> MachineProfileData;
-
-/// The ProfileDataLoader class is used to load raw profiling data from the
-/// dump file.
-class ProfileDataLoader {
-private:
- /// The name of the file where the raw profiling data is stored.
- const std::string &Filename;
-
- /// A vector of the command line arguments used when the target program was
- /// run to generate profiling data. One entry per program run.
- SmallVector<std::string, 1> CommandLines;
-
- /// The raw values for how many times each edge was traversed, values from
- /// multiple program runs are accumulated.
- SmallVector<unsigned, 32> EdgeCounts;
-
-public:
- /// ProfileDataLoader ctor - Read the specified profiling data file, exiting
- /// the program if the file is invalid or broken.
- ProfileDataLoader(const char *ToolName, const std::string &Filename);
-
- /// A special value used to represent the weight of an edge which has not
- /// been counted yet.
- static const unsigned Uncounted;
-
- /// getNumExecutions - Return the number of times the target program was run
- /// to generate this profiling data.
- unsigned getNumExecutions() const { return CommandLines.size(); }
-
- /// getExecution - Return the command line parameters used to generate the
- /// i'th set of profiling data.
- const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
-
- const std::string &getFileName() const { return Filename; }
-
- /// getRawEdgeCounts - Return the raw profiling data, this is just a list of
- /// numbers with no mappings to edges.
- ArrayRef<unsigned> getRawEdgeCounts() const { return EdgeCounts; }
-};
-
-/// createProfileMetadataLoaderPass - This function returns a Pass that loads
-/// the profiling information for the module from the specified filename.
-ModulePass *createProfileMetadataLoaderPass(const std::string &Filename);
-
-} // End llvm namespace
-
-#endif
diff --git a/include/llvm/Analysis/ProfileDataTypes.h b/include/llvm/Analysis/ProfileDataTypes.h
deleted file mode 100644
index 1be15e0..0000000
--- a/include/llvm/Analysis/ProfileDataTypes.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*===-- ProfileDataTypes.h - Profiling info shared constants --------------===*\
-|*
-|* The LLVM Compiler Infrastructure
-|*
-|* This file is distributed under the University of Illinois Open Source
-|* License. See LICENSE.TXT for details.
-|*
-|*===----------------------------------------------------------------------===*|
-|*
-|* This file defines constants shared by the various different profiling
-|* runtime libraries and the LLVM C++ profile metadata loader. It must be a
-|* C header because, at present, the profiling runtimes are written in C.
-|*
-\*===----------------------------------------------------------------------===*/
-
-#ifndef LLVM_ANALYSIS_PROFILEDATATYPES_H
-#define LLVM_ANALYSIS_PROFILEDATATYPES_H
-
-/* Included by libprofile. */
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* TODO: Strip out unused entries once ProfileInfo etc has been removed. */
-enum ProfilingType {
- ArgumentInfo = 1, /* The command line argument block */
- FunctionInfo = 2, /* Function profiling information */
- BlockInfo = 3, /* Block profiling information */
- EdgeInfo = 4, /* Edge profiling information */
- PathInfo = 5, /* Path profiling information */
- BBTraceInfo = 6, /* Basic block trace information */
- OptEdgeInfo = 7 /* Edge profiling information, optimal version */
-};
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* LLVM_ANALYSIS_PROFILEDATATYPES_H */
diff --git a/include/llvm/Analysis/ProfileInfo.h b/include/llvm/Analysis/ProfileInfo.h
deleted file mode 100644
index 5d17fa1..0000000
--- a/include/llvm/Analysis/ProfileInfo.h
+++ /dev/null
@@ -1,247 +0,0 @@
-//===- llvm/Analysis/ProfileInfo.h - Profile Info Interface -----*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the generic ProfileInfo interface, which is used as the
-// common interface used by all clients of profiling information, and
-// implemented either by making static guestimations, or by actually reading in
-// profiling information gathered by running the program.
-//
-// Note that to be useful, all profile-based optimizations should preserve
-// ProfileInfo, which requires that they notify it when changes to the CFG are
-// made. (This is not implemented yet.)
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_PROFILEINFO_H
-#define LLVM_ANALYSIS_PROFILEINFO_H
-
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/raw_ostream.h"
-#include <cassert>
-#include <map>
-#include <set>
-#include <string>
-
-namespace llvm {
- class Pass;
- class raw_ostream;
-
- class BasicBlock;
- class Function;
- class MachineBasicBlock;
- class MachineFunction;
-
- // Helper for dumping edges to dbgs().
- raw_ostream& operator<<(raw_ostream &O, std::pair<const BasicBlock *, const BasicBlock *> E);
- raw_ostream& operator<<(raw_ostream &O, std::pair<const MachineBasicBlock *, const MachineBasicBlock *> E);
-
- raw_ostream& operator<<(raw_ostream &O, const BasicBlock *BB);
- raw_ostream& operator<<(raw_ostream &O, const MachineBasicBlock *MBB);
-
- raw_ostream& operator<<(raw_ostream &O, const Function *F);
- raw_ostream& operator<<(raw_ostream &O, const MachineFunction *MF);
-
- /// ProfileInfo Class - This class holds and maintains profiling
- /// information for some unit of code.
- template<class FType, class BType>
- class ProfileInfoT {
- public:
- // Types for handling profiling information.
- typedef std::pair<const BType*, const BType*> Edge;
- typedef std::pair<Edge, double> EdgeWeight;
- typedef std::map<Edge, double> EdgeWeights;
- typedef std::map<const BType*, double> BlockCounts;
- typedef std::map<const BType*, const BType*> Path;
-
- protected:
- // EdgeInformation - Count the number of times a transition between two
- // blocks is executed. As a special case, we also hold an edge from the
- // null BasicBlock to the entry block to indicate how many times the
- // function was entered.
- std::map<const FType*, EdgeWeights> EdgeInformation;
-
- // BlockInformation - Count the number of times a block is executed.
- std::map<const FType*, BlockCounts> BlockInformation;
-
- // FunctionInformation - Count the number of times a function is executed.
- std::map<const FType*, double> FunctionInformation;
-
- ProfileInfoT<MachineFunction, MachineBasicBlock> *MachineProfile;
- public:
- static char ID; // Class identification, replacement for typeinfo
- ProfileInfoT();
- ~ProfileInfoT(); // We want to be subclassed
-
- // MissingValue - The value that is returned for execution counts in case
- // no value is available.
- static const double MissingValue;
-
- // getFunction() - Returns the Function for an Edge, checking for validity.
- static const FType* getFunction(Edge e) {
- if (e.first)
- return e.first->getParent();
- if (e.second)
- return e.second->getParent();
- llvm_unreachable("Invalid ProfileInfo::Edge");
- }
-
- // getEdge() - Creates an Edge from two BasicBlocks.
- static Edge getEdge(const BType *Src, const BType *Dest) {
- return std::make_pair(Src, Dest);
- }
-
- //===------------------------------------------------------------------===//
- /// Profile Information Queries
- ///
- double getExecutionCount(const FType *F);
-
- double getExecutionCount(const BType *BB);
-
- void setExecutionCount(const BType *BB, double w);
-
- void addExecutionCount(const BType *BB, double w);
-
- double getEdgeWeight(Edge e) const {
- typename std::map<const FType*, EdgeWeights>::const_iterator J =
- EdgeInformation.find(getFunction(e));
- if (J == EdgeInformation.end()) return MissingValue;
-
- typename EdgeWeights::const_iterator I = J->second.find(e);
- if (I == J->second.end()) return MissingValue;
-
- return I->second;
- }
-
- void setEdgeWeight(Edge e, double w) {
- DEBUG_WITH_TYPE("profile-info",
- dbgs() << "Creating Edge " << e
- << " (weight: " << format("%.20g",w) << ")\n");
- EdgeInformation[getFunction(e)][e] = w;
- }
-
- void addEdgeWeight(Edge e, double w);
-
- EdgeWeights &getEdgeWeights (const FType *F) {
- return EdgeInformation[F];
- }
-
- //===------------------------------------------------------------------===//
- /// Analysis Update Methods
- ///
- void removeBlock(const BType *BB);
-
- void removeEdge(Edge e);
-
- void replaceEdge(const Edge &, const Edge &);
-
- enum GetPathMode {
- GetPathToExit = 1,
- GetPathToValue = 2,
- GetPathToDest = 4,
- GetPathWithNewEdges = 8
- };
-
- const BType *GetPath(const BType *Src, const BType *Dest,
- Path &P, unsigned Mode);
-
- void divertFlow(const Edge &, const Edge &);
-
- void splitEdge(const BType *FirstBB, const BType *SecondBB,
- const BType *NewBB, bool MergeIdenticalEdges = false);
-
- void splitBlock(const BType *Old, const BType* New);
-
- void splitBlock(const BType *BB, const BType* NewBB,
- BType *const *Preds, unsigned NumPreds);
-
- void replaceAllUses(const BType *RmBB, const BType *DestBB);
-
- void transfer(const FType *Old, const FType *New);
-
- void repair(const FType *F);
-
- void dump(FType *F = 0, bool real = true) {
- dbgs() << "**** This is ProfileInfo " << this << " speaking:\n";
- if (!real) {
- typename std::set<const FType*> Functions;
-
- dbgs() << "Functions: \n";
- if (F) {
- dbgs() << F << "@" << format("%p", F) << ": " << format("%.20g",getExecutionCount(F)) << "\n";
- Functions.insert(F);
- } else {
- for (typename std::map<const FType*, double>::iterator fi = FunctionInformation.begin(),
- fe = FunctionInformation.end(); fi != fe; ++fi) {
- dbgs() << fi->first << "@" << format("%p",fi->first) << ": " << format("%.20g",fi->second) << "\n";
- Functions.insert(fi->first);
- }
- }
-
- for (typename std::set<const FType*>::iterator FI = Functions.begin(), FE = Functions.end();
- FI != FE; ++FI) {
- const FType *F = *FI;
- typename std::map<const FType*, BlockCounts>::iterator bwi = BlockInformation.find(F);
- dbgs() << "BasicBlocks for Function " << F << ":\n";
- for (typename BlockCounts::const_iterator bi = bwi->second.begin(), be = bwi->second.end(); bi != be; ++bi) {
- dbgs() << bi->first << "@" << format("%p", bi->first) << ": " << format("%.20g",bi->second) << "\n";
- }
- }
-
- for (typename std::set<const FType*>::iterator FI = Functions.begin(), FE = Functions.end();
- FI != FE; ++FI) {
- typename std::map<const FType*, EdgeWeights>::iterator ei = EdgeInformation.find(*FI);
- dbgs() << "Edges for Function " << ei->first << ":\n";
- for (typename EdgeWeights::iterator ewi = ei->second.begin(), ewe = ei->second.end();
- ewi != ewe; ++ewi) {
- dbgs() << ewi->first << ": " << format("%.20g",ewi->second) << "\n";
- }
- }
- } else {
- assert(F && "No function given, this is not supported!");
- dbgs() << "Functions: \n";
- dbgs() << F << "@" << format("%p", F) << ": " << format("%.20g",getExecutionCount(F)) << "\n";
-
- dbgs() << "BasicBlocks for Function " << F << ":\n";
- for (typename FType::const_iterator BI = F->begin(), BE = F->end();
- BI != BE; ++BI) {
- const BType *BB = &(*BI);
- dbgs() << BB << "@" << format("%p", BB) << ": " << format("%.20g",getExecutionCount(BB)) << "\n";
- }
- }
- dbgs() << "**** ProfileInfo " << this << ", over and out.\n";
- }
-
- bool CalculateMissingEdge(const BType *BB, Edge &removed, bool assumeEmptyExit = false);
-
- bool EstimateMissingEdges(const BType *BB);
-
- ProfileInfoT<MachineFunction, MachineBasicBlock> *MI() {
- if (MachineProfile == 0)
- MachineProfile = new ProfileInfoT<MachineFunction, MachineBasicBlock>();
- return MachineProfile;
- }
-
- bool hasMI() const {
- return (MachineProfile != 0);
- }
- };
-
- typedef ProfileInfoT<Function, BasicBlock> ProfileInfo;
- typedef ProfileInfoT<MachineFunction, MachineBasicBlock> MachineProfileInfo;
-
- /// createProfileLoaderPass - This function returns a Pass that loads the
- /// profiling information for the module from the specified filename, making
- /// it available to the optimizers.
- Pass *createProfileLoaderPass(const std::string &Filename);
-
-} // End llvm namespace
-
-#endif
diff --git a/include/llvm/Analysis/ProfileInfoLoader.h b/include/llvm/Analysis/ProfileInfoLoader.h
deleted file mode 100644
index e0f49f3..0000000
--- a/include/llvm/Analysis/ProfileInfoLoader.h
+++ /dev/null
@@ -1,81 +0,0 @@
-//===- ProfileInfoLoader.h - Load & convert profile information -*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// The ProfileInfoLoader class is used to load and represent profiling
-// information read in from the dump file. If conversions between formats are
-// needed, it can also do this.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_ANALYSIS_PROFILEINFOLOADER_H
-#define LLVM_ANALYSIS_PROFILEINFOLOADER_H
-
-#include <string>
-#include <utility>
-#include <vector>
-
-namespace llvm {
-
-class Module;
-class Function;
-class BasicBlock;
-
-class ProfileInfoLoader {
- const std::string &Filename;
- std::vector<std::string> CommandLines;
- std::vector<unsigned> FunctionCounts;
- std::vector<unsigned> BlockCounts;
- std::vector<unsigned> EdgeCounts;
- std::vector<unsigned> OptimalEdgeCounts;
- std::vector<unsigned> BBTrace;
-public:
- // ProfileInfoLoader ctor - Read the specified profiling data file, exiting
- // the program if the file is invalid or broken.
- ProfileInfoLoader(const char *ToolName, const std::string &Filename);
-
- static const unsigned Uncounted;
-
- unsigned getNumExecutions() const { return CommandLines.size(); }
- const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
-
- const std::string &getFileName() const { return Filename; }
-
- // getRawFunctionCounts - This method is used by consumers of function
- // counting information.
- //
- const std::vector<unsigned> &getRawFunctionCounts() const {
- return FunctionCounts;
- }
-
- // getRawBlockCounts - This method is used by consumers of block counting
- // information.
- //
- const std::vector<unsigned> &getRawBlockCounts() const {
- return BlockCounts;
- }
-
- // getEdgeCounts - This method is used by consumers of edge counting
- // information.
- //
- const std::vector<unsigned> &getRawEdgeCounts() const {
- return EdgeCounts;
- }
-
- // getEdgeOptimalCounts - This method is used by consumers of optimal edge
- // counting information.
- //
- const std::vector<unsigned> &getRawOptimalEdgeCounts() const {
- return OptimalEdgeCounts;
- }
-
-};
-
-} // End llvm namespace
-
-#endif
diff --git a/include/llvm/Analysis/ProfileInfoTypes.h b/include/llvm/Analysis/ProfileInfoTypes.h
deleted file mode 100644
index 45aab5b..0000000
--- a/include/llvm/Analysis/ProfileInfoTypes.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*===-- ProfileInfoTypes.h - Profiling info shared constants --------------===*\
-|*
-|* The LLVM Compiler Infrastructure
-|*
-|* This file is distributed under the University of Illinois Open Source
-|* License. See LICENSE.TXT for details.
-|*
-|*===----------------------------------------------------------------------===*|
-|*
-|* This file defines constants shared by the various different profiling
-|* runtime libraries and the LLVM C++ profile info loader. It must be a
-|* C header because, at present, the profiling runtimes are written in C.
-|*
-\*===----------------------------------------------------------------------===*/
-
-#ifndef LLVM_ANALYSIS_PROFILEINFOTYPES_H
-#define LLVM_ANALYSIS_PROFILEINFOTYPES_H
-
-/* Included by libprofile. */
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* IDs to distinguish between those path counters stored in hashses vs arrays */
-enum ProfilingStorageType {
- ProfilingArray = 1,
- ProfilingHash = 2
-};
-
-#include "llvm/Analysis/ProfileDataTypes.h"
-
-/*
- * The header for tables that map path numbers to path counters.
- */
-typedef struct {
- unsigned fnNumber; /* function number for these counters */
- unsigned numEntries; /* number of entries stored */
-} PathProfileHeader;
-
-/*
- * Describes an entry in a tagged table for path counters.
- */
-typedef struct {
- unsigned pathNumber;
- unsigned pathCounter;
-} PathProfileTableEntry;
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* LLVM_ANALYSIS_PROFILEINFOTYPES_H */
diff --git a/include/llvm/Analysis/RegionPass.h b/include/llvm/Analysis/RegionPass.h
index 6ae3191..3907ad9 100644
--- a/include/llvm/Analysis/RegionPass.h
+++ b/include/llvm/Analysis/RegionPass.h
@@ -18,8 +18,8 @@
#include "llvm/Analysis/RegionInfo.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/LegacyPassManagers.h"
#include "llvm/Pass.h"
-#include "llvm/PassManagers.h"
#include <deque>
namespace llvm {
diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h
index 3817e41..d7f6178 100644
--- a/include/llvm/Analysis/ScalarEvolution.h
+++ b/include/llvm/Analysis/ScalarEvolution.h
@@ -189,15 +189,16 @@ namespace llvm {
/// Convenient NoWrapFlags manipulation that hides enum casts and is
/// visible in the ScalarEvolution name space.
- static SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags, int Mask) {
+ static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
+ maskFlags(SCEV::NoWrapFlags Flags, int Mask) {
return (SCEV::NoWrapFlags)(Flags & Mask);
}
- static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags,
- SCEV::NoWrapFlags OnFlags) {
+ static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
+ setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags) {
return (SCEV::NoWrapFlags)(Flags | OnFlags);
}
- static SCEV::NoWrapFlags clearFlags(SCEV::NoWrapFlags Flags,
- SCEV::NoWrapFlags OffFlags) {
+ static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
+ clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags) {
return (SCEV::NoWrapFlags)(Flags & ~OffFlags);
}
@@ -361,18 +362,18 @@ namespace llvm {
/// that we attempt to compute getSCEVAtScope information for, which can
/// be expensive in extreme cases.
DenseMap<const SCEV *,
- std::map<const Loop *, const SCEV *> > ValuesAtScopes;
+ SmallVector<std::pair<const Loop *, const SCEV *>, 2> > ValuesAtScopes;
/// LoopDispositions - Memoized computeLoopDisposition results.
DenseMap<const SCEV *,
- std::map<const Loop *, LoopDisposition> > LoopDispositions;
+ SmallVector<std::pair<const Loop *, LoopDisposition>, 2> > LoopDispositions;
/// computeLoopDisposition - Compute a LoopDisposition value.
LoopDisposition computeLoopDisposition(const SCEV *S, const Loop *L);
/// BlockDispositions - Memoized computeBlockDisposition results.
DenseMap<const SCEV *,
- std::map<const BasicBlock *, BlockDisposition> > BlockDispositions;
+ SmallVector<std::pair<const BasicBlock *, BlockDisposition>, 2> > BlockDispositions;
/// computeBlockDisposition - Compute a BlockDisposition value.
BlockDisposition computeBlockDisposition(const SCEV *S, const BasicBlock *BB);
@@ -426,14 +427,6 @@ namespace llvm {
/// resolution.
void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
- /// getBECount - Subtract the end and start values and divide by the step,
- /// rounding up, to get the number of times the backedge is executed. Return
- /// CouldNotCompute if an intermediate computation overflows.
- const SCEV *getBECount(const SCEV *Start,
- const SCEV *End,
- const SCEV *Step,
- bool NoWrap);
-
/// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given
/// loop, lazily computing new values if the loop hasn't been analyzed
/// yet.
@@ -498,6 +491,8 @@ namespace llvm {
/// less-than is signed.
ExitLimit HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
const Loop *L, bool isSigned, bool IsSubExpr);
+ ExitLimit HowManyGreaterThans(const SCEV *LHS, const SCEV *RHS,
+ const Loop *L, bool isSigned, bool IsSubExpr);
/// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
/// (which may not be an immediate predecessor) which has exactly one
@@ -636,21 +631,15 @@ namespace llvm {
const SCEV *getUnknown(Value *V);
const SCEV *getCouldNotCompute();
- /// getSizeOfExpr - Return an expression for sizeof on the given type.
- ///
- const SCEV *getSizeOfExpr(Type *AllocTy);
-
- /// getAlignOfExpr - Return an expression for alignof on the given type.
+ /// getSizeOfExpr - Return an expression for sizeof AllocTy that is type
+ /// IntTy
///
- const SCEV *getAlignOfExpr(Type *AllocTy);
+ const SCEV *getSizeOfExpr(Type *IntTy, Type *AllocTy);
- /// getOffsetOfExpr - Return an expression for offsetof on the given field.
+ /// getOffsetOfExpr - Return an expression for offsetof on the given field
+ /// with type IntTy
///
- const SCEV *getOffsetOfExpr(StructType *STy, unsigned FieldNo);
-
- /// getOffsetOfExpr - Return an expression for offsetof on the given field.
- ///
- const SCEV *getOffsetOfExpr(Type *CTy, Constant *FieldNo);
+ const SCEV *getOffsetOfExpr(Type *IntTy, StructType *STy, unsigned FieldNo);
/// getNegativeSCEV - Return the SCEV object corresponding to -V.
///
@@ -886,6 +875,24 @@ namespace llvm {
virtual void verifyAnalysis() const;
private:
+ /// Compute the backedge taken count knowing the interval difference, the
+ /// stride and presence of the equality in the comparison.
+ const SCEV *computeBECount(const SCEV *Delta, const SCEV *Stride,
+ bool Equality);
+
+ /// Verify if an linear IV with positive stride can overflow when in a
+ /// less-than comparison, knowing the invariant term of the comparison,
+ /// the stride and the knowledge of NSW/NUW flags on the recurrence.
+ bool doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride,
+ bool IsSigned, bool NoWrap);
+
+ /// Verify if an linear IV with negative stride can overflow when in a
+ /// greater-than comparison, knowing the invariant term of the comparison,
+ /// the stride and the knowledge of NSW/NUW flags on the recurrence.
+ bool doesIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride,
+ bool IsSigned, bool NoWrap);
+
+ private:
FoldingSet<SCEV> UniqueSCEVs;
BumpPtrAllocator SCEVAllocator;
diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h
index 00779fc..4433be0 100644
--- a/include/llvm/Analysis/ScalarEvolutionExpander.h
+++ b/include/llvm/Analysis/ScalarEvolutionExpander.h
@@ -26,7 +26,7 @@ namespace llvm {
/// Return true if the given expression is safe to expand in the sense that
/// all materialized values are safe to speculate.
- bool isSafeToExpand(const SCEV *S);
+ bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE);
/// SCEVExpander - This class uses information about analyze scalars to
/// rewrite expressions in canonical form.
@@ -252,8 +252,6 @@ namespace llvm {
void rememberInstruction(Value *I);
- void restoreInsertPoint(BasicBlock *BB, BasicBlock::iterator I);
-
bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
diff --git a/include/llvm/Analysis/ScalarEvolutionExpressions.h b/include/llvm/Analysis/ScalarEvolutionExpressions.h
index eac9113..9cd902a 100644
--- a/include/llvm/Analysis/ScalarEvolutionExpressions.h
+++ b/include/llvm/Analysis/ScalarEvolutionExpressions.h
@@ -351,8 +351,14 @@ namespace llvm {
static inline bool classof(const SCEV *S) {
return S->getSCEVType() == scAddRecExpr;
}
- };
+ /// Splits the SCEV into two vectors of SCEVs representing the subscripts
+ /// and sizes of an array access. Returns the remainder of the
+ /// delinearization that is the offset start of the array.
+ const SCEV *delinearize(ScalarEvolution &SE,
+ SmallVectorImpl<const SCEV *> &Subscripts,
+ SmallVectorImpl<const SCEV *> &Sizes) const;
+ };
//===--------------------------------------------------------------------===//
/// SCEVSMaxExpr - This class represents a signed maximum selection.
@@ -549,53 +555,60 @@ namespace llvm {
T.visitAll(Root);
}
- /// The SCEVRewriter takes a scalar evolution expression and copies all its
- /// components. The result after a rewrite is an identical SCEV.
- struct SCEVRewriter
- : public SCEVVisitor<SCEVRewriter, const SCEV*> {
+ typedef DenseMap<const Value*, Value*> ValueToValueMap;
+
+ /// The SCEVParameterRewriter takes a scalar evolution expression and updates
+ /// the SCEVUnknown components following the Map (Value -> Value).
+ struct SCEVParameterRewriter
+ : public SCEVVisitor<SCEVParameterRewriter, const SCEV*> {
public:
- SCEVRewriter(ScalarEvolution &S) : SE(S) {}
+ static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE,
+ ValueToValueMap &Map) {
+ SCEVParameterRewriter Rewriter(SE, Map);
+ return Rewriter.visit(Scev);
+ }
- virtual ~SCEVRewriter() {}
+ SCEVParameterRewriter(ScalarEvolution &S, ValueToValueMap &M)
+ : SE(S), Map(M) {}
- virtual const SCEV *visitConstant(const SCEVConstant *Constant) {
+ const SCEV *visitConstant(const SCEVConstant *Constant) {
return Constant;
}
- virtual const SCEV *visitTruncateExpr(const SCEVTruncateExpr *Expr) {
+ const SCEV *visitTruncateExpr(const SCEVTruncateExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getTruncateExpr(Operand, Expr->getType());
}
- virtual const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
+ const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getZeroExtendExpr(Operand, Expr->getType());
}
- virtual const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
+ const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
const SCEV *Operand = visit(Expr->getOperand());
return SE.getSignExtendExpr(Operand, Expr->getType());
}
- virtual const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
+ const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getAddExpr(Operands);
}
- virtual const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
+ const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getMulExpr(Operands);
}
- virtual const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
+ const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
return SE.getUDivExpr(visit(Expr->getLHS()), visit(Expr->getRHS()));
}
- virtual const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
+ const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
@@ -603,54 +616,33 @@ namespace llvm {
Expr->getNoWrapFlags());
}
- virtual const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
+ const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getSMaxExpr(Operands);
}
- virtual const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
+ const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
return SE.getUMaxExpr(Operands);
}
- virtual const SCEV *visitUnknown(const SCEVUnknown *Expr) {
- return Expr;
- }
-
- virtual const SCEV *visitCouldNotCompute(const SCEVCouldNotCompute *Expr) {
- return Expr;
- }
-
- protected:
- ScalarEvolution &SE;
- };
-
- typedef DenseMap<const Value*, Value*> ValueToValueMap;
-
- /// The SCEVParameterRewriter takes a scalar evolution expression and updates
- /// the SCEVUnknown components following the Map (Value -> Value).
- struct SCEVParameterRewriter: public SCEVRewriter {
- public:
- static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution &SE,
- ValueToValueMap &Map) {
- SCEVParameterRewriter Rewriter(SE, Map);
- return Rewriter.visit(Scev);
- }
- SCEVParameterRewriter(ScalarEvolution &S, ValueToValueMap &M)
- : SCEVRewriter(S), Map(M) {}
-
- virtual const SCEV *visitUnknown(const SCEVUnknown *Expr) {
+ const SCEV *visitUnknown(const SCEVUnknown *Expr) {
Value *V = Expr->getValue();
if (Map.count(V))
return SE.getUnknown(Map[V]);
return Expr;
}
+ const SCEV *visitCouldNotCompute(const SCEVCouldNotCompute *Expr) {
+ return Expr;
+ }
+
private:
+ ScalarEvolution &SE;
ValueToValueMap &Map;
};
@@ -658,17 +650,56 @@ namespace llvm {
/// The SCEVApplyRewriter takes a scalar evolution expression and applies
/// the Map (Loop -> SCEV) to all AddRecExprs.
- struct SCEVApplyRewriter: public SCEVRewriter {
+ struct SCEVApplyRewriter
+ : public SCEVVisitor<SCEVApplyRewriter, const SCEV*> {
public:
static const SCEV *rewrite(const SCEV *Scev, LoopToScevMapT &Map,
ScalarEvolution &SE) {
SCEVApplyRewriter Rewriter(SE, Map);
return Rewriter.visit(Scev);
}
+
SCEVApplyRewriter(ScalarEvolution &S, LoopToScevMapT &M)
- : SCEVRewriter(S), Map(M) {}
+ : SE(S), Map(M) {}
+
+ const SCEV *visitConstant(const SCEVConstant *Constant) {
+ return Constant;
+ }
+
+ const SCEV *visitTruncateExpr(const SCEVTruncateExpr *Expr) {
+ const SCEV *Operand = visit(Expr->getOperand());
+ return SE.getTruncateExpr(Operand, Expr->getType());
+ }
+
+ const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
+ const SCEV *Operand = visit(Expr->getOperand());
+ return SE.getZeroExtendExpr(Operand, Expr->getType());
+ }
+
+ const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
+ const SCEV *Operand = visit(Expr->getOperand());
+ return SE.getSignExtendExpr(Operand, Expr->getType());
+ }
+
+ const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
+ SmallVector<const SCEV *, 2> Operands;
+ for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
+ Operands.push_back(visit(Expr->getOperand(i)));
+ return SE.getAddExpr(Operands);
+ }
+
+ const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
+ SmallVector<const SCEV *, 2> Operands;
+ for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
+ Operands.push_back(visit(Expr->getOperand(i)));
+ return SE.getMulExpr(Operands);
+ }
- virtual const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
+ const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
+ return SE.getUDivExpr(visit(Expr->getLHS()), visit(Expr->getRHS()));
+ }
+
+ const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
@@ -683,7 +714,30 @@ namespace llvm {
return Rec->evaluateAtIteration(Map[L], SE);
}
+ const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
+ SmallVector<const SCEV *, 2> Operands;
+ for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
+ Operands.push_back(visit(Expr->getOperand(i)));
+ return SE.getSMaxExpr(Operands);
+ }
+
+ const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
+ SmallVector<const SCEV *, 2> Operands;
+ for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
+ Operands.push_back(visit(Expr->getOperand(i)));
+ return SE.getUMaxExpr(Operands);
+ }
+
+ const SCEV *visitUnknown(const SCEVUnknown *Expr) {
+ return Expr;
+ }
+
+ const SCEV *visitCouldNotCompute(const SCEVCouldNotCompute *Expr) {
+ return Expr;
+ }
+
private:
+ ScalarEvolution &SE;
LoopToScevMapT &Map;
};
diff --git a/include/llvm/Analysis/TargetTransformInfo.h b/include/llvm/Analysis/TargetTransformInfo.h
index 21a3a12..4f47562 100644
--- a/include/llvm/Analysis/TargetTransformInfo.h
+++ b/include/llvm/Analysis/TargetTransformInfo.h
@@ -29,6 +29,7 @@
namespace llvm {
class GlobalValue;
+class Loop;
class Type;
class User;
class Value;
@@ -191,6 +192,36 @@ public:
/// incurs significant execution cost.
virtual bool isLoweredToCall(const Function *F) const;
+ /// Parameters that control the generic loop unrolling transformation.
+ struct UnrollingPreferences {
+ /// The cost threshold for the unrolled loop, compared to
+ /// CodeMetrics.NumInsts aggregated over all basic blocks in the loop body.
+ /// The unrolling factor is set such that the unrolled loop body does not
+ /// exceed this cost. Set this to UINT_MAX to disable the loop body cost
+ /// restriction.
+ unsigned Threshold;
+ /// The cost threshold for the unrolled loop when optimizing for size (set
+ /// to UINT_MAX to disable).
+ unsigned OptSizeThreshold;
+ /// A forced unrolling factor (the number of concatenated bodies of the
+ /// original loop in the unrolled loop body). When set to 0, the unrolling
+ /// transformation will select an unrolling factor based on the current cost
+ /// threshold and other factors.
+ unsigned Count;
+ /// Allow partial unrolling (unrolling of loops to expand the size of the
+ /// loop body, not only to eliminate small constant-trip-count loops).
+ bool Partial;
+ /// Allow runtime unrolling (unrolling of loops to expand the size of the
+ /// loop body even when the number of loop iterations is not known at compile
+ /// time).
+ bool Runtime;
+ };
+
+ /// \brief Get target-customized preferences for the generic loop unrolling
+ /// transformation. The caller will initialize UP with the current
+ /// target-independent defaults.
+ virtual void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP) const;
+
/// @}
/// \name Scalar Target Information
@@ -262,6 +293,10 @@ public:
/// getPopcntSupport - Return hardware support for population count.
virtual PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const;
+ /// haveFastSqrt -- Return true if the hardware has a fast square-root
+ /// instruction.
+ virtual bool haveFastSqrt(Type *Ty) const;
+
/// getIntImmCost - Return the expected cost of materializing the given
/// integer immediate of the specified type.
virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty) const;
@@ -279,7 +314,7 @@ public:
SK_ExtractSubvector ///< ExtractSubvector Index indicates start offset.
};
- /// \brief Additonal information about an operand's possible values.
+ /// \brief Additional information about an operand's possible values.
enum OperandValueKind {
OK_AnyValue, // Operand can have any value.
OK_UniformValue, // Operand is uniform (splat of a value).
@@ -333,6 +368,22 @@ public:
unsigned Alignment,
unsigned AddressSpace) const;
+ /// \brief Calculate the cost of performing a vector reduction.
+ ///
+ /// This is the cost of reducing the vector value of type \p Ty to a scalar
+ /// value using the operation denoted by \p Opcode. The form of the reduction
+ /// can either be a pairwise reduction or a reduction that splits the vector
+ /// at every reduction level.
+ ///
+ /// Pairwise:
+ /// (v0, v1, v2, v3)
+ /// ((v0+v1), (v2, v3), undef, undef)
+ /// Split:
+ /// (v0, v1, v2, v3)
+ /// ((v0+v2), (v1+v3), undef, undef)
+ virtual unsigned getReductionCost(unsigned Opcode, Type *Ty,
+ bool IsPairwiseForm) const;
+
/// \returns The cost of Intrinsic instructions.
virtual unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy,
ArrayRef<Type *> Tys) const;
diff --git a/include/llvm/Analysis/ValueTracking.h b/include/llvm/Analysis/ValueTracking.h
index 3775ec9..0392f98 100644
--- a/include/llvm/Analysis/ValueTracking.h
+++ b/include/llvm/Analysis/ValueTracking.h
@@ -25,6 +25,7 @@ namespace llvm {
class DataLayout;
class StringRef;
class MDNode;
+ class TargetLibraryInfo;
/// ComputeMaskedBits - Determine which of the bits specified in Mask are
/// known to be either zero or one and return them in the KnownZero/KnownOne
@@ -186,7 +187,7 @@ namespace llvm {
/// isKnownNonNull - Return true if this pointer couldn't possibly be null by
/// its definition. This returns true for allocas, non-extern-weak globals
/// and byval arguments.
- bool isKnownNonNull(const Value *V);
+ bool isKnownNonNull(const Value *V, const TargetLibraryInfo *TLI = 0);
} // end namespace llvm