OpenASIP  2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BFSwapOperands Class Reference

#include <BFSwapOperands.hh>

Inheritance diagram for BFSwapOperands:
Inheritance graph
Collaboration diagram for BFSwapOperands:
Collaboration graph

Public Member Functions

 BFSwapOperands (BF2Scheduler &sched, MoveNode &mn)
 
 BFSwapOperands (BF2Scheduler &sched, ProgramOperationPtr po, MoveNode &mn1, MoveNode &mn2)
 
virtual bool operator() ()
 
virtual ~BFSwapOperands ()
 
std::pair< MoveNode *, MoveNode * > switchedMNs ()
 
- Public Member Functions inherited from BFOptimization
 BFOptimization (BF2Scheduler &sched)
 
virtual bool isFinishFront ()
 
virtual void mightBeReady (MoveNode &mn)
 
- Public Member Functions inherited from Reversible
virtual void undo ()
 
virtual ~Reversible ()
 
void deleteChildren (std::stack< Reversible * > &children)
 
int id ()
 
 Reversible ()
 

Protected Member Functions

virtual void undoOnlyMe ()
 
- Protected Member Functions inherited from BFOptimization
DataDependenceGraphddg ()
 
DataDependenceGraphrootDDG ()
 
const DataDependenceGraphddg () const
 
DataDependenceGraphprologDDG ()
 
SimpleResourceManagerrm () const
 
SimpleResourceManagerprologRM () const
 
BUMoveNodeSelectorselector ()
 
const TTAMachine::MachinetargetMachine () const
 
unsigned int ii () const
 
MoveNodeDuplicatorduplicator () const
 
virtual bool assign (int cycle, MoveNode &, const TTAMachine::Bus *bus=nullptr, const TTAMachine::FunctionUnit *srcFU_=nullptr, const TTAMachine::FunctionUnit *dstFU=nullptr, const TTAMachine::Bus *prologBus=nullptr, int immWriteCycle=-1, int prologImmWriteCycle=-1, const TTAMachine::ImmediateUnit *immu=nullptr, int immRegIndex=-1, bool ignoreGuardWriteCycle=false)
 
virtual void unassign (MoveNode &mn, bool disposePrologCopy=true)
 
virtual int rmEC (int cycle, MoveNode &mn, const TTAMachine::Bus *bus=nullptr, const TTAMachine::FunctionUnit *srcFU=nullptr, const TTAMachine::FunctionUnit *dstFU=nullptr, const TTAMachine::Bus *prologBus=nullptr, int immWriteCycle=-1, int prologImmWriteCycle=-1, const TTAMachine::ImmediateUnit *immu=nullptr, int immRegIndex=-1)
 
virtual int rmLC (int cycle, MoveNode &mn, const TTAMachine::Bus *bus=nullptr, const TTAMachine::FunctionUnit *srcFU=nullptr, const TTAMachine::FunctionUnit *dstFU=nullptr, const TTAMachine::Bus *prologBus=nullptr, int immWriteCycle=-1, int prologImmWriteCycle=-1, const TTAMachine::ImmediateUnit *immu=nullptr, int immRegIndex=-1)
 
virtual bool canAssign (int cycle, MoveNode &mn, const TTAMachine::Bus *bus=nullptr, const TTAMachine::FunctionUnit *srcFU=nullptr, const TTAMachine::FunctionUnit *dstFU=nullptr, const TTAMachine::Bus *prologBus=nullptr, int immWriteCycle=-1, int prologImmWriteCycle=-1, const TTAMachine::ImmediateUnit *immu=nullptr, int immRegIndex=-1, bool ignoreGWN=false)
 
bool putAlsoToPrologEpilog (int cycle, MoveNode &mn)
 
void setPrologSrcFUAnno (MoveNode &prologMN, MoveNode &loopMN)
 
void setPrologDstFUAnno (MoveNode &prologMN, MoveNode &loopMN)
 
void setJumpGuard (MoveNode &mn)
 
void unsetJumpGuard (MoveNode &mn)
 
bool needJumpGuard (const MoveNode &mn, int cycle)
 
int jumpGuardAvailableCycle (const MoveNode &mn)
 
bool canBeSpeculated (const Operation &op)
 
bool canBeSpeculated (const MoveNode &mn)
 
bool usePrologMove (const MoveNode &mn)
 
bool canBeScheduled (const MoveNode &mn)
 
const TTAMachine::RegisterFileRFReadPortCountPreventsScheduling (const MoveNode &mn)
 
bool immCountPreventsScheduling (const MoveNode &mn)
 
- Protected Member Functions inherited from Reversible
bool runPreChild (Reversible *preChild)
 
bool runPostChild (Reversible *preChild)
 
bool runChild (std::stack< Reversible * > &children, Reversible *child)
 
bool runChild (Reversible *child, bool pre)
 
void undoAndRemovePreChildren ()
 
void undoAndRemovePostChildren ()
 
void undoAndRemoveChildren (std::stack< Reversible * > &children)
 

Protected Attributes

std::pair< MoveNode *, MoveNode * > switched_
 
ProgramOperationPtr poPtr_
 
int idx1_
 
int idx2_
 
- Protected Attributes inherited from BFOptimization
BF2Schedulersched_
 
- Protected Attributes inherited from Reversible
std::stack< Reversible * > preChildren_
 
std::stack< Reversible * > postChildren_
 

Additional Inherited Members

- Static Public Member Functions inherited from BFOptimization
static void clearPrologMoves ()
 
static MoveNodegetSisterTrigger (const MoveNode &mn, const TTAMachine::Machine &mach)
 
- Static Protected Attributes inherited from BFOptimization
static std::map< MoveNode *, MoveNode *, MoveNode::ComparatorprologMoves_
 

Detailed Description

Definition at line 41 of file BFSwapOperands.hh.

Constructor & Destructor Documentation

◆ BFSwapOperands() [1/2]

BFSwapOperands::BFSwapOperands ( BF2Scheduler sched,
MoveNode trigger 
)

Tries to switch operand and trigger so that it makees immediates triggers, but minimizes the critical path if both operands come from variables.

Definition at line 56 of file BFSwapOperands.cc.

56  :
57  BFOptimization(sched), switched_(NULL,NULL), poPtr_(),
58  idx1_(0), idx2_(0) {
59 
60  if (trigger.destinationOperationCount() != 1) {
61 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
62  std::cerr << "not exactly one destop:" << trigger.toString()
63  << std::endl;
64 #endif
65  return;
66  }
67 
68  // keep immediates as triggers
69  if (trigger.move().source().isImmediate()) {
70  return;
71  }
72 
73  int index = trigger.move().destination().operationIndex();
75  const Operation &op = poPtr->operation();
76 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
77  std::cerr << "trying to swap operand of po: "
78  << poPtr->toString() << std::endl;
79 #endif
80 
81  for (int i = 1; i <= op.numberOfInputs(); i++) {
82  if (i == index) {
83 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
84  std::cerr << "\tNot swapping with itself" << std::endl;
85 #endif
86  continue;
87  }
88  if (!op.canSwap(i, index)) {
89 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
90  std::cerr << "\tnot commutative" << std::endl;
91 #endif
92  continue;
93  }
94 
95  MoveNodeSet& otherInputs = poPtr->inputNode(i);
96  if (otherInputs.count() != 1) {
97 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
98  std::cerr << "\tother input count not 1" << std::endl;
99 #endif
100  continue;
101  }
102 
103  MoveNode& other = otherInputs.at(0);
104  if (other.isScheduled()) {
105  continue;
106  }
107 
108  if (sched_.isPreLoopSharedOperand(other)) {
109 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
110  std::cerr << "\tCannot swap operand with pre-loop-shared" << std::endl;
111 #endif
112  continue;
113  }
114 
115 
116  // make longer path OR immediate into trigger
117  // currently only immediate.
118  if (other.move().source().isImmediate()) {
119 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
120  std::cerr << "\tshould swap indeces: " << i << " and " << index
121  << std::endl;
122 #endif
123  idx1_ = index;
124  idx2_ = i;
125  poPtr_ = poPtr;
126  switched_.first = &trigger;
127  switched_.second = &other;
128  return;
129  }
130 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
131  std::cerr << "\tother input is: " << other.toString() << std::endl;
132 #endif
133  }
134  return;
135 }

References MoveNodeSet::at(), Operation::canSwap(), MoveNodeSet::count(), TTAProgram::Move::destination(), MoveNode::destinationOperationCount(), MoveNode::destinationOperationPtr(), idx1_, idx2_, TTAProgram::Terminal::isImmediate(), BF2Scheduler::isPreLoopSharedOperand(), MoveNode::isScheduled(), MoveNode::move(), Operation::numberOfInputs(), TTAProgram::Terminal::operationIndex(), poPtr_, BFOptimization::sched_, TTAProgram::Move::source(), switched_, and MoveNode::toString().

Here is the call graph for this function:

◆ BFSwapOperands() [2/2]

BFSwapOperands::BFSwapOperands ( BF2Scheduler sched,
ProgramOperationPtr  po,
MoveNode mn1,
MoveNode mn2 
)

Definition at line 45 of file BFSwapOperands.cc.

46  :
47  BFOptimization(sched), switched_(&mn1, &mn2), poPtr_(po),
49  idx2_(mn2.move().destination().operationIndex()) {}

◆ ~BFSwapOperands()

virtual BFSwapOperands::~BFSwapOperands ( )
inlinevirtual

Definition at line 48 of file BFSwapOperands.hh.

48 {}

Member Function Documentation

◆ operator()()

bool BFSwapOperands::operator() ( )
virtual

This performs the operation. Returns true if success, false if fail.

Implements Reversible.

Definition at line 137 of file BFSwapOperands.cc.

137  {
138  if (poPtr_ == NULL) {
139  return false;
140  }
141  const Operation &op = poPtr_->operation();
142  if (!op.canSwap(idx1_, idx2_)) {
143 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
144  std::cerr << "Cannot swap: " << idx1_ << " and " << idx2_ << std::endl;
145 #endif
146  return false;
147  }
148 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
149  std::cerr << "Swapping inputs: " << poPtr_->toString() << std::endl;
150 #endif
151  poPtr_->switchInputs(idx1_, idx2_);
152 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
153  std::cerr << "Swapped inputs: " << poPtr_->toString() << std::endl;
154 #endif
155  return true;
156 }

References Operation::canSwap(), idx1_, idx2_, and poPtr_.

Here is the call graph for this function:

◆ switchedMNs()

std::pair<MoveNode*,MoveNode*> BFSwapOperands::switchedMNs ( )
inline

Definition at line 49 of file BFSwapOperands.hh.

49 { return switched_; }

References switched_.

Referenced by BF2ScheduleFront::getMoveNodeFromFrontBU().

◆ undoOnlyMe()

void BFSwapOperands::undoOnlyMe ( )
protectedvirtual

Undoes the operations done by this class but not children. This method should be overloaded by most derived classes.

Reimplemented from Reversible.

Definition at line 158 of file BFSwapOperands.cc.

158  {
159 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
160  std::cerr << "undoing swap: " << poPtr_->toString() << std::endl;
161 #endif
162  poPtr_->switchInputs(idx1_, idx2_);
163 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
164  std::cerr << "undid swap: " << poPtr_->toString() << std::endl;
165 #endif
166 }

References idx1_, idx2_, and poPtr_.

Member Data Documentation

◆ idx1_

int BFSwapOperands::idx1_
protected

Definition at line 54 of file BFSwapOperands.hh.

Referenced by BFSwapOperands(), operator()(), and undoOnlyMe().

◆ idx2_

int BFSwapOperands::idx2_
protected

Definition at line 55 of file BFSwapOperands.hh.

Referenced by BFSwapOperands(), operator()(), and undoOnlyMe().

◆ poPtr_

ProgramOperationPtr BFSwapOperands::poPtr_
protected

Definition at line 53 of file BFSwapOperands.hh.

Referenced by BFSwapOperands(), operator()(), and undoOnlyMe().

◆ switched_

std::pair<MoveNode*, MoveNode*> BFSwapOperands::switched_
protected

Definition at line 52 of file BFSwapOperands.hh.

Referenced by BFSwapOperands(), and switchedMNs().


The documentation for this class was generated from the following files:
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFSwapOperands::poPtr_
ProgramOperationPtr poPtr_
Definition: BFSwapOperands.hh:53
BFSwapOperands::idx1_
int idx1_
Definition: BFSwapOperands.hh:54
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
Operation::numberOfInputs
virtual int numberOfInputs() const
Definition: Operation.cc:192
MoveNode
Definition: MoveNode.hh:65
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: MoveNode.hh:52
Operation::canSwap
virtual bool canSwap(int id1, int id2) const
Definition: Operation.cc:470
BF2Scheduler::isPreLoopSharedOperand
TTAMachine::FUPort * isPreLoopSharedOperand(MoveNode &mn) const
Definition: BF2Scheduler.cc:1625
TTAProgram::Terminal::operationIndex
virtual int operationIndex() const
Definition: Terminal.cc:364
MoveNodeSet::at
MoveNode & at(int index)
BFSwapOperands::idx2_
int idx2_
Definition: BFSwapOperands.hh:55
BFSwapOperands::switched_
std::pair< MoveNode *, MoveNode * > switched_
Definition: BFSwapOperands.hh:52
MoveNode::destinationOperationCount
unsigned int destinationOperationCount() const
MoveNodeSet
Definition: MoveNodeSet.hh:41
Operation
Definition: Operation.hh:59
BFOptimization::BFOptimization
BFOptimization(BF2Scheduler &sched)
Definition: BFOptimization.hh:75
MoveNodeSet::count
int count() const
MoveNode::destinationOperationPtr
ProgramOperationPtr destinationOperationPtr(unsigned int index=0) const
MoveNode::move
TTAProgram::Move & move()
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
TTAProgram::Terminal::isImmediate
virtual bool isImmediate() const
Definition: Terminal.cc:63