[polly] r275435 - GPGPU: Add dummy implementation for ast expression construction

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 14 08:51:32 PDT 2016


Author: grosser
Date: Thu Jul 14 10:51:32 2016
New Revision: 275435

URL: http://llvm.org/viewvc/llvm-project?rev=275435&view=rev
Log:
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.

Modified:
    polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp
    polly/trunk/lib/External/ppcg/gpu.c
    polly/trunk/lib/External/ppcg/gpu.h

Modified: polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp?rev=275435&r1=275434&r2=275435&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/PPCGCodeGeneration.cpp Thu Jul 14 10:51:32 2016
@@ -41,6 +41,23 @@ static cl::opt<bool> DumpSchedule("polly
                                   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;

Modified: polly/trunk/lib/External/ppcg/gpu.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/ppcg/gpu.c?rev=275435&r1=275434&r2=275435&view=diff
==============================================================================
--- polly/trunk/lib/External/ppcg/gpu.c (original)
+++ polly/trunk/lib/External/ppcg/gpu.c Thu Jul 14 10:51:32 2016
@@ -1453,6 +1453,7 @@ static int find_array_index(struct ppcg_
  * 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 *transfor
  */
 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_d
 	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_s
  */
 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_domai
 	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
 	int depth;
 
 	data.prog = gen->prog;
+	data.gen = gen;
 	data.kernel = NULL;
 
 	depth = 0;

Modified: polly/trunk/lib/External/ppcg/gpu.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/ppcg/gpu.h?rev=275435&r1=275434&r2=275435&view=diff
==============================================================================
--- polly/trunk/lib/External/ppcg/gpu.h (original)
+++ polly/trunk/lib/External/ppcg/gpu.h Thu Jul 14 10:51:32 2016
@@ -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;




More information about the llvm-commits mailing list