MemoryDependenceAnalysis.h revision 9a193fd8ae630478123938e12b56f84c5b2227b9
178e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson//===- llvm/Analysis/MemoryDependenceAnalysis.h - Memory Deps --*- C++ -*-===// 278e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson// 378e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson// The LLVM Compiler Infrastructure 478e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 778e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson// 878e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson//===----------------------------------------------------------------------===// 978e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson// 10e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner// This file defines the MemoryDependenceAnalysis analysis pass. 1178e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson// 1278e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson//===----------------------------------------------------------------------===// 1378e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 1478e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson#ifndef LLVM_ANALYSIS_MEMORY_DEPENDENCE_H 1578e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson#define LLVM_ANALYSIS_MEMORY_DEPENDENCE_H 1678e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 175391a1d8046396fb4dd005b1910973789f5427f4Chris Lattner#include "llvm/BasicBlock.h" 1878e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson#include "llvm/Pass.h" 1978e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson#include "llvm/ADT/DenseMap.h" 204beedbd0063a8ba6f97db02c3c94707d8ab45b50Owen Anderson#include "llvm/ADT/SmallPtrSet.h" 2139f372e23e49cecb8db2eb7120eb331173e50c74Chris Lattner#include "llvm/ADT/PointerIntPair.h" 2278e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 2378e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Andersonnamespace llvm { 24e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner class Function; 25e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner class FunctionPass; 26e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner class Instruction; 27b390b1728e6c36f1f28d75d6f8f27cb91f8a8c56Chris Lattner class CallSite; 28d777d405cdda8d418ba8e8818e5c1272dfd999a0Chris Lattner class AliasAnalysis; 29d777d405cdda8d418ba8e8818e5c1272dfd999a0Chris Lattner class TargetData; 30fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner class MemoryDependenceAnalysis; 314c724006256032e827177afeae04ea62436796e7Chris Lattner 324c724006256032e827177afeae04ea62436796e7Chris Lattner /// MemDepResult - A memory dependence query can return one of three different 33fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// answers, described below. 344c724006256032e827177afeae04ea62436796e7Chris Lattner class MemDepResult { 354c724006256032e827177afeae04ea62436796e7Chris Lattner enum DepType { 36fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// Invalid - Clients of MemDep never see this. 37fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner Invalid = 0, 380f41ad3bc9a295332a8e6d025b42cebc9b9e8125Chris Lattner 39b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// Clobber - This is a dependence on the specified instruction which 40b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// clobbers the desired value. The pointer member of the MemDepResult 41b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// pair holds the instruction that clobbers the memory. For example, 42b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// this occurs when we see a may-aliased store to the memory location we 43b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// care about. 44b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner Clobber, 45fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner 46b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// Def - This is a dependence on the specified instruction which 47b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// defines/produces the desired memory location. The pointer member of 48b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// the MemDepResult pair holds the instruction that defines the memory. 49b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// Cases of interest: 50b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// 1. This could be a load or store for dependence queries on 51b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// load/store. The value loaded or stored is the produced value. 52b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// Note that the pointer operand may be different than that of the 53b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// queried pointer due to must aliases and phi translation. Note 54b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// that the def may not be the same type as the query, the pointers 55b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// may just be must aliases. 56b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// 2. For loads and stores, this could be an allocation instruction. In 57b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// this case, the load is loading an undef value or a store is the 58b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// first store to (that part of) the allocation. 59b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// 3. Dependence queries on calls return Def only when they are 60b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// readonly calls with identical callees and no intervening 61b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// clobbers. No validation is done that the operands to the calls 62b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// are the same. 63b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner Def, 64b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner 65fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// NonLocal - This marker indicates that the query has no dependency in 66fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// the specified block. To find out more, the client should query other 67fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// predecessor blocks. 68b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner NonLocal 694c724006256032e827177afeae04ea62436796e7Chris Lattner }; 704c724006256032e827177afeae04ea62436796e7Chris Lattner typedef PointerIntPair<Instruction*, 2, DepType> PairTy; 714c724006256032e827177afeae04ea62436796e7Chris Lattner PairTy Value; 724c724006256032e827177afeae04ea62436796e7Chris Lattner explicit MemDepResult(PairTy V) : Value(V) {} 734c724006256032e827177afeae04ea62436796e7Chris Lattner public: 744c724006256032e827177afeae04ea62436796e7Chris Lattner MemDepResult() : Value(0, Invalid) {} 754c724006256032e827177afeae04ea62436796e7Chris Lattner 764c724006256032e827177afeae04ea62436796e7Chris Lattner /// get methods: These are static ctor methods for creating various 774c724006256032e827177afeae04ea62436796e7Chris Lattner /// MemDepResult kinds. 78b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner static MemDepResult getDef(Instruction *Inst) { 79b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner return MemDepResult(PairTy(Inst, Def)); 80b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner } 81b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner static MemDepResult getClobber(Instruction *Inst) { 82b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner return MemDepResult(PairTy(Inst, Clobber)); 834c724006256032e827177afeae04ea62436796e7Chris Lattner } 844c724006256032e827177afeae04ea62436796e7Chris Lattner static MemDepResult getNonLocal() { 854c724006256032e827177afeae04ea62436796e7Chris Lattner return MemDepResult(PairTy(0, NonLocal)); 864c724006256032e827177afeae04ea62436796e7Chris Lattner } 874c724006256032e827177afeae04ea62436796e7Chris Lattner 88b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// isClobber - Return true if this MemDepResult represents a query that is 89b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// a instruction clobber dependency. 90b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner bool isClobber() const { return Value.getInt() == Clobber; } 91b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner 92b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// isDef - Return true if this MemDepResult represents a query that is 93b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner /// a instruction definition dependency. 94b51deb929ca95ce62e622b0475a05d83f26ab04dChris Lattner bool isDef() const { return Value.getInt() == Def; } 954c724006256032e827177afeae04ea62436796e7Chris Lattner 964c724006256032e827177afeae04ea62436796e7Chris Lattner /// isNonLocal - Return true if this MemDepResult represents an query that 974c724006256032e827177afeae04ea62436796e7Chris Lattner /// is transparent to the start of the block, but where a non-local hasn't 984c724006256032e827177afeae04ea62436796e7Chris Lattner /// been done. 9986b29ef64a36c8779ef7855b3c4b95744eb2f08bChris Lattner bool isNonLocal() const { return Value.getInt() == NonLocal; } 1004c724006256032e827177afeae04ea62436796e7Chris Lattner 1014c724006256032e827177afeae04ea62436796e7Chris Lattner /// getInst() - If this is a normal dependency, return the instruction that 1024c724006256032e827177afeae04ea62436796e7Chris Lattner /// is depended on. Otherwise, return null. 103fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner Instruction *getInst() const { return Value.getPointer(); } 1044c724006256032e827177afeae04ea62436796e7Chris Lattner 105bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner bool operator==(const MemDepResult &M) const { return M.Value == Value; } 106bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner bool operator!=(const MemDepResult &M) const { return M.Value != Value; } 107bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner bool operator<(const MemDepResult &M) const { return M.Value < Value; } 108bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner bool operator>(const MemDepResult &M) const { return M.Value > Value; } 109fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner private: 110fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner friend class MemoryDependenceAnalysis; 111fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// Dirty - Entries with this marker occur in a LocalDeps map or 112fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// NonLocalDeps map when the instruction they previously referenced was 113fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// removed from MemDep. In either case, the entry may include an 114fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// instruction pointer. If so, the pointer is an instruction in the 115fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// block where scanning can start from, saving some work. 116fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// 117bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner /// In a default-constructed MemDepResult object, the type will be Dirty 118fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// and the instruction pointer will be null. 119fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// 120bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner 121fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// isDirty - Return true if this is a MemDepResult in its dirty/invalid. 122fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner /// state. 123fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner bool isDirty() const { return Value.getInt() == Invalid; } 124bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner 125fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner static MemDepResult getDirty(Instruction *Inst) { 126fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner return MemDepResult(PairTy(Inst, Invalid)); 127fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner } 1284c724006256032e827177afeae04ea62436796e7Chris Lattner }; 12978e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 130e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner /// MemoryDependenceAnalysis - This is an analysis that determines, for a 131e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner /// given memory operation, what preceding memory operations it depends on. 132e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner /// It builds on alias analysis information, and tries to provide a lazy, 133e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner /// caching interface to a common kind of alias information query. 1340e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// 1350e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// The dependency information returned is somewhat unusual, but is pragmatic. 1360e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// If queried about a store or call that might modify memory, the analysis 1370e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// will return the instruction[s] that may either load from that memory or 1380e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// store to it. If queried with a load or call that can never modify memory, 1390e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// the analysis will return calls and stores that might modify the pointer, 1400e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// but generally does not return loads unless a) they are volatile, or 1410e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// b) they load from *must-aliased* pointers. Returning a dependence on 1420e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// must-alias'd pointers instead of all pointers interacts well with the 1430e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// internal caching mechanism. 1440e0a5b690ca772a9002d8e8d21edac5f011bc7e8Chris Lattner /// 145e85866313a551fa3d4e2f118c3bf34e96af36763Chris Lattner class MemoryDependenceAnalysis : public FunctionPass { 1467f52422a3c821c1deb7171808ffcf83386970791Chris Lattner // A map from instructions to their dependency. 147fd3dcbea06f934572a3ba02821b1485eb7a073aaChris Lattner typedef DenseMap<Instruction*, MemDepResult> LocalDepMapType; 14839f372e23e49cecb8db2eb7120eb331173e50c74Chris Lattner LocalDepMapType LocalDeps; 149df464195fe049d5ea921e2e37f4f833c2ea4e3ecDavid Greene 150bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner public: 151bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner typedef std::pair<BasicBlock*, MemDepResult> NonLocalDepEntry; 152bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner typedef std::vector<NonLocalDepEntry> NonLocalDepInfo; 153bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner private: 1549a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner 1554a69bade2385022ca776edc22150f3b750cdf23cChris Lattner /// PerInstNLInfo - This is the instruction we keep for each cached access 1564a69bade2385022ca776edc22150f3b750cdf23cChris Lattner /// that we have for an instruction. The pointer is an owning pointer and 1574a69bade2385022ca776edc22150f3b750cdf23cChris Lattner /// the bool indicates whether we have any dirty bits in the set. 158bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner typedef std::pair<NonLocalDepInfo, bool> PerInstNLInfo; 15925f4b2b7a3f1f2bbaf954257e7834ba29a6ede7cChris Lattner 1604d13de4e3bfc5121207efd01e1b31caa6bb4e40bOwen Anderson // A map from instructions to their non-local dependencies. 1614a69bade2385022ca776edc22150f3b750cdf23cChris Lattner typedef DenseMap<Instruction*, PerInstNLInfo> NonLocalDepMapType; 1624a69bade2385022ca776edc22150f3b750cdf23cChris Lattner 1638c4652790e04515f34cf920b0783d6ec4161a313Chris Lattner NonLocalDepMapType NonLocalDeps; 1644d13de4e3bfc5121207efd01e1b31caa6bb4e40bOwen Anderson 165956033a4f5de491fcc07bc3ef0700ad22fd836a0Chris Lattner // A reverse mapping from dependencies to the dependees. This is 166179463c0d4c20bfb2c6b1e697eed6f16305a201eOwen Anderson // used when removing instructions to keep the cache coherent. 1677f52422a3c821c1deb7171808ffcf83386970791Chris Lattner typedef DenseMap<Instruction*, 1688c4652790e04515f34cf920b0783d6ec4161a313Chris Lattner SmallPtrSet<Instruction*, 4> > ReverseDepMapType; 1698c4652790e04515f34cf920b0783d6ec4161a313Chris Lattner ReverseDepMapType ReverseLocalDeps; 17078e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 1714d13de4e3bfc5121207efd01e1b31caa6bb4e40bOwen Anderson // A reverse mapping form dependencies to the non-local dependees. 1728c4652790e04515f34cf920b0783d6ec4161a313Chris Lattner ReverseDepMapType ReverseNonLocalDeps; 1734d13de4e3bfc5121207efd01e1b31caa6bb4e40bOwen Anderson 174d777d405cdda8d418ba8e8818e5c1272dfd999a0Chris Lattner /// Current AA implementation, just a cache. 175d777d405cdda8d418ba8e8818e5c1272dfd999a0Chris Lattner AliasAnalysis *AA; 176d777d405cdda8d418ba8e8818e5c1272dfd999a0Chris Lattner TargetData *TD; 177179463c0d4c20bfb2c6b1e697eed6f16305a201eOwen Anderson public: 178ae73dc1448d25b02cabc7c64c86c64371453dda8Dan Gohman MemoryDependenceAnalysis() : FunctionPass(&ID) {} 17939f372e23e49cecb8db2eb7120eb331173e50c74Chris Lattner static char ID; 1801cee94f04111cfd7114979d6dfddce2669c9380dDevang Patel 181d777d405cdda8d418ba8e8818e5c1272dfd999a0Chris Lattner /// Pass Implementation stuff. This doesn't do any analysis eagerly. 182d777d405cdda8d418ba8e8818e5c1272dfd999a0Chris Lattner bool runOnFunction(Function &); 1836b278fc7860c1e0e5cf72340e43f78a87159be4cOwen Anderson 1846b278fc7860c1e0e5cf72340e43f78a87159be4cOwen Anderson /// Clean up memory in between runs 1856b278fc7860c1e0e5cf72340e43f78a87159be4cOwen Anderson void releaseMemory() { 18639f372e23e49cecb8db2eb7120eb331173e50c74Chris Lattner LocalDeps.clear(); 187bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner NonLocalDeps.clear(); 1888c4652790e04515f34cf920b0783d6ec4161a313Chris Lattner NonLocalDeps.clear(); 1898c4652790e04515f34cf920b0783d6ec4161a313Chris Lattner ReverseLocalDeps.clear(); 1908c4652790e04515f34cf920b0783d6ec4161a313Chris Lattner ReverseNonLocalDeps.clear(); 19178e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson } 19278e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 19378e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson /// getAnalysisUsage - Does not modify anything. It uses Value Numbering 19478e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson /// and Alias Analysis. 19578e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson /// 19678e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson virtual void getAnalysisUsage(AnalysisUsage &AU) const; 19778e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 19878e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson /// getDependency - Return the instruction on which a memory operation 1996951381995f24dc9c7bbcacefd5a1315784f66f3Chris Lattner /// depends. See the class comment for more details. It is illegal to call 2006951381995f24dc9c7bbcacefd5a1315784f66f3Chris Lattner /// this on non-memory instructions. 2015391a1d8046396fb4dd005b1910973789f5427f4Chris Lattner MemDepResult getDependency(Instruction *QueryInst); 2025391a1d8046396fb4dd005b1910973789f5427f4Chris Lattner 20386b29ef64a36c8779ef7855b3c4b95744eb2f08bChris Lattner /// getNonLocalDependency - Perform a full dependency query for the 20486b29ef64a36c8779ef7855b3c4b95744eb2f08bChris Lattner /// specified instruction, returning the set of blocks that the value is 20586b29ef64a36c8779ef7855b3c4b95744eb2f08bChris Lattner /// potentially live across. The returned set of results will include a 20686b29ef64a36c8779ef7855b3c4b95744eb2f08bChris Lattner /// "NonLocal" result for all blocks where the value is live across. 20786b29ef64a36c8779ef7855b3c4b95744eb2f08bChris Lattner /// 208bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner /// This method assumes the instruction returns a "NonLocal" dependency 20986b29ef64a36c8779ef7855b3c4b95744eb2f08bChris Lattner /// within its own block. 210bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner /// 211bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner /// This returns a reference to an internal data structure that may be 212bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner /// invalidated on the next non-local query or when an instruction is 213bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner /// removed. Clients must copy this data if they want it around longer than 214bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner /// that. 215bf145d6e2ba01f5099ccaa1b58ed3619406928a0Chris Lattner const NonLocalDepInfo &getNonLocalDependency(Instruction *QueryInst); 21678e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 2177ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner 2187ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner /// getNonLocalPointerDependency - Perform a full dependency query for an 2197ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner /// access to the specified (non-volatile) memory location, returning the 2207ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner /// set of instructions that either define or clobber the value. 2217ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner /// 2229a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner /// This method assumes the pointer has a "NonLocal" dependency within BB. 2237ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner void getNonLocalPointerDependency(Value *Pointer, bool isLoad, 2247ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner BasicBlock *BB, 2257ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner SmallVectorImpl<NonLocalDepEntry> &Result); 2267ebcf0324668b7c6ba48832d5d8df95689a8d837Chris Lattner 22778e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson /// removeInstruction - Remove an instruction from the dependence analysis, 22878e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson /// updating the dependence of instructions that previously depended on it. 22939f372e23e49cecb8db2eb7120eb331173e50c74Chris Lattner void removeInstruction(Instruction *InstToRemove); 230179463c0d4c20bfb2c6b1e697eed6f16305a201eOwen Anderson 231179463c0d4c20bfb2c6b1e697eed6f16305a201eOwen Anderson private: 232aea5a2a22ad5fa030bb77899f79d9aa27a8b6a88Chris Lattner 233e79be944c8ced0a0cb80ede8cb9f97e4fdc6778fChris Lattner /// getDependencyFrom - Return the instruction on which the memory location 234e79be944c8ced0a0cb80ede8cb9f97e4fdc6778fChris Lattner /// '*Pointer' depends. This starts scanning from the instruction before 235aea5a2a22ad5fa030bb77899f79d9aa27a8b6a88Chris Lattner /// the position indicated by ScanIt. 236e79be944c8ced0a0cb80ede8cb9f97e4fdc6778fChris Lattner MemDepResult getPointerDependencyFrom(Value *Pointer, uint64_t MemSize, 237e79be944c8ced0a0cb80ede8cb9f97e4fdc6778fChris Lattner bool isLoad, 238e79be944c8ced0a0cb80ede8cb9f97e4fdc6778fChris Lattner BasicBlock::iterator ScanIt, 239e79be944c8ced0a0cb80ede8cb9f97e4fdc6778fChris Lattner BasicBlock *BB); 2408ef57c5faf77890828ac439482420646b2a0beb8Chris Lattner MemDepResult getCallSiteDependencyFrom(CallSite C, 2418ef57c5faf77890828ac439482420646b2a0beb8Chris Lattner BasicBlock::iterator ScanIt, 2428ef57c5faf77890828ac439482420646b2a0beb8Chris Lattner BasicBlock *BB); 243aea5a2a22ad5fa030bb77899f79d9aa27a8b6a88Chris Lattner 2449a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner void getNonLocalPointerDepInternal(Value *Pointer, uint64_t Size, 2459a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner bool isLoad, BasicBlock *BB, 2469a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner SmallVectorImpl<NonLocalDepEntry> &Result, 2479a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner SmallPtrSet<BasicBlock*, 64> &Visited); 2489a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner 2499a193fd8ae630478123938e12b56f84c5b2227b9Chris Lattner 2508b589fa135d873e683b29ed0918638a79272f5d2Chris Lattner /// verifyRemoved - Verify that the specified instruction does not occur 2518b589fa135d873e683b29ed0918638a79272f5d2Chris Lattner /// in our internal data structures. 2528b589fa135d873e683b29ed0918638a79272f5d2Chris Lattner void verifyRemoved(Instruction *Inst) const; 2538b589fa135d873e683b29ed0918638a79272f5d2Chris Lattner 25478e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson }; 25578e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 25678e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson} // End llvm namespace 25778e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson 25878e02f78ce68274163e1e63be59abd17aaaf6cbfOwen Anderson#endif 259