From 8d3a888ca34bfa196087a233aa8b3ce4a9ccf5c3 Mon Sep 17 00:00:00 2001 From: Hongbin Zheng Date: Sat, 29 Jun 2013 07:00:14 +0000 Subject: [PATCH] TempScop: (Partial) Implement the printDetail function. llvm-svn: 185254 --- polly/include/polly/TempScopInfo.h | 2 + polly/lib/Analysis/TempScopInfo.cpp | 33 ++++++++++++++- polly/test/TempScop/tempscop-printing.ll | 51 ++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 polly/test/TempScop/tempscop-printing.ll diff --git a/polly/include/polly/TempScopInfo.h b/polly/include/polly/TempScopInfo.h index 6d98e9254129..da84a7135e45 100755 --- a/polly/include/polly/TempScopInfo.h +++ b/polly/include/polly/TempScopInfo.h @@ -74,6 +74,8 @@ public: bool isWrite() const { return Type & WRITE; } bool isScalar() const { return Type & SCALAR; } + + void print(raw_ostream &OS) const; }; class Comparison { diff --git a/polly/lib/Analysis/TempScopInfo.cpp b/polly/lib/Analysis/TempScopInfo.cpp index 7537bdbc5a8a..6eab175444ad 100644 --- a/polly/lib/Analysis/TempScopInfo.cpp +++ b/polly/lib/Analysis/TempScopInfo.cpp @@ -35,7 +35,16 @@ using namespace llvm; using namespace polly; //===----------------------------------------------------------------------===// -/// Helper Class +/// Helper Classes + +void IRAccess::print(raw_ostream &OS) const { + if (isRead()) + OS << "Read "; + else + OS << "Write "; + + OS << BaseAddress->getName() << '[' << *Offset << "]\n"; +} void Comparison::print(raw_ostream &OS) const { // Not yet implemented. @@ -72,7 +81,27 @@ void TempScop::print(raw_ostream &OS, ScalarEvolution *SE, LoopInfo *LI) const { void TempScop::printDetail(raw_ostream &OS, ScalarEvolution *SE, LoopInfo *LI, const Region *CurR, - unsigned ind) const {} + unsigned ind) const { + + // FIXME: Print other details rather than memory accesses. + typedef Region::const_block_iterator bb_iterator; + for (bb_iterator I = CurR->block_begin(), E = CurR->block_end(); I != E; ++I){ + BasicBlock *CurBlock = *I; + + AccFuncMapType::const_iterator AccSetIt = AccFuncMap.find(CurBlock); + + // Ignore trivial blocks that do not contain any memory access. + if (AccSetIt == AccFuncMap.end()) continue; + + OS.indent(ind) << "BB: " << CurBlock->getName() << '\n'; + typedef AccFuncSetType::const_iterator access_iterator; + const AccFuncSetType &AccFuncs = AccSetIt->second; + + for (access_iterator AI = AccFuncs.begin(), AE = AccFuncs.end(); + AI != AE; ++AI) + AI->first.print(OS.indent(ind + 2)); + } +} void TempScopInfo::buildScalarDependences(Instruction *Inst, Region *R) { // No need to translate these scalar dependences into polyhedral form, because diff --git a/polly/test/TempScop/tempscop-printing.ll b/polly/test/TempScop/tempscop-printing.ll new file mode 100644 index 000000000000..3e990bd7f94c --- /dev/null +++ b/polly/test/TempScop/tempscop-printing.ll @@ -0,0 +1,51 @@ +; RUN: opt %loadPolly -basicaa -polly-analyze-ir -analyze < %s | FileCheck %s + +; void f(long A[], int N, int *init_ptr) { +; long i, j; +; +; for (i = 0; i < N; ++i) { +; init = *init_ptr; +; for (i = 0; i < N; ++i) { +; A[i] = init + 2; +; } +; } +; } + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" +target triple = "x86_64-unknown-linux-gnu" + +define void @f(i64* noalias %A, i64 %N, i64* noalias %init_ptr) nounwind { +entry: + br label %for.i + +for.i: + %indvar.i = phi i64 [ 0, %entry ], [ %indvar.i.next, %for.i.end ] + %indvar.i.next = add nsw i64 %indvar.i, 1 + br label %entry.next + +entry.next: +; CHECK: BB: entry.next + %init = load i64* %init_ptr +; CHECK: Read init_ptr[0] +; CHECK: Write init.s2a[0] + br label %for.j + +for.j: + %indvar.j = phi i64 [ 0, %entry.next ], [ %indvar.j.next, %for.j ] +; CHECK: BB: for.j +; CHECK: Read init.s2a[0] +; CHECK: Write A[{0,+,8}<%for.j>] + %init_plus_two = add i64 %init, 2 + %scevgep = getelementptr i64* %A, i64 %indvar.j + store i64 %init_plus_two, i64* %scevgep + %indvar.j.next = add nsw i64 %indvar.j, 1 + %exitcond.j = icmp eq i64 %indvar.j.next, %N + br i1 %exitcond.j, label %for.i.end, label %for.j + +for.i.end: + %exitcond.i = icmp eq i64 %indvar.i.next, %N + br i1 %exitcond.i, label %return, label %for.i + +return: + ret void +} -- 2.34.1