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

#include <PostpassOperandSharer.hh>

Inheritance diagram for PostpassOperandSharer:
Inheritance graph
Collaboration diagram for PostpassOperandSharer:
Collaboration graph

Public Member Functions

 PostpassOperandSharer (InterPassData &ipd, TTAProgram::InstructionReferenceManager &irm)
 
virtual ~PostpassOperandSharer ()
 
virtual void handleBasicBlock (TTAProgram::BasicBlock &basicBlock, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, BasicBlockNode *bbn=NULL)
 
bool tryRemoveOperandWrite (TTAProgram::BasicBlock &basicBlock, int insIndex, TTAProgram::Move &move)
 
virtual std::string shortDescription () const
 
- Public Member Functions inherited from BasicBlockPass
 BasicBlockPass (InterPassData &data)
 
virtual ~BasicBlockPass ()
 
virtual void executeDDGPass (TTAProgram::BasicBlock &bb, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, std::vector< DDGPass * > ddgPasses, BasicBlockNode *bbn=NULL)
 
virtual bool executeLoopPass (TTAProgram::BasicBlock &bb, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, std::vector< DDGPass * > ddgPasses, BasicBlockNode *bbn=NULL)
 
virtual DataDependenceGraphBuilderddgBuilder ()
 
- Public Member Functions inherited from SchedulerPass
 SchedulerPass (InterPassData &data)
 
virtual ~SchedulerPass ()
 
InterPassDatainterPassData ()
 
virtual std::string longDescription () const
 
- Public Member Functions inherited from ControlFlowGraphPass
 ControlFlowGraphPass (InterPassData &data)
 
virtual ~ControlFlowGraphPass ()
 
virtual void handleControlFlowGraph (ControlFlowGraph &cfg, const TTAMachine::Machine &targetMachine)
 
void executeBasicBlockPass (ControlFlowGraph &cfg, const TTAMachine::Machine &targetMachine, BasicBlockPass &bbPass)
 

Static Public Member Functions

static void printStats ()
 
- Static Public Member Functions inherited from BasicBlockPass
static void copyRMToBB (SimpleResourceManager &rm, TTAProgram::BasicBlock &bb, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, int lastCycle=-1)
 

Private Attributes

TTAProgram::InstructionReferenceManagerirm_
 

Static Private Attributes

static unsigned int moveCount_ = 0
 
static unsigned int operandCount_ = 0
 
static unsigned int removedOperands_ = 0
 
static unsigned int registerReads_ = 0
 
static unsigned int triggerCannotRemove_ = 0
 

Additional Inherited Members

- Protected Member Functions inherited from BasicBlockPass
void ddgSnapshot (DataDependenceGraph *ddg, std::string &name, DataDependenceGraph::DumpFileFormat format, bool final)
 
virtual DataDependenceGraphcreateDDGFromBB (TTAProgram::BasicBlock &bb, const TTAMachine::Machine &mach)
 

Detailed Description

Definition at line 47 of file PostpassOperandSharer.hh.

Constructor & Destructor Documentation

◆ PostpassOperandSharer()

PostpassOperandSharer::PostpassOperandSharer ( InterPassData ipd,
TTAProgram::InstructionReferenceManager irm 
)
inline

Definition at line 51 of file PostpassOperandSharer.hh.

53  :
54  BasicBlockPass(ipd), ControlFlowGraphPass(ipd), irm_(&irm) {}

◆ ~PostpassOperandSharer()

PostpassOperandSharer::~PostpassOperandSharer ( )
virtual

Definition at line 223 of file PostpassOperandSharer.cc.

223 {}

Member Function Documentation

◆ handleBasicBlock()

void PostpassOperandSharer::handleBasicBlock ( TTAProgram::BasicBlock basicBlock,
const TTAMachine::Machine targetMachine,
TTAProgram::InstructionReferenceManager irm,
BasicBlockNode bbn = NULL 
)
virtual

Handles a single basic block.

Modifies the given basic block, so if the old one is to be preserved, client should copy the original. Does not restore the BB even though handling was not successful.

Todo:
: Why both BB and BBN as arguments? If BBN is needed then I think BB argument can be replaced with a BBN one. We always should have it anyways.
Parameters
basicBlockThe basic block to handle.
machineThe target machine if any. (NullMachine::instance() if target machine is irrelevant).
Exceptions
Incase handling is unsuccesful for any reason (basicBlock might still get modified).

Reimplemented from BasicBlockPass.

Definition at line 62 of file PostpassOperandSharer.cc.

64  {
65  for (int i = basicBlock.instructionCount()-1; i >= 0; i--) {
66  Instruction& ins = basicBlock.instructionAtIndex(i);
67  for (int j = 0; j < ins.moveCount(); j++) {
68  Move& move = ins.move(j);
69  moveCount_++;
70  if (tryRemoveOperandWrite(basicBlock, i, move)) {
71  ins.removeMove(move);
72  // TODO: make sure there is no movenode to this.
73 // delete &move;
74  j--;
75  }
76  }
77  }
78 }

References TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), moveCount_, TTAProgram::Instruction::removeMove(), and tryRemoveOperandWrite().

Here is the call graph for this function:

◆ printStats()

void PostpassOperandSharer::printStats ( )
static

Definition at line 225 of file PostpassOperandSharer.cc.

225  {
226  std::cerr << "PostpassOperandSharer statistics: " << std::endl
227  << "\tTotal moves: " << moveCount_ << std::endl
228  << "\tTotal reg reads: " << registerReads_ << std::endl
229  << "\tTotal operands: "<<operandCount_
230  << std::endl
231  << "\tRemoved operands: " << removedOperands_ << std::endl
232  << "\tCannot share trigger count: " << triggerCannotRemove_
233  << std::endl;
234 
235 }

References moveCount_, operandCount_, registerReads_, removedOperands_, and triggerCannotRemove_.

◆ shortDescription()

virtual std::string PostpassOperandSharer::shortDescription ( ) const
inlinevirtual

A short description of the pass, usually the optimization name, such as "basic block scheduler".

Returns
The description as a string.

Implements SchedulerPass.

Definition at line 71 of file PostpassOperandSharer.hh.

71  {
72  return "Post-pass that reduced redundant operand writes";
73  }

◆ tryRemoveOperandWrite()

bool PostpassOperandSharer::tryRemoveOperandWrite ( TTAProgram::BasicBlock basicBlock,
int  insIndex,
TTAProgram::Move move 
)

Definition at line 83 of file PostpassOperandSharer.cc.

84  {
85 
86  bool guardOK = false;
87  Terminal& dest = move.destination();
88  Terminal& src = move.source();
89 
90  if (src.isGPR()) {
92  }
93 
94 #ifdef GET_BETTER_STATISTICS
95  if (!dest.isFUPort())
96  {
97  return false;
98  }
99 #else
100 
101  if (!dest.isFUPort() ||
102  dest.isTriggering() ||
103  dest.isOpcodeSetting()) {
104  return false;
105  }
106 #endif
107 
108  operandCount_++;
109  if (src.isFUPort()) {
110  return false;
111  }
112 
113  if (src.isImmediateRegister()) {
114  return false;
115  }
116 
117  const TTAMachine::RegisterFile* guardRF = NULL;
118  int guardIndex = -1;
119  if (!move.isUnconditional()) {
120  const TTAMachine::Guard& guard = move.guard().guard();
121  const RegisterGuard* rg = dynamic_cast<const TTAMachine::RegisterGuard*>(&guard);
122  if (rg) {
123  guardRF = rg->registerFile();
124  guardIndex = rg->registerIndex();
125  }
126  }
127 
128  int srcIndex = -1;
129  const TTAMachine::RegisterFile* srcRF = NULL;
130  if (src.isGPR()) {
131  srcIndex = src.index();
132  srcRF = &src.registerFile();
133  }
134 
135  int glat = move.guardLatency();
136  bool lastDueJump = false;
137 
138  for (int i = insIndex -1; i >= basicBlock.skippedFirstInstructions() && !lastDueJump; i--) {
139 
140  // first check guard writes..
141  // if guard has longer latency than 1 , this has to go to previous
142  // cycles.
143  int k = i+1 - glat;
144  if (k>= 0) {
145  Instruction& gIns = basicBlock.instructionAtIndex(k);
146 
147  // check that does not overwrite the source
148  for (int j = 0; j < gIns.moveCount(); j++) {
149  Move& gMove = gIns.move(j);
150  Terminal& gDst = gMove.destination();
151  if (gDst.isGPR()) {
152  int pdIndex = gDst.index();
153  const RegisterFile* pdRF = &gDst.registerFile();
154  if (guardIndex == pdIndex && guardRF == pdRF) {
155  guardOK = false;
156  }
157  }
158  }
159  }
160 
161  Instruction& prevIns = basicBlock.instructionAtIndex(i);
162  if (irm_->hasReference(prevIns)) {
163  lastDueJump = true;
164  }
165  // check that does not overwrite the source
166  for (int j = 0; j < prevIns.moveCount(); j++) {
167  Move& prevMove = prevIns.move(j);
168  Terminal& prevDst = prevMove.destination();
169 
170  if (prevDst.isGPR()) {
171  int pdIndex = prevDst.index();
172  const RegisterFile* pdRF = &prevDst.registerFile();
173  if ((srcIndex == pdIndex && srcRF == pdRF) &&
174  (!guardOK || prevMove.isUnconditional() ||
175  move.isUnconditional() ||
176  !prevMove.guard().guard().isOpposite(
177  move.guard().guard()))) {
178  return false;
179  }
180  }
181  }
182 
183  // check if writes the same operand
184  for (int j = 0; j < prevIns.moveCount(); j++) {
185  Move& prevMove = prevIns.move(j);
186  Terminal& prevDest = prevMove.destination();
187 
188  // write to same port..
189  if (&prevDest.port() == &dest.port()) {
190  // Check if previous move used narrower bus and
191  // potentially cut upper bits of the transported value.
192  // This is possible is the value was previously used in
193  // operation which used only the lower bits of the value
194  // (see BusResource::canAssign()).
195  if (move.source().equals(prevMove.source())
196  && move.bus().width() <= prevMove.bus().width()) {
197 
198  // TODO: what if guard is conditional, ok or not?
199  if (!prevMove.isUnconditional() &&
200  (move.isUnconditional() ||
201  (!guardOK || !prevMove.guard().guard().isEqual(
202  move.guard().guard())))) {
203  continue;
204  }
205 
206  if (prevDest.isTriggering() ||
207  prevDest.isOpcodeSetting()) {
209  return false;
210  }
211 
213  return true;
214  } else {
215  return false;
216  }
217  }
218  }
219  }
220  return false;
221 }

References TTAProgram::Move::bus(), TTAProgram::Move::destination(), TTAProgram::Terminal::equals(), TTAProgram::MoveGuard::guard(), TTAProgram::Move::guard(), TTAProgram::Move::guardLatency(), TTAProgram::InstructionReferenceManager::hasReference(), TTAProgram::Terminal::index(), TTAProgram::CodeSnippet::instructionAtIndex(), irm_, TTAMachine::Guard::isEqual(), TTAProgram::Terminal::isFUPort(), TTAProgram::Terminal::isGPR(), TTAProgram::Terminal::isImmediateRegister(), TTAProgram::Terminal::isOpcodeSetting(), TTAMachine::Guard::isOpposite(), TTAProgram::Terminal::isTriggering(), TTAProgram::Move::isUnconditional(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), operandCount_, TTAProgram::Terminal::port(), TTAProgram::Terminal::registerFile(), TTAMachine::RegisterGuard::registerFile(), TTAMachine::RegisterGuard::registerIndex(), registerReads_, removedOperands_, TTAProgram::BasicBlock::skippedFirstInstructions(), TTAProgram::Move::source(), triggerCannotRemove_, and TTAMachine::Bus::width().

Referenced by handleBasicBlock().

Here is the call graph for this function:

Member Data Documentation

◆ irm_

TTAProgram::InstructionReferenceManager* PostpassOperandSharer::irm_
private

Definition at line 75 of file PostpassOperandSharer.hh.

Referenced by tryRemoveOperandWrite().

◆ moveCount_

unsigned int PostpassOperandSharer::moveCount_ = 0
staticprivate

Definition at line 76 of file PostpassOperandSharer.hh.

Referenced by handleBasicBlock(), and printStats().

◆ operandCount_

unsigned int PostpassOperandSharer::operandCount_ = 0
staticprivate

Definition at line 77 of file PostpassOperandSharer.hh.

Referenced by printStats(), and tryRemoveOperandWrite().

◆ registerReads_

unsigned int PostpassOperandSharer::registerReads_ = 0
staticprivate

Definition at line 79 of file PostpassOperandSharer.hh.

Referenced by printStats(), and tryRemoveOperandWrite().

◆ removedOperands_

unsigned int PostpassOperandSharer::removedOperands_ = 0
staticprivate

Definition at line 78 of file PostpassOperandSharer.hh.

Referenced by printStats(), and tryRemoveOperandWrite().

◆ triggerCannotRemove_

unsigned int PostpassOperandSharer::triggerCannotRemove_ = 0
staticprivate

Definition at line 80 of file PostpassOperandSharer.hh.

Referenced by printStats(), and tryRemoveOperandWrite().


The documentation for this class was generated from the following files:
TTAMachine::Guard
Definition: Guard.hh:55
TTAProgram::Terminal::isFUPort
virtual bool isFUPort() const
Definition: Terminal.cc:118
TTAProgram::Instruction::removeMove
void removeMove(Move &move)
Definition: Instruction.cc:536
TTAProgram::Terminal::isTriggering
virtual bool isTriggering() const
Definition: Terminal.cc:298
TTAProgram::Instruction::move
Move & move(int i) const
Definition: Instruction.cc:193
TTAProgram::Terminal::index
virtual int index() const
Definition: Terminal.cc:274
TTAProgram::Move::guardLatency
int guardLatency() const
Definition: Move.cc:503
TTAMachine::RegisterGuard::registerIndex
int registerIndex() const
PostpassOperandSharer::registerReads_
static unsigned int registerReads_
Definition: PostpassOperandSharer.hh:79
TTAProgram::Terminal::registerFile
virtual const TTAMachine::RegisterFile & registerFile() const
Definition: Terminal.cc:225
TTAMachine::Bus::width
int width() const
Definition: Bus.cc:149
TTAProgram::Instruction
Definition: Instruction.hh:57
TTAProgram::Move::isUnconditional
bool isUnconditional() const
Definition: Move.cc:154
TTAMachine::Guard::isEqual
virtual bool isEqual(const Guard &guard) const =0
TTAProgram::Move::destination
Terminal & destination() const
Definition: Move.cc:323
TTAProgram::Move::bus
const TTAMachine::Bus & bus() const
Definition: Move.cc:373
ControlFlowGraphPass::ControlFlowGraphPass
ControlFlowGraphPass(InterPassData &data)
Definition: ControlFlowGraphPass.cc:42
PostpassOperandSharer::operandCount_
static unsigned int operandCount_
Definition: PostpassOperandSharer.hh:77
TTAProgram::Terminal::isImmediateRegister
virtual bool isImmediateRegister() const
Definition: Terminal.cc:97
PostpassOperandSharer::moveCount_
static unsigned int moveCount_
Definition: PostpassOperandSharer.hh:76
PostpassOperandSharer::triggerCannotRemove_
static unsigned int triggerCannotRemove_
Definition: PostpassOperandSharer.hh:80
TTAProgram::BasicBlock::skippedFirstInstructions
int skippedFirstInstructions() const
Definition: BasicBlock.cc:88
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
TTAMachine::RegisterGuard
Definition: Guard.hh:137
TTAProgram::InstructionReferenceManager::hasReference
bool hasReference(Instruction &ins) const
Definition: InstructionReferenceManager.cc:143
TTAProgram::Move::guard
MoveGuard & guard() const
Definition: Move.cc:345
TTAProgram::Terminal::isGPR
virtual bool isGPR() const
Definition: Terminal.cc:107
BasicBlockPass::BasicBlockPass
BasicBlockPass(InterPassData &data)
Definition: BasicBlockPass.cc:51
TTAProgram::Move
Definition: Move.hh:55
TTAProgram::Terminal::isOpcodeSetting
virtual bool isOpcodeSetting() const
Definition: Terminal.cc:285
TTAMachine::Guard::isOpposite
virtual bool isOpposite(const Guard &guard) const =0
TTAProgram::Terminal
Definition: Terminal.hh:60
TTAProgram::Terminal::equals
virtual bool equals(const Terminal &other) const =0
TTAProgram::CodeSnippet::instructionAtIndex
virtual Instruction & instructionAtIndex(int index) const
Definition: CodeSnippet.cc:285
TTAProgram::Move::source
Terminal & source() const
Definition: Move.cc:302
PostpassOperandSharer::irm_
TTAProgram::InstructionReferenceManager * irm_
Definition: PostpassOperandSharer.hh:75
TTAProgram::Terminal::port
virtual const TTAMachine::Port & port() const
Definition: Terminal.cc:378
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
TTAProgram::MoveGuard::guard
const TTAMachine::Guard & guard() const
Definition: MoveGuard.cc:86
PostpassOperandSharer::removedOperands_
static unsigned int removedOperands_
Definition: PostpassOperandSharer.hh:78
PostpassOperandSharer::tryRemoveOperandWrite
bool tryRemoveOperandWrite(TTAProgram::BasicBlock &basicBlock, int insIndex, TTAProgram::Move &move)
Definition: PostpassOperandSharer.cc:83
TTAMachine::RegisterGuard::registerFile
const RegisterFile * registerFile() const
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176