1 //===- LoopDependenceAnalysis.cpp - LDA Implementation ----------*- 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 // 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.
13 // Please note that this is work in progress and the interface is subject to
16 // TODO: adapt as implementation progresses.
18 //===----------------------------------------------------------------------===//
20 #define DEBUG_TYPE "lda"
21 #include "llvm/Analysis/LoopDependenceAnalysis.h"
22 #include "llvm/Analysis/LoopPass.h"
23 #include "llvm/Analysis/ScalarEvolution.h"
24 #include "llvm/Instructions.h"
27 LoopPass *llvm::createLoopDependenceAnalysisPass() {
28 return new LoopDependenceAnalysis();
31 static RegisterPass<LoopDependenceAnalysis>
32 R("lda", "Loop Dependence Analysis", false, true);
33 char LoopDependenceAnalysis::ID = 0;
35 //===----------------------------------------------------------------------===//
37 //===----------------------------------------------------------------------===//
39 static inline bool isMemRefInstr(const Value *I) {
40 return isa<LoadInst>(I) || isa<StoreInst>(I);
43 //===----------------------------------------------------------------------===//
45 //===----------------------------------------------------------------------===//
47 bool LoopDependenceAnalysis::isDependencePair(const Value *x,
48 const Value *y) const {
49 return isMemRefInstr(x) && isMemRefInstr(y)
50 && (isa<StoreInst>(x) || isa<StoreInst>(y));
53 bool LoopDependenceAnalysis::depends(Value *src, Value *dst) {
54 assert(isDependencePair(src, dst) && "Values form no dependence pair!");
58 //===----------------------------------------------------------------------===//
59 // LoopDependenceAnalysis Implementation
60 //===----------------------------------------------------------------------===//
62 bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) {
64 SE = &getAnalysis<ScalarEvolution>();
68 void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
70 AU.addRequiredTransitive<ScalarEvolution>();
73 static void PrintLoopInfo(
74 raw_ostream &OS, const LoopDependenceAnalysis *LDA, const Loop *L) {
75 if (!L->empty()) return; // ignore non-innermost loops
77 OS << "Loop at depth " << L->getLoopDepth() << ", header block: ";
78 WriteAsOperand(OS, L->getHeader(), false);
82 void LoopDependenceAnalysis::print(raw_ostream &OS, const Module*) const {
83 PrintLoopInfo(OS, this, this->L);
86 void LoopDependenceAnalysis::print(std::ostream &OS, const Module *M) const {
87 raw_os_ostream os(OS);