From: Tobias Grosser Date: Thu, 14 Jul 2016 15:51:32 +0000 (+0000) Subject: GPGPU: Add dummy implementation for ast expression construction X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=60c60025701177df9c369af9195fba0067d4379e;p=platform%2Fupstream%2Fllvm.git GPGPU: Add dummy implementation for ast expression construction Instead of calling to a pet function that does not return anything, we pass our own dummy implementation to ppcg that always returns a nullptr. This ensures that the list of ast expressions always contains a nullptr and we do not accidentally free a random (uninitalized) pointer. This resolves the last valgrind warning we see. We provide an implementation for this function, when the generated AST expressions can be used and consequently can be tested. llvm-svn: 275435 --- diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp index d0921db..bb6ea8cd 100644 --- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -41,6 +41,23 @@ static cl::opt DumpSchedule("polly-acc-dump-schedule", cl::desc("Dump the computed GPU Schedule"), cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); +/// Create the ast expressions for a ScopStmt. +/// +/// This function is a callback for to generate the ast expressions for each +/// of the scheduled ScopStmts. +static __isl_give isl_id_to_ast_expr *pollyBuildAstExprForStmt( + void *Stmt, isl_ast_build *Build, + isl_multi_pw_aff *(*FunctionIndex)(__isl_take isl_multi_pw_aff *MPA, + isl_id *Id, void *User), + void *UserIndex, + isl_ast_expr *(*FunctionExpr)(isl_ast_expr *Expr, isl_id *Id, void *User), + void *User_expr) { + + // TODO: Implement the AST expression generation. For now we just return a + // nullptr to ensure that we do not free uninitialized pointers. + + return nullptr; +} namespace { class PPCGCodeGeneration : public ScopPass { @@ -288,6 +305,7 @@ public: PPCGGen->options = PPCGScop->options; PPCGGen->print = nullptr; PPCGGen->print_user = nullptr; + PPCGGen->build_ast_expr = &pollyBuildAstExprForStmt; PPCGGen->prog = PPCGProg; PPCGGen->tree = nullptr; PPCGGen->types.n = 0; diff --git a/polly/lib/External/ppcg/gpu.c b/polly/lib/External/ppcg/gpu.c index 3eecf45..7bda56a 100644 --- a/polly/lib/External/ppcg/gpu.c +++ b/polly/lib/External/ppcg/gpu.c @@ -1453,6 +1453,7 @@ static int find_array_index(struct ppcg_kernel *kernel, const char *name) * to the current kernel. */ struct ppcg_transform_data { + struct ppcg_options *options; struct ppcg_kernel *kernel; struct gpu_stmt_access *accesses; isl_pw_multi_aff *iterator_map; @@ -1787,7 +1788,8 @@ static __isl_give isl_ast_expr *transform_expr(__isl_take isl_ast_expr *expr, */ static __isl_give isl_ast_node *create_domain_leaf( struct ppcg_kernel *kernel, __isl_take isl_ast_node *node, - __isl_keep isl_ast_build *build, struct gpu_stmt *gpu_stmt) + __isl_keep isl_ast_build *build, struct gpu_stmt *gpu_stmt, + struct gpu_gen *gen) { struct ppcg_transform_data data; struct ppcg_kernel_stmt *stmt; @@ -1822,10 +1824,9 @@ static __isl_give isl_ast_node *create_domain_leaf( data.accesses = stmt->u.d.stmt->accesses; data.iterator_map = iterator_map; data.sched2shared = sched2shared; - stmt->u.d.ref2expr = pet_stmt_build_ast_exprs(stmt->u.d.stmt->stmt, + stmt->u.d.ref2expr = gen->build_ast_expr(stmt->u.d.stmt->stmt, build, &transform_index, &data, &transform_expr, &data); - isl_pw_multi_aff_free(iterator_map); isl_pw_multi_aff_free(sched2shared); @@ -1944,6 +1945,7 @@ static __isl_give isl_ast_node *create_sync_leaf( */ struct ppcg_at_domain_data { struct gpu_prog *prog; + struct gpu_gen *gen; struct ppcg_kernel *kernel; }; @@ -1985,7 +1987,8 @@ static __isl_give isl_ast_node *at_domain(__isl_take isl_ast_node *node, isl_id_free(id); if (gpu_stmt) - return create_domain_leaf(data->kernel, node, build, gpu_stmt); + return create_domain_leaf(data->kernel, node, build, gpu_stmt, + data->gen); if (!prefixcmp(name, "to_device_") || !prefixcmp(name, "from_device_")) return node; @@ -2304,6 +2307,7 @@ static __isl_give isl_ast_node *generate_code(struct gpu_gen *gen, int depth; data.prog = gen->prog; + data.gen = gen; data.kernel = NULL; depth = 0; diff --git a/polly/lib/External/ppcg/gpu.h b/polly/lib/External/ppcg/gpu.h index c5009c0..7038901 100644 --- a/polly/lib/External/ppcg/gpu.h +++ b/polly/lib/External/ppcg/gpu.h @@ -148,6 +148,17 @@ struct gpu_gen { struct gpu_types *types, void *user); void *print_user; + isl_id_to_ast_expr *(*build_ast_expr)(void *stmt, + isl_ast_build *build, + isl_multi_pw_aff *(*fn_index)( + __isl_take isl_multi_pw_aff *mpa, isl_id *id, + void *user), + void *user_index, + isl_ast_expr *(*fn_expr)(isl_ast_expr *expr, + isl_id *id, void *user), + void *user_expr); + + struct gpu_prog *prog; /* The generated AST. */ isl_ast_node *tree;