mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-14 15:28:20 +00:00
Implement review feedback from Devang: make use
of mayReadFromMemory and mayWriteToMemory. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56387 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -54,7 +54,7 @@ bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
|
|||||||
Function *F = SCC[i]->getFunction();
|
Function *F = SCC[i]->getFunction();
|
||||||
|
|
||||||
if (F == 0)
|
if (F == 0)
|
||||||
// May write memory.
|
// External node - may write memory.
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (F->doesNotAccessMemory())
|
if (F->doesNotAccessMemory())
|
||||||
@@ -72,34 +72,19 @@ bool AddReadAttrs::runOnSCC(const std::vector<CallGraphNode *> &SCC) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan the function body for explicit loads and stores, or calls to
|
// Scan the function body for instructions that may read or write memory.
|
||||||
// functions that may read or write memory.
|
|
||||||
for (inst_iterator II = inst_begin(F), E = inst_end(F); II != E; ++II) {
|
for (inst_iterator II = inst_begin(F), E = inst_end(F); II != E; ++II) {
|
||||||
Instruction *I = &*II;
|
CallSite CS = CallSite::get(&*II);
|
||||||
if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
|
|
||||||
if (LI->isVolatile())
|
|
||||||
// Volatile loads may have side-effects, so treat them as writing
|
|
||||||
// memory.
|
|
||||||
return false;
|
|
||||||
ReadsMemory = true;
|
|
||||||
} else if (isa<StoreInst>(I) || isa<MallocInst>(I) || isa<FreeInst>(I)) {
|
|
||||||
// Writes memory.
|
|
||||||
return false;
|
|
||||||
} else if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
|
|
||||||
CallSite CS(I);
|
|
||||||
|
|
||||||
if (std::find(SCC.begin(), SCC.end(), CG[CS.getCalledFunction()]) !=
|
// Ignore calls to functions in the same SCC.
|
||||||
|
if (CS.getInstruction() &&
|
||||||
|
std::find(SCC.begin(), SCC.end(), CG[CS.getCalledFunction()]) !=
|
||||||
SCC.end())
|
SCC.end())
|
||||||
// The callee is inside our current SCC - ignore it.
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!CS.onlyReadsMemory())
|
if (II->mayWriteToMemory())
|
||||||
// May write memory.
|
|
||||||
return false;
|
return false;
|
||||||
|
ReadsMemory |= II->mayReadFromMemory();
|
||||||
if (!CS.doesNotAccessMemory())
|
|
||||||
ReadsMemory = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user