CACAO
Value.hpp
Go to the documentation of this file.
1 /* src/vm/jit/loop/Value.hpp
2 
3  Copyright (C) 1996-2012
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 #ifndef _VALUE_HPP
26 #define _VALUE_HPP
27 
28 #include <limits>
29 
30 #include "vm/types.hpp"
31 
32 /**
33  * Represents the result of the addition of a certain IR-variable with a certain constant.
34  * The addition may overflow.
35  */
36 class Value
37 {
38  s4 _variable; // If _variable == -1, this value is considered as "unknown".
40 
41  /**
42  * Initializes this value with (variable + constant).
43  */
45  : _variable(variable)
46  , _constant(constant)
47  {}
48 
49 public:
50 
52  static Value newUnknown();
53 
54  s4 variable() const;
55  s4 constant() const;
56 
57  bool isUnknown() const;
58 
59  /**
60  * Adds a constant to this value.
61  * If this value is "unknown", it stays unknown.
62  */
63  void addConstant(s4 constant);
64 
65  /**
66  * Subtracts a constant from this value.
67  * If this value is "unknown", it stays unknown.
68  */
70 };
71 
72 inline Value Value::newAddition(s4 variable, s4 constant)
73 {
74  assert(variable != -1);
75  return Value(variable, constant);
76 }
77 
79 {
80  return Value(-1, 0);
81 }
82 
83 inline s4 Value::variable() const
84 {
85  assert(_variable != -1);
86  return _variable;
87 }
88 
89 inline s4 Value::constant() const
90 {
91  return _constant;
92 }
93 
94 inline bool Value::isUnknown() const
95 {
96  return _variable == -1;
97 }
98 
99 inline void Value::addConstant(s4 constant)
100 {
101  s8 sum = static_cast<s8>(_constant) + constant;
103  _constant = static_cast<s4>(sum);
104  else
105  _variable = -1; // In case of an overflow, we get an "unknown" value.
106 }
107 
108 inline void Value::subtractConstant(s4 constant)
109 {
110  s8 sum = static_cast<s8>(_constant) - constant;
112  _constant = static_cast<s4>(sum);
113  else
114  _variable = -1; // In case of an overflow, we get an "unknown" value.
115 }
116 
117 #endif
118 
119 /*
120  * These are local overrides for various environment variables in Emacs.
121  * Please do not remove this and leave it at the end of the file, where
122  * Emacs will automagically detect them.
123  * ---------------------------------------------------------------------
124  * Local variables:
125  * mode: c++
126  * indent-tabs-mode: t
127  * c-basic-offset: 4
128  * tab-width: 4
129  * End:
130  * vim:noexpandtab:sw=4:ts=4:
131  */
132 
Value(s4 variable, s4 constant)
Initializes this value with (variable + constant).
Definition: Value.hpp:44
void addConstant(s4 constant)
Adds a constant to this value.
Definition: Value.hpp:99
s4 constant() const
Definition: Value.hpp:89
#define max(a, b)
Definition: lsra.hpp:80
bool isUnknown() const
Definition: Value.hpp:94
int64_t s8
Definition: types.hpp:48
#define min(a, b)
Definition: lsra.hpp:79
s4 variable() const
Definition: Value.hpp:83
s4 _variable
Definition: Value.hpp:38
int32_t s4
Definition: types.hpp:45
static Value newUnknown()
Definition: Value.hpp:78
Represents the result of the addition of a certain IR-variable with a certain constant.
Definition: Value.hpp:36
void subtractConstant(s4 constant)
Subtracts a constant from this value.
Definition: Value.hpp:108
static Value newAddition(s4 variable, s4 constant)
Definition: Value.hpp:72
s4 _constant
Definition: Value.hpp:39