forked from OSchip/llvm-project
Make non-local memdep not be recursive, and fix a bug on 403.gcc that this exposed.
llvm-svn: 40692
This commit is contained in:
parent
da549ece5c
commit
c321e5e272
|
@ -43,9 +43,8 @@ class MemoryDependenceAnalysis : public FunctionPass {
|
|||
|
||||
Instruction* getCallSiteDependency(CallSite C, Instruction* start,
|
||||
bool local = true);
|
||||
bool nonLocalHelper(Instruction* query, BasicBlock* block,
|
||||
DenseMap<BasicBlock*, Value*>& resp,
|
||||
SmallPtrSet<BasicBlock*, 4>& visited);
|
||||
void nonLocalHelper(Instruction* query, BasicBlock* block,
|
||||
DenseMap<BasicBlock*, Value*>& resp);
|
||||
public:
|
||||
|
||||
static Instruction* NonLocal;
|
||||
|
@ -74,7 +73,7 @@ class MemoryDependenceAnalysis : public FunctionPass {
|
|||
Instruction* getDependency(Instruction* query, Instruction* start = 0,
|
||||
BasicBlock* block = 0);
|
||||
|
||||
bool getNonLocalDependency(Instruction* query,
|
||||
void getNonLocalDependency(Instruction* query,
|
||||
DenseMap<BasicBlock*, Value*>& resp);
|
||||
|
||||
/// removeInstruction - Remove an instruction from the dependence analysis,
|
||||
|
|
|
@ -101,63 +101,62 @@ Instruction* MemoryDependenceAnalysis::getCallSiteDependency(CallSite C, Instruc
|
|||
return NonLocal;
|
||||
}
|
||||
|
||||
bool MemoryDependenceAnalysis::nonLocalHelper(Instruction* query,
|
||||
void MemoryDependenceAnalysis::nonLocalHelper(Instruction* query,
|
||||
BasicBlock* block,
|
||||
DenseMap<BasicBlock*, Value*>& resp,
|
||||
SmallPtrSet<BasicBlock*, 4>& visited) {
|
||||
if (resp.count(block))
|
||||
return resp[block] != None;
|
||||
DenseMap<BasicBlock*, Value*>& resp) {
|
||||
SmallPtrSet<BasicBlock*, 4> visited;
|
||||
SmallVector<BasicBlock*, 4> stack;
|
||||
stack.push_back(block);
|
||||
|
||||
Instruction* localDep = getDependency(query, 0, block);
|
||||
if (localDep != NonLocal) {
|
||||
resp.insert(std::make_pair(block, localDep));
|
||||
return true;
|
||||
while (!stack.empty()) {
|
||||
BasicBlock* BB = stack.back();
|
||||
|
||||
visited.insert(BB);
|
||||
|
||||
if (resp.count(BB)) {
|
||||
stack.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (BB != block) {
|
||||
Instruction* localDep = getDependency(query, 0, BB);
|
||||
if (localDep != NonLocal) {
|
||||
resp.insert(std::make_pair(BB, localDep));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
bool predOnStack = false;
|
||||
bool inserted = false;
|
||||
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
|
||||
PI != PE; ++PI)
|
||||
if (!visited.count(*PI)) {
|
||||
stack.push_back(*PI);
|
||||
inserted = true;
|
||||
} else
|
||||
predOnStack = true;
|
||||
|
||||
if (inserted)
|
||||
continue;
|
||||
else if (!inserted && !predOnStack) {
|
||||
resp.insert(std::make_pair(BB, None));
|
||||
} else if (!inserted && predOnStack){
|
||||
resp.insert(std::make_pair(BB, NonLocal));
|
||||
}
|
||||
|
||||
stack.pop_back();
|
||||
}
|
||||
|
||||
visited.insert(block);
|
||||
|
||||
bool inserted = false;
|
||||
bool predOnStack = false;
|
||||
for (pred_iterator PI = pred_begin(block), PE = pred_end(block);
|
||||
PI != PE; ++PI)
|
||||
if (!visited.count(*PI))
|
||||
inserted |= nonLocalHelper(query, *PI, resp, visited);
|
||||
else
|
||||
predOnStack = true;
|
||||
|
||||
visited.erase(block);
|
||||
|
||||
if (!inserted && !predOnStack)
|
||||
resp.insert(std::make_pair(block, None));
|
||||
else if (inserted && predOnStack)
|
||||
resp.insert(std::make_pair(block, NonLocal));
|
||||
|
||||
return inserted;
|
||||
}
|
||||
|
||||
bool MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
|
||||
void MemoryDependenceAnalysis::getNonLocalDependency(Instruction* query,
|
||||
DenseMap<BasicBlock*, Value*>& resp) {
|
||||
Instruction* localDep = getDependency(query);
|
||||
if (localDep != NonLocal) {
|
||||
resp.insert(std::make_pair(query->getParent(), localDep));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
bool inserted = false;
|
||||
SmallPtrSet<BasicBlock*, 4> visited;
|
||||
visited.insert(query->getParent());
|
||||
|
||||
BasicBlock* parent = query->getParent();
|
||||
for (pred_iterator PI = pred_begin(parent), PE = pred_end(parent);
|
||||
PI != PE; ++PI) {
|
||||
if (!visited.count(*PI))
|
||||
inserted |= nonLocalHelper(query, *PI, resp, visited);
|
||||
}
|
||||
|
||||
if (!inserted)
|
||||
resp.insert(std::make_pair(query->getParent(), None));
|
||||
|
||||
return inserted;
|
||||
nonLocalHelper(query, query->getParent(), resp);
|
||||
}
|
||||
|
||||
/// getDependency - Return the instruction on which a memory operation
|
||||
|
|
|
@ -721,8 +721,9 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,
|
|||
Value *&V = Phis[BB];
|
||||
if (V) return V;
|
||||
|
||||
if (std::distance(pred_begin(BB), pred_end(BB)) == 1)
|
||||
return V = GetValueForBlock(*pred_begin(BB), orig, Phis);
|
||||
BasicBlock* singlePred = BB->getSinglePredecessor();
|
||||
if (singlePred)
|
||||
return V = GetValueForBlock(singlePred, orig, Phis);
|
||||
|
||||
// Otherwise, the idom is the loop, so we need to insert a PHI node. Do so
|
||||
// now, then get values to fill in the incoming values for the PHI.
|
||||
|
@ -750,6 +751,16 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,
|
|||
|
||||
MD.removeInstruction(PN);
|
||||
PN->replaceAllUsesWith(first);
|
||||
|
||||
SmallVector<BasicBlock*, 4> toRemove;
|
||||
for (DenseMap<BasicBlock*, Value*>::iterator I = Phis.begin(),
|
||||
E = Phis.end(); I != E; ++I)
|
||||
if (I->second == PN)
|
||||
toRemove.push_back(I->first);
|
||||
for (SmallVector<BasicBlock*, 4>::iterator I = toRemove.begin(),
|
||||
E= toRemove.end(); I != E; ++I)
|
||||
Phis[*I] = first;
|
||||
|
||||
PN->eraseFromParent();
|
||||
|
||||
Phis[BB] = first;
|
||||
|
@ -764,9 +775,7 @@ bool GVN::processNonLocalLoad(LoadInst* L, SmallVector<Instruction*, 4>& toErase
|
|||
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||
|
||||
DenseMap<BasicBlock*, Value*> deps;
|
||||
bool ret = MD.getNonLocalDependency(L, deps);
|
||||
if (!ret)
|
||||
return false;
|
||||
MD.getNonLocalDependency(L, deps);
|
||||
|
||||
DenseMap<BasicBlock*, Value*> repl;
|
||||
for (DenseMap<BasicBlock*, Value*>::iterator I = deps.begin(), E = deps.end();
|
||||
|
|
Loading…
Reference in New Issue