diff --git a/src/SDCCnaddr.cc b/src/SDCCnaddr.cc index 1330de3..213d644 100644 --- a/src/SDCCnaddr.cc +++ b/src/SDCCnaddr.cc @@ -21,6 +21,42 @@ #include "SDCCnaddr.hpp" +// A quick-and-dirty function to get the CFG from sdcc (a simplified version of the function from SDCCralloc.hpp). +void +create_cfg_naddr(cfg_t &cfg, iCode *start_ic, ebbIndex *ebbi) +{ + iCode *ic; + + std::map key_to_index; + { + int i; + + for (ic = start_ic, i = 0; ic; ic = ic->next, i++) + { + boost::add_vertex(cfg); + key_to_index[ic->key] = i; + cfg[i].ic = ic; + } + } + + // Get control flow graph from sdcc. + for (ic = start_ic; ic; ic = ic->next) + { + if (ic->op != GOTO && ic->op != RETURN && ic->op != JUMPTABLE && ic->next) + boost::add_edge(key_to_index[ic->key], key_to_index[ic->next->key], 3.0f, cfg); + + if (ic->op == GOTO) + boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, ic->label)->sch->key], 6.0f, cfg); + else if (ic->op == RETURN) + boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, returnLabel)->sch->key], 6.0f, cfg); + else if (ic->op == IFX) + boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, IC_TRUE(ic) ? IC_TRUE(ic) : IC_FALSE(ic))->sch->key], 6.0f, cfg); + else if (ic->op == JUMPTABLE) + for (symbol *lbl = (symbol *)(setFirstItem (IC_JTLABELS (ic))); lbl; lbl = (symbol *)(setNextItem (IC_JTLABELS (ic)))) + boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, lbl)->sch->key], 6.0f, cfg); + } +} + int switchAddressSpacesOptimally (iCode *ic, ebbIndex *ebbi) { diff --git a/src/SDCCnaddr.hpp b/src/SDCCnaddr.hpp index 1cfec51..3096baa 100644 --- a/src/SDCCnaddr.hpp +++ b/src/SDCCnaddr.hpp @@ -48,9 +48,9 @@ extern "C" typedef short int naddrspace_t; // Named address spaces. -1: Undefined, Others: see map. #ifdef HAVE_STX_BTREE_SET_H -typedef stx::btree_set naddrspaceset_t; // Faster than std::set +typedef stx::btree_set naddrspaceset_t; // Faster than std::set #else -typedef std::set naddrspaceset_t; +typedef std::set naddrspaceset_t; #endif struct assignment_naddr @@ -113,45 +113,9 @@ struct tree_dec_naddr_node assignment_list_naddr_t assignments; }; -typedef boost::adjacency_list cfg_t; // The edge property is the cost of subdividing he edge and inserting a bank switching instruction. +typedef boost::adjacency_list cfg_t; // The edge property is the cost of subdividing the edge and inserting a bank switching instruction. typedef boost::adjacency_list tree_dec_naddr_t; -// A quick-and-dirty function to get the CFG from sdcc (a simplified version of the function from SDCCralloc.hpp). -void -create_cfg_naddr(cfg_t &cfg, iCode *start_ic, ebbIndex *ebbi) -{ - iCode *ic; - - std::map key_to_index; - { - int i; - - for (ic = start_ic, i = 0; ic; ic = ic->next, i++) - { - boost::add_vertex(cfg); - key_to_index[ic->key] = i; - cfg[i].ic = ic; - } - } - - // Get control flow graph from sdcc. - for (ic = start_ic; ic; ic = ic->next) - { - if (ic->op != GOTO && ic->op != RETURN && ic->op != JUMPTABLE && ic->next) - boost::add_edge(key_to_index[ic->key], key_to_index[ic->next->key], 3.0f, cfg); - - if (ic->op == GOTO) - boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, ic->label)->sch->key], 6.0f, cfg); - else if (ic->op == RETURN) - boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, returnLabel)->sch->key], 6.0f, cfg); - else if (ic->op == IFX) - boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, IC_TRUE(ic) ? IC_TRUE(ic) : IC_FALSE(ic))->sch->key], 6.0f, cfg); - else if (ic->op == JUMPTABLE) - for (symbol *lbl = (symbol *)(setFirstItem (IC_JTLABELS (ic))); lbl; lbl = (symbol *)(setNextItem (IC_JTLABELS (ic)))) - boost::add_edge(key_to_index[ic->key], key_to_index[eBBWithEntryLabel(ebbi, lbl)->sch->key], 6.0f, cfg); - } -} - // Annotate nodes of the control flow graph with the set of possible named address spaces active there. void annotate_cfg_naddr(cfg_t &cfg, std::map &addrspaces) { @@ -435,7 +399,7 @@ int tree_dec_naddrswitch_nodes(T_t &T, typename boost::graph_traits::vertex } template -void implement_assignment(const assignment_naddr &a, const G_t &G, const std::map addrspaces) +static void implement_naddr_assignment(const assignment_naddr &a, const G_t &G, const std::map addrspaces) { typedef typename boost::graph_traits::vertex_descriptor vertex_t; typedef typename boost::graph_traits::edge_iterator ei_t; @@ -479,7 +443,7 @@ int tree_dec_address_switch(T_t &T, const G_t &G, const std::map= 0; i--) { cfg_sym_t cfg2; - boost::copy_graph(cfg, cfg2); + boost::copy_graph(cfg, cfg2, boost::vertex_copy(forget_properties()).edge_copy(forget_properties())); for (int j = boost::num_vertices(cfg) - 1; j >= 0; j--) { if (cfg[j].alive.find(i) == cfg[j].alive.end()) @@ -436,7 +436,7 @@ create_cfg(cfg_t &cfg, con_t &con, ebbIndex *ebbi) #endif // Non-connected CFGs shouldn't exist either. Another problem with dead code eliminarion. cfg_sym_t cfg2; - boost::copy_graph(cfg, cfg2); + boost::copy_graph(cfg, cfg2, boost::vertex_copy(forget_properties()).edge_copy(forget_properties())); std::vector::vertices_size_type> component(num_vertices(cfg2)); boost::connected_components(cfg2, &component[0]); diff --git a/src/SDCCtree_dec.hpp b/src/SDCCtree_dec.hpp index e5b1de3..2dce8a6 100644 --- a/src/SDCCtree_dec.hpp +++ b/src/SDCCtree_dec.hpp @@ -53,6 +53,14 @@ #include #include +struct forget_properties +{ + template + void operator()(const T1&, const T2&) const + { + } +}; + // Thorup algorithm D. // The use of the multimap makes the complexity of this O(|I|log|I|), which could be reduced to O(|I|). template @@ -97,7 +105,7 @@ template void thorup_E(std::multimap &M, const I_t &I) { typedef typename boost::graph_traits::adjacency_iterator adjacency_iter_t; - typedef typename boost::graph_traits::vertex_iterator vertex_iter_t; +// typedef typename boost::graph_traits::vertex_iterator vertex_iter_t; typedef typename boost::property_map::type index_map; index_map index = boost::get(boost::vertex_index, I); @@ -152,7 +160,7 @@ void thorup_elimination_ordering(l_t &l, const G_t &G) { // Should we do this? Or just use G as J? The Thorup paper seems unclear, it speaks of statements that contain jumps to other statements, but does it count as a jump, when they're just subsequent? boost::adjacency_list J; - boost::copy_graph(G, J); + boost::copy_graph(G, J, boost::vertex_copy(forget_properties()).edge_copy(forget_properties())); for (unsigned int i = 0; i < boost::num_vertices(J) - 1; i++) remove_edge(i, i + 1, J); @@ -256,7 +264,7 @@ void tree_decomposition_from_elimination_ordering(T_t &T, const std::list G_sym; - boost::copy_graph(G, G_sym); + boost::copy_graph(G, G_sym, boost::vertex_copy(forget_properties()).edge_copy(forget_properties())); std::vector active(boost::num_vertices(G), true);