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

#include <BFMergeAndKeepUser.hh>

Inheritance diagram for BFMergeAndKeepUser:
Inheritance graph
Collaboration diagram for BFMergeAndKeepUser:
Collaboration graph

Public Member Functions

 BFMergeAndKeepUser (BF2Scheduler &sched, MoveNode &src, MoveNode &mn, bool force=false, bool updatePrologMove=true)
 
bool operator() () override
 
 ~BFMergeAndKeepUser ()
 
- 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

void undoOnlyMe () override
 
bool updateEdges (MoveNode *src, MoveNode *dst, bool loopBypass, bool pre)
 
- 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)
 

Private Attributes

MoveNodesrc_
 
MoveNodedst_
 
bool force_
 
TCEString reg_
 
bool updatePrologMove_
 
bool duplicatedSrc_
 

Additional Inherited Members

- Static Public Member Functions inherited from BFOptimization
static void clearPrologMoves ()
 
static MoveNodegetSisterTrigger (const MoveNode &mn, const TTAMachine::Machine &mach)
 
- 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 41 of file BFMergeAndKeepUser.hh.

Constructor & Destructor Documentation

◆ BFMergeAndKeepUser()

BFMergeAndKeepUser::BFMergeAndKeepUser ( BF2Scheduler sched,
MoveNode src,
MoveNode mn,
bool  force = false,
bool  updatePrologMove = true 
)
inline

Definition at line 43 of file BFMergeAndKeepUser.hh.

47  :
48  BFOptimization(sched), src_(src), dst_(mn),
49  force_(force),
50  updatePrologMove_(updatePrologMove),
51  duplicatedSrc_(false) {}

◆ ~BFMergeAndKeepUser()

BFMergeAndKeepUser::~BFMergeAndKeepUser ( )
inline

Definition at line 53 of file BFMergeAndKeepUser.hh.

53 {}

Member Function Documentation

◆ operator()()

bool BFMergeAndKeepUser::operator() ( )
overridevirtual

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

Implements Reversible.

Definition at line 150 of file BFMergeAndKeepUser.cc.

150  {
151 
152 
153  if (!ddg().mergeAndKeepAllowed(src_, dst_)) {
154  if (!force_) {
155  return false;
156  }
157  }
158 
159  bool loopBypass = ddg().isLoopBypass(src_, dst_);
160 
161  // Cannot bypass over multiple loop iterations. even with force flag.
162  if (loopBypass) {
163  for (int i = 0; i < ddg().inDegree(src_); i++) {
164  DataDependenceEdge& edge = ddg().inEdge(src_,i);
165  if (!edge.isFalseDep() && edge.isBackEdge()) {
166  return false;
167  }
168  }
169  }
171 
172  if (!updateEdges(&src_, &dst_, loopBypass, true)) {
173  return false;
174  }
175 
176 
177  if (ii() && updatePrologMove_) {
178  MoveNode* prologMove = duplicator().getMoveNode(dst_);
179  if (prologMove != nullptr) {
180  auto prologSrcMove =
181  duplicator().duplicateMoveNode(src_,true, false);
182  duplicatedSrc_ = prologSrcMove.second;
183 
184  runPostChild(
186  sched_, *prologSrcMove.first, *prologMove));
187 
188  updateEdges(
189  prologSrcMove.first, prologMove, loopBypass, false);
190 
191  }
192  }
193  return true;
194 
195 }

References BFOptimization::ddg(), dst_, duplicatedSrc_, MoveNodeDuplicator::duplicateMoveNode(), BFOptimization::duplicator(), force_, MoveNodeDuplicator::getMoveNode(), BFOptimization::ii(), BoostGraph< GraphNode, GraphEdge >::inDegree(), BoostGraph< GraphNode, GraphEdge >::inEdge(), DataDependenceEdge::isBackEdge(), DataDependenceEdge::isFalseDep(), DataDependenceGraph::isLoopBypass(), Reversible::runPostChild(), Reversible::runPreChild(), BFOptimization::sched_, src_, updateEdges(), and updatePrologMove_.

Here is the call graph for this function:

◆ undoOnlyMe()

void BFMergeAndKeepUser::undoOnlyMe ( )
overrideprotectedvirtual

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 197 of file BFMergeAndKeepUser.cc.

197  {
198  if (duplicatedSrc_) {
199  duplicator().disposeMoveNode(duplicator().getMoveNode(src_));
200  }
201 }

References MoveNodeDuplicator::disposeMoveNode(), duplicatedSrc_, BFOptimization::duplicator(), and src_.

Here is the call graph for this function:

◆ updateEdges()

bool BFMergeAndKeepUser::updateEdges ( MoveNode src,
MoveNode dst,
bool  loopBypass,
bool  pre 
)
protected

Definition at line 47 of file BFMergeAndKeepUser.cc.

48  {
49 
50  bool sourceIsRegToItselfCopy = false;
51 
52  if (src != nullptr && dst != nullptr &&
53  ddg().rootGraph()->hasNode(*dst) &
54  ddg().rootGraph()->hasNode(*src)) {
55  bool removedRawEdge = false;
56  auto edges = ddg().rootGraph()->connectingEdges(*src, *dst);
57  for (auto e: edges) {
58  if (e->isRAW()) {
59  removedRawEdge = true;
60  runChild(new BFRemoveEdge(sched_, *src, *dst, *e), pre);
61  reg_ = e->data();
62  }
63  }
64  if (!removedRawEdge) {
65  undo();
66  return false;
67  }
68 
69  TTAProgram::Move& sm = src->move();
70  sourceIsRegToItselfCopy = sm.source().equals(sm.destination());
71 
72  // if we are bypassing from a register-to-register copy, we'll have to
73  // copy incoming raw edges also in rootgraph level to preserve inter-bb
74  // -dependencies.
75  for (int i = 0; i < ddg().rootGraphInDegree(*src); i++) {
76  DataDependenceEdge& edge = ddg().rootGraphInEdge(*src,i);
77 
78  // skip antidependencies due bypassed register.. these are no more
80  edge.data() == reg_) {
83  continue;
84  }
85  }
86 
87  // do not copy guard use edges - the user already ahs them.
88  // copying them leads to exponential increase in guard ege counts.
89  if (edge.guardUse()) {
90  continue;
91  }
92 
93  // copy other edges.
94  MoveNode& source = ddg().rootGraph()->tailNode(edge);
95  DataDependenceEdge* newEdge =
96  new DataDependenceEdge(edge, loopBypass);
97  runChild(new BFConnectNodes(sched_, source, *dst, newEdge), pre);
98  }
99 
100  if (src->isSourceVariable() || src->isSourceRA()) {
101  // if bypassing reg-to-reg this copy anti edges resulting from the
102  // read of the other register.
103  for (int i = 0; i < ddg().rootGraphOutDegree(*src); i++) {
104  DataDependenceEdge& edge = ddg().rootGraphOutEdge(*src,i);
108  !edge.tailPseudo()) {
109 
110  MoveNode& target = ddg().rootGraph()->headNode(edge);
111 
112  if (!(static_cast<DataDependenceGraph*>(ddg().rootGraph()))
113  ->exclusingGuards(*dst, target) &&
114  dst != &target) {
115 
116  DataDependenceEdge* newEdge =
117  new DataDependenceEdge(edge, loopBypass);
118  // TODO: loop here!
120  sched_, *dst, target, newEdge), pre);
121  }
122  }
123  }
124  }
125  }
126 
127 
128  if (dst != nullptr && ddg().rootGraph()->hasNode(*dst)) {
129  // fix WAR antidependencies to WaW
130  for (int i = 0; i < ddg().rootGraphOutDegree(*dst); i++) {
131  DataDependenceEdge& edge = ddg().rootGraphOutEdge(*dst,i);
134  edge.data() == reg_) {
135  // if stupid reg to itself copy, keep to in edges..
136  if (!sourceIsRegToItselfCopy) {
137  runChild(
138  new BFRemoveEdge(
139  sched_, *dst,
140  ddg().rootGraph()->headNode(edge), edge), pre);
141  i--; // don't skip one edge here!
142  }
143  }
144  }
145  }
146  return true;
147 }

References BoostGraph< GraphNode, GraphEdge >::connectingEdges(), DataDependenceEdge::data(), BFOptimization::ddg(), DataDependenceEdge::DEP_WAR, DataDependenceEdge::DEP_WAW, DataDependenceEdge::dependenceType(), TTAProgram::Move::destination(), DataDependenceEdge::EDGE_RA, DataDependenceEdge::EDGE_REGISTER, DataDependenceEdge::edgeReason(), TTAProgram::Terminal::equals(), DataDependenceEdge::guardUse(), BoostGraph< GraphNode, GraphEdge >::headNode(), MoveNode::isSourceRA(), MoveNode::isSourceVariable(), MoveNode::move(), reg_, BoostGraph< GraphNode, GraphEdge >::rootGraph(), BoostGraph< GraphNode, GraphEdge >::rootGraphInDegree(), BoostGraph< GraphNode, GraphEdge >::rootGraphInEdge(), BoostGraph< GraphNode, GraphEdge >::rootGraphOutDegree(), BoostGraph< GraphNode, GraphEdge >::rootGraphOutEdge(), Reversible::runChild(), BFOptimization::sched_, TTAProgram::Move::source(), BoostGraph< GraphNode, GraphEdge >::tailNode(), DataDependenceEdge::tailPseudo(), and Reversible::undo().

Referenced by operator()().

Here is the call graph for this function:

Member Data Documentation

◆ dst_

MoveNode& BFMergeAndKeepUser::dst_
private

Definition at line 61 of file BFMergeAndKeepUser.hh.

Referenced by operator()().

◆ duplicatedSrc_

bool BFMergeAndKeepUser::duplicatedSrc_
private

Definition at line 65 of file BFMergeAndKeepUser.hh.

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

◆ force_

bool BFMergeAndKeepUser::force_
private

Definition at line 62 of file BFMergeAndKeepUser.hh.

Referenced by operator()().

◆ reg_

TCEString BFMergeAndKeepUser::reg_
private

Definition at line 63 of file BFMergeAndKeepUser.hh.

Referenced by updateEdges().

◆ src_

MoveNode& BFMergeAndKeepUser::src_
private

Definition at line 60 of file BFMergeAndKeepUser.hh.

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

◆ updatePrologMove_

bool BFMergeAndKeepUser::updatePrologMove_
private

Definition at line 64 of file BFMergeAndKeepUser.hh.

Referenced by operator()().


The documentation for this class was generated from the following files:
DataDependenceGraph::isLoopBypass
bool isLoopBypass(MoveNode &sourceNode, MoveNode &userNode)
Definition: DataDependenceGraph.cc:1916
BoostGraph::tailNode
virtual Node & tailNode(const Edge &edge) const
BFOptimization::duplicator
MoveNodeDuplicator & duplicator() const
Definition: BFOptimization.cc:87
BoostGraph::headNode
virtual Node & headNode(const Edge &edge) const
DataDependenceEdge::isBackEdge
bool isBackEdge() const
Definition: DataDependenceEdge.hh:118
BoostGraph::rootGraphInDegree
virtual int rootGraphInDegree(const Node &node) const
BFOptimization::ii
unsigned int ii() const
Definition: BFOptimization.cc:85
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
DataDependenceEdge::isFalseDep
bool isFalseDep() const
Definition: DataDependenceEdge.hh:95
MoveNode
Definition: MoveNode.hh:65
BoostGraph::rootGraphOutEdge
virtual Edge & rootGraphOutEdge(const Node &node, const int index) const
BoostGraph::rootGraphOutDegree
virtual int rootGraphOutDegree(const Node &node) const
DataDependenceEdge::EDGE_REGISTER
@ EDGE_REGISTER
Definition: DataDependenceEdge.hh:53
DataDependenceEdge::dependenceType
DependenceType dependenceType() const
Definition: DataDependenceEdge.hh:88
DataDependenceEdge::tailPseudo
bool tailPseudo() const
Definition: DataDependenceEdge.hh:109
MoveNode::isSourceRA
bool isSourceRA() const
Definition: MoveNode.cc:210
BFOptimization::sched_
BF2Scheduler & sched_
Definition: BFOptimization.hh:103
BFConnectNodes
Definition: BFConnectNodes.hh:38
BFMergeAndKeepUser::reg_
TCEString reg_
Definition: BFMergeAndKeepUser.hh:63
MoveNodeDuplicator::duplicateMoveNode
std::pair< MoveNode *, bool > duplicateMoveNode(MoveNode &mn, bool addToDDG, bool ignoreSameBBBackEdges)
Definition: MoveNodeDuplicator.cc:106
BoostGraph::rootGraphInEdge
virtual Edge & rootGraphInEdge(const Node &node, const int index) const
BFMergeAndKeepUser::force_
bool force_
Definition: BFMergeAndKeepUser.hh:62
BFRemoveEdge
Definition: BFRemoveEdge.hh:40
BoostGraph::rootGraph
BoostGraph * rootGraph()
BoostGraph::inEdge
virtual Edge & inEdge(const Node &node, const int index) const
MoveNodeDuplicator::disposeMoveNode
void disposeMoveNode(MoveNode *newMN)
Definition: MoveNodeDuplicator.cc:53
Reversible::undo
virtual void undo()
Definition: Reversible.cc:69
BFOptimization::ddg
DataDependenceGraph & ddg()
Definition: BFOptimization.cc:70
TTAProgram::Move
Definition: Move.hh:55
BFMergeAndKeepUser::updateEdges
bool updateEdges(MoveNode *src, MoveNode *dst, bool loopBypass, bool pre)
Definition: BFMergeAndKeepUser.cc:47
BoostGraph::inDegree
virtual int inDegree(const Node &node) const
DataDependenceEdge::data
const TCEString data() const
Definition: DataDependenceEdge.hh:142
DataDependenceEdge::DEP_WAW
@ DEP_WAW
Definition: DataDependenceEdge.hh:49
BoostGraph::connectingEdges
EdgeSet connectingEdges(const Node &nTail, const Node &nHead) const
BFOptimization::BFOptimization
BFOptimization(BF2Scheduler &sched)
Definition: BFOptimization.hh:75
MoveNodeDuplicator::getMoveNode
MoveNode * getMoveNode(MoveNode &mn)
Definition: MoveNodeDuplicator.cc:85
MoveNode::isSourceVariable
bool isSourceVariable() const
Definition: MoveNode.cc:196
DataDependenceEdge::guardUse
bool guardUse() const
Definition: DataDependenceEdge.hh:100
MoveNode::move
TTAProgram::Move & move()
Reversible::runChild
bool runChild(std::stack< Reversible * > &children, Reversible *child)
Definition: Reversible.cc:109
Reversible::runPreChild
bool runPreChild(Reversible *preChild)
Definition: Reversible.cc:127
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
TTAProgram::Terminal::equals
virtual bool equals(const Terminal &other) const =0
DataDependenceEdge
Definition: DataDependenceEdge.hh:43
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
BFMergeAndKeepUser::dst_
MoveNode & dst_
Definition: BFMergeAndKeepUser.hh:61
DataDependenceEdge::DEP_WAR
@ DEP_WAR
Definition: DataDependenceEdge.hh:48
Reversible::runPostChild
bool runPostChild(Reversible *preChild)
Definition: Reversible.cc:139
DataDependenceEdge::EDGE_RA
@ EDGE_RA
Definition: DataDependenceEdge.hh:57
BFUpdateMoveOnBypass
Definition: BFUpdateMoveOnBypass.hh:41
BFMergeAndKeepUser::updatePrologMove_
bool updatePrologMove_
Definition: BFMergeAndKeepUser.hh:64
BFMergeAndKeepUser::duplicatedSrc_
bool duplicatedSrc_
Definition: BFMergeAndKeepUser.hh:65
BFMergeAndKeepUser::src_
MoveNode & src_
Definition: BFMergeAndKeepUser.hh:60
DataDependenceEdge::edgeReason
EdgeReason edgeReason() const
Definition: DataDependenceEdge.hh:91