mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-29 15:37:46 +00:00
Fix a bunch of things from Chris' feedback
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@38493 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
02e25b70aa
commit
6b278fc786
@ -28,7 +28,7 @@ class Function;
|
|||||||
class FunctionPass;
|
class FunctionPass;
|
||||||
class Instruction;
|
class Instruction;
|
||||||
|
|
||||||
class VISIBILITY_HIDDEN MemoryDependenceAnalysis : public FunctionPass {
|
class MemoryDependenceAnalysis : public FunctionPass {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
DenseMap<Instruction*, std::pair<Instruction*, bool> > depGraphLocal;
|
DenseMap<Instruction*, std::pair<Instruction*, bool> > depGraphLocal;
|
||||||
@ -44,10 +44,12 @@ class VISIBILITY_HIDDEN MemoryDependenceAnalysis : public FunctionPass {
|
|||||||
|
|
||||||
/// Pass Implementation stuff. This doesn't do any analysis.
|
/// Pass Implementation stuff. This doesn't do any analysis.
|
||||||
///
|
///
|
||||||
bool runOnFunction(Function &) {
|
bool runOnFunction(Function &) {return false; }
|
||||||
|
|
||||||
|
/// Clean up memory in between runs
|
||||||
|
void releaseMemory() {
|
||||||
depGraphLocal.clear();
|
depGraphLocal.clear();
|
||||||
reverseDep.clear();
|
reverseDep.clear();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getAnalysisUsage - Does not modify anything. It uses Value Numbering
|
/// getAnalysisUsage - Does not modify anything. It uses Value Numbering
|
||||||
|
@ -40,8 +40,8 @@ void MemoryDependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// getDependency - Return the instruction on which a memory operation
|
/// getDependency - Return the instruction on which a memory operation
|
||||||
/// depends. NOTE: A return value of NULL indicates that no dependency
|
/// depends. The local paramter indicates if the query should only
|
||||||
/// was found in the parent block.
|
/// evaluate dependencies within the same basic block.
|
||||||
Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
||||||
bool local) {
|
bool local) {
|
||||||
if (!local)
|
if (!local)
|
||||||
@ -60,51 +60,68 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
QI = cachedResult.first;
|
QI = cachedResult.first;
|
||||||
|
|
||||||
AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
|
AliasAnalysis& AA = getAnalysis<AliasAnalysis>();
|
||||||
|
TargetData& TD = getAnalysis<TargetData>();
|
||||||
BasicBlock::iterator blockBegin = query->getParent()->begin();
|
|
||||||
|
|
||||||
// Get the pointer value for which dependence will be determined
|
// Get the pointer value for which dependence will be determined
|
||||||
Value* dependee = 0;
|
Value* dependee = 0;
|
||||||
if (StoreInst* S = dyn_cast<StoreInst>(QI))
|
uint64_t dependeeSize = 0;
|
||||||
|
if (StoreInst* S = dyn_cast<StoreInst>(QI)) {
|
||||||
dependee = S->getPointerOperand();
|
dependee = S->getPointerOperand();
|
||||||
else if (LoadInst* L = dyn_cast<LoadInst>(QI))
|
dependeeSize = TD.getTypeSize(dependee->getType());
|
||||||
|
} else if (LoadInst* L = dyn_cast<LoadInst>(QI)) {
|
||||||
dependee = L->getPointerOperand();
|
dependee = L->getPointerOperand();
|
||||||
else if (FreeInst* F = dyn_cast<FreeInst>(QI))
|
dependeeSize = TD.getTypeSize(dependee->getType());
|
||||||
|
} else if (FreeInst* F = dyn_cast<FreeInst>(QI)) {
|
||||||
dependee = F->getPointerOperand();
|
dependee = F->getPointerOperand();
|
||||||
else if (isa<AllocationInst>(query)) {
|
|
||||||
|
// FreeInsts erase the entire structure, not just a field
|
||||||
|
dependeeSize = ~0UL;
|
||||||
|
} else if (isa<AllocationInst>(query)) {
|
||||||
// Allocations don't depend on anything
|
// Allocations don't depend on anything
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(None,
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(None,
|
||||||
true)));
|
true)));
|
||||||
reverseDep.insert(std::make_pair(None, query));
|
reverseDep.insert(std::make_pair(None, query));
|
||||||
return None;
|
return None;
|
||||||
} else {
|
} else
|
||||||
// Non-memory operations depend on their immediate predecessor
|
// FIXME: Call/InvokeInsts need proper handling
|
||||||
--QI;
|
return None;
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
|
||||||
reverseDep.insert(std::make_pair(QI, query));
|
|
||||||
return QI;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start with the predecessor of the queried inst
|
|
||||||
--QI;
|
|
||||||
|
|
||||||
TargetData& TD = getAnalysis<TargetData>();
|
BasicBlock::iterator blockBegin = query->getParent()->begin();
|
||||||
|
|
||||||
while (QI != blockBegin) {
|
while (QI != blockBegin) {
|
||||||
|
--QI;
|
||||||
|
|
||||||
|
// If we've reached the pointer's definition...
|
||||||
|
if (QI == dependee) {
|
||||||
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
||||||
|
reverseDep.insert(std::make_pair(QI, query));
|
||||||
|
return QI;
|
||||||
|
}
|
||||||
|
|
||||||
// If this inst is a memory op, get the pointer it accessed
|
// If this inst is a memory op, get the pointer it accessed
|
||||||
Value* pointer = 0;
|
Value* pointer = 0;
|
||||||
if (StoreInst* S = dyn_cast<StoreInst>(QI))
|
uint64_t pointerSize = 0;
|
||||||
|
if (StoreInst* S = dyn_cast<StoreInst>(QI)) {
|
||||||
pointer = S->getPointerOperand();
|
pointer = S->getPointerOperand();
|
||||||
else if (LoadInst* L = dyn_cast<LoadInst>(QI))
|
pointerSize = TD.getTypeSize(pointer->getType());
|
||||||
|
} else if (LoadInst* L = dyn_cast<LoadInst>(QI)) {
|
||||||
pointer = L->getPointerOperand();
|
pointer = L->getPointerOperand();
|
||||||
else if (isa<AllocationInst>(QI))
|
pointerSize = TD.getTypeSize(pointer->getType());
|
||||||
pointer = QI;
|
} else if (AllocationInst* AI = dyn_cast<AllocationInst>(QI)) {
|
||||||
else if (FreeInst* F = dyn_cast<FreeInst>(QI))
|
pointer = AI;
|
||||||
|
if (isa<ConstantInt>(AI->getArraySize()))
|
||||||
|
pointerSize = AI->getZExtValue();
|
||||||
|
else
|
||||||
|
pointerSize = ~0UL;
|
||||||
|
} else if (FreeInst* F = dyn_cast<FreeInst>(QI)) {
|
||||||
pointer = F->getPointerOperand();
|
pointer = F->getPointerOperand();
|
||||||
else if (CallInst* C = dyn_cast<CallInst>(QI)) {
|
|
||||||
|
// FreeInsts erase the entire structure
|
||||||
|
pointerSize = ~0UL;
|
||||||
|
} else if (CallSite* C = dyn_cast<CallSite>(QI)) {
|
||||||
// Call insts need special handling. Check is they can modify our pointer
|
// Call insts need special handling. Check is they can modify our pointer
|
||||||
if (AA.getModRefInfo(C, dependee, TD.getTypeSize(dependee->getType())) !=
|
if (AA.getModRefInfo(C, dependee, dependeeSize) != AliasAnalysis::NoModRef) {
|
||||||
AliasAnalysis::NoModRef) {
|
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(C, true)));
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(C, true)));
|
||||||
reverseDep.insert(std::make_pair(C, query));
|
reverseDep.insert(std::make_pair(C, query));
|
||||||
return C;
|
return C;
|
||||||
@ -115,9 +132,8 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
|
|
||||||
// If we found a pointer, check if it could be the same as our pointer
|
// If we found a pointer, check if it could be the same as our pointer
|
||||||
if (pointer) {
|
if (pointer) {
|
||||||
AliasAnalysis::AliasResult R = AA.alias(
|
AliasAnalysis::AliasResult R = AA.alias(pointer, pointerSize,
|
||||||
pointer, TD.getTypeSize(pointer->getType()),
|
dependee, dependeeSize);
|
||||||
dependee, TD.getTypeSize(dependee->getType()));
|
|
||||||
|
|
||||||
if (R != AliasAnalysis::NoAlias) {
|
if (R != AliasAnalysis::NoAlias) {
|
||||||
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
depGraphLocal.insert(std::make_pair(query, std::make_pair(QI, true)));
|
||||||
@ -125,8 +141,6 @@ Instruction* MemoryDependenceAnalysis::getDependency(Instruction* query,
|
|||||||
return QI;
|
return QI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QI--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we found nothing, return the non-local flag
|
// If we found nothing, return the non-local flag
|
||||||
|
Loading…
x
Reference in New Issue
Block a user