llvm.org GIT mirror llvm / a51f091
IR printing improvement for loop passes Summary: Loop-pass printing is somewhat deficient since it does not provide the context around the loop (e.g. preheader). This context information becomes pretty essential when analyzing transformations that move stuff out of the loop. Extending printLoop to cover preheader and exit blocks (if any). Reviewers: sanjoy, silvas, weimingz Reviewed By: sanjoy Subscribers: apilipenko, skatkov, llvm-commits Differential Revision: https://reviews.llvm.org/D40246 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318878 91177308-0d34-0410-b5e6-96231b3b80d8 Fedor Sergeev 1 year, 9 months ago
2 changed file(s) with 86 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
731731
732732 void llvm::printLoop(Loop &L, raw_ostream &OS, const std::string &Banner) {
733733 OS << Banner;
734
735 auto *PreHeader = L.getLoopPreheader();
736 if (PreHeader) {
737 OS << "\n; Preheader:";
738 PreHeader->print(OS);
739 OS << "\n; Loop:";
740 }
741
734742 for (auto *Block : L.blocks())
735743 if (Block)
736744 Block->print(OS);
737745 else
738746 OS << "Printing block";
747
748 SmallVector ExitBlocks;
749 L.getExitBlocks(ExitBlocks);
750 if (!ExitBlocks.empty()) {
751 OS << "\n; Exit blocks";
752 for (auto *Block : ExitBlocks)
753 if (Block)
754 Block->print(OS);
755 else
756 OS << "Printing block";
757 }
739758 }
740759
741760 //===----------------------------------------------------------------------===//
0 ; This test checks -print-after/before on loop passes
1 ; Besides of the loop itself it should be dumping loop pre-header and exits.
2 ;
3 ; RUN: opt < %s 2>&1 -disable-output \
4 ; RUN: -loop-deletion -print-before=loop-deletion \
5 ; RUN: | FileCheck %s -check-prefix=DEL
6 ; RUN: opt < %s 2>&1 -disable-output \
7 ; RUN: -loop-unroll -print-after=loop-unroll -filter-print-funcs=bar \
8 ; RUN: | FileCheck %s -check-prefix=BAR
9 ;
10
11 ; DEL: IR Dump Before
12 ; DEL-SAME: dead loops
13 ; DEL: ; Preheader:
14 ; DEL-NEXT: %idx = alloca i32, align 4
15 ; DEL: ; Loop:
16 ; DEL-NEXT: loop:
17 ; DEL: cont:
18 ; DEL: ; Exit blocks
19 ; DEL: done:
20 ; DEL: IR Dump Before
21 ; DEL-SAME: dead loops
22 ; DEL: ; Preheader:
23 ; DEL-NEXT: br label %loop
24 ; DEL: ; Loop:
25 ; DEL-NEXT: loop:
26 ; DEL: ; Exit blocks
27 ; DEL: end:
28
29 ; BAR: IR Dump After
30 ; BAR-SAME: Unroll
31 ; BAR: ; Preheader:
32 ; BAR-NEXT: br label %loop
33 ; BAR: ; Loop:
34 ; BAR-NEXT: loop:
35 ; BAR: ; Exit blocks
36 ; BAR: end:
37 ; BAR-NOT: IR Dump Before
38 ; BAR-NOT: ; Loop
39
40 define void @foo(){
41 %idx = alloca i32, align 4
42 store i32 0, i32* %idx, align 4
43 br label %loop
44
45 loop:
46 %1 = load i32, i32* %idx, align 4
47 %2 = icmp slt i32 %1, 10
48 br i1 %2, label %cont, label %done
49
50 cont:
51 %3 = load i32, i32* %idx, align 4
52 %4 = add nsw i32 %3, 1
53 store i32 %4, i32* %idx, align 4
54 br label %loop
55
56 done:
57 ret void
58 }
59
60 define void @bar(){
61 br label %loop
62 loop:
63 br i1 1, label %loop, label %end
64 end:
65 ret void
66 }