2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief iropt --- optimizations of an ir node.
9 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
11 #ifndef FIRM_IR_IROPT_H
12 #define FIRM_IR_IROPT_H
14 #include "firm_types.h"
19 * @defgroup iropt Local Optimizations
24 * The Floating point model.
26 * Several basic properties are defined:
27 * - fp_explicit_rounding
28 * - fp_strict_algebraic
30 * - fp_strict_eval_order
32 * - fp_environment_access
34 * From those basic properties three general models are defined,
35 * compatible to the VC8 compiler:
37 * Default mode. Associative and distributive law forbidden unless a transformation
38 * is guaranteed to produce the same result.
39 * No FPU environment access. No FP exception semantics.
41 * Slowest mode. Additionally to fp_model_precise allows correct handling of
42 * FP exceptions and FPU environment access.
44 * Fastest mode. Associative and distributive law allowed at the expense
45 * of floating point accuracy and correctness. Explicit rounding is disabled.
47 typedef enum fp_model_t {
48 fp_explicit_rounding = (1u << 0), /**< Explicit rounding at assignments, typecasts, return
49 and function calls. Conv nodes may NOT be removed, even
50 if they look useless. */
51 fp_strict_algebraic = (1u << 1), /**< Strict adherence to non-associative and non-distributive
52 algebra unless the same result is guaranteed. */
53 fp_contradictions = (1u << 2), /**< FP contradictions are enabled. Only for backend. */
54 fp_strict_eval_order = (1u << 3), /**< FP instructions must be strict evaluated in given order. */
55 fp_exceptions = (1u << 4), /**< FP exceptions are supported. No reordering that changes
56 the exception flow are allowed. Backends must generate
57 synchronized exception code. */
58 fp_environment_access = (1u << 5), /**< FPU environment can be accessed. Even Constant folding
61 /** Precise floating point model. Default. */
62 fp_model_precise = fp_explicit_rounding|fp_strict_algebraic|fp_contradictions,
63 /** Strict floating point model. */
64 fp_model_strict = fp_explicit_rounding|fp_strict_algebraic|fp_strict_eval_order|
65 fp_exceptions|fp_environment_access,
66 /** Fast floating point model. */
67 fp_model_fast = fp_contradictions
70 /** If the expression referenced can be evaluated statically
71 * computed_value returns a tarval representing the result.
72 * Else returns tarval_bad. */
73 FIRM_API ir_tarval *computed_value(const ir_node *n);
75 /** Applies all optimizations to n that are expressible as a pattern
76 * in Firm, i.e., they need not a walk of the graph.
77 * Returns a better node for n. Does not free n -- other nodes could
80 * An equivalent optimization is applied in the constructors defined in
81 * ircons.ch. There n is freed if a better node could be found.
83 FIRM_API ir_node *optimize_in_place(ir_node *n);
86 * checks whether 1 value is the negated other value
88 FIRM_API int ir_is_negated_value(const ir_node *a, const ir_node *b);
91 * (conservatively) approximates all possible relations when comparing
92 * the value @p left and @p right
94 FIRM_API ir_relation ir_get_possible_cmp_relations(const ir_node *left,
95 const ir_node *right);