summaryrefslogtreecommitdiff
path: root/src/SDCCnaddr.cc
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /src/SDCCnaddr.cc
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'src/SDCCnaddr.cc')
-rw-r--r--src/SDCCnaddr.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/SDCCnaddr.cc b/src/SDCCnaddr.cc
new file mode 100644
index 0000000..d867f6c
--- /dev/null
+++ b/src/SDCCnaddr.cc
@@ -0,0 +1,80 @@
+// Philipp Klaus Krause, philipp@informatik.uni-frankfurt.de, pkk@spth.de, 2011
+//
+// (c) 2011 Goethe-Universität Frankfurt
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option) any
+// later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+//
+// Optimal placement of bank switching instructions for named address spaces.
+
+#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<int, unsigned int> 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)
+{
+ cfg_t control_flow_graph;
+ tree_dec_t tree_decomposition;
+ std::map<naddrspace_t, const symbol *> addrspaces;
+
+ create_cfg_naddr(control_flow_graph, ic, ebbi);
+ annotate_cfg_naddr(control_flow_graph, addrspaces);
+
+ if(options.dump_graphs)
+ dump_cfg_naddr(control_flow_graph);
+
+ get_nice_tree_decomposition (tree_decomposition, control_flow_graph);
+
+ if(options.dump_graphs)
+ dump_tree_decomposition_naddr(tree_decomposition);
+
+ return(tree_dec_address_switch(tree_decomposition, control_flow_graph, addrspaces));
+}
+