From: Tobias Grosser Date: Thu, 1 Nov 2012 21:28:32 +0000 (+0000) Subject: Dependences: Add support to calculate memory based dependences X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81a1c7503575543a8b6f5d785d437a4dcf7fef5c;p=platform%2Fupstream%2Fllvm.git Dependences: Add support to calculate memory based dependences Instead of calculating exact value (flow) dependences, it is also possible to calculate memory based dependences. Sometimes memory based dependences are a lot easier to calculate. To evaluate the benefits, we add an option to calculate memory based dependences (use -polly-value-dependences=false). llvm-svn: 167251 --- diff --git a/polly/lib/Analysis/Dependences.cpp b/polly/lib/Analysis/Dependences.cpp index 114ba47..16be7ab 100644 --- a/polly/lib/Analysis/Dependences.cpp +++ b/polly/lib/Analysis/Dependences.cpp @@ -43,6 +43,11 @@ static cl::opt cl::desc("Disable polly legality check"), cl::Hidden, cl::init(false)); +static cl::opt + ValueDependences("polly-value-dependences", + cl::desc("Use value instead of memory based dependences"), cl::Hidden, + cl::init(true)); + //===----------------------------------------------------------------------===// Dependences::Dependences() : ScopPass(ID) { RAW = WAR = WAW = NULL; @@ -82,19 +87,48 @@ void Dependences::calculateDependences(Scop &S) { collectInfo(S, &Read, &Write, &MayWrite, &Schedule); - isl_union_map_compute_flow(isl_union_map_copy(Read), - isl_union_map_copy(Write), - isl_union_map_copy(MayWrite), - isl_union_map_copy(Schedule), - &RAW, NULL, NULL, NULL); - - isl_union_map_compute_flow(isl_union_map_copy(Write), - isl_union_map_copy(Write), - Read, Schedule, - &WAW, &WAR, NULL, NULL); + if (ValueDependences) { + isl_union_map_compute_flow(isl_union_map_copy(Read), + isl_union_map_copy(Write), + isl_union_map_copy(MayWrite), + isl_union_map_copy(Schedule), + &RAW, NULL, NULL, NULL); + + isl_union_map_compute_flow(isl_union_map_copy(Write), + isl_union_map_copy(Write), + isl_union_map_copy(Read), + isl_union_map_copy(Schedule), + &WAW, &WAR, NULL, NULL); + } else { + isl_union_map *Empty; + + Empty = isl_union_map_empty(isl_union_map_get_space(Write)); + Write = isl_union_map_union(Write, isl_union_map_copy(MayWrite)); + + isl_union_map_compute_flow(isl_union_map_copy(Read), + isl_union_map_copy(Empty), + isl_union_map_copy(Write), + isl_union_map_copy(Schedule), + NULL, &RAW, NULL, NULL); + + isl_union_map_compute_flow(isl_union_map_copy(Write), + isl_union_map_copy(Empty), + isl_union_map_copy(Read), + isl_union_map_copy(Schedule), + NULL, &WAR, NULL, NULL); + + isl_union_map_compute_flow(isl_union_map_copy(Write), + isl_union_map_copy(Empty), + isl_union_map_copy(Write), + isl_union_map_copy(Schedule), + NULL, &WAW, NULL, NULL); + isl_union_map_free(Empty); + } isl_union_map_free(MayWrite); isl_union_map_free(Write); + isl_union_map_free(Read); + isl_union_map_free(Schedule); RAW = isl_union_map_coalesce(RAW); WAW = isl_union_map_coalesce(WAW); diff --git a/polly/test/Dependences/do_pluto_matmult.ll b/polly/test/Dependences/do_pluto_matmult.ll new file mode 100644 index 0000000..c026305 --- /dev/null +++ b/polly/test/Dependences/do_pluto_matmult.ll @@ -0,0 +1,80 @@ +; RUN: opt %loadPolly -basicaa -polly-dependences -analyze -polly-value-dependences=true < %s | FileCheck %s -check-prefix=VALUE +; RUN: opt %loadPolly -basicaa -polly-dependences -analyze -polly-value-dependences=false < %s | FileCheck %s -check-prefix=MEMORY + +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-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" + +%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i64, i32, [20 x i8] } +%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 } + +@A = common global [36 x [49 x double]] zeroinitializer, align 8 ; <[36 x [49 x double]]*> [#uses=3] +@B = common global [36 x [49 x double]] zeroinitializer, align 8 ; <[36 x [49 x double]]*> [#uses=3] +@C = common global [36 x [49 x double]] zeroinitializer, align 8 ; <[36 x [49 x double]]*> [#uses=4] + +define void @do_pluto_matmult() nounwind { +entry: + fence seq_cst + br label %do.body + +do.body: ; preds = %do.cond42, %entry + %indvar3 = phi i64 [ %indvar.next4, %do.cond42 ], [ 0, %entry ] ; [#uses=3] + br label %do.body1 + +do.body1: ; preds = %do.cond36, %do.body + %indvar1 = phi i64 [ %indvar.next2, %do.cond36 ], [ 0, %do.body ] ; [#uses=3] + %arrayidx5 = getelementptr [36 x [49 x double]]* @C, i64 0, i64 %indvar3, i64 %indvar1 ; [#uses=2] + br label %do.body2 + +do.body2: ; preds = %do.cond, %do.body1 + %indvar = phi i64 [ %indvar.next, %do.cond ], [ 0, %do.body1 ] ; [#uses=3] + %arrayidx13 = getelementptr [36 x [49 x double]]* @A, i64 0, i64 %indvar3, i64 %indvar ; [#uses=1] + %arrayidx22 = getelementptr [36 x [49 x double]]* @B, i64 0, i64 %indvar, i64 %indvar1 ; [#uses=1] + %tmp6 = load double* %arrayidx5 ; [#uses=1] + %mul = fmul double 1.000000e+00, %tmp6 ; [#uses=1] + %tmp14 = load double* %arrayidx13 ; [#uses=1] + %mul15 = fmul double 1.000000e+00, %tmp14 ; [#uses=1] + %tmp23 = load double* %arrayidx22 ; [#uses=1] + %mul24 = fmul double %mul15, %tmp23 ; [#uses=1] + %add = fadd double %mul, %mul24 ; [#uses=1] + store double %add, double* %arrayidx5 + br label %do.cond + +do.cond: ; preds = %do.body2 + %indvar.next = add i64 %indvar, 1 ; [#uses=2] + %exitcond = icmp ne i64 %indvar.next, 36 ; [#uses=1] + br i1 %exitcond, label %do.body2, label %do.end + +do.end: ; preds = %do.cond + br label %do.cond36 + +do.cond36: ; preds = %do.end + %indvar.next2 = add i64 %indvar1, 1 ; [#uses=2] + %exitcond5 = icmp ne i64 %indvar.next2, 36 ; [#uses=1] + br i1 %exitcond5, label %do.body1, label %do.end39 + +do.end39: ; preds = %do.cond36 + br label %do.cond42 + +do.cond42: ; preds = %do.end39 + %indvar.next4 = add i64 %indvar3, 1 ; [#uses=2] + %exitcond6 = icmp ne i64 %indvar.next4, 36 ; [#uses=1] + br i1 %exitcond6, label %do.body, label %do.end45 + +do.end45: ; preds = %do.cond42 + fence seq_cst + ret void +} + +; VALUE: RAW dependences: +; VALUE: { Stmt_do_body2[i0, i1, i2] -> Stmt_do_body2[i0, i1, 1 + i2] : i0 >= 0 and i0 <= 35 and i1 >= 0 and i1 <= 35 and i2 >= 0 and i2 <= 34 } +; VALUE: WAR dependences: +; VALUE: { } +; VALUE: WAW dependences: +; VALUE: { Stmt_do_body2[i0, i1, i2] -> Stmt_do_body2[i0, i1, 1 + i2] : i0 >= 0 and i0 <= 35 and i1 >= 0 and i1 <= 35 and i2 >= 0 and i2 <= 34 } + +; MEMORY: RAW dependences: +; MEMORY: { Stmt_do_body2[i0, i1, i2] -> Stmt_do_body2[i0, i1, o2] : i0 >= 0 and i0 <= 35 and i1 >= 0 and i1 <= 35 and i2 >= 0 and i2 <= 35 and o2 >= 1 + i2 and o2 <= 35 and o2 >= 0 } +; MEMORY: WAR dependences: +; MEMORY: { Stmt_do_body2[i0, i1, i2] -> Stmt_do_body2[i0, i1, o2] : i0 >= 0 and i0 <= 35 and i1 >= 0 and i1 <= 35 and i2 >= 0 and i2 <= 35 and o2 >= 1 + i2 and o2 <= 35 and o2 >= 0 } +; MEMORY: WAW dependences: +; MEMORY: { Stmt_do_body2[i0, i1, i2] -> Stmt_do_body2[i0, i1, o2] : i0 >= 0 and i0 <= 35 and i1 >= 0 and i1 <= 35 and i2 >= 0 and i2 <= 35 and o2 >= 1 + i2 and o2 <= 35 and o2 >= 0 }