1 // Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de, pkk@spth.de, 2011
3 // (c) 2011 Goethe-Universität Frankfurt
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 2, or (at your option) any
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // Optimal placement of bank switching instructions for named address spaces.
22 #include "SDCCnaddr.hpp"
24 // A quick-and-dirty function to get the CFG from sdcc (a simplified version of the function from SDCCralloc.hpp).
26 create_cfg_naddr(cfg_t
&cfg
, iCode
*start_ic
, ebbIndex
*ebbi
)
30 std::map
<int, unsigned int> key_to_index
;
34 for (ic
= start_ic
, i
= 0; ic
; ic
= ic
->next
, i
++)
36 boost::add_vertex(cfg
);
37 key_to_index
[ic
->key
] = i
;
42 // Get control flow graph from sdcc.
43 for (ic
= start_ic
; ic
; ic
= ic
->next
)
45 if (ic
->op
!= GOTO
&& ic
->op
!= RETURN
&& ic
->op
!= JUMPTABLE
&& ic
->next
)
46 boost::add_edge(key_to_index
[ic
->key
], key_to_index
[ic
->next
->key
], 3.0f
, cfg
);
49 boost::add_edge(key_to_index
[ic
->key
], key_to_index
[eBBWithEntryLabel(ebbi
, ic
->label
)->sch
->key
], 6.0f
, cfg
);
50 else if (ic
->op
== RETURN
)
51 boost::add_edge(key_to_index
[ic
->key
], key_to_index
[eBBWithEntryLabel(ebbi
, returnLabel
)->sch
->key
], 6.0f
, cfg
);
52 else if (ic
->op
== IFX
)
53 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
);
54 else if (ic
->op
== JUMPTABLE
)
55 for (symbol
*lbl
= (symbol
*)(setFirstItem (IC_JTLABELS (ic
))); lbl
; lbl
= (symbol
*)(setNextItem (IC_JTLABELS (ic
))))
56 boost::add_edge(key_to_index
[ic
->key
], key_to_index
[eBBWithEntryLabel(ebbi
, lbl
)->sch
->key
], 6.0f
, cfg
);
61 switchAddressSpacesOptimally (iCode
*ic
, ebbIndex
*ebbi
)
63 cfg_t control_flow_graph
;
64 tree_dec_t tree_decomposition
;
65 std::map
<naddrspace_t
, const symbol
*> addrspaces
;
67 create_cfg_naddr(control_flow_graph
, ic
, ebbi
);
68 annotate_cfg_naddr(control_flow_graph
, addrspaces
);
70 if(options
.dump_graphs
)
71 dump_cfg_naddr(control_flow_graph
);
73 get_nice_tree_decomposition (tree_decomposition
, control_flow_graph
);
75 if(options
.dump_graphs
)
76 dump_tree_decomposition_naddr(tree_decomposition
);
78 return(tree_dec_address_switch(tree_decomposition
, control_flow_graph
, addrspaces
));