blob: b23459e81ac76086a95167a6f7d3c63cca70cff8 [file] [log] [blame]
Andreas Bolka306b5b22009-06-24 21:29:13 +00001//===- LoopDependenceAnalysis.cpp - LDA Implementation ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is the (beginning) of an implementation of a loop dependence analysis
11// framework, which is used to detect dependences in memory accesses in loops.
12//
13// Please note that this is work in progress and the interface is subject to
14// change.
15//
16// TODO: adapt as implementation progresses.
17//
18//===----------------------------------------------------------------------===//
19
20#define DEBUG_TYPE "lda"
21#include "llvm/Analysis/LoopDependenceAnalysis.h"
22#include "llvm/Analysis/LoopPass.h"
23#include "llvm/Analysis/ScalarEvolution.h"
Andreas Bolkaf17ab7f2009-06-28 00:21:21 +000024#include "llvm/Instructions.h"
Andreas Bolka306b5b22009-06-24 21:29:13 +000025using namespace llvm;
26
27LoopPass *llvm::createLoopDependenceAnalysisPass() {
28 return new LoopDependenceAnalysis();
29}
30
31static RegisterPass<LoopDependenceAnalysis>
32R("lda", "Loop Dependence Analysis", false, true);
33char LoopDependenceAnalysis::ID = 0;
34
35//===----------------------------------------------------------------------===//
Andreas Bolkaf17ab7f2009-06-28 00:21:21 +000036// Utility Functions
37//===----------------------------------------------------------------------===//
38
39static inline bool isMemRefInstr(const Value *I) {
40 return isa<LoadInst>(I) || isa<StoreInst>(I);
41}
42
43//===----------------------------------------------------------------------===//
44// Dependence Testing
45//===----------------------------------------------------------------------===//
46
47bool LoopDependenceAnalysis::isDependencePair(const Value *x,
48 const Value *y) const {
49 return isMemRefInstr(x) && isMemRefInstr(y)
50 && (isa<StoreInst>(x) || isa<StoreInst>(y));
51}
52
53bool LoopDependenceAnalysis::depends(Value *src, Value *dst) {
54 assert(isDependencePair(src, dst) && "Values form no dependence pair!");
55 return true;
56}
57
58//===----------------------------------------------------------------------===//
Andreas Bolka306b5b22009-06-24 21:29:13 +000059// LoopDependenceAnalysis Implementation
60//===----------------------------------------------------------------------===//
61
62bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) {
63 this->L = L;
64 SE = &getAnalysis<ScalarEvolution>();
65 return false;
66}
67
68void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
69 AU.setPreservesAll();
Andreas Bolkab88ee912009-06-28 00:16:08 +000070 AU.addRequiredTransitive<ScalarEvolution>();
71}
72
73static void PrintLoopInfo(
74 raw_ostream &OS, const LoopDependenceAnalysis *LDA, const Loop *L) {
75 if (!L->empty()) return; // ignore non-innermost loops
76
77 OS << "Loop at depth " << L->getLoopDepth() << ", header block: ";
78 WriteAsOperand(OS, L->getHeader(), false);
79 OS << "\n";
80}
81
82void LoopDependenceAnalysis::print(raw_ostream &OS, const Module*) const {
83 PrintLoopInfo(OS, this, this->L);
84}
85
86void LoopDependenceAnalysis::print(std::ostream &OS, const Module *M) const {
87 raw_os_ostream os(OS);
88 print(os, M);
Andreas Bolka306b5b22009-06-24 21:29:13 +000089}