2009-06-24 23:29:13 +02:00
|
|
|
//===- llvm/Analysis/LoopDependenceAnalysis.h --------------- -*- C++ -*---===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// LoopDependenceAnalysis is an LLVM pass that analyses dependences in memory
|
|
|
|
// accesses in loops.
|
|
|
|
//
|
|
|
|
// Please note that this is work in progress and the interface is subject to
|
|
|
|
// change.
|
|
|
|
//
|
|
|
|
// TODO: adapt as interface progresses
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
|
|
|
|
#define LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H
|
|
|
|
|
2009-08-07 20:23:41 +02:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2009-07-23 16:32:46 +02:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2009-07-29 07:35:53 +02:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-06-24 23:29:13 +02:00
|
|
|
#include "llvm/Analysis/LoopPass.h"
|
2009-07-23 16:32:46 +02:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2009-06-24 23:29:13 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
class AliasAnalysis;
|
|
|
|
class AnalysisUsage;
|
|
|
|
class ScalarEvolution;
|
2009-07-29 07:35:53 +02:00
|
|
|
class SCEV;
|
2009-07-23 03:57:06 +02:00
|
|
|
class Value;
|
2009-07-25 01:19:28 +02:00
|
|
|
class raw_ostream;
|
2009-06-24 23:29:13 +02:00
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
class LoopDependenceAnalysis : public LoopPass {
|
|
|
|
AliasAnalysis *AA;
|
|
|
|
ScalarEvolution *SE;
|
2009-06-24 23:29:13 +02:00
|
|
|
|
2009-07-23 16:32:46 +02:00
|
|
|
/// L - The loop we are currently analysing.
|
|
|
|
Loop *L;
|
|
|
|
|
|
|
|
/// TODO: doc
|
|
|
|
enum DependenceResult { Independent = 0, Dependent = 1, Unknown = 2 };
|
|
|
|
|
2009-07-29 07:35:53 +02:00
|
|
|
/// TODO: doc
|
|
|
|
struct Subscript {
|
|
|
|
/// TODO: Add distance, direction, breaking conditions, ...
|
|
|
|
};
|
|
|
|
|
2009-07-23 16:32:46 +02:00
|
|
|
/// DependencePair - Represents a data dependence relation between to memory
|
|
|
|
/// reference instructions.
|
|
|
|
struct DependencePair : public FastFoldingSetNode {
|
|
|
|
Value *A;
|
|
|
|
Value *B;
|
|
|
|
DependenceResult Result;
|
2009-07-29 07:35:53 +02:00
|
|
|
SmallVector<Subscript, 4> Subscripts;
|
2009-07-23 16:32:46 +02:00
|
|
|
|
|
|
|
DependencePair(const FoldingSetNodeID &ID, Value *a, Value *b) :
|
2009-07-29 07:35:53 +02:00
|
|
|
FastFoldingSetNode(ID), A(a), B(b), Result(Unknown), Subscripts() {}
|
2009-07-23 16:32:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// findOrInsertDependencePair - Return true if a DependencePair for the
|
|
|
|
/// given Values already exists, false if a new DependencePair had to be
|
|
|
|
/// created. The third argument is set to the pair found or created.
|
|
|
|
bool findOrInsertDependencePair(Value*, Value*, DependencePair*&);
|
|
|
|
|
2009-12-07 10:06:37 +01:00
|
|
|
/// getLoops - Collect all loops of the loop nest L in which
|
|
|
|
/// a given SCEV is variant.
|
2009-08-07 20:23:41 +02:00
|
|
|
void getLoops(const SCEV*, DenseSet<const Loop*>*) const;
|
|
|
|
|
2009-08-03 03:03:48 +02:00
|
|
|
/// isLoopInvariant - True if a given SCEV is invariant in all loops of the
|
2009-12-07 10:06:37 +01:00
|
|
|
/// loop nest starting at the innermost loop L.
|
2009-08-03 03:03:48 +02:00
|
|
|
bool isLoopInvariant(const SCEV*) const;
|
|
|
|
|
2009-12-07 10:06:37 +01:00
|
|
|
/// isAffine - An SCEV is affine with respect to the loop nest starting at
|
2009-08-03 03:03:48 +02:00
|
|
|
/// the innermost loop L if it is of the form A+B*X where A, B are invariant
|
2009-12-07 10:06:37 +01:00
|
|
|
/// in the loop nest and X is a induction variable in the loop nest.
|
2009-08-03 03:03:48 +02:00
|
|
|
bool isAffine(const SCEV*) const;
|
|
|
|
|
2009-07-23 16:32:46 +02:00
|
|
|
/// TODO: doc
|
2009-08-05 06:26:05 +02:00
|
|
|
bool isZIVPair(const SCEV*, const SCEV*) const;
|
2009-08-07 20:23:41 +02:00
|
|
|
bool isSIVPair(const SCEV*, const SCEV*) const;
|
2009-08-05 06:26:05 +02:00
|
|
|
DependenceResult analyseZIV(const SCEV*, const SCEV*, Subscript*) const;
|
2009-08-07 20:23:41 +02:00
|
|
|
DependenceResult analyseSIV(const SCEV*, const SCEV*, Subscript*) const;
|
|
|
|
DependenceResult analyseMIV(const SCEV*, const SCEV*, Subscript*) const;
|
2009-07-29 07:35:53 +02:00
|
|
|
DependenceResult analyseSubscript(const SCEV*, const SCEV*, Subscript*) const;
|
|
|
|
DependenceResult analysePair(DependencePair*) const;
|
2009-07-23 16:32:46 +02:00
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
public:
|
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
|
|
|
LoopDependenceAnalysis() : LoopPass(&ID) {}
|
2009-06-24 23:29:13 +02:00
|
|
|
|
2009-12-07 10:06:37 +01:00
|
|
|
/// isDependencePair - Check whether two values can possibly give rise to
|
|
|
|
/// a data dependence: that is the case if both are instructions accessing
|
2009-07-23 16:32:46 +02:00
|
|
|
/// memory and at least one of those accesses is a write.
|
2009-07-23 03:57:06 +02:00
|
|
|
bool isDependencePair(const Value*, const Value*) const;
|
2009-07-23 16:32:46 +02:00
|
|
|
|
|
|
|
/// depends - Return a boolean indicating if there is a data dependence
|
|
|
|
/// between two instructions.
|
2009-07-23 03:57:06 +02:00
|
|
|
bool depends(Value*, Value*);
|
2009-06-28 02:21:21 +02:00
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
bool runOnLoop(Loop*, LPPassManager&);
|
2009-07-23 16:32:46 +02:00
|
|
|
virtual void releaseMemory();
|
2009-07-23 03:57:06 +02:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage&) const;
|
|
|
|
void print(raw_ostream&, const Module* = 0) const;
|
2009-07-23 16:32:46 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
FoldingSet<DependencePair> Pairs;
|
|
|
|
BumpPtrAllocator PairAllocator;
|
2009-07-23 03:57:06 +02:00
|
|
|
}; // class LoopDependenceAnalysis
|
2009-06-24 23:29:13 +02:00
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
// createLoopDependenceAnalysisPass - This creates an instance of the
|
|
|
|
// LoopDependenceAnalysis pass.
|
|
|
|
//
|
|
|
|
LoopPass *createLoopDependenceAnalysisPass();
|
2009-06-24 23:29:13 +02:00
|
|
|
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif /* LLVM_ANALYSIS_LOOP_DEPENDENCE_ANALYSIS_H */
|