Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2b2a8f1

Browse files
committed
[LoopDataPrefetch] Add optimization remark
With -Rpass=loop-data-prefetch, show the memory access that got prefetched. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268578 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6e64fd8 commit 2b2a8f1

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

lib/Transforms/Scalar/LoopDataPrefetch.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Analysis/TargetTransformInfo.h"
2727
#include "llvm/Analysis/ValueTracking.h"
2828
#include "llvm/IR/CFG.h"
29+
#include "llvm/IR/DiagnosticInfo.h"
2930
#include "llvm/IR/Dominators.h"
3031
#include "llvm/IR/Function.h"
3132
#include "llvm/IR/IntrinsicInst.h"
@@ -209,9 +210,10 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) {
209210
if (ItersAhead > getMaxPrefetchIterationsAhead())
210211
return MadeChange;
211212

213+
Function *F = L->getHeader()->getParent();
212214
DEBUG(dbgs() << "Prefetching " << ItersAhead
213215
<< " iterations ahead (loop size: " << LoopSize << ") in "
214-
<< L->getHeader()->getParent()->getName() << ": " << *L);
216+
<< F->getName() << ": " << *L);
215217

216218
SmallVector<std::pair<Instruction *, const SCEVAddRecExpr *>, 16> PrefLoads;
217219
for (Loop::block_iterator I = L->block_begin(), IE = L->block_end();
@@ -291,6 +293,9 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) {
291293
++NumPrefetches;
292294
DEBUG(dbgs() << " Access: " << *PtrValue << ", SCEV: " << *LSCEV
293295
<< "\n");
296+
emitOptimizationRemark(F->getContext(), DEBUG_TYPE, *F,
297+
MemI->getDebugLoc(), "prefetched memory access");
298+
294299

295300
MadeChange = true;
296301
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
; RUN: opt -mcpu=cyclone -mtriple=arm64-apple-ios -loop-data-prefetch \
2+
; RUN: -pass-remarks=loop-data-prefetch -S -max-prefetch-iters-ahead=100 \
3+
; RUN: < %s 2>&1 | FileCheck %s
4+
5+
; ModuleID = '/tmp/s.c'
6+
source_filename = "/tmp/s.c"
7+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
8+
target triple = "arm64-apple-ios5.0.0"
9+
10+
; 1 struct MyStruct {
11+
; 2 int field;
12+
; 3 char kk[2044];
13+
; 4 } *my_struct;
14+
; 5
15+
; 6 int f(struct MyStruct *p, int N) {
16+
; 7 int total = 0;
17+
; 8 for (int i = 0; i < N; i++) {
18+
; 9 total += my_struct[i].field;
19+
; 10 }
20+
; 11 return total;
21+
; 12 }
22+
23+
; CHECK: remark: /tmp/s.c:9:27: prefetched memory access
24+
25+
%struct.MyStruct = type { i32, [2044 x i8] }
26+
27+
@my_struct = common global %struct.MyStruct* null, align 8
28+
29+
define i32 @f(%struct.MyStruct* nocapture readnone %p, i32 %N) !dbg !6 {
30+
entry:
31+
%cmp6 = icmp sgt i32 %N, 0, !dbg !8
32+
br i1 %cmp6, label %for.body.lr.ph, label %for.cond.cleanup, !dbg !9
33+
34+
for.body.lr.ph: ; preds = %entry
35+
%0 = load %struct.MyStruct*, %struct.MyStruct** @my_struct, align 8, !dbg !10, !tbaa !11
36+
br label %for.body, !dbg !9
37+
38+
for.cond.cleanup: ; preds = %for.body, %entry
39+
%total.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ]
40+
ret i32 %total.0.lcssa, !dbg !15
41+
42+
for.body: ; preds = %for.body, %for.body.lr.ph
43+
%indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
44+
%total.07 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %for.body ]
45+
%field = getelementptr inbounds %struct.MyStruct, %struct.MyStruct* %0, i64 %indvars.iv, i32 0, !dbg !16
46+
%1 = load i32, i32* %field, align 4, !dbg !16, !tbaa !17
47+
%add = add nsw i32 %1, %total.07, !dbg !20
48+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !9
49+
%lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !9
50+
%exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !9
51+
br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !9
52+
}
53+
54+
!llvm.dbg.cu = !{!0}
55+
!llvm.module.flags = !{!3, !4}
56+
!llvm.ident = !{!5}
57+
58+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
59+
!1 = !DIFile(filename: "/tmp/s.c", directory: "/tmp")
60+
!2 = !{}
61+
!3 = !{i32 2, !"Debug Info Version", i32 3}
62+
!4 = !{i32 1, !"PIC Level", i32 2}
63+
!5 = !{!"clang version 3.9.0"}
64+
!6 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 6, type: !7, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
65+
!7 = !DISubroutineType(types: !2)
66+
!8 = !DILocation(line: 8, column: 21, scope: !6)
67+
!9 = !DILocation(line: 8, column: 3, scope: !6)
68+
!10 = !DILocation(line: 9, column: 14, scope: !6)
69+
!11 = !{!12, !12, i64 0}
70+
!12 = !{!"any pointer", !13, i64 0}
71+
!13 = !{!"omnipotent char", !14, i64 0}
72+
!14 = !{!"Simple C/C++ TBAA"}
73+
!15 = !DILocation(line: 11, column: 3, scope: !6)
74+
!16 = !DILocation(line: 9, column: 27, scope: !6)
75+
!17 = !{!18, !19, i64 0}
76+
!18 = !{!"MyStruct", !19, i64 0, !13, i64 4}
77+
!19 = !{!"int", !13, i64 0}
78+
!20 = !DILocation(line: 9, column: 11, scope: !6)

0 commit comments

Comments
 (0)