30 #include "instruction.h"
59 std::shared_ptr<InstructionSequence> m_source, m_target;
66 Edge(std::shared_ptr<InstructionSequence> source, std::shared_ptr<InstructionSequence> target,
EdgeKind kind);
75 std::shared_ptr<InstructionSequence>
get_source()
const {
return m_source; }
79 std::shared_ptr<InstructionSequence>
get_target()
const {
return m_target; }
89 typedef std::vector<std::shared_ptr<InstructionSequence> >
BlockList;
99 std::shared_ptr<InstructionSequence> m_entry, m_exit;
112 void append(std::shared_ptr<InstructionSequence> bb) {
113 blocks.push_back(bb);
116 void prepend(std::shared_ptr<InstructionSequence> bb) {
117 blocks.insert(blocks.begin(), bb);
121 Chunk *merge_with(Chunk *other) {
122 Chunk *merged =
new Chunk();
123 for (
auto i = blocks.begin(); i != blocks.end(); i++) {
126 for (
auto i = other->blocks.begin(); i != other->blocks.end(); i++) {
132 bool is_first(std::shared_ptr<InstructionSequence> bb)
const {
133 return !blocks.empty() && blocks.front() == bb;
136 bool is_last(std::shared_ptr<InstructionSequence> bb)
const {
137 return !blocks.empty() && blocks.back() == bb;
140 bool contains_exit_block()
const {
return is_exit; }
162 std::shared_ptr<InstructionSequence>
get_block(
unsigned id)
const {
163 assert(
id < m_basic_blocks.size());
164 return m_basic_blocks[id];
172 BlockList::const_iterator
bb_begin()
const {
return m_basic_blocks.cbegin(); }
177 BlockList::const_iterator
bb_end()
const {
return m_basic_blocks.cend(); }
206 Edge *
create_edge(std::shared_ptr<InstructionSequence> source, std::shared_ptr<InstructionSequence> target,
EdgeKind kind);
214 Edge *
lookup_edge(std::shared_ptr<InstructionSequence> source, std::shared_ptr<InstructionSequence> target)
const;
233 std::vector<std::shared_ptr<InstructionSequence> > get_blocks_in_code_order()
const;
234 bool can_use_original_block_order()
const;
235 std::shared_ptr<InstructionSequence> rebuild_instruction_sequence()
const;
236 std::shared_ptr<InstructionSequence> reconstruct_instruction_sequence()
const;
237 void append_basic_block(std::shared_ptr<InstructionSequence> &iseq, std::shared_ptr<InstructionSequence> bb, std::vector<bool> &finished_blocks)
const;
238 void append_chunk(std::shared_ptr<InstructionSequence> &iseq, Chunk *chunk, std::vector<bool> &finished_blocks)
const;
239 void visit_successors(std::shared_ptr<InstructionSequence> bb, std::deque<std::shared_ptr<InstructionSequence> > &work_list)
const;
240 void delete_edges(
EdgeMap &edge_map);
EdgeKind
Control-flow graph edge kinds.
Definition: cfg.h:48
ControlFlowGraph: graph of basic blocks connected by control edges.
Definition: cfg.h:86
std::vector< Edge * > EdgeList
Data type for a vector of edges.
Definition: cfg.h:92
BlockList::const_iterator bb_end() const
Get an end iterator for the list of all basic blocks in the ControlFlowGraph.
Definition: cfg.h:177
const EdgeList & get_incoming_edges(std::shared_ptr< InstructionSequence > bb) const
Get vector of all incoming edges to given block.
Definition: cfg.cpp:135
std::vector< std::shared_ptr< InstructionSequence > > BlockList
Data type for a vector of basic blocks.
Definition: cfg.h:89
Edge * create_edge(std::shared_ptr< InstructionSequence > source, std::shared_ptr< InstructionSequence > target, EdgeKind kind)
Create Edge of given kind from source basic block to target basic block.
Definition: cfg.cpp:98
std::shared_ptr< InstructionSequence > create_basic_block(BasicBlockKind kind, int code_order, const std::string &label="")
Create a new InstructionSequence.
Definition: cfg.cpp:74
BlockList::const_iterator bb_begin() const
Get a begin iterator for the list of all basic blocks in the ControlFlowGraph.
Definition: cfg.h:172
unsigned get_num_blocks() const
Get total number of basic blocks (including entry and exit).
Definition: cfg.h:149
const EdgeList & get_outgoing_edges(std::shared_ptr< InstructionSequence > bb) const
Get vector of all outgoing edges from given block.
Definition: cfg.cpp:130
std::shared_ptr< InstructionSequence > get_entry_block() const
Get pointer to the dedicated empty entry block.
Definition: cfg.cpp:66
std::shared_ptr< InstructionSequence > create_instruction_sequence() const
Return a "flat" InstructionSequence created from this ControlFlowGraph.
Definition: cfg.cpp:140
std::shared_ptr< InstructionSequence > get_exit_block() const
Get pointer to the dedicated empty exit block.
Definition: cfg.cpp:70
std::shared_ptr< InstructionSequence > get_block(unsigned id) const
Get block with specified id.
Definition: cfg.h:162
std::map< std::shared_ptr< InstructionSequence >, EdgeList > EdgeMap
Data type for a map of basic blocks to an EdgeList.
Definition: cfg.h:95
Edge * lookup_edge(std::shared_ptr< InstructionSequence > source, std::shared_ptr< InstructionSequence > target) const
Look up edge from specified source block to target block.
Definition: cfg.cpp:114
void adopt_basic_block(std::shared_ptr< InstructionSequence > &bb)
Adopt a new basic block.
Definition: cfg.cpp:80
Control-flow graph edge data type.
Definition: cfg.h:56
Edge(std::shared_ptr< InstructionSequence > source, std::shared_ptr< InstructionSequence > target, EdgeKind kind)
Constructor.
Definition: cfg.cpp:38
EdgeKind get_kind() const
Get the EdgeKind of this Edge.
Definition: cfg.h:71
std::shared_ptr< InstructionSequence > get_source() const
Get the source basic block.
Definition: cfg.h:75
std::shared_ptr< InstructionSequence > get_target() const
Get the target basic block.
Definition: cfg.h:79
InstructionSequence and friends.
BasicBlockKind
Kinds of basic blocks.
Definition: instruction_seq.h:39
@ BASICBLOCK_EXIT
special "exit" block
Definition: instruction_seq.h:41