OpenASIP 2.2
Loading...
Searching...
No Matches
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) {}
TTAProgram::InstructionReferenceManager * 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}
bool tryRemoveOperandWrite(TTAProgram::BasicBlock &basicBlock, int insIndex, TTAProgram::Move &move)
static unsigned int moveCount_
virtual int instructionCount() const
virtual Instruction & instructionAtIndex(int index) const
Move & move(int i) const
void removeMove(Move &move)

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}
static unsigned int operandCount_
static unsigned int registerReads_
static unsigned int triggerCannotRemove_
static unsigned int removedOperands_

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
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}
int width() const
Definition Bus.cc:149
virtual bool isOpposite(const Guard &guard) const =0
virtual bool isEqual(const Guard &guard) const =0
const RegisterFile * registerFile() const
int skippedFirstInstructions() const
Definition BasicBlock.cc:88
const TTAMachine::Guard & guard() const
Definition MoveGuard.cc:86
MoveGuard & guard() const
Definition Move.cc:345
bool isUnconditional() const
Definition Move.cc:154
Terminal & source() const
Definition Move.cc:302
int guardLatency() const
Definition Move.cc:503
Terminal & destination() const
Definition Move.cc:323
const TTAMachine::Bus & bus() const
Definition Move.cc:373
virtual bool isTriggering() const
Definition Terminal.cc:298
virtual int index() const
Definition Terminal.cc:274
virtual bool isOpcodeSetting() const
Definition Terminal.cc:285
virtual bool equals(const Terminal &other) const =0
virtual bool isGPR() const
Definition Terminal.cc:107
virtual bool isImmediateRegister() const
Definition Terminal.cc:97
virtual const TTAMachine::Port & port() const
Definition Terminal.cc:378
virtual const TTAMachine::RegisterFile & registerFile() const
Definition Terminal.cc:225
virtual bool isFUPort() const
Definition Terminal.cc:118

References TTAProgram::Move::bus(), TTAProgram::Move::destination(), TTAProgram::Terminal::equals(), TTAProgram::Move::guard(), TTAProgram::MoveGuard::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(), TTAMachine::RegisterGuard::registerFile(), TTAProgram::Terminal::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: