X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fbearch.h;h=6307741ed82c09187942bb34b202f86d5afe1d67;hb=2232b14b4acf810ae96a69d1d2a33cf150b695d9;hp=526f969ebdc1bf1c5caf72ed25cd37bd1105c832;hpb=a73a2f92b35f5feffbdb81d3b6be553dad71451b;p=libfirm diff --git a/ir/be/bearch.h b/ir/be/bearch.h index 526f969eb..6307741ed 100644 --- a/ir/be/bearch.h +++ b/ir/be/bearch.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -40,6 +40,13 @@ #include "beirg.h" #include "error.h" +/** + * this constant is returned by the get_sp_bias functions if the stack + * is reset (usually because the frame pointer is copied to the stack + * pointer + */ +#define SP_BIAS_RESET INT_MIN + typedef enum arch_register_class_flags_t { arch_register_class_flag_none = 0, /** don't do automatic register allocation for this class */ @@ -51,24 +58,18 @@ ENUM_BITSET(arch_register_class_flags_t) typedef enum arch_register_type_t { arch_register_type_none = 0, - /** The register must be saved by the caller upon a function call. It thus - * can be overwritten in the called function. */ - arch_register_type_caller_save = 1U << 0, - /** The register must be saved by the caller upon a function call. It thus - * can be overwritten in the called function. */ - arch_register_type_callee_save = 1U << 1, /** Do not consider this register when allocating. */ - arch_register_type_ignore = 1U << 2, + arch_register_type_ignore = 1U << 0, /** The emitter can choose an arbitrary register. The register fulfills any * register constraints as long as the register class matches */ - arch_register_type_joker = 1U << 3, + arch_register_type_joker = 1U << 1, /** This is just a virtual register. Virtual registers fulfill any register * constraints as long as the register class matches. It is a allowed to * have multiple definitions for the same virtual register at a point */ - arch_register_type_virtual = 1U << 4, + arch_register_type_virtual = 1U << 2, /** The register represents a state that should be handled by bestate * code */ - arch_register_type_state = 1U << 5, + arch_register_type_state = 1U << 3, } arch_register_type_t; ENUM_BITSET(arch_register_type_t) @@ -138,84 +139,98 @@ void arch_perform_memory_operand(ir_node *irn, ir_node *spill, unsigned int i); /** - * Get the register requirements for a node. - * @note Deprecated API! Preferably use - * arch_get_in_register_req and - * arch_get_out_register_req. - * - * @param irn The node. - * @param pos The position of the operand you're interested in. - * @return A pointer to the register requirements. If NULL is returned, the - * operand was no register operand. + * Get the register allocated for a value. */ -const arch_register_req_t *arch_get_register_req(const ir_node *irn, int pos); +const arch_register_t *arch_get_irn_register(const ir_node *irn); /** - * Check, if a register is assignable to an operand of a node. - * @param irn The node. - * @param pos The position of the operand. - * @param reg The register. - * @return 1, if the register might be allocated to the operand 0 if not. + * Assign register to a value */ -int arch_reg_is_allocatable(const ir_node *irn, int pos, - const arch_register_t *reg); - -#define arch_reg_out_is_allocatable(irn, reg) arch_reg_is_allocatable(irn, -1, reg) +void arch_set_irn_register(ir_node *irn, const arch_register_t *reg); /** - * Get the register class of an operand of a node. - * @param irn The node. - * @param pos The position of the operand, -1 for the output. - * @return The register class of the operand or NULL, if - * operand is a non-register operand. + * Set the register for a certain output operand. */ -const arch_register_class_t *arch_get_irn_reg_class(const ir_node *irn, - int pos); +void arch_set_irn_register_out(ir_node *irn, int pos, const arch_register_t *r); -#define arch_get_irn_reg_class_out(irn) arch_get_irn_reg_class(irn, -1) +const arch_register_t *arch_get_irn_register_out(const ir_node *irn, int pos); +const arch_register_t *arch_get_irn_register_in(const ir_node *irn, int pos); /** - * Get the register allocated at a certain output operand of a node. - * @param irn The node. - * @return The register allocated for this operand + * Get register constraints for an operand at position @p */ -const arch_register_t *arch_get_irn_register(const ir_node *irn); -const arch_register_t *arch_irn_get_register(const ir_node *irn, int pos); +static inline const arch_register_req_t *arch_get_irn_register_req_in( + const ir_node *node, int pos) +{ + const backend_info_t *info = be_get_info(node); + if (info->in_reqs == NULL) + return arch_no_register_req; + return info->in_reqs[pos]; +} /** - * Set the register for a certain output operand. - * @param irn The node. - * @param reg The register. + * Get register constraint for a produced result (the @p pos result) */ -void arch_set_irn_register(ir_node *irn, const arch_register_t *reg); -void arch_irn_set_register(ir_node *irn, int pos, const arch_register_t *reg); +static inline const arch_register_req_t *arch_get_irn_register_req_out( + const ir_node *node, int pos) +{ + const backend_info_t *info = be_get_info(node); + if (info->out_infos == NULL) + return arch_no_register_req; + return info->out_infos[pos].req; +} -/** - * Classify a node. - * @param irn The node. - * @return A classification of the node. - */ -arch_irn_class_t arch_irn_classify(const ir_node *irn); +static inline void arch_set_irn_register_req_out(ir_node *node, int pos, + const arch_register_req_t *req) +{ + backend_info_t *info = be_get_info(node); + assert(pos < (int)ARR_LEN(info->out_infos)); + info->out_infos[pos].req = req; +} + +static inline void arch_set_irn_register_reqs_in(ir_node *node, + const arch_register_req_t **reqs) +{ + backend_info_t *info = be_get_info(node); + info->in_reqs = reqs; +} + +static inline const arch_register_req_t **arch_get_irn_register_reqs_in( + const ir_node *node) +{ + backend_info_t *info = be_get_info(node); + return info->in_reqs; +} + +const arch_register_req_t *arch_get_irn_register_req(const ir_node *node); /** * Get the flags of a node. * @param irn The node. * @return The flags. */ -arch_irn_flags_t arch_irn_get_flags(const ir_node *irn); +arch_irn_flags_t arch_get_irn_flags(const ir_node *irn); + +void arch_set_irn_flags(ir_node *node, arch_irn_flags_t flags); +void arch_add_irn_flags(ir_node *node, arch_irn_flags_t flags); -void arch_irn_set_flags(ir_node *node, arch_irn_flags_t flags); -void arch_irn_add_flags(ir_node *node, arch_irn_flags_t flags); +#define arch_irn_is(irn, flag) ((arch_get_irn_flags(irn) & arch_irn_flags_ ## flag) != 0) + +static inline unsigned arch_get_irn_n_outs(const ir_node *node) +{ + backend_info_t *info = be_get_info(node); + if (info->out_infos == NULL) + return 0; -#define arch_irn_is(irn, flag) ((arch_irn_get_flags(irn) & arch_irn_flags_ ## flag) != 0) + return (unsigned)ARR_LEN(info->out_infos); +} /** - * Get the operations of an irn. - * @param self The handler from which the method is invoked. - * @param irn Some node. - * @return Operations for that irn. + * Classify a node. + * @param irn The node. + * @return A classification of the node. */ -typedef const void *(arch_get_irn_ops_t)(const ir_node *irn); +arch_irn_class_t arch_irn_classify(const ir_node *irn); /** * Initialize the architecture environment struct. @@ -262,15 +277,6 @@ static inline const char *arch_register_get_name(const arch_register_t *reg) return reg->name; } -/** - * Convenience macro to check for register type. - * @param req A pointer to register. - * @param kind The kind of type to check for (see arch_register_type_t). - * @return 1, If register is of given kind, 0 if not. - */ -#define arch_register_type_is(reg, kind) \ - (((reg)->type & arch_register_type_ ## kind) != 0) - /** * A class of registers. * Like general purpose or floating point. @@ -335,30 +341,26 @@ struct arch_register_req_t { registers are required */ }; -static inline int reg_reqs_equal(const arch_register_req_t *req1, - const arch_register_req_t *req2) +static inline bool reg_reqs_equal(const arch_register_req_t *req1, + const arch_register_req_t *req2) { if (req1 == req2) - return 1; + return true; - if (req1->type != req2->type - || req1->cls != req2->cls - || req1->other_same != req2->other_same - || req1->other_different != req2->other_different) - return 0; + if (req1->type != req2->type || + req1->cls != req2->cls || + req1->other_same != req2->other_same || + req1->other_different != req2->other_different || + (req1->limited != NULL) != (req2->limited != NULL)) + return false; if (req1->limited != NULL) { - size_t n_regs; - - if (req2->limited == NULL) - return 0; - - n_regs = arch_register_class_n_regs(req1->cls); + size_t const n_regs = arch_register_class_n_regs(req1->cls); if (!rbitsets_equal(req1->limited, req2->limited, n_regs)) - return 0; + return false; } - return 1; + return true; } /** @@ -467,6 +469,12 @@ struct arch_isa_if_t { */ arch_env_t *(*init)(FILE *file_handle); + /** + * lowers current program for target. See the documentation for + * be_lower_for_target() for details. + */ + void (*lower_for_target)(void); + /** * Free the isa instance. */ @@ -567,11 +575,6 @@ struct arch_isa_if_t { */ void (*before_ra)(ir_graph *irg); - /** - * Called after register allocation. - */ - void (*after_ra)(ir_graph *irg); - /** * Called directly before done is called. This should be the last place * where the irg is modified. @@ -584,6 +587,33 @@ struct arch_isa_if_t { * The code generator must also be de-allocated here. */ void (*emit)(ir_graph *irg); + + /** + * Checks if the given register is callee/caller saved. + * @deprecated, only necessary if backend still uses beabi functions + */ + int (*register_saved_by)(const arch_register_t *reg, int callee); + + /** + * Create a spill instruction. We assume that spill instructions + * do not need any additional registers and do not affect cpu-flags in any + * way. + * Construct a sequence of instructions after @p after (the resulting nodes + * are already scheduled). + * Returns a mode_M value which is used as input for a reload instruction. + */ + ir_node *(*new_spill)(ir_node *value, ir_node *after); + + /** + * Create a reload instruction. We assume that reload instructions do not + * need any additional registers and do not affect cpu-flags in any way. + * Constructs a sequence of instruction before @p before (the resulting + * nodes are already scheduled). A rewiring of users is not performed in + * this function. + * Returns a value representing the restored value. + */ + ir_node *(*new_reload)(ir_node *value, ir_node *spilled_value, + ir_node *before); }; #define arch_env_done(env) ((env)->impl->done(env)) @@ -601,6 +631,9 @@ struct arch_isa_if_t { #define arch_env_mark_remat(env,node) \ do { if ((env)->impl->mark_remat != NULL) (env)->impl->mark_remat((node)); } while(0) +#define arch_env_new_spill(env,value,after) ((env)->impl->new_spill(value, after)) +#define arch_env_new_reload(env,value,spilled,before) ((env)->impl->new_reload(value, spilled, before)) + /** * ISA base class. */ @@ -614,8 +647,6 @@ struct arch_env_t { const arch_register_t *bp; /**< The base pointer register. */ const arch_register_class_t *link_class; /**< The static link pointer register class. */ - int stack_dir; /**< -1 for decreasing, 1 for - increasing. */ int stack_alignment; /**< power of 2 stack alignment */ const be_main_env_t *main_env; /**< the be main environment */ int spill_cost; /**< cost for a be_Spill node */ @@ -625,107 +656,21 @@ struct arch_env_t { stuff from beabi.h/.c */ }; -static inline unsigned arch_irn_get_n_outs(const ir_node *node) -{ - backend_info_t *info = be_get_info(node); - if (info->out_infos == NULL) - return 0; - - return ARR_LEN(info->out_infos); -} - -static inline const arch_irn_ops_t *get_irn_ops_simple(const ir_node *node) -{ - const ir_op *ops = get_irn_op(node); - const arch_irn_ops_t *be_ops = get_op_ops(ops)->be_ops; - assert(!is_Proj(node)); - return be_ops; -} - -static inline const arch_register_req_t *arch_get_register_req_out( - const ir_node *irn) -{ - int pos = 0; - backend_info_t *info; - - /* you have to query the Proj nodes for the constraints (or use - * arch_get_out_register_req. Querying a mode_T node and expecting - * arch_no_register_req is a bug in your code! */ - assert(get_irn_mode(irn) != mode_T); - - if (is_Proj(irn)) { - pos = get_Proj_proj(irn); - irn = get_Proj_pred(irn); - } - - info = be_get_info(irn); - if (info->out_infos == NULL) - return arch_no_register_req; - - return info->out_infos[pos].req; -} - static inline bool arch_irn_is_ignore(const ir_node *irn) { - const arch_register_req_t *req = arch_get_register_req_out(irn); - return !!(req->type & arch_register_req_type_ignore); + const arch_register_req_t *req = arch_get_irn_register_req(irn); + return req->type & arch_register_req_type_ignore; } static inline bool arch_irn_consider_in_reg_alloc( const arch_register_class_t *cls, const ir_node *node) { - const arch_register_req_t *req = arch_get_register_req_out(node); + const arch_register_req_t *req = arch_get_irn_register_req(node); return req->cls == cls && !(req->type & arch_register_req_type_ignore); } -/** - * Get register constraints for an operand at position @p - */ -static inline const arch_register_req_t *arch_get_in_register_req( - const ir_node *node, int pos) -{ - const backend_info_t *info = be_get_info(node); - if (info->in_reqs == NULL) - return arch_no_register_req; - return info->in_reqs[pos]; -} - -/** - * Get register constraint for a produced result (the @p pos result) - */ -static inline const arch_register_req_t *arch_get_out_register_req( - const ir_node *node, int pos) -{ - const backend_info_t *info = be_get_info(node); - if (info->out_infos == NULL) - return arch_no_register_req; - return info->out_infos[pos].req; -} - -static inline void arch_set_out_register_req(ir_node *node, int pos, - const arch_register_req_t *req) -{ - backend_info_t *info = be_get_info(node); - assert(pos < (int) arch_irn_get_n_outs(node)); - info->out_infos[pos].req = req; -} - -static inline void arch_set_in_register_reqs(ir_node *node, - const arch_register_req_t **in_reqs) -{ - backend_info_t *info = be_get_info(node); - info->in_reqs = in_reqs; -} - -static inline const arch_register_req_t **arch_get_in_register_reqs( - const ir_node *node) -{ - backend_info_t *info = be_get_info(node); - return info->in_reqs; -} - /** * Iterate over all values defined by an instruction. * Only looks at values in a certain register class where the requirements @@ -739,13 +684,13 @@ static inline const arch_register_req_t **arch_get_in_register_reqs( foreach_out_edge(node, edge_) { \ const arch_register_req_t *req_; \ value = get_edge_src_irn(edge_); \ - req_ = arch_get_register_req_out(value); \ + req_ = arch_get_irn_register_req(value); \ if (req_->cls != cls) \ continue; \ code \ } \ } else { \ - const arch_register_req_t *req_ = arch_get_register_req_out(node); \ + const arch_register_req_t *req_ = arch_get_irn_register_req(node); \ value = node; \ if (req_->cls == cls) { \ code \ @@ -760,4 +705,14 @@ static inline const arch_register_req_t **arch_get_in_register_reqs( code \ ) +static inline const arch_register_class_t *arch_get_irn_reg_class( + const ir_node *node) +{ + const arch_register_req_t *req = arch_get_irn_register_req(node); + return req->cls; +} + +bool arch_reg_is_allocatable(const arch_register_req_t *req, + const arch_register_t *reg); + #endif