2 * Copyright 2012 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
12 #include "gpu_print.h"
15 static int print_macro(enum isl_ast_op_type type
, void *user
)
17 isl_printer
**p
= user
;
19 if (type
== isl_ast_op_fdiv_q
)
22 *p
= isl_ast_op_type_print_macro(type
, *p
);
27 /* Print the required macros for "node", including one for floord.
28 * We always print a macro for floord as it may also appear in the statements.
30 __isl_give isl_printer
*gpu_print_macros(__isl_take isl_printer
*p
,
31 __isl_keep isl_ast_node
*node
)
33 p
= isl_ast_op_type_print_macro(isl_ast_op_fdiv_q
, p
);
34 if (isl_ast_node_foreach_ast_op_type(node
, &print_macro
, &p
) < 0)
35 return isl_printer_free(p
);
39 /* Print an expression for the size of "array" in bytes.
41 __isl_give isl_printer
*gpu_array_info_print_size(__isl_take isl_printer
*prn
,
42 struct gpu_array_info
*array
)
46 for (i
= 0; i
< array
->n_index
; ++i
) {
47 prn
= isl_printer_print_str(prn
, "(");
48 prn
= isl_printer_print_pw_aff(prn
, array
->bound
[i
]);
49 prn
= isl_printer_print_str(prn
, ") * ");
51 prn
= isl_printer_print_str(prn
, "sizeof(");
52 prn
= isl_printer_print_str(prn
, array
->type
);
53 prn
= isl_printer_print_str(prn
, ")");
58 /* Print an access to the element in the private/shared memory copy
59 * described by "stmt". The index of the copy is recorded in
60 * stmt->local_index as an access to the array.
62 static __isl_give isl_printer
*stmt_print_local_index(__isl_take isl_printer
*p
,
63 struct ppcg_kernel_stmt
*stmt
)
65 return isl_printer_print_ast_expr(p
, stmt
->u
.c
.local_index
);
68 /* Print an access to the element in the global memory copy
69 * described by "stmt". The index of the copy is recorded in
70 * stmt->index as an access to the array.
72 * The copy in global memory has been linearized, so we need to take
73 * the array size into account.
75 static __isl_give isl_printer
*stmt_print_global_index(
76 __isl_take isl_printer
*p
, struct ppcg_kernel_stmt
*stmt
)
79 struct gpu_array_info
*array
= stmt
->u
.c
.array
;
80 struct gpu_local_array_info
*local
= stmt
->u
.c
.local_array
;
83 if (gpu_array_is_scalar(array
)) {
84 if (!array
->read_only
)
85 p
= isl_printer_print_str(p
, "*");
86 p
= isl_printer_print_str(p
, array
->name
);
90 index
= isl_ast_expr_copy(stmt
->u
.c
.index
);
91 index
= gpu_local_array_info_linearize_index(local
, index
);
92 p
= isl_printer_print_ast_expr(p
, index
);
93 isl_ast_expr_free(index
);
98 /* Print a copy statement.
100 * A read copy statement is printed as
104 * while a write copy statement is printed as
108 __isl_give isl_printer
*ppcg_kernel_print_copy(__isl_take isl_printer
*p
,
109 struct ppcg_kernel_stmt
*stmt
)
111 p
= isl_printer_start_line(p
);
112 if (stmt
->u
.c
.read
) {
113 p
= stmt_print_local_index(p
, stmt
);
114 p
= isl_printer_print_str(p
, " = ");
115 p
= stmt_print_global_index(p
, stmt
);
117 p
= stmt_print_global_index(p
, stmt
);
118 p
= isl_printer_print_str(p
, " = ");
119 p
= stmt_print_local_index(p
, stmt
);
121 p
= isl_printer_print_str(p
, ";");
122 p
= isl_printer_end_line(p
);
127 __isl_give isl_printer
*ppcg_kernel_print_domain(__isl_take isl_printer
*p
,
128 struct ppcg_kernel_stmt
*stmt
)
130 return pet_stmt_print_body(stmt
->u
.d
.stmt
->stmt
, p
, stmt
->u
.d
.ref2expr
);