Commit 34258536 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

tr: Set variadicity directly when creating method types.

parent b0f7f0ac
......@@ -11,6 +11,7 @@
#define FIRM_TYPEREP_H
#include <stddef.h>
#include <stdbool.h>
#include "firm_types.h"
......@@ -1242,13 +1243,14 @@ FIRM_API int is_Union_type(const ir_type *uni);
/** Create a new method type.
*
* @param n_param the number of parameters
* @param n_res the number of results
* @param n_param the number of parameters
* @param n_res the number of results
* @param is_variadic whether the function is variadic
*
* The arrays for the parameter and result types are not initialized by
* the constructor.
*/
FIRM_API ir_type *new_type_method(size_t n_param, size_t n_res);
FIRM_API ir_type *new_type_method(size_t n_param, size_t n_res, bool is_variadic);
/** Returns the number of parameters of this method. */
FIRM_API size_t get_method_n_params(const ir_type *method);
......@@ -1269,9 +1271,6 @@ FIRM_API void set_method_res_type(ir_type *method, size_t pos, ir_type *tp);
/** Returns the variadicity of a method. */
FIRM_API int is_method_variadic(ir_type const *method);
/** Sets the variadicity of a method. */
FIRM_API void set_method_variadic(ir_type *method, int is_variadic);
/** Returns the mask of the additional graph properties. */
FIRM_API mtp_additional_properties get_method_additional_properties(const ir_type *method);
......
......@@ -894,11 +894,11 @@ static pmap *mtp_map;
*
* @param tp the type to clone
*/
static ir_type *clone_type_and_cache(ir_type *tp)
static ir_type *clone_type_and_cache(ir_type *const tp, bool const is_variadic)
{
ir_type *res = pmap_get(ir_type, mtp_map, tp);
if (res == NULL) {
res = clone_type_method(tp);
res = clone_type_method(tp, is_variadic);
add_method_additional_properties(res, mtp_property_private);
pmap_insert(mtp_map, tp, res);
}
......@@ -922,11 +922,10 @@ static void update_calls_to_private(ir_node *call, void *env)
ir_type *ctp = get_Call_type(call);
if ((get_entity_additional_properties(callee) & mtp_property_private)
&& ((get_method_additional_properties(ctp) & mtp_property_private) == 0)) {
ctp = clone_type_and_cache(ctp);
ir_type *const entity_ctp = get_entity_type(callee);
/* clear mismatches in variadicity that can happen in obscure C
* programs and break when changing to private calling convention. */
ir_type *entity_ctp = get_entity_type(callee);
set_method_variadic(ctp, is_method_variadic(entity_ctp));
ctp = clone_type_and_cache(ctp, is_method_variadic(entity_ctp));
set_Call_type(call, ctp);
DB((dbgcall, LEVEL_1,
"changed call to private method %+F using cloned type %+F\n",
......@@ -952,7 +951,7 @@ void mark_private_methods(void)
DB((dbgcall, LEVEL_1, "found private method %+F\n", ent));
if ((get_method_additional_properties(mtp) & mtp_property_private) == 0) {
/* need a new type */
mtp = clone_type_and_cache(mtp);
mtp = clone_type_and_cache(mtp, is_method_variadic(mtp));
set_entity_type(ent, mtp);
DB((dbgcall, LEVEL_2, "changed entity type of %+F to %+F\n", ent, mtp));
changed = true;
......
......@@ -117,7 +117,7 @@ static void handle_intrinsic(ir_node *node, void *data)
static ir_type *make_divmod_type(ir_type *const tp)
{
ir_type *const mtp = new_type_method(2, 1);
ir_type *const mtp = new_type_method(2, 1, false);
set_method_param_type(mtp, 0, tp);
set_method_param_type(mtp, 1, tp);
set_method_res_type(mtp, 0, tp);
......
......@@ -107,7 +107,7 @@ static ir_entity *uldivmod;
static ir_entity *make_divmod(char const *const name, ir_type *const even, ir_type *const odd)
{
ir_type *const mtp = new_type_method(4, 4);
ir_type *const mtp = new_type_method(4, 4, false);
set_method_param_type(mtp, 0, even);
set_method_param_type(mtp, 1, odd);
set_method_param_type(mtp, 2, even);
......
......@@ -1135,7 +1135,7 @@ static void ia32_select_instructions(ir_graph *irg)
static ir_entity *mcount = NULL;
if (mcount == NULL) {
ir_type *tp = new_type_method(0, 0);
ir_type *tp = new_type_method(0, 0, false);
ident *id = new_id_from_str("mcount");
mcount = new_global_entity(get_glob_type(), id, tp,
ir_visibility_external,
......
......@@ -1188,7 +1188,7 @@ zero_neg:
static ir_type *get_thunk_type(void)
{
if (!thunk_type) {
ir_type *const tp = new_type_method(0, 1);
ir_type *const tp = new_type_method(0, 1, false);
set_method_res_type(tp, 0, get_type_for_mode(mode_P));
thunk_type = tp;
}
......
......@@ -290,7 +290,7 @@ static void handle_intrinsic(ir_node *node, void *data)
static ir_type *make_mod_type(ir_type *const tp)
{
ir_type *const mtp = new_type_method(2, 1);
ir_type *const mtp = new_type_method(2, 1, false);
set_method_param_type(mtp, 0, tp);
set_method_param_type(mtp, 1, tp);
set_method_res_type(mtp, 0, tp);
......
......@@ -160,7 +160,7 @@ bool sparc_variadic_fixups(ir_graph *irg, calling_convention_t *cconv)
size_t const n_params = get_method_n_params(mtp);
size_t const n_ress = get_method_n_ress(mtp);
size_t const new_n_params = n_params + (SPARC_N_PARAM_REGS - cconv->n_param_regs);
ir_type *const new_mtp = new_type_method(new_n_params, n_ress);
ir_type *const new_mtp = new_type_method(new_n_params, n_ress, true);
type_dbg_info *const dbgi = get_type_dbg_info(mtp);
set_type_dbg_info(new_mtp, dbgi);
......
......@@ -595,11 +595,11 @@ static void write_type_method(write_env_t *env, ir_type *tp)
write_unsigned(env, get_method_additional_properties(tp));
write_size_t(env, nparams);
write_size_t(env, nresults);
write_unsigned(env, is_method_variadic(tp));
for (size_t i = 0; i < nparams; i++)
write_type_ref(env, get_method_param_type(tp, i));
for (size_t i = 0; i < nresults; i++)
write_type_ref(env, get_method_res_type(tp, i));
write_unsigned(env, is_method_variadic(tp));
fputc('\n', env->file);
}
......@@ -1626,10 +1626,10 @@ static void read_type(read_env_t *env)
unsigned callingconv = read_unsigned(env);
mtp_additional_properties addprops
= (mtp_additional_properties) read_long(env);
size_t nparams = read_size_t(env);
size_t nresults = read_size_t(env);
type = new_type_method(nparams, nresults);
size_t const nparams = read_size_t(env);
size_t const nresults = read_size_t(env);
bool const is_variadic = read_long(env);
type = new_type_method(nparams, nresults, is_variadic);
for (size_t i = 0; i < nparams; i++) {
long ptypenr = read_long(env);
......@@ -1644,9 +1644,6 @@ static void read_type(read_env_t *env)
set_method_res_type(type, i, restype);
}
int const variadic = read_long(env);
set_method_variadic(type, variadic);
set_method_calling_convention(type, callingconv);
set_method_additional_properties(type, addprops);
goto finish_type;
......
......@@ -151,7 +151,7 @@ static void add_constructor(ir_entity *method)
static ir_entity *get_init_firmprof_ref(void)
{
ident *const init_name = new_id_from_str("__init_firmprof");
ir_type *const init_type = new_type_method(3, 0);
ir_type *const init_type = new_type_method(3, 0, false);
ir_type *const uint = new_type_primitive(mode_Iu);
ir_type *const uintptr = new_type_pointer(uint);
ir_type *const string = new_type_pointer(new_type_primitive(mode_Bs));
......@@ -176,7 +176,7 @@ static ir_graph *gen_initializer_irg(ir_entity *ent_filename, ir_entity *bblock_
{
ident *const name = new_id_from_str("__firmprof_initializer");
ir_type *const owner = get_glob_type();
ir_type *const type = new_type_method(0, 0);
ir_type *const type = new_type_method(0, 0, false);
ir_entity *const ent = new_global_entity(owner, name, type, ir_visibility_local, IR_LINKAGE_DEFAULT);
ir_graph *const irg = new_ir_graph(ent, 0);
......
......@@ -95,7 +95,7 @@ static void widen_builtin(ir_node *node)
ir_type *new_arg1 = get_type_for_mode(target_mode);
ir_type *new_result = get_method_res_type(mtp, 0);
ir_type *new_type = new_type_method(1, 1);
ir_type *new_type = new_type_method(1, 1, false);
set_method_param_type(new_type, 0, new_arg1);
set_method_res_type(new_type, 0, new_result);
set_Builtin_type(node, new_type);
......
......@@ -180,7 +180,8 @@ static ir_type *lower_mtp(lowering_env_t const *const env, ir_type *mtp)
assert(nn_params <= n_params + n_ress);
/* create the new type */
lowered = new_type_method(nn_params, nn_ress);
bool const is_variadic = is_method_variadic(mtp);
lowered = new_type_method(nn_params, nn_ress, is_variadic);
set_type_dbg_info(lowered, get_type_dbg_info(mtp));
/* fill it */
......@@ -189,8 +190,6 @@ static ir_type *lower_mtp(lowering_env_t const *const env, ir_type *mtp)
for (size_t i = 0; i < nn_ress; ++i)
set_method_res_type(lowered, i, results[i]);
set_method_variadic(lowered, is_method_variadic(mtp));
unsigned cconv = get_method_calling_convention(mtp);
if (nn_params > n_params) {
cconv |= cc_compound_ret;
......
......@@ -94,7 +94,7 @@ static void lower_small_copyb_node(ir_node *irn)
static ir_type *get_memcpy_methodtype(void)
{
ir_type *tp = new_type_method(3, 1);
ir_type *tp = new_type_method(3, 1, false);
ir_mode *size_t_mode = get_ir_mode(native_mode_bytes);
set_method_param_type(tp, 0, get_type_for_mode(mode_P));
......
......@@ -149,7 +149,7 @@ static ir_type *get_conv_type(ir_mode *imode, ir_mode *omode)
n_res = 2;
/* create a new method type */
mtd = new_type_method(n_param, n_res);
mtd = new_type_method(n_param, n_res, false);
/* set param types and result types */
n_param = 0;
......@@ -1588,7 +1588,8 @@ static ir_type *lower_mtp(ir_type *mtp)
return mtp;
}
res = new_type_method(n_param, n_res);
bool const is_variadic = is_method_variadic(mtp);
res = new_type_method(n_param, n_res, is_variadic);
set_type_dbg_info(res, get_type_dbg_info(mtp));
/* set param types and result types */
......@@ -2115,7 +2116,7 @@ static ir_type *lower_Builtin_type_high(ir_type *mtp)
return mtp;
}
res = new_type_method(n_params, n_results);
res = new_type_method(n_params, n_results, false);
set_type_dbg_info(res, get_type_dbg_info(mtp));
/* set param types and result types */
......@@ -2197,7 +2198,7 @@ static ir_type *lower_Builtin_type_low(ir_type *mtp)
return mtp;
}
res = new_type_method(n_params, n_results);
res = new_type_method(n_params, n_results, false);
set_type_dbg_info(res, get_type_dbg_info(mtp));
/* set param types and result types */
......@@ -2685,7 +2686,7 @@ static int lower_mux_cb(ir_node *mux)
static ir_type *make_type_4_2(ir_type *const even, ir_type *const odd)
{
ir_type *const tp = new_type_method(4, 2);
ir_type *const tp = new_type_method(4, 2, false);
set_method_param_type(tp, 0, even);
set_method_param_type(tp, 1, odd);
set_method_param_type(tp, 2, even);
......@@ -2697,7 +2698,7 @@ static ir_type *make_type_4_2(ir_type *const even, ir_type *const odd)
static ir_type *make_type_2_2(ir_type *const even, ir_type *const odd)
{
ir_type *const tp = new_type_method(2, 2);
ir_type *const tp = new_type_method(2, 2, false);
set_method_param_type(tp, 0, even);
set_method_param_type(tp, 1, odd);
set_method_res_type(tp, 0, even);
......
......@@ -327,9 +327,10 @@ static ir_type *lower_method_type(ir_type *mtp)
if (res != NULL)
return res;
size_t const n_param = get_method_n_params(mtp);
size_t const n_res = get_method_n_ress(mtp);
res = new_type_method(n_param, n_res);
size_t const n_param = get_method_n_params(mtp);
size_t const n_res = get_method_n_ress(mtp);
bool const is_variadic = is_method_variadic(mtp);
res = new_type_method(n_param, n_res, is_variadic);
/* set param types and result types */
for (size_t i = 0; i < n_param; ++i) {
......@@ -764,7 +765,7 @@ static void make_binop_type(ir_type **const memoized, ir_type *const left,
ir_type *const right, ir_type *const res)
{
if (!*memoized) {
ir_type *const type = *memoized = new_type_method(2, 1);
ir_type *const type = *memoized = new_type_method(2, 1, false);
set_method_param_type(type, 0, left);
set_method_param_type(type, 1, right);
set_method_res_type( type, 0, res);
......@@ -775,7 +776,7 @@ static void make_unop_type(ir_type **const memoized, ir_type *const op,
ir_type *const res)
{
if (!*memoized) {
ir_type *const type = *memoized = new_type_method(1, 1);
ir_type *const type = *memoized = new_type_method(1, 1, false);
set_method_param_type(type, 0, op);
set_method_res_type( type, 0, res);
}
......
......@@ -422,7 +422,7 @@ static void change_entity_type(const quadruple_t *q, ir_entity *ent)
/* Create the new type for our clone. It must have one parameter
less then the original.*/
ir_type *const new_mtp = new_type_method(n_params - 1, n_ress);
ir_type *const new_mtp = new_type_method(n_params - 1, n_ress, false);
/* We must set the type of the methods parameters.*/
for (size_t i = 0, j = 0; i < n_params; ++i) {
......
......@@ -559,7 +559,7 @@ int (is_Struct_type)(const ir_type *strct)
return is_struct_type_(strct);
}
ir_type *new_type_method(size_t n_param, size_t n_res)
ir_type *new_type_method(size_t const n_param, size_t const n_res, bool const is_variadic)
{
ir_type *res = new_type(tpo_method, sizeof(method_attr), mode_P);
res->flags |= tf_layout_fixed;
......@@ -568,14 +568,14 @@ ir_type *new_type_method(size_t n_param, size_t n_res)
res->attr.method.params = XMALLOCNZ(ir_type*, n_param);
res->attr.method.n_res = n_res;
res->attr.method.res_type = XMALLOCNZ(ir_type*, n_res);
res->attr.method.variadic = false;
res->attr.method.variadic = is_variadic;
res->attr.method.properties = mtp_no_property;
set_type_alignment(res, 1);
hook_new_type(res);
return res;
}
ir_type *clone_type_method(ir_type *tp)
ir_type *clone_type_method(ir_type *const tp, bool const is_variadic)
{
assert(is_Method_type(tp));
ir_mode *mode = tp->mode;
......@@ -594,7 +594,7 @@ ir_type *clone_type_method(ir_type *tp)
res->attr.method.n_res = n_res;
res->attr.method.res_type = XMALLOCN(ir_type*, n_res);
MEMCPY(res->attr.method.res_type, tp->attr.method.res_type, n_res);
res->attr.method.variadic = tp->attr.method.variadic;
res->attr.method.variadic = is_variadic;
res->attr.method.properties = tp->attr.method.properties;
res->attr.method.irg_calling_conv = tp->attr.method.irg_calling_conv;
set_type_alignment(res, get_type_alignment(tp));
......@@ -655,12 +655,6 @@ int is_method_variadic(ir_type const *const method)
return method->attr.method.variadic;
}
void set_method_variadic(ir_type *const method, int const is_variadic)
{
assert(is_Method_type(method));
method->attr.method.variadic = is_variadic;
}
mtp_additional_properties (get_method_additional_properties)(const ir_type *method)
{
return get_method_additional_properties_(method);
......
......@@ -162,13 +162,12 @@ void ir_finish_type(ir_prog *irp);
/** Clone an existing method type.
*
* @param tp the method type to clone.
* @param prefix if non-null, will be the prefix for the name of
* the cloned type
* @param tp the method type to clone.
* @param is_variadic whether the cloned type is variadic
*
* @return the cloned method type.
*/
ir_type *clone_type_method(ir_type *tp);
ir_type *clone_type_method(ir_type *tp, bool is_variadic);
extern ir_visited_t firm_type_visited;
......@@ -386,7 +385,6 @@ ir_type *new_type_segment(ident *name, type_flags flags);
static inline void copy_method_properties(ir_type *const dst, ir_type const *const src)
{
set_method_variadic(dst, is_method_variadic(src));
set_method_calling_convention(dst, get_method_calling_convention(src));
set_method_additional_properties(dst, get_method_additional_properties(src));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment