236
|
1 ; RUN: opt %loadPolly -polly-print-scops -disable-output < %s | FileCheck %s --check-prefix=SCOP
|
150
|
2
|
|
3 ; RUN: opt %loadPolly -polly-codegen-ppcg \
|
|
4 ; RUN: -S -polly-acc-codegen-managed-memory \
|
|
5 ; RUN: -polly-acc-rewrite-managed-memory < %s | FileCheck %s --check-prefix=HOST-IR
|
|
6 ;
|
|
7 ; REQUIRES: pollyacc
|
|
8 ;
|
|
9 ; Check that we can correctly rewrite `malloc` to `polly_mallocManaged`, and
|
|
10 ; `free` to `polly_freeManaged` with the `polly-acc-rewrite-managed-memory`
|
|
11 ; pass, even inside `constantExpr`. This is necessary because a cookie cutter
|
|
12 ; Inst->replaceUsesOfWith(...) call does not actually work, because this does
|
|
13 ; not replace the instruction within a ConstantExpr.
|
|
14 ;
|
|
15 ; #include <memory.h>
|
|
16 ;
|
|
17 ; static const int N = 100;
|
|
18 ; int* f(int *ToFree) {
|
|
19 ; free(ToFree);
|
|
20 ; int *A = (int *)malloc(sizeof(int) * N);
|
|
21 ; for(int i = 0; i < N; i++) {
|
|
22 ; A[i] = 42;
|
|
23 ; }
|
|
24 ; return A;
|
|
25 ;
|
|
26 ; }
|
|
27
|
|
28 ; SCOP: Function: f
|
|
29 ; SCOP-NEXT: Region: %for.body---%for.end
|
|
30 ; SCOP-NEXT: Max Loop Depth: 1
|
|
31
|
|
32 ; SCOP: Arrays {
|
|
33 ; SCOP-NEXT: i32 MemRef_tmp[*]; // Element size 4
|
|
34 ; SCOP-NEXT: }
|
|
35
|
|
36 ; // Check that polly_mallocManaged is declared and used correctly.
|
|
37 ; HOST-IR: %1 = bitcast i8* (i64)* @polly_mallocManaged to i32* (i64)*
|
|
38 ; HOST-IR: declare i8* @polly_mallocManaged(i64)
|
|
39
|
|
40 ; // Check that polly_freeManaged is declared and used correctly.
|
|
41 ; HOST-IR call void @polly_freeManaged(i8* %toFree)
|
|
42 ; HOST-IR: declare void @polly_freeManaged(i8*)
|
|
43
|
|
44 ; // Check that we remove the original malloc,free
|
|
45 ; HOST-IR-NOT: declare i8* @malloc(i64)
|
|
46 ; HOST-IR-NOT: declare void @free(i8*)
|
|
47
|
|
48 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
|
49 target triple = "x86_64-apple-macosx10.12.0"
|
|
50
|
|
51 define i32* @f(i32 *%toFree) {
|
|
52 entry:
|
|
53 ; Free inside bitcast
|
|
54 call void bitcast (void (i8*)* @free to void (i32 *)*) (i32 * %toFree)
|
|
55 br label %entry.split
|
|
56
|
|
57 entry.split: ; preds = %entry
|
|
58 ; malloc inside bitcast.
|
|
59 %tmp = call i32* bitcast (i8* (i64)* @malloc to i32* (i64)*) (i64 400)
|
|
60 br label %for.body
|
|
61
|
|
62 for.body: ; preds = %entry.split, %for.body
|
|
63 %indvars.iv1 = phi i64 [ 0, %entry.split ], [ %indvars.iv.next, %for.body ]
|
|
64 %arrayidx = getelementptr inbounds i32, i32* %tmp, i64 %indvars.iv1
|
|
65 store i32 42, i32* %arrayidx, align 4, !tbaa !3
|
|
66 %indvars.iv.next = add nuw nsw i64 %indvars.iv1, 1
|
|
67 %exitcond = icmp eq i64 %indvars.iv.next, 100
|
|
68 br i1 %exitcond, label %for.end, label %for.body
|
|
69
|
|
70 for.end: ; preds = %for.body
|
|
71 ret i32* %tmp
|
|
72 }
|
|
73
|
|
74 ; Function Attrs: argmemonly nounwind
|
|
75 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #0
|
|
76
|
|
77 declare i8* @malloc(i64)
|
|
78 declare void @free(i8*)
|
|
79
|
|
80 ; Function Attrs: argmemonly nounwind
|
|
81 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #0
|
|
82
|
|
83 attributes #0 = { argmemonly nounwind }
|
|
84
|
|
85 !llvm.module.flags = !{!0, !1}
|
|
86 !llvm.ident = !{!2}
|
|
87
|
|
88 !0 = !{i32 1, !"wchar_size", i32 4}
|
|
89 !1 = !{i32 7, !"PIC Level", i32 2}
|
|
90 !2 = !{!"clang version 6.0.0"}
|
|
91 !3 = !{!4, !4, i64 0}
|
|
92 !4 = !{!"int", !5, i64 0}
|
|
93 !5 = !{!"omnipotent char", !6, i64 0}
|
|
94 !6 = !{!"Simple C/C++ TBAA"}
|