OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
BFLateBypasses Class Reference

#include <BFLateBypasses.hh>

Inheritance diagram for BFLateBypasses:
Inheritance graph
Collaboration diagram for BFLateBypasses:
Collaboration graph

Public Member Functions

 BFLateBypasses (BF2Scheduler &sched, MoveNode &src, int lc)
 
virtual bool operator() ()
 
bool removedSource ()
 
- 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 ()
 

Private Attributes

MoveNodesrc_
 
int lc_
 
bool removedSource_
 
int bypassDistance_
 

Additional Inherited Members

- Static Public Member Functions inherited from BFOptimization
static void clearPrologMoves ()
 
static MoveNodegetSisterTrigger (const MoveNode &mn, const TTAMachine::Machine &mach)
 
- 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)
 
virtual void undoOnlyMe ()
 
- Protected Attributes inherited from BFOptimization
BF2Schedulersched_
 
- Protected Attributes inherited from Reversible
std::stack< Reversible * > preChildren_
 
std::stack< Reversible * > postChildren_
 
- Static Protected Attributes inherited from BFOptimization
static std::map< MoveNode *, MoveNode *, MoveNode::ComparatorprologMoves_
 

Detailed Description

Definition at line 44 of file BFLateBypasses.hh.

Constructor & Destructor Documentation

◆ BFLateBypasses()

BFLateBypasses::BFLateBypasses ( BF2Scheduler sched,
MoveNode src,
int  lc 
)

Definition at line 53 of file BFLateBypasses.cc.

53  :
54  BFOptimization(sched), src_(src), lc_(lc), removedSource_(false),
55  bypassDistance_(5) {
58  if (opts != NULL) {
59  if (opts->bypassDistance() > -1) {
61  }
62  }
63 }

References SchedulerCmdLineOptions::bypassDistance(), bypassDistance_, and Application::cmdLineOptions().

Here is the call graph for this function:

Member Function Documentation

◆ operator()()

bool BFLateBypasses::operator() ( )
virtual

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

Implements Reversible.

Definition at line 66 of file BFLateBypasses.cc.

66  {
67 
68  int variableDstCount = 0;
69  bool bypassed = false;
70  auto rrDestinations =
72 
73  // the boolean specifies whether this is normal or guard bypass.
74  std::map<MoveNode*, bool, MoveNode::Comparator> bypassDestinations;
75 
76  int earliestDst = INT_MAX;
77  // first just search all potentials.
78  for (auto i : rrDestinations) {
79  MoveNode* n = i.second;
80  int guardParam = i.first->guardUse() ? 1 : 2;
81  // TODO: the rootgraph here prevents over-loop-edge bypass.
82  // TODO: enable over-loop-edge bypass when it works.
83  // Needs update to ddg.mergeAndKeep() to put backedge
84  // properties and BFOptimization::assign() to keep original
85  // register in prolog. (create copy MN of original for prolog
86  // when bypassing?
87  if ((static_cast<DataDependenceGraph*>(ddg().rootGraph()))->
88  onlyRegisterRawSource(*n, guardParam) == NULL) {
89  continue;
90  }
91 
92  // not guard but normal read
93  if (guardParam == 2) {
94  MachineConnectivityCheck::PortSet destinationPorts;
95  destinationPorts.insert(&n->move().destination().port());
96 
98  src_, destinationPorts)) {
99  if (n->isScheduled() == false
100  && (static_cast<SimpleResourceManager&>(
101  rm()).initiationInterval() != 0)) {
102  // Found node connected by loop edge, ignore it.
103  continue;
104  }
105 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
106  std::cerr << "\t\tFound ok bypass dest: " << n->toString()
107  << std::endl;
108 #endif
109 
110  if (!ddg().guardsAllowBypass(src_, *n)) {
111 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
112  std::cerr << "\t\tGuards do not allow bypass to: "
113  << n->toString() << std::endl;
114 #endif
115  continue;
116  }
117 
118  assert(n->isScheduled());
119  int originalCycle = n->cycle();
120  int earliestLimit = originalCycle - bypassDistance_;
121  if (lc_ < earliestLimit) {
122 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
123  std::cerr << "\t\t\tcycle limites prevent late bypass "
124  << std::endl;
125 #endif
126  continue;
127  }
128  earliestDst = std::min(earliestDst, originalCycle);
129  bypassDestinations.insert(std::make_pair(n, false));
130  }
131  } else {
132  // TODO: test if guard bypass possible.
133  // now handled in the guard bypass class itself.
134  assert(n->isScheduled());
135  int originalCycle = n->cycle();
136  int earliestLimit = originalCycle - bypassDistance_;
137  if (lc_ < earliestLimit) {
138 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
139  std::cerr << "\t\t\tcycle limites prevent late bypass "
140  << std::endl;
141 #endif
142  continue;
143  }
144  earliestDst = std::min(earliestDst, originalCycle);
145  bypassDestinations.insert(std::make_pair(n, true));
146  }
147  }
148 
149  // Do the critical one first. This may force the source FU.
150  for (auto n : bypassDestinations) {
151  if (n.first->cycle() == earliestDst) {
152  if (!n.second) {
153 
154  // if always write results,
155  // op cannot have more than one register target.
156  if (targetMachine().alwaysWriteResults() &&
158  n.first->isDestinationVariable() &&
159  variableDstCount>0) {
160  continue;
161  }
162 
163  BFLateBypass* lbp =
164  new BFLateBypass(sched_, src_, *n.first, lc_);
165  if (runPreChild(lbp)) {
166  bypassed = true;
167  if (n.first->isDestinationVariable()) {
168  variableDstCount++;
169  }
170  }
171  bypassDestinations.erase(n.first);
172  break;
173  } else {
174 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
175  std::cerr << "\nAttempting guard bypass from: " <<
176  src_.toString() << " to: " << n.first->toString()
177  << std::endl;
178 #endif
179  // guard bypass
180  BFLateBypassGuard* lbp =
181  new BFLateBypassGuard(sched_, src_, *n.first, lc_);
182  if (runPreChild(lbp)) {
183  bypassed = true;
184 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
185  std::cerr << "\tguard bypass ok." << std::endl;
186  } else {
187  std::cerr << "\tGuard bypass failed." << std::endl;
188 #endif
189  }
190  bypassDestinations.erase(n.first);
191  break;
192  }
193  }
194  }
195 
196  // then actually do the bypass for the other, non-critical moves
197  for (auto n : bypassDestinations) {
198  if (!n.second) {
199  // if always write results,
200  // op cannot have more than one register target.
201  if (targetMachine().alwaysWriteResults() &&
203  n.first->isDestinationVariable() &&
204  variableDstCount>0) {
205  continue;
206  }
207 
208  int originalCycle = n.first->cycle();
209  if (originalCycle > earliestDst + bypassDistance_) {
210  continue;
211  }
212  BFLateBypass* lbp = new BFLateBypass(sched_, src_, *n.first, lc_);
213  if (runPreChild(lbp)) {
214  bypassed = true;
215  if (n.first->isDestinationVariable()) {
216  variableDstCount++;
217  }
218  }
219  }
220  }
221  if (!bypassed) {
222  return false;
223  }
224 
225  // if always write results,
226  // op must have exactly one register target.
227  if (targetMachine().alwaysWriteResults() &&
229  // if none of the bypassed are to reg,
230  // may not DRE
231  if (variableDstCount == 0) {
232  return true;
233  }
234  assert(variableDstCount == 1);
235  // if one of the bypasses are to reg,
236  // MUST dre.
237  BFDRELate* dre = new BFDRELate(sched_, src_);
238  if (runPostChild(dre)) {
239  removedSource_ = true;
240  return true;
241  } else {
243  return false;
244  }
245  }
246 
247  BFDRELate* dre = new BFDRELate(sched_, src_);
248  if (runPostChild(dre)) {
249  removedSource_ = true;
250 #ifdef DEBUG_BUBBLEFISH_SCHEDULER
251  std::cerr << "DRE ok!" << std::endl;
252  } else {
253  std::cerr << "Could not DRE away: " << src_.toString() << std::endl;
254 #endif
255  }
256  return true;
257 }

References assert, bypassDistance_, MachineConnectivityCheck::canSourceWriteToAnyDestinationPort(), MoveNode::cycle(), BFOptimization::ddg(), TTAProgram::Move::destination(), MoveNode::isScheduled(), MoveNode::isSourceOperation(), lc_, MoveNode::move(), DataDependenceGraph::onlyRegisterRawDestinationsWithEdges(), TTAProgram::Terminal::port(), removedSource_, BFOptimization::rm(), Reversible::runPostChild(), Reversible::runPreChild(), BFOptimization::sched_, src_, BFOptimization::targetMachine(), MoveNode::toString(), and Reversible::undoAndRemovePreChildren().

Here is the call graph for this function:

◆ removedSource()

bool BFLateBypasses::removedSource ( )
inline

Definition at line 49 of file BFLateBypasses.hh.

49 { return removedSource_;}

References removedSource_.

Referenced by BFScheduleTD::operator()(), and BFScheduleBU::operator()().

Member Data Documentation

◆ bypassDistance_

int BFLateBypasses::bypassDistance_
private

Definition at line 54 of file BFLateBypasses.hh.

Referenced by BFLateBypasses(), and operator()().

◆ lc_

int BFLateBypasses::lc_
private

Definition at line 52 of file BFLateBypasses.hh.

Referenced by operator()().

◆ removedSource_

bool BFLateBypasses::removedSource_
private

Definition at line 53 of file BFLateBypasses.hh.

Referenced by operator()(), and removedSource().

◆ src_

MoveNode& BFLateBypasses::src_
private

Definition at line 51 of file BFLateBypasses.hh.

Referenced by operator()().


The documentation for this class was generated from the following files:
DataDependenceGraph::onlyRegisterRawDestinationsWithEdges
std::map< DataDependenceEdge *, MoveNode *, DataDependenceEdge::Comparator > onlyRegisterRawDestinationsWithEdges(const MoveNode &mn, bool allowBackEdges) const
Definition: DataDependenceGraph.cc:4124
Reversible::undoAndRemovePreChildren
void undoAndRemovePreChildren()
Definition: Reversible.cc:80
MoveNode::isDestinationVariable
bool isDestinationVariable() const
Definition: MoveNode.cc:264
MoveNode::toString
std::string toString() const
Definition: MoveNode.cc:576
BFLateBypasses::src_
MoveNode & src_
Definition: BFLateBypasses.hh:51
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
MoveNode
Definition: MoveNode.hh:65
BFLateBypasses::lc_
int lc_
Definition: BFLateBypasses.hh:52
SchedulerCmdLineOptions
Definition: SchedulerCmdLineOptions.hh:45
BFOptimization::targetMachine
const TTAMachine::Machine & targetMachine() const
Definition: BFOptimization.cc:81
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFLateBypasses::bypassDistance_
int bypassDistance_
Definition: BFLateBypasses.hh:54
assert
#define assert(condition)
Definition: Application.hh:86
MoveNode::cycle
int cycle() const
Definition: MoveNode.cc:421
Application::cmdLineOptions
static CmdLineOptions * cmdLineOptions()
Definition: Application.cc:397
MachineConnectivityCheck::canSourceWriteToAnyDestinationPort
static int canSourceWriteToAnyDestinationPort(const MoveNode &src, PortSet &ports, bool ignoreGuard=false)
Definition: MachineConnectivityCheck.cc:1754
MoveNode::isSourceOperation
bool isSourceOperation() const
Definition: MoveNode.cc:168
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
BFOptimization::rm
SimpleResourceManager & rm() const
Definition: BFOptimization.cc:76
BFOptimization::BFOptimization
BFOptimization(BF2Scheduler &sched)
Definition: BFOptimization.hh:75
MoveNode::move
TTAProgram::Move & move()
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
MoveNode::isScheduled
bool isScheduled() const
Definition: MoveNode.cc:409
SimpleResourceManager
Definition: SimpleResourceManager.hh:58
TTAProgram::Terminal::port
virtual const TTAMachine::Port & port() const
Definition: Terminal.cc:378
BFDRELate
Definition: BFDRELate.hh:40
SchedulerCmdLineOptions::bypassDistance
virtual int bypassDistance() const
Definition: SchedulerCmdLineOptions.cc:327
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
BFLateBypass
Definition: BFLateBypass.hh:47
BFLateBypassGuard
Definition: BFLateBypassGuard.hh:8
MachineConnectivityCheck::PortSet
std::set< const TTAMachine::Port *, const TTAMachine::MachinePart::Comparator > PortSet
Definition: MachineConnectivityCheck.hh:72
BFLateBypasses::removedSource_
bool removedSource_
Definition: BFLateBypasses.hh:53