OpenASIP
2.0
src
base
program
InstructionReferenceImpl.cc
Go to the documentation of this file.
1
/*
2
Copyright (c) 2002-2009 Tampere University.
3
4
This file is part of TTA-Based Codesign Environment (TCE).
5
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
23
*/
24
/**
25
* @file InstructionReferenceImpl.cc
26
*
27
* Implementation of InstructionReferenceImpl class.
28
*
29
* This class provides the internal tracking of instruction references to
30
* a single instruction. This class contains information about
31
* all references pointing to this instructions. When the reference count
32
* reaches 0, this class is automatically deleted.
33
*
34
* @author Heikki Kultala 2009 (heikki.kultala-no.spam-tut.fi)
35
* @note rating: red
36
*/
37
38
#include <set>
39
40
#include <iostream>
41
#include "
InstructionReference.hh
"
42
#include "
InstructionReferenceImpl.hh
"
43
#include "
InstructionReferenceManager.hh
"
44
45
#include "
Application.hh
"
46
47
48
namespace
TTAProgram
{
49
class
InstructionReference;
50
51
52
/**
53
* Constructor.
54
*
55
* Stores the instruction and reference manager.
56
*
57
* @param ins Instruction whose references this will handle
58
* @param irm the InstructionReferenceManager owning this object.
59
*/
60
InstructionReferenceImpl::InstructionReferenceImpl
(
61
TTAProgram::Instruction
& ins,
InstructionReferenceManager
& irm) :
62
ins_(&ins), refMan_(&irm) {}
63
64
65
/**
66
* Destructor.
67
*
68
* Just asserts no refs point into this.
69
*/
70
InstructionReferenceImpl::~InstructionReferenceImpl
() {
71
assert
(
refs_
.empty());
72
}
73
74
/**
75
* Nullifies all references pointing to this.
76
*
77
* This should only be called by instructionreferenec manager when removing
78
* zombie refs.
79
*/
80
void
81
InstructionReferenceImpl::nullify
() {
82
// the set is modified inside so cannot iterate normally.
83
// get the first as long as there are some.
84
while
(!
refs_
.empty()) {
85
// if setimpl return false, I am dead and cannot do
86
// anything.
87
if
(!(*
refs_
.begin())->setImpl(NULL)) {
88
return
;
89
}
90
}
91
}
92
93
/**
94
* A new reference has been created for the instruction handled by
95
* this object. Adds it to the list.
96
*
97
* @param InstructionReference new reference.
98
*/
99
void
100
InstructionReferenceImpl::addRef
(
InstructionReference
& ref) {
101
refs_
.insert(&
ref
);
102
}
103
104
/**
105
* A reference no longer points to instruction handled by this object.
106
*
107
* Removes it from the list. If it was last, ask InstructionReferenceManager
108
* to delete this object.
109
*
110
* @param ref reference which no longer points here
111
* @return true if impl stays alive, false if dies.(removed last ref)
112
*/
113
bool
114
InstructionReferenceImpl::removeRef
(
InstructionReference
& ref) {
115
assert
(
refs_
.find(&
ref
) !=
refs_
.end());
116
refs_
.erase(&
ref
);
117
if
(
refs_
.empty()) {
118
refMan_
->
referenceDied
(
ins_
);
119
return
false
;
120
}
121
return
true
;
122
}
123
124
/**
125
* Merges another irimpl to this object.
126
*
127
* Makes all of it's references to point into this instead. This will also
128
* indirectly lead to the deletion of the other. This is used for irm.update()
129
* when the new target ins already has a ref.
130
*
131
* @param other InstructionRefererenceImpl which to merge into this.
132
*/
133
void
134
InstructionReferenceImpl::merge
(
InstructionReferenceImpl
& other) {
135
// copy this in order to prevent it being deleted on last iteration
136
std::set<InstructionReference*> otherRefs = other.
refs_
;
137
for
(std::set<InstructionReference*>::iterator iter =
138
otherRefs.begin(); iter != otherRefs.end(); iter++) {
139
(*iter)->setImpl(
this
);
140
}
141
}
142
143
/**
144
* Sets this object to point into another instruction.
145
*
146
* This method should be only called by InstructionReferenceManager.
147
*
148
* @param ins new insruction where to point.
149
*/
150
void
151
InstructionReferenceImpl::setInstruction
(
Instruction
& ins) {
152
ins_
= &ins;
153
}
154
155
/**
156
* Returns a reference pointing into instruction handled by this object.
157
*
158
* @return some InstructionReference pointing to this.
159
*/
160
const
InstructionReference
&
161
InstructionReferenceImpl::ref
() {
162
return
**
refs_
.begin();
163
}
164
165
}
TTAProgram::InstructionReferenceImpl::ref
const InstructionReference & ref()
Definition:
InstructionReferenceImpl.cc:161
TTAProgram
Definition:
Estimator.hh:65
TTAProgram::InstructionReferenceImpl::setInstruction
void setInstruction(Instruction &ins)
Definition:
InstructionReferenceImpl.cc:151
TTAProgram::InstructionReferenceImpl::nullify
void nullify()
Definition:
InstructionReferenceImpl.cc:81
TTAProgram::InstructionReferenceImpl::refMan_
InstructionReferenceManager * refMan_
Definition:
InstructionReferenceImpl.hh:67
TTAProgram::Instruction
Definition:
Instruction.hh:57
TTAProgram::InstructionReferenceImpl::addRef
void addRef(InstructionReference &ref)
Definition:
InstructionReferenceImpl.cc:100
TTAProgram::InstructionReferenceImpl::InstructionReferenceImpl
InstructionReferenceImpl()
assert
#define assert(condition)
Definition:
Application.hh:86
InstructionReferenceImpl.hh
TTAProgram::InstructionReferenceImpl::ins_
Instruction * ins_
Definition:
InstructionReferenceImpl.hh:65
Application.hh
TTAProgram::InstructionReferenceImpl::refs_
std::set< InstructionReference * > refs_
Definition:
InstructionReferenceImpl.hh:66
TTAProgram::InstructionReferenceImpl::~InstructionReferenceImpl
~InstructionReferenceImpl()
Definition:
InstructionReferenceImpl.cc:70
TTAProgram::InstructionReferenceManager
Definition:
InstructionReferenceManager.hh:82
TTAProgram::InstructionReferenceImpl::removeRef
bool removeRef(InstructionReference &ref)
Definition:
InstructionReferenceImpl.cc:114
InstructionReference.hh
InstructionReferenceManager.hh
TTAProgram::InstructionReferenceImpl::merge
void merge(InstructionReferenceImpl &other)
Definition:
InstructionReferenceImpl.cc:134
TTAProgram::InstructionReferenceManager::referenceDied
void referenceDied(Instruction *ins)
Definition:
InstructionReferenceManager.cc:165
TTAProgram::InstructionReference
Definition:
InstructionReference.hh:49
TTAProgram::InstructionReferenceImpl
Definition:
InstructionReferenceImpl.hh:48
Generated by
1.8.17