OpenASIP
2.0
|
#include <ControlFlowGraph.hh>
Classes | |
class | DFSBackEdgeVisitor |
DFS visitor which when finding back edge marks such edge as back edge. More... | |
Private Types | |
enum | RemovedJumpData { JUMP_NOT_REMOVED = 0, JUMP_REMOVED, LAST_ELEMENT_REMOVED } |
typedef hash_map< InstructionAddress, const TTAProgram::Instruction * > | InstructionAddressMap |
typedef std::vector< InstructionAddress > | InstructionAddressVector |
typedef reverse_graph< ControlFlowGraph::Graph > | ReversedGraph |
typedef BoostGraph< BasicBlockNode, ControlFlowEdge >::NodeDescriptor | NodeDescriptor |
typedef std::pair< InstructionAddress, ControlFlowEdge::CFGEdgePredicate > | ReturnSource |
typedef std::set< ReturnSource > | ReturnSourceSet |
typedef hash_map< TTAProgram::Instruction *, TTAProgram::Instruction * > | InsMap |
Private Attributes | |
TCEString | procedureName_ |
TTAProgram::Program * | program_ |
const TTAProgram::Procedure * | procedure_ |
TTAProgram::Address | startAddress_ |
TTAProgram::Address | endAddress_ |
int | alignment_ |
hash_map< InstructionAddress, BasicBlockNode * > | blocks_ |
InsMap | originalToCfgInstructions_ |
InsMap | cfgToOriginalInstructions_ |
ReturnSourceSet | returnSources_ |
InterPassData * | passData_ |
TTAProgram::InstructionReferenceManager * | irm_ |
std::map< const TTAProgram::BasicBlock *, llvm::MachineBasicBlock * > | bbMap_ |
std::set< std::pair< ProgramOperationPtr, llvm::MCSymbol * > > | tpos_ |
For LLVM conversion: the dummy label instructions for SPU should be created for with the given MCSymbol as argument after building. More... | |
std::map< ProgramOperation *, llvm::MachineInstr * > | programOperationToMIMap_ |
For LLVM conversion: mapping of created MachineInstructions to TCE ProgramOperations. More... | |
Friends | |
class | ControlDependenceGraph |
class | ProgramDependenceGraph |
Additional Inherited Members | |
Public Types inherited from BoostGraph< BasicBlockNode, ControlFlowEdge > | |
typedef std::set< BasicBlockNode *, typename BasicBlockNode ::Comparator > | NodeSet |
typedef std::set< ControlFlowEdge *, typename ControlFlowEdge ::Comparator > | EdgeSet |
typedef BasicBlockNode | Node |
The (base) node type managed by this graph. More... | |
typedef ControlFlowEdge | Edge |
The (base) edge type managed by this graph. More... | |
Public Types inherited from GraphBase< BasicBlockNode, ControlFlowEdge > | |
typedef std::set< BasicBlockNode *, typename BasicBlockNode ::Comparator > | NodeSet |
typedef std::set< ControlFlowEdge *, typename ControlFlowEdge ::Comparator > | EdgeSet |
typedef BasicBlockNode | Node |
Node type of this graph (possibly, a base class). More... | |
typedef ControlFlowEdge | Edge |
Edge type of this graph (possibly, a base class). More... | |
Protected Types inherited from BoostGraph< BasicBlockNode, ControlFlowEdge > | |
typedef std::set< RemovedEdgeDatum > | RemovedEdgeMap |
typedef boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS, Node *, Edge * > | Graph |
Internal graph type, providing actual graph-like operations. This type definition relies on bundled properties of boost library, which need the host compiler to support partial template specialisation. More... | |
typedef boost::graph_traits< Graph > | GraphTraits |
Traits characterising the internal graph type. More... | |
typedef GraphTraits::out_edge_iterator | OutEdgeIter |
Output edge iterator type. More... | |
typedef GraphTraits::in_edge_iterator | InEdgeIter |
Input edge iterator type. More... | |
typedef GraphTraits::edge_iterator | EdgeIter |
Iterator type for the list of all edges in the graph. More... | |
typedef GraphTraits::vertex_iterator | NodeIter |
Iterator type for the list of all nodes in the graph. More... | |
typedef GraphTraits::edge_descriptor | EdgeDescriptor |
Type with which edges of the graph are seen internally. More... | |
typedef GraphTraits::vertex_descriptor | NodeDescriptor |
Type with which nodes of the graph are seen internally. More... | |
typedef hash_map< const Edge *, EdgeDescriptor, GraphHashFunctions > | EdgeDescMap |
typedef hash_map< const Node *, NodeDescriptor, GraphHashFunctions > | NodeDescMap |
typedef std::vector< std::vector< int > > | PathCache |
Protected Member Functions inherited from BoostGraph< BasicBlockNode, ControlFlowEdge > | |
Node & | tailNode (const Edge &edge, const NodeDescriptor &headNode) const |
Node & | headNode (const Edge &edge, const NodeDescriptor &tailNode) const |
virtual void | connectNodes (const Node &nTail, const Node &nHead, Edge &e, GraphBase< BasicBlockNode, ControlFlowEdge > *modifier, bool creatingSG=false) |
void | moveInEdges (const Node &source, const Node &destination, BoostGraph *modifierGraph) |
virtual void | moveOutEdges (const Node &source, const Node &destination, BoostGraph *modifierGraph) |
virtual void | removeNode (Node &node, BoostGraph *modifierGraph) |
virtual void | removeEdge (Edge &e, const BasicBlockNode *tailNode, const BasicBlockNode *headNode, BoostGraph *modifierGraph=NULL) |
bool | hasEdge (const Node &nTail, const Node &nHead, const Edge &edge) const |
bool | hasEdge (const Edge &edge, const Node *nTail=NULL, const Node *nHead=NULL) const |
void | restoreRemovedEdges (RemovedEdgeMap removedEdges) |
EdgeDescriptor | descriptor (const Edge &e) const |
NodeDescriptor | descriptor (const Node &n) const |
EdgeDescriptor | edgeDescriptor (const NodeDescriptor &tailNode, const Edge &e) const |
EdgeDescriptor | edgeDescriptor (const Edge &e, const NodeDescriptor &headNode) const |
EdgeDescriptor | connectingEdge (const Node &nTail, const Node &nHead) const |
void | replaceNodeWithLastNode (BasicBlockNode &dest) |
void | calculatePathLengths () const |
void | calculatePathLengthsFast () const |
void | calculateSinkDistance (const BasicBlockNode &node, int len, bool looping=false) const |
void | calculateSourceDistances (const BasicBlockNode *startNode=NULL, int startingLength=0, bool looping=false) const |
void | calculatePathLengthsOnConnect (const BasicBlockNode &nTail, const BasicBlockNode &nHead, ControlFlowEdge &e) |
void | sinkDistDecreased (const BasicBlockNode &n) const |
void | sourceDistDecreased (const BasicBlockNode &n) const |
virtual int | edgeWeight (ControlFlowEdge &e, const BasicBlockNode &n) const |
void | clearDescriptorCache (EdgeSet edges) |
void | constructSubGraph (BoostGraph &subGraph, NodeSet &nodes) |
Protected Attributes inherited from BoostGraph< BasicBlockNode, ControlFlowEdge > | |
std::map< const BasicBlockNode *, int, typename BasicBlockNode ::Comparator > | sourceDistances_ |
std::map< const BasicBlockNode *, int, typename BasicBlockNode ::Comparator > | sinkDistances_ |
std::map< const BasicBlockNode *, int, typename BasicBlockNode ::Comparator > | loopingSourceDistances_ |
std::map< const BasicBlockNode *, int, typename BasicBlockNode ::Comparator > | loopingSinkDistances_ |
int | height_ |
Graph | graph_ |
The internal graph structure. More... | |
EdgeDescMap | edgeDescriptors_ |
NodeDescMap | nodeDescriptors_ |
BoostGraph< BasicBlockNode, ControlFlowEdge > * | parentGraph_ |
std::vector< BoostGraph< BasicBlockNode, ControlFlowEdge > * > | childGraphs_ |
TCEString | name_ |
int | sgCounter_ |
std::set< Edge * > | ownedEdges_ |
bool | allowLoopEdges_ |
PathCache * | pathCache_ |
Control Flow Graph.
The basic blocks are initially in the original program order when traversed with nodeCount()/node().
Definition at line 100 of file ControlFlowGraph.hh.
|
private |
Definition at line 330 of file ControlFlowGraph.hh.
|
private |
Definition at line 193 of file ControlFlowGraph.hh.
|
private |
Definition at line 194 of file ControlFlowGraph.hh.
|
private |
Definition at line 199 of file ControlFlowGraph.hh.
|
private |
Definition at line 201 of file ControlFlowGraph.hh.
|
private |
Definition at line 202 of file ControlFlowGraph.hh.
|
private |
Definition at line 197 of file ControlFlowGraph.hh.
|
private |
Enumerator | |
---|---|
JUMP_NOT_REMOVED | |
JUMP_REMOVED | nothing removed |
LAST_ELEMENT_REMOVED | jump removed, other things remain in BB last jump removed, no immeds in BB. |
Definition at line 296 of file ControlFlowGraph.hh.
ControlFlowGraph::ControlFlowGraph | ( | const TCEString | name, |
TTAProgram::Program * | program = NULL |
||
) |
Create empty CFG with given name
Definition at line 145 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::name(), and procedureName_.
ControlFlowGraph::ControlFlowGraph | ( | const TTAProgram::Procedure & | procedure, |
InterPassData & | passData | ||
) |
Read a procedure of TTA program and build a control flow graph out of it.
A version that allows adding inter pass data with additional data to add to the CFG (currently inner loop BB trip counts).
Create a control flow graph using the procedure of POM. Procedure must be registered in Program to get access to relocations.
Definition at line 184 of file ControlFlowGraph.cc.
References buildFrom().
ControlFlowGraph::ControlFlowGraph | ( | const TTAProgram::Procedure & | procedure | ) |
Read a procedure of TTA program and build a control flow graph out of it.
Create a control flow graph using the procedure of POM. Procedure must be registered in Program to get access to relocations.
Definition at line 163 of file ControlFlowGraph.cc.
References buildFrom().
|
virtual |
Removes nodes and edge from the graph.
Removal of nodes automatically frees also the edges.
Definition at line 133 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::removeNode().
|
private |
Create a "false" edge between Entry and Exit. Replaces edges from Entry to graph with "true" edges. This is not strictly part of Control Flow Graph, it is used during construction of control dependencies.
The entry node is connected to exit node
Definition at line 1097 of file ControlFlowGraph.cc.
References ControlFlowEdge::CFLOW_EDGE_FALSE, ControlFlowEdge::CFLOW_EDGE_TRUE, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), BoostGraph< BasicBlockNode, ControlFlowEdge >::disconnectNodes(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edge(), entryNode(), exitNode(), BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdge().
Referenced by ControlDependenceGraph::createPostDominanceTree().
|
private |
Adds artificial block named 'Exit' to the graph
Definition at line 922 of file ControlFlowGraph.cc.
References __func__, addExitFromSinkNodes(), BoostGraph< BasicBlockNode, ControlFlowEdge >::addNode(), blocks_, ControlFlowEdge::CFLOW_EDGE_JUMP, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), MapTools::containsKey(), Application::logStream(), returnSources_, Conversion::toString(), and Application::verboseLevel().
Referenced by buildFrom().
void ControlFlowGraph::addExit | ( | NodeSet & | retSourceNodes | ) |
Referenced by llvm::LLVMTCEIRBuilder::buildTCECFG(), and ProgramDependenceGraph::processEntry().
void ControlFlowGraph::addExitFromSinkNodes | ( | BasicBlockNode * | exitNode | ) |
Definition at line 966 of file ControlFlowGraph.cc.
References ControlFlowEdge::CFLOW_EDGE_CALL, ControlFlowEdge::CFLOW_EDGE_NORMAL, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edge(), exitNode(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree().
Referenced by addExit().
int ControlFlowGraph::alignment | ( | ) | const |
Returns alignment value copied from original POM procedure
Definition at line 1160 of file ControlFlowGraph.cc.
References alignment_.
Referenced by ControlDependenceGraph::ControlDependenceGraph().
bool ControlFlowGraph::allScheduledInBetween | ( | const BasicBlockNode & | src, |
const BasicBlockNode & | dst | ||
) | const |
Definition at line 3178 of file ControlFlowGraph.cc.
References BasicBlockNode::isNormalBB(), BasicBlockNode::isScheduled(), and BasicBlockNode::successor().
Referenced by BBSchedulerController::handleCFGDDG().
|
private |
Constructs the CFG from the given procedure.
While finding jump successors, also test if there is indirect jump in procedure, in such case also rellocations are used to find basic block starts.
Definition at line 200 of file ControlFlowGraph.cc.
References addExit(), TTAProgram::Procedure::alignment(), alignment_, computeLeadersFromJumpSuccessors(), computeLeadersFromRefManager(), computeLeadersFromRelocations(), createAllBlocks(), createBBEdges(), detectBackEdges(), TTAProgram::CodeSnippet::endAddress(), endAddress_, TTAProgram::CodeSnippet::isInProgram(), TTAProgram::Procedure::name(), TTAProgram::CodeSnippet::parent(), procedure_, procedureName_, program_, TTAProgram::CodeSnippet::startAddress(), and startAddress_.
Referenced by ControlFlowGraph().
|
private |
Definition at line 1893 of file ControlFlowGraph.cc.
References abortWithError, assert, TTAProgram::Terminal::basicBlock(), TTAProgram::Move::bus(), TTAProgram::Move::destination(), findLLVMTargetInstrDesc(), TTAProgram::Terminal::functionUnit(), TTAMachine::Machine::functionUnitNavigator(), getMBB(), TTAProgram::TerminalFUPort::hwOperation(), TTAProgram::Terminal::index(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), SimValue::intValue(), TTAProgram::Terminal::isBasicBlockReference(), TTAProgram::Terminal::isCodeSymbolReference(), TTAProgram::Terminal::isFUPort(), TTAProgram::Terminal::isGPR(), TTAProgram::Terminal::isImmediate(), TTAProgram::Instruction::isNOP(), TTAProgram::Terminal::isProgramOperationReference(), TTAProgram::Terminal::isRA(), TTAProgram::Move::isTriggering(), TTAMachine::Machine::Navigator< ComponentType >::item(), TTAProgram::TerminalProgramOperation::label(), TTAMachine::HWOperation::latency(), Application::logStream(), TTAMachine::Component::machine(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), TTAMachine::HWOperation::name(), Operation::name(), Operation::numberOfInputs(), Operation::numberOfOutputs(), OperationPool::operation(), TTAMachine::HWOperation::parentUnit(), TTAMachine::HWOperation::port(), TTAProgram::Terminal::port(), PRINT_VAR, TTAProgram::TerminalProgramOperation::programOperation(), TTAProgram::TerminalFUPort::programOperation(), programOperationToMIMap_, TTAProgram::BasicBlock::skippedFirstInstructions(), TTAProgram::Move::source(), TCEString::split(), TCEString::startsWith(), Conversion::toInt(), TTAProgram::Terminal::toString(), TTAProgram::CodeSnippet::toString(), tpos_, and TTAProgram::Terminal::value().
Referenced by copyToLLVMMachineFunction().
|
private |
Computes starts of basic blocks which follows jumps or calls or are targets of jump.
Also detect if any of jumps is indirect, which will require data-code rellocation information for creating jumps as well.
leaders | Set of leader instructions to update. |
procedure | The procedure to analyse. |
Definition at line 444 of file ControlFlowGraph.cc.
References TTAProgram::Instruction::address(), findNextIndex(), indirectJump(), TTAProgram::InstructionReference::instruction(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Terminal::instructionReference(), TTAProgram::Move::isControlFlowMove(), TTAProgram::Terminal::isGPR(), TTAProgram::Terminal::isImmediateRegister(), TTAProgram::Terminal::isInstructionAddress(), TTAProgram::Move::isJump(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), and TTAProgram::Move::source().
Referenced by buildFrom().
|
private |
Internal helper. Find the leader instructions from program reference manager. Should also find startAddress of procedure.
leaders | Set of leader instructions to update. |
procedure | The procedure to analyse, uses it's parent() program to find referenceManager. |
Definition at line 351 of file ControlFlowGraph.cc.
References __func__, TTAProgram::Instruction::address(), assert, TTAProgram::InstructionReferenceManager::begin(), TTAProgram::InstructionReferenceManager::end(), endAddress_, TTAProgram::CodeSnippet::firstInstruction(), TTAProgram::Program::instructionReferenceManager(), TTAProgram::CodeSnippet::isInProgram(), TTAProgram::Address::location(), TTAProgram::CodeSnippet::parent(), TTAProgram::Instruction::parent(), and startAddress_.
Referenced by buildFrom().
|
private |
Internal helper. Finds the leader instructions that are referred to via addressed stored in data memory and recorded as data-to-code relocation entries.
Adds to a given instruction set all instructions whose address is stored in data memory (thus are potential targets of an indirect jump) and is recorded in a data-to-code relocation entry.
leaders | Set of leader instructions to update. |
dataCodeRellocations | Set of dataCodeRellocations that applies for given procedure |
procedure | The procedure to analyse, uses it's parent() program to access data memory |
Definition at line 397 of file ControlFlowGraph.cc.
References __func__, TTAProgram::DataMemory::dataDefinition(), TTAProgram::DataMemory::dataDefinitionCount(), TTAProgram::Program::dataMemory(), TTAProgram::Program::dataMemoryCount(), TTAProgram::DataDefinition::destinationAddress(), endAddress_, TTAProgram::CodeSnippet::instructionAt(), TTAProgram::CodeSnippet::isInProgram(), TTAProgram::DataDefinition::isInstructionAddress(), TTAProgram::Address::location(), TTAProgram::CodeSnippet::parent(), program(), and startAddress_.
Referenced by buildFrom().
void ControlFlowGraph::convertBBRefsToInstRefs | ( | ) |
Definition at line 2436 of file ControlFlowGraph.cc.
References assert, TTAProgram::Terminal::basicBlock(), BasicBlockNode::basicBlock(), TTAProgram::CodeSnippet::firstInstruction(), TTAProgram::Instruction::immediate(), TTAProgram::Instruction::immediateCount(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), instructionReferenceManager(), TTAProgram::Terminal::isBasicBlockReference(), BasicBlockNode::isNormalBB(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), TTAProgram::Move::setSource(), TTAProgram::Immediate::setValue(), TTAProgram::Move::source(), and TTAProgram::Immediate::value().
Referenced by llvm::LLVMTCEIRBuilder::compileOptimized(), and llvm::LLVMTCEIRBuilder::writeMachineFunction().
void ControlFlowGraph::copyToLLVMMachineFunction | ( | llvm::MachineFunction & | mf, |
TTAProgram::InstructionReferenceManager * | irm = NULL |
||
) |
Copies the CFG into an LLVM MachineFunction.
Assumes an operation triggered target and that all scheduler restrictions to produce valid code for such an target have been enabled in ADF while producing the schedule.
mf | The MachineFunction where to copy the cfg. |
irm | InstructionReferenceManager for resolving instruction refs. |
This loop now only creates empty basic blocks in same order as they were transfered from LLVM to POM previously. Actuall copying of the content is done afterwords.
This will create MachineBasicblock corresponding to BB if it does not exists already.
Fill in created machine basic blocks with machine instructions based on corresponding basic blocks.
Add the dummy instructions denoting labels to instructions that are not basic block starts. This is only for the SPU's branch hint instructions at the moment. It instantiates an LLVM/SPU-backend-specific dummy instruction HBR_LABEL at the moment.
Based on CFG edges, add successor information to the generated machine function.
Definition at line 1679 of file ControlFlowGraph.cc.
References assert, BasicBlockNode::basicBlock(), buildMBBFromBB(), AssocTools::containsKey(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edgeCount(), entryNode(), fallThruSuccessor(), findLLVMTargetInstrDesc(), findReachableNodes(), getMBB(), hasFallThruPredecessor(), TTAProgram::InstructionReferenceManager::hasReference(), BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), TTAProgram::Program::instructionReferenceManager(), BasicBlockNode::isNormalBB(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdges(), program_, programOperationToMIMap_, TTAProgram::InstructionReferenceManager::replace(), BoostGraph< BasicBlockNode, ControlFlowEdge >::successors(), BoostGraph< BasicBlockNode, ControlFlowEdge >::tailNode(), BasicBlockNode::toString(), tpos_, and GraphBase< BasicBlockNode, ControlFlowEdge >::writeToDotFile().
Referenced by llvm::LLVMTCEIRBuilder::writeMachineFunction().
void ControlFlowGraph::copyToProcedure | ( | TTAProgram::Procedure & | proc, |
TTAProgram::InstructionReferenceManager * | irm = NULL |
||
) |
Copies the CFG into a procedure.
Clears the procedure and replaces all instructions in it with ones in CFG. Tries to get rid of some unnecessary jumps.
proc | procedure where the copy the cfg. |
Definition at line 1448 of file ControlFlowGraph.cc.
References assert, BasicBlockNode::basicBlock(), ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH, TTAProgram::Procedure::clear(), BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), TTAProgram::Instruction::copy(), ControlFlowEdge::edgePredicate(), entryNode(), fallThruSuccessor(), findReachableNodes(), findUnreachableNodes(), TTAProgram::CodeSnippet::firstInstruction(), hasFallThruPredecessor(), TTAProgram::InstructionReferenceManager::hasReference(), BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Program::instructionReferenceManager(), TTAProgram::CodeSnippet::isInProgram(), BasicBlockNode::isNormalBB(), JUMP_NOT_REMOVED, LAST_ELEMENT_REMOVED, TTAProgram::Program::lastProcedure(), TTAProgram::Program::moveProcedure(), TTAProgram::Procedure::name(), TTAProgram::Program::nextProcedure(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdges(), TTAProgram::CodeSnippet::parent(), PRINT_VAR, program_, BoostGraph< BasicBlockNode, ControlFlowEdge >::removeEdge(), removeJumpToTarget(), TTAProgram::InstructionReferenceManager::replace(), TTAProgram::BasicBlock::skippedFirstInstructions(), BoostGraph< BasicBlockNode, ControlFlowEdge >::successors(), BasicBlockNode::toString(), TTAProgram::CodeSnippet::toString(), and GraphBase< BasicBlockNode, ControlFlowEdge >::writeToDotFile().
Referenced by ProgramDependenceGraph::disassemble(), SimpleIfConverter::handleProcedure(), PreOptimizer::handleProcedure(), BBSchedulerController::handleProcedure(), and llvm::LLVMTCEIRBuilder::writeMachineFunction().
|
private |
Split Procedure into the set of basic blocks.
leaders | Set of instructions which starts basic block. |
procedure | Procedure that is analysed. |
Definition at line 503 of file ControlFlowGraph.cc.
References createBlock(), TTAProgram::CodeSnippet::instructionAt(), and TTAProgram::CodeSnippet::lastInstruction().
Referenced by buildFrom().
|
private |
Creates edges between basic blocks.
procedure | Procedure that holds the instructions. |
leaders | Leader instructions, first instructions in basic blocks. |
dataCodeRellocations | Set of dataCodeRellocations that applies to the given procedure. |
Look for __exit procedure, if it is found, calls to it will not have fall through edges in CFG to avoid possible endless loops and create possible unreachable basic blocks
The __exit procedure was not found, we do not detect calls to __exit in calls
Do not create fall through edge after call to __exit
Definition at line 240 of file ControlFlowGraph.cc.
References TTAProgram::Instruction::address(), blocks_, ControlFlowEdge::CFLOW_EDGE_CALL, ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH, ControlFlowEdge::CFLOW_EDGE_NORMAL, MapTools::containsKey(), createControlFlowEdge(), createJumps(), findNextIndex(), TTAProgram::CodeSnippet::firstInstruction(), BoostGraph< BasicBlockNode, ControlFlowEdge >::hasEdge(), TTAProgram::Program::hasProcedure(), TTAProgram::InstructionReference::instruction(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::TerminalInstructionReference::instructionReference(), TTAProgram::Move::isCall(), TTAProgram::CodeSnippet::isInProgram(), TTAProgram::Terminal::isInstructionAddress(), TTAProgram::Move::isJump(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), TTAProgram::Program::procedure(), program_, TTAProgram::Move::source(), and TTAProgram::CodeSnippet::startAddress().
Referenced by buildFrom().
|
private |
Internal helper. Create a basic block.
Given the first and last instructions of a basic block, create a new basic block of graph. It is assumed that the graph does not have a basic block for the given pair of instructions yet. If such a block exists, this method aborts.
leader | The first instruction of the basic block to create. |
endBlock | The last instruction of the basic block to create. |
Definition at line 540 of file ControlFlowGraph.cc.
References __func__, TTAProgram::CodeSnippet::add(), BoostGraph< BasicBlockNode, ControlFlowEdge >::addNode(), TTAProgram::Instruction::address(), TTAProgram::ProgramAnnotation::ANN_LOOP_INNER, TTAProgram::ProgramAnnotation::ANN_LOOP_TRIP_COUNT, TTAProgram::AnnotatedInstructionElement::annotation(), BasicBlockNode::basicBlock(), blocks_, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), MapTools::containsKey(), TTAProgram::Instruction::copy(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edge(), TTAProgram::AnnotatedInstructionElement::hasAnnotations(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::Address::location(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), TTAProgram::Instruction::parent(), TTAProgram::BasicBlock::setInInnerLoop(), TTAProgram::BasicBlock::setTripCount(), TTAProgram::CodeSnippet::startAddress(), and startAddress_.
Referenced by createAllBlocks().
|
private |
Internal helper. Create a control flow edge between two basic blocks.
Given the leader instructions of two basic blocks, create a new control flow edge connecting the blocks. The basic blocks are assumed to be already existing and added to the graph. If either basic block does not exist, this method aborts. A new edge is created even if the blocks are already connected. Thus, parallel edges are possible.
iTail | The first instruction of the tail basic block (from). |
iHead | The first instruction of the head basic block (to). |
edgePredicate | The value of an edge (true, false, normal, call) |
edgeType | Defines if edge represents jump or call or fall-through, default jump |
Definition at line 618 of file ControlFlowGraph.cc.
References __func__, TTAProgram::Instruction::address(), assert, blocks_, ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), MapTools::containsKey(), POMDisassembler::disassemble(), TTAProgram::Address::location(), Application::logStream(), BasicBlockNode::originalEndAddress(), BasicBlockNode::originalStartAddress(), Conversion::toString(), and Application::verboseLevel().
Referenced by createBBEdges(), directJump(), and indirectJump().
|
private |
Helper function to find target address of a jump in case source of jump is immediate register or general purpose register.
leaders | Starting instructions of all basic blocks |
leaderAddr | Address of a first instruction of present Basic Block |
dataCodeRellocations | Read from POM, the possible targets of indirect jumps are in data code rellocation information |
instruction | Currect instruction containing jump |
procedure | The reference to current procedure |
moveIndex | Index of move with jump in current instruction |
Definition at line 1190 of file ControlFlowGraph.cc.
References __func__, TTAProgram::Instruction::address(), TTAProgram::Immediate::destination(), TTAProgram::Move::destination(), directJump(), TTAProgram::TerminalRegister::equals(), TTAProgram::Instruction::immediate(), TTAProgram::Instruction::immediateCount(), indirectJump(), TTAProgram::InstructionReference::instruction(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::Terminal::instructionReference(), TTAProgram::Terminal::isFUPort(), TTAProgram::TerminalRegister::isGPR(), TTAProgram::Terminal::isGPR(), TTAProgram::TerminalRegister::isImmediateRegister(), TTAProgram::Terminal::isImmediateRegister(), TTAProgram::Terminal::isInstructionAddress(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), TTAProgram::CodeSnippet::previousInstruction(), TTAProgram::Move::source(), and TTAProgram::Immediate::value().
Referenced by createBBEdges().
void ControlFlowGraph::deleteNodeAndRefs | ( | BasicBlockNode & | node | ) |
Removes and deletes a basic block node from the grpahs and updates all references that point to it to point elsewhere.
node | basic block node to be removed and deleted. |
Definition at line 2395 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::removeNode().
Referenced by Peel2BBLoops::updateCFG(), and SimpleIfConverter::updateCfg().
void ControlFlowGraph::detectBackEdges | ( | ) |
Tests created control flow graph using depth first search algorithm of boost graph library and mark back edges.
Default starting vertex is vertex(g).first, which is actually first basic block created. Entry is created as second and there is connection added from entry to first BB. Using default parameter for root_vertex is therefore sufficient
Definition at line 2426 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::graph_.
Referenced by buildFrom(), llvm::LLVMTCEIRBuilder::buildTCECFG(), and optimizeBBOrdering().
|
private |
Creates edges for direct jump (source is immediate value).
leaders | Set of beginnings of basic blocks |
leaderAddr | Address of beginning of current basic block |
instruction | Instruction to analyse (only one move in instruction) |
procedure | Procedure we are working with |
Definition at line 679 of file ControlFlowGraph.cc.
References __func__, TTAProgram::Instruction::address(), ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH, ControlFlowEdge::CFLOW_EDGE_FALSE, ControlFlowEdge::CFLOW_EDGE_TRUE, MapTools::containsKey(), createControlFlowEdge(), POMDisassembler::disassemble(), findNextIndex(), TTAProgram::Move::guard(), hasInstructionAnotherJump(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::MoveGuard::isInverted(), TTAProgram::Move::isUnconditional(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), and TTAProgram::CodeSnippet::startAddress().
Referenced by createJumps().
BasicBlockNode & ControlFlowGraph::entryNode | ( | ) | const |
Return the entry node of the graph.
InstanceNotFound | if the graph does not have a entry node. |
InvalidData | if the graph has multiple nodes that are recognised as entry nodes. |
Definition at line 1003 of file ControlFlowGraph.cc.
References __func__, BoostGraph< BasicBlockNode, ControlFlowEdge >::inDegree(), BasicBlockNode::isEntryBB(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount().
Referenced by addEntryExitEdge(), copyToLLVMMachineFunction(), copyToProcedure(), DataDependenceGraphBuilder::createRegisterDeps(), findReachableNodes(), firstNormalNode(), optimizeBBOrdering(), DataDependenceGraphBuilder::queueFirstBB(), and removeEntryExitEdge().
BasicBlockNode & ControlFlowGraph::exitNode | ( | ) | const |
Return the stop/exit node of the graph.
InstanceNotFound | if the graph does not have a stop node. |
InvalidData | if the graph has multiple nodes that are recognised as stop nodes. |
Definition at line 1058 of file ControlFlowGraph.cc.
References __func__, BasicBlockNode::isExitBB(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree().
Referenced by addEntryExitEdge(), addExitFromSinkNodes(), ControlDependenceGraph::createPostDominanceTree(), optimizeBBOrdering(), and removeEntryExitEdge().
BasicBlockNode * ControlFlowGraph::fallThroughPredecessor | ( | const BasicBlockNode & | bbn | ) | const |
Finds a node where control falls thru to the give node.
bbn | basic block node whose successor we are searching |
Definition at line 1379 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::inEdges(), BasicBlockNode::isEntryBB(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::tailNode().
BasicBlockNode * ControlFlowGraph::fallThruSuccessor | ( | const BasicBlockNode & | bbn | ) | const |
Finds a node where control falls thru from the give node.
bbn | basic block node whose successor we are searching |
Definition at line 1358 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), BasicBlockNode::isExitBB(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdges().
Referenced by copyToLLVMMachineFunction(), copyToProcedure(), CallsToJumps::handleControlFlowGraph(), and optimizeBBOrdering().
TTAProgram::Terminal * ControlFlowGraph::findJumpAddress | ( | BasicBlockNode & | src, |
ControlFlowEdge & | e | ||
) |
Finds the terminal containing the target address of the jump corresponding to the edge.
src | basic block node which is the tail of the edge, containing the jump. |
edge | edge whose target address is being searched. |
Definition at line 3006 of file ControlFlowGraph.cc.
References assert, BasicBlockNode::basicBlock(), ControlFlowEdge::edgePredicate(), ControlFlowEdge::edgePredicateFromMove(), and findLimmWrite().
Referenced by sanitize().
TTAProgram::Immediate * ControlFlowGraph::findLimmWrite | ( | TTAProgram::Move & | move, |
BasicBlockNode & | bbn, | ||
int | moveIndex | ||
) |
Finds the immediate write which is read by a move.
move | move containing the immediate use. |
bbn | basic block containing the move |
moveIndex | index of the instruction containing the move in the BB. |
Definition at line 3037 of file ControlFlowGraph.cc.
References BasicBlockNode::basicBlock(), TTAProgram::Instruction::immediate(), TTAProgram::Instruction::immediateCount(), TTAProgram::Terminal::immediateUnit(), BoostGraph< BasicBlockNode, ControlFlowEdge >::inDegree(), TTAProgram::Terminal::index(), TTAProgram::CodeSnippet::instructionCount(), BasicBlockNode::isNormalBB(), TTAMachine::ImmediateUnit::latency(), BoostGraph< BasicBlockNode, ControlFlowEdge >::predecessors(), and TTAProgram::Move::source().
Referenced by findJumpAddress().
|
private |
Finds the TargetInstrDesc for the given LLVM instruction name.
Definition at line 1881 of file ControlFlowGraph.cc.
References abortWithError, TCEString::ciEqual(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::name().
Referenced by buildMBBFromBB(), and copyToLLVMMachineFunction().
|
private |
Finds the index of the next instruction after jump and delay slots in the procedure.
Also checks for control flow moves in delay slots, and throws if found, or if the procedure ends before all delays slots.
procedure | procedure we are processing |
jumpInsIndex | index of the jump inside in the procedure |
index | of the jump move in the jump instruction. |
Definition at line 877 of file ControlFlowGraph.cc.
References __func__, TTAProgram::Instruction::address(), TTAMachine::ControlUnit::delaySlots(), TTAProgram::Move::destination(), POMDisassembler::disassemble(), TTAProgram::Terminal::functionUnit(), TTAProgram::Instruction::hasControlFlowMove(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), and TTAMachine::Component::name().
Referenced by computeLeadersFromJumpSuccessors(), createBBEdges(), directJump(), and indirectJump().
|
private |
Does a breadth first search to find all reachable nodes.
Definition at line 1415 of file ControlFlowGraph.cc.
References AssocTools::append(), AssocTools::containsKey(), entryNode(), BasicBlockNode::isNormalBB(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::successors().
Referenced by copyToLLVMMachineFunction(), copyToProcedure(), and optimizeBBOrdering().
int ControlFlowGraph::findRelJumpDistance | ( | const BasicBlockNode & | src, |
const TTAProgram::Terminal & | jumpAddr, | ||
const TTAMachine::Machine & | mach | ||
) | const |
Definition at line 3137 of file ControlFlowGraph.cc.
References TTAMachine::Machine::controlUnit(), TTAMachine::ControlUnit::delaySlots(), BasicBlockNode::isNormalBB(), jumpToBBN(), BasicBlockNode::maximumSize(), BasicBlockNode::predecessor(), and BasicBlockNode::successor().
|
private |
Definition at line 2503 of file ControlFlowGraph.cc.
References AssocTools::containsKey(), BasicBlockNode::isNormalBB(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount().
Referenced by copyToProcedure(), and optimizeBBOrdering().
BasicBlockNode & ControlFlowGraph::firstNormalNode | ( | ) | const |
Definition at line 1033 of file ControlFlowGraph.cc.
References __func__, entryNode(), BasicBlockNode::isNormalBB(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::successors().
llvm::MachineBasicBlock & ControlFlowGraph::getMBB | ( | llvm::MachineFunction & | mf, |
const TTAProgram::BasicBlock & | bb | ||
) | const |
Fetch machine basic block corresponding to the BasicBlock passed, if it does not exist create empty one.
Definition at line 2829 of file ControlFlowGraph.cc.
References bbMap_, and MapTools::containsKey().
Referenced by buildMBBFromBB(), copyToLLVMMachineFunction(), and llvm::LLVMTCEIRBuilder::fixJumpTableDestinations().
bool ControlFlowGraph::hasFallThruPredecessor | ( | const BasicBlockNode & | bbn | ) |
Returns true if given basic blocks has a predecessor which falls thru to it.
bbn | bbn to check for fall-thru predecessors |
Definition at line 1401 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::inEdges().
Referenced by copyToLLVMMachineFunction(), copyToProcedure(), and optimizeBBOrdering().
bool ControlFlowGraph::hasIncomingExternalJumps | ( | const BasicBlockNode & | bbn | ) | const |
Tells whether a node has incoming jumps that are not from a single-basic block loop, ie source is not the same node.
bbn | the node |
Definition at line 2253 of file ControlFlowGraph.cc.
References incomingJumpEdges(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::tailNode().
|
private |
Tells whether an instruction has another jump in addition to the given.
ins | instruction to check |
moveIndex | index of the move triggering the known jump. |
Definition at line 758 of file ControlFlowGraph.cc.
References TTAProgram::Move::isJump(), TTAProgram::Instruction::move(), and TTAProgram::Instruction::moveCount().
Referenced by directJump(), and indirectJump().
bool ControlFlowGraph::hasMultipleUnconditionalSuccessors | ( | const BasicBlockNode & | node | ) | const |
Definition at line 3103 of file ControlFlowGraph.cc.
References ControlFlowEdge::isNormalEdge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdge().
ControlFlowEdge * ControlFlowGraph::incomingFTEdge | ( | const BasicBlockNode & | bbn | ) | const |
Return an incoming fall-thru edge to a node. Jump and entry is also considered fall-thru
bbn | the node |
Definition at line 2233 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::descriptor(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edgeDescriptors_, BoostGraph< BasicBlockNode, ControlFlowEdge >::graph_, and ControlFlowEdge::isJumpEdge().
ControlFlowGraph::EdgeSet ControlFlowGraph::incomingJumpEdges | ( | const BasicBlockNode & | bbn | ) | const |
Definition at line 2265 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::descriptor(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edgeDescriptors_, BoostGraph< BasicBlockNode, ControlFlowEdge >::graph_, and ControlFlowEdge::isJumpEdge().
Referenced by hasIncomingExternalJumps().
|
private |
Creates edges for indirect jump (source is NOT immediate value).
leaders | Set of beginnings of basic blocks |
leaderAddr | Address of beginning of current basic block |
dataCodeRellocations | Rellocation information for targets of jump |
instruction | Instruction to analyse (only one move in instruction) |
procedure | Procedure we are working with |
Definition at line 779 of file ControlFlowGraph.cc.
References __func__, ControlFlowEdge::CFLOW_EDGE_FAKE, ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH, ControlFlowEdge::CFLOW_EDGE_FALSE, ControlFlowEdge::CFLOW_EDGE_NORMAL, ControlFlowEdge::CFLOW_EDGE_TRUE, MapTools::containsKey(), createControlFlowEdge(), findNextIndex(), TTAProgram::Move::guard(), TTAProgram::AnnotatedInstructionElement::hasAnnotations(), hasInstructionAnotherJump(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::MoveGuard::isInverted(), TTAProgram::Move::isUnconditional(), TTAProgram::Address::location(), TTAProgram::Instruction::move(), TTAProgram::Terminal::port(), returnSources_, TTAProgram::Move::source(), and TTAProgram::CodeSnippet::startAddress().
Referenced by computeLeadersFromJumpSuccessors(), and createJumps().
TTAProgram::InstructionReferenceManager & ControlFlowGraph::instructionReferenceManager | ( | ) |
Definition at line 2401 of file ControlFlowGraph.cc.
References __func__, TTAProgram::Program::instructionReferenceManager(), irm_, and program_.
Referenced by LoopPrologAndEpilogBuilder::addPrologFromRM(), LoopPrologAndEpilogBuilder::addPrologIntoCfg(), llvm::LLVMTCEIRBuilder::compileOptimized(), convertBBRefsToInstRefs(), ControlFlowGraphPass::executeBasicBlockPass(), BBSchedulerController::handleBBNode(), Peel2BBLoops::handleControlFlowGraph(), CallsToJumps::handleControlFlowGraph(), SimpleIfConverter::handleControlFlowGraph(), and sanitize().
bool ControlFlowGraph::isSingleBBLoop | ( | const BasicBlockNode & | node | ) | const |
Definition at line 2919 of file ControlFlowGraph.cc.
References assert, BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), ControlFlowEdge::isBackEdge(), ControlFlowEdge::isJumpEdge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdge().
Referenced by ControlFlowGraphPass::executeBasicBlockPass(), BBSchedulerController::handleBasicBlock(), and BBSchedulerController::handleCFGDDG().
BasicBlockNode * ControlFlowGraph::jumpSuccessor | ( | BasicBlockNode & | bbn | ) |
Definition at line 2411 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), ControlFlowEdge::isJumpEdge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdge().
Referenced by SimpleIfConverter::detectTriangleViaFt(), and BBSchedulerController::handleCFGDDG().
|
private |
Definition at line 3120 of file ControlFlowGraph.cc.
References TTAProgram::Terminal::basicBlock(), BasicBlockNode::basicBlock(), TTAProgram::CodeSnippet::firstInstruction(), TTAProgram::InstructionReference::instruction(), TTAProgram::Terminal::instructionReference(), TTAProgram::Terminal::isBasicBlockReference(), TTAProgram::Terminal::isCodeSymbolReference(), TTAProgram::Terminal::isInstructionAddress(), and BasicBlockNode::isNormalBB().
Referenced by findRelJumpDistance().
|
private |
Definition at line 2762 of file ControlFlowGraph.cc.
References TTAProgram::CodeSnippet::add(), assert, BasicBlockNode::basicBlock(), BoostGraph< BasicBlockNode, ControlFlowEdge >::connectingEdge(), DataDependenceGraph::fixInterBBAntiEdges(), DataDependenceGraph::hasAllRegisterAntidependencies(), DataDependenceGraph::hasIntraBBRegisterAntidependencies(), BoostGraph< BasicBlockNode, ControlFlowEdge >::inEdges(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), BasicBlockNode::isNormalBB(), ControlFlowEdge::isNormalEdge(), TTAProgram::BasicBlock::liveRangeData_, LiveRangeData::merge(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), BoostGraph< BasicBlockNode, ControlFlowEdge >::moveInEdge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::moveOutEdge(), DataDependenceGraph::nodeOfMove(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdges(), TTAProgram::CodeSnippet::remove(), BoostGraph< BasicBlockNode, ControlFlowEdge >::removeNode(), DataDependenceGraph::setBasicBlockNode(), ControlFlowEdge::setPredicate(), TTAProgram::BasicBlock::skippedFirstInstructions(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::tailNode().
Referenced by optimizeBBOrdering().
void ControlFlowGraph::optimizeBBOrdering | ( | bool | removeDeadCode, |
TTAProgram::InstructionReferenceManager & | irm, | ||
DataDependenceGraph * | ddg | ||
) |
The algorithm is same as in CopyToProcedure, but without the copying. Still removes jump, and also does BB mergeing.
Definition at line 2522 of file ControlFlowGraph.cc.
References assert, BasicBlockNode::basicBlock(), ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectingEdges(), BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), detectBackEdges(), ControlFlowEdge::edgePredicate(), entryNode(), exitNode(), fallThruSuccessor(), findReachableNodes(), findUnreachableNodes(), TTAProgram::CodeSnippet::firstInstruction(), hasFallThruPredecessor(), TTAProgram::InstructionReferenceManager::hasReference(), BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), BoostGraph< BasicBlockNode, ControlFlowEdge >::inDegree(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), ControlFlowEdge::isBackEdge(), ControlFlowEdge::isCallPassEdge(), TTAProgram::BasicBlock::isEmpty(), BasicBlockNode::isNormalBB(), BasicBlockNode::isScheduled(), JUMP_NOT_REMOVED, LAST_ELEMENT_REMOVED, BasicBlockNode::link(), mergeNodes(), BoostGraph< BasicBlockNode, ControlFlowEdge >::name(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdges(), BoostGraph< BasicBlockNode, ControlFlowEdge >::removeEdge(), removeJumpToTarget(), removeUnreachableNodes(), TTAProgram::InstructionReferenceManager::replace(), TTAProgram::BasicBlock::skipFirstInstructions(), BoostGraph< BasicBlockNode, ControlFlowEdge >::successors(), BasicBlockNode::toString(), and GraphBase< BasicBlockNode, ControlFlowEdge >::writeToDotFile().
Referenced by llvm::LLVMTCEIRBuilder::compileOptimized().
TCEString ControlFlowGraph::printStatistics | ( | ) |
Returns basic statistics about control flow graph as a string.
Definition at line 1286 of file ControlFlowGraph.cc.
References TTAProgram::BasicBlockStatistics::bypassedCount(), TTAProgram::BasicBlockStatistics::immediateCount(), TTAProgram::BasicBlockStatistics::instructionCount(), CFGStatistics::maxBypassedCount(), CFGStatistics::maxImmediateCount(), CFGStatistics::maxInstructionCount(), CFGStatistics::maxMoveCount(), TTAProgram::BasicBlockStatistics::moveCount(), CFGStatistics::normalBBCount(), procedureName(), and statistics().
TCEString ControlFlowGraph::procedureName | ( | ) | const |
Returns a name of procedure the graph represents taken from original POM object.
Definition at line 1150 of file ControlFlowGraph.cc.
References procedureName_.
Referenced by BBSchedulerController::handleBBNode(), and printStatistics().
TTAProgram::Program * ControlFlowGraph::program | ( | ) | const |
Returns a pointer to the POM Program object procedure was part of in POM.
Definition at line 1171 of file ControlFlowGraph.cc.
References program_.
Referenced by computeLeadersFromRelocations(), ControlDependenceGraph::ControlDependenceGraph(), and PreOptimizer::handleCFGDDG().
|
private |
Remove a "false" edge between Entry and Exit after control dependencies are created.
The entry node is connected to exit
Definition at line 1125 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), BoostGraph< BasicBlockNode, ControlFlowEdge >::disconnectNodes(), BoostGraph< BasicBlockNode, ControlFlowEdge >::edge(), entryNode(), exitNode(), BoostGraph< BasicBlockNode, ControlFlowEdge >::headNode(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree(), and BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdge().
Referenced by ControlDependenceGraph::computeDependence(), and ControlDependenceGraph::detectControlDependencies().
|
private |
Finds a jump that jumps to target from a codesnippet and removes the jump.
cs | CodeSnippet where to remove the jump from. |
target | jump target instruction. |
idx | index which after to check for existing moves and immeds |
Definition at line 2291 of file ControlFlowGraph.cc.
References TTAProgram::Move::bus(), TTAProgram::Move::guard(), TTAProgram::Instruction::immediateCount(), TTAProgram::InstructionReference::instruction(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::TerminalInstructionReference::instructionReference(), TTAProgram::Terminal::isInstructionAddress(), TTAProgram::Move::isJump(), TTAProgram::Move::isUnconditional(), JUMP_NOT_REMOVED, JUMP_REMOVED, LAST_ELEMENT_REMOVED, TTAMachine::Component::machine(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), DataDependenceGraph::nodeOfMove(), TTAProgram::Instruction::removeMove(), DataDependenceGraph::removeNode(), TTAProgram::Move::setGuard(), and TTAProgram::Move::source().
Referenced by copyToProcedure(), and optimizeBBOrdering().
|
private |
TODO: what to do with exit node?
Definition at line 2740 of file ControlFlowGraph.cc.
References BasicBlockNode::basicBlock(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Instruction::move(), TTAProgram::Instruction::moveCount(), DataDependenceGraph::nodeOfMove(), BoostGraph< BasicBlockNode, ControlFlowEdge >::removeNode(), and DataDependenceGraph::removeNode().
Referenced by optimizeBBOrdering().
|
private |
Creates reversed underlying graph.
Control Flow Graph has member graph_ which stores actual data. This function returns reversed graph_ (edge directions changed).
Definition at line 989 of file ControlFlowGraph.cc.
References BoostGraph< BasicBlockNode, ControlFlowEdge >::graph_, and R().
Referenced by ControlDependenceGraph::createPostDominanceTree().
void ControlFlowGraph::reverseGuardOnOutEdges | ( | const BasicBlockNode & | bbn | ) |
Reverses predicate of outgoing edges.
Definition at line 2486 of file ControlFlowGraph.cc.
References assert, ControlFlowEdge::CFLOW_EDGE_FALSE, ControlFlowEdge::CFLOW_EDGE_TRUE, ControlFlowEdge::isFalseEdge(), ControlFlowEdge::isTrueEdge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outDegree(), BoostGraph< BasicBlockNode, ControlFlowEdge >::outEdge(), ControlFlowEdge::setPredicate(), ControlFlowEdge::toString(), BasicBlockNode::toString(), and GraphBase< BasicBlockNode, ControlFlowEdge >::writeToDotFile().
Referenced by PreOptimizer::handleCFGDDG().
void ControlFlowGraph::sanitize | ( | ) |
Sanitizes CFG back to a format where there are no jumps to middle of a BB, And where the instruction index 0 of all basic blocks really mean the first instructions. The delay slot filler may generate such "insane" CFGs which breaks these. So this should be run after the delay slot filler to make the CFG sane again.
Definition at line 2938 of file ControlFlowGraph.cc.
References assert, TTAProgram::InstructionReferenceManager::createReference(), TTAProgram::TerminalInstructionReference::equals(), findJumpAddress(), BoostGraph< BasicBlockNode, ControlFlowEdge >::inEdges(), instructionReferenceManager(), BoostGraph< BasicBlockNode, ControlFlowEdge >::moveInEdge(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), splitBB(), BoostGraph< BasicBlockNode, ControlFlowEdge >::tailNode(), and GraphBase< BasicBlockNode, ControlFlowEdge >::writeToDotFile().
|
inline |
Definition at line 142 of file ControlFlowGraph.hh.
References irm_.
Referenced by llvm::LLVMTCEIRBuilder::buildTCECFG(), and llvm::LLVMTCEIRBuilder::writeMachineFunction().
|
private |
Definition at line 2878 of file ControlFlowGraph.cc.
References TTAProgram::CodeSnippet::add(), BoostGraph< BasicBlockNode, ControlFlowEdge >::addNode(), BasicBlockNode::basicBlock(), ControlFlowEdge::CFLOW_EDGE_CALL, ControlFlowEdge::CFLOW_EDGE_NORMAL, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), LiveRangeData::inlineAsmClobbers_, LiveRangeData::inlineAsmRegDefs_, LiveRangeData::inlineAsmRegUses_, TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), BasicBlockNode::isScheduled(), TTAProgram::BasicBlock::liveRangeData_, BoostGraph< BasicBlockNode, ControlFlowEdge >::moveOutEdges(), TTAProgram::CodeSnippet::remove(), and BasicBlockNode::setScheduled().
Referenced by splitBasicBlocksWithCallsAndRefs().
void ControlFlowGraph::splitBasicBlocksWithCallsAndRefs | ( | ) |
Checks if the basic blocks have calls in the middle of them and splits them to multiple basic blocks with call edge chains.
TCE scheduler assumes there cannot be calls in the middle of basic block.
Definition at line 2850 of file ControlFlowGraph.cc.
References assert, BasicBlockNode::basicBlock(), TTAProgram::Instruction::hasCall(), TTAProgram::InstructionReferenceManager::hasReference(), TTAProgram::CodeSnippet::instructionAt(), TTAProgram::CodeSnippet::instructionCount(), irm_, TTAProgram::CodeSnippet::lastInstruction(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), and splitBasicBlockAtIndex().
Referenced by llvm::LLVMTCEIRBuilder::buildTCECFG().
BasicBlockNode * ControlFlowGraph::splitBB | ( | BasicBlockNode & | n, |
int | remainingSize | ||
) |
Splits a basic block into two parts.
n | basic block node being splitted |
remainingSize | remaining effective size of the first bb, or index of the instruction starting the new BB. |
Definition at line 3075 of file ControlFlowGraph.cc.
References TTAProgram::CodeSnippet::add(), BoostGraph< BasicBlockNode, ControlFlowEdge >::addNode(), BasicBlockNode::basicBlock(), ControlFlowEdge::CFLOW_EDGE_FALLTHROUGH, ControlFlowEdge::CFLOW_EDGE_NORMAL, BoostGraph< BasicBlockNode, ControlFlowEdge >::connectNodes(), TTAProgram::CodeSnippet::instructionCount(), BasicBlockNode::isScheduled(), BasicBlockNode::link(), BoostGraph< BasicBlockNode, ControlFlowEdge >::moveOutEdges(), TTAProgram::CodeSnippet::remove(), BasicBlockNode::setScheduled(), and TTAProgram::BasicBlock::skippedFirstInstructions().
Referenced by sanitize().
const CFGStatistics & ControlFlowGraph::statistics | ( | ) |
Returns basic statistics about control flow graph in statistic object.
Definition at line 1308 of file ControlFlowGraph.cc.
References TTAProgram::BasicBlockStatistics::bypassedCount(), TTAProgram::BasicBlockStatistics::immediateCount(), TTAProgram::BasicBlockStatistics::instructionCount(), BasicBlockNode::isNormalBB(), TTAProgram::BasicBlockStatistics::moveCount(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), TTAProgram::BasicBlockStatistics::setBypassedCount(), TTAProgram::BasicBlockStatistics::setImmediateCount(), TTAProgram::BasicBlockStatistics::setInstructionCount(), CFGStatistics::setMaxBypassedCount(), CFGStatistics::setMaxImmediateCount(), CFGStatistics::setMaxInstructionCount(), CFGStatistics::setMaxMoveCount(), TTAProgram::BasicBlockStatistics::setMoveCount(), CFGStatistics::setNormalBBCount(), and BasicBlockNode::statistics().
Referenced by printStatistics().
void ControlFlowGraph::updateReferencesFromProcToCfg | ( | ) |
Updates instruction references from procedure to cfg Which is constructed from the procedure.
Definition at line 2207 of file ControlFlowGraph.cc.
References assert, TTAProgram::InstructionReferenceManager::hasReference(), TTAProgram::CodeSnippet::instructionAtIndex(), TTAProgram::CodeSnippet::instructionCount(), TTAProgram::Program::instructionReferenceManager(), BoostGraph< BasicBlockNode, ControlFlowEdge >::node(), BoostGraph< BasicBlockNode, ControlFlowEdge >::nodeCount(), procedure_, program_, and BasicBlockNode::updateReferencesFromProcToCfg().
Referenced by SimpleIfConverter::handleProcedure(), PreOptimizer::handleProcedure(), and BBSchedulerController::handleProcedure().
|
friend |
Definition at line 121 of file ControlFlowGraph.hh.
|
friend |
Definition at line 122 of file ControlFlowGraph.hh.
|
private |
Definition at line 322 of file ControlFlowGraph.hh.
Referenced by alignment(), and buildFrom().
|
mutableprivate |
Definition at line 347 of file ControlFlowGraph.hh.
Referenced by getMBB().
|
private |
Definition at line 326 of file ControlFlowGraph.hh.
Referenced by addExit(), createBBEdges(), createBlock(), and createControlFlowEdge().
|
private |
Definition at line 333 of file ControlFlowGraph.hh.
|
private |
Definition at line 321 of file ControlFlowGraph.hh.
Referenced by buildFrom(), computeLeadersFromRefManager(), and computeLeadersFromRelocations().
|
private |
Definition at line 343 of file ControlFlowGraph.hh.
Referenced by instructionReferenceManager(), setInstructionReferenceManager(), and splitBasicBlocksWithCallsAndRefs().
|
private |
Definition at line 332 of file ControlFlowGraph.hh.
|
private |
Definition at line 339 of file ControlFlowGraph.hh.
|
private |
Definition at line 319 of file ControlFlowGraph.hh.
Referenced by buildFrom(), and updateReferencesFromProcToCfg().
|
private |
Definition at line 317 of file ControlFlowGraph.hh.
Referenced by buildFrom(), ControlFlowGraph(), and procedureName().
|
private |
Definition at line 318 of file ControlFlowGraph.hh.
Referenced by buildFrom(), copyToLLVMMachineFunction(), copyToProcedure(), createBBEdges(), instructionReferenceManager(), program(), and updateReferencesFromProcToCfg().
|
mutableprivate |
For LLVM conversion: mapping of created MachineInstructions to TCE ProgramOperations.
Definition at line 355 of file ControlFlowGraph.hh.
Referenced by buildMBBFromBB(), and copyToLLVMMachineFunction().
|
private |
Definition at line 336 of file ControlFlowGraph.hh.
Referenced by addExit(), and indirectJump().
|
private |
Definition at line 320 of file ControlFlowGraph.hh.
Referenced by buildFrom(), computeLeadersFromRefManager(), computeLeadersFromRelocations(), and createBlock().
|
mutableprivate |
For LLVM conversion: the dummy label instructions for SPU should be created for with the given MCSymbol as argument after building.
Definition at line 351 of file ControlFlowGraph.hh.
Referenced by buildMBBFromBB(), and copyToLLVMMachineFunction().