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

#include <BasicBlockPass.hh>

Inheritance diagram for BasicBlockPass:
Inheritance graph
Collaboration diagram for BasicBlockPass:
Collaboration graph

Public Member Functions

 BasicBlockPass (InterPassData &data)
 
virtual ~BasicBlockPass ()
 
virtual void handleBasicBlock (TTAProgram::BasicBlock &basicBlock, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, BasicBlockNode *bbn=NULL)
 
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 shortDescription () const =0
 
virtual std::string longDescription () const
 

Static Public Member Functions

static void copyRMToBB (SimpleResourceManager &rm, TTAProgram::BasicBlock &bb, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, int lastCycle=-1)
 

Protected Member Functions

void ddgSnapshot (DataDependenceGraph *ddg, std::string &name, DataDependenceGraph::DumpFileFormat format, bool final)
 
virtual DataDependenceGraphcreateDDGFromBB (TTAProgram::BasicBlock &bb, const TTAMachine::Machine &mach)
 

Private Attributes

DataDependenceGraphBuilder ddgBuilder_
 

Detailed Description

Interface for scheduler passes that handle basic blocks.

Definition at line 60 of file BasicBlockPass.hh.

Constructor & Destructor Documentation

◆ BasicBlockPass()

BasicBlockPass::BasicBlockPass ( InterPassData data)

Constructor.

Definition at line 51 of file BasicBlockPass.cc.

51  :
52  SchedulerPass(data), ddgBuilder_(data) {
53 }

◆ ~BasicBlockPass()

BasicBlockPass::~BasicBlockPass ( )
virtual

Destructor.

Definition at line 58 of file BasicBlockPass.cc.

58  {
59 }

Member Function Documentation

◆ copyRMToBB()

void BasicBlockPass::copyRMToBB ( SimpleResourceManager rm,
TTAProgram::BasicBlock bb,
const TTAMachine::Machine targetMachine,
TTAProgram::InstructionReferenceManager irm,
int  lastCycle = -1 
)
static

Copies moves back from resourcemanager to basicblock, putting them to correct instructions based in their cycle, and adding the final delay slots.

Parameters
rmthe resourcemanager
bbthe basicblock
targetMachinemachine we are scheduling for.
irmIRM to keep book of the instruction references.
lastCyclethe last instruction cycle of BB to copy.
Returns
number of cycles/instructions copied.

Definition at line 213 of file BasicBlockPass.cc.

216  {
217 
218  // find the largest cycle any of a pipelines is still used
219  if (lastCycle == -1) {
220  const int rmLastCycle = rm.largestCycle();
221  lastCycle = rmLastCycle;
222  }
223 
224  // only first ins of bb may have incoming references
225  for (int i = 1; i < bb.instructionCount(); i++) {
226  if (irm.hasReference(bb.instructionAtIndex(i))) {
227  std::cerr << "non-first has ref:, index: " << i <<
228  " bb size: " << bb.instructionCount() << std::endl;
229  }
230  assert (!irm.hasReference(bb.instructionAtIndex(i)));
231  }
232 
233  TTAProgram::Instruction refHolder;
234  if (bb.instructionCount() && irm.hasReference(bb.instructionAtIndex(0))) {
235  irm.replace(bb.instructionAtIndex(0), refHolder);
236  }
237 
238  int moveCount = 0;
239 
240  // update the BB with the new instructions
241  bb.clear();
242 
243  int index = rm.smallestCycle();
244  if (rm.initiationInterval() > 0 && rm.initiationInterval() != INT_MAX) {
245  lastCycle = rm.initiationInterval() -1;
246  index = 0;
247  }
248 
249  for (; index <= lastCycle; ++index) {
250  TTAProgram::Instruction* newInstruction = rm.instruction(index);
251  if (newInstruction->hasControlFlowMove()) {
252  // Add delay slots of the last control flow instruction
253  // to loop end count. There can be multiple control
254  // flow instructions in a basic block in case thread yield
255  // emitter is enabled and it has inserted one or more
256  // calls to thread_yield().
257 
258  // only this this when not modulo-scheduling.
259  if (rm.initiationInterval() < 1 ||
260  rm.initiationInterval() == INT_MAX) {
261  lastCycle =
262  std::max(
263  lastCycle,
264  index + targetMachine.controlUnit()->delaySlots());
265 // assert(lastCycle >= rmLastCycle);
266  }
267  }
268 
269  moveCount += newInstruction->moveCount();
270  bb.add(newInstruction);
271 #if 0
273  << newInstruction->instructionTemplate().name() << ": "
274  << newInstruction->toString() << std::endl;
275 #endif
276  rm.loseInstructionOwnership(index);
277  }
278 
279  if (irm.hasReference(refHolder)) {
280  irm.replace(refHolder, bb.firstInstruction());
281  }
282 
283  const int instructionCount = lastCycle + 1 - rm.smallestCycle();
284  if (Application::verboseLevel() > 1 && bb.isInInnerLoop()) {
285  const int busCount = targetMachine.busNavigator().count();
286  const int moveSlotCount = busCount * instructionCount;
288  << "BB -- inner loop with trip count: " << bb.tripCount()
289  << std::endl
290  << "BB -- instruction count: " << instructionCount << std::endl;
292  << "BB -- move slots used: " << moveCount << " of "
293  << moveSlotCount << " (" << (float)moveCount * 100 / moveSlotCount
294  << "%)" << std::endl;
295  }
296 
297  return;
298 }

References TTAProgram::CodeSnippet::add(), assert, TTAMachine::Machine::busNavigator(), TTAProgram::BasicBlock::clear(), TTAMachine::Machine::controlUnit(), TTAMachine::Machine::Navigator< ComponentType >::count(), TTAMachine::ControlUnit::delaySlots(), TTAProgram::CodeSnippet::firstInstruction(), TTAProgram::Instruction::hasControlFlowMove(), TTAProgram::InstructionReferenceManager::hasReference(), SimpleResourceManager::initiationInterval(), SimpleResourceManager::instruction(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Instruction::instructionTemplate(), TTAProgram::BasicBlock::isInInnerLoop(), SimpleResourceManager::largestCycle(), Application::logStream(), SimpleResourceManager::loseInstructionOwnership(), TTAProgram::Instruction::moveCount(), TTAMachine::Component::name(), TTAProgram::InstructionReferenceManager::replace(), SimpleResourceManager::smallestCycle(), TTAProgram::Instruction::toString(), TTAProgram::BasicBlock::tripCount(), and Application::verboseLevel().

Referenced by LoopPrologAndEpilogBuilder::addPrologFromRM(), executeDDGPass(), BBSchedulerController::executeDDGPass(), and SequentialScheduler::handleBasicBlock().

Here is the call graph for this function:

◆ createDDGFromBB()

DataDependenceGraph * BasicBlockPass::createDDGFromBB ( TTAProgram::BasicBlock bb,
const TTAMachine::Machine mach 
)
protectedvirtual

Reimplemented in BBSchedulerController.

Definition at line 302 of file BasicBlockPass.cc.

303  {
304  return ddgBuilder().build(
305  bb, DataDependenceGraph::INTRA_BB_ANTIDEPS, mach, "unknown_bb");
306 }

References DataDependenceGraphBuilder::build(), ddgBuilder(), and DataDependenceGraph::INTRA_BB_ANTIDEPS.

Referenced by executeDDGPass().

Here is the call graph for this function:

◆ ddgBuilder()

virtual DataDependenceGraphBuilder& BasicBlockPass::ddgBuilder ( )
inlinevirtual

◆ ddgSnapshot()

void BasicBlockPass::ddgSnapshot ( DataDependenceGraph ddg,
std::string &  name,
DataDependenceGraph::DumpFileFormat  format,
bool  final 
)
protected

Prints DDG to a dot file before and after scheudling

Parameters
ddgto print
nameoperation name for ddg
finalspecify if ddg is after scheduling
formatformat of the file
Returns
number of cycles/instructions copied.

Definition at line 172 of file BasicBlockPass.cc.

176  {
177  static int bbCounter = 0;
178 
179  if (final) {
180  if (format == DataDependenceGraph::DUMP_DOT) {
181  ddg->writeToDotFile(
182  (boost::format("bb_%.4d_1_after_%2%.dot") % bbCounter % name).str());
183  } else {
184  ddg->writeToXMLFile(
185  (boost::format("bb_%.4d_1_after_%2%.xml") % bbCounter % name).str());
186  }
187  ++bbCounter;
188  } else {
189  if (format == DataDependenceGraph::DUMP_DOT) {
190  ddg->writeToDotFile(
191  (boost::format("bb_%.4d_0_before_%2%.dot") % bbCounter % name).str());
192  } else {
193  ddg->writeToXMLFile(
194  (boost::format("bb_%.4d_0_before_%2%.xml") % bbCounter % name).str());
195  }
196  Application::logStream() << "\nBB " << bbCounter << std::endl;
197  }
198 }

References DataDependenceGraph::DUMP_DOT, Application::logStream(), GraphBase< GraphNode, GraphEdge >::writeToDotFile(), and DataDependenceGraph::writeToXMLFile().

Referenced by executeDDGPass(), and BBSchedulerController::executeDDGPass().

Here is the call graph for this function:

◆ executeDDGPass()

void BasicBlockPass::executeDDGPass ( TTAProgram::BasicBlock bb,
const TTAMachine::Machine targetMachine,
TTAProgram::InstructionReferenceManager irm,
std::vector< DDGPass * >  ddgPasses,
BasicBlockNode bbn = NULL 
)
virtual

Creates a DDG from the given basic block and executes a DDG pass for that.

Reimplemented in BBSchedulerController.

Definition at line 101 of file BasicBlockPass.cc.

104  {
105  std::cerr << "Calling bbpass::executedgpass." << std::endl;
106 
107  DataDependenceGraph* ddg = createDDGFromBB(bb, targetMachine);
108 
109  // Used for live info dumping.
110  static int bbNumber = 0;
111 
112 #ifdef DDG_SNAPSHOTS
113  std::string name = "scheduling";
114  ddgSnapshot(ddg, name, false);
115 #endif
116 
118  ddgPasses[0]->handleDDG(*ddg, *rm, targetMachine);
119 
120 #ifdef DDG_SNAPSHOTS
121  std::string name = "scheduling";
122  ddgSnapshot(ddg, name, true);
123 #endif
124 
125  copyRMToBB(*rm, bb, targetMachine, irm);
126 
127  // Print the live range count for each cycle for the sched_yield emitting
128  // paper.
129  if (Application::verboseLevel() > 1 ||
130  getenv("TCE_DUMP_LIVE_INFO") != NULL) {
131  for (int index = 0; index < bb.instructionCount(); ++index) {
132  if (bb.liveRangeData_ != NULL) {
134  << "liveinfo:" << bbNumber << ":" << index + rm->smallestCycle() << ":"
136  rm->smallestCycle()+index, targetMachine.controlUnit()->delaySlots(), *ddg).
137  size()
138  << std::endl;
139  }
140  }
141  bbNumber++;
142  }
143 
144  delete ddg;
146 }

References TTAMachine::Machine::controlUnit(), copyRMToBB(), createDDGFromBB(), SimpleResourceManager::createRM(), ddgSnapshot(), TTAMachine::ControlUnit::delaySlots(), SimpleResourceManager::disposeRM(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::BasicBlock::liveRangeData_, Application::logStream(), LiveRangeData::registersAlive(), SimpleResourceManager::smallestCycle(), and Application::verboseLevel().

Referenced by handleBasicBlock().

Here is the call graph for this function:

◆ executeLoopPass()

bool BasicBlockPass::executeLoopPass ( TTAProgram::BasicBlock bb,
const TTAMachine::Machine targetMachine,
TTAProgram::InstructionReferenceManager irm,
std::vector< DDGPass * >  ddgPasses,
BasicBlockNode bbn = NULL 
)
virtual

Creates a DDG from the given basic block and executes a Loop pass for that.

Definition at line 152 of file BasicBlockPass.cc.

155  {
156  // not implemented
157  assert(0 && "should not be here?");
158  return false;
159 }

References assert.

Referenced by BBSchedulerController::handleBasicBlock().

◆ handleBasicBlock()

void BasicBlockPass::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 in BBSchedulerController, SequentialScheduler, and PostpassOperandSharer.

Definition at line 79 of file BasicBlockPass.cc.

82  {
83  if (basicBlock.instructionCount() == 0)
84  return;
85 
86  DDGPass* ddgPass = dynamic_cast<DDGPass*>(this);
87  std::vector<DDGPass*> ddgPasses;
88  ddgPasses.push_back(ddgPass);
89  if (ddgPass != NULL) {
90  executeDDGPass(basicBlock, targetMachine, irm, ddgPasses, bbn);
91  } else {
92  abortWithError("basic block pass is not also a ddg pass so you "
93  "must overload handleBasicBlock method!");
94  }
95 }

References abortWithError, executeDDGPass(), and TTAProgram::CodeSnippet::instructionCount().

Referenced by ControlFlowGraphPass::executeBasicBlockPass().

Here is the call graph for this function:

Member Data Documentation

◆ ddgBuilder_

DataDependenceGraphBuilder BasicBlockPass::ddgBuilder_
private

Definition at line 100 of file BasicBlockPass.hh.

Referenced by ddgBuilder().


The documentation for this class was generated from the following files:
TTAProgram::CodeSnippet::firstInstruction
virtual Instruction & firstInstruction() const
Definition: CodeSnippet.cc:216
TTAMachine::Component::name
virtual TCEString name() const
Definition: MachinePart.cc:125
SimpleResourceManager::largestCycle
virtual int largestCycle() const override
Definition: SimpleResourceManager.cc:463
BasicBlockPass::ddgBuilder_
DataDependenceGraphBuilder ddgBuilder_
Definition: BasicBlockPass.hh:100
TTAProgram::Instruction
Definition: Instruction.hh:57
SimpleResourceManager::smallestCycle
virtual int smallestCycle() const override
Definition: SimpleResourceManager.cc:480
TTAProgram::Instruction::toString
std::string toString() const
Definition: Instruction.cc:576
BasicBlockPass::ddgBuilder
virtual DataDependenceGraphBuilder & ddgBuilder()
Definition: BasicBlockPass.hh:86
Application::verboseLevel
static int verboseLevel()
Definition: Application.hh:176
Application::logStream
static std::ostream & logStream()
Definition: Application.cc:155
SchedulerPass::SchedulerPass
SchedulerPass(InterPassData &data)
Definition: SchedulerPass.cc:40
TTAMachine::Machine::Navigator::count
int count() const
SimpleResourceManager::initiationInterval
virtual unsigned initiationInterval() const
Definition: SimpleResourceManager.hh:135
LiveRangeData::registersAlive
std::set< TCEString > registersAlive(int cycle, int delaySlots, class DataDependenceGraph &ddg)
Definition: LiveRangeData.cc:127
assert
#define assert(condition)
Definition: Application.hh:86
DataDependenceGraph::writeToXMLFile
void writeToXMLFile(std::string fileName) const
Definition: DataDependenceGraph.cc:1747
TTAMachine::Machine::controlUnit
virtual ControlUnit * controlUnit() const
Definition: Machine.cc:345
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
TTAProgram::BasicBlock::liveRangeData_
LiveRangeData * liveRangeData_
Definition: BasicBlock.hh:111
TTAProgram::CodeSnippet::instructionCount
virtual int instructionCount() const
Definition: CodeSnippet.cc:205
BasicBlockPass::executeDDGPass
virtual void executeDDGPass(TTAProgram::BasicBlock &bb, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, std::vector< DDGPass * > ddgPasses, BasicBlockNode *bbn=NULL)
Definition: BasicBlockPass.cc:101
TTAProgram::CodeSnippet::add
virtual void add(Instruction *ins)
Definition: CodeSnippet.cc:432
DataDependenceGraph::INTRA_BB_ANTIDEPS
@ INTRA_BB_ANTIDEPS
Definition: DataDependenceGraph.hh:80
TTAProgram::InstructionReferenceManager::hasReference
bool hasReference(Instruction &ins) const
Definition: InstructionReferenceManager.cc:143
TTAProgram::InstructionReferenceManager::replace
void replace(Instruction &insA, Instruction &insB)
Definition: InstructionReferenceManager.cc:96
SimpleResourceManager::disposeRM
static void disposeRM(SimpleResourceManager *rm, bool allowReuse=true)
Definition: SimpleResourceManager.cc:92
DataDependenceGraph::DUMP_DOT
@ DUMP_DOT
Definition: DataDependenceGraph.hh:86
TTAMachine::ControlUnit::delaySlots
int delaySlots() const
BasicBlockPass::copyRMToBB
static void copyRMToBB(SimpleResourceManager &rm, TTAProgram::BasicBlock &bb, const TTAMachine::Machine &targetMachine, TTAProgram::InstructionReferenceManager &irm, int lastCycle=-1)
Definition: BasicBlockPass.cc:213
SimpleResourceManager::createRM
static SimpleResourceManager * createRM(const TTAMachine::Machine &machine, unsigned int ii=0)
Definition: SimpleResourceManager.cc:73
GraphBase::writeToDotFile
virtual void writeToDotFile(const TCEString &fileName) const
TTAProgram::Instruction::instructionTemplate
const TTAMachine::InstructionTemplate & instructionTemplate() const
Definition: Instruction.cc:523
DDGPass
Definition: DDGPass.hh:51
TTAProgram::BasicBlock::tripCount
unsigned tripCount() const
in case the BB is inside a loop and trip count is known, returns it, otherwise returns 0
Definition: BasicBlock.hh:108
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
TTAMachine::Machine::busNavigator
virtual BusNavigator busNavigator() const
Definition: Machine.cc:356
DataDependenceGraphBuilder::build
virtual DataDependenceGraph * build(ControlFlowGraph &cGraph, DataDependenceGraph::AntidependenceLevel antidependenceLevel, const TTAMachine::Machine &mach, const UniversalMachine *um=NULL, bool createMemAndFUDeps=true, bool createDeathInformation=true, llvm::AliasAnalysis *AA=NULL)
Definition: DataDependenceGraphBuilder.cc:2120
SimpleResourceManager::loseInstructionOwnership
virtual void loseInstructionOwnership(int cycle)
Definition: SimpleResourceManager.cc:498
TTAProgram::CodeSnippet::instructionAtIndex
virtual Instruction & instructionAtIndex(int index) const
Definition: CodeSnippet.cc:285
SimpleResourceManager
Definition: SimpleResourceManager.hh:58
TTAProgram::Instruction::hasControlFlowMove
bool hasControlFlowMove() const
Definition: Instruction.cc:471
BasicBlockPass::ddgSnapshot
void ddgSnapshot(DataDependenceGraph *ddg, std::string &name, DataDependenceGraph::DumpFileFormat format, bool final)
Definition: BasicBlockPass.cc:172
TTAProgram::BasicBlock::isInInnerLoop
bool isInInnerLoop() const
returns true in case the BB is known to be inside an inner loop
Definition: BasicBlock.hh:103
TTAProgram::BasicBlock::clear
virtual void clear()
Definition: BasicBlock.cc:152
BasicBlockPass::createDDGFromBB
virtual DataDependenceGraph * createDDGFromBB(TTAProgram::BasicBlock &bb, const TTAMachine::Machine &mach)
Definition: BasicBlockPass.cc:302
TTAProgram::Instruction::moveCount
int moveCount() const
Definition: Instruction.cc:176
SimpleResourceManager::instruction
virtual TTAProgram::Instruction * instruction(int cycle) const override
Definition: SimpleResourceManager.cc:442