1 //===- llvm/Analysis/LoopDependenceAnalysis.h --------------- -*- C++ -*---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // LoopDependenceAnalysis is an LLVM pass that analyses dependences in memory
13 // Please note that this is work in progress and the interface is subject to
16 // TODO: adapt as interface progresses
18 //===----------------------------------------------------------------------===//
20 #ifndef LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
21 #define LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/Analysis/LoopPass.h"
25 #include "llvm/Support/Allocator.h"
32 class ScalarEvolution;
36 class LoopDependenceAnalysis : public LoopPass {
40 /// L - The loop we are currently analysing.
44 enum DependenceResult { Independent = 0, Dependent = 1, Unknown = 2 };
46 /// DependencePair - Represents a data dependence relation between to memory
47 /// reference instructions.
49 /// TODO: add subscripts vector
50 struct DependencePair : public FastFoldingSetNode {
53 DependenceResult Result;
55 DependencePair(const FoldingSetNodeID &ID, Value *a, Value *b) :
56 FastFoldingSetNode(ID), A(a), B(b), Result(Unknown) {}
59 /// findOrInsertDependencePair - Return true if a DependencePair for the
60 /// given Values already exists, false if a new DependencePair had to be
61 /// created. The third argument is set to the pair found or created.
62 bool findOrInsertDependencePair(Value*, Value*, DependencePair*&);
65 DependenceResult analysePair(DependencePair *P) const;
68 static char ID; // Class identification, replacement for typeinfo
69 LoopDependenceAnalysis() : LoopPass(&ID) {}
71 /// isDependencePair - Check wether two values can possibly give rise to a
72 /// data dependence: that is the case if both are instructions accessing
73 /// memory and at least one of those accesses is a write.
74 bool isDependencePair(const Value*, const Value*) const;
76 /// depends - Return a boolean indicating if there is a data dependence
77 /// between two instructions.
78 bool depends(Value*, Value*);
80 bool runOnLoop(Loop*, LPPassManager&);
81 virtual void releaseMemory();
82 virtual void getAnalysisUsage(AnalysisUsage&) const;
83 void print(raw_ostream&, const Module* = 0) const;
84 virtual void print(std::ostream&, const Module* = 0) const;
87 FoldingSet<DependencePair> Pairs;
88 BumpPtrAllocator PairAllocator;
89 }; // class LoopDependenceAnalysis
92 // createLoopDependenceAnalysisPass - This creates an instance of the
93 // LoopDependenceAnalysis pass.
95 LoopPass *createLoopDependenceAnalysisPass();
99 #endif /* LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H */