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"
26 LoopPass *llvm::createLoopDependenceAnalysisPass() {
27 return new LoopDependenceAnalysis();
30 static RegisterPass<LoopDependenceAnalysis>
31 R("lda", "Loop Dependence Analysis", false, true);
32 char LoopDependenceAnalysis::ID = 0;
34 //===----------------------------------------------------------------------===//
35 // LoopDependenceAnalysis Implementation
36 //===----------------------------------------------------------------------===//
38 bool LoopDependenceAnalysis::runOnLoop(Loop *L, LPPassManager &) {
40 SE = &getAnalysis<ScalarEvolution>();
44 void LoopDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
46 AU.addRequiredTransitive<ScalarEvolution>();
49 static void PrintLoopInfo(
50 raw_ostream &OS, const LoopDependenceAnalysis *LDA, const Loop *L) {
51 if (!L->empty()) return; // ignore non-innermost loops
53 OS << "Loop at depth " << L->getLoopDepth() << ", header block: ";
54 WriteAsOperand(OS, L->getHeader(), false);
58 void LoopDependenceAnalysis::print(raw_ostream &OS, const Module*) const {
59 PrintLoopInfo(OS, this, this->L);
62 void LoopDependenceAnalysis::print(std::ostream &OS, const Module *M) const {
63 raw_os_ostream os(OS);