aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVibhav Pant2022-10-14 17:21:13 +0530
committerVibhav Pant2022-10-14 17:27:12 +0530
commit1b48e8dde5bfee65c036fbfdc32b68c9093c2e06 (patch)
tree2c948c1651adc463efba3aed99053905aa6c09f8
parent271791b55b29945c30ddeb3eb7988f36246a2dfa (diff)
downloademacs-1b48e8dde5bfee65c036fbfdc32b68c9093c2e06.tar.gz
emacs-1b48e8dde5bfee65c036fbfdc32b68c9093c2e06.zip
src/comp.c: Use constructor expressions when possible.feature/comp-use-ctors
* src/comp.c: - Add declarations for creating constructor/initializer expressions when supported. - (emit_coerce): Use a struct constructor expression to create a Lisp_Object value instead of creating a new local variable. - emit_limple_call_ref: Emit a single constructor expression for initializing tmp_arr.
-rw-r--r--src/comp.c109
1 files changed, 97 insertions, 12 deletions
diff --git a/src/comp.c b/src/comp.c
index b7541c5d9f7..57e566603bc 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -67,6 +67,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
67#undef gcc_jit_context_get_int_type 67#undef gcc_jit_context_get_int_type
68#undef gcc_jit_context_get_type 68#undef gcc_jit_context_get_type
69#undef gcc_jit_context_new_array_access 69#undef gcc_jit_context_new_array_access
70#undef gcc_jit_context_new_array_constructor
70#undef gcc_jit_context_new_array_type 71#undef gcc_jit_context_new_array_type
71#undef gcc_jit_context_new_bitcast 72#undef gcc_jit_context_new_bitcast
72#undef gcc_jit_context_new_binary_op 73#undef gcc_jit_context_new_binary_op
@@ -84,7 +85,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
84#undef gcc_jit_context_new_rvalue_from_long 85#undef gcc_jit_context_new_rvalue_from_long
85#undef gcc_jit_context_new_rvalue_from_ptr 86#undef gcc_jit_context_new_rvalue_from_ptr
86#undef gcc_jit_context_new_string_literal 87#undef gcc_jit_context_new_string_literal
88#undef gcc_jit_context_new_struct_constructor
87#undef gcc_jit_context_new_struct_type 89#undef gcc_jit_context_new_struct_type
90#undef gcc_jit_context_new_union_constructor
88#undef gcc_jit_context_new_unary_op 91#undef gcc_jit_context_new_unary_op
89#undef gcc_jit_context_new_union_type 92#undef gcc_jit_context_new_union_type
90#undef gcc_jit_context_release 93#undef gcc_jit_context_release
@@ -96,6 +99,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
96#undef gcc_jit_function_new_block 99#undef gcc_jit_function_new_block
97#undef gcc_jit_function_new_local 100#undef gcc_jit_function_new_local
98#undef gcc_jit_global_set_initializer 101#undef gcc_jit_global_set_initializer
102#undef gcc_jit_global_set_initializer_rvalue
99#undef gcc_jit_lvalue_access_field 103#undef gcc_jit_lvalue_access_field
100#undef gcc_jit_lvalue_as_rvalue 104#undef gcc_jit_lvalue_as_rvalue
101#undef gcc_jit_lvalue_get_address 105#undef gcc_jit_lvalue_get_address
@@ -147,6 +151,12 @@ DEF_DLL_FN (gcc_jit_function *, gcc_jit_context_new_function,
147DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_context_new_array_access, 151DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_context_new_array_access,
148 (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_rvalue *ptr, 152 (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_rvalue *ptr,
149 gcc_jit_rvalue *index)); 153 gcc_jit_rvalue *index));
154#ifdef LIBGCCJIT_HAVE_CTORS
155DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_array_constructor,
156 (gcc_jit_context * ctxt, gcc_jit_location *loc,
157 gcc_jit_type *type, size_t num_values,
158 gcc_jit_rvalue **values));
159#endif
150DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_context_new_global, 160DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_context_new_global,
151 (gcc_jit_context *ctxt, gcc_jit_location *loc, 161 (gcc_jit_context *ctxt, gcc_jit_location *loc,
152 enum gcc_jit_global_kind kind, gcc_jit_type *type, 162 enum gcc_jit_global_kind kind, gcc_jit_type *type,
@@ -158,6 +168,10 @@ DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_function_new_local,
158DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_global_set_initializer, 168DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_global_set_initializer,
159 (gcc_jit_lvalue *global, const void *blob, size_t num_bytes)); 169 (gcc_jit_lvalue *global, const void *blob, size_t num_bytes));
160#endif 170#endif
171#ifdef LIBGCCJIT_HAVE_CTORS
172DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_global_set_initializer_rvalue,
173 (gcc_jit_lvalue *global, gcc_jit_rvalue *init_value));
174#endif
161DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_lvalue_access_field, 175DEF_DLL_FN (gcc_jit_lvalue *, gcc_jit_lvalue_access_field,
162 (gcc_jit_lvalue *struct_or_union, gcc_jit_location *loc, 176 (gcc_jit_lvalue *struct_or_union, gcc_jit_location *loc,
163 gcc_jit_field *field)); 177 gcc_jit_field *field));
@@ -200,6 +214,16 @@ DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_rvalue_from_ptr,
200#endif 214#endif
201DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_string_literal, 215DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_string_literal,
202 (gcc_jit_context *ctxt, const char *value)); 216 (gcc_jit_context *ctxt, const char *value));
217#ifdef LIBGCCJIT_HAVE_CTORS
218DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_struct_constructor,
219 (gcc_jit_context * ctxt, gcc_jit_location *loc,
220 gcc_jit_type *type, size_t num_values,
221 gcc_jit_field **fields, gcc_jit_rvalue **values));
222DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_union_constructor,
223 (gcc_jit_context * ctxt, gcc_jit_location *loc,
224 gcc_jit_type *type, gcc_jit_field *field,
225 gcc_jit_rvalue *value));
226#endif
203DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_unary_op, 227DEF_DLL_FN (gcc_jit_rvalue *, gcc_jit_context_new_unary_op,
204 (gcc_jit_context *ctxt, gcc_jit_location *loc, 228 (gcc_jit_context *ctxt, gcc_jit_location *loc,
205 enum gcc_jit_unary_op op, gcc_jit_type *result_type, 229 enum gcc_jit_unary_op op, gcc_jit_type *result_type,
@@ -302,6 +326,9 @@ init_gccjit_functions (void)
302 LOAD_DLL_FN (library, gcc_jit_context_get_int_type); 326 LOAD_DLL_FN (library, gcc_jit_context_get_int_type);
303 LOAD_DLL_FN (library, gcc_jit_context_get_type); 327 LOAD_DLL_FN (library, gcc_jit_context_get_type);
304 LOAD_DLL_FN (library, gcc_jit_context_new_array_access); 328 LOAD_DLL_FN (library, gcc_jit_context_new_array_access);
329#ifdef LIBGCCJIT_HAVE_CTORS
330 LOAD_DLL_FN (library, gcc_jit_context_new_array_constructor);
331#endif
305 LOAD_DLL_FN (library, gcc_jit_context_new_array_type); 332 LOAD_DLL_FN (library, gcc_jit_context_new_array_type);
306#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast 333#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
307 LOAD_DLL_FN (library, gcc_jit_context_new_bitcast); 334 LOAD_DLL_FN (library, gcc_jit_context_new_bitcast);
@@ -323,7 +350,13 @@ init_gccjit_functions (void)
323 LOAD_DLL_FN (library, gcc_jit_context_new_rvalue_from_ptr); 350 LOAD_DLL_FN (library, gcc_jit_context_new_rvalue_from_ptr);
324#endif 351#endif
325 LOAD_DLL_FN (library, gcc_jit_context_new_string_literal); 352 LOAD_DLL_FN (library, gcc_jit_context_new_string_literal);
353#ifdef LIBGCCJIT_HAVE_CTORS
354 LOAD_DLL_FN (library, gcc_jit_context_new_struct_constructor);
355#endif
326 LOAD_DLL_FN (library, gcc_jit_context_new_struct_type); 356 LOAD_DLL_FN (library, gcc_jit_context_new_struct_type);
357#ifdef LIBGCCJIT_HAVE_CTORS
358 LOAD_DLL_FN (library, gcc_jit_context_new_union_constructor);
359#endif
327 LOAD_DLL_FN (library, gcc_jit_context_new_unary_op); 360 LOAD_DLL_FN (library, gcc_jit_context_new_unary_op);
328 LOAD_DLL_FN (library, gcc_jit_context_new_union_type); 361 LOAD_DLL_FN (library, gcc_jit_context_new_union_type);
329 LOAD_DLL_FN (library, gcc_jit_context_release); 362 LOAD_DLL_FN (library, gcc_jit_context_release);
@@ -355,6 +388,10 @@ init_gccjit_functions (void)
355#if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer) 388#if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer)
356 LOAD_DLL_FN_OPT (library, gcc_jit_global_set_initializer); 389 LOAD_DLL_FN_OPT (library, gcc_jit_global_set_initializer);
357#endif 390#endif
391#ifdef LIBGCCJIT_HAVE_CTORS
392 LOAD_DLL_FN (gcc_jit_global_set_initializer_rvalue);
393#endif
394
358#if defined (LIBGCCJIT_HAVE_gcc_jit_version) 395#if defined (LIBGCCJIT_HAVE_gcc_jit_version)
359 LOAD_DLL_FN_OPT (library, gcc_jit_version_major); 396 LOAD_DLL_FN_OPT (library, gcc_jit_version_major);
360 LOAD_DLL_FN_OPT (library, gcc_jit_version_minor); 397 LOAD_DLL_FN_OPT (library, gcc_jit_version_minor);
@@ -383,6 +420,9 @@ init_gccjit_functions (void)
383#define gcc_jit_context_get_int_type fn_gcc_jit_context_get_int_type 420#define gcc_jit_context_get_int_type fn_gcc_jit_context_get_int_type
384#define gcc_jit_context_get_type fn_gcc_jit_context_get_type 421#define gcc_jit_context_get_type fn_gcc_jit_context_get_type
385#define gcc_jit_context_new_array_access fn_gcc_jit_context_new_array_access 422#define gcc_jit_context_new_array_access fn_gcc_jit_context_new_array_access
423#ifdef LIBGCCJIT_HAVE_CTORS
424#define gcc_jit_context_new_array_constructor fn_gcc_jit_context_new_array_constructor
425#endif
386#define gcc_jit_context_new_array_type fn_gcc_jit_context_new_array_type 426#define gcc_jit_context_new_array_type fn_gcc_jit_context_new_array_type
387#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast 427#ifdef LIBGCCJIT_HAVE_gcc_jit_context_new_bitcast
388# define gcc_jit_context_new_bitcast fn_gcc_jit_context_new_bitcast 428# define gcc_jit_context_new_bitcast fn_gcc_jit_context_new_bitcast
@@ -404,7 +444,13 @@ init_gccjit_functions (void)
404# define gcc_jit_context_new_rvalue_from_ptr fn_gcc_jit_context_new_rvalue_from_ptr 444# define gcc_jit_context_new_rvalue_from_ptr fn_gcc_jit_context_new_rvalue_from_ptr
405#endif 445#endif
406#define gcc_jit_context_new_string_literal fn_gcc_jit_context_new_string_literal 446#define gcc_jit_context_new_string_literal fn_gcc_jit_context_new_string_literal
447#ifdef LIBGCCJIT_HAVE_CTORS
448#define gcc_jit_context_new_struct_constructor fn_gcc_jit_context_new_struct_constructor
449#endif
407#define gcc_jit_context_new_struct_type fn_gcc_jit_context_new_struct_type 450#define gcc_jit_context_new_struct_type fn_gcc_jit_context_new_struct_type
451#ifdef LIBGCCJIT_HAVE_CTORS
452#define gcc_jit_context_new_union_constructor fn_gcc_jit_context_new_union_constructor
453#endif
408#define gcc_jit_context_new_unary_op fn_gcc_jit_context_new_unary_op 454#define gcc_jit_context_new_unary_op fn_gcc_jit_context_new_unary_op
409#define gcc_jit_context_new_union_type fn_gcc_jit_context_new_union_type 455#define gcc_jit_context_new_union_type fn_gcc_jit_context_new_union_type
410#define gcc_jit_context_release fn_gcc_jit_context_release 456#define gcc_jit_context_release fn_gcc_jit_context_release
@@ -418,6 +464,9 @@ init_gccjit_functions (void)
418#if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer) 464#if defined (LIBGCCJIT_HAVE_gcc_jit_global_set_initializer)
419 #define gcc_jit_global_set_initializer fn_gcc_jit_global_set_initializer 465 #define gcc_jit_global_set_initializer fn_gcc_jit_global_set_initializer
420#endif 466#endif
467#ifdef LIBGCCJIT_HAVE_CTORS
468#define gcc_jit_global_set_initializer_rvalue fn_gcc_jit_global_set_initializer_rvalue
469#endif
421#define gcc_jit_lvalue_access_field fn_gcc_jit_lvalue_access_field 470#define gcc_jit_lvalue_access_field fn_gcc_jit_lvalue_access_field
422#define gcc_jit_lvalue_as_rvalue fn_gcc_jit_lvalue_as_rvalue 471#define gcc_jit_lvalue_as_rvalue fn_gcc_jit_lvalue_as_rvalue
423#define gcc_jit_lvalue_get_address fn_gcc_jit_lvalue_get_address 472#define gcc_jit_lvalue_get_address fn_gcc_jit_lvalue_get_address
@@ -1159,6 +1208,14 @@ emit_coerce (gcc_jit_type *new_type, gcc_jit_rvalue *obj)
1159 gcc_jit_rvalue *lwordobj = 1208 gcc_jit_rvalue *lwordobj =
1160 emit_coerce (comp.lisp_word_type, obj); 1209 emit_coerce (comp.lisp_word_type, obj);
1161 1210
1211#ifdef LIBGCCJIT_HAVE_CTORS
1212 gcc_jit_rvalue *s
1213 = gcc_jit_context_new_struct_constructor (comp.ctxt, NULL,
1214 comp.lisp_obj_type,
1215 1, &comp.lisp_obj_i,
1216 &lwordobj);
1217 return s;
1218#else /* !LIBGCCJIT_HAVE_CTORS */
1162 static ptrdiff_t i; 1219 static ptrdiff_t i;
1163 gcc_jit_lvalue *tmp_s = 1220 gcc_jit_lvalue *tmp_s =
1164 gcc_jit_function_new_local (comp.func, NULL, comp.lisp_obj_type, 1221 gcc_jit_function_new_local (comp.func, NULL, comp.lisp_obj_type,
@@ -1170,6 +1227,7 @@ emit_coerce (gcc_jit_type *new_type, gcc_jit_rvalue *obj)
1170 comp.lisp_obj_i), 1227 comp.lisp_obj_i),
1171 lwordobj); 1228 lwordobj);
1172 return gcc_jit_lvalue_as_rvalue (tmp_s); 1229 return gcc_jit_lvalue_as_rvalue (tmp_s);
1230#endif
1173 } 1231 }
1174#endif 1232#endif
1175 1233
@@ -2138,6 +2196,10 @@ emit_limple_call_ref (Lisp_Object insn, bool direct)
2138 /* Ex: (funcall #s(comp-mvar 1 5 t eql symbol t) 2196 /* Ex: (funcall #s(comp-mvar 1 5 t eql symbol t)
2139 #s(comp-mvar 2 6 nil nil nil t) 2197 #s(comp-mvar 2 6 nil nil nil t)
2140 #s(comp-mvar 3 7 t 0 fixnum t)). */ 2198 #s(comp-mvar 3 7 t 0 fixnum t)). */
2199#ifdef LIBGCCJIT_HAVE_CTORS
2200 USE_SAFE_ALLOCA;
2201#endif
2202
2141 static int i = 0; 2203 static int i = 0;
2142 Lisp_Object callee = FIRST (insn); 2204 Lisp_Object callee = FIRST (insn);
2143 EMACS_INT nargs = XFIXNUM (Flength (CDR (insn))); 2205 EMACS_INT nargs = XFIXNUM (Flength (CDR (insn)));
@@ -2153,20 +2215,30 @@ emit_limple_call_ref (Lisp_Object insn, bool direct)
2153 return emit_call_ref (callee, nargs, comp.frame[first_slot], direct); 2215 return emit_call_ref (callee, nargs, comp.frame[first_slot], direct);
2154 } 2216 }
2155 2217
2218 gcc_jit_type *call_arr_type
2219 = gcc_jit_context_new_array_type (comp.ctxt, NULL,
2220 comp.lisp_obj_type, nargs);
2156 gcc_jit_lvalue *tmp_arr = 2221 gcc_jit_lvalue *tmp_arr =
2157 gcc_jit_function_new_local ( 2222 gcc_jit_function_new_local (
2158 comp.func, 2223 comp.func,
2159 NULL, 2224 NULL,
2160 gcc_jit_context_new_array_type (comp.ctxt, 2225 call_arr_type,
2161 NULL,
2162 comp.lisp_obj_type,
2163 nargs),
2164 format_string ("call_arr_%d", i++)); 2226 format_string ("call_arr_%d", i++));
2165 2227
2166 ptrdiff_t j = 0; 2228 ptrdiff_t j = 0;
2167 Lisp_Object arg = CDR (insn); 2229 Lisp_Object arg = CDR (insn);
2230#ifdef LIBGCCJIT_HAVE_CTORS
2231 /* Instead of emitting nargs assignments to the call array, emit
2232 a single initialize expression for the array. */
2233 gcc_jit_rvalue **values;
2234 SAFE_NALLOCA (values, 1, nargs);
2235#endif
2236
2168 FOR_EACH_TAIL (arg) 2237 FOR_EACH_TAIL (arg)
2169 { 2238 {
2239#ifdef LIBGCCJIT_HAVE_CTORS
2240 values[j] = emit_mvar_rval (XCAR (arg));
2241#else /* !LIBGCCJIT_HAVE_CTORS*/
2170 gcc_jit_block_add_assignment ( 2242 gcc_jit_block_add_assignment (
2171 comp.block, 2243 comp.block,
2172 NULL, 2244 NULL,
@@ -2178,17 +2250,30 @@ emit_limple_call_ref (Lisp_Object insn, bool direct)
2178 comp.int_type, 2250 comp.int_type,
2179 j)), 2251 j)),
2180 emit_mvar_rval (XCAR (arg))); 2252 emit_mvar_rval (XCAR (arg)));
2253#endif
2181 ++j; 2254 ++j;
2182 } 2255 }
2183 2256
2184 return emit_call_ref ( 2257#ifdef LIBGCCJIT_HAVE_CTORS
2185 callee, 2258 gcc_jit_rvalue *ctor
2186 nargs, 2259 = gcc_jit_context_new_array_constructor (comp.ctxt, NULL,
2187 gcc_jit_context_new_array_access (comp.ctxt, 2260 call_arr_type, nargs,
2188 NULL, 2261 values);
2189 gcc_jit_lvalue_as_rvalue (tmp_arr), 2262 gcc_jit_block_add_assignment (comp.block, NULL, tmp_arr, ctor);
2190 comp.zero), 2263#endif
2191 direct); 2264
2265 gcc_jit_rvalue *call
2266 = emit_call_ref (callee, nargs,
2267 gcc_jit_context_new_array_access (
2268 comp.ctxt, NULL,
2269 gcc_jit_lvalue_as_rvalue (tmp_arr), comp.zero),
2270 direct);
2271
2272#ifdef LIBGCCJIT_HAVE_CTORS
2273 SAFE_FREE();
2274#endif
2275
2276 return call;
2192} 2277}
2193 2278
2194static gcc_jit_rvalue * 2279static gcc_jit_rvalue *