2009-06-24 23:29:13 +02:00
|
|
|
//===- LoopDependenceAnalysis.cpp - LDA Implementation ----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is the (beginning) of an implementation of a loop dependence analysis
|
|
|
|
// framework, which is used to detect dependences in memory accesses in loops.
|
|
|
|
//
|
|
|
|
// Please note that this is work in progress and the interface is subject to
|
|
|
|
// change.
|
|
|
|
//
|
|
|
|
// TODO: adapt as implementation progresses.
|
|
|
|
//
|
2009-07-29 07:35:53 +02:00
|
|
|
// TODO: document lingo (pair, subscript, index)
|
|
|
|
//
|
2009-06-24 23:29:13 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "lda"
|
2009-08-07 20:23:41 +02:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2009-07-28 21:49:49 +02:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2009-07-01 23:45:23 +02:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2009-06-24 23:29:13 +02:00
|
|
|
#include "llvm/Analysis/LoopDependenceAnalysis.h"
|
|
|
|
#include "llvm/Analysis/LoopPass.h"
|
|
|
|
#include "llvm/Analysis/ScalarEvolution.h"
|
2009-08-03 03:03:48 +02:00
|
|
|
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
|
2010-12-15 21:02:24 +01:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2011-01-02 23:09:33 +01:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2009-06-28 02:21:21 +02:00
|
|
|
#include "llvm/Instructions.h"
|
2009-07-29 07:35:53 +02:00
|
|
|
#include "llvm/Operator.h"
|
2009-07-25 01:19:28 +02:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2009-06-30 04:12:10 +02:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-25 01:19:28 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-07-01 23:45:23 +02:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2009-06-24 23:29:13 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-07-28 21:49:49 +02:00
|
|
|
STATISTIC(NumAnswered, "Number of dependence queries answered");
|
|
|
|
STATISTIC(NumAnalysed, "Number of distinct dependence pairs analysed");
|
|
|
|
STATISTIC(NumDependent, "Number of pairs with dependent accesses");
|
|
|
|
STATISTIC(NumIndependent, "Number of pairs with independent accesses");
|
|
|
|
STATISTIC(NumUnknown, "Number of pairs with unknown accesses");
|
|
|
|
|
2009-06-24 23:29:13 +02:00
|
|
|
LoopPass *llvm::createLoopDependenceAnalysisPass() {
|
|
|
|
return new LoopDependenceAnalysis();
|
|
|
|
}
|
|
|
|
|
2010-10-12 21:48:12 +02:00
|
|
|
INITIALIZE_PASS_BEGIN(LoopDependenceAnalysis, "lda",
|
|
|
|
"Loop Dependence Analysis", false, true)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
|
|
|
|
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
|
|
|
INITIALIZE_PASS_END(LoopDependenceAnalysis, "lda",
|
2010-10-08 00:25:06 +02:00
|
|
|
"Loop Dependence Analysis", false, true)
|
2009-06-24 23:29:13 +02:00
|
|
|
char LoopDependenceAnalysis::ID = 0;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-28 02:21:21 +02:00
|
|
|
// Utility Functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-06-29 20:51:11 +02:00
|
|
|
static inline bool IsMemRefInstr(const Value *V) {
|
|
|
|
const Instruction *I = dyn_cast<const Instruction>(V);
|
|
|
|
return I && (I->mayReadFromMemory() || I->mayWriteToMemory());
|
2009-06-28 02:21:21 +02:00
|
|
|
}
|
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
static void GetMemRefInstrs(const Loop *L,
|
|
|
|
SmallVectorImpl<Instruction*> &Memrefs) {
|
2009-06-28 02:35:22 +02:00
|
|
|
for (Loop::block_iterator b = L->block_begin(), be = L->block_end();
|
2009-07-28 21:49:25 +02:00
|
|
|
b != be; ++b)
|
2009-06-28 02:35:22 +02:00
|
|
|
for (BasicBlock::iterator i = (*b)->begin(), ie = (*b)->end();
|
2009-07-28 21:49:25 +02:00
|
|
|
i != ie; ++i)
|
2009-06-29 02:50:26 +02:00
|
|
|
if (IsMemRefInstr(i))
|
2009-07-23 03:57:06 +02:00
|
|
|
Memrefs.push_back(i);
|
2009-06-28 02:35:22 +02:00
|
|
|
}
|
|
|
|
|
2009-06-30 04:12:10 +02:00
|
|
|
static bool IsLoadOrStoreInst(Value *I) {
|
2011-08-15 22:54:19 +02:00
|
|
|
// Returns true if the load or store can be analyzed. Atomic and volatile
|
|
|
|
// operations have properties which this analysis does not understand.
|
|
|
|
if (LoadInst *LI = dyn_cast<LoadInst>(I))
|
|
|
|
return LI->isUnordered();
|
|
|
|
else if (StoreInst *SI = dyn_cast<StoreInst>(I))
|
|
|
|
return SI->isUnordered();
|
|
|
|
return false;
|
2009-06-30 04:12:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static Value *GetPointerOperand(Value *I) {
|
|
|
|
if (LoadInst *i = dyn_cast<LoadInst>(I))
|
|
|
|
return i->getPointerOperand();
|
|
|
|
if (StoreInst *i = dyn_cast<StoreInst>(I))
|
|
|
|
return i->getPointerOperand();
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Value is no load or store instruction!");
|
2009-06-30 04:12:10 +02:00
|
|
|
// Never reached.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-28 21:49:25 +02:00
|
|
|
static AliasAnalysis::AliasResult UnderlyingObjectsAlias(AliasAnalysis *AA,
|
|
|
|
const Value *A,
|
|
|
|
const Value *B) {
|
2010-12-15 21:02:24 +01:00
|
|
|
const Value *aObj = GetUnderlyingObject(A);
|
|
|
|
const Value *bObj = GetUnderlyingObject(B);
|
2009-07-28 21:49:25 +02:00
|
|
|
return AA->alias(aObj, AA->getTypeStoreSize(aObj->getType()),
|
|
|
|
bObj, AA->getTypeStoreSize(bObj->getType()));
|
|
|
|
}
|
|
|
|
|
2009-07-29 07:35:53 +02:00
|
|
|
static inline const SCEV *GetZeroSCEV(ScalarEvolution *SE) {
|
2009-08-13 23:58:54 +02:00
|
|
|
return SE->getConstant(Type::getInt32Ty(SE->getContext()), 0L);
|
2009-07-29 07:35:53 +02:00
|
|
|
}
|
|
|
|
|
2009-06-28 02:21:21 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dependence Testing
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
bool LoopDependenceAnalysis::isDependencePair(const Value *A,
|
|
|
|
const Value *B) const {
|
|
|
|
return IsMemRefInstr(A) &&
|
|
|
|
IsMemRefInstr(B) &&
|
|
|
|
(cast<const Instruction>(A)->mayWriteToMemory() ||
|
|
|
|
cast<const Instruction>(B)->mayWriteToMemory());
|
2009-06-28 02:21:21 +02:00
|
|
|
}
|
|
|
|
|
2009-07-28 21:49:25 +02:00
|
|
|
bool LoopDependenceAnalysis::findOrInsertDependencePair(Value *A,
|
|
|
|
Value *B,
|
2009-07-23 16:32:46 +02:00
|
|
|
DependencePair *&P) {
|
|
|
|
void *insertPos = 0;
|
|
|
|
FoldingSetNodeID id;
|
2009-07-28 21:49:25 +02:00
|
|
|
id.AddPointer(A);
|
|
|
|
id.AddPointer(B);
|
2009-07-23 16:32:46 +02:00
|
|
|
|
|
|
|
P = Pairs.FindNodeOrInsertPos(id, insertPos);
|
|
|
|
if (P) return true;
|
|
|
|
|
2010-03-18 19:49:47 +01:00
|
|
|
P = new (PairAllocator) DependencePair(id, A, B);
|
2009-07-23 16:32:46 +02:00
|
|
|
Pairs.InsertNode(P, insertPos);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-08-07 20:23:41 +02:00
|
|
|
void LoopDependenceAnalysis::getLoops(const SCEV *S,
|
|
|
|
DenseSet<const Loop*>* Loops) const {
|
|
|
|
// Refactor this into an SCEVVisitor, if efficiency becomes a concern.
|
2009-08-03 03:03:48 +02:00
|
|
|
for (const Loop *L = this->L; L != 0; L = L->getParentLoop())
|
2010-11-17 22:23:15 +01:00
|
|
|
if (!SE->isLoopInvariant(S, L))
|
2009-08-07 20:23:41 +02:00
|
|
|
Loops->insert(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LoopDependenceAnalysis::isLoopInvariant(const SCEV *S) const {
|
|
|
|
DenseSet<const Loop*> loops;
|
|
|
|
getLoops(S, &loops);
|
|
|
|
return loops.empty();
|
2009-08-03 03:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LoopDependenceAnalysis::isAffine(const SCEV *S) const {
|
|
|
|
const SCEVAddRecExpr *rec = dyn_cast<SCEVAddRecExpr>(S);
|
|
|
|
return isLoopInvariant(S) || (rec && rec->isAffine());
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:26:05 +02:00
|
|
|
bool LoopDependenceAnalysis::isZIVPair(const SCEV *A, const SCEV *B) const {
|
|
|
|
return isLoopInvariant(A) && isLoopInvariant(B);
|
|
|
|
}
|
|
|
|
|
2009-08-07 20:23:41 +02:00
|
|
|
bool LoopDependenceAnalysis::isSIVPair(const SCEV *A, const SCEV *B) const {
|
|
|
|
DenseSet<const Loop*> loops;
|
|
|
|
getLoops(A, &loops);
|
|
|
|
getLoops(B, &loops);
|
|
|
|
return loops.size() == 1;
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:26:05 +02:00
|
|
|
LoopDependenceAnalysis::DependenceResult
|
|
|
|
LoopDependenceAnalysis::analyseZIV(const SCEV *A,
|
|
|
|
const SCEV *B,
|
|
|
|
Subscript *S) const {
|
2009-08-06 05:10:33 +02:00
|
|
|
assert(isZIVPair(A, B) && "Attempted to ZIV-test non-ZIV SCEVs!");
|
|
|
|
return A == B ? Dependent : Independent;
|
2009-08-05 06:26:05 +02:00
|
|
|
}
|
|
|
|
|
2009-08-07 20:23:41 +02:00
|
|
|
LoopDependenceAnalysis::DependenceResult
|
|
|
|
LoopDependenceAnalysis::analyseSIV(const SCEV *A,
|
|
|
|
const SCEV *B,
|
|
|
|
Subscript *S) const {
|
|
|
|
return Unknown; // TODO: Implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
LoopDependenceAnalysis::DependenceResult
|
|
|
|
LoopDependenceAnalysis::analyseMIV(const SCEV *A,
|
|
|
|
const SCEV *B,
|
|
|
|
Subscript *S) const {
|
|
|
|
return Unknown; // TODO: Implement.
|
|
|
|
}
|
|
|
|
|
2009-07-29 07:35:53 +02:00
|
|
|
LoopDependenceAnalysis::DependenceResult
|
|
|
|
LoopDependenceAnalysis::analyseSubscript(const SCEV *A,
|
|
|
|
const SCEV *B,
|
|
|
|
Subscript *S) const {
|
2009-12-23 21:52:41 +01:00
|
|
|
DEBUG(dbgs() << " Testing subscript: " << *A << ", " << *B << "\n");
|
2009-07-30 04:26:01 +02:00
|
|
|
|
|
|
|
if (A == B) {
|
2009-12-23 21:52:41 +01:00
|
|
|
DEBUG(dbgs() << " -> [D] same SCEV\n");
|
2009-07-30 04:26:01 +02:00
|
|
|
return Dependent;
|
|
|
|
}
|
|
|
|
|
2009-08-03 03:03:48 +02:00
|
|
|
if (!isAffine(A) || !isAffine(B)) {
|
2009-12-23 21:52:41 +01:00
|
|
|
DEBUG(dbgs() << " -> [?] not affine\n");
|
2009-08-03 03:03:48 +02:00
|
|
|
return Unknown;
|
|
|
|
}
|
|
|
|
|
2009-08-05 06:26:05 +02:00
|
|
|
if (isZIVPair(A, B))
|
|
|
|
return analyseZIV(A, B, S);
|
|
|
|
|
2009-08-07 20:23:41 +02:00
|
|
|
if (isSIVPair(A, B))
|
|
|
|
return analyseSIV(A, B, S);
|
2009-07-30 04:26:01 +02:00
|
|
|
|
2009-08-07 20:23:41 +02:00
|
|
|
return analyseMIV(A, B, S);
|
2009-07-29 07:35:53 +02:00
|
|
|
}
|
|
|
|
|
2009-07-28 21:50:13 +02:00
|
|
|
LoopDependenceAnalysis::DependenceResult
|
|
|
|
LoopDependenceAnalysis::analysePair(DependencePair *P) const {
|
2009-12-23 21:52:41 +01:00
|
|
|
DEBUG(dbgs() << "Analysing:\n" << *P->A << "\n" << *P->B << "\n");
|
2009-07-23 16:32:46 +02:00
|
|
|
|
|
|
|
// We only analyse loads and stores but no possible memory accesses by e.g.
|
|
|
|
// free, call, or invoke instructions.
|
|
|
|
if (!IsLoadOrStoreInst(P->A) || !IsLoadOrStoreInst(P->B)) {
|
2009-12-23 21:52:41 +01:00
|
|
|
DEBUG(dbgs() << "--> [?] no load/store\n");
|
2009-07-28 21:50:13 +02:00
|
|
|
return Unknown;
|
2009-07-23 16:32:46 +02:00
|
|
|
}
|
|
|
|
|
2009-07-28 21:49:25 +02:00
|
|
|
Value *aPtr = GetPointerOperand(P->A);
|
|
|
|
Value *bPtr = GetPointerOperand(P->B);
|
2009-07-01 23:45:23 +02:00
|
|
|
|
2009-07-28 21:49:25 +02:00
|
|
|
switch (UnderlyingObjectsAlias(AA, aPtr, bPtr)) {
|
|
|
|
case AliasAnalysis::MayAlias:
|
2010-12-10 21:14:49 +01:00
|
|
|
case AliasAnalysis::PartialAlias:
|
2009-07-28 21:49:25 +02:00
|
|
|
// We can not analyse objects if we do not know about their aliasing.
|
2009-12-23 21:52:41 +01:00
|
|
|
DEBUG(dbgs() << "---> [?] may alias\n");
|
2009-07-28 21:50:13 +02:00
|
|
|
return Unknown;
|
2009-06-30 04:12:10 +02:00
|
|
|
|
2009-07-28 21:49:25 +02:00
|
|
|
case AliasAnalysis::NoAlias:
|
|
|
|
// If the objects noalias, they are distinct, accesses are independent.
|
2009-12-23 21:52:41 +01:00
|
|
|
DEBUG(dbgs() << "---> [I] no alias\n");
|
2009-07-28 21:50:13 +02:00
|
|
|
return Independent;
|
2009-06-30 04:12:10 +02:00
|
|
|
|
2009-07-28 21:49:25 +02:00
|
|
|
case AliasAnalysis::MustAlias:
|
|
|
|
break; // The underlying objects alias, test accesses for dependence.
|
|
|
|
}
|
2009-07-01 23:45:23 +02:00
|
|
|
|
2009-07-29 07:35:53 +02:00
|
|
|
const GEPOperator *aGEP = dyn_cast<GEPOperator>(aPtr);
|
|
|
|
const GEPOperator *bGEP = dyn_cast<GEPOperator>(bPtr);
|
|
|
|
|
|
|
|
if (!aGEP || !bGEP)
|
|
|
|
return Unknown;
|
|
|
|
|
|
|
|
// FIXME: Is filtering coupled subscripts necessary?
|
|
|
|
|
2009-08-05 06:13:41 +02:00
|
|
|
// Collect GEP operand pairs (FIXME: use GetGEPOperands from BasicAA), adding
|
2009-07-29 07:35:53 +02:00
|
|
|
// trailing zeroes to the smaller GEP, if needed.
|
2009-08-05 06:13:41 +02:00
|
|
|
typedef SmallVector<std::pair<const SCEV*, const SCEV*>, 4> GEPOpdPairsTy;
|
|
|
|
GEPOpdPairsTy opds;
|
|
|
|
for(GEPOperator::const_op_iterator aIdx = aGEP->idx_begin(),
|
|
|
|
aEnd = aGEP->idx_end(),
|
|
|
|
bIdx = bGEP->idx_begin(),
|
|
|
|
bEnd = bGEP->idx_end();
|
|
|
|
aIdx != aEnd && bIdx != bEnd;
|
|
|
|
aIdx += (aIdx != aEnd), bIdx += (bIdx != bEnd)) {
|
2009-07-29 07:35:53 +02:00
|
|
|
const SCEV* aSCEV = (aIdx != aEnd) ? SE->getSCEV(*aIdx) : GetZeroSCEV(SE);
|
|
|
|
const SCEV* bSCEV = (bIdx != bEnd) ? SE->getSCEV(*bIdx) : GetZeroSCEV(SE);
|
2009-08-05 06:13:41 +02:00
|
|
|
opds.push_back(std::make_pair(aSCEV, bSCEV));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opds.empty() && opds[0].first != opds[0].second) {
|
|
|
|
// We cannot (yet) handle arbitrary GEP pointer offsets. By limiting
|
|
|
|
//
|
|
|
|
// TODO: this could be relaxed by adding the size of the underlying object
|
|
|
|
// to the first subscript. If we have e.g. (GEP x,0,i; GEP x,2,-i) and we
|
|
|
|
// know that x is a [100 x i8]*, we could modify the first subscript to be
|
|
|
|
// (i, 200-i) instead of (i, -i).
|
|
|
|
return Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now analyse the collected operand pairs (skipping the GEP ptr offsets).
|
|
|
|
for (GEPOpdPairsTy::const_iterator i = opds.begin() + 1, end = opds.end();
|
|
|
|
i != end; ++i) {
|
2009-07-29 07:35:53 +02:00
|
|
|
Subscript subscript;
|
2009-08-05 06:13:41 +02:00
|
|
|
DependenceResult result = analyseSubscript(i->first, i->second, &subscript);
|
2009-07-29 07:35:53 +02:00
|
|
|
if (result != Dependent) {
|
|
|
|
// We either proved independence or failed to analyse this subscript.
|
|
|
|
// Further subscripts will not improve the situation, so abort early.
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
P->Subscripts.push_back(subscript);
|
|
|
|
}
|
2009-08-05 06:13:41 +02:00
|
|
|
// We successfully analysed all subscripts but failed to prove independence.
|
2009-07-29 07:35:53 +02:00
|
|
|
return Dependent;
|
2009-07-23 16:32:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LoopDependenceAnalysis::depends(Value *A, Value *B) {
|
|
|
|
assert(isDependencePair(A, B) && "Values form no dependence pair!");
|
2009-07-28 21:49:49 +02:00
|
|
|
++NumAnswered;
|
2009-07-23 16:32:46 +02:00
|
|
|
|
|
|
|
DependencePair *p;
|
|
|
|
if (!findOrInsertDependencePair(A, B, p)) {
|
|
|
|
// The pair is not cached, so analyse it.
|
2009-07-28 21:49:49 +02:00
|
|
|
++NumAnalysed;
|
2009-07-28 21:50:13 +02:00
|
|
|
switch (p->Result = analysePair(p)) {
|
2009-07-28 21:49:49 +02:00
|
|
|
case Dependent: ++NumDependent; break;
|
|
|
|
case Independent: ++NumIndependent; break;
|
|
|
|
case Unknown: ++NumUnknown; break;
|
|
|
|
}
|
2009-07-23 16:32:46 +02:00
|
|
|
}
|
|
|
|
return p->Result != Independent;
|
2009-06-28 02:21:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-24 23:29:13 +02:00
|
|
|
// LoopDependenceAnalysis Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) {
|
|
|
|
this->L = L;
|
2009-07-01 23:45:23 +02:00
|
|
|
AA = &getAnalysis<AliasAnalysis>();
|
2009-06-24 23:29:13 +02:00
|
|
|
SE = &getAnalysis<ScalarEvolution>();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-23 16:32:46 +02:00
|
|
|
void LoopDependenceAnalysis::releaseMemory() {
|
|
|
|
Pairs.clear();
|
|
|
|
PairAllocator.Reset();
|
|
|
|
}
|
|
|
|
|
2009-06-24 23:29:13 +02:00
|
|
|
void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
2009-07-01 23:45:23 +02:00
|
|
|
AU.addRequiredTransitive<AliasAnalysis>();
|
2009-06-28 02:16:08 +02:00
|
|
|
AU.addRequiredTransitive<ScalarEvolution>();
|
|
|
|
}
|
|
|
|
|
2009-07-23 03:57:06 +02:00
|
|
|
static void PrintLoopInfo(raw_ostream &OS,
|
|
|
|
LoopDependenceAnalysis *LDA, const Loop *L) {
|
2009-06-28 02:16:08 +02:00
|
|
|
if (!L->empty()) return; // ignore non-innermost loops
|
|
|
|
|
2009-07-03 03:42:52 +02:00
|
|
|
SmallVector<Instruction*, 8> memrefs;
|
|
|
|
GetMemRefInstrs(L, memrefs);
|
|
|
|
|
2009-06-28 02:16:08 +02:00
|
|
|
OS << "Loop at depth " << L->getLoopDepth() << ", header block: ";
|
|
|
|
WriteAsOperand(OS, L->getHeader(), false);
|
|
|
|
OS << "\n";
|
2009-06-28 02:35:22 +02:00
|
|
|
|
|
|
|
OS << " Load/store instructions: " << memrefs.size() << "\n";
|
2009-07-03 03:42:52 +02:00
|
|
|
for (SmallVector<Instruction*, 8>::const_iterator x = memrefs.begin(),
|
2009-07-28 21:49:25 +02:00
|
|
|
end = memrefs.end(); x != end; ++x)
|
2009-07-23 03:57:06 +02:00
|
|
|
OS << "\t" << (x - memrefs.begin()) << ": " << **x << "\n";
|
2009-07-03 03:42:52 +02:00
|
|
|
|
2009-06-28 02:35:22 +02:00
|
|
|
OS << " Pairwise dependence results:\n";
|
|
|
|
for (SmallVector<Instruction*, 8>::const_iterator x = memrefs.begin(),
|
2009-07-28 21:49:25 +02:00
|
|
|
end = memrefs.end(); x != end; ++x)
|
2009-06-28 02:35:22 +02:00
|
|
|
for (SmallVector<Instruction*, 8>::const_iterator y = x + 1;
|
2009-07-28 21:49:25 +02:00
|
|
|
y != end; ++y)
|
2009-06-28 02:35:22 +02:00
|
|
|
if (LDA->isDependencePair(*x, *y))
|
|
|
|
OS << "\t" << (x - memrefs.begin()) << "," << (y - memrefs.begin())
|
|
|
|
<< ": " << (LDA->depends(*x, *y) ? "dependent" : "independent")
|
|
|
|
<< "\n";
|
2009-06-28 02:16:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoopDependenceAnalysis::print(raw_ostream &OS, const Module*) const {
|
2009-06-28 02:35:22 +02:00
|
|
|
// TODO: doc why const_cast is safe
|
|
|
|
PrintLoopInfo(OS, const_cast<LoopDependenceAnalysis*>(this), this->L);
|
2009-06-28 02:16:08 +02:00
|
|
|
}
|