mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-28 07:17:32 +00:00
[LoopAccesses] Add -analyze support
The LoopInfo in combination with depth_first is used to enumerate the loops. Right now -analyze is not yet complete. It only prints the result of the analysis, the report and the run-time checks. Printing the unsafe depedences will require a bit more reshuffling which I'd like to do in a follow-on to this patchset. Unsafe dependences are currently checked via -debug-only=loop-accesses in the new test. This is part of the patchset that converts LoopAccessAnalysis into an actual analysis pass. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229898 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -135,6 +135,23 @@ bool LoopAccessInfo::RuntimePointerCheck::needsChecking(unsigned I,
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoopAccessInfo::RuntimePointerCheck::print(raw_ostream &OS,
|
||||
unsigned Depth) const {
|
||||
unsigned NumPointers = Pointers.size();
|
||||
if (NumPointers == 0)
|
||||
return;
|
||||
|
||||
OS.indent(Depth) << "Run-time memory checks:\n";
|
||||
unsigned N = 0;
|
||||
for (unsigned I = 0; I < NumPointers; ++I)
|
||||
for (unsigned J = I + 1; J < NumPointers; ++J)
|
||||
if (needsChecking(I, J)) {
|
||||
OS.indent(Depth) << N++ << ":\n";
|
||||
OS.indent(Depth + 2) << *Pointers[I] << "\n";
|
||||
OS.indent(Depth + 2) << *Pointers[J] << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
/// \brief Analyses memory accesses in a loop.
|
||||
///
|
||||
@@ -1291,6 +1308,24 @@ LoopAccessInfo::LoopAccessInfo(Loop *L, ScalarEvolution *SE,
|
||||
analyzeLoop(Strides);
|
||||
}
|
||||
|
||||
void LoopAccessInfo::print(raw_ostream &OS, unsigned Depth) const {
|
||||
if (CanVecMem) {
|
||||
if (PtrRtCheck.empty())
|
||||
OS.indent(Depth) << "Memory dependences are safe\n";
|
||||
else
|
||||
OS.indent(Depth) << "Memory dependences are safe with run-time checks\n";
|
||||
}
|
||||
|
||||
if (Report)
|
||||
OS.indent(Depth) << "Report: " << Report->str() << "\n";
|
||||
|
||||
// FIXME: Print unsafe dependences
|
||||
|
||||
// List the pair of accesses need run-time checks to prove independence.
|
||||
PtrRtCheck.print(OS, Depth);
|
||||
OS << "\n";
|
||||
}
|
||||
|
||||
LoopAccessInfo &LoopAccessAnalysis::getInfo(Loop *L, ValueToValueMap &Strides) {
|
||||
auto &LAI = LoopAccessInfoMap[L];
|
||||
|
||||
@@ -1308,6 +1343,20 @@ LoopAccessInfo &LoopAccessAnalysis::getInfo(Loop *L, ValueToValueMap &Strides) {
|
||||
return *LAI.get();
|
||||
}
|
||||
|
||||
void LoopAccessAnalysis::print(raw_ostream &OS, const Module *M) const {
|
||||
LoopAccessAnalysis &LAA = *const_cast<LoopAccessAnalysis *>(this);
|
||||
|
||||
LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||
ValueToValueMap NoSymbolicStrides;
|
||||
|
||||
for (Loop *TopLevelLoop : *LI)
|
||||
for (Loop *L : depth_first(TopLevelLoop)) {
|
||||
OS.indent(2) << L->getHeader()->getName() << ":\n";
|
||||
auto &LAI = LAA.getInfo(L, NoSymbolicStrides);
|
||||
LAI.print(OS, 4);
|
||||
}
|
||||
}
|
||||
|
||||
bool LoopAccessAnalysis::runOnFunction(Function &F) {
|
||||
SE = &getAnalysis<ScalarEvolution>();
|
||||
DL = F.getParent()->getDataLayout();
|
||||
@@ -1323,6 +1372,7 @@ void LoopAccessAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
AU.addRequired<ScalarEvolution>();
|
||||
AU.addRequired<AliasAnalysis>();
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<LoopInfoWrapperPass>();
|
||||
|
||||
AU.setPreservesAll();
|
||||
}
|
||||
@@ -1335,6 +1385,7 @@ INITIALIZE_PASS_BEGIN(LoopAccessAnalysis, LAA_NAME, laa_name, false, true)
|
||||
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
||||
INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||
INITIALIZE_PASS_END(LoopAccessAnalysis, LAA_NAME, laa_name, false, true)
|
||||
|
||||
namespace llvm {
|
||||
|
Reference in New Issue
Block a user