Some internal refactoring to make it easier to cache results.

llvm-svn: 60650
This commit is contained in:
Chris Lattner 2008-12-07 02:56:57 +00:00
parent 2faa2c724a
commit 7564a3b81b
2 changed files with 34 additions and 21 deletions

View File

@ -151,7 +151,7 @@ namespace llvm {
typedef std::pair<BasicBlock*, MemDepResult> NonLocalDepEntry; typedef std::pair<BasicBlock*, MemDepResult> NonLocalDepEntry;
typedef std::vector<NonLocalDepEntry> NonLocalDepInfo; typedef std::vector<NonLocalDepEntry> NonLocalDepInfo;
private: private:
/// PerInstNLInfo - This is the instruction we keep for each cached access /// PerInstNLInfo - This is the instruction we keep for each cached access
/// that we have for an instruction. The pointer is an owning pointer and /// that we have for an instruction. The pointer is an owning pointer and
/// the bool indicates whether we have any dirty bits in the set. /// the bool indicates whether we have any dirty bits in the set.
@ -219,9 +219,7 @@ namespace llvm {
/// access to the specified (non-volatile) memory location, returning the /// access to the specified (non-volatile) memory location, returning the
/// set of instructions that either define or clobber the value. /// set of instructions that either define or clobber the value.
/// ///
/// This method assumes the pointer has a "NonLocal" dependency within BB /// This method assumes the pointer has a "NonLocal" dependency within BB.
/// and assumes that Result is empty when you call it.
///
void getNonLocalPointerDependency(Value *Pointer, bool isLoad, void getNonLocalPointerDependency(Value *Pointer, bool isLoad,
BasicBlock *BB, BasicBlock *BB,
SmallVectorImpl<NonLocalDepEntry> &Result); SmallVectorImpl<NonLocalDepEntry> &Result);
@ -243,6 +241,12 @@ namespace llvm {
BasicBlock::iterator ScanIt, BasicBlock::iterator ScanIt,
BasicBlock *BB); BasicBlock *BB);
void getNonLocalPointerDepInternal(Value *Pointer, uint64_t Size,
bool isLoad, BasicBlock *BB,
SmallVectorImpl<NonLocalDepEntry> &Result,
SmallPtrSet<BasicBlock*, 64> &Visited);
/// verifyRemoved - Verify that the specified instruction does not occur /// verifyRemoved - Verify that the specified instruction does not occur
/// in our internal data structures. /// in our internal data structures.
void verifyRemoved(Instruction *Inst) const; void verifyRemoved(Instruction *Inst) const;

View File

@ -437,53 +437,62 @@ MemoryDependenceAnalysis::getNonLocalDependency(Instruction *QueryInst) {
void MemoryDependenceAnalysis:: void MemoryDependenceAnalysis::
getNonLocalPointerDependency(Value *Pointer, bool isLoad, BasicBlock *FromBB, getNonLocalPointerDependency(Value *Pointer, bool isLoad, BasicBlock *FromBB,
SmallVectorImpl<NonLocalDepEntry> &Result) { SmallVectorImpl<NonLocalDepEntry> &Result) {
Result.clear();
// We know that the pointer value is live into FromBB find the def/clobbers // We know that the pointer value is live into FromBB find the def/clobbers
// from presecessors. // from presecessors.
SmallVector<std::pair<BasicBlock*, Value*>, 32> Worklist;
for (pred_iterator PI = pred_begin(FromBB), E = pred_end(FromBB); PI != E;
++PI)
// TODO: PHI TRANSLATE.
Worklist.push_back(std::make_pair(*PI, Pointer));
const Type *EltTy = cast<PointerType>(Pointer->getType())->getElementType(); const Type *EltTy = cast<PointerType>(Pointer->getType())->getElementType();
uint64_t PointeeSize = TD->getTypeStoreSize(EltTy); uint64_t PointeeSize = TD->getTypeStoreSize(EltTy);
// While we have blocks to analyze, get their values. // While we have blocks to analyze, get their values.
SmallPtrSet<BasicBlock*, 64> Visited; SmallPtrSet<BasicBlock*, 64> Visited;
for (pred_iterator PI = pred_begin(FromBB), E = pred_end(FromBB); PI != E;
++PI) {
// TODO: PHI TRANSLATE.
getNonLocalPointerDepInternal(Pointer, PointeeSize, isLoad, *PI,
Result, Visited);
}
}
void MemoryDependenceAnalysis::
getNonLocalPointerDepInternal(Value *Pointer, uint64_t PointeeSize,
bool isLoad, BasicBlock *StartBB,
SmallVectorImpl<NonLocalDepEntry> &Result,
SmallPtrSet<BasicBlock*, 64> &Visited) {
SmallVector<BasicBlock*, 32> Worklist;
Worklist.push_back(StartBB);
while (!Worklist.empty()) { while (!Worklist.empty()) {
FromBB = Worklist.back().first; BasicBlock *BB = Worklist.pop_back_val();
Pointer = Worklist.back().second;
Worklist.pop_back();
// Analyze the dependency of *Pointer in FromBB. See if we already have // Analyze the dependency of *Pointer in FromBB. See if we already have
// been here. // been here.
if (!Visited.insert(FromBB)) if (!Visited.insert(BB))
continue; continue;
// FIXME: CACHE! // FIXME: CACHE!
MemDepResult Dep = MemDepResult Dep =
getPointerDependencyFrom(Pointer, PointeeSize, isLoad, getPointerDependencyFrom(Pointer, PointeeSize, isLoad, BB->end(), BB);
FromBB->end(), FromBB);
// If we got a Def or Clobber, add this to the list of results. // If we got a Def or Clobber, add this to the list of results.
if (!Dep.isNonLocal()) { if (!Dep.isNonLocal()) {
Result.push_back(NonLocalDepEntry(FromBB, Dep)); Result.push_back(NonLocalDepEntry(BB, Dep));
continue; continue;
} }
// Otherwise, we have to process all the predecessors of this block to scan // Otherwise, we have to process all the predecessors of this block to scan
// them as well. // them as well.
for (pred_iterator PI = pred_begin(FromBB), E = pred_end(FromBB); PI != E; for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
++PI)
// TODO: PHI TRANSLATE. // TODO: PHI TRANSLATE.
Worklist.push_back(std::make_pair(*PI, Pointer)); Worklist.push_back(*PI);
}
} }
} }
/// removeInstruction - Remove an instruction from the dependence analysis, /// removeInstruction - Remove an instruction from the dependence analysis,
/// updating the dependence of instructions that previously depended on it. /// updating the dependence of instructions that previously depended on it.
/// This method attempts to keep the cache coherent using the reverse map. /// This method attempts to keep the cache coherent using the reverse map.