OpenASIP  2.0
SimpleIfConverter.hh
Go to the documentation of this file.
1 /**
2  * @file SimpleIfConverter.hh
3  *
4  * Declaration of simple if converter optimizer class
5  *
6  * @author Heikki Kultala 2008 (heikki.kultala@tut.fi)
7  * @note rating: red
8  */
9 
10 #ifndef TTA_SIMPLE_IF_CONVERTER_HH
11 #define TTA_SIMPLE_IF_CONVERTER_HH
12 
13 #include "ControlFlowGraphPass.hh"
14 #include "ProcedurePass.hh"
15 #include "ProgramPass.hh"
16 #include "ProgramOperation.hh"
17 
18 class ControlFlowGraph;
19 class BasicBlockNode;
20 class BasicBlock;
21 class ControlFlowEdge;
23 class MoveNode;
24 
25 namespace TTAMachine {
26  class RegisterFile;
27 }
28 
29 namespace TTAProgram {
30  class Instruction;
31  class MoveGuard;
32  class Move;
33  class InstructionReferenceManager;
34  class CodeGenerator;
35  class CodeSnippet;
36  class BasicBlock;
37  class TerminalFUPort;
38 }
39 
41  ProgramPass {
42 
43 public:
45  InterPassData& data, const TTAMachine::Machine& targetMachine);
46 
47  virtual void handleControlFlowGraph(
48  ControlFlowGraph& cfg, const TTAMachine::Machine& targetMachine);
49 
50  virtual void handleProcedure(
51  TTAProgram::Procedure& procedure,
52  const TTAMachine::Machine& targetMachine);
53 
54  virtual void handleProgram(
55  TTAProgram::Program& program, const TTAMachine::Machine& targetMachine);
56 
57  virtual std::string shortDescription() const;
58 
59  static bool removeJump(TTAProgram::BasicBlock& bb);
62  std::map<ProgramOperationPtr,ProgramOperationPtr>& poMapping);
63 
64 private:
65 
66  /**
67  * This struct holds data about one area being if-converted,
68  * all the nodes and their order and the form of the area.
69  */
70  struct CandidateBlocks {
71 
73  BasicBlockNode& firstNode, BasicBlockNode& fallThruNode,
74  BasicBlockNode& jumpNode, BasicBlockNode& lastNode,
75  BasicBlockNode* joinNode, BasicBlockNode* succNode1,
76  BasicBlockNode* succNode2, bool removeJoin, bool removeFT,
77  bool removeJd);
78 
80 
88 
94 
96  bool removeFt_;
97  bool removeJd_;
101  int grIndex_;
103  };
104 
106  BasicBlockNode& bbn, BasicBlockNode& fallThruNode,
107  BasicBlockNode& jumpDestNode, ControlFlowGraph& cfg);
108 
110  BasicBlockNode& bbn, BasicBlockNode& fallThruNode,
111  BasicBlockNode& jumpDestNode, ControlFlowGraph& cfg);
112 
114  BasicBlockNode& bbn, BasicBlockNode& fallThruNode,
115  BasicBlockNode& jumpDestNode, ControlFlowGraph& cfg);
116 
117  std::pair<BasicBlockNode*,BasicBlockNode*> successors(
118  BasicBlockNode& node, ControlFlowGraph& cfg);
119 
121 
123 
124  void appendBB(
126  TTAProgram::MoveGuard* mg, bool removeJumps);
127 
128  bool writesRegister(
129  const TTAProgram::BasicBlock& bb,
130  int index,
131  const TTAMachine::RegisterFile& rf,
132  bool ignoreLastInstruction);
133 
135 
136  bool canConvert(
137  CandidateBlocks* candidates,
138  ControlFlowGraph& cfg);
139 
140  void combineBlocks(CandidateBlocks& bblocks);
141 
142  void convert(CandidateBlocks& bblocks, ControlFlowGraph& cfg);
143 
144  void updateCfg(CandidateBlocks& bblocks, ControlFlowGraph& cfg);
145 
148 
153 
161 
165 };
166 
167 #endif
SimpleIfConverter::CandidateBlocks::lastBB_
TTAProgram::BasicBlock & lastBB_
Definition: SimpleIfConverter.hh:92
SimpleIfConverter::CandidateBlocks::invg_
TTAProgram::MoveGuard * invg_
Definition: SimpleIfConverter.hh:100
SimpleIfConverter::CandidateBlocks::firstNode_
BasicBlockNode & firstNode_
Definition: SimpleIfConverter.hh:81
ProcedurePass
Definition: ProcedurePass.hh:53
TTAProgram
Definition: Estimator.hh:65
SimpleIfConverter::CandidateBlocks::guard_
TTAProgram::MoveGuard * guard_
Definition: SimpleIfConverter.hh:99
TTAProgram::Program
Definition: Program.hh:63
SimpleIfConverter::writesRegister
bool writesRegister(const TTAProgram::BasicBlock &bb, int index, const TTAMachine::RegisterFile &rf, bool ignoreLastInstruction)
Definition: SimpleIfConverter.cc:644
SimpleIfConverter::CandidateBlocks::jumpDestBB_
TTAProgram::BasicBlock & jumpDestBB_
Definition: SimpleIfConverter.hh:91
SimpleIfConverter::fixTerminalPO
static ProgramOperationPtr fixTerminalPO(TTAProgram::TerminalFUPort &terminal, std::map< ProgramOperationPtr, ProgramOperationPtr > &poMapping)
Definition: SimpleIfConverter.cc:563
SimpleIfConverter::CandidateBlocks::createJump_
bool createJump_
Definition: SimpleIfConverter.hh:98
SimpleIfConverter::shortDescription
virtual std::string shortDescription() const
Definition: SimpleIfConverter.cc:125
SimpleIfConverter::irm_
TTAProgram::InstructionReferenceManager * irm_
Definition: SimpleIfConverter.hh:147
SimpleIfConverter::grUseAborts_
int grUseAborts_
Definition: SimpleIfConverter.hh:156
SimpleIfConverter::detectDiamond
CandidateBlocks * detectDiamond(BasicBlockNode &bbn, BasicBlockNode &fallThruNode, BasicBlockNode &jumpDestNode, ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:781
SimpleIfConverter::handleProgram
virtual void handleProgram(TTAProgram::Program &program, const TTAMachine::Machine &targetMachine)
Definition: SimpleIfConverter.cc:210
ProgramPass
Definition: ProgramPass.hh:52
SimpleIfConverter::sizeAborts_
int sizeAborts_
Definition: SimpleIfConverter.hh:159
SimpleIfConverter::CandidateBlocks::joinNode_
BasicBlockNode * joinNode_
Definition: SimpleIfConverter.hh:85
MoveNode
Definition: MoveNode.hh:65
SimpleIfConverter::triangleSizeLimit1_
int triangleSizeLimit1_
Definition: SimpleIfConverter.hh:163
SimpleIfConverter::searchCandidate
CandidateBlocks * searchCandidate(ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:234
SimpleIfConverter::SimpleIfConverter
SimpleIfConverter(InterPassData &data, const TTAMachine::Machine &targetMachine)
Definition: SimpleIfConverter.cc:60
SimpleIfConverter::diamonds_
int diamonds_
Definition: SimpleIfConverter.hh:149
SimpleIfConverter::triangleSizeLimit2_
int triangleSizeLimit2_
Definition: SimpleIfConverter.hh:164
ControlFlowEdge
Definition: ControlFlowEdge.hh:50
ProgramOperationPtr
std::shared_ptr< ProgramOperation > ProgramOperationPtr
Definition: MoveNode.hh:52
SimpleIfConverter::addJump
void addJump(TTAProgram::BasicBlock &bb, BasicBlockNode &bbn)
Definition: SimpleIfConverter.cc:704
SimpleIfConverter
Definition: SimpleIfConverter.hh:40
SimpleIfConverter::successors
std::pair< BasicBlockNode *, BasicBlockNode * > successors(BasicBlockNode &node, ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:728
SimpleIfConverter::CandidateBlocks::removeJd_
bool removeJd_
Definition: SimpleIfConverter.hh:97
SimpleIfConverter::CandidateBlocks::~CandidateBlocks
~CandidateBlocks()
Definition: SimpleIfConverter.cc:1037
SimpleIfConverter::triangles1_
int triangles1_
Definition: SimpleIfConverter.hh:151
SimpleIfConverter::CandidateBlocks::firstBB_
TTAProgram::BasicBlock & firstBB_
Definition: SimpleIfConverter.hh:89
SimpleIfConverter::uncondAborts_
int uncondAborts_
Definition: SimpleIfConverter.hh:158
SimpleIfConverter::CandidateBlocks::fallThruNode_
BasicBlockNode & fallThruNode_
Definition: SimpleIfConverter.hh:82
SimpleIfConverter::triangles2_
int triangles2_
Definition: SimpleIfConverter.hh:152
ProgramPass.hh
SimpleIfConverter::succAborts_
int succAborts_
Definition: SimpleIfConverter.hh:160
SimpleIfConverter::canConvert
bool canConvert(CandidateBlocks *candidates, ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:289
ProcedurePass.hh
SimpleIfConverter::CandidateBlocks::grFile_
const TTAMachine::RegisterFile * grFile_
Definition: SimpleIfConverter.hh:102
SimpleIfConverter::diamondSizeLimit_
int diamondSizeLimit_
Definition: SimpleIfConverter.hh:162
BasicBlockNode
Definition: BasicBlockNode.hh:64
InterPassData
Definition: InterPassData.hh:48
SimpleIfConverter::convert
void convert(CandidateBlocks &bblocks, ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:405
SimpleIfConverter::CandidateBlocks::succNode1_
BasicBlockNode * succNode1_
Definition: SimpleIfConverter.hh:86
SimpleIfConverter::handleProcedure
virtual void handleProcedure(TTAProgram::Procedure &procedure, const TTAMachine::Machine &targetMachine)
Definition: SimpleIfConverter.cc:190
SimpleIfConverter::CandidateBlocks::lastNode_
BasicBlockNode & lastNode_
Definition: SimpleIfConverter.hh:84
SimpleIfConverter::grDefAborts_
int grDefAborts_
Definition: SimpleIfConverter.hh:155
SimpleIfConverter::CandidateBlocks::joinBB_
TTAProgram::BasicBlock * joinBB_
Definition: SimpleIfConverter.hh:93
SimpleIfConverter::CandidateBlocks::removeJoin_
bool removeJoin_
Definition: SimpleIfConverter.hh:95
TTAProgram::TerminalFUPort
Definition: TerminalFUPort.hh:56
SimpleIfConverter::hasConditionals
bool hasConditionals(TTAProgram::BasicBlock &bb)
Definition: SimpleIfConverter.cc:550
ProgramOperation.hh
TTAProgram::BasicBlock
Definition: BasicBlock.hh:85
SimpleIfConverter::combineBlocks
void combineBlocks(CandidateBlocks &bblocks)
Definition: SimpleIfConverter.cc:492
TTAProgram::InstructionReferenceManager
Definition: InstructionReferenceManager.hh:82
ControlFlowGraphPass.hh
DataDependenceGraph
Definition: DataDependenceGraph.hh:67
SimpleIfConverter::removeJump
static bool removeJump(TTAProgram::BasicBlock &bb)
Definition: SimpleIfConverter.cc:679
TTAProgram::CodeGenerator
Definition: CodeGenerator.hh:53
SimpleIfConverter::handleControlFlowGraph
virtual void handleControlFlowGraph(ControlFlowGraph &cfg, const TTAMachine::Machine &targetMachine)
Definition: SimpleIfConverter.cc:135
SimpleIfConverter::detectTriangleViaJump
CandidateBlocks * detectTriangleViaJump(BasicBlockNode &bbn, BasicBlockNode &fallThruNode, BasicBlockNode &jumpDestNode, ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:873
ControlFlowGraphPass
Definition: ControlFlowGraphPass.hh:50
SimpleIfConverter::CandidateBlocks::grIndex_
int grIndex_
Definition: SimpleIfConverter.hh:101
program
find Finds info of the inner loops in the program
Definition: InnerLoopFinder.cc:80
SimpleIfConverter::CandidateBlocks::fallThruBB_
TTAProgram::BasicBlock & fallThruBB_
Definition: SimpleIfConverter.hh:90
TTAMachine::RegisterFile
Definition: RegisterFile.hh:47
SimpleIfConverter::diamonds2_
int diamonds2_
Definition: SimpleIfConverter.hh:150
TTAMachine
Definition: Assembler.hh:48
SimpleIfConverter::detectTriangleViaFt
CandidateBlocks * detectTriangleViaFt(BasicBlockNode &bbn, BasicBlockNode &fallThruNode, BasicBlockNode &jumpDestNode, ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:932
SimpleIfConverter::CandidateBlocks::CandidateBlocks
CandidateBlocks(BasicBlockNode &firstNode, BasicBlockNode &fallThruNode, BasicBlockNode &jumpNode, BasicBlockNode &lastNode, BasicBlockNode *joinNode, BasicBlockNode *succNode1, BasicBlockNode *succNode2, bool removeJoin, bool removeFT, bool removeJd)
Definition: SimpleIfConverter.cc:1015
TTAProgram::MoveGuard
Definition: MoveGuard.hh:47
SimpleIfConverter::CandidateBlocks
Definition: SimpleIfConverter.hh:70
SimpleIfConverter::CandidateBlocks::jumpDestNode_
BasicBlockNode & jumpDestNode_
Definition: SimpleIfConverter.hh:83
SimpleIfConverter::appendBB
void appendBB(const TTAProgram::BasicBlock &src, TTAProgram::BasicBlock &dest, TTAProgram::MoveGuard *mg, bool removeJumps)
Definition: SimpleIfConverter.cc:587
TTAProgram::Procedure
Definition: Procedure.hh:55
SimpleIfConverter::codeGenerator_
TTAProgram::CodeGenerator * codeGenerator_
Definition: SimpleIfConverter.hh:146
SimpleIfConverter::CandidateBlocks::removeFt_
bool removeFt_
Definition: SimpleIfConverter.hh:96
SimpleIfConverter::grAborts_
int grAborts_
Definition: SimpleIfConverter.hh:154
SimpleIfConverter::updateCfg
void updateCfg(CandidateBlocks &bblocks, ControlFlowGraph &cfg)
Definition: SimpleIfConverter.cc:421
SimpleIfConverter::CandidateBlocks::succNode2_
BasicBlockNode * succNode2_
Definition: SimpleIfConverter.hh:87
ControlFlowGraph
Definition: ControlFlowGraph.hh:100
TTAMachine::Machine
Definition: Machine.hh:73
SimpleIfConverter::loopAborts_
int loopAborts_
Definition: SimpleIfConverter.hh:157