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

#include <InstructionReferenceManager.hh>

Inheritance diagram for TTAProgram::InstructionReferenceManager:
Inheritance graph
Collaboration diagram for TTAProgram::InstructionReferenceManager:
Collaboration graph

Classes

class  Iterator
 

Public Types

typedef std::map< Instruction *, InstructionReferenceImpl * > RefMap
 Map for instruction references. faster to search than list. More...
 

Public Member Functions

 InstructionReferenceManager ()
 
virtual ~InstructionReferenceManager ()
 
InstructionReference createReference (Instruction &ins)
 
void replace (Instruction &insA, Instruction &insB)
 
void clearReferences ()
 
bool hasReference (Instruction &ins) const
 
unsigned int referenceCount (Instruction &ins) const
 
void referenceDied (Instruction *ins)
 
void validate ()
 
Iterator begin ()
 
Iterator end ()
 

Private Member Functions

 InstructionReferenceManager (const InstructionReferenceManager &)
 
InstructionReferenceManageroperator= (const InstructionReferenceManager &)
 

Private Attributes

RefMap references_
 Instruction references to maintain. More...
 

Detailed Description

Helps in keeping instructions referenced in POM up-to-date.

Instructions are not referenced directly, but through an InstructionReference instance. The actual Instruction instance referred can be changed as needed.

Definition at line 82 of file InstructionReferenceManager.hh.

Member Typedef Documentation

◆ RefMap

Map for instruction references. faster to search than list.

Definition at line 85 of file InstructionReferenceManager.hh.

Constructor & Destructor Documentation

◆ InstructionReferenceManager() [1/2]

TTAProgram::InstructionReferenceManager::InstructionReferenceManager ( )

Constructor.

Note
Should not be instantiated independent of a Program instance.

Definition at line 54 of file InstructionReferenceManager.cc.

54  {
55 }

◆ ~InstructionReferenceManager()

TTAProgram::InstructionReferenceManager::~InstructionReferenceManager ( )
virtual

Destructor. Clears all instruction references.

Definition at line 60 of file InstructionReferenceManager.cc.

60  {
61 // assert(references_.empty());
63 }

References clearReferences().

Here is the call graph for this function:

◆ InstructionReferenceManager() [2/2]

TTAProgram::InstructionReferenceManager::InstructionReferenceManager ( const InstructionReferenceManager )
private

Member Function Documentation

◆ begin()

Iterator TTAProgram::InstructionReferenceManager::begin ( )
inline

◆ clearReferences()

void TTAProgram::InstructionReferenceManager::clearReferences ( )

Clears all instruction references.

The result is a totally empty instruction reference manager. This nullifies all instructionreferences handled by this reference manager.

Definition at line 125 of file InstructionReferenceManager.cc.

125  {
126  // nullify modifies so take new iter every round.
127  for (RefMap::iterator iter = references_.begin();
128  iter != references_.end(); iter = references_.begin()) {
129  assert(iter->second != NULL);
130  // nullify causes use count to drop to 0 which kills this.
131  iter->second->nullify();
132  }
133  references_.clear();
134 }

References assert, and references_.

Referenced by ~InstructionReferenceManager().

◆ createReference()

InstructionReference TTAProgram::InstructionReferenceManager::createReference ( Instruction ins)

Creates a new reference to an instruction.

Parameters
insReferred instruction.
Returns
A new reference to an instruction, or if one already exists, return it.

Definition at line 73 of file InstructionReferenceManager.cc.

73  {
74  RefMap::const_iterator iter = references_.find(&ins);
75  if (iter == references_.end()) {
76  InstructionReferenceImpl* newRef =
77  new InstructionReferenceImpl(ins, *this);
78  references_[&ins] = newRef;
79  return InstructionReference(newRef);
80  } else {
81  return InstructionReference(iter->second);
82  }
83 }

References references_.

Referenced by SimpleIfConverter::addJump(), TTAProgram::TPEFProgramFactory::build(), TTAProgram::Program::convertSymbolRef(), TTAProgram::Program::copyDataMemoriesFrom(), InlineAsmParser::copyInstructions(), llvm::LLVMTCEBuilder::createGlobalValueDataDefinition(), ProgramDependenceGraph::createJump(), TTAProgram::TPEFProgramFactory::createLabels(), TTAProgram::CodeGenerator::createSchedYieldProcedure(), llvm::LLVMTCEBuilder::doFinalization(), llvm::LLVMTCEBuilder::emitSetjmp(), TTAProgram::Program::fixInstructionReferences(), CallsToJumps::handleControlFlowGraph(), TTAProgram::CodeLabel::instructionReference(), LoopPrologAndEpilogBuilder::moveJumpDestination(), ControlFlowGraph::sanitize(), and CopyingDelaySlotFiller::updateJumpsAndCfg().

◆ end()

Iterator TTAProgram::InstructionReferenceManager::end ( )
inline

◆ hasReference()

bool TTAProgram::InstructionReferenceManager::hasReference ( Instruction ins) const

◆ operator=()

InstructionReferenceManager& TTAProgram::InstructionReferenceManager::operator= ( const InstructionReferenceManager )
private

◆ referenceCount()

unsigned int TTAProgram::InstructionReferenceManager::referenceCount ( Instruction ins) const

Tells how many alive references there are to an instruction.

Definition at line 151 of file InstructionReferenceManager.cc.

151  {
152  RefMap::const_iterator iter = references_.find(&ins);
153  if (iter == references_.end()) {
154  return 0;
155  }
156  return iter->second->count();
157 }

References references_.

◆ referenceDied()

void TTAProgram::InstructionReferenceManager::referenceDied ( Instruction ins)

Notifies instructionreferencemanager that a reference has completely died.

This causes the reference manager to remove the reference impl object.

Definition at line 165 of file InstructionReferenceManager.cc.

165  {
166  RefMap::iterator iter = references_.find(ins);
167  assert (iter != references_.end());
168  assert (iter->second->count() == 0);
169  delete iter->second; iter->second = NULL;
170  references_.erase(iter);
171 }

References assert, and references_.

Referenced by TTAProgram::InstructionReferenceImpl::removeRef().

◆ replace()

void TTAProgram::InstructionReferenceManager::replace ( Instruction insA,
Instruction insB 
)

Replaces a referred instruction with another. This replaces ALL references that point into the same instruction.

Parameters
insAInstruction to be replaced.
insBThe new referred instruction.
Returns
A handle to the reference to the new referred instruction.
Exceptions
InstanceNotFoundif the instruction to be replaced is not found.

Definition at line 96 of file InstructionReferenceManager.cc.

96  {
97  RefMap::iterator itera = references_.find(&insA);
98  if (itera == references_.end()) {
99  throw InstanceNotFound(
100  __FILE__, __LINE__, "InstructionReferenceManager::replace()",
101  "Instruction reference to be replaced not found.");
102  }
103 
104  RefMap::iterator iterb = references_.find(&insB);
105  if (iterb == references_.end()) { // just update one.
106  // no ref to b, just update a to point to b.
107  InstructionReferenceImpl* impl = itera->second;
108  impl->setInstruction(insB);
109  references_.erase(itera);
110  references_[&insB] = impl;
111  return;
112  }
113 
114  // merge the two ref implementations.
115  iterb->second->merge(*itera->second);
116 }

References TTAProgram::InstructionReferenceImpl::merge(), references_, and TTAProgram::InstructionReferenceImpl::setInstruction().

Referenced by SequentialScheduler::copyBasicBlocksToProcedure(), ProcedurePass::copyCfgToProcedure(), BasicBlockPass::copyRMToBB(), ControlFlowGraph::copyToLLVMMachineFunction(), ControlFlowGraph::copyToProcedure(), TTAProgram::CodeGenerator::createSchedYieldProcedure(), llvm::LLVMTCEBuilder::emitSPInitialization(), CallsToJumps::handleControlFlowGraph(), ControlFlowGraph::optimizeBBOrdering(), and BasicBlockNode::updateReferencesFromProcToCfg().

Here is the call graph for this function:

◆ validate()

void TTAProgram::InstructionReferenceManager::validate ( )

Performs sanity checks to the instruction references.

Asserts in case of illegal irefs found. Before calling this method, all instruction references must have been "stabilized", i.e., pointing to valid instructions inside the Program.

Definition at line 181 of file InstructionReferenceManager.cc.

181  {
182 
183  for (InstructionReferenceManager::Iterator i = begin();
184  i != end(); ++i) {
185  Instruction& targetInstruction = i->instruction();
186 
187  if (!targetInstruction.isInProcedure()) {
189  << "Reference to an instruction " << &targetInstruction
190  << " that is not in a Procedure." << std::endl;
191  PRINT_VAR(targetInstruction.address().location());
192  abort();
193  } else if (!targetInstruction.parent().isInProgram()) {
195  << "Reference to an instruction " << &targetInstruction
196  << " that is not in a Program." << std::endl;
197  PRINT_VAR(&(*i));
198  PRINT_VAR(
199  dynamic_cast<TTAProgram::Procedure&>(
200  targetInstruction.parent()).name());
201  PRINT_VAR(
202  &targetInstruction.parent().firstInstruction());
203  PRINT_VAR(targetInstruction.address().location());
204  abort();
205  }
206  }
207 }

References TTAProgram::Instruction::address(), begin(), end(), TTAProgram::CodeSnippet::firstInstruction(), TTAProgram::Instruction::isInProcedure(), TTAProgram::CodeSnippet::isInProgram(), TTAProgram::Address::location(), Application::logStream(), TTAProgram::Procedure::name(), TTAProgram::Instruction::parent(), and PRINT_VAR.

Here is the call graph for this function:

Member Data Documentation

◆ references_

RefMap TTAProgram::InstructionReferenceManager::references_
private

The documentation for this class was generated from the following files:
TTAProgram::InstructionReferenceManager::end
Iterator end()
PRINT_VAR
#define PRINT_VAR(VARIABLE__)
Definition: Application.hh:118
TTAProgram::InstructionReferenceManager::references_
RefMap references_
Instruction references to maintain.
Definition: InstructionReferenceManager.hh:120
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
TTAProgram::InstructionReferenceManager::clearReferences
void clearReferences()
Definition: InstructionReferenceManager.cc:125
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::Procedure::name
TCEString name() const
Definition: Procedure.hh:66
TTAProgram::InstructionReferenceManager::begin
Iterator begin()
TTAProgram::Procedure
Definition: Procedure.hh:55
InstanceNotFound
Definition: Exception.hh:304