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 Data modes of operations. 23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Mathias Heil, 24 * Michael Beck 25 */ 26 #ifndef FIRM_IR_IRMODE_H 27 #define FIRM_IR_IRMODE_H 28 29 #include "firm_types.h" 30 #include "begin.h" 31 32 #include <stddef.h> 33 34 /** 35 * @defgroup ir_mode Value Modes 36 * This module specifies the modes that type the firm nodes. It defines 37 * a datasturcture that describes a mode and implements constructors and 38 * access routines to this datastructure. Further it defines a set of 39 * predefined modes. 40 * 41 * SEE ALSO: 42 * UKA tech report 1999-44 for more information about modes. 43 * @{ 44 */ 45 46 /** 47 * These values represent the different arithmetic operations possible with a 48 * mode. 49 */ 50 typedef enum ir_mode_arithmetic { 51 irma_none = 1, /**< For modes for which no representation is 52 specified. These are modes of sort auxiliary, 53 internal_boolean and character. */ 54 irma_twos_complement = 2, /**< Values of the mode are represented as two's 55 complement. Only legal for modes of sort 56 int_number and reference. */ 57 irma_ieee754 = 256, /**< Values of the mode are represented according 58 to ieee754 floating point standard. Only 59 legal for modes of sort float_number. */ 60 irma_x86_extended_float, /**< x86 extended floatingpoint values */ 61 irma_last = irma_x86_extended_float, 62 } ir_mode_arithmetic; 63 64 /** 65 * Creates a new mode. 66 * 67 * @param name the name of the mode to be created 68 * @param arithmetic arithmetic operations possible with a mode 69 * @param bit_size number of bits this mode allocate 70 * @param sign non-zero if this is a signed mode 71 * @param modulo_shift Is ignored for modes other than integer. 72 * 73 * This function constructs a new mode given by the parameters. 74 * If the parameters match an already defined mode, this mode is returned 75 * (including the default modes). 76 * 77 * @return 78 * The new mode or NULL on error. 79 */ 80 FIRM_API ir_mode *new_int_mode(const char *name, 81 ir_mode_arithmetic arithmetic, 82 unsigned bit_size, int sign, 83 unsigned modulo_shift); 84 85 /** 86 * Create a new reference mode. 87 * 88 * Reference modes are always unsigned. 89 */ 90 FIRM_API ir_mode *new_reference_mode(const char *name, 91 ir_mode_arithmetic arithmetic, 92 unsigned bit_size, 93 unsigned modulo_shift); 94 95 /** 96 * Create a new ieee754 float mode. 97 * 98 * float-modes are always signed and have no modulo shift. 99 * @param name the name of the mode to be created 100 * @param arithmetic arithmetic/representation of the mode 101 * @param exponent_size size of exponent in bits 102 * @param mantissa_size size of mantissa in bits (number of bits after the 103 * leading one). 104 */ 105 FIRM_API ir_mode *new_float_mode(const char *name, 106 ir_mode_arithmetic arithmetic, 107 unsigned exponent_size, 108 unsigned mantissa_size); 109 110 /** 111 * Checks whether a pointer points to a mode. 112 * 113 * @param thing an arbitrary pointer 114 * 115 * @return 116 * true if the thing is a mode, else false 117 */ 118 FIRM_API int is_mode(const void *thing); 119 120 /** Returns the ident* of the mode */ 121 FIRM_API ident *get_mode_ident(const ir_mode *mode); 122 123 /** Returns the null-terminated name of this mode. */ 124 FIRM_API const char *get_mode_name(const ir_mode *mode); 125 126 /** Returns the size of values of the mode in bits. */ 127 FIRM_API unsigned get_mode_size_bits(const ir_mode *mode); 128 129 /** Returns the size of values of the mode in bytes. 130 * If the size is not dividable by 8 returns -1. */ 131 FIRM_API unsigned get_mode_size_bytes(const ir_mode *mode); 132 133 /** Returns the signess of a mode. 134 * 135 * Returns the signess of a mode: 1 if mode is signed. */ 136 FIRM_API int get_mode_sign(const ir_mode *mode); 137 138 /** Returns the arithmetic of a mode */ 139 FIRM_API ir_mode_arithmetic get_mode_arithmetic(const ir_mode *mode); 140 141 /** Returns the modulo shift attribute. 142 * 143 * Attribute modulo shift specifies for modes of kind irms_int_number 144 * whether shift applies modulo to value of bits to shift. Zero for 145 * modes that are not integer. 146 */ 147 FIRM_API unsigned int get_mode_modulo_shift(const ir_mode *mode); 148 149 /** Returns the stored intermediate information. */ 150 FIRM_API void *get_mode_link(const ir_mode *mode); 151 152 /** Stores new intermediate information. */ 153 FIRM_API void set_mode_link(ir_mode *mode, void *l); 154 155 /** 156 * Returns the smallest representable value of a given mode. 157 * 158 * For modes of the sort float_number this is the most negative value 159 * bigger than -infinite. 160 */ 161 FIRM_API ir_tarval *get_mode_min(ir_mode *mode); 162 163 /** 164 * Returns the biggest representable value o f a given mode. 165 * 166 * For modes of the sort float_number this is the largest value lower 167 * than infinite. 168 */ 169 FIRM_API ir_tarval *get_mode_max(ir_mode *mode); 170 171 /** 172 * Returns the value Zero represented in this mode. 173 * 174 * Zero is the additive neutral element and as such 175 * is defined only for modes allowing addition, i.e. 176 * op_pin_state_floats and ints, and references (NULL-Pointer) 177 * else returns tarval_bad. 178 */ 179 FIRM_API ir_tarval *get_mode_null(ir_mode *mode); 180 181 /** 182 * Returns the value One, represented in this mode. 183 * 184 * One, being the multiplicative neutral element, 185 * is defined only for modes allowing multiplication, 186 * i.e. ints and floats. 187 */ 188 FIRM_API ir_tarval *get_mode_one(ir_mode *mode); 189 190 /** 191 * Returns the value Minus One, represented in this mode. 192 * 193 * Minus One is defined only for modes allowing 194 * multiplication with signed values, i.e. signed ints and floats. 195 */ 196 FIRM_API ir_tarval *get_mode_minus_one(ir_mode *mode); 197 198 /** 199 * Returns the value where all bits are One, represented in this mode. 200 * 201 * All One is defined only for modes integer, reference and boolean modes 202 */ 203 FIRM_API ir_tarval *get_mode_all_one(ir_mode *mode); 204 205 /** 206 * Returns the positive infinite value of a mode. 207 * 208 * This is only valid for float_numbers, other modes 209 * will result in tarval_bad. 210 */ 211 FIRM_API ir_tarval *get_mode_infinite(ir_mode *mode); 212 213 /** 214 * Returns the NAN value of a given mode. 215 * 216 * This is only valid for float_numbers, other modes 217 * will result in tarval_bad. 218 */ 219 FIRM_API ir_tarval *get_mode_NAN(ir_mode *mode); 220 221 FIRM_API ir_mode *mode_M; /**< memory */ 222 223 FIRM_API ir_mode *mode_F; /**< ieee754 binary32 float (single precision) */ 224 FIRM_API ir_mode *mode_D; /**< ieee754 binary64 float (double precision) */ 225 FIRM_API ir_mode *mode_Q; /**< ieee754 binary128 float (quadruple precision)*/ 226 FIRM_API ir_mode *mode_Bs; /**< int8 */ 227 FIRM_API ir_mode *mode_Bu; /**< uint8 */ 228 FIRM_API ir_mode *mode_Hs; /**< int16 */ 229 FIRM_API ir_mode *mode_Hu; /**< uint16 */ 230 FIRM_API ir_mode *mode_Is; /**< int32 */ 231 FIRM_API ir_mode *mode_Iu; /**< uint32 */ 232 FIRM_API ir_mode *mode_Ls; /**< int64 */ 233 FIRM_API ir_mode *mode_Lu; /**< uint64 */ 234 FIRM_API ir_mode *mode_LLs; /**< int128 */ 235 FIRM_API ir_mode *mode_LLu; /**< uint128 */ 236 237 FIRM_API ir_mode *mode_P; /**< pointer */ 238 FIRM_API ir_mode *mode_P_code; /**< A pointer mode that is set by the client of libfirm. This mode 239 represents the pointer size of the target machine code addresses. Is initialized 240 to mode_P. */ 241 FIRM_API ir_mode *mode_P_data; /**< A pointer mode that is set by the client of libfirm. This mode 242 represents the pointer size of the target machine data addresses. Is initialized 243 to mode_P. */ 244 245 FIRM_API ir_mode *mode_b; /**< internal boolean */ 246 247 FIRM_API ir_mode *mode_X; /**< execution */ 248 FIRM_API ir_mode *mode_BB; /**< block */ 249 250 FIRM_API ir_mode *mode_T; /**< tuple (none) */ 251 FIRM_API ir_mode *mode_ANY;/**< undefined mode */ 252 FIRM_API ir_mode *mode_BAD;/**< bad mode */ 253 254 /** Returns float mode */ 255 FIRM_API ir_mode *get_modeF(void); 256 /** Returns double mode */ 257 FIRM_API ir_mode *get_modeD(void); 258 /** Returns quadruple prevision mode */ 259 FIRM_API ir_mode *get_modeQ(void); 260 /** Returns byte signed mode */ 261 FIRM_API ir_mode *get_modeBs(void); 262 /** Returns byte unsigned mode */ 263 FIRM_API ir_mode *get_modeBu(void); 264 /** Returns halfword signed mode */ 265 FIRM_API ir_mode *get_modeHs(void); 266 /** Returns halfword unsigned mode */ 267 FIRM_API ir_mode *get_modeHu(void); 268 /** Returns integer signed mode */ 269 FIRM_API ir_mode *get_modeIs(void); 270 /** Returns integer unsigned mode */ 271 FIRM_API ir_mode *get_modeIu(void); 272 /** Returns long signed mode */ 273 FIRM_API ir_mode *get_modeLs(void); 274 /** Returns long unsigned mode */ 275 FIRM_API ir_mode *get_modeLu(void); 276 /** Returns long long signed mode */ 277 FIRM_API ir_mode *get_modeLLs(void); 278 /** Returns long long unsigned mode */ 279 FIRM_API ir_mode *get_modeLLu(void); 280 /** Returns pointer mode */ 281 FIRM_API ir_mode *get_modeP(void); 282 /** Returns internal boolean mode */ 283 FIRM_API ir_mode *get_modeb(void); 284 /** Returns control-flow mode */ 285 FIRM_API ir_mode *get_modeX(void); 286 /** Returns Basic-Block mode */ 287 FIRM_API ir_mode *get_modeBB(void); 288 /** Returns memory mode */ 289 FIRM_API ir_mode *get_modeM(void); 290 /** Returns tuple mode */ 291 FIRM_API ir_mode *get_modeT(void); 292 /** Returns ANY mode */ 293 FIRM_API ir_mode *get_modeANY(void); 294 /** Returns BAD mode */ 295 FIRM_API ir_mode *get_modeBAD(void); 296 297 /** Returns the machine specific pointer mode for code addresses. */ 298 FIRM_API ir_mode *get_modeP_code(void); 299 300 /** Returns the machine specific pointer mode for data addresses. */ 301 FIRM_API ir_mode *get_modeP_data(void); 302 303 /** 304 * Sets the machine specific pointer mode for code addresses. 305 * If not set, the predefined mode mode_P will be used. 306 */ 307 FIRM_API void set_modeP_code(ir_mode *p); 308 309 /** 310 * Sets the machine specific pointer mode for data addresses. 311 * If not set, the predefined mode mode_P will be used. 312 */ 313 FIRM_API void set_modeP_data(ir_mode *p); 314 315 /** Returns 1 if @p mode is signed, 0 otherwise */ 316 FIRM_API int mode_is_signed (const ir_mode *mode); 317 /** Returns 1 if @p mode is for floatingpoint numbers, 0 otherwise */ 318 FIRM_API int mode_is_float (const ir_mode *mode); 319 /** Returns 1 if @p mode is for integer numbers, 0 otherwise */ 320 FIRM_API int mode_is_int (const ir_mode *mode); 321 /** Returns 1 if @p mode is for references/pointers, 0 otherwise */ 322 FIRM_API int mode_is_reference (const ir_mode *mode); 323 /** Returns 1 if @p mode is for numeric values, 0 otherwise */ 324 FIRM_API int mode_is_num (const ir_mode *mode); 325 /** Returns 1 if @p mode is for data values, 0 otherwise */ 326 FIRM_API int mode_is_data (const ir_mode *mode); 327 /** Returns 1 if @p mode is for data values or internal booleans, 0 otherwise */ 328 FIRM_API int mode_is_datab (const ir_mode *mode); 329 /** Returns 1 if @p mode is for data values or memory, 0 otherwise */ 330 FIRM_API int mode_is_dataM (const ir_mode *mode); 331 332 /** 333 * Returns true if a value of mode @p sm can be converted to mode @p lm without 334 * loss. 335 * 336 * That is the interpretation of the numbers does not changes, so you a signed 337 * integer mode is never smaller than an unsigned integer mode since the 338 * unsigned mode can't represent negative numbers in a way that they are 339 * interpreted as negative numbers. 340 * 341 * @see values_in_mode() 342 */ 343 FIRM_API int smaller_mode(const ir_mode *sm, const ir_mode *lm); 344 345 /** 346 * Returns true if no information is lost when converting a value of mode @p sm 347 * into mode @p lm (and back to mode @p sm). 348 * 349 * So the interpretation of the values may change in the intermediate mode @p sm 350 * (for example when converting negative signed integer numbers into unsigned 351 * integers) but after a conversion back they are exactly the same value. 352 * 353 * @see smaller_mode() 354 */ 355 FIRM_API int values_in_mode(const ir_mode *sm, const ir_mode *lm); 356 357 /** 358 * Returns a matching unsigned mode for a given integer signed mode. 359 * Returns NULL if no matching mode exists. 360 */ 361 FIRM_API ir_mode *find_unsigned_mode(const ir_mode *mode); 362 363 /** 364 * Returns a matching signed mode for a given integer unsigned mode. 365 * Returns NULL if no matching mode exists. 366 */ 367 FIRM_API ir_mode *find_signed_mode(const ir_mode *mode); 368 369 /** 370 * Returns an integer mode with 2*n bits for a given integer mode with n bits. 371 * Returns NULL if no matching mode exists. 372 */ 373 FIRM_API ir_mode *find_double_bits_int_mode(const ir_mode *mode); 374 375 /** 376 * Returns non-zero if the given mode honors signed zero's, i.e., 377 * a +0 and a -0 exists and handled differently. 378 */ 379 FIRM_API int mode_honor_signed_zeros(const ir_mode *mode); 380 381 /** 382 * Returns non-zero if the given mode might overflow on unary Minus. 383 */ 384 FIRM_API int mode_overflow_on_unary_Minus(const ir_mode *mode); 385 386 /** 387 * Returns non-zero if the mode has a reversed wrap-around 388 * logic, especially (a + x) - x == a. 389 * This is normally true for integer modes, not for floating 390 * point modes. 391 */ 392 FIRM_API int mode_wrap_around(const ir_mode *mode); 393 394 /** 395 * Returns the signed integer equivalent mode for an reference mode. 396 */ 397 FIRM_API ir_mode *get_reference_mode_signed_eq(ir_mode *mode); 398 399 /** 400 * Sets the signed integer equivalent mode for an reference mode. 401 */ 402 FIRM_API void set_reference_mode_signed_eq(ir_mode *ref_mode, ir_mode *int_mode); 403 404 /** 405 * Returns the unsigned integer equivalent mode for an reference mode. 406 */ 407 FIRM_API ir_mode *get_reference_mode_unsigned_eq(ir_mode *mode); 408 409 /** 410 * Sets the unsigned integer equivalent mode for an reference mode. 411 */ 412 FIRM_API void set_reference_mode_unsigned_eq(ir_mode *ref_mode, ir_mode *int_mode); 413 414 /** 415 * Returns size of mantissa in bits (for float modes). 416 * Note: This is the number of bits used after the leading one. So the actual 417 * accuracy of the significand is get_mode_mantissa_size()+1. The number of bits 418 * used in the encoding depends on wether the floatingpoint mode has an implicit 419 * (ieee754) or explicit (x86_extended) encoding of the leading one. 420 */ 421 FIRM_API unsigned get_mode_mantissa_size(const ir_mode *mode); 422 423 /** 424 * Returns size of exponent in bits (for float modes) 425 */ 426 FIRM_API unsigned get_mode_exponent_size(const ir_mode *mode); 427 428 /** 429 * Returns non-zero if the cast from mode src to mode dst is a 430 * reinterpret cast (ie. only the bit pattern is reinterpreted, 431 * no conversion is done) 432 */ 433 FIRM_API int is_reinterpret_cast(const ir_mode *src, const ir_mode *dst); 434 435 /** 436 * Returns the primitive type matching the given mode 437 */ 438 FIRM_API ir_type *get_type_for_mode(const ir_mode *mode); 439 440 /** Returns number of known modes. */ 441 FIRM_API size_t ir_get_n_modes(void); 442 443 /** Returns known mode number @p num. */ 444 FIRM_API ir_mode *ir_get_mode(size_t num); 445 446 /** @} */ 447 448 #include "end.h" 449 450 #endif 451