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

#include <Instruction.hh>

Inheritance diagram for TTAProgram::Instruction:
Inheritance graph
Collaboration diagram for TTAProgram::Instruction:
Collaboration graph

Public Member Functions

 Instruction (const TTAMachine::InstructionTemplate &instructionTemplate=TTAMachine::NullInstructionTemplate::instance())
 
 Instruction (int size, const TTAMachine::InstructionTemplate &instructionTemplate=TTAMachine::NullInstructionTemplate::instance())
 
 ~Instruction ()
 
CodeSnippetparent () const
 
void setParent (CodeSnippet &proc)
 
bool isInProcedure () const
 
void addMove (std::shared_ptr< Move > move)
 
int moveCount () const
 
Movemove (int i) const
 
std::shared_ptr< MovemovePtr (int i) const
 
void removeMove (Move &move)
 
bool isNOP () const
 
void addImmediate (std::shared_ptr< Immediate > imm)
 
int immediateCount () const
 
Immediateimmediate (int i) const
 
std::shared_ptr< ImmediateimmediatePtr (int i) const
 
void removeImmediate (Immediate &imm)
 
Address address () const
 
bool hasFinalAddress () const
 
short size () const
 
void setSize (short size)
 
bool hasRegisterAccesses () const
 
bool hasConditionalRegisterAccesses () const
 
bool hasJump () const
 
bool hasCall () const
 
bool hasReturn () const
 
bool hasControlFlowMove () const
 
Instructioncopy () const
 
void setInstructionTemplate (const TTAMachine::InstructionTemplate &insTemp)
 
const TTAMachine::InstructionTemplateinstructionTemplate () const
 
std::string toString () const
 
void setFinalAddress (InstructionAddress addr)
 
- Public Member Functions inherited from TTAProgram::AnnotatedInstructionElement
 AnnotatedInstructionElement ()
 
 ~AnnotatedInstructionElement ()
 
void addAnnotation (const ProgramAnnotation &annotation)
 
void setAnnotation (const ProgramAnnotation &annotation)
 
ProgramAnnotation annotation (int index, ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID) const
 
int annotationCount (ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID) const
 
void removeAnnotations (ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID)
 
bool hasAnnotations (ProgramAnnotation::Id id=ProgramAnnotation::ANN_UNDEF_ID) const
 
bool hasAnnotation (ProgramAnnotation::Id id, const TCEString &data) const
 
void copyAnnotationsFrom (const AnnotatedInstructionElement &other)
 

Private Types

typedef std::vector< std::shared_ptr< Move > > MoveList
 List for moves. More...
 
typedef std::vector< std::shared_ptr< Immediate > > ImmList
 List for immediates. More...
 

Private Member Functions

 Instruction (const Instruction &)
 Copying not allowed. More...
 
Instructionoperator= (const Instruction &)
 Assignment not allowed. More...
 

Private Attributes

MoveList moves_
 Moves contained in this instruction. More...
 
ImmList immediates_
 Immediates contained in this instruction. More...
 
CodeSnippetparent_
 Parent procedure. More...
 
const TTAMachine::InstructionTemplateinsTemplate_
 Instruction template that is used for this instruction. More...
 
InstructionAddress positionInProcedure_
 Cache the instruction's index in the its procedure for faster address(). More...
 
InstructionAddress finalAddress_
 In case the final instruction address is known (due to program not modified anymore), the final instruction address is stored here. -1 in case not known. More...
 
short size_
 Size of instruction in MAU's. More...
 
bool hasRegisterAccesses_
 Set to true in case this instruction has moves that access registers. More...
 
bool hasConditionalRegisterAccesses_
 Set to true in case this instruction has moves that access registers and are conditional. More...
 

Detailed Description

Represents a TTA instruction.

Note
: The annotations added with the AnnotatedInstructionElement are not saved to a TPEF file when the program is written!

Definition at line 57 of file Instruction.hh.

Member Typedef Documentation

◆ ImmList

typedef std::vector<std::shared_ptr<Immediate> > TTAProgram::Instruction::ImmList
private

List for immediates.

Definition at line 127 of file Instruction.hh.

◆ MoveList

typedef std::vector<std::shared_ptr<Move> > TTAProgram::Instruction::MoveList
private

List for moves.

Definition at line 125 of file Instruction.hh.

Constructor & Destructor Documentation

◆ Instruction() [1/3]

TTAProgram::Instruction::Instruction ( const TTAMachine::InstructionTemplate instructionTemplate = TTAMachine::NullInstructionTemplate::instance())

The constructor.

The default size of an instruction is 1 MAU.

Definition at line 63 of file Instruction.cc.

Referenced by copy().

◆ Instruction() [2/3]

TTAProgram::Instruction::Instruction ( int  size,
const TTAMachine::InstructionTemplate instructionTemplate = TTAMachine::NullInstructionTemplate::instance() 
)
explicit

Constructor.

Alternative constructor that takes the instruction size as a parameter.

Parameters
sizeThe size of the instruction in MAU's.

Definition at line 78 of file Instruction.cc.

80  :
85  assert(size == 1 &&
86  "Instructions sizes other than 1 not supported in POM at the "
87  "moment.");
88 }

References assert, and size().

Here is the call graph for this function:

◆ ~Instruction()

TTAProgram::Instruction::~Instruction ( )

The destructor.

Definition at line 93 of file Instruction.cc.

93  {
94  for (auto i : moves_) {
95  i->setParent(NullInstruction::instance());
96  }
97  moves_.clear();
98  immediates_.clear();
99 }

References immediates_, TTAProgram::NullInstruction::instance(), and moves_.

Here is the call graph for this function:

◆ Instruction() [3/3]

TTAProgram::Instruction::Instruction ( const Instruction )
private

Copying not allowed.

Member Function Documentation

◆ addImmediate()

void TTAProgram::Instruction::addImmediate ( std::shared_ptr< Immediate imm)

Adds an immediate to the instruction.

The ownership of the immediate will be passed to the instruction.

Parameters
immThe immediate to add.

Definition at line 234 of file Instruction.cc.

234  {
236  throw ObjectAlreadyExists(__FILE__, __LINE__, __func__,
237  "Immediate is already added.");
238  } else {
239  immediates_.push_back(imm);
240  imm->setParent(this);
241  }
242 
243 #if 0
245  int requiredWidth = std::min(
246  MathTools::requiredBits(imm->value().value().unsignedValue()),
247  imm->value().value().width());
248 
249  if (requiredWidth >
250  insTemplate_->supportedWidth(imm->destination().immediateUnit())) {
251  assert(false &&
252  "The immediate is wider than the instruction template can "
253  "transport.");
254  }
255  }
256 #endif
257 }

References __func__, assert, ContainerTools::containsValue(), immediates_, TTAMachine::NullInstructionTemplate::instance(), insTemplate_, MathTools::requiredBits(), and TTAMachine::InstructionTemplate::supportedWidth().

Referenced by ITemplateBroker::assign(), ITemplateBroker::assignImmediate(), LoopPrologAndEpilogBuilder::build(), copy(), TTAProgram::TPEFProgramFactory::createInstruction(), and ITemplateBroker::unassign().

Here is the call graph for this function:

◆ addMove()

void TTAProgram::Instruction::addMove ( std::shared_ptr< Move move)

Adds a move to the instruction.

The ownership of the move will be passed to the instruction.

Parameters
moveThe move to add.

Definition at line 147 of file Instruction.cc.

147  {
149  throw ObjectAlreadyExists(__FILE__, __LINE__, __func__,
150  "Move is already added.");
151  } else {
152  if (move->source().isGPR() || move->destination().isGPR()) {
153  hasRegisterAccesses_ = true;
154  if (!move->isUnconditional())
156  }
157  moves_.push_back(move);
158  move->setParent(*this);
159  }
160 #if 0
162  if (insTemplate_->usesSlot(move->bus().name())) {
163  assert(false &&
164  "Instruction template already uses the move's slot");
165  }
166  }
167 #endif
168 }

References __func__, assert, TTAProgram::Move::bus(), ContainerTools::containsValue(), TTAProgram::Move::destination(), hasConditionalRegisterAccesses_, hasRegisterAccesses_, TTAMachine::NullInstructionTemplate::instance(), insTemplate_, TTAProgram::Terminal::isGPR(), TTAProgram::Move::isUnconditional(), move(), moves_, TTAMachine::Component::name(), TTAProgram::Move::setParent(), TTAProgram::Move::source(), and TTAMachine::InstructionTemplate::usesSlot().

Referenced by TTAProgram::CodeGenerator::addAnnotatedMoveToProcedure(), ProgrammabilityValidator::addConnectionToProgram(), SimpleIfConverter::addJump(), TTAProgram::CodeGenerator::addMoveToProcedure(), Peel2BBLoops::appendBB(), SimpleIfConverter::appendBB(), ITemplateBroker::assign(), LoopPrologAndEpilogBuilder::build(), ProGe::RV32MicroCodeGenerator::constructBInstructions(), ProGe::RV32MicroCodeGenerator::constructIInstructions(), ProGe::RV32MicroCodeGenerator::constructRInstructions(), ProGe::RV32MicroCodeGenerator::constructSInstructions(), ProGe::RV32MicroCodeGenerator::constructUJInstructions(), copy(), TTAProgram::TPEFProgramFactory::createInstruction(), ProgramDependenceGraph::createJump(), llvm::LLVMTCEBuilder::emitComparisonForBranch(), llvm::LLVMTCEBuilder::emitGlobalXXtructorCalls(), llvm::LLVMTCEBuilder::emitInstruction(), llvm::LLVMTCEPOMBuilder::emitMove(), llvm::LLVMTCEBuilder::emitMove(), llvm::LLVMTCEBuilder::emitOperationMacro(), llvm::LLVMTCEBuilder::emitRemaingingBrach(), llvm::LLVMTCEBuilder::emitReturn(), llvm::LLVMTCEBuilder::emitSelect(), llvm::LLVMTCEBuilder::emitSPInitialization(), CallsToJumps::handleControlFlowGraph(), ProgramDependenceGraph::processPredicate(), ProgramDependenceGraph::processRegion(), PreOptimizer::tryToRemoveGuardInversingOp(), and ITemplateBroker::unassign().

Here is the call graph for this function:

◆ address()

Address TTAProgram::Instruction::address ( ) const

Returns the address of the instruction.

Returns
The address of the instruction.
Exceptions
IllegalRegistrationif the instruction does not belong to a procedure.

Definition at line 327 of file Instruction.cc.

327  {
328  if (finalAddress_ != (InstructionAddress)-1) {
329  Address address(finalAddress_, parent().startAddress().space());
330  return address;
331  }
332 
333  if (!isInProcedure()) {
334  TCEString msg = "Instruction is not registered in a procedure: ";
335  msg += POMDisassembler::disassemble(*this);
336  throw IllegalRegistration(
337  __FILE__, __LINE__, __func__,
338  msg);
339  }
340  // speed up by caching the Instruction's position in the Procedure
343  (InstructionAddress)parent().instructionCount() &&
344  &parent().instructionAtIndex(positionInProcedure_) == this) {
345  // the instruction has not moved in the Procedure, we
346  // can compute its address in constant time
347  // cannot cache the Address itself because the Procedure might
348  // have moved
349  Address address(
350  parent().startAddress().location() + positionInProcedure_,
351  parent().startAddress().space());
352  return address;
353  } else {
354  Address address = parent().address(*this);
357  return address;
358  }
359 }

References __func__, TTAProgram::CodeSnippet::address(), POMDisassembler::disassemble(), finalAddress_, isInProcedure(), TTAProgram::Address::location(), parent(), positionInProcedure_, and TTAProgram::CodeSnippet::startAddress().

Referenced by TTAProgram::TerminalInstructionReference::address(), TTAProgram::CodeLabel::address(), TTAProgram::Procedure::address(), TTAProgram::CodeSnippet::address(), SimProgramBuilder::build(), CompiledSimUtilizationStats::calculate(), SimulationStatistics::calculate(), POMValidator::checkCompiledSimulatability(), POMValidator::checkConnectivity(), POMValidator::checkLongImmediates(), POMValidator::checkSimulatability(), TTAProgram::CodeLabel::CodeLabel(), ControlFlowGraph::computeLeadersFromJumpSuccessors(), ControlFlowGraph::computeLeadersFromRefManager(), ProcedurePass::copyCfgToProcedure(), SequentialScheduler::createBasicBlocks(), ControlFlowGraph::createBBEdges(), ControlFlowGraph::createBlock(), TTAProgram::ProgramWriter::createCodeSection(), ControlFlowGraph::createControlFlowEdge(), ControlFlowGraph::createJumps(), SimulatorFrontend::currentProcedure(), TTAProgram::DataInstructionAddressDef::destinationAddress(), ControlFlowGraph::directJump(), POMDisassembler::disassemble(), DisassembleCommand::execute(), TTAProgram::Program::finalize(), ControlFlowGraph::findNextIndex(), TTASimulationController::findProgramExitPoints(), SimulatorFrontend::finishSimulation(), TTAProgram::Program::fixInstructionReferences(), CompiledSimCodeGenerator::generateInstruction(), DisassemblyGridTable::GetNumberRows(), ProcedureTransferTracker::handleEvent(), RFAccessTracker::handleEvent(), TTAProgram::CodeSnippet::instructionAt(), TTAProgram::CodeSnippet::nextInstruction(), TTAProgram::Program::nextInstruction(), TTAProgram::CodeSnippet::previousInstruction(), POMDisassembler::printAddress(), CompiledSimController::reset(), DisasmTopCountAttrProvider::updateTopCountTable(), and TTAProgram::InstructionReferenceManager::validate().

Here is the call graph for this function:

◆ copy()

Instruction * TTAProgram::Instruction::copy ( ) const

Make a complete copy of the instruction.

The copy is identical, except that it is not registered to the procedure of the original instruction (and therefore, any address it refers to is not meaningful).

Returns
A complete copy of the instruction.

Definition at line 379 of file Instruction.cc.

379  {
380  Instruction* newIns = new Instruction(size_, *insTemplate_);
381  for (int i = 0; i < moveCount(); i++) {
382  newIns->addMove(move(i).copy());
383  }
384  for (int i = 0; i < immediateCount(); i++) {
385  newIns->addImmediate(immediate(i).copy());
386  }
387  newIns->hasRegisterAccesses_ = hasRegisterAccesses_;
388  newIns->hasConditionalRegisterAccesses_ = hasConditionalRegisterAccesses_;
389  newIns->copyAnnotationsFrom(*this);
390  return newIns;
391 }

References addImmediate(), addMove(), TTAProgram::Immediate::copy(), TTAProgram::Move::copy(), TTAProgram::AnnotatedInstructionElement::copyAnnotationsFrom(), hasConditionalRegisterAccesses_, hasRegisterAccesses_, immediate(), immediateCount(), insTemplate_, Instruction(), move(), moveCount(), and size_.

Referenced by TTAProgram::CodeSnippet::append(), TTAProgram::Procedure::copy(), TTAProgram::BasicBlock::copy(), TTAProgram::CodeSnippet::copy(), SequentialScheduler::copyBasicBlocksToProcedure(), ProcedurePass::copyCfgToProcedure(), TTAProgram::Program::copyFrom(), ControlFlowGraph::copyToProcedure(), SequentialScheduler::createBasicBlocks(), ControlFlowGraph::createBlock(), TTAProgram::CodeSnippet::insertAfter(), TTAProgram::CodeSnippet::insertBefore(), and TTAProgram::CodeSnippet::prepend().

Here is the call graph for this function:

◆ hasCall()

bool TTAProgram::Instruction::hasCall ( ) const

Returns whether this instruction contains moves that are calls.

Returns
True in case at least one move in this instruction is a call.

Definition at line 438 of file Instruction.cc.

438  {
439 
440  for (int i = 0; i < moveCount(); i++ ) {
441  if (move(i).isCall()) {
442  return true;
443  }
444  }
445  return false;
446 }

References TTAProgram::Move::isCall(), move(), and moveCount().

Referenced by CopyingDelaySlotFiller::collectMoves(), CopyingDelaySlotFiller::findJump(), CallsToJumps::handleControlFlowGraph(), and ControlFlowGraph::splitBasicBlocksWithCallsAndRefs().

Here is the call graph for this function:

◆ hasConditionalRegisterAccesses()

bool TTAProgram::Instruction::hasConditionalRegisterAccesses ( ) const

Returns true in case this Instruction contains moves that access registers and are conditional.

This method can be used to optimize register utilization analysis.

Returns
True in case at least one conditional move accesses registers.

Definition at line 412 of file Instruction.cc.

412  {
414 }

References hasConditionalRegisterAccesses_.

Referenced by RFAccessTracker::handleEvent().

◆ hasControlFlowMove()

bool TTAProgram::Instruction::hasControlFlowMove ( ) const

Returns whether this instruction contains moves that affect the control flow (branches or calls).

Returns
True in case at least one move in this instruction is a control flow move.

Definition at line 471 of file Instruction.cc.

471  {
472  for (int i = 0; i < moveCount(); i++) {
473  if (move(i).isControlFlowMove()) {
474  return true;
475  }
476  }
477  return false;
478 }

References TTAProgram::Move::isControlFlowMove(), move(), and moveCount().

Referenced by llvm::LLVMTCEIRBuilder::buildTCECFG(), BasicBlockPass::copyRMToBB(), SequentialScheduler::createBasicBlocks(), ProgramDependenceGraph::createJump(), and ControlFlowGraph::findNextIndex().

Here is the call graph for this function:

◆ hasFinalAddress()

bool TTAProgram::Instruction::hasFinalAddress ( ) const
inline

Definition at line 100 of file Instruction.hh.

101  { return finalAddress_ != (InstructionAddress)-1; }

References finalAddress_.

Referenced by TTAProgram::Procedure::address(), and TTAProgram::CodeSnippet::address().

◆ hasJump()

bool TTAProgram::Instruction::hasJump ( ) const

Returns whether this instruction contains moves that are jumps.

Returns
True in case at least one move in this instruction is a jump.

Definition at line 422 of file Instruction.cc.

422  {
423 
424  for (int i = 0; i < moveCount(); i++ ) {
425  if (move(i).isJump()) {
426  return true;
427  }
428  }
429  return false;
430 }

References TTAProgram::Move::isJump(), move(), and moveCount().

Referenced by BBSchedulerController::handleBasicBlock(), and SimpleIfConverter::removeJump().

Here is the call graph for this function:

◆ hasRegisterAccesses()

bool TTAProgram::Instruction::hasRegisterAccesses ( ) const

Returns true in case this Instruction contains moves that access registers.

This method can be used to optimize register utilization analysis.

Definition at line 399 of file Instruction.cc.

399  {
400  return hasRegisterAccesses_;
401 }

References hasRegisterAccesses_.

Referenced by RFAccessTracker::handleEvent().

◆ hasReturn()

bool TTAProgram::Instruction::hasReturn ( ) const

Returns whether this instruction contains a procedure return move.

Definition at line 452 of file Instruction.cc.

452  {
453 
454  for (int i = 0; i < moveCount(); i++ ) {
455  if (move(i).isReturn()) {
456  return true;
457  }
458  }
459  return false;
460 }

References TTAProgram::Move::isReturn(), move(), and moveCount().

Here is the call graph for this function:

◆ immediate()

Immediate & TTAProgram::Instruction::immediate ( int  i) const

Return the immediate write action at the given index in this instruction.

The order of immediates is arbitrary, no assumption should be made by clients.

Parameters
iThe index of the immediate.
Returns
The immediate write action at the given index in this instruction.
Exceptions
OutOfRangeif the index is negative or greater than the number of immediates in the instruction.

Definition at line 285 of file Instruction.cc.

285  {
286  if (i < 0 || static_cast<unsigned int>(i) >= immediates_.size()) {
287  throw OutOfRange(__FILE__, __LINE__, __func__,
288  "No immediate in instruction with index: " +
290  } else {
291  return *immediates_.at(i);
292  }
293 }

References __func__, immediates_, and Conversion::toString().

Referenced by CodeCompressorPlugin::addBitsForDstRegisterField(), ITemplateBroker::assign(), LoopPrologAndEpilogBuilder::build(), CopyingDelaySlotFiller::checkImmediatesAfter(), POMValidator::checkLongImmediates(), CopyingDelaySlotFiller::collectMoves(), ControlFlowGraph::convertBBRefsToInstRefs(), TTAProgram::Program::convertSymbolRefsToInsRefs(), copy(), TTAProgram::ProgramWriter::createCodeSection(), POMDisassembler::createInstruction(), ControlFlowGraph::createJumps(), POMDisassembler::disassemble(), CodeCompressorPlugin::encodeLongImmediate(), ControlFlowGraph::findLimmWrite(), TTAProgram::Program::fixInstructionReferences(), CompiledSimCodeGenerator::generateInstruction(), ProgramImageGenerator::generateProgramImage(), getInstructionReferenceTerminals(), ITemplateBroker::isImmediateInTemplate(), main(), LoopPrologAndEpilogBuilder::optimizeProlog(), SimProgramBuilder::processInstruction(), CodeCompressorPlugin::programImmediate(), setInstructionTemplate(), CopyingDelaySlotFiller::tryToAssignNodes(), ITemplateBroker::unassignImmediate(), CopyingDelaySlotFiller::updateFTBBAndCfg(), and CopyingDelaySlotFiller::updateJumpsAndCfg().

Here is the call graph for this function:

◆ immediateCount()

int TTAProgram::Instruction::immediateCount ( ) const

Returns the number of immediate registers written by the instruction template of this instruction.

Returns
The number of immediate registers written by the instruction template of this instruction.

Definition at line 267 of file Instruction.cc.

267  {
268  return immediates_.size();
269 }

References immediates_.

Referenced by CodeCompressorPlugin::addBitsForDstRegisterField(), ITemplateBroker::assign(), LoopPrologAndEpilogBuilder::build(), CopyingDelaySlotFiller::checkImmediatesAfter(), POMValidator::checkLongImmediates(), CopyingDelaySlotFiller::collectMoves(), ControlFlowGraph::convertBBRefsToInstRefs(), TTAProgram::Program::convertSymbolRefsToInsRefs(), copy(), TTAProgram::ProgramWriter::createCodeSection(), POMDisassembler::createInstruction(), ControlFlowGraph::createJumps(), POMDisassembler::disassemble(), CodeCompressorPlugin::encodeLongImmediate(), ITemplateBroker::findITemplates(), CopyingDelaySlotFiller::findJumpImmediate(), ControlFlowGraph::findLimmWrite(), TTAProgram::Program::fixInstructionReferences(), CompiledSimCodeGenerator::generateInstruction(), ProgramImageGenerator::generateProgramImage(), getInstructionReferenceTerminals(), CodeCompressorPlugin::instructionTemplate(), ITemplateBroker::isImmediateInTemplate(), isNOP(), main(), LoopPrologAndEpilogBuilder::optimizeProlog(), SimProgramBuilder::processInstruction(), CodeCompressorPlugin::programImmediate(), ControlFlowGraph::removeJumpToTarget(), BFUnscheduleFromBody::returnOriginal(), BFUnscheduleMove::returnOriginal(), setInstructionTemplate(), TTAProgram::BasicBlock::statistics(), CopyingDelaySlotFiller::tryToAssignNodes(), SimpleBrokerDirector::unassign(), ITemplateBroker::unassignImmediate(), CopyingDelaySlotFiller::updateFTBBAndCfg(), and CopyingDelaySlotFiller::updateJumpsAndCfg().

◆ immediatePtr()

std::shared_ptr< Immediate > TTAProgram::Instruction::immediatePtr ( int  i) const

Return the immediate write action at the given index in this instruction.

The order of immediates is arbitrary, no assumption should be made by clients.

Parameters
iThe index of the immediate.
Returns
The immediate write action at the given index in this instruction.
Exceptions
OutOfRangeif the index is negative or greater than the number of immediates in the instruction.

Definition at line 309 of file Instruction.cc.

309  {
310  if (i < 0 || static_cast<unsigned int>(i) >= immediates_.size()) {
311  throw OutOfRange(__FILE__, __LINE__, __func__,
312  "No immediate in instruction with index: " +
314  } else {
315  return immediates_[i];
316  }
317 }

References __func__, immediates_, and Conversion::toString().

Referenced by ITemplateBroker::findITemplates(), CopyingDelaySlotFiller::findJumpImmediate(), and AbsoluteToRelativeJumps::handleProcedure().

Here is the call graph for this function:

◆ instructionTemplate()

const TTAMachine::InstructionTemplate & TTAProgram::Instruction::instructionTemplate ( ) const

◆ isInProcedure()

bool TTAProgram::Instruction::isInProcedure ( ) const

◆ isNOP()

bool TTAProgram::Instruction::isNOP ( ) const
inline

Definition at line 90 of file Instruction.hh.

90 { return moveCount() == 0 && immediateCount() == 0; }

References immediateCount(), and moveCount().

Referenced by ControlFlowGraph::buildMBBFromBB(), and ProgramImageGenerator::generateProgramImage().

Here is the call graph for this function:

◆ move()

Move & TTAProgram::Instruction::move ( int  i) const

Return the move at the given index in this instruction.

The order of moves is arbitrary, no assumption should be made by clients. Anyways, order of moves in instruction does not change between calls to this method.

Parameters
iThe index of the move.
Returns
The move at the given index in this instruction.
Exceptions
OutOfRangeif the given index is negative or greater than the number of moves in the instruction.

Definition at line 193 of file Instruction.cc.

193  {
194  if (i < 0 || static_cast<unsigned int>(i) >= moves_.size()) {
195  throw OutOfRange(__FILE__, __LINE__, __func__,
196  "No move in instruction for given index: " +
198  } else {
199  return *moves_.at(i);
200  }
201 }

References __func__, moves_, and Conversion::toString().

Referenced by SimpleICOptimizer::addConnections(), InlineAsmParser::addDebugInfoToInlineAsmBB(), TTAProgram::Program::addInstruction(), addMove(), ProximMachineStateWindow::addMoves(), StaticProgramAnalyzer::addProgram(), LoopAnalyzer::analyze(), ResourceConstraintAnalyzer::analyzeMoveNode(), Peel2BBLoops::appendBB(), SimpleIfConverter::appendBB(), ControlFlowGraph::buildMBBFromBB(), llvm::LLVMTCEIRBuilder::buildTCECFG(), UtilizationStats::calculateForInstruction(), SimpleIfConverter::canConvert(), POMValidator::checkCompiledSimulatability(), POMValidator::checkConnectivity(), CopyingDelaySlotFiller::checkImmediatesAfter(), POMValidator::checkSimulatability(), CopyingDelaySlotFiller::collectMoves(), SimpleIfConverter::combineBlocks(), ControlFlowGraph::computeLeadersFromJumpSuccessors(), ControlFlowGraph::convertBBRefsToInstRefs(), TTAProgram::Program::convertSymbolRefsToInsRefs(), copy(), ProcedurePass::copyCfgToProcedure(), ControlFlowGraph::createBBEdges(), TTAProgram::ProgramWriter::createCodeSection(), POMDisassembler::createInstruction(), ControlFlowGraph::createJumps(), ControlFlowGraph::directJump(), POMDisassembler::disassemble(), llvm::LLVMTCEBuilder::emitInstruction(), CodeCompressorPlugin::encodeMove(), FindWindow::find(), CopyingDelaySlotFiller::findJump(), CopyingDelaySlotFiller::findJumpImmediate(), BasicBlockNode::findJumps(), ControlFlowGraph::findNextIndex(), TTASimulationController::findProgramExitPoints(), DataDependenceGraphBuilder::findStaticRegisters(), TTAProgram::Program::fixInstructionReferences(), DataDependenceGraph::fixInterBBAntiEdges(), CompiledSimCodeGenerator::generateAddFUResult(), CompiledSimCodeGenerator::generateInstruction(), getInstructionReferenceTerminals(), PostpassOperandSharer::handleBasicBlock(), CallsToJumps::handleControlFlowGraph(), ProcedureTransferTracker::handleEvent(), RFAccessTracker::handleEvent(), llvm::LLVMTCEBuilder::hasAmbiguousASpaceRefs(), hasCall(), SimpleIfConverter::hasConditionals(), hasControlFlowMove(), ControlFlowGraph::hasInstructionAnotherJump(), hasJump(), hasReturn(), CodeCompressorPlugin::immediateTerminal(), ControlFlowGraph::indirectJump(), main(), ControlFlowGraph::mergeNodes(), DisasmExecPercentageAttrProvider::moveCellAttr(), BFShareOperandsLate::operator()(), LoopPrologAndEpilogBuilder::optimizeProlog(), SimProgramBuilder::processInstruction(), SimpleIfConverter::removeJump(), ControlFlowGraph::removeJumpToTarget(), removeMove(), ControlFlowGraph::removeUnreachableNodes(), TTAProgram::Program::replaceUniversalAddressSpaces(), BFUnscheduleFromBody::returnOriginal(), BFUnscheduleMove::returnOriginal(), BFShareOperandLate::revert(), setInstructionTemplate(), TTAProgram::BasicBlock::statistics(), SimpleIfConverter::successors(), BasicBlockNode::toString(), PostpassOperandSharer::tryRemoveOperandWrite(), SimpleBrokerDirector::unassign(), ProximDebuggerWindow::updateAnnotations(), CopyingDelaySlotFiller::updateFTBBAndCfg(), BasicBlockNode::updateHWloopLength(), CopyingDelaySlotFiller::updateJumpsAndCfg(), and SimpleIfConverter::writesRegister().

Here is the call graph for this function:

◆ moveCount()

int TTAProgram::Instruction::moveCount ( ) const

Returns the number of moves contained in this instruction.

Returns
The number of moves contained in this instruction.

Definition at line 176 of file Instruction.cc.

176  {
177  return moves_.size();
178 }

References moves_.

Referenced by SimpleICOptimizer::addConnections(), InlineAsmParser::addDebugInfoToInlineAsmBB(), TTAProgram::Program::addInstruction(), ProximMachineStateWindow::addMoves(), StaticProgramAnalyzer::addProgram(), LoopAnalyzer::analyze(), ResourceConstraintAnalyzer::analyzeMoveNode(), Peel2BBLoops::appendBB(), SimpleIfConverter::appendBB(), MoveNodeGroupBuilder::build(), ControlFlowGraph::buildMBBFromBB(), CompiledSimUtilizationStats::calculate(), UtilizationStats::calculateForInstruction(), SimpleIfConverter::canConvert(), POMValidator::checkCompiledSimulatability(), POMValidator::checkConnectivity(), POMValidator::checkSimulatability(), CopyingDelaySlotFiller::collectMoves(), SimpleIfConverter::combineBlocks(), ControlFlowGraph::computeLeadersFromJumpSuccessors(), DataDependenceGraphBuilder::constructIndividualBB(), DataDependenceGraphBuilder::constructIndividualFromInlineAsmBB(), ControlFlowGraph::convertBBRefsToInstRefs(), TTAProgram::Program::convertSymbolRefsToInsRefs(), copy(), ProcedurePass::copyCfgToProcedure(), BasicBlockPass::copyRMToBB(), ControlFlowGraph::createBBEdges(), TTAProgram::ProgramWriter::createCodeSection(), POMDisassembler::createInstruction(), ProgramDependenceGraph::createJump(), ControlFlowGraph::createJumps(), POMDisassembler::disassemble(), llvm::LLVMTCEBuilder::emitInstruction(), CodeCompressorPlugin::encodeMove(), FindWindow::find(), ITemplateBroker::findITemplates(), CopyingDelaySlotFiller::findJump(), CopyingDelaySlotFiller::findJumpImmediate(), BasicBlockNode::findJumps(), TTASimulationController::findProgramExitPoints(), DataDependenceGraphBuilder::findStaticRegisters(), TTAProgram::Program::fixInstructionReferences(), DataDependenceGraph::fixInterBBAntiEdges(), CompiledSimCodeGenerator::generateAddFUResult(), CompiledSimCodeGenerator::generateInstruction(), getInstructionReferenceTerminals(), PostpassOperandSharer::handleBasicBlock(), CallsToJumps::handleControlFlowGraph(), ProcedureTransferTracker::handleEvent(), RFAccessTracker::handleEvent(), hasCall(), SimpleIfConverter::hasConditionals(), hasControlFlowMove(), ControlFlowGraph::hasInstructionAnotherJump(), hasJump(), hasReturn(), CodeCompressorPlugin::immediateTerminal(), isNOP(), main(), ControlFlowGraph::mergeNodes(), DisasmExecPercentageAttrProvider::moveCellAttr(), BFShareOperandsLate::operator()(), LoopPrologAndEpilogBuilder::optimizeEpilog(), LoopPrologAndEpilogBuilder::optimizeProlog(), SimProgramBuilder::processInstruction(), SimpleIfConverter::removeJump(), ControlFlowGraph::removeJumpToTarget(), ControlFlowGraph::removeUnreachableNodes(), TTAProgram::Program::replaceUniversalAddressSpaces(), BFUnscheduleFromBody::returnOriginal(), BFUnscheduleMove::returnOriginal(), BFShareOperandLate::revert(), setInstructionTemplate(), TTAProgram::BasicBlock::statistics(), BasicBlockNode::toString(), PostpassOperandSharer::tryRemoveOperandWrite(), PreOptimizer::tryToPrecalcConstantAdd(), PreOptimizer::tryToRemoveGuardInversingOp(), SimpleBrokerDirector::unassign(), ProximDebuggerWindow::updateAnnotations(), CopyingDelaySlotFiller::updateFTBBAndCfg(), BasicBlockNode::updateHWloopLength(), CopyingDelaySlotFiller::updateJumpsAndCfg(), and SimpleIfConverter::writesRegister().

◆ movePtr()

std::shared_ptr< Move > TTAProgram::Instruction::movePtr ( int  i) const

Return the move at the given index in this instruction.

The order of moves is arbitrary, no assumption should be made by clients. Anyways, order of moves in instruction does not change between calls to this method.

Parameters
iThe index of the move.
Returns
The move at the given index in this instruction.
Exceptions
OutOfRangeif the given index is negative or greater than the number of moves in the instruction.

Definition at line 216 of file Instruction.cc.

216  {
217  if (i < 0 || static_cast<unsigned int>(i) >= moves_.size()) {
218  throw OutOfRange(__FILE__, __LINE__, __func__,
219  "No move in instruction for given index: " +
221  } else {
222  return moves_.at(i);
223  }
224 }

References __func__, moves_, and Conversion::toString().

Referenced by MoveNodeGroupBuilder::build(), DataDependenceGraphBuilder::constructIndividualBB(), DataDependenceGraphBuilder::constructIndividualFromInlineAsmBB(), llvm::LLVMTCEBuilder::emitInstruction(), and ITemplateBroker::findITemplates().

Here is the call graph for this function:

◆ operator=()

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

Assignment not allowed.

◆ parent()

CodeSnippet & TTAProgram::Instruction::parent ( ) const

Return the parent that contains the instruction.

Returns
The parent that contains the instruction.
Exceptions
IllegalRegistrationIf the instruction is not registered anywhere.

Definition at line 109 of file Instruction.cc.

109  {
110  if (parent_ != NULL) {
111  return *parent_;
112  } else {
113  throw IllegalRegistration(__FILE__, __LINE__, __func__,
114  "Instruction is not registered.");
115  }
116 }

References __func__, and parent_.

Referenced by TTAProgram::Procedure::add(), TTAProgram::CodeSnippet::add(), address(), PreOptimizer::cfgAllowsJumpReversal(), TTAProgram::CodeLabel::CodeLabel(), SimulatorFrontend::compareState(), ControlFlowGraph::computeLeadersFromRefManager(), ControlFlowGraph::createBlock(), POMDisassembler::createMove(), DataDependenceGraph::createSubgraph(), SimulatorFrontend::currentProcedure(), POMDisassembler::disassemble(), SimulatorFrontend::disassembleInstruction(), llvm::LLVMTCEBuilder::emitSPInitialization(), DisassembleCommand::execute(), CopyingDelaySlotFiller::findJumpImmediate(), TTAProgram::Program::fixInstructionReferences(), ProcedureTransferTracker::handleEvent(), SimulationController::next(), TTAProgram::CodeSnippet::nextInstruction(), TTAProgram::Program::nextInstruction(), TTAProgram::CodeSnippet::previousInstruction(), TTAProgram::CodeLabel::procedure(), SimulatorFrontend::programLocationDescription(), TTAProgram::Procedure::remove(), TTAProgram::CodeSnippet::remove(), PreOptimizer::tryToPrecalcConstantAdd(), PreOptimizer::tryToRemoveGuardInversingOp(), and TTAProgram::InstructionReferenceManager::validate().

◆ removeImmediate()

void TTAProgram::Instruction::removeImmediate ( Immediate imm)

Remove immediate from instruction.

Immediate may get deleted if use-count of smart pointer goes to zero.

Parameters
immediateImmediate to remove.
Exceptions
IllegalRegistrationIf immediate doesn't belong to instruction.

Definition at line 560 of file Instruction.cc.

560  {
561  for (ImmList::iterator iter = immediates_.begin();
562  iter != immediates_.end(); iter++) {
563  if ((*iter).get() == &imm) {
564  imm.setParent(nullptr);
565  immediates_.erase(iter);
566  return;
567  }
568  }
569  throw IllegalRegistration(__FILE__, __LINE__);
570 }

References immediates_, and TTAProgram::Immediate::setParent().

Referenced by ITemplateBroker::assign(), LoopPrologAndEpilogBuilder::optimizeProlog(), ITemplateBroker::unassign(), ITemplateBroker::unassignImmediate(), CopyingDelaySlotFiller::updateFTBBAndCfg(), and CopyingDelaySlotFiller::updateJumpsAndCfg().

Here is the call graph for this function:

◆ removeMove()

void TTAProgram::Instruction::removeMove ( Move move)

Remove move from instruction.

Move may become deleted if last smart pointer to it gets removed.

Parameters
moveMove to remove.
Exceptions
IllegalRegistrationIf move doesn't belong to instruction.

Definition at line 536 of file Instruction.cc.

536  {
537  if (&move.parent() != this) {
538  throw IllegalRegistration(__FILE__, __LINE__);
539  }
540 
542  for (MoveList::iterator iter = moves_.begin();
543  iter != moves_.end(); iter++) {
544  if ((iter->get()) == &move) {
545  moves_.erase(iter);
546  break;
547  }
548  }
549 }

References TTAProgram::NullInstruction::instance(), move(), moves_, TTAProgram::Move::parent(), and TTAProgram::Move::setParent().

Referenced by ITemplateBroker::assign(), ProcedurePass::copyCfgToProcedure(), PostpassOperandSharer::handleBasicBlock(), SimpleIfConverter::removeJump(), ControlFlowGraph::removeJumpToTarget(), ITemplateBroker::unassign(), CopyingDelaySlotFiller::updateFTBBAndCfg(), and CopyingDelaySlotFiller::updateJumpsAndCfg().

Here is the call graph for this function:

◆ setFinalAddress()

void TTAProgram::Instruction::setFinalAddress ( InstructionAddress  addr)
inline

Definition at line 121 of file Instruction.hh.

121 { finalAddress_ = addr; }

References finalAddress_.

Referenced by TTAProgram::Program::finalize().

◆ setInstructionTemplate()

void TTAProgram::Instruction::setInstructionTemplate ( const TTAMachine::InstructionTemplate insTemp)

Sets instruction template.

Parameters
insTempInstruction template for the instruction.

Definition at line 488 of file Instruction.cc.

489  {
490  insTemplate_= &insTemp;
491 
492 #if 0
493  for (int i = 0; i < moveCount(); i++) {
494  if (insTemplate_->usesSlot(move(i).bus().name())) {
495  assert(false && "Instruction template conflicts with the "
496  "instruction's slot layout: Both the new template and a move "
497  "uses same slot.");
498  }
499  }
500 
501  for (int i = 0; i < immediateCount(); i++) {
502  int requiredWidth = std::min(
504  immediate(i).value().value().unsignedValue()),
505  immediate(i).value().value().width());
506  if (requiredWidth >
508  immediate(i).destination().immediateUnit())) {
509  assert(false && "The instruction has an long immediate "
510  "not supported by the new instruction template.");
511  }
512  }
513 #endif
514 }

References assert, immediate(), immediateCount(), insTemplate_, move(), moveCount(), MathTools::requiredBits(), TTAMachine::InstructionTemplate::supportedWidth(), and TTAMachine::InstructionTemplate::usesSlot().

Referenced by ITemplateBroker::assign(), ITemplateBroker::assignImmediate(), TTAProgram::TPEFProgramFactory::createInstruction(), ITemplateBroker::instruction(), and ITemplateBroker::reselectTemplate().

Here is the call graph for this function:

◆ setParent()

void TTAProgram::Instruction::setParent ( CodeSnippet proc)

◆ setSize()

void TTAProgram::Instruction::setSize ( short  size)
inline

Definition at line 104 of file Instruction.hh.

104 { size_ = size; }

References size(), and size_.

Referenced by TTAProgram::Program::finalize().

Here is the call graph for this function:

◆ size()

short TTAProgram::Instruction::size ( ) const

◆ toString()

std::string TTAProgram::Instruction::toString ( ) const

Member Data Documentation

◆ finalAddress_

InstructionAddress TTAProgram::Instruction::finalAddress_
mutableprivate

In case the final instruction address is known (due to program not modified anymore), the final instruction address is stored here. -1 in case not known.

Definition at line 149 of file Instruction.hh.

Referenced by address(), hasFinalAddress(), and setFinalAddress().

◆ hasConditionalRegisterAccesses_

bool TTAProgram::Instruction::hasConditionalRegisterAccesses_
private

Set to true in case this instruction has moves that access registers and are conditional.

Definition at line 157 of file Instruction.hh.

Referenced by addMove(), copy(), and hasConditionalRegisterAccesses().

◆ hasRegisterAccesses_

bool TTAProgram::Instruction::hasRegisterAccesses_
private

Set to true in case this instruction has moves that access registers.

Definition at line 154 of file Instruction.hh.

Referenced by addMove(), copy(), and hasRegisterAccesses().

◆ immediates_

ImmList TTAProgram::Instruction::immediates_
private

Immediates contained in this instruction.

Definition at line 137 of file Instruction.hh.

Referenced by addImmediate(), immediate(), immediateCount(), immediatePtr(), removeImmediate(), and ~Instruction().

◆ insTemplate_

const TTAMachine::InstructionTemplate* TTAProgram::Instruction::insTemplate_
private

Instruction template that is used for this instruction.

Definition at line 142 of file Instruction.hh.

Referenced by addImmediate(), addMove(), copy(), instructionTemplate(), and setInstructionTemplate().

◆ moves_

MoveList TTAProgram::Instruction::moves_
private

Moves contained in this instruction.

Definition at line 135 of file Instruction.hh.

Referenced by addMove(), move(), moveCount(), movePtr(), removeMove(), and ~Instruction().

◆ parent_

CodeSnippet* TTAProgram::Instruction::parent_
private

Parent procedure.

Definition at line 139 of file Instruction.hh.

Referenced by isInProcedure(), parent(), and setParent().

◆ positionInProcedure_

InstructionAddress TTAProgram::Instruction::positionInProcedure_
mutableprivate

Cache the instruction's index in the its procedure for faster address().

Definition at line 145 of file Instruction.hh.

Referenced by address().

◆ size_

short TTAProgram::Instruction::size_
mutableprivate

Size of instruction in MAU's.

Definition at line 152 of file Instruction.hh.

Referenced by copy(), setSize(), and size().


The documentation for this class was generated from the following files:
TTAProgram::Move::copy
std::shared_ptr< Move > copy() const
Definition: Move.cc:413
InstructionAddress
UInt32 InstructionAddress
Definition: BaseType.hh:175
TTAProgram::Instruction::finalAddress_
InstructionAddress finalAddress_
In case the final instruction address is known (due to program not modified anymore),...
Definition: Instruction.hh:149
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTAProgram::Move::isReturn
bool isReturn() const
Definition: Move.cc:259
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
OutOfRange
Definition: Exception.hh:320
TTAProgram::NullProcedure::instance
static NullProcedure & instance()
Definition: NullProcedure.cc:68
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
TTAProgram::CodeSnippet::startAddress
virtual Address startAddress() const
Definition: CodeSnippet.cc:780
TTAProgram::Immediate::copy
std::shared_ptr< Immediate > copy() const
Definition: Immediate.cc:131
TTAProgram::Instruction::immediates_
ImmList immediates_
Immediates contained in this instruction.
Definition: Instruction.hh:137
Conversion::toString
static std::string toString(const T &source)
TTAProgram::Move::setParent
void setParent(Instruction &ins)
Definition: Move.cc:130
assert
#define assert(condition)
Definition: Application.hh:86
TTAProgram::Instruction::hasRegisterAccesses_
bool hasRegisterAccesses_
Set to true in case this instruction has moves that access registers.
Definition: Instruction.hh:154
TTAProgram::Instruction::insTemplate_
const TTAMachine::InstructionTemplate * insTemplate_
Instruction template that is used for this instruction.
Definition: Instruction.hh:142
TTAProgram::Move::isControlFlowMove
bool isControlFlowMove() const
Definition: Move.cc:233
TTAProgram::Move::isCall
bool isCall() const
Definition: Move.cc:190
__func__
#define __func__
Definition: Application.hh:67
TTAProgram::Instruction::parent
CodeSnippet & parent() const
Definition: Instruction.cc:109
TTAProgram::Instruction::size_
short size_
Size of instruction in MAU's.
Definition: Instruction.hh:152
TTAProgram::Terminal::isGPR
virtual bool isGPR() const
Definition: Terminal.cc:107
MathTools::requiredBits
static int requiredBits(unsigned long int number)
TTAMachine::InstructionTemplate::supportedWidth
virtual int supportedWidth() const
Definition: InstructionTemplate.cc:427
TTAProgram::Address::location
InstructionAddress location() const
TTAProgram::NullInstruction::instance
static NullInstruction & instance()
Definition: NullInstruction.cc:66
TTAProgram::Instruction::immediate
Immediate & immediate(int i) const
Definition: Instruction.cc:285
IllegalRegistration
Definition: Exception.hh:532
TTAProgram::Instruction::instructionTemplate
const TTAMachine::InstructionTemplate & instructionTemplate() const
Definition: Instruction.cc:523
TTAProgram::Instruction::isInProcedure
bool isInProcedure() const
Definition: Instruction.cc:135
TTAProgram::Instruction::positionInProcedure_
InstructionAddress positionInProcedure_
Cache the instruction's index in the its procedure for faster address().
Definition: Instruction.hh:145
TTAProgram::CodeSnippet::address
virtual Address address(const Instruction &ins) const
Definition: CodeSnippet.cc:163
POMDisassembler::disassemble
static std::string disassemble(const TTAProgram::Move &move)
Definition: POMDisassembler.cc:629
TTAMachine::NullInstructionTemplate::instance
static NullInstructionTemplate & instance()
Definition: NullInstructionTemplate.cc:62
TTAProgram::Instruction::moves_
MoveList moves_
Moves contained in this instruction.
Definition: Instruction.hh:135
TTAProgram::Move::parent
Instruction & parent() const
Definition: Move.cc:115
ObjectAlreadyExists
Definition: Exception.hh:1002
TTAProgram::Instruction::hasConditionalRegisterAccesses_
bool hasConditionalRegisterAccesses_
Set to true in case this instruction has moves that access registers and are conditional.
Definition: Instruction.hh:157
TCEString
Definition: TCEString.hh:53
TTAProgram::Instruction::size
short size() const
Definition: Instruction.cc:365
TTAProgram::Instruction::immediateCount
int immediateCount() const
Definition: Instruction.cc:267
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
ContainerTools::containsValue
static bool containsValue(const ContainerType &aContainer, const ElementType &aKey)
TTAProgram::Move::isJump
bool isJump() const
Definition: Move.cc:164
TTAProgram::Instruction::parent_
CodeSnippet * parent_
Parent procedure.
Definition: Instruction.hh:139
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
TTAMachine::InstructionTemplate::usesSlot
virtual bool usesSlot(const std::string &slotName) const
Definition: InstructionTemplate.cc:265
TTAProgram::Instruction::address
Address address() const
Definition: Instruction.cc:327
TTAProgram::Instruction::Instruction
Instruction(const TTAMachine::InstructionTemplate &instructionTemplate=TTAMachine::NullInstructionTemplate::instance())
Definition: Instruction.cc:63