2007-07-06 23:14:35 +00:00
|
|
|
//===- llvm/Analysis/MemoryDependenceAnalysis.h - Memory Deps --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-06 23:14:35 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines an analysis that determines, for a given memory operation,
|
|
|
|
// what preceding memory operations it depends on. It builds on alias analysis
|
|
|
|
// information, and tries to provide a lazy, caching interface to a common kind
|
|
|
|
// of alias information query.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_MEMORY_DEPENDENCE_H
|
|
|
|
#define LLVM_ANALYSIS_MEMORY_DEPENDENCE_H
|
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
2007-07-10 17:59:22 +00:00
|
|
|
#include "llvm/Support/CallSite.h"
|
2007-07-06 23:14:35 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-07-24 21:52:37 +00:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2007-07-06 23:14:35 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Function;
|
|
|
|
class FunctionPass;
|
|
|
|
class Instruction;
|
|
|
|
|
2007-07-10 17:08:11 +00:00
|
|
|
class MemoryDependenceAnalysis : public FunctionPass {
|
2007-07-06 23:14:35 +00:00
|
|
|
private:
|
2007-08-08 21:53:20 +00:00
|
|
|
// A map from instructions to their dependency, with a boolean
|
|
|
|
// flags for whether this mapping is confirmed or not
|
2007-08-09 04:42:44 +00:00
|
|
|
typedef DenseMap<Instruction*, std::pair<Instruction*, bool> >
|
2007-08-08 21:53:20 +00:00
|
|
|
depMapType;
|
2007-07-31 20:01:27 +00:00
|
|
|
depMapType depGraphLocal;
|
|
|
|
|
2007-08-16 21:27:05 +00:00
|
|
|
// A map from instructions to their non-local dependencies.
|
|
|
|
typedef DenseMap<Instruction*, DenseMap<BasicBlock*, Value*> >
|
|
|
|
nonLocalDepMapType;
|
|
|
|
nonLocalDepMapType depGraphNonLocal;
|
|
|
|
|
2007-08-08 21:53:20 +00:00
|
|
|
// A reverse mapping form dependencies to the dependees. This is
|
|
|
|
// used when removing instructions to keep the cache coherent.
|
2007-08-16 21:27:05 +00:00
|
|
|
typedef DenseMap<Value*, SmallPtrSet<Instruction*, 4> >
|
2007-08-08 21:53:20 +00:00
|
|
|
reverseDepMapType;
|
2007-07-31 20:01:27 +00:00
|
|
|
reverseDepMapType reverseDep;
|
2007-07-06 23:14:35 +00:00
|
|
|
|
2007-08-16 21:27:05 +00:00
|
|
|
// A reverse mapping form dependencies to the non-local dependees.
|
|
|
|
reverseDepMapType reverseDepNonLocal;
|
|
|
|
|
2007-08-08 21:53:20 +00:00
|
|
|
public:
|
2007-12-08 01:37:09 +00:00
|
|
|
void ping(Instruction* D);
|
|
|
|
|
2007-08-08 21:53:20 +00:00
|
|
|
// Special marker indicating that the query has no dependency
|
|
|
|
// in the specified block.
|
2007-08-09 04:42:44 +00:00
|
|
|
static Instruction* const NonLocal;
|
2007-08-08 21:53:20 +00:00
|
|
|
|
|
|
|
// Special marker indicating that the query has no dependency at all
|
2007-08-09 04:42:44 +00:00
|
|
|
static Instruction* const None;
|
2007-07-06 23:14:35 +00:00
|
|
|
|
2007-09-19 16:13:57 +00:00
|
|
|
|
|
|
|
// Special marker indicating a dirty cache entry
|
|
|
|
static Instruction* const Dirty;
|
|
|
|
|
2007-07-06 23:14:35 +00:00
|
|
|
static char ID; // Class identification, replacement for typeinfo
|
2008-09-04 17:05:41 +00:00
|
|
|
MemoryDependenceAnalysis() : FunctionPass(&ID) {}
|
2008-03-18 00:39:19 +00:00
|
|
|
|
2007-07-06 23:14:35 +00:00
|
|
|
/// Pass Implementation stuff. This doesn't do any analysis.
|
|
|
|
///
|
2007-07-10 17:08:11 +00:00
|
|
|
bool runOnFunction(Function &) {return false; }
|
|
|
|
|
|
|
|
/// Clean up memory in between runs
|
|
|
|
void releaseMemory() {
|
2007-07-06 23:14:35 +00:00
|
|
|
depGraphLocal.clear();
|
2007-08-16 21:27:05 +00:00
|
|
|
depGraphNonLocal.clear();
|
2007-07-06 23:14:35 +00:00
|
|
|
reverseDep.clear();
|
2007-08-16 21:27:05 +00:00
|
|
|
reverseDepNonLocal.clear();
|
2007-07-06 23:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getAnalysisUsage - Does not modify anything. It uses Value Numbering
|
|
|
|
/// and Alias Analysis.
|
|
|
|
///
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
|
|
|
|
|
|
|
/// getDependency - Return the instruction on which a memory operation
|
2007-07-16 21:52:50 +00:00
|
|
|
/// depends, starting with start.
|
2007-08-09 04:42:44 +00:00
|
|
|
Instruction* getDependency(Instruction* query, Instruction* start = 0,
|
2007-07-24 21:52:37 +00:00
|
|
|
BasicBlock* block = 0);
|
|
|
|
|
2007-08-08 21:54:33 +00:00
|
|
|
/// getNonLocalDependency - Fills the passed-in map with the non-local
|
|
|
|
/// dependencies of the queries. The map will contain NonLocal for
|
|
|
|
/// blocks between the query and its dependencies.
|
2007-08-01 22:01:54 +00:00
|
|
|
void getNonLocalDependency(Instruction* query,
|
2007-07-25 19:57:03 +00:00
|
|
|
DenseMap<BasicBlock*, Value*>& resp);
|
2007-07-06 23:14:35 +00:00
|
|
|
|
|
|
|
/// removeInstruction - Remove an instruction from the dependence analysis,
|
|
|
|
/// updating the dependence of instructions that previously depended on it.
|
|
|
|
void removeInstruction(Instruction* rem);
|
2007-08-08 21:53:20 +00:00
|
|
|
|
2008-02-12 21:15:18 +00:00
|
|
|
/// dropInstruction - Remove an instruction from the analysis, making
|
|
|
|
/// absolutely conservative assumptions when updating the cache. This is
|
|
|
|
/// useful, for example when an instruction is changed rather than removed.
|
|
|
|
void dropInstruction(Instruction* drop);
|
|
|
|
|
2007-08-08 21:53:20 +00:00
|
|
|
private:
|
2007-08-09 04:42:44 +00:00
|
|
|
Instruction* getCallSiteDependency(CallSite C, Instruction* start,
|
2007-08-08 21:53:20 +00:00
|
|
|
BasicBlock* block);
|
|
|
|
void nonLocalHelper(Instruction* query, BasicBlock* block,
|
|
|
|
DenseMap<BasicBlock*, Value*>& resp);
|
2007-07-06 23:14:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|