OpenASIP  2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TTAProgram::InstructionReferenceImpl Class Reference

#include <InstructionReferenceImpl.hh>

Collaboration diagram for TTAProgram::InstructionReferenceImpl:
Collaboration graph

Public Member Functions

 InstructionReferenceImpl (TTAProgram::Instruction &ins, TTAProgram::InstructionReferenceManager &irm)
 
 ~InstructionReferenceImpl ()
 
void nullify ()
 
void addRef (InstructionReference &ref)
 
bool removeRef (InstructionReference &ref)
 
InstructionReferenceManagerreferencemanager ()
 
void setInstruction (Instruction &ins)
 
void merge (InstructionReferenceImpl &other)
 
Instructioninstruction ()
 
unsigned int count ()
 
const InstructionReferenceref ()
 

Private Member Functions

 InstructionReferenceImpl ()
 
 InstructionReferenceImpl (const InstructionReferenceImpl &)
 

Private Attributes

Instructionins_
 
std::set< InstructionReference * > refs_
 
InstructionReferenceManagerrefMan_
 

Detailed Description

Definition at line 48 of file InstructionReferenceImpl.hh.

Constructor & Destructor Documentation

◆ InstructionReferenceImpl() [1/3]

TTAProgram::InstructionReferenceImpl::InstructionReferenceImpl ( TTAProgram::Instruction ins,
TTAProgram::InstructionReferenceManager irm 
)

Constructor.

Stores the instruction and reference manager.

Parameters
insInstruction whose references this will handle
irmthe InstructionReferenceManager owning this object.

Definition at line 60 of file InstructionReferenceImpl.cc.

61  :
62  ins_(&ins), refMan_(&irm) {}

◆ ~InstructionReferenceImpl()

TTAProgram::InstructionReferenceImpl::~InstructionReferenceImpl ( )

Destructor.

Just asserts no refs point into this.

Definition at line 70 of file InstructionReferenceImpl.cc.

70  {
71  assert(refs_.empty());
72 }

References assert, and refs_.

◆ InstructionReferenceImpl() [2/3]

TTAProgram::InstructionReferenceImpl::InstructionReferenceImpl ( )
private

◆ InstructionReferenceImpl() [3/3]

TTAProgram::InstructionReferenceImpl::InstructionReferenceImpl ( const InstructionReferenceImpl )
private

Member Function Documentation

◆ addRef()

void TTAProgram::InstructionReferenceImpl::addRef ( InstructionReference ref)

A new reference has been created for the instruction handled by this object. Adds it to the list.

Parameters
InstructionReferencenew reference.

Definition at line 100 of file InstructionReferenceImpl.cc.

100  {
101  refs_.insert(&ref);
102 }

References ref(), and refs_.

Referenced by TTAProgram::InstructionReference::InstructionReference(), TTAProgram::InstructionReference::operator=(), and TTAProgram::InstructionReference::setImpl().

Here is the call graph for this function:

◆ count()

unsigned int TTAProgram::InstructionReferenceImpl::count ( )
inline

◆ instruction()

Instruction& TTAProgram::InstructionReferenceImpl::instruction ( )
inline

◆ merge()

void TTAProgram::InstructionReferenceImpl::merge ( InstructionReferenceImpl other)

Merges another irimpl to this object.

Makes all of it's references to point into this instead. This will also indirectly lead to the deletion of the other. This is used for irm.update() when the new target ins already has a ref.

Parameters
otherInstructionRefererenceImpl which to merge into this.

Definition at line 134 of file InstructionReferenceImpl.cc.

134  {
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 }

References refs_.

Referenced by TTAProgram::InstructionReferenceManager::replace().

◆ nullify()

void TTAProgram::InstructionReferenceImpl::nullify ( )

Nullifies all references pointing to this.

This should only be called by instructionreferenec manager when removing zombie refs.

Definition at line 81 of file InstructionReferenceImpl.cc.

81  {
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 }

References refs_.

◆ ref()

const InstructionReference & TTAProgram::InstructionReferenceImpl::ref ( )

Returns a reference pointing into instruction handled by this object.

Returns
some InstructionReference pointing to this.

Definition at line 161 of file InstructionReferenceImpl.cc.

161  {
162  return **refs_.begin();
163 }

References refs_.

Referenced by addRef(), and removeRef().

◆ referencemanager()

InstructionReferenceManager& TTAProgram::InstructionReferenceImpl::referencemanager ( )

◆ removeRef()

bool TTAProgram::InstructionReferenceImpl::removeRef ( InstructionReference ref)

A reference no longer points to instruction handled by this object.

Removes it from the list. If it was last, ask InstructionReferenceManager to delete this object.

Parameters
refreference which no longer points here
Returns
true if impl stays alive, false if dies.(removed last ref)

Definition at line 114 of file InstructionReferenceImpl.cc.

114  {
115  assert(refs_.find(&ref) != refs_.end());
116  refs_.erase(&ref);
117  if (refs_.empty()) {
119  return false;
120  }
121  return true;
122 }

References assert, ins_, ref(), TTAProgram::InstructionReferenceManager::referenceDied(), refMan_, and refs_.

Referenced by TTAProgram::InstructionReference::operator=(), TTAProgram::InstructionReference::setImpl(), and TTAProgram::InstructionReference::~InstructionReference().

Here is the call graph for this function:

◆ setInstruction()

void TTAProgram::InstructionReferenceImpl::setInstruction ( Instruction ins)

Sets this object to point into another instruction.

This method should be only called by InstructionReferenceManager.

Parameters
insnew insruction where to point.

Definition at line 151 of file InstructionReferenceImpl.cc.

151  {
152  ins_ = &ins;
153 }

References ins_.

Referenced by TTAProgram::InstructionReferenceManager::replace().

Member Data Documentation

◆ ins_

Instruction* TTAProgram::InstructionReferenceImpl::ins_
private

Definition at line 65 of file InstructionReferenceImpl.hh.

Referenced by removeRef(), and setInstruction().

◆ refMan_

InstructionReferenceManager* TTAProgram::InstructionReferenceImpl::refMan_
private

Definition at line 67 of file InstructionReferenceImpl.hh.

Referenced by removeRef().

◆ refs_

std::set<InstructionReference*> TTAProgram::InstructionReferenceImpl::refs_
private

The documentation for this class was generated from the following files:
TTAProgram::InstructionReferenceImpl::ref
const InstructionReference & ref()
Definition: InstructionReferenceImpl.cc:161
TTAProgram::InstructionReferenceImpl::refMan_
InstructionReferenceManager * refMan_
Definition: InstructionReferenceImpl.hh:67
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::InstructionReferenceImpl::ins_
Instruction * ins_
Definition: InstructionReferenceImpl.hh:65
TTAProgram::InstructionReferenceImpl::refs_
std::set< InstructionReference * > refs_
Definition: InstructionReferenceImpl.hh:66
TTAProgram::InstructionReferenceManager::referenceDied
void referenceDied(Instruction *ins)
Definition: InstructionReferenceManager.cc:165