CACAO
Value.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Value.hpp - Value
2 
3  Copyright (C) 2013
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 _JIT_COMPILER2_VALUE
26 #define _JIT_COMPILER2_VALUE
27 
31 
32 #include <cstddef>
33 #include <algorithm>
34 #include <cassert>
35 
37 
38 namespace cacao {
39 
40 class OStream;
41 
42 namespace jit {
43 namespace compiler2 {
44 
45 class Instruction;
46 
47 class Value : public memory::ManagerMixin<Value> {
48 public:
50 private:
53 protected:
55  assert(I);
56  user_list.insert(I);
57  }
58  OStream& print_users(OStream &OS) const;
59 
61  user_list.erase(I);
62  }
64  type = t;
65  }
66 public:
67  Value(Type::TypeID type) : type(type) {}
68  Type::TypeID get_type() const { return type; } ///< get the value type of the instruction
69 
70  virtual ~Value();
71 
72  UserListTy::const_iterator user_begin() const { return user_list.begin(); }
73  UserListTy::const_iterator user_end() const { return user_list.end(); }
74  /**
75  * Get the number of (unique) users.
76  *
77  * @note This is not the number of usages but the number of different
78  * Instructions which use this Value, i.e. if an Instruction uses this Value
79  * multiple times it is only counted once!
80  */
81  size_t user_size() const { return user_list.size(); }
82 
83  /**
84  * Replace this Value this the new one in all users.
85  */
86  void replace_value(Value *v);
87 
88  virtual Instruction* to_Instruction() { return NULL; }
89 
90  /// print
91  virtual OStream& print(OStream &OS) const;
92 
93  // we need this to access append_user
94  friend class Instruction;
95 };
96 
97 inline OStream& operator<<(OStream &OS, const Value &V) {
98  return V.print(OS);
99 }
100 OStream& operator<<(OStream &OS, const Value *V);
101 
102 } // end namespace compiler2
103 } // end namespace jit
104 } // end namespace cacao
105 
106 #endif /* _JIT_COMPILER2_VALUE */
107 
108 
109 /*
110  * These are local overrides for various environment variables in Emacs.
111  * Please do not remove this and leave it at the end of the file, where
112  * Emacs will automagically detect them.
113  * ---------------------------------------------------------------------
114  * Local variables:
115  * mode: c++
116  * indent-tabs-mode: t
117  * c-basic-offset: 4
118  * tab-width: 4
119  * End:
120  * vim:noexpandtab:sw=4:ts=4:
121  */
virtual OStream & print(OStream &OS) const
print
Definition: Value.cpp:40
virtual Instruction * to_Instruction()
Definition: Value.hpp:88
void append_user(Instruction *I)
Definition: Value.hpp:54
UserListTy::const_iterator user_begin() const
Definition: Value.hpp:72
Type::TypeID get_type() const
get the value type of the instruction
Definition: Value.hpp:68
Custom new/delete handler mixin.
Definition: Manager.hpp:43
#define MM_MAKE_NAME(x)
Definition: memstats.hpp:128
UserListTy::const_iterator user_end() const
Definition: Value.hpp:73
Value(Type::TypeID type)
Definition: Value.hpp:67
std::unordered_set< Key, Hash, KeyEqual, Allocator< Key > > type
Simple stream class for formatted output.
Definition: OStream.hpp:141
Instruction super class.
Definition: Instruction.hpp:75
void user_remove(Instruction *I)
Definition: Value.hpp:60
OStream & OS
OStream & operator<<(OStream &OS, const std::string &t)
Definition: OStream.hpp:459
#define I(value)
Definition: codegen.c:279
Represents the result of the addition of a certain IR-variable with a certain constant.
Definition: Value.hpp:36
size_t user_size() const
Get the number of (unique) users.
Definition: Value.hpp:81
void set_type(Type::TypeID t)
Definition: Value.hpp:63
alloc::unordered_set< Instruction * >::type UserListTy
Definition: Value.hpp:49