iropt.h 3.98 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
/*
Michael Beck's avatar
Michael Beck committed
2
 * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
Christian Würdig's avatar
Christian Würdig committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *
 * This file is part of libFirm.
 *
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 *
 * Licensees holding valid libFirm Professional Edition licenses may use
 * this file in accordance with the libFirm Commercial License.
 * Agreement provided with the Software.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

Michael Beck's avatar
Michael Beck committed
20
/**
Matthias Braun's avatar
Matthias Braun committed
21
22
23
24
 * @file
 * @brief   iropt --- optimizations of an ir node.
 * @author  Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
 * @version $Id$
25
 */
Matthias Braun's avatar
Matthias Braun committed
26
27
#ifndef FIRM_IR_IROPT_H
#define FIRM_IR_IROPT_H
Christian Schäfer's avatar
Christian Schäfer committed
28

29
#include "firm_types.h"
Christian Schäfer's avatar
Christian Schäfer committed
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * The Floating point model.
 *
 * Several basic properties are defined:
 * - fp_explicit_rounding
 * - fp_strict_algebraic
 * - fp_contradictions
 * - fp_strict_eval_order
 * - fp_exceptions
 * - fp_environment_access
 *
 * From those basic properties three general models are defined,
 * compatible to the VC8 compiler:
 * - fp_model_precise:
 *     Default mode. Associative and distributive law forbidden unless a transformation
 *     is guaranteed to produce the same result.
 *     No FPU environment access. No FP exception semantics.
 * - fp_model_strict:
 *     Slowest mode. Additionally to fp_model_precise allows correct handling of
 *     FP exceptions and FPU environment access.
 * - fp_model_fast:
 *     Fastest mode. Associative and distributive law allowed at the expense
Michael Beck's avatar
Michael Beck committed
53
 *     of floating point accuracy and correctness. Explicit rounding is disabled.
54
 * - fp_no_float_fold:
Christoph Mallon's avatar
Christoph Mallon committed
55
 *     Avoid floating point constant folding. Useful for frontends which do not
56
 *     create arithmetic operations in the backends arithmetic mode.
57
58
 */
typedef enum _fp_model_t {
59
	fp_explicit_rounding  = (1u << 0),  /**< Explicit rounding at assignments, typecasts, return
Michael Beck's avatar
Michael Beck committed
60
61
	                                  and function calls. Conv nodes may NOT be removed, even
	                                  if they look useless. */
62
	fp_strict_algebraic   = (1u << 1),  /**< Strict adherence to non-associative and non-distributive
Michael Beck's avatar
Michael Beck committed
63
	                                  algebra unless the same result is guaranteed. */
64
65
66
	fp_contradictions     = (1u << 2),  /**< FP contradictions are enabled. Only for backend. */
	fp_strict_eval_order  = (1u << 3),  /**< FP instructions must be strict evaluated in given order. */
	fp_exceptions         = (1u << 4),  /**< FP exceptions are supported. No reordering that changes
Michael Beck's avatar
Michael Beck committed
67
68
	                                  the exception flow are allowed. Backends must generate
	                                  synchronized exception code. */
69
	fp_environment_access = (1u << 5),  /**< FPU environment can be accessed. Even Constant folding
Michael Beck's avatar
Michael Beck committed
70
	                                  cannot be done. */
71
	fp_no_float_fold      = (1u << 6),
72

Michael Beck's avatar
Michael Beck committed
73
74
75
76
77
78
	/** Precise floating point model. Default. */
	fp_model_precise = fp_explicit_rounding|fp_strict_algebraic|fp_contradictions,
	/** Strict floating point model. */
	fp_model_strict  = fp_explicit_rounding|fp_strict_algebraic|fp_strict_eval_order|
	                   fp_exceptions|fp_environment_access,
	/** Fast floating point model. */
Matthias Braun's avatar
Matthias Braun committed
79
	fp_model_fast    = fp_contradictions
80
81
} fp_model_t;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
82
83
84
/** If the expression referenced can be evaluated statically
 *  computed_value returns a tarval representing the result.
 *  Else returns tarval_bad. */
Michael Beck's avatar
Michael Beck committed
85
tarval *computed_value(const ir_node *n);
Christian Schäfer's avatar
Christian Schäfer committed
86

Götz Lindenmaier's avatar
Götz Lindenmaier committed
87
88
89
90
91
92
93
94
/** Applies all optimizations to n that are expressible as a pattern
 *  in Firm, i.e., they need not a walk of the graph.
 *  Returns a better node for n.  Does not free n -- other nodes could
 *  reference n.
 *
 *  An equivalent optimization is applied in the constructors defined in
 *  ircons.ch.  There n is freed if a better node could be found.
 */
95
ir_node *optimize_in_place(ir_node *n);
Florian Liekweg's avatar
Florian Liekweg committed
96

Matthias Braun's avatar
Matthias Braun committed
97
#endif