1 //===- llvm/Analysis/MemoryDependenceAnalysis.h - Memory Deps --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the Owen Anderson and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines an analysis that determines, for a given memory operation,
11 // what preceding memory operations it depends on. It builds on alias analysis
12 // information, and tries to provide a lazy, caching interface to a common kind
13 // of alias information query.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_ANALYSIS_MEMORY_DEPENDENCE_H
18 #define LLVM_ANALYSIS_MEMORY_DEPENDENCE_H
20 #include "llvm/Pass.h"
21 #include "llvm/Support/CallSite.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SmallPtrSet.h"
24 #include "llvm/Support/Compiler.h"
32 class MemoryDependenceAnalysis : public FunctionPass {
34 // A map from instructions to their dependency, with a boolean
35 // flags for whether this mapping is confirmed or not
36 typedef DenseMap<Instruction*, std::pair<Instruction*, bool> >
38 depMapType depGraphLocal;
40 // A map from instructions to their non-local dependencies.
41 typedef DenseMap<Instruction*, DenseMap<BasicBlock*, Value*> >
43 nonLocalDepMapType depGraphNonLocal;
45 // A reverse mapping form dependencies to the dependees. This is
46 // used when removing instructions to keep the cache coherent.
47 typedef DenseMap<Value*, SmallPtrSet<Instruction*, 4> >
49 reverseDepMapType reverseDep;
51 // A reverse mapping form dependencies to the non-local dependees.
52 reverseDepMapType reverseDepNonLocal;
55 // Special marker indicating that the query has no dependency
56 // in the specified block.
57 static Instruction* const NonLocal;
59 // Special marker indicating that the query has no dependency at all
60 static Instruction* const None;
62 static char ID; // Class identification, replacement for typeinfo
63 MemoryDependenceAnalysis() : FunctionPass((intptr_t)&ID) {}
65 /// Pass Implementation stuff. This doesn't do any analysis.
67 bool runOnFunction(Function &) {return false; }
69 /// Clean up memory in between runs
70 void releaseMemory() {
71 depGraphLocal.clear();
72 depGraphNonLocal.clear();
74 reverseDepNonLocal.clear();
77 /// getAnalysisUsage - Does not modify anything. It uses Value Numbering
78 /// and Alias Analysis.
80 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
82 /// getDependency - Return the instruction on which a memory operation
83 /// depends, starting with start.
84 Instruction* getDependency(Instruction* query, Instruction* start = 0,
85 BasicBlock* block = 0);
87 /// getNonLocalDependency - Fills the passed-in map with the non-local
88 /// dependencies of the queries. The map will contain NonLocal for
89 /// blocks between the query and its dependencies.
90 void getNonLocalDependency(Instruction* query,
91 DenseMap<BasicBlock*, Value*>& resp);
93 /// removeInstruction - Remove an instruction from the dependence analysis,
94 /// updating the dependence of instructions that previously depended on it.
95 void removeInstruction(Instruction* rem);
98 Instruction* getCallSiteDependency(CallSite C, Instruction* start,
100 void nonLocalHelper(Instruction* query, BasicBlock* block,
101 DenseMap<BasicBlock*, Value*>& resp);
104 } // End llvm namespace