1 /* 2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. 3 * 4 * This file is part of libFirm. 5 * 6 * This file may be distributed and/or modified under the terms of the 7 * GNU General Public License version 2 as published by the Free Software 8 * Foundation and appearing in the file LICENSE.GPL included in the 9 * packaging of this file. 10 * 11 * Licensees holding valid libFirm Professional Edition licenses may use 12 * this file in accordance with the libFirm Commercial License. 13 * Agreement provided with the Software. 14 * 15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE. 18 */ 19 20 /** 21 * @file 22 * @brief Backend ABI implementation. 23 * @author Sebastian Hack 24 */ 25 #ifndef FIRM_BE_BEABI_H 26 #define FIRM_BE_BEABI_H 27 28 #include "firm_types.h" 29 30 #include "pset.h" 31 #include "pmap.h" 32 #include "bitset.h" 33 34 #include "be.h" 35 #include "beirg.h" 36 #include "bearch.h" 37 #include "beabi.h" 38 #include "beabihelper.h" 39 40 struct be_abi_call_flags_bits_t { 41 bool try_omit_fp : 1; /**< Try to omit the frame pointer. */ 42 bool call_has_imm : 1; /**< A call can take the callee's address as an 43 immediate. */ 44 }; 45 46 union be_abi_call_flags_t { 47 be_abi_call_flags_bits_t bits; 48 unsigned val; 49 }; 50 51 struct be_abi_callbacks_t { 52 /** 53 * Get the between type for that call. 54 * @param self The callback object. 55 * @return The between type of for that call. 56 */ 57 ir_type *(*get_between_type)(ir_graph *irg); 58 }; 59 60 /** 61 * Set the flags for a call. 62 * @param call The call. 63 * @param flags Some flags to be set. 64 * @param cb The call callbacks for that call. 65 * @note The ABI phase might change the flags due to analysis. 66 */ 67 void be_abi_call_set_flags(be_abi_call_t *call, be_abi_call_flags_t flags, const be_abi_callbacks_t *cb); 68 69 /** 70 * Sets the number of bytes the stackframe is shrinked by the callee on return 71 */ 72 void be_abi_call_set_pop(be_abi_call_t *call, int pop); 73 74 /** 75 * Set register class for call address. 76 * @param call The call. 77 * @param cls The register class for call address. 78 */ 79 void be_abi_call_set_call_address_reg_class(be_abi_call_t *call, const arch_register_class_t *cls); 80 81 /** 82 * The ABI can change when we call a function vs. when we have 83 * been called. 84 */ 85 typedef enum { 86 ABI_CONTEXT_CALLEE = 1 << 0, 87 ABI_CONTEXT_CALLER = 1 << 1, 88 ABI_CONTEXT_BOTH = ABI_CONTEXT_CALLEE | ABI_CONTEXT_CALLER 89 } be_abi_context_t; 90 91 /** 92 * Record the that ABI transmits call argument pos on the stack. Modifies the abi object. 93 * 94 * @param call the abi call object 95 * @param pos the parameter position 96 * @param load_mode load the parameter with this mode (if the parameter mode is different from this mode a Conv is inserted) 97 * @param alignment stack alignment for the parameter on the current architecture 98 * @param space_before size of allocated additional space before the parameter 99 * @param space_after size of allocated additional space after the parameter 100 */ 101 void be_abi_call_param_stack(be_abi_call_t *call, int pos, ir_mode *load_mode, 102 unsigned alignment, unsigned space_before, 103 unsigned space_after, be_abi_context_t context); 104 105 /** 106 * Record the that ABI transmits call argument pos in the given register. 107 * 108 * @param call the abi call object 109 * @param pos the parameter position 110 * @param reg the register used 111 */ 112 void be_abi_call_param_reg(be_abi_call_t *call, int pos, 113 const arch_register_t *reg, 114 be_abi_context_t context); 115 116 /** 117 * Record the that ABI transmits return value pos in the given register. 118 * 119 * @param call the abi call object 120 * @param pos the return value position 121 * @param reg the register used 122 */ 123 void be_abi_call_res_reg(be_abi_call_t *call, int pos, 124 const arch_register_t *reg, 125 be_abi_context_t context); 126 127 /** 128 * Get the flags of a ABI call object. 129 * Note that the flags must not be the same as set by be_abi_call_set_flags(). Analysis may have 130 * altered several flags, so getting them from the call object is always a good idea. 131 * @param call The call object. 132 * @return The flags. 133 */ 134 be_abi_call_flags_t be_abi_call_get_flags(const be_abi_call_t *call); 135 136 /** 137 * Get the method type of an ABI call object. 138 * @param call The call object. 139 * @return The method type for that call object. 140 */ 141 ir_type *be_abi_call_get_method_type(const be_abi_call_t *call); 142 143 void be_abi_introduce(ir_graph *irg); 144 145 void be_abi_free(ir_graph *irg); 146 147 #endif 148