mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Reimplement the internal abstraction used by MemDep in terms
of a pointer/int pair instead of a manually bitmangled pointer. This forces clients to think a little more about checking the appropriate pieces and will be useful for internal implementation improvements later. I'm not particularly happy with this. After going through this I don't think that the clients of memdep should be exposed to the internal type at all. I'll fix this in a subsequent commit. This has no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60230 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/PointerIntPair.h"
|
||||
|
||||
namespace llvm {
|
||||
class Function;
|
||||
@@ -29,38 +30,54 @@ namespace llvm {
|
||||
/// It builds on alias analysis information, and tries to provide a lazy,
|
||||
/// caching interface to a common kind of alias information query.
|
||||
class MemoryDependenceAnalysis : public FunctionPass {
|
||||
public:
|
||||
/// DepType - This enum is used to indicate what flavor of dependence this
|
||||
/// is. If the type is Normal, there is an associated instruction pointer.
|
||||
enum DepType {
|
||||
/// Normal - This is a normal instruction dependence. The pointer member
|
||||
/// of the DepResultTy pair holds the instruction.
|
||||
Normal = 0,
|
||||
|
||||
/// None - This dependence type indicates that the query does not depend
|
||||
/// on any instructions, either because it scanned to the start of the
|
||||
/// function or it scanned to the definition of the memory
|
||||
/// (alloca/malloc).
|
||||
None,
|
||||
|
||||
/// NonLocal - This marker indicates that the query has no dependency in
|
||||
/// the specified block. To find out more, the client should query other
|
||||
/// predecessor blocks.
|
||||
NonLocal,
|
||||
|
||||
/// Dirty - This is an internal marker indicating that that a cache entry
|
||||
/// is dirty.
|
||||
Dirty
|
||||
};
|
||||
typedef PointerIntPair<Instruction*, 2, DepType> DepResultTy;
|
||||
private:
|
||||
// A map from instructions to their dependency, with a boolean
|
||||
// flags for whether this mapping is confirmed or not.
|
||||
typedef DenseMap<Instruction*, std::pair<Instruction*, bool> > depMapType;
|
||||
depMapType depGraphLocal;
|
||||
typedef DenseMap<Instruction*,
|
||||
std::pair<DepResultTy, bool> > LocalDepMapType;
|
||||
LocalDepMapType LocalDeps;
|
||||
|
||||
// A map from instructions to their non-local dependencies.
|
||||
typedef DenseMap<Instruction*,
|
||||
DenseMap<BasicBlock*, Value*> > nonLocalDepMapType;
|
||||
DenseMap<BasicBlock*, DepResultTy> > nonLocalDepMapType;
|
||||
nonLocalDepMapType depGraphNonLocal;
|
||||
|
||||
// A reverse mapping from dependencies to the dependees. This is
|
||||
// used when removing instructions to keep the cache coherent.
|
||||
typedef DenseMap<Value*, SmallPtrSet<Instruction*, 4> > reverseDepMapType;
|
||||
typedef DenseMap<DepResultTy,
|
||||
SmallPtrSet<Instruction*, 4> > reverseDepMapType;
|
||||
reverseDepMapType reverseDep;
|
||||
|
||||
// A reverse mapping form dependencies to the non-local dependees.
|
||||
reverseDepMapType reverseDepNonLocal;
|
||||
|
||||
public:
|
||||
// Special marker indicating that the query has no dependency
|
||||
// in the specified block.
|
||||
static Instruction* const NonLocal;
|
||||
|
||||
// Special marker indicating that the query has no dependency at all
|
||||
static Instruction* const None;
|
||||
|
||||
// Special marker indicating a dirty cache entry
|
||||
static Instruction* const Dirty;
|
||||
|
||||
static char ID; // Class identification, replacement for typeinfo
|
||||
MemoryDependenceAnalysis() : FunctionPass(&ID) {}
|
||||
static char ID;
|
||||
|
||||
/// Pass Implementation stuff. This doesn't do any analysis.
|
||||
///
|
||||
@@ -68,7 +85,7 @@ namespace llvm {
|
||||
|
||||
/// Clean up memory in between runs
|
||||
void releaseMemory() {
|
||||
depGraphLocal.clear();
|
||||
LocalDeps.clear();
|
||||
depGraphNonLocal.clear();
|
||||
reverseDep.clear();
|
||||
reverseDepNonLocal.clear();
|
||||
@@ -81,33 +98,33 @@ namespace llvm {
|
||||
|
||||
/// getDependency - Return the instruction on which a memory operation
|
||||
/// depends, starting with start.
|
||||
Instruction* getDependency(Instruction* query, Instruction* start = 0,
|
||||
BasicBlock* block = 0);
|
||||
DepResultTy getDependency(Instruction *query, Instruction *start = 0,
|
||||
BasicBlock *block = 0);
|
||||
|
||||
/// 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.
|
||||
void getNonLocalDependency(Instruction* query,
|
||||
DenseMap<BasicBlock*, Value*>& resp);
|
||||
DenseMap<BasicBlock*, DepResultTy> &resp);
|
||||
|
||||
/// removeInstruction - Remove an instruction from the dependence analysis,
|
||||
/// updating the dependence of instructions that previously depended on it.
|
||||
void removeInstruction(Instruction* rem);
|
||||
void removeInstruction(Instruction *InstToRemove);
|
||||
|
||||
/// 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);
|
||||
void dropInstruction(Instruction *InstToDrop);
|
||||
|
||||
private:
|
||||
/// verifyRemoved - Verify that the specified instruction does not occur
|
||||
/// in our internal data structures.
|
||||
void verifyRemoved(Instruction *Inst) const;
|
||||
|
||||
Instruction* getCallSiteDependency(CallSite C, Instruction* start,
|
||||
BasicBlock* block);
|
||||
DepResultTy getCallSiteDependency(CallSite C, Instruction* start,
|
||||
BasicBlock* block);
|
||||
void nonLocalHelper(Instruction* query, BasicBlock* block,
|
||||
DenseMap<BasicBlock*, Value*>& resp);
|
||||
DenseMap<BasicBlock*, DepResultTy>& resp);
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
Reference in New Issue
Block a user