From 1ec30d95387eb392ba5a1adc7958ebd91383d59c Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 1 Jun 2007 15:47:30 +0000 Subject: [PATCH] moved external headers into include dir [r14240] --- Makefile.in | 2 +- {ir/common => include}/firm_types.h | 0 {ir/ana => include/libfirm}/absgraph.h | 0 .../libfirm}/analyze_irg_args.h | 2 +- {ir/arch => include/libfirm}/archop.h | 0 {ir/be => include/libfirm}/be.h | 2 +- {ir/ana => include/libfirm}/callgraph.h | 0 {ir/ana => include/libfirm}/cdep.h | 0 {ir/ana => include/libfirm}/cgana.h | 2 +- .../libfirm}/compute_loop_info.h | 0 {ir/debug => include/libfirm}/dbginfo.h | 3 +- {ir/ana => include/libfirm}/dfs.h | 0 {ir/ana => include/libfirm}/execfreq.h | 5 - .../libfirm}/execution_frequency.h | 0 .../libfirm}/field_temperature.h | 0 {ir/common => include/libfirm}/firm.h | 30 +- {ir/common => include/libfirm}/firm_common.h | 0 include/libfirm/firm_types.h | 69 + {ir/debug => include/libfirm}/firm_ycomp.h | 0 {ir/stat => include/libfirm}/firmstat.h | 0 {ir/ana => include/libfirm}/height.h | 0 {ir/ident => include/libfirm}/ident.h | 38 +- .../libfirm}/interval_analysis.h | 0 {ir/ir => include/libfirm}/irarch.h | 0 {ir/ir => include/libfirm}/ircgcons.h | 0 {ir/ir => include/libfirm}/ircgopt.h | 0 {ir/ir => include/libfirm}/ircons.h | 0 {ir/ana => include/libfirm}/irconsconfirm.h | 0 {ir/ana => include/libfirm}/irdom.h | 0 {ir/ir => include/libfirm}/irdump.h | 0 {ir/ir => include/libfirm}/iredgekinds.h | 0 {ir/ir => include/libfirm}/iredges.h | 5 - {ir/ana => include/libfirm}/irextbb.h | 5 - {ir/ir => include/libfirm}/irflag.h | 0 {ir/ir => include/libfirm}/irgmod.h | 0 {ir/ir => include/libfirm}/irgopt.h | 0 {ir/ir => include/libfirm}/irgraph.h | 2 +- {ir/ir => include/libfirm}/irgwalk.h | 12 - {ir/ir => include/libfirm}/irhooks.h | 0 {ir/ana => include/libfirm}/irlivechk.h | 0 {ir/ana => include/libfirm}/irloop.h | 23 +- {ir/ana => include/libfirm}/irmemory.h | 0 {ir/ir => include/libfirm}/irmode.h | 26 - {ir/ir => include/libfirm}/irnode.h | 60 +- {ir/ir => include/libfirm}/irop.h | 5 - {ir/ir => include/libfirm}/iropt.h | 0 {ir/ir => include/libfirm}/iropt_dbg.h | 0 include/libfirm/iroptimize.h | 496 ++++++ {ir/ana => include/libfirm}/irouts.h | 0 {ir/ir => include/libfirm}/irprintf.h | 0 {ir/ir => include/libfirm}/irprog.h | 0 {ir/ana => include/libfirm}/irsimpletype.h | 2 +- {ir/ana => include/libfirm}/irtypeinfo.h | 0 {ir/ir => include/libfirm}/irvrfy.h | 0 {ir/lower => include/libfirm}/lower_calls.h | 0 {ir/lower => include/libfirm}/lower_dw.h | 0 {ir/lower => include/libfirm}/lower_hl.h | 0 .../libfirm}/lower_intrinsics.h | 0 {ir/common => include/libfirm}/old_fctnames.h | 0 {ir/ana => include/libfirm}/phiclass.h | 0 {ir/ana => include/libfirm}/rta.h | 0 {ir/debug => include/libfirm}/seqnumbers.h | 6 +- {ir/ana => include/libfirm}/structure.h | 0 {ir/ana => include/libfirm}/trouts.h | 0 {ir/tv => include/libfirm}/tv.h | 5 - ir/tr/type.h => include/libfirm/typerep.h | 1502 +++++++++++++++-- ir/ana/callgraph.c | 2 - ir/ana/compute_loop_info.c | 2 +- ir/ana/field_temperature.c | 6 +- ir/ana/interval_analysis.c | 24 +- ir/ana/ircfscc.c | 2 - ir/ana/irloop_t.h | 17 +- ir/ana/irscc.c | 43 +- ir/ana/irsimpletype.c | 7 +- ir/ana/rta.c | 22 +- ir/ana2/Makefile.in | 41 - ir/ana2/ecg.c | 1364 --------------- ir/ana2/ecg.h | 128 -- ir/ana2/gnu_ext.h | 73 - ir/ana2/irmemwalk.c | 313 ---- ir/ana2/irmemwalk.h | 49 - ir/ana2/lset.c | 227 --- ir/ana2/lset.h | 90 - ir/ana2/pto.c | 185 -- ir/ana2/pto.h | 75 - ir/ana2/pto_comp.c | 837 --------- ir/ana2/pto_comp.h | 94 -- ir/ana2/pto_ctx.c | 123 -- ir/ana2/pto_ctx.h | 79 - ir/ana2/pto_debug.c | 105 -- ir/ana2/pto_debug.h | 83 - ir/ana2/pto_init.c | 521 ------ ir/ana2/pto_init.h | 85 - ir/ana2/pto_mod.c | 119 -- ir/ana2/pto_mod.h | 71 - ir/ana2/pto_name.c | 732 -------- ir/ana2/pto_name.h | 152 -- ir/ana2/pto_util.c | 215 --- ir/ana2/pto_util.h | 87 - ir/ana2/qset.c | 786 --------- ir/ana2/qset.h | 129 -- ir/ana2/timing.c | 134 -- ir/ana2/timing.h | 55 - ir/ana2/typalise.c | 937 ---------- ir/ana2/typalise.h | 98 -- ir/arch/modeconv.c | 260 --- ir/arch/modeconv.h | 44 - ir/be/TEMPLATE/TEMPLATE_transform.c | 2 +- ir/be/TEMPLATE/bearch_TEMPLATE.c | 7 +- ir/be/TEMPLATE/bearch_TEMPLATE_t.h | 2 +- ir/be/arm/arm_nodes_attr.h | 2 +- ir/be/arm/arm_transform.c | 2 +- ir/be/arm/bearch_arm.c | 2 +- ir/be/arm/bearch_arm_t.h | 2 +- ir/be/beabi.c | 1 - ir/be/bearch.c | 1 - ir/be/begnuas.c | 1 - ir/be/bemain.c | 2 - ir/be/benode_t.h | 5 +- ir/be/beprofile.c | 3 +- ir/be/bespillslots.c | 1 - ir/be/bestabs.c | 2 - ir/be/beverify.c | 17 +- ir/be/firm/bearch_firm.c | 1 - ir/be/ia32/bearch_ia32.c | 2 +- ir/be/ia32/bearch_ia32_t.h | 2 +- ir/be/ia32/ia32_intrinsics.c | 1 - ir/be/ia32/ia32_transform.c | 2 - ir/be/mips/bearch_mips.c | 2 +- ir/be/mips/bearch_mips_t.h | 2 +- ir/be/mips/mips_scheduler.c | 2 +- ir/be/mips/mips_transform.c | 2 +- ir/be/ppc32/bearch_ppc32.c | 2 +- ir/be/ppc32/bearch_ppc32_t.h | 2 +- ir/be/ppc32/ppc32_transform.c | 2 +- ir/common/firm.c | 5 - ir/common/firmwalk.c | 1 - ir/debug/debugger.c | 3 +- ir/external/read.c | 11 +- ir/{tr => ident}/mangle.c | 4 +- ir/ir/irarch.c | 10 - ir/ir/ircgopt.c | 1 - ir/ir/irdump.c | 2 - ir/ir/irdumptxt.c | 4 +- ir/ir/irgmod.c | 5 +- ir/ir/irgopt.c | 2 +- ir/ir/irgraph.c | 1 - ir/ir/irgraph_t.h | 2 - ir/ir/irgwalk.c | 1 - ir/ir/irmode_t.h | 22 +- ir/ir/irnode.c | 1 - ir/ir/iropt.c | 4 +- ir/ir/irprog.c | 1 - ir/ir/irprog_t.h | 2 - ir/ir/irreflect.c | 504 ------ ir/ir/irreflect.def | 481 ------ ir/ir/irreflect.h | 237 --- ir/ir/irreflect_t.h | 32 - ir/lower/lower_calls.c | 3 +- ir/lower/lower_hl.c | 2 +- ir/opt/cfopt.c | 3 +- ir/opt/cfopt.h | 47 - ir/opt/condeval.c | 3 +- ir/opt/condeval.h | 38 - ir/opt/convopt.c | 3 +- ir/opt/convopt.h | 38 - ir/opt/data_flow_scalar_replace.c | 11 +- ir/opt/data_flow_scalar_replace.h | 40 - ir/opt/escape_ana.c | 4 +- ir/opt/escape_ana.h | 71 - ir/opt/funccall.c | 3 +- ir/opt/funccall.h | 64 - ir/opt/gvn_pre.c | 5 +- ir/opt/gvn_pre.h | 47 - ir/opt/ifconv.c | 3 +- ir/opt/ifconv.h | 75 - ir/opt/ldst2.c | 4 +- ir/opt/ldst2.h | 33 - ir/opt/ldstopt.c | 5 +- ir/opt/ldstopt.h | 57 - ir/opt/loop_unrolling.c | 7 +- ir/opt/loop_unrolling.h | 48 - ir/opt/opt_frame.c | 2 +- ir/opt/opt_frame.h | 52 - ir/opt/opt_osr.c | 2 +- ir/opt/opt_osr.h | 120 -- ir/opt/opt_polymorphy.c | 1 + ir/opt/opt_polymorphy.h | 8 - ir/opt/proc_cloning.c | 6 +- ir/opt/proc_cloning.h | 47 - ir/opt/reassoc.c | 2 +- ir/opt/reassoc.h | 60 - ir/opt/reassoc_t.h | 6 +- ir/opt/return.c | 1 + ir/opt/return.h | 75 - ir/opt/scalar_replace.c | 3 +- ir/opt/scalar_replace.h | 9 - ir/opt/strength_red.c | 39 +- ir/opt/strength_red.h | 78 - ir/opt/tailrec.c | 9 +- ir/opt/tailrec.h | 50 - ir/opt/tropt.c | 6 +- ir/opt/tropt.h | 96 -- ir/st/Makefile.in | 34 - ir/st/bs.h | 54 - ir/st/exc.c | 262 --- ir/st/exc.h | 94 -- ir/st/st.c | 554 ------ ir/st/st.h | 86 - ir/tr/entity.c | 15 +- ir/tr/entity.h | 648 ------- ir/tr/entity_t.h | 7 +- ir/tr/mangle.h | 52 - ir/tr/tpop.h | 226 --- ir/tr/tpop_t.h | 2 +- ir/tr/tr_inheritance.c | 17 +- ir/tr/tr_inheritance.h | 250 --- ir/tr/trvrfy.c | 2 - ir/tr/trvrfy.h | 89 - ir/tr/type.c | 2 - ir/tr/type_identify.c | 4 +- ir/tr/type_identify.h | 140 -- ir/tr/type_or_entity.h | 38 - ir/tr/type_t.h | 66 +- ir/tr/typegmod.c | 1 - ir/tr/typegmod.h | 63 - ir/tr/typewalk.c | 3 - ir/tr/typewalk.h | 134 -- 228 files changed, 2187 insertions(+), 14070 deletions(-) rename {ir/common => include}/firm_types.h (100%) rename {ir/ana => include/libfirm}/absgraph.h (100%) rename {ir/ana => include/libfirm}/analyze_irg_args.h (98%) rename {ir/arch => include/libfirm}/archop.h (100%) rename {ir/be => include/libfirm}/be.h (99%) rename {ir/ana => include/libfirm}/callgraph.h (100%) rename {ir/ana => include/libfirm}/cdep.h (100%) rename {ir/ana => include/libfirm}/cgana.h (99%) rename {ir/ana => include/libfirm}/compute_loop_info.h (100%) rename {ir/debug => include/libfirm}/dbginfo.h (99%) rename {ir/ana => include/libfirm}/dfs.h (100%) rename {ir/ana => include/libfirm}/execfreq.h (93%) rename {ir/ana => include/libfirm}/execution_frequency.h (100%) rename {ir/ana => include/libfirm}/field_temperature.h (100%) rename {ir/common => include/libfirm}/firm.h (82%) rename {ir/common => include/libfirm}/firm_common.h (100%) create mode 100644 include/libfirm/firm_types.h rename {ir/debug => include/libfirm}/firm_ycomp.h (100%) rename {ir/stat => include/libfirm}/firmstat.h (100%) rename {ir/ana => include/libfirm}/height.h (100%) rename {ir/ident => include/libfirm}/ident.h (90%) rename {ir/ana => include/libfirm}/interval_analysis.h (100%) rename {ir/ir => include/libfirm}/irarch.h (100%) rename {ir/ir => include/libfirm}/ircgcons.h (100%) rename {ir/ir => include/libfirm}/ircgopt.h (100%) rename {ir/ir => include/libfirm}/ircons.h (100%) rename {ir/ana => include/libfirm}/irconsconfirm.h (100%) rename {ir/ana => include/libfirm}/irdom.h (100%) rename {ir/ir => include/libfirm}/irdump.h (100%) rename {ir/ir => include/libfirm}/iredgekinds.h (100%) rename {ir/ir => include/libfirm}/iredges.h (98%) rename {ir/ana => include/libfirm}/irextbb.h (98%) rename {ir/ir => include/libfirm}/irflag.h (100%) rename {ir/ir => include/libfirm}/irgmod.h (100%) rename {ir/ir => include/libfirm}/irgopt.h (100%) rename {ir/ir => include/libfirm}/irgraph.h (99%) rename {ir/ir => include/libfirm}/irgwalk.h (96%) rename {ir/ir => include/libfirm}/irhooks.h (100%) rename {ir/ana => include/libfirm}/irlivechk.h (100%) rename {ir/ana => include/libfirm}/irloop.h (89%) rename {ir/ana => include/libfirm}/irmemory.h (100%) rename {ir/ir => include/libfirm}/irmode.h (94%) rename {ir/ir => include/libfirm}/irnode.h (94%) rename {ir/ir => include/libfirm}/irop.h (99%) rename {ir/ir => include/libfirm}/iropt.h (100%) rename {ir/ir => include/libfirm}/iropt_dbg.h (100%) create mode 100644 include/libfirm/iroptimize.h rename {ir/ana => include/libfirm}/irouts.h (100%) rename {ir/ir => include/libfirm}/irprintf.h (100%) rename {ir/ir => include/libfirm}/irprog.h (100%) rename {ir/ana => include/libfirm}/irsimpletype.h (99%) rename {ir/ana => include/libfirm}/irtypeinfo.h (100%) rename {ir/ir => include/libfirm}/irvrfy.h (100%) rename {ir/lower => include/libfirm}/lower_calls.h (100%) rename {ir/lower => include/libfirm}/lower_dw.h (100%) rename {ir/lower => include/libfirm}/lower_hl.h (100%) rename {ir/lower => include/libfirm}/lower_intrinsics.h (100%) rename {ir/common => include/libfirm}/old_fctnames.h (100%) rename {ir/ana => include/libfirm}/phiclass.h (100%) rename {ir/ana => include/libfirm}/rta.h (100%) rename {ir/debug => include/libfirm}/seqnumbers.h (96%) rename {ir/ana => include/libfirm}/structure.h (100%) rename {ir/ana => include/libfirm}/trouts.h (100%) rename {ir/tv => include/libfirm}/tv.h (99%) rename ir/tr/type.h => include/libfirm/typerep.h (51%) delete mode 100644 ir/ana2/Makefile.in delete mode 100644 ir/ana2/ecg.c delete mode 100644 ir/ana2/ecg.h delete mode 100644 ir/ana2/gnu_ext.h delete mode 100644 ir/ana2/irmemwalk.c delete mode 100644 ir/ana2/irmemwalk.h delete mode 100644 ir/ana2/lset.c delete mode 100644 ir/ana2/lset.h delete mode 100644 ir/ana2/pto.c delete mode 100644 ir/ana2/pto.h delete mode 100644 ir/ana2/pto_comp.c delete mode 100644 ir/ana2/pto_comp.h delete mode 100644 ir/ana2/pto_ctx.c delete mode 100644 ir/ana2/pto_ctx.h delete mode 100644 ir/ana2/pto_debug.c delete mode 100644 ir/ana2/pto_debug.h delete mode 100644 ir/ana2/pto_init.c delete mode 100644 ir/ana2/pto_init.h delete mode 100644 ir/ana2/pto_mod.c delete mode 100644 ir/ana2/pto_mod.h delete mode 100644 ir/ana2/pto_name.c delete mode 100644 ir/ana2/pto_name.h delete mode 100644 ir/ana2/pto_util.c delete mode 100644 ir/ana2/pto_util.h delete mode 100644 ir/ana2/qset.c delete mode 100644 ir/ana2/qset.h delete mode 100644 ir/ana2/timing.c delete mode 100644 ir/ana2/timing.h delete mode 100644 ir/ana2/typalise.c delete mode 100644 ir/ana2/typalise.h delete mode 100644 ir/arch/modeconv.c delete mode 100644 ir/arch/modeconv.h rename ir/{tr => ident}/mangle.c (98%) delete mode 100644 ir/ir/irreflect.c delete mode 100644 ir/ir/irreflect.def delete mode 100644 ir/ir/irreflect.h delete mode 100644 ir/ir/irreflect_t.h delete mode 100644 ir/opt/cfopt.h delete mode 100644 ir/opt/condeval.h delete mode 100644 ir/opt/convopt.h delete mode 100644 ir/opt/data_flow_scalar_replace.h delete mode 100644 ir/opt/escape_ana.h delete mode 100644 ir/opt/funccall.h delete mode 100644 ir/opt/gvn_pre.h delete mode 100644 ir/opt/ifconv.h delete mode 100644 ir/opt/ldst2.h delete mode 100644 ir/opt/ldstopt.h delete mode 100644 ir/opt/loop_unrolling.h delete mode 100644 ir/opt/opt_frame.h delete mode 100644 ir/opt/opt_osr.h delete mode 100644 ir/opt/proc_cloning.h delete mode 100644 ir/opt/reassoc.h delete mode 100644 ir/opt/return.h delete mode 100644 ir/opt/strength_red.h delete mode 100644 ir/opt/tailrec.h delete mode 100644 ir/opt/tropt.h delete mode 100644 ir/st/Makefile.in delete mode 100644 ir/st/bs.h delete mode 100644 ir/st/exc.c delete mode 100644 ir/st/exc.h delete mode 100644 ir/st/st.c delete mode 100644 ir/st/st.h delete mode 100644 ir/tr/entity.h delete mode 100644 ir/tr/mangle.h delete mode 100644 ir/tr/tpop.h delete mode 100644 ir/tr/tr_inheritance.h delete mode 100644 ir/tr/trvrfy.h delete mode 100644 ir/tr/type_identify.h delete mode 100644 ir/tr/type_or_entity.h delete mode 100644 ir/tr/typegmod.h delete mode 100644 ir/tr/typewalk.h diff --git a/Makefile.in b/Makefile.in index a8ad6ffe6..01f22c5ad 100644 --- a/Makefile.in +++ b/Makefile.in @@ -39,7 +39,7 @@ LIBS = @LIBS@ $(LIBCORE_LIBS) plugin_subdirs := @plugin_subdirs@ build_subdirs := ir/adt ir/net ir/debug ir/tv ir/common ir/ident ir/ir \ - ir/opt ir/tr ir/ana ir/stat ir/ana2 ir/arch ir/lower \ + ir/opt ir/tr ir/ana ir/stat ir/arch ir/lower include/libfirm \ $(plugin_subdirs) ifeq ($(enable_external_effects),yes) diff --git a/ir/common/firm_types.h b/include/firm_types.h similarity index 100% rename from ir/common/firm_types.h rename to include/firm_types.h diff --git a/ir/ana/absgraph.h b/include/libfirm/absgraph.h similarity index 100% rename from ir/ana/absgraph.h rename to include/libfirm/absgraph.h diff --git a/ir/ana/analyze_irg_args.h b/include/libfirm/analyze_irg_args.h similarity index 98% rename from ir/ana/analyze_irg_args.h rename to include/libfirm/analyze_irg_args.h index 1323b34ba..beb51a1c4 100644 --- a/ir/ana/analyze_irg_args.h +++ b/include/libfirm/analyze_irg_args.h @@ -27,7 +27,7 @@ #define FIRM_ANA_ANALYZE_IRG_ARGS_H #include "irgraph.h" -#include "entity.h" +#include "firm_types.h" /** * Returns for a method with pointer parameter diff --git a/ir/arch/archop.h b/include/libfirm/archop.h similarity index 100% rename from ir/arch/archop.h rename to include/libfirm/archop.h diff --git a/ir/be/be.h b/include/libfirm/be.h similarity index 99% rename from ir/be/be.h rename to include/libfirm/be.h index 69cf8b39e..998dd9f5d 100644 --- a/ir/be/be.h +++ b/include/libfirm/be.h @@ -31,7 +31,7 @@ #include "archop.h" #include "lower_dw.h" #include "dbginfo.h" -#include "ifconv.h" +#include "iroptimize.h" #include diff --git a/ir/ana/callgraph.h b/include/libfirm/callgraph.h similarity index 100% rename from ir/ana/callgraph.h rename to include/libfirm/callgraph.h diff --git a/ir/ana/cdep.h b/include/libfirm/cdep.h similarity index 100% rename from ir/ana/cdep.h rename to include/libfirm/cdep.h diff --git a/ir/ana/cgana.h b/include/libfirm/cgana.h similarity index 99% rename from ir/ana/cgana.h rename to include/libfirm/cgana.h index 0af3cce37..d784be628 100644 --- a/ir/ana/cgana.h +++ b/include/libfirm/cgana.h @@ -35,7 +35,7 @@ #ifndef FIRM_ANA_CGANA_H #define FIRM_ANA_CGANA_H -#include "entity.h" +#include "firm_types.h" /* Methoden sind "frei", wenn ihr Funktionszeiger (potentiell) * "explizit" bekannt ist, d.h.: diff --git a/ir/ana/compute_loop_info.h b/include/libfirm/compute_loop_info.h similarity index 100% rename from ir/ana/compute_loop_info.h rename to include/libfirm/compute_loop_info.h diff --git a/ir/debug/dbginfo.h b/include/libfirm/dbginfo.h similarity index 99% rename from ir/debug/dbginfo.h rename to include/libfirm/dbginfo.h index 1168907ef..317e821e0 100644 --- a/ir/debug/dbginfo.h +++ b/include/libfirm/dbginfo.h @@ -49,13 +49,14 @@ extern "C" { */ /** + * @typedef dbg_info + * * An abstract data type containing information for * debugging support. * * This opaque data type is not defined anywhere in the Firm library, * but pointers to this type can be stored in Firm nodes. */ -typedef struct dbg_info dbg_info; /** * Sets the debug information of a node. diff --git a/ir/ana/dfs.h b/include/libfirm/dfs.h similarity index 100% rename from ir/ana/dfs.h rename to include/libfirm/dfs.h diff --git a/ir/ana/execfreq.h b/include/libfirm/execfreq.h similarity index 93% rename from ir/ana/execfreq.h rename to include/libfirm/execfreq.h index 8742589dd..9e36f80cd 100644 --- a/ir/ana/execfreq.h +++ b/include/libfirm/execfreq.h @@ -31,11 +31,6 @@ struct ir_exec_freq; -#ifndef _EXECFREQ_TYPEDEF -#define _EXECFREQ_TYPEDEF -typedef struct ir_exec_freq ir_exec_freq; -#endif - /** * Create execfreq structure (to be used with set_execfreq) */ diff --git a/ir/ana/execution_frequency.h b/include/libfirm/execution_frequency.h similarity index 100% rename from ir/ana/execution_frequency.h rename to include/libfirm/execution_frequency.h diff --git a/ir/ana/field_temperature.h b/include/libfirm/field_temperature.h similarity index 100% rename from ir/ana/field_temperature.h rename to include/libfirm/field_temperature.h diff --git a/ir/common/firm.h b/include/libfirm/firm.h similarity index 82% rename from ir/common/firm.h rename to include/libfirm/firm.h index 09edffc77..05bc86dad 100644 --- a/ir/common/firm.h +++ b/include/libfirm/firm.h @@ -67,8 +67,7 @@ extern "C" { #include "firm_common.h" /* common type tags. */ #include "irprog.h" /* control flow and data of a program */ #include "irgraph.h" /* graphs */ -#include "type.h" /* type representation */ -#include "entity.h" /* entity representation */ +#include "typerep.h" /* type representation */ #include "tv.h" /* target values */ #include "ident.h" /* source code identificators */ @@ -79,24 +78,8 @@ extern "C" { /* Optimizations */ #include "irflag.h" /* optimization flags */ #include "irgopt.h" /* optimize ir */ -#include "reassoc.h" /* optimize ir by reassociation */ -#include "ldstopt.h" /* optimize Load/Store */ -#include "cfopt.h" /* optimize control flow */ -#include "tailrec.h" /* optimize tail-recursion calls */ +#include "iroptimize.h" /* optimize ir by reassociation */ #include "ircgopt.h" /* Optimizations based on interprocedural graph */ -#include "opt_osr.h" /* Operator Strength Reduction */ -#include "strength_red.h" /* Old (and buggy) Strength reduction */ -#include "loop_unrolling.h" /* Do loop unrolling */ -#include "ifconv.h" /* if conversion */ -#include "funccall.h" /* real function call optimization */ -#include "return.h" /* Return node normalizations */ -#include "scalar_replace.h" /* Scalar replacement */ -#include "proc_cloning.h" /* procedure cloning */ -#include "opt_confirms.h" /* Confirm based optimizations */ -#include "gvn_pre.h" /* global value numbering and partial redundancy elimination */ -#include "opt_frame.h" /* frame type optimization */ -#include "tropt.h" /* optimize the type representation */ -#include "condeval.h" /* control flow optimization by conditional evaluation */ /* Lowering */ #include "lower_calls.h" /* lowering of different calls */ @@ -123,20 +106,12 @@ extern "C" { /* Support */ #include "irgmod.h" /* Support to modify ir */ #include "irgwalk.h" /* Support to walk ir */ -#include "typewalk.h" /* Support to walk type information */ -#include "typegmod.h" /* Support to modify type graph */ -#include "type_identify.h" /* Support for type identification */ -#include "mangle.h" /* Support for mangling ident names. */ -#include "tr_inheritance.h" /* Support to handle inheritance. */ #include "irarch.h" /* architecture dependent optimizations */ #include "archop.h" /* architecture dependent opcodes */ -//#include "modeconv.h" /* architecture dependent mode conversion */ #include "firmstat.h" /* statistics */ -#include "irreflect.h" /* reflection */ - #include "seqnumbers.h" /* debug support */ #include "firm_ycomp.h" /* ycomp debugging support */ @@ -148,7 +123,6 @@ extern "C" { #include "irdump.h" #include "irprintf.h" #include "irvrfy.h" -#include "trvrfy.h" #include "irarch.h" diff --git a/ir/common/firm_common.h b/include/libfirm/firm_common.h similarity index 100% rename from ir/common/firm_common.h rename to include/libfirm/firm_common.h diff --git a/include/libfirm/firm_types.h b/include/libfirm/firm_types.h new file mode 100644 index 000000000..b73e400e9 --- /dev/null +++ b/include/libfirm/firm_types.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @brief Definition of opaque firm types + * @author Michael Beck + * @version $Id$ + */ +#ifndef FIRM_COMMON_FIRM_TYPES_H +#define FIRM_COMMON_FIRM_TYPES_H + +#ifdef _MSC_VER +typedef __int64 long64; +typedef unsigned __int64 ulong64; + +#define LL_FMT "i64" +#define ULL_FMT "ui64" + +#else +typedef long long long64; +typedef unsigned long long ulong64; + +#define LL_FMT "ll" +#define ULL_FMT "llu" + +#endif /* _MSC_VER */ + +typedef struct dbg_info dbg_info, *dbg_info_ptr; +typedef const struct _ident ident, *ir_ident_ptr; +typedef struct ir_node ir_node, *ir_node_ptr; +typedef struct ir_op ir_op, *ir_op_ptr; +typedef struct ir_mode ir_mode, *ir_mode_ptr; +typedef struct _ir_edge_t ir_edge_t, *ir_edge_ptr; +typedef struct tarval tarval, *ir_tarval_ptr; +typedef struct ir_enum_const ir_enum_const, *ir_enum_const_ptr; +typedef struct ir_type ir_type, *ir_type_ptr; +typedef struct ir_graph ir_graph, *ir_graph_ptr; +typedef struct ir_loop ir_loop, *ir_loop_ptr; +typedef struct ir_region ir_region, *ir_region_ptr; +typedef struct ir_reg_tree ir_reg_tree, *ir_reg_tree_ptr; +typedef struct ir_entity ir_entity, *ir_entity_ptr; +typedef struct compound_graph_path compound_graph_path, *ir_compound_graph_path_ptr; +typedef struct _ir_phase ir_phase, *ir_phase_ptr; +typedef struct _ir_extblk ir_extblk, *ir_extblk_ptr; +typedef struct ir_exec_freq ir_exec_freq, *ir_exec_freq_ptr; +typedef struct sn_entry *seqno_t; + + +typedef void irg_walk_func(ir_node *, void *); +typedef void irg_reg_walk_func(ir_region *, void *); + +#endif diff --git a/ir/debug/firm_ycomp.h b/include/libfirm/firm_ycomp.h similarity index 100% rename from ir/debug/firm_ycomp.h rename to include/libfirm/firm_ycomp.h diff --git a/ir/stat/firmstat.h b/include/libfirm/firmstat.h similarity index 100% rename from ir/stat/firmstat.h rename to include/libfirm/firmstat.h diff --git a/ir/ana/height.h b/include/libfirm/height.h similarity index 100% rename from ir/ana/height.h rename to include/libfirm/height.h diff --git a/ir/ident/ident.h b/include/libfirm/ident.h similarity index 90% rename from ir/ident/ident.h rename to include/libfirm/ident.h index 0cfd0235c..9015ddfc2 100644 --- a/ir/ident/ident.h +++ b/include/libfirm/ident.h @@ -31,28 +31,14 @@ #define FIRM_IDENT_IDENT_H #include "firm_config.h" +#include "firm_types.h" #ifdef FIRM_ENABLE_WCHAR #include #endif -#ifdef __cplusplus -extern "C" { -#endif - /* Identifiers */ -/** - * The abstract data type ident. - * - * An ident represents an unique string. The == operator - * is sufficient to compare two idents. - */ -#ifndef _IDENT_TYPEDEF_ -#define _IDENT_TYPEDEF_ -typedef const struct _ident ident; -#endif - /** * The ident module interface. */ @@ -296,8 +282,24 @@ int id_contains_wchar (ident *id, wchar_t c); #endif /* FIRM_ENABLE_WCHAR */ -#ifdef __cplusplus -} -#endif +/** initializes the name mangling code */ +void firm_init_mangle (void); + +/** Computes a definite name for this entity by concatenating + the name of the owner type and the name of the entity with + a separating "_". */ +ident *mangle_entity (ir_entity *ent); + +/** mangle underscore: Returns a new ident that represents first_scnd. */ +ident *mangle_u (ident *first, ident* scnd); + +/** mangle dot: Returns a new ident that represents first.scnd. */ +ident *mangle_dot (ident *first, ident* scnd); + +/** mangle: Returns a new ident that represents firstscnd. */ +ident *mangle (ident *first, ident* scnd); + +/** returns a mangled name for a Win32 function using it's calling convention */ +ident *decorate_win32_c_fkt(ir_entity *ent, ident *id); #endif diff --git a/ir/ana/interval_analysis.h b/include/libfirm/interval_analysis.h similarity index 100% rename from ir/ana/interval_analysis.h rename to include/libfirm/interval_analysis.h diff --git a/ir/ir/irarch.h b/include/libfirm/irarch.h similarity index 100% rename from ir/ir/irarch.h rename to include/libfirm/irarch.h diff --git a/ir/ir/ircgcons.h b/include/libfirm/ircgcons.h similarity index 100% rename from ir/ir/ircgcons.h rename to include/libfirm/ircgcons.h diff --git a/ir/ir/ircgopt.h b/include/libfirm/ircgopt.h similarity index 100% rename from ir/ir/ircgopt.h rename to include/libfirm/ircgopt.h diff --git a/ir/ir/ircons.h b/include/libfirm/ircons.h similarity index 100% rename from ir/ir/ircons.h rename to include/libfirm/ircons.h diff --git a/ir/ana/irconsconfirm.h b/include/libfirm/irconsconfirm.h similarity index 100% rename from ir/ana/irconsconfirm.h rename to include/libfirm/irconsconfirm.h diff --git a/ir/ana/irdom.h b/include/libfirm/irdom.h similarity index 100% rename from ir/ana/irdom.h rename to include/libfirm/irdom.h diff --git a/ir/ir/irdump.h b/include/libfirm/irdump.h similarity index 100% rename from ir/ir/irdump.h rename to include/libfirm/irdump.h diff --git a/ir/ir/iredgekinds.h b/include/libfirm/iredgekinds.h similarity index 100% rename from ir/ir/iredgekinds.h rename to include/libfirm/iredgekinds.h diff --git a/ir/ir/iredges.h b/include/libfirm/iredges.h similarity index 98% rename from ir/ir/iredges.h rename to include/libfirm/iredges.h index 8c1da4fe9..639fd9d06 100644 --- a/ir/ir/iredges.h +++ b/include/libfirm/iredges.h @@ -30,11 +30,6 @@ #include "firm_types.h" #include "iredgekinds.h" -#ifndef _IR_EDGE_TYPEDEF_ -#define _IR_EDGE_TYPEDEF_ -typedef struct _ir_edge_t ir_edge_t; -#endif - /** * Get the first edge pointing to some node. * @note There is no order on out edges. First in this context only diff --git a/ir/ana/irextbb.h b/include/libfirm/irextbb.h similarity index 98% rename from ir/ana/irextbb.h rename to include/libfirm/irextbb.h index a6d94026f..30f34a52c 100644 --- a/ir/ana/irextbb.h +++ b/include/libfirm/irextbb.h @@ -30,11 +30,6 @@ #include "firm_types.h" #include "execfreq.h" -#ifndef _IR_EXTBB_TYPEDEF_ -#define _IR_EXTBB_TYPEDEF_ -typedef struct _ir_extblk ir_extblk; -#endif - /** Flags for extended basic block state. */ typedef enum { ir_extblk_info_none = 0, /**< No extended basic block information is constructed. Default. */ diff --git a/ir/ir/irflag.h b/include/libfirm/irflag.h similarity index 100% rename from ir/ir/irflag.h rename to include/libfirm/irflag.h diff --git a/ir/ir/irgmod.h b/include/libfirm/irgmod.h similarity index 100% rename from ir/ir/irgmod.h rename to include/libfirm/irgmod.h diff --git a/ir/ir/irgopt.h b/include/libfirm/irgopt.h similarity index 100% rename from ir/ir/irgopt.h rename to include/libfirm/irgopt.h diff --git a/ir/ir/irgraph.h b/include/libfirm/irgraph.h similarity index 99% rename from ir/ir/irgraph.h rename to include/libfirm/irgraph.h index a2d769bc1..0d664fb74 100644 --- a/ir/ir/irgraph.h +++ b/include/libfirm/irgraph.h @@ -32,7 +32,7 @@ #include "irop.h" #include "iropt.h" #include "irextbb.h" -#include "type.h" +#include "typerep.h" /** * @page ir_graph The struct ir_graph diff --git a/ir/ir/irgwalk.h b/include/libfirm/irgwalk.h similarity index 96% rename from ir/ir/irgwalk.h rename to include/libfirm/irgwalk.h index 5809fe26c..b2572d49e 100644 --- a/ir/ir/irgwalk.h +++ b/include/libfirm/irgwalk.h @@ -35,18 +35,6 @@ #include "firm_types.h" -/* type of callback function for ir_graph walk */ -#ifndef _IRG_WALK_FUNC_TYPEDEF_ -#define _IRG_WALK_FUNC_TYPEDEF_ -/** - * The type of a walk function. Does not use the link field. - * - * @param node - the node that is just visited - * @param env - an environment pointer passed by the walk functions - */ -typedef void irg_walk_func(ir_node *node, void *env); -#endif - /** * Walks over the ir graph. * diff --git a/ir/ir/irhooks.h b/include/libfirm/irhooks.h similarity index 100% rename from ir/ir/irhooks.h rename to include/libfirm/irhooks.h diff --git a/ir/ana/irlivechk.h b/include/libfirm/irlivechk.h similarity index 100% rename from ir/ana/irlivechk.h rename to include/libfirm/irlivechk.h diff --git a/ir/ana/irloop.h b/include/libfirm/irloop.h similarity index 89% rename from ir/ana/irloop.h rename to include/libfirm/irloop.h index 9426dce02..b7d1180f9 100644 --- a/ir/ana/irloop.h +++ b/include/libfirm/irloop.h @@ -63,28 +63,7 @@ int has_backedges (ir_node *n); /** Clears all backedge information. */ void clear_backedges (ir_node *n); -/* ------------------------------------------------------------------- */ -/** - * The loops data structure. - * - * The loops data structure represents circles in the intermediate - * representation. It does not represent loops in the terms of a - * source program. - * Each ir_graph can contain one outermost loop data structure. - * loop is the entry point to the nested loops. - * The loop data structure contains a field indicating the depth of - * the loop within the nesting. Further it contains a list of the - * loops with nesting depth -1. Finally it contains a list of all - * nodes in the loop. - * - * @todo We could add a field pointing from a node to the containing loop, - * this would cost a lot of memory, though. - */ -/* ------------------------------------------------------------------- */ -#ifndef _IR_LOOP_TYPEDEF_ -#define _IR_LOOP_TYPEDEF_ -typedef struct ir_loop ir_loop; -#endif + /** Loop elements: loop nodes and ir nodes */ typedef union { diff --git a/ir/ana/irmemory.h b/include/libfirm/irmemory.h similarity index 100% rename from ir/ana/irmemory.h rename to include/libfirm/irmemory.h diff --git a/ir/ir/irmode.h b/include/libfirm/irmode.h similarity index 94% rename from ir/ir/irmode.h rename to include/libfirm/irmode.h index d33c0f7d1..bc68a40c0 100644 --- a/ir/ir/irmode.h +++ b/include/libfirm/irmode.h @@ -38,32 +38,6 @@ #include "firm_types.h" #include "ident.h" -/** - * Contains relevant information about a mode. - * - * Necessary information about a mode is stored in this struct - * which is used by the tarval module to perform calculations - * and comparisons of values of a such described mode. - * - * ATTRIBUTES: - * - modecode code: An unambiguous int (enum) for the mode - * - ident *name: Name of this mode. Two modes are different if the name is different. - * - mode_sort sort: sort of mode specifying possible usage categories - * - int size: size of the mode in Bits. - * - unsigned sign:1: signedness of this mode - * - ... more to come - * - modulo_shift specifies for modes of kind irms_int_number - * whether shift applies modulo to value of bits to shift - * - * SEE ALSO: - * The tech report 1999-44 describing FIRM and predefined modes - * tarval.h - */ -#ifndef _IR_MODE_TYPEDEF_ -#define _IR_MODE_TYPEDEF_ -typedef struct ir_mode ir_mode; -#endif - /* ********** Predefined modes ********** */ /** diff --git a/ir/ir/irnode.h b/include/libfirm/irnode.h similarity index 94% rename from ir/ir/irnode.h rename to include/libfirm/irnode.h index 280c8ff88..4792c542b 100644 --- a/ir/ir/irnode.h +++ b/include/libfirm/irnode.h @@ -29,7 +29,7 @@ #include #include "firm_common.h" -#include "entity.h" +#include "typerep.h" #include "irop.h" #include "irmode.h" #include "dbginfo.h" @@ -67,15 +67,6 @@ * @{ */ -#ifndef _IR_NODE_TYPEDEF_ -#define _IR_NODE_TYPEDEF_ -typedef struct ir_node ir_node; -#endif - -#ifdef __cplusplus -extern "C" { -#endif - /** * you can work on the graph without considering the different types * of nodes, it's just a big graph. @@ -1401,55 +1392,6 @@ unsigned get_irn_idx(const ir_node *node); * is set. Else does nothing. */ void dump_irn(ir_node *n); -#include "ident.h" -#include - -#ifdef __GNUC__ -/* GNU C has the __FUNCTION__ extension */ -#define __MYFUNC__ __FUNCTION__ -#else -/* use Filename instead */ -#define __MYFUNC__ __FILE__ -#endif - -/* !!!!!!!!! @@@ - Don't format with "\", firmjni gets problems */ -/** Output location */ -#define DDM printf("%s(l.%i).\n", __MYFUNC__, __LINE__); -/** Output the firm kind of the node */ -#define DDMK(X) printf("%s(l.%i) %s: %p\n", __MYFUNC__, __LINE__, print_firm_kind(X), (void *)(X)); -/** Output information about a node */ - -/*#define DDMN(X) printf("%s(l.%i) %s%s: %ld (%p)\n", __MYFUNC__, __LINE__, get_irn_opname(X), get_mode_name(get_irn_mode(X)), get_irn_node_nr(X), (void *)(X))*/ -int dump_node_opcode(FILE *F, ir_node *n); -#define DDMN(X) do { printf("%s(l.%i) ", __MYFUNC__, __LINE__); dump_node_opcode(stdout, X); printf(": %ld (%p)\n", get_irn_node_nr(X), (void *)(X)); } while (0) - -/** Output information about a node and its block */ -#define DDMNB(X) printf("%s%s: %ld (in block %ld)\n", get_irn_opname(X), get_mode_name(get_irn_mode(X)), get_irn_node_nr(X), get_irn_node_nr(get_nodes_block(X))) -/** Output information about a type */ -#define DDMT(X) printf("%s(l.%i) %s %s: %ld (%p)\n", __MYFUNC__, __LINE__, get_type_tpop_name(X), get_type_name(X), get_type_nr(X), (void *)(X)) -/** Output information about an entity */ -#define DDME(X) printf("%s(l.%i) %s: %ld (%p)\n", __MYFUNC__, __LINE__, get_entity_name(X), get_entity_nr(X), (void *)(X)) -/** Output information about an entity and its type */ -#define DDMET(X) printf("%s(l.%i) %s (typ: %s): %ld (%p)\n", __MYFUNC__, __LINE__, get_entity_name(X), get_type_name(get_entity_type(X)), get_entity_nr(X), (void *)(X)) -/** Output information about an entity and its owner */ -#define DDMEO(X) printf("%s(l.%i) %s (own: %s): %ld (%p)\n", __MYFUNC__, __LINE__, get_entity_name(X), get_type_name(get_entity_owner(X)), get_entity_nr(X), (void *)(X)) -/** Output information about a graph */ -#define DDMG(X) printf("%s(l.%i) graph %s: %ld (%p) in %s %s.\n", __MYFUNC__, __LINE__, get_entity_name(get_irg_entity(X)), get_irg_graph_nr(X), (void *)(X), get_type_tpop_name(get_entity_owner(get_irg_entity(X))), get_type_name(get_entity_owner(get_irg_entity(X)))) -/** Output information about an ident */ -#define DDMI(X) printf("%s(l.%i) %s: %p\n", __MYFUNC__, __LINE__, get_id_str(X), (void *)(X)) -/** Output information about a mode */ -#define DDMM(X) printf("%s(l.%i) %s: %p\n", __MYFUNC__, __LINE__, get_mode_name(X), (void *)(X)) -/** Output information about a loop */ -#define DDML(X) printf("%s(l.%i) loop with depth %d: %d\n", __MYFUNC__, __LINE__, get_loop_depth(X), get_loop_loop_nr(X)) -/** Output information about a tarVal */ -#define DDMV(X) printf("%s(l.%i) tarval: ",__MYFUNC__, __LINE__); tarval_printf(X); printf(" (%p)\n", (void *)(X)); - /*@}*/ /* end of ir_node group definition */ - -#ifdef __cplusplus -} -#endif - #endif diff --git a/ir/ir/irop.h b/include/libfirm/irop.h similarity index 99% rename from ir/ir/irop.h rename to include/libfirm/irop.h index e096c5435..6accd3cbf 100644 --- a/ir/ir/irop.h +++ b/include/libfirm/irop.h @@ -96,11 +96,6 @@ typedef enum { iro_MaxOpcode } ir_opcode; -#ifndef _IR_OP_TYPEDEF_ -#define _IR_OP_TYPEDEF_ -typedef struct ir_op ir_op; -#endif - extern ir_op *op_Block; ir_op *get_op_Block (void); extern ir_op *op_Start; ir_op *get_op_Start (void); diff --git a/ir/ir/iropt.h b/include/libfirm/iropt.h similarity index 100% rename from ir/ir/iropt.h rename to include/libfirm/iropt.h diff --git a/ir/ir/iropt_dbg.h b/include/libfirm/iropt_dbg.h similarity index 100% rename from ir/ir/iropt_dbg.h rename to include/libfirm/iropt_dbg.h diff --git a/include/libfirm/iroptimize.h b/include/libfirm/iroptimize.h new file mode 100644 index 000000000..50ba39193 --- /dev/null +++ b/include/libfirm/iroptimize.h @@ -0,0 +1,496 @@ +/* + * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @brief Optimisations + * @version $Id: cfopt.h 13543 2007-04-29 19:29:02Z beck $ + */ +#ifndef FIRM_IROPTIMIZE_H +#define FIRM_IROPTIMIZE_H + +#include "firm_types.h" + +/** + * Control flow optimization. + * + * Removes empty blocks doing if simplifications and loop simplifications. + * A block is empty if it contains only a Jmp node and Phi nodes. + * Merges single entry single exit blocks with their predecessor + * and propagates dead control flow by calling equivalent_node(). + * Independent of compiler flag it removes Tuples from cf edges, + * Bad predecessors from Blocks and Phis, and unnecessary predecessors of End. + * + * @bug So far destroys backedge information. + * @bug Chokes on Id nodes if called in a certain order with other + * optimizations. Call local_optimize_graph() before to remove + * Ids. + */ +void optimize_cf(ir_graph *irg); + +/** + * Perform partial conditionla evaluation on the given graph. + * + * @param irg the graph + */ +void opt_cond_eval(ir_graph* irg); + +/** + * Try to reduce the number of conv nodes in the given ir graph. + * + * @param irg the graph + */ +void conv_opt(ir_graph *irg); + +/** + * Do the scalar replacement optimization. + * Make a date flow analyze and split the + * data flow edges. + * + * @param irg the graph which should be optimized + */ +void data_flow_scalar_replacement_opt(ir_graph *irg); + +/** + * A callback that checks whether a entity is an allocation + * routine. + */ +typedef int (*check_alloc_entity_func)(ir_entity *ent); + +/** + * Do simple and fast escape analysis for one graph. + * + * @param irg the graph + * @param callback a callback function to check whether a + * given entity is a allocation call + */ +void escape_enalysis_irg(ir_graph *irg, check_alloc_entity_func callback); + +/** + * Do simple and fast escape analysis for all graphs. + * + * This optimization implements a simple and fast but inexact + * escape analysis. Some addresses might be marked as 'escaped' even + * if they are not. + * The advantage is a low memory footprint and fast speed. + * + * @param run_scalar_replace if this flag in non-zero, scalar + * replacement optimization is run on graphs with removed + * allocation + * @param callback a callback function to check whether a + * given entity is a allocation call + * + * This optimization removes allocation which are not used (rare) and replace + * allocation that can be proved dead at the end of the graph which stack variables. + * + * The creation of stack variable allows scalar replacement to be run only + * on those graphs that have been changed. + * + * This is most effective on Java where no other stack variables exists. + */ +void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback); + +/** + * Optimize function calls by handling const functions. + * + * This optimization first detects all "const functions", i.e., + * IR graphs that neither read nor write memory (and hence did + * not create exceptions, as these use memory in Firm). + * + * The result of calls to such functions depends only on its + * arguments, hence those calls are no more pinned. + * + * This is a rather strong criteria, so do not expect that a + * lot of functions will be found. Moreover, all of them might + * already be inlined if inlining is activated. + * Anyway, it might be good for handling builtin's or pseudo-graphs, + * even if the later read/write memory (but we know how). + * + * This optimizations read the irg_const_function property of + * entities and and sets the irg_const_function property of + * graphs. + * + * If callee information is valid, we also optimize polymorphic Calls. + * + * @param force_run if non-zero, an optimization run is started even + * if no const function graph was detected. + * Else calls are only optimized if at least one + * const function graph was detected. + * + * If the fontend created external entities with the irg_const_function + * property set, the force_run parameter should be set, else + * should be unset. + * + * @note This optimization destroys the link fields of nodes. + */ +void optimize_funccalls(int force_run); + +/** + * Does Partial Redundancy Elimination combined with + * Global Value Numbering. + * Can be used to replace place_code() completely. + * + * Based on VanDrunen and Hosking 2004. + * + * @param irg the graph + * + * @note + * Currently completely broken because the used sets do NOT + * preserve the topological sort of its elements. + */ +void do_gvn_pre(ir_graph *irg); + +/** + * This function is called to evaluate, if a mux can build + * of the current architecture. + * If it returns non-zero, a mux is created, else the code + * is not modified. + * @param sel A selector of a Cond. + * @param phi_list List of Phi nodes about to be converted (linked via link field) + * @param i First data predecessor involved in if conversion + * @param j Second data predecessor involved in if conversion + */ +typedef int (*arch_allow_ifconv_func)(ir_node *sel, ir_node* phi_list, int i, int j); + +/** + * The parameters structure. + */ +typedef struct _opt_if_conv_info_t { + int max_depth; /**< The maximum depth up to which expressions + are examined when it has to be decided if they + can be placed into another block. */ + arch_allow_ifconv_func allow_ifconv; /**< Evaluator function, if not set all possible Psi + nodes will be created. */ +} opt_if_conv_info_t; + +/** + * Perform If conversion on a graph. + * + * @param irg The graph. + * @param params The parameters for the if conversion. + * + * Cannot handle blocks with Bad control predecessors, so call it after control + * flow optimization. + */ +void opt_if_conv(ir_graph *irg, const opt_if_conv_info_t *params); + +void opt_ldst2(ir_graph *irg); + +/** + * Load/Store optimization. + * + * Removes redundant non-volatile Loads and Stores. + * May introduce Bad nodes if exceptional control flow + * is removed. The following cases are optimized: + * + * Load without result: A Load which has only a memory use + * is removed. + * + * Load after Store: A Load after a Store is removed, if + * the Load doesn't have an exception handler OR is in + * the same block as the Store. + * + * Load after Load: A Load after a Load is removed, if the + * Load doesn't have an exception handler OR is in the + * same block as the previous Load. + * + * Store before Store: A Store immediately before another + * Store in the same block is removed, if the Store doesn't + * have an exception handler. + * + * Store after Load: A Store after a Load is removed, if the + * Store doesn't have an exception handler. + */ +void optimize_load_store(ir_graph *irg); + +/** + * Do Loop unrolling in the given graph. + */ +void optimize_loop_unrolling(ir_graph *irg); + +/** + * Optimize the frame type of an irg by removing + * never touched entities. + * + * @param irg The graph whose frame type will be optimized + * + * This function did not change the graph, only it's frame type. + * The layout state of the frame type will be set to layout_undefined + * if entities were removed. + */ +void opt_frame_irg(ir_graph *irg); + +/** Possible flags for the Operator Scalar Replacement. */ +typedef enum osr_flags { + osr_flag_none = 0, /**< no additional flags */ + osr_flag_lftr_with_ov_check = 1, /**< do linear function test replacement + only if no overflow can occur. */ + osr_flag_ignore_x86_shift = 2 /**< ignore Multiplications by 2, 4, 8 */ +} osr_flags; + +/* FirmJNI cannot handle identical enum values... */ + +/** default setting */ +#define osr_flag_default osr_flag_lftr_with_ov_check + +/** + * Do the Operator Scalar Replacement optimization and linear + * function test replacement for loop control. + * Can be switched off using the set_opt_strength_red() flag. + * In that case, only remove_phi_cycles() is executed. + * + * @param irg the graph which should be optimized + * @param flags set of osr_flags + * + * The linear function replacement test is controlled by the flags. + * If the osr_flag_lftr_with_ov_check is set, the replacement is only + * done if do overflow can occur. + * Otherwise it is ALWAYS done which might be insecure. + * + * For instance: + * + * for (i = 0; i < 100; ++i) + * + * might be replaced by + * + * for (i = 0; i < 400; i += 4) + * + * But + * + * for (i = 0; i < 0x7FFFFFFF; ++i) + * + * will not be replaced by + * + * for (i = 0; i < 0xFFFFFFFC; i += 4) + * + * because of overflow. + * + * More bad cases: + * + * for (i = 0; i <= 0xF; ++i) + * + * will NOT be transformed into + * + * for (i = 0xFFFFFFF0; i <= 0xFFFFFFFF; ++i) + * + * although here is no direct overflow. The OV occurs when the ++i + * is executed (and would created an endless loop here!). + * + * For the same reason, a loop + * + * for (i = 0; i <= 9; i += x) + * + * will NOT be transformed because we cannot estimate whether an overflow + * might happen adding x. + * + * Note that i < a + 400 is also not possible with the current implementation + * although this might be allowed by other compilers... + * + * Note further that tests for equality can be handled some simpler (but are not + * implemented yet). + * + * This algorithm destroys the link field of nodes. + */ +void opt_osr(ir_graph *irg, unsigned flags); + +/** + * Removes useless Phi cycles, i.e cycles of Phi nodes with only one + * non-Phi node. + * This is automatically done in opt_osr(), so there is no need to call it + * additionally. + * + * @param irg the graph which should be optimized + * + * This algorithm destroys the link field of nodes. + */ +void remove_phi_cycles(ir_graph *irg); + +/** A default threshold. */ +#define DEFAULT_CLONE_THRESHOLD 300 + +/** + * Do procedure cloning. Evaluate a heuristic weight for every + * Call(..., Const, ...). If the weight is bigger than threshold, + * clone the entity and fix the calls. + * + * @param threshold the threshold for cloning + * + * The threshold is an estimation of how many instructions are saved + * when executing a cloned method. If threshold is 0.0, every possible + * call is cloned. + */ +void proc_cloning(float threshold); + +/** + * Reassociation. + * + * Applies Reassociation rules to integer expressions. + * Beware: Works only if integer overflow might be ignored, as for C, Java + * and for address expression. + * Works only if Constant folding is activated. + * + * Uses loop information to detect loop-invariant (ie contant + * inside the loop) values. + * + * See Muchnik 12.3.1 Algebraic Simplification and Reassociation of + * Addressing Expressions. + * + * + */ +void optimize_reassociation(ir_graph *irg); + +/** + * Normalize the Returns of a graph by creating a new End block + * with One Return(Phi). + * This is the preferred input for the if-conversion. + * + * In pseudocode, it means: + * + * if (a) + * return b; + * else + * return c; + * + * is transformed into + * + * if (a) + * res = b; + * else + * res = c; + * return res; + */ +void normalize_one_return(ir_graph *irg); + +/** + * Normalize the Returns of a graph by moving + * the Returns upwards as much as possible. + * This might be preferred for code generation. + * + * In pseudocode, it means: + * + * if (a) + * res = b; + * else + * res = c; + * return res; + * + * is transformed into + * + * if (a) + * return b; + * else + * return c; + */ +void normalize_n_returns(ir_graph *irg); + +/** + * Do the scalar replacement optimization. + * Replace local compound entities (like structures and arrays) + * with atomic values if possible. Does not handle classes yet. + * + * @param irg the graph which should be optimized + */ +void scalar_replacement_opt(ir_graph *irg); + +/** Performs strength reduction for the passed graph. */ +void reduce_strength(ir_graph *irg); + +/** + * Optimizes simple tail-recursion calls by + * converting them into loops. Depends on the flag opt_tail_recursion. + * + * Does not work for Calls that use the exception stuff. + * + * @param irg the graph to be optimized + * + * @return non-zero if the optimization could be applied, 0 else + */ +int opt_tail_rec_irg(ir_graph *irg); + +/* + * Optimize tail-recursion calls for all IR-Graphs. + * Depends on the flag opt_tail_recursion. + */ +void opt_tail_recursion(void); + +/** This is the type for a method, that returns a pointer type to + * tp. This is needed in the normalization. */ +typedef ir_type *(*gen_pointer_type_to_func)(ir_type *tp); + +/** Insert Casts so that class type casts conform exactly with the type hierarchy. + * + * Formulated in Java, this achieves the following: + * + * For a class hierarchy + * class A {} + * class B extends A {} + * class C extends B {} + * we transforms a cast + * (A)new C() + * to + * (A)((B)new C()). + * + * The algorithm works for Casts with class types, but also for Casts + * with all pointer types that point (over several indirections, + * i.e. ***A) to a class type. Normalizes all graphs. Computes type + * information (@see irtypeinfo.h) if not available. + * Invalidates trout information as new casts are generated. + * + * @param gppt_fct A function that returns a pointer type that points + * to the type given as argument. If this parameter is NULL, a default + * function is used that either uses trout information or performs a O(n) + * search to find an existing pointer type. If it can not find a type, + * generates a pointer type with mode_P_mach and suffix "cc_ptr_tp". + */ +void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct); + + +/** Insert Casts so that class type casts conform exactly with the type hierarchy + * in given graph. + * + * For more details see normalize_irp_class_casts(). + * + * This transformation requires that type information is computed. @see irtypeinfo.h. + */ +void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct); + + +/** Optimize casting between class types. + * + * class A { m(); } + * class B extends A { } + * class C extends B {} + * Performs the following transformations: + * C c = (C)(B)(A)(B)new C() --> C c = (C)(B)newC() --> C c = new C() + * (Optimizing downcasts as A a = (A)(B)(new A()) --> A a = new A() can + * be suppressed by setting the flag opt_suppress_downcast_optimization. + * Downcasting A to B might cause an exception. It is not clear + * whether this is modeled by the Firm Cast node, as it has no exception + * outputs.); + * If there is inh_m() that overwrites m() in B: + * ((A) new B()).m() --> (new B()).inh_m() + * Phi((A)x, (A)y) --> (A) Phi (x, y) if (A) is an upcast. + * + * Computes type information if not available. @see irtypeinfo.h. + * Typeinformation is valid after optimization. + * Invalidates trout information. + */ +void optimize_class_casts(void); + +#endif diff --git a/ir/ana/irouts.h b/include/libfirm/irouts.h similarity index 100% rename from ir/ana/irouts.h rename to include/libfirm/irouts.h diff --git a/ir/ir/irprintf.h b/include/libfirm/irprintf.h similarity index 100% rename from ir/ir/irprintf.h rename to include/libfirm/irprintf.h diff --git a/ir/ir/irprog.h b/include/libfirm/irprog.h similarity index 100% rename from ir/ir/irprog.h rename to include/libfirm/irprog.h diff --git a/ir/ana/irsimpletype.h b/include/libfirm/irsimpletype.h similarity index 99% rename from ir/ana/irsimpletype.h rename to include/libfirm/irsimpletype.h index 68fdbbdb9..f318553dd 100644 --- a/ir/ana/irsimpletype.h +++ b/include/libfirm/irsimpletype.h @@ -34,7 +34,7 @@ #include "irgraph.h" #include "irnode.h" -#include "type.h" +#include "typerep.h" diff --git a/ir/ana/irtypeinfo.h b/include/libfirm/irtypeinfo.h similarity index 100% rename from ir/ana/irtypeinfo.h rename to include/libfirm/irtypeinfo.h diff --git a/ir/ir/irvrfy.h b/include/libfirm/irvrfy.h similarity index 100% rename from ir/ir/irvrfy.h rename to include/libfirm/irvrfy.h diff --git a/ir/lower/lower_calls.h b/include/libfirm/lower_calls.h similarity index 100% rename from ir/lower/lower_calls.h rename to include/libfirm/lower_calls.h diff --git a/ir/lower/lower_dw.h b/include/libfirm/lower_dw.h similarity index 100% rename from ir/lower/lower_dw.h rename to include/libfirm/lower_dw.h diff --git a/ir/lower/lower_hl.h b/include/libfirm/lower_hl.h similarity index 100% rename from ir/lower/lower_hl.h rename to include/libfirm/lower_hl.h diff --git a/ir/lower/lower_intrinsics.h b/include/libfirm/lower_intrinsics.h similarity index 100% rename from ir/lower/lower_intrinsics.h rename to include/libfirm/lower_intrinsics.h diff --git a/ir/common/old_fctnames.h b/include/libfirm/old_fctnames.h similarity index 100% rename from ir/common/old_fctnames.h rename to include/libfirm/old_fctnames.h diff --git a/ir/ana/phiclass.h b/include/libfirm/phiclass.h similarity index 100% rename from ir/ana/phiclass.h rename to include/libfirm/phiclass.h diff --git a/ir/ana/rta.h b/include/libfirm/rta.h similarity index 100% rename from ir/ana/rta.h rename to include/libfirm/rta.h diff --git a/ir/debug/seqnumbers.h b/include/libfirm/seqnumbers.h similarity index 96% rename from ir/debug/seqnumbers.h rename to include/libfirm/seqnumbers.h index bc48057d0..741bc403b 100644 --- a/ir/debug/seqnumbers.h +++ b/include/libfirm/seqnumbers.h @@ -38,12 +38,10 @@ #include "ident.h" /** + * @typedef seqno_t + * * An opaque type for a sequence number. */ -#ifndef _SEQNO_T_TYPEDEF_ -#define _SEQNO_T_TYPEDEF_ -typedef struct sn_entry *seqno_t; -#endif /** * Create a new sequence number from a filename and a line number. diff --git a/ir/ana/structure.h b/include/libfirm/structure.h similarity index 100% rename from ir/ana/structure.h rename to include/libfirm/structure.h diff --git a/ir/ana/trouts.h b/include/libfirm/trouts.h similarity index 100% rename from ir/ana/trouts.h rename to include/libfirm/trouts.h diff --git a/ir/tv/tv.h b/include/libfirm/tv.h similarity index 99% rename from ir/tv/tv.h rename to include/libfirm/tv.h index 80525f2ab..f67edd797 100644 --- a/ir/tv/tv.h +++ b/include/libfirm/tv.h @@ -53,11 +53,6 @@ #include "firm_types.h" #include "irnode.h" -#ifndef _TARVAL_TYPEDEF_ -#define _TARVAL_TYPEDEF_ - typedef struct tarval tarval; -#endif - /* ************************ Constructors for tarvals ************************ */ /** diff --git a/ir/tr/type.h b/include/libfirm/typerep.h similarity index 51% rename from ir/tr/type.h rename to include/libfirm/typerep.h index 1ca784b84..48516e61c 100644 --- a/ir/tr/type.h +++ b/include/libfirm/typerep.h @@ -16,13 +16,1153 @@ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. */ +#ifndef FIRM_TYPEREP_H +#define FIRM_TYPEREP_H + +#include "firm_types.h" + +/** + * @page entity Entity representation + * + * An entity is the representation of program known objects in Firm. + * The primary concept of entities is to represent members of complex + * types, i.e., fields and methods of classes. As not all programming + * language model all variables and methods as members of some class, + * the concept of entities is extended to cover also local and global + * variables, and arbitrary procedures. + * + * An entity always specifies the type of the object it represents and + * the type of the object it is a part of, the owner of the entity. + * Originally this is the type of the class of which the entity is a + * member. + * The owner of local variables is the procedure they are defined in. + * The owner of global variables and procedures visible in the whole + * program is a universally defined class type "GlobalType". The owner + * of procedures defined in the scope of an other procedure is the + * enclosing procedure. + * + * The type ir_entity is an abstract data type to represent program entities. + * If contains the following attributes: + * + * - owner: A compound type this entity is a part of. + * - type: The type of this entity. + * - name: The string that represents this entity in the source program. * - allocation: A flag saying whether the entity is dynamically or statically * allocated (values: dynamic_allocated, static_allocated, + * automatic_allocated). + * - visibility: A flag indicating the visibility of this entity (values: local, + * external_visible, external_allocated) + * - variability: A flag indicating the variability of this entity (values: + * uninitialized, initialized, part_constant, constant) + * - volatility: @@@ + * - offset: The offset of the entity within the compound object in bytes. Only set + * if the owner in the state "layout_fixed". + * - offset_bits_remainder: The offset bit remainder of a bitfield entity (in a compound) + * in bits. Only set if the owner in the state "layout_fixed". + * - overwrites: A list of entities overwritten by this entity. This list is only + * existent if the owner of this entity is a class. The members in + * this list must be entities of super classes. + * - overwrittenby: A list of entities that overwrite this entity. This list is only + * existent if the owner of this entity is a class. The members in + * this list must be entities of sub classes. + * - link: A void* to associate some additional information with the entity. + * - irg: If the entity is a method this is the ir graph that represents the + * code of the method. + * - peculiarity: The peculiarity of the entity. If the entity is a method this + * indicates whether the entity represents + * a real method or whether it only exists to describe an interface. + * In that case there nowhere exists code for this entity and this entity + * is never dynamically used in the code. + * Values: description, existent. Default: existent. + * - visited: visited flag. Master flag is type_visited. + * + * These fields can only be accessed via access functions. + * + * @see ir_type, ir_entity + */ + +/** This enumeration flags the visibility of entities and types. + * + * This is necessary for partial compilation. + * We rely on the ordering of the flags. + */ +typedef enum { + visibility_local, /**< The entity is only visible locally. This is the default for + entities. + The type is only visible locally. All instances are allocated + locally, and no pointer to entities of this type are passed + out of this compilation unit. */ + visibility_external_visible, /**< The entity is visible to other external program parts, but + it is defined here. It may not be optimized away. The entity must + be static_allocated. + For types: entities of this type can be accessed externally. No + instances of this type are allocated externally. */ + visibility_external_allocated /**< The entity is defined and allocated externally. This compilation + must not allocate memory for this entity. The entity must + be static_allocated. This can also be an external defined + method. + For types: entities of this type are allocated and accessed from + external code. Default for types. */ +} ir_visibility; + +/** This enumeration flags the peculiarity of entities and types. */ +typedef enum { + peculiarity_description, /**< Represents only a description. The entity/type is never + allocated, no code/data exists for this entity/type. + @@@ eventually rename to descriptive (adjective as the others!)*/ + peculiarity_inherited, /**< Describes explicitly that other entities are + inherited to the owner of this entity. + Overwrites must refer to at least one other + entity. If this is a method entity there exists + no irg for this entity, only for one of the + overwritten ones. + Only for entity. */ + peculiarity_existent /**< The entity/type (can) exist. + @@@ eventually rename to 'real' i.e., 'echt' + This serves better as opposition to description _and_ inherited.*/ +} ir_peculiarity; + +/** + * Additional method type properties: + * Tell about special properties of a method type. Some + * of these may be discovered by analyses. + */ +typedef enum { + mtp_no_property = 0x00000000, /**< no additional properties, default */ + mtp_property_const = 0x00000001, /**< This method did not access memory and calculates + its return values solely from its parameters. + GCC: __attribute__((const)). */ + mtp_property_pure = 0x00000002, /**< This method did NOT write to memory and calculates + its return values solely from its parameters and + the memory they points to (or global vars). + GCC: __attribute__((pure)). */ + mtp_property_noreturn = 0x00000004, /**< This method did not return due to an aborting system + call. + GCC: __attribute__((noreturn)). */ + mtp_property_nothrow = 0x00000008, /**< This method cannot throw an exception. + GCC: __attribute__((nothrow)). */ + mtp_property_naked = 0x00000010, /**< This method is naked. + GCC: __attribute__((naked)). */ + mtp_property_malloc = 0x00000020, /**< This method returns newly allocate memory. + GCC: __attribute__((malloc)). */ + mtp_property_intrinsic = 0x00000040, /**< This method is intrinsic. It is expected that + a lowering phase will remove all calls to it. */ + mtp_property_runtime = 0x00000080, /**< This method represents a runtime routine. */ + mtp_property_inherited = (1<<31) /**< Internal. Used only in irg's, means property is + inherited from type. */ +} mtp_additional_property; + +/** + * Creates a new entity. + * + * Automatically inserts the entity as a member of owner. + * Entity is automatic_allocated and uninitialized except if the type + * is type_method, then it is static_allocated and constant. The constant + * value is a pointer to the method. + * Visibility is local, offset -1, and it is not volatile. + */ +ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp); + +/** + * Creates a new entity. + * + * Automatically inserts the entity as a member of owner. + * The entity is automatic allocated and uninitialized except if the type + * is type_method, then it is static allocated and constant. The constant + * value is a pointer to the method. + * Visibility is local, offset -1, and it is not volatile. + */ +ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *tp, dbg_info *db); + +/** + * Copies the entity if the new_owner is different from the + * owner of the old entity, else returns the old entity. + * + * Automatically inserts the new entity as a member of owner. + * Resets the overwrites/overwritten_by fields. + * Keeps the old atomic value. + * @@@ Maybe we should change this. If peculiarity of a method + * is existent, we should add a new SymConst that points to + * itself and not to the origin. Right now we have to change + * the peculiarity and then set a new atomic value by hand. + */ +ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner); + +/** + * Copies the entity if the new_name is different from the + * name of the old entity, else returns the old entity. + * + * Automatically inserts the new entity as a member of owner. + * The mangled name ld_name is set to NULL. + * Overwrites relation is copied from old. + */ +ir_entity *copy_entity_name(ir_entity *old, ident *new_name); + +/** + * Frees the entity. + * + * The owner will still contain the pointer to this + * entity, as well as all other references! + */ +void free_entity(ir_entity *ent); + +/** Returns the name of an entity. */ +const char *get_entity_name(const ir_entity *ent); + +/** Returns the ident of an entity. */ +ident *get_entity_ident(const ir_entity *ent); + +/** Sets the ident of the entity. */ +void set_entity_ident(ir_entity *ent, ident *id); + +/** Returns the mangled name of the entity. + * + * If the mangled name is set it returns the existing name. + * Else it generates a name with mangle_entity() + * and remembers this new name internally. + */ +ident *get_entity_ld_ident(ir_entity *ent); + +/** Sets the mangled name of the entity. */ +void set_entity_ld_ident(ir_entity *ent, ident *ld_ident); + +/** Returns the mangled name of the entity as a string. */ +const char *get_entity_ld_name(ir_entity *ent); + +/** Returns the owner of the entity. */ +ir_type *get_entity_owner(ir_entity *ent); + +/** Sets the owner field in entity to owner. Don't forget to add + ent to owner!! */ +void set_entity_owner(ir_entity *ent, ir_type *owner); + +/** Returns the type of an entity. */ +ir_type *get_entity_type(ir_entity *ent); + +/** Sets the type of an entity. */ +void set_entity_type(ir_entity *ent, ir_type *tp); + +/** The allocation type. */ +typedef enum { + allocation_automatic, /**< The entity is allocated during runtime, implicitly + as component of a compound type. This is the default. */ + allocation_parameter, /**< The entity is a parameter. It is also automatic allocated. + We distinguish the allocation of parameters from the allocation + of local variables as their placement depends on the calling + conventions. */ + allocation_dynamic, /**< The entity is allocated during runtime, explicitly + by an Alloc node. */ + allocation_static /**< The entity is allocated statically. We can use a + Const as address of the entity. This is the default for methods. */ +} ir_allocation; + +/** Returns the allocation type of an entity. */ +ir_allocation get_entity_allocation(const ir_entity *ent); + +/** Sets the allocation type of an entity. */ +void set_entity_allocation(ir_entity *ent, ir_allocation al); + +/** Return the name of the allocation type. */ +const char *get_allocation_name(ir_allocation vis); + +/** Returns the visibility of an entity. */ +ir_visibility get_entity_visibility(const ir_entity *ent); + +/** Sets the visibility of an entity. */ +void set_entity_visibility(ir_entity *ent, ir_visibility vis); + +/** Return the name of the visibility */ +const char *get_visibility_name(ir_visibility vis); + +/** This enumeration flags the variability of entities. */ +typedef enum { + variability_uninitialized, /**< The content of the entity is completely unknown. Default. */ + variability_initialized, /**< After allocation the entity is initialized with the + value given somewhere in the entity. */ + variability_part_constant, /**< For entities of compound types. + The members of the entity are mixed constant, + initialized or uninitialized. */ + variability_constant /**< The entity is constant. */ +} ir_variability; + +/** Returns the variability of an entity. */ +ir_variability get_entity_variability(const ir_entity *ent); + +/** Sets the variability of an entity. */ +void set_entity_variability(ir_entity *ent, ir_variability var); + +/** Return the name of the variability. */ +const char *get_variability_name(ir_variability var); + +/** This enumeration flags the volatility of entities. */ +typedef enum { + volatility_non_volatile, /**< The entity is not volatile. Default. */ + volatility_is_volatile /**< The entity is volatile */ +} ir_volatility; + +/** Returns the volatility of an entity. */ +ir_volatility get_entity_volatility(const ir_entity *ent); + +/** Sets the volatility of an entity. */ +void set_entity_volatility(ir_entity *ent, ir_volatility vol); + +/** Return the name of the volatility. */ +const char *get_volatility_name(ir_volatility var); + +/** This enumeration flags the stickyness of an entity. */ +typedef enum { + stickyness_unsticky, /**< The entity can be removed from + the program, unless contraindicated + by other attributes. Default. */ + stickyness_sticky /**< The entity must remain in the + program in any case. */ +} ir_stickyness; + +/** Get the entity's stickyness. */ +ir_stickyness get_entity_stickyness(const ir_entity *ent); + +/** Set the entity's stickyness. */ +void set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness); + +/** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */ +int get_entity_offset(const ir_entity *ent); + +/** Sets the offset of an entity (in a compound) in bytes. */ +void set_entity_offset(ir_entity *ent, int offset); + +/** Returns the offset bit remainder of a bitfield entity (in a compound) in bits. Only set if layout = fixed. */ +unsigned char get_entity_offset_bits_remainder(const ir_entity *ent); + +/** Sets the offset bit remainder of a bitfield entity (in a compound) in bits. */ +void set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset); + +/** Returns the stored intermediate information. */ +void *get_entity_link(const ir_entity *ent); + +/** Stores new intermediate information. */ +void set_entity_link(ir_entity *ent, void *l); + +/* -- Fields of method entities -- */ +/** The entity knows the corresponding irg if the entity is a method. + This allows to get from a Call to the called irg. + Only entities of peculiarity "existent" can have a corresponding irg, + else the field is fixed to NULL. (Get returns NULL, set asserts.) */ +ir_graph *get_entity_irg(const ir_entity *ent); +void set_entity_irg(ir_entity *ent, ir_graph *irg); + +/** Gets the entity vtable number. */ +unsigned get_entity_vtable_number(const ir_entity *ent); + +/** Sets the entity vtable number. */ +void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number); + +/** Return the peculiarity of an entity. */ +ir_peculiarity get_entity_peculiarity(const ir_entity *ent); + +/** Sets the peculiarity of an entity. */ +void set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec); + +/** Checks if an entity cannot be overridden anymore. */ +int is_entity_final(const ir_entity *ent); + +/** Sets/resets the final flag of an entity. */ +void set_entity_final(ir_entity *ent, int final); + +/** Checks if an entity is compiler generated. */ +int is_entity_compiler_generated(const ir_entity *ent); + +/** Sets/resets the compiler generated flag. */ +void set_entity_compiler_generated(ir_entity *ent, int flag); + +/** + * The state of the address_taken flag. + */ +typedef enum { + ir_address_not_taken = 0, /**< The address is NOT taken. */ + ir_address_taken_unknown = 1, /**< The state of the address taken flag is unknown. */ + ir_address_taken = 2 /**< The address IS taken. */ +} ir_address_taken_state; + +/** Return the state of the address taken flag of an entity. */ +ir_address_taken_state get_entity_address_taken(const ir_entity *ent); + +/** Sets/resets the state of the address taken flag of an entity. */ +void set_entity_address_taken(ir_entity *ent, ir_address_taken_state flag); + +/** Return the name of the address_taken state. */ +const char *get_address_taken_state_name(ir_address_taken_state state); + +/* -- Representation of constant values of entities -- */ +/** + * Returns true if the the node is representable as code on + * const_code_irg. + * + * @deprecated This function is not used by libFirm and stays here + * only as a helper for the old Jack frontend. + */ +int is_irn_const_expression(ir_node *n); + +/** + * Copies a Firm subgraph that complies to the restrictions for + * constant expressions to current_block in current_ir_graph. + * + * @param dbg debug info for all newly created nodes + * @param n the node + * + * Set current_ir_graph to get_const_code_irg() to generate a constant + * expression. + */ +ir_node *copy_const_value(dbg_info *dbg, ir_node *n); + +/* Set has no effect for existent entities of type method. */ +ir_node *get_atomic_ent_value(ir_entity *ent); +void set_atomic_ent_value(ir_entity *ent, ir_node *val); + +/** Creates a new compound graph path. */ +compound_graph_path *new_compound_graph_path(ir_type *tp, int length); + +/** Returns non-zero if an object is a compound graph path */ +int is_compound_graph_path(const void *thing); + +/** Frees a graph path object */ +void free_compound_graph_path (compound_graph_path *gr); + +/** Returns the length of a graph path */ +int get_compound_graph_path_length(const compound_graph_path *gr); + +ir_entity *get_compound_graph_path_node(const compound_graph_path *gr, int pos); +void set_compound_graph_path_node(compound_graph_path *gr, int pos, ir_entity *node); +int get_compound_graph_path_array_index(const compound_graph_path *gr, int pos); +void set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index); + +/** Checks whether the path up to pos is correct. If the path contains a NULL, + * assumes the path is not complete and returns non-zero. */ +int is_proper_compound_graph_path(compound_graph_path *gr, int pos); + +/* A value of a compound entity is a pair of a value and the description of the + corresponding access path to the member of the compound. */ +void add_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path); +void set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, int pos); +/** Returns the number of constant values needed to initialize the entity. + * + * Asserts if the entity has variability_uninitialized. + * */ +int get_compound_ent_n_values(ir_entity *ent); +/** Returns a constant value given the position. */ +ir_node *get_compound_ent_value(ir_entity *ent, int pos); +/** Returns the access path for value at position pos. */ +compound_graph_path *get_compound_ent_value_path(ir_entity *ent, int pos); +/** Returns a constant value given the access path. + * The path must contain array indices for all array element entities. */ +ir_node *get_compound_ent_value_by_path(ir_entity *ent, compound_graph_path *path); + +/** Removes all constant entries where the path ends at value_ent. Does not + free the memory of the paths. (The same path might be used for several + constant entities. */ +void remove_compound_ent_value(ir_entity *ent, ir_entity *value_ent); + +/* Some languages support only trivial access paths, i.e., the member is a + direct, atomic member of the constant entities type. In this case the + corresponding entity can be accessed directly. The following functions + allow direct access. */ + +/** Generates a Path with length 1. + Beware: Has a bad runtime for array elements (O(|array|) and should be + avoided there. Use add_compound_ent_value_w_path() instead and create + the path manually. */ +void add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member); + +/** Returns the last member in the path */ +ir_entity *get_compound_ent_value_member(ir_entity *ent, int pos); + +/** Sets the path at pos 0 */ +void set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member, int pos); + +/** Initializes the entity ent which must be of a one dimensional + array type with the values given in the values array. + The array must have a lower and an upper bound. Keeps the + order of values. Does not test whether the number of values + fits into the given array size. Does not test whether the + values have the proper mode for the array. */ +void set_array_entity_values(ir_entity *ent, tarval **values, int num_vals); + +/** + * Return the offset in bits from the last byte address. + * + * This requires that the layout of all concerned types is fixed. + * + * @param ent Any entity of compound type with at least pos initialization values. + * @param pos The position of the value for which the offset is requested. + */ +int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos); + +/** Return the overall offset of value at position pos in bytes. + * + * This requires that the layout of all concerned types is fixed. + * Asserts if bit offset is not byte aligned. + * + * @param ent Any entity of compound type with at least pos initialization values. + * @param pos The position of the value for which the offset is requested. + */ +int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos); + +/* --- Fields of entities with a class type as owner --- */ +/* Overwrites is a field that specifies that an access to the overwritten + entity in the supertype must use this entity. It's a list as with + multiple inheritance several entities can be overwritten. This field + is mostly useful for method entities. + If a Sel node selects an entity that is overwritten by other entities it + must return a pointer to the entity of the dynamic type of the pointer + that is passed to it. Lowering of the Sel node must assure this. + Overwrittenby is the inverse of overwrites. Both add routines add + both relations, they only differ in the order of arguments. */ +void add_entity_overwrites (ir_entity *ent, ir_entity *overwritten); +int get_entity_n_overwrites (ir_entity *ent); +int get_entity_overwrites_index(ir_entity *ent, ir_entity *overwritten); +ir_entity *get_entity_overwrites (ir_entity *ent, int pos); +void set_entity_overwrites (ir_entity *ent, int pos, ir_entity *overwritten); +void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten); + +void add_entity_overwrittenby (ir_entity *ent, ir_entity *overwrites); +int get_entity_n_overwrittenby (ir_entity *ent); +int get_entity_overwrittenby_index(ir_entity *ent, ir_entity *overwrites); +ir_entity *get_entity_overwrittenby (ir_entity *ent, int pos); +void set_entity_overwrittenby (ir_entity *ent, int pos, ir_entity *overwrites); +void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites); + +/** + * Checks whether a pointer points to an entity. + * + * @param thing an arbitrary pointer + * + * @return + * true if the thing is an entity, else false + */ +int is_entity (const void *thing); + +/** Returns true if the type of the entity is a primitive, pointer + * enumeration or method type. + * + * @Note This is a different classification than from is_primitive_type(). + */ +int is_atomic_entity(ir_entity *ent); +/** Returns true if the type of the entity is a class, structure, + array or union type. */ +int is_compound_entity(ir_entity *ent); +/** Returns true if the type of the entity is a Method type. */ +int is_method_entity(ir_entity *ent); + +/** Returns non-zero if ent1 and ent2 have are equal except for their owner. + Two entities are equal if + - they have the same type (the same C-struct) + - ...? +*/ +int equal_entity(ir_entity *ent1, ir_entity *ent2); + +/** Outputs a unique number for this entity if libfirm is compiled for + * debugging, (configure with --enable-debug) else returns the address + * of the type cast to long. + */ +long get_entity_nr(const ir_entity *ent); + +/** Returns the entities visited count. */ +unsigned long get_entity_visited(ir_entity *ent); + +/** Sets the entities visited count. */ +void set_entity_visited(ir_entity *ent, unsigned long num); + +/** Sets visited field in entity to entity_visited. */ +void mark_entity_visited(ir_entity *ent); + +/** Returns true if this entity was visited. */ +int entity_visited(ir_entity *ent); + +/** Returns true if this entity was not visited. */ +int entity_not_visited(ir_entity *ent); + +/** + * Returns the mask of the additional entity properties. + * The properties are automatically inherited from the irg if available + * or from the method type if they were not set using + * set_entity_additional_properties() or + * set_entity_additional_property(). + */ +unsigned get_entity_additional_properties(ir_entity *ent); + +/** Sets the mask of the additional graph properties. */ +void set_entity_additional_properties(ir_entity *ent, unsigned property_mask); + +/** Sets one additional graph property. */ +void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag); + +/** Returns the class type that this type info entity represents or NULL + if ent is no type info entity. */ +ir_type *get_entity_repr_class(const ir_entity *ent); + +/** + * @page unknown_entity The Unknown entity + * + * This entity is an auxiliary entity dedicated to support analyses. + * + * The unknown entity represents that there could be an entity, but it is not + * known. This entity can be used to initialize fields before an analysis (not known + * yet) or to represent the top of a lattice (could not be determined). There exists + * exactly one entity unknown. This entity has as owner and as type the unknown type. It is + * allocated when initializing the entity module. + * + * The entity can take the role of any entity, also methods. It returns default + * values in these cases. + * + * The following values are set: + * + * - name = "unknown_entity" + * - ld_name = "unknown_entity" + * - owner = unknown_type + * - type = unknown_type + * - allocation = allocation_automatic + * - visibility = visibility_external_allocated + * - offset = -1 + * - variability = variability_uninitialized + * - value = SymConst(unknown_entity) + * - values = NULL + * - val_paths = NULL + * - peculiarity = peculiarity_existent + * - volatility = volatility_non_volatile + * - stickyness = stickyness_unsticky + * - ld_name = NULL + * - overwrites = NULL + * - overwrittenby = NULL + * - irg = NULL + * - link = NULL + */ +/* A variable that contains the only unknown entity. */ +extern ir_entity *unknown_entity; + +/** Returns the @link unknown_entity unknown entity @endlink. */ +ir_entity *get_unknown_entity(void); + +/** Encodes how a pointer parameter is accessed. */ +typedef enum acc_bits { + ptr_access_none = 0, /**< no access */ + ptr_access_read = 1, /**< read access */ + ptr_access_write = 2, /**< write access */ + ptr_access_rw = ptr_access_read|ptr_access_write, /**< read AND write access */ + ptr_access_store = 4, /**< the pointer is stored */ + ptr_access_all = ptr_access_rw|ptr_access_store /**< all possible access */ +} ptr_access_kind; + +#define IS_READ(a) ((a) & ptr_access_read) +#define IS_WRITTEN(a) ((a) & ptr_access_write) +#define IS_STORED(a) ((a) & ptr_access_store) + +/** + * Supported image sections. + * Currently only methods can be placed in different sections. + */ +typedef enum { + section_text, /**< The code segment. This is the default for methods. */ + section_constructors /**< The constructor section. */ +} ir_img_section; + +/** Returns the section of a method. */ +ir_img_section get_method_img_section(const ir_entity *method); + +/** Sets the section of a method. */ +void set_method_img_section(ir_entity *method, ir_img_section section); + + + + +/** + * @page tyop type operations + * This module specifies the kinds of types available in firm. + * + * They are called type opcodes. These include classes, structs, methods, unions, + * arrays, enumerations, pointers and primitive types. + * Special types with own opcodes are the id type, a type representing an unknown + * type and a type used to specify that something has no type. + * + * @see type.h + */ + +/** + * An enum for the type kinds. + * For each type kind exists a typecode to identify it. + */ +typedef enum { + tpo_uninitialized = 0, /* not a type opcode */ + tpo_class, /**< A class type. */ + tpo_struct, /**< A struct type. */ + tpo_method, /**< A method type. */ + tpo_union, /**< An union type. */ + tpo_array, /**< An array type. */ + tpo_enumeration, /**< An enumeration type. */ + tpo_pointer, /**< A pointer type. */ + tpo_primitive, /**< A primitive type. */ + tpo_id, /**< Special Id tag used for type replacement. */ + tpo_none, /**< Special type for the None type. */ + tpo_unknown, /**< Special code for the Unknown type. */ + tpo_max /* not a type opcode */ +} tp_opcode; + +/** + * A structure containing information about a kind of type. + * A structure containing information about a kind of type. So far + * this is only the kind name, an enum for case-switching and some + * internal values. + * + * @see get_tpop_name(), get_tpop_code(), get_tpop_ident() + */ +typedef struct tp_op tp_op; + + +/** + * Returns the string for the type opcode. + * + * @param op The type opcode to get the string from. + * @return a string. (@todo Null terminated???) + */ +const char *get_tpop_name (const tp_op *op); + +/** + * Returns an enum for the type opcode. + * + * @param op The type opcode to get the enum from. + * @return the enum. + */ +tp_opcode get_tpop_code (const tp_op *op); + +/** + * Returns the ident for the type opcode. + * + * @param op The type opcode to get the ident from. + * @return The ident. + */ +ident *get_tpop_ident (const tp_op *op); + +/** + * This type opcode marks that the corresponding type is a class type. + * + * Consequently the type refers to supertypes, subtypes and entities. + * Entities can be any fields, but also methods. + * @@@ value class or not??? + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_class; +tp_op *get_tpop_class(void); + +/** + * This type opcode marks that the corresponding type is a compound type + * as a struct in C. + * + * Consequently the type refers to a list of entities + * which may not be methods (but pointers to methods). + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_struct; +tp_op *get_tpop_struct(void); + +/** + * This type opcode marks that the corresponding type is a method type. + * + * Consequently it refers to a list of arguments and results. + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_method; +tp_op *get_tpop_method(void); + +/** + * This type opcode marks that the corresponding type is a union type. + * + * Consequently it refers to a list of unioned types. + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_union; +tp_op *get_tpop_union(void); + +/** + * This type opcode marks that the corresponding type is an array type. + * + * Consequently it contains a list of dimensions (lower and upper bounds) + * and an element type. + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_array; +tp_op *get_tpop_array(void); + +/** + * This type opcode marks that the corresponding type is an enumeration type. + * + * Consequently it contains a list of idents for the enumeration identifiers + * and a list of target values that are the constants used to implement + * the enumerators. + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_enumeration; +tp_op *get_tpop_enumeration(void); + +/** + * This type opcode marks that the corresponding type is a pointer type. + * + * It contains a reference to the type the pointer points to. + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_pointer; +tp_op *get_tpop_pointer(void); + +/** + * This type opcode marks that the corresponding type is a primitive type. + * + * Primitive types are types that are directly mapped to target machine + * modes. + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_primitive; +tp_op *get_tpop_primitive(void); + +/** + * This type opcode is an auxiliary opcode dedicated to support transformations + * of the type structure. + * + * If a type is changed to another type with another + * opcode the new type will be allocated with new memory. All nodes refering + * to the old type need to be changed to refer to the new one. This is simplified + * by turning the old type into an id type that merely forwards to the new type + * that now replaces the old one. + * type_ids should never be visible out of the type module. All access routines + * should automatically check for type_id and eventually follow the forward in + * type_id. Two types are exchanged by a call to exchange_types. + * If a type_id is visible externally report this as bug. If it is assured that + * this never happens this extern variable can be moved to tpop_t.h. + * This struct is dynamically allocated but constant for the lifetime + * of the library. + */ +extern tp_op *type_id; +tp_op *get_tpop_id(void); + +/** + * This type opcode is an auxiliary opcode dedicated to support type analyses. + * + * Types with this opcode represents that there is no type. + * The type can be used to initialize fields of the type* that actually can not + * contain a type or that are initialized for an analysis. There exists exactly + * one type with this opcode. + */ +extern tp_op *tpop_none; +tp_op *get_tpop_none(void); + +/** + * This type opcode is an auxiliary opcode dedicated to support type analyses. + * + * Types with this opcode represents that there could be a type, but it is not + * known. This type can be used to initialize fields before an analysis (not known + * yet) or to represent the top of a lattice (could not be determined). There exists + * exactly one type with this opcode. + */ +extern tp_op *tpop_unknown; +tp_op *get_tpop_unknown(void); + +/* ----------------------------------------------------------------------- */ +/* Classify pairs of types/entities in the inheritance relations. */ +/* ----------------------------------------------------------------------- */ + +/** Returns true if low is subclass of high. + * + * Low is a subclass of high if low == high or if low is a subclass of + * a subclass of high. I.e, we search in all subtypes of high for low. + * @@@ this can be implemented more efficient if we know the set of all + * subclasses of high. */ +int is_SubClass_of(ir_type *low, ir_type *high); + +/** Subclass check for pointers to classes. + * + * Dereferences at both types the same amount of pointer types (as + * many as possible). If the remaining types are both class types + * and subclasses, returns true, else false. Can also be called with + * two class types. */ +int is_SubClass_ptr_of(ir_type *low, ir_type *high); + +/** Returns true if high is superclass of low. + * + * Low is a subclass of high if low == high or if low is a subclass of + * a subclass of high. I.e, we search in all subtypes of high for low. + * @@@ this can be implemented more efficient if we know the set of all + * subclasses of high. */ +#define is_SuperClass_of(high, low) is_SubClass_of(low, high) + +/** Superclass check for pointers to classes. + * + * Dereferences at both types the same amount of pointer types (as + * many as possible). If the remaining types are both class types + * and superclasses, returns true, else false. Can also be called with + * two class types. */ +#define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low) + +/** Returns true if high is (transitive) overwritten by low. + * + * Returns false if high == low. */ +int is_overwritten_by(ir_entity *high, ir_entity *low); + +/** Resolve polymorphism in the inheritance relation. + * + * Returns the dynamically referenced entity if the static entity and the + * dynamic type are given. + * Searches downwards in overwritten tree. */ +ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity* static_ent); + +/* ----------------------------------------------------------------------- */ +/* Resolve implicit inheritance. */ +/* ----------------------------------------------------------------------- */ + +/** Default name mangling for inherited entities. + * + * Returns an ident that consists of the name of type followed by an + * underscore and the name (not ld_name) of the entity. */ +ident *default_mangle_inherited_name(ir_entity *ent, ir_type *clss); + +/** Type of argument functions for inheritance resolver. + * + * @param ent The entity in the super type that will be overwritten + * by the newly generated entity, for which this name is + * used. + * @param clss The class type in which the new entity will be placed. + */ +typedef ident *mangle_inherited_name_func(ir_entity *ent, ir_type *clss); + +/** Resolve implicit inheritance. + * + * Resolves the implicit inheritance supplied by firm. Firm defines, + * that each entity that is not overwritten in a subclass is + * inherited to this subclass without change implicitly. This + * function generates entities that explicitly represent this + * inheritance. It generates for each entity overwriting entities in + * all subclasses of the owner of the entity, if the entity is not + * overwritten in that subclass. + * + * The name of the new entity is generated with the function passed. + * If the function is NULL, the default_mangle_inherited_name() is + * used. + * + * This function was moved here from firmlower 3/2005. + */ +void resolve_inheritance(mangle_inherited_name_func *mfunc); + + +/* ----------------------------------------------------------------------- */ +/* The transitive closure of the subclass/superclass and */ +/* overwrites/overwrittenby relation. */ +/* */ +/* A walk over the ir (O(#types+#entities)) computes the transitive */ +/* closure. Adding a new type/entity or changing the basic relations in */ +/* some other way invalidates the transitive closure, i.e., it is not */ +/* updated by the basic functions. */ +/* */ +/* The transitive edges are held in a set, not in an array as the */ +/* underlying relation. */ +/* */ +/* Do the sets contain the node itself? I assume NOT! */ +/* ----------------------------------------------------------------------- */ + +/** The state of the transitive closure. + * + * @todo: we could manage the state for each relation separately. Invalidating + * the entity relations does not mean invalidating the class relation. */ +typedef enum { + inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */ + inh_transitive_closure_valid, /**< Closure computed and valid. */ + inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */ + inh_transitive_closure_max /**< Invalid value. */ +} inh_transitive_closure_state; + +void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s); +void invalidate_irp_inh_transitive_closure_state(void); +inh_transitive_closure_state get_irp_inh_transitive_closure_state(void); + + +/** Compute transitive closure of the subclass/superclass and + * overwrites/overwrittenby relation. + * + * This function walks over the ir (O(#types+#entities)) to compute the + * transitive closure. */ +void compute_inh_transitive_closure(void); + +/** Free memory occupied by the transitive closure information. */ +void free_inh_transitive_closure(void); + + +/* - subtype ------------------------------------------------------------- */ + +/** Iterate over all transitive subtypes. */ +ir_type *get_class_trans_subtype_first(ir_type *tp); +ir_type *get_class_trans_subtype_next (ir_type *tp); +int is_class_trans_subtype (ir_type *tp, ir_type *subtp); + +/* - supertype ----------------------------------------------------------- */ + +/** Iterate over all transitive supertypes. */ +ir_type *get_class_trans_supertype_first(ir_type *tp); +ir_type *get_class_trans_supertype_next (ir_type *tp); + +/* - overwrittenby ------------------------------------------------------- */ + +/** Iterate over all entities that transitive overwrite this entities. */ +ir_entity *get_entity_trans_overwrittenby_first(ir_entity *ent); +ir_entity *get_entity_trans_overwrittenby_next (ir_entity *ent); + +/* - overwrites ---------------------------------------------------------- */ + +/** Iterate over all transitive overwritten entities. */ +ir_entity *get_entity_trans_overwrites_first(ir_entity *ent); +ir_entity *get_entity_trans_overwrites_next (ir_entity *ent); + + +/* ----------------------------------------------------------------------- */ +/** The state of Cast operations that cast class types or pointers to class + * types. + * + * The state expresses, how far Cast operations conform with the class + * hierarchy. + * + * class A {} + * class B1 extends A {} + * class B2 extends A {} + * class C extends B1 {} + * normalized: Cast operations conform with the inheritance relation. + * I.e., the type of the operand of a Cast is either a super= or a sub- + * type of the type casted to. Example: (A)((B2) (new C())). + * transitive: Cast operations conform with the transitive inheritance + * relation. Example: (A)(new C()). + * any: Cast operations do not conform with the transitive inheritance + * relation. Example: (B2)(new B1()) + * + * @see: tropt.h + */ +/* ----------------------------------------------------------------------- */ + +/** Flags for class cast state. + * + * The state in irp is always smaller or equal to the state of any + * irg. + * + * We rely on the ordering of the enum. */ +typedef enum { + ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with + the class hierarchy. @@@ So far this does not happen in Firm. */ + ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */ + ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */ + ir_class_casts_state_max +} ir_class_cast_state; +char *get_class_cast_state_string(ir_class_cast_state s); + +void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s); +ir_class_cast_state get_irg_class_cast_state(ir_graph *irg); +void set_irp_class_cast_state(ir_class_cast_state s); +ir_class_cast_state get_irp_class_cast_state(void); + +/** Verify the class cast state of an irg. + * + * Asserts if state is to high, outputs warning if state is to low + * and firm verbosity is set. + */ +void verify_irg_class_cast_state(ir_graph *irg); + +/** + * possible trvrfy() error codes + */ +enum trvrfy_error_codes { + no_error = 0, /**< no error */ + error_ent_not_cont, /**< overwritten entity not in superclass */ + error_null_mem, /**< compound contains NULL member */ + error_const_on_wrong_irg, /**< constant placed on wrong IRG */ + error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */ + error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */ + error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */ + error_glob_ent_allocation, /**< wrong allocation of a global entity */ + error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */ + error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */ +}; + +/** + * Checks a type. + * + * @return + * 0 if no error encountered + */ +int check_type(ir_type *tp); + +/** + * Check an entity. Currently, we check only if initialized constants + * are build on the const irg graph. + * + * @return + * 0 if no error encountered + * != 0 a trvrfy_error_codes code + */ +int check_entity(ir_entity *ent); + +/** + * Walks the type information and performs a set of sanity checks. + * + * Currently, the following checks are executed: + * - values of initialized entities must be allocated on the constant IRG + * - class types: doesn't have NULL members + * - class types: all overwrites are existent in the super type + * + * @return + * 0 if graph is correct + * else error code. + */ +int tr_vrfy(void); + +/** + * If NDEBUG is defined performs nothing, else calls the tr_vrfy() function. + */ +#ifdef NDEBUG +#define TR_VRFY() 0 +#else +#define TR_VRFY() tr_vrfy() +#endif + +/** + * + * @file typegmod.h + * This module supplies routines that support changing the type graph. + */ + +/** Replaces one type by the other. + * + * Old type is replaced by new_type. All references to old_type + * now point to new_type. The memory for the old type is destroyed, + * but still used. Therefore it is not freed. + * All referenced to this memory will be lost after a certain while. + * An exception is the list of types in irp (irprog.h). + * In the future there might be a routine to recover the memory, but + * this will be at considerable runtime cost. + * + * @param old_type - The old type that shall be replaced by the new type. + * @param new_type - The new type that will replace old_type. + * + */ +void exchange_types(ir_type *old_type, ir_type *new_type); + +/** Skip id types until a useful type is reached. + * + * @param tp - A type of arbitrary kind. + * + * @return + * tp if it is not an id type. + * If tp is an id type returns the real type it stands for. + */ +ir_type *skip_tid(ir_type *tp); /** - * @file type.h - * @brief Representation of types. - * @author Goetz Lindenmaier, Michael Beck - * @version $Id$ - * @summary + * @page type representation of types * * Datastructure to hold type information. * @@ -43,82 +1183,8 @@ * * @see tpop.h */ -#ifndef FIRM_TR_TYPE_H -#define FIRM_TR_TYPE_H - -#include "firm_types.h" -#include "tpop.h" -#include "firm_common.h" -#include "dbginfo.h" - -/** - * An abstract data type to represent types. - * - * This is the abstract data type with which any type known in the - * compiled program can be represented. This includes types specified - * in the program as well as types defined by the language. In the - * view of the intermediate representation there is no difference - * between these types. - * - * There exist several kinds of types, arranged by the structure of - * the type. These are distinguished by a type opcode. - * A type is described by a set of attributes. Some of these attributes - * are common to all types, others depend on the kind of the type. - * - * The following describes the common attributes. They can only be - * accessed by the functions given below. - * - * The common fields are: - * - * - firm_kind: A firm_kind tag containing k_type. This is useful - * for dynamically checking whether a node is a type node. - * - type_op: A tp_op specifying the kind of the type. - * - name: An identifier specifying the name of the type. To be - * set by the frontend. - * - visibility: The visibility of this type. - * - size: The size of the type, i.e. an entity of this type will - * occupy size bits in memory. In several cases this is - * determined when fixing the layout of this type (class, - * struct, union, array, enumeration). - * - alignment The alignment of the type, i.e. an entity of this type will - * be allocated an an address in memory with this alignment. - * In several cases this is determined when fixing the layout - * of this type (class, struct, union, array) - * - mode: The mode to be used to represent the type on a machine. - * - state: The state of the type. The state represents whether the - * layout of the type is undefined or fixed (values: layout_undefined - * or layout_fixed). Compound types can have an undefined - * layout. The layout of the basic types primitive and pointer - * is always layout_fixed. If the layout of - * compound types is fixed all entities must have an offset - * and the size of the type must be set. - * A fixed layout for enumeration types means that each enumeration - * is associated with an implementation value. - * - assoc_type: The associated lowered/upper type. - * - visit: A counter for walks of the type information. - * - link: A void* to associate some additional information with the type. - * - * These fields can only be accessed via access functions. - * - * Depending on the value of @c type_op, i.e., depending on the kind of the - * type the adt contains further attributes. These are documented below. - * - * @see - * - * @link class_type class @endlink, @link struct_type struct @endlink, - * @link method_type method @endlink, @link union_type union @endlink, - * @link array_type array @endlink, @link enumeration_type enumeration @endlink, - * @link pointer_type pointer @endlink, @link primitive_type primitive @endlink - * - * @todo - * mode maybe not global field?? - */ -#ifndef _IR_TYPE_TYPEDEF_ -#define _IR_TYPE_TYPEDEF_ -typedef struct ir_type ir_type; -#endif -# include "type_or_entity.h" +#include "typerep.h" /** Frees all entities associated with a type. * Does not free the array entity. @@ -145,30 +1211,6 @@ ident* get_type_ident(const ir_type *tp); void set_type_ident(ir_type *tp, ident* id); const char* get_type_name(const ir_type *tp); -/** This enumeration flags the visibility of entities and types. - * - * This is necessary for partial compilation. - * We rely on the ordering of the flags. - */ -typedef enum { - visibility_local, /**< The entity is only visible locally. This is the default for - entities. - The type is only visible locally. All instances are allocated - locally, and no pointer to entities of this type are passed - out of this compilation unit. */ - visibility_external_visible, /**< The entity is visible to other external program parts, but - it is defined here. It may not be optimized away. The entity must - be static_allocated. - For types: entities of this type can be accessed externally. No - instances of this type are allocated externally. */ - visibility_external_allocated /**< The entity is defined and allocated externally. This compilation - must not allocate memory for this entity. The entity must - be static_allocated. This can also be an external defined - method. - For types: entities of this type are allocated and accessed from - external code. Default for types. */ -} ir_visibility; - /** The visibility of a type. * * The visibility of a type indicates, whether entities of this type @@ -593,23 +1635,6 @@ void remove_class_supertype(ir_type *clss, ir_type *supertype); #define set_class_base_type(clss, basetype, pos) set_class_supertype(clss, basetype, pos) #define remove_class_base_type(clss, basetype) remove_class_supertype(clss, basetype) -/** This enumeration flags the peculiarity of entities and types. */ -typedef enum { - peculiarity_description, /**< Represents only a description. The entity/type is never - allocated, no code/data exists for this entity/type. - @@@ eventually rename to descriptive (adjective as the others!)*/ - peculiarity_inherited, /**< Describes explicitly that other entities are - inherited to the owner of this entity. - Overwrites must refer to at least one other - entity. If this is a method entity there exists - no irg for this entity, only for one of the - overwritten ones. - Only for entity. */ - peculiarity_existent /**< The entity/type (can) exist. - @@@ eventually rename to 'real' i.e., 'echt' - This serves better as opposition to description _and_ inherited.*/ -} ir_peculiarity; - /** Returns a human readable string for a peculiarity. */ const char *get_peculiarity_name(ir_peculiarity p); @@ -843,36 +1868,6 @@ int get_method_first_variadic_param_index(const ir_type *method); */ void set_method_first_variadic_param_index(ir_type *method, int index); -/** - * Additional method type properties: - * Tell about special properties of a method type. Some - * of these may be discovered by analyses. - */ -typedef enum { - mtp_no_property = 0x00000000, /**< no additional properties, default */ - mtp_property_const = 0x00000001, /**< This method did not access memory and calculates - its return values solely from its parameters. - GCC: __attribute__((const)). */ - mtp_property_pure = 0x00000002, /**< This method did NOT write to memory and calculates - its return values solely from its parameters and - the memory they points to (or global vars). - GCC: __attribute__((pure)). */ - mtp_property_noreturn = 0x00000004, /**< This method did not return due to an aborting system - call. - GCC: __attribute__((noreturn)). */ - mtp_property_nothrow = 0x00000008, /**< This method cannot throw an exception. - GCC: __attribute__((nothrow)). */ - mtp_property_naked = 0x00000010, /**< This method is naked. - GCC: __attribute__((naked)). */ - mtp_property_malloc = 0x00000020, /**< This method returns newly allocate memory. - GCC: __attribute__((malloc)). */ - mtp_property_intrinsic = 0x00000040, /**< This method is intrinsic. It is expected that - a lowering phase will remove all calls to it. */ - mtp_property_runtime = 0x00000080, /**< This method represents a runtime routine. */ - mtp_property_inherited = (1<<31) /**< Internal. Used only in irg's, means property is - inherited from type. */ -} mtp_additional_property; - /** Returns the mask of the additional graph properties. */ unsigned get_method_additional_properties(const ir_type *method); @@ -1122,11 +2117,6 @@ int is_Array_type(const ir_type *array); * represent individual enumerations. */ -#ifndef _IR_ENUM_CONST_TYPEDEF_ -#define _IR_ENUM_CONST_TYPEDEF_ -typedef struct ir_enum_const ir_enum_const; -#endif - /** Create a new type enumeration -- set the enumerators independently. */ ir_type *new_type_enumeration(ident *name, int n_enums); @@ -1365,4 +2355,202 @@ ir_entity *frame_alloc_area(ir_type *frame_type, int size, int alignment, int at */ long get_type_nr(const ir_type *tp); -#endif /* FIRM_TR_TYPE_H */ +/* ------------------------------------------------------------------------ */ + +/** Type for a function that compares two types. + * + * @param tp1 The first type to compare. + * @param tp2 The second type to compare. + */ +typedef int (compare_types_func_t)(const void *tp1, const void *tp2); + +/** Compares two types by their name. + * + * Compares the opcode and the name of the types. If these are + * equal returns 0, else non-zero. + */ +int compare_names (const void *tp1, const void *tp2); + +/** Compares two types strict. + * + * returns 0 if tp1 == tp2, else non-zero + */ +int compare_strict (const void *tp1, const void *tp2); + +/* ------------------------------------------------------------------------ */ + +/** Type for a function that computes a hash value for a type. + * + * @param tp The type to compute a hash for. + */ +typedef int (hash_types_func_t)(ir_type *tp); + +/** Computes a hash value by the type name. + * + * Uses the name of the type and the type opcode to compute the hash. + */ +int firm_hash_name (ir_type *tp); + +/* ------------------------------------------------------------------------ */ + +/** Finalize type construction. + * + * Indicate that a type is so far completed that it can be + * distinguished from other types. Mature_type hashes the type into a + * table. It uses the function in compare_types_func to compare the + * types. + * + * If it finds a type identical to tp it returns this type. It turns + * tp into the Id type. All places formerly pointing to tp will now + * point to the found type. All entities of tp now refer to the found + * type as their owner, but they are not a member of this type. This + * is invalid firm -- the entities must be replaced by entities of the + * found type. The Id type will be removed from the representation + * automatically, but within an unknown time span. It occupies memory + * for this time. + * + * @param tp The type to mature. + */ +ir_type * mature_type(ir_type *tp); + +/** Finalize type construction. + * + * Indicate that a type is so far completed that it can be + * distinguished from other types. Mature_type hashes the type into a + * table. It uses the function in compare_types_func to compare the + * types. + * + * If it finds a type identical to tp it returns this type. It frees + * type tp and all its entities. + * + * @param tp The type to mature. + */ +ir_type * mature_type_free(ir_type *tp); + +/** Finalize type construction. + * + * Indicate that a type is so far completed that it can be + * distinguished from other types. Mature_type hashes the type into a + * table. It uses the function in compare_types_func to compare the + * types. + * + * If it find a type identical to tp it returns this type. It frees + * the entities and turns the type into an Id type. All places + * formerly pointing to tp will now point to the found type. The Id + * type will be removed from the representation automatically, but + * within an unknown time span. It occupies memory for this time. + * + * @param tp The type to mature. + */ +ir_type * mature_type_free_entities(ir_type *tp); + +/** + * The interface type for the type identify module; + */ +typedef struct _type_identify_if_t { + compare_types_func_t *cmp; /**< The function that should be used to compare two types. + If NULL, compare_strict() will be used. */ + hash_types_func_t *hash; /**< The function that should be used to calculate a hash + value of a type. If NULL, hash_name() will be used. */ +} type_identify_if_t; + +/** + * Initialise the type identifier module. + * + * @param ti_if The interface functions for this module. + * + * If the parameter ti_if is NULL, the default functions compare_strict() and + * firm_hash_name() will be used. + */ +void init_type_identify(type_identify_if_t *ti_if); + +/** A data type to treat types and entities as the same. */ +typedef union { + ir_type *typ; /**< points to a type */ + ir_entity *ent; /**< points to an entity */ +} type_or_ent; + +/** Type of argument functions for type walkers. + * + * @param tore points to the visited type or entity + * @param env free environment pointer + */ +typedef void type_walk_func(type_or_ent *tore, void *env); + +/** The class walk function + * + * @param clss points to the visited class + * @param env free environment pointer + */ +typedef void class_walk_func(ir_type *clss, void *env); + +/** Touches every type and entity in unspecified order. If new + * types/entities are created during the traversal these will + * be visited, too. + * Does not touch frame types or types for value params ... */ +void type_walk(type_walk_func *pre, type_walk_func *post, void *env); + +/** Walks over all type information reachable from an ir graph. + * + * Walks over all type information reachable from irg, i.e., starts a + * type walk at the irgs entity, the irgs frame type and all types and + * entities that are attributes to firm nodes. */ +void type_walk_irg(ir_graph *irg, type_walk_func *pre, type_walk_func *post, + void *env); + +/** + Touches every class in specified order: + - first the super class + - second the class itself + - third the sub classes. If new classes are created + during the traversal these will be visited, too. + + @todo should be named class-walk + + @deprecated will be removed? +*/ +void type_walk_super2sub(type_walk_func *pre, type_walk_func *post, void *env); + +/** Walker for class types in inheritance order. + * + * Touches every class in specified order: + * - first the super class + * - second the class itself + * If new classes are created during the traversal these + * will be visited, too. + * Starts the walk at arbitrary classes. + * Executes pre when first visiting a class. Executes post after + * visiting all superclasses. + * + * The arguments pre, post, env may be NULL. */ +void type_walk_super(type_walk_func *pre, type_walk_func *post, void *env); + +/** Same as type_walk_super2sub, but visits only class types. + Executes pre for a class if all superclasses have been visited. + Then iterates to subclasses. Executes post after return from + subclass. + Does not visit global type, frame types. + + @bug ?? something is wrong with this. +*/ +void class_walk_super2sub(class_walk_func *pre, class_walk_func *post, + void *env); + +/** + * the entity walk function. A function type for entity walkers. + * + * @param ent points to the visited entity + * @param env free environment pointer + */ +typedef void entity_walk_func(ir_entity *ent, void *env); + +/** + * Walks over all entities in the type. + * + * @param tp the type + * @param doit the entity walker function + * @param env environment, will be passed to the walker function + */ +void walk_types_entities(ir_type *tp, entity_walk_func *doit, void *env); + +#endif diff --git a/ir/ana/callgraph.c b/ir/ana/callgraph.c index d7e0715d3..696486805 100644 --- a/ir/ana/callgraph.c +++ b/ir/ana/callgraph.c @@ -698,7 +698,6 @@ is_head(ir_graph *n, ir_graph *root) some_outof_loop = 1; } else { if (get_irg_uplink(pred) < get_irg_uplink(root)) { - DDMG(pred); DDMG(root); assert(get_irg_uplink(pred) >= get_irg_uplink(root)); } some_in_loop = 1; @@ -729,7 +728,6 @@ is_endless_head(ir_graph *n, ir_graph *root) some_outof_loop = 1; } else { if(get_irg_uplink(pred) < get_irg_uplink(root)) { - DDMG(pred); DDMG(root); assert(get_irg_uplink(pred) >= get_irg_uplink(root)); } some_in_loop = 1; diff --git a/ir/ana/compute_loop_info.c b/ir/ana/compute_loop_info.c index 2672af811..b3930e749 100644 --- a/ir/ana/compute_loop_info.c +++ b/ir/ana/compute_loop_info.c @@ -28,7 +28,7 @@ #endif #include "compute_loop_info.h" -#include "strength_red.h" +#include "strength_red_t.h" #include "tv.h" #include "irgwalk.h" #include "irnode_t.h" diff --git a/ir/ana/field_temperature.c b/ir/ana/field_temperature.c index 83ac3ae8a..f36bff4b5 100644 --- a/ir/ana/field_temperature.c +++ b/ir/ana/field_temperature.c @@ -40,6 +40,7 @@ #include "irprog_t.h" #include "entity_t.h" #include "irgwalk.h" +#include "error.h" #include "array.h" @@ -172,7 +173,8 @@ int get_type_estimated_n_fields(ir_type *tp) { s = n_elt; } break; - default: DDMT(tp); assert(0); + default: + panic("Unsupported type in get_type_estimated_n_fields %+F", tp); } return s; @@ -215,7 +217,7 @@ int get_type_estimated_size_bytes(ir_type *tp) { break; } - default: DDMT(tp); assert(0); + default: assert(0); } return s; diff --git a/ir/ana/interval_analysis.c b/ir/ana/interval_analysis.c index 36ff2bb66..896cd3698 100644 --- a/ir/ana/interval_analysis.c +++ b/ir/ana/interval_analysis.c @@ -41,6 +41,7 @@ #include "irdump_t.h" #include "irdom.h" #include "irflag.h" +#include "irprintf.h" #include "hashptr.h" /*------------------------------------------------------------------*/ @@ -211,14 +212,6 @@ static int find_previous_loop(ir_loop *l, ir_loop *pred_l, ir_node *b, ir_node * } } - if (!found) { - DDMG(current_ir_graph); - DDML(l); - DDML(pred_l); - DDMN(b); - DDMN(pred_b); - } - return found; } @@ -253,7 +246,7 @@ static void construct_interval_block(ir_node *b, ir_loop *l) { if (is_backedge(b, i)) { if (b != get_loop_element(l, 0).node) { if (get_firm_verbosity()) { - printf("Loophead not at loop position 0. "); DDMN(b); + ir_printf("Loophead not at loop position 0. %+F\n", b); } } /* There are no backedges in the interval decomposition. */ @@ -284,7 +277,7 @@ static void construct_interval_block(ir_node *b, ir_loop *l) { if (!found) { if (b != get_loop_element(l, 0).node) { if (get_firm_verbosity()) { - printf("Loop entry not at loop position 0. "); DDMN(b); + ir_printf("Loop entry not at loop position 0. %+F\n", b); } } found = find_outer_loop(l, pred_l, pred, cfop); @@ -294,9 +287,6 @@ static void construct_interval_block(ir_node *b, ir_loop *l) { found = find_previous_loop(l, pred_l, b, pred, cfop); } if (!found) { - DDMG(current_ir_graph); - DDMN(b); - DDMN(pred); assert(is_backedge(b, i)); assert(found && "backedge from inner loop"); } @@ -305,10 +295,7 @@ static void construct_interval_block(ir_node *b, ir_loop *l) { if (b != get_loop_element(l, 0).node) { /* Check for improper region */ if (has_backedges(b)) { - printf("Improper Region!!!!!!\n"); - DDMG(current_ir_graph); - DDMN(b); - DDML(l); + ir_fprintf(stderr, "Improper Region!!!!!! %+F\n", b); } } } @@ -387,8 +374,7 @@ void dump_region_edges(FILE *F, void *reg) { if (is_ir_node(reg)) { if (get_Block_n_cfgpreds((ir_node *)reg) != get_region_n_ins(reg)) { - printf("n_cfgpreds = %d, n_ins = %d\n", get_Block_n_cfgpreds((ir_node *)reg), get_region_n_ins(reg)); - DDMN((ir_node *)reg); + ir_printf("n_cfgpreds = %d, n_ins = %d\n %+F\n", get_Block_n_cfgpreds((ir_node *)reg), get_region_n_ins(reg), (ir_node*) reg); } } diff --git a/ir/ana/ircfscc.c b/ir/ana/ircfscc.c index a802a92a3..6adbc979c 100644 --- a/ir/ana/ircfscc.c +++ b/ir/ana/ircfscc.c @@ -382,7 +382,6 @@ is_head (ir_node *n, ir_node *root) some_outof_loop = 1; } else { if (get_irn_uplink(pred) < get_irn_uplink(root)) { - DDMN(pred); DDMN(root); assert(get_irn_uplink(pred) >= get_irn_uplink(root)); } some_in_loop = 1; @@ -419,7 +418,6 @@ is_endless_head (ir_node *n, ir_node *root) some_outof_loop = 1; //printf(" some out of loop "); } else { if(get_irn_uplink(pred) < get_irn_uplink(root)) { - DDMN(pred); DDMN(root); assert(get_irn_uplink(pred) >= get_irn_uplink(root)); } some_in_loop = 1; diff --git a/ir/ana/irloop_t.h b/ir/ana/irloop_t.h index 9e9fe5e56..594308a74 100644 --- a/ir/ana/irloop_t.h +++ b/ir/ana/irloop_t.h @@ -46,7 +46,22 @@ typedef enum loop_flags { once = 0x00000080, /**< this is a do loop, with a false condition.It itarate once */ } loop_flags_t; -/** The loops datastructure. */ +/** + * The loops data structure. + * + * The loops data structure represents circles in the intermediate + * representation. It does not represent loops in the terms of a + * source program. + * Each ir_graph can contain one outermost loop data structure. + * loop is the entry point to the nested loops. + * The loop data structure contains a field indicating the depth of + * the loop within the nesting. Further it contains a list of the + * loops with nesting depth -1. Finally it contains a list of all + * nodes in the loop. + * + * @todo We could add a field pointing from a node to the containing loop, + * this would cost a lot of memory, though. + */ struct ir_loop { firm_kind kind; /**< A type tag, set to k_ir_loop. */ diff --git a/ir/ana/irscc.c b/ir/ana/irscc.c index 83aad9812..0a6833727 100644 --- a/ir/ana/irscc.c +++ b/ir/ana/irscc.c @@ -219,8 +219,6 @@ static INLINE void free_stack(void) { static INLINE void push (ir_node *n) { - /*DDMN(n);*/ - if (tos == ARR_LEN (stack)) { int nlen = ARR_LEN (stack) * 2; ARR_RESIZE (ir_node *, stack, nlen); @@ -255,8 +253,6 @@ pop_scc_to_loop (ir_node *n) do { m = pop(); - //printf(" dfn: %d, upl %d upl-new %d ", get_irn_dfn(m), get_irn_uplink(m), loop_node_cnt+1); DDMN(m); - loop_node_cnt++; set_irn_dfn(m, loop_node_cnt); add_loop_node(current_loop, m); @@ -431,8 +427,7 @@ ir_node *get_loop_node (ir_loop *loop, int pos) { if(node_nr == pos) return(loop -> children[child_nr].node); } - DDML(loop); - printf("pos: %d\n", pos); + assert(0 && "no child at pos found"); return NULL; } @@ -621,26 +616,6 @@ get_start_index(ir_node *n) { #endif } - -#if 0 -static void test(ir_node *pred, ir_node *root, ir_node *this) { - int i; - if (get_irn_uplink(pred) >= get_irn_uplink(root)) return; - - printf("this: %d ", get_irn_uplink(this)); DDMN(this); - printf("pred: %d ", get_irn_uplink(pred)); DDMN(pred); - printf("root: %d ", get_irn_uplink(root)); DDMN(root); - - printf("tos: %d\n", tos); - - for (i = tos; i >= 0; i--) { - ir_node *n = stack[i]; - if (!n) continue; - printf(" uplink: %d, pos: %d ", get_irn_uplink(n), i); DDMN(n); - } -} -#endif - /* Test for legal loop header: Block, Phi, ... */ static INLINE int is_possible_loop_head(ir_node *n) { ir_op *op = get_irn_op(n); @@ -673,7 +648,6 @@ is_head (ir_node *n, ir_node *root) some_outof_loop = 1; } else { if(get_irn_uplink(pred) < get_irn_uplink(root)) { - DDMN(n); DDMN(pred); DDMN(root); assert(get_irn_uplink(pred) >= get_irn_uplink(root)); } some_in_loop = 1; @@ -709,7 +683,6 @@ is_endless_head (ir_node *n, ir_node *root) some_outof_loop = 1; //printf(" some out of loop "); } else { if(get_irn_uplink(pred) < get_irn_uplink(root)) { - DDMN(pred); DDMN(root); assert(get_irn_uplink(pred) >= get_irn_uplink(root)); } some_in_loop = 1; @@ -863,7 +836,6 @@ int search_endproj_in_stack(ir_node *start_block) assert(is_Block(start_block)); for(i = tos - 1; i >= 0; --i) { - DDMN(stack[i]); if(get_irn_op(stack[i]) == op_Proj && get_irn_mode(stack[i]) == mode_X && get_irn_op(get_irn_n(stack[i], 0)) == op_EndReg) { @@ -875,7 +847,6 @@ int search_endproj_in_stack(ir_node *start_block) { ir_node *begin_projx = get_Block_cfgpred(get_irg_start_block(get_irn_irg(end_projx)), get_Proj_proj(end_projx)); - DDMN(begin_projx); if(get_irn_n(start_block, j) == begin_projx) { printf("FOUND IT!!!!!!!!!!!!!!!!!!\n"); @@ -898,9 +869,6 @@ void link_to_reg_end (ir_node *n, void *env) { ir_node *end_projx = n; ir_node *begin_projx = get_Block_cfgpred(get_irg_start_block(get_irn_irg(end_projx)), get_Proj_proj(end_projx)); - printf("Linked the following ProjxNodes:\n"); - DDMN(begin_projx); - DDMN(end_projx); set_projx_link(begin_projx, end_projx); } } @@ -1377,7 +1345,6 @@ static int test_loop_node(ir_loop *l) { assert(l && l->kind == k_ir_loop); if (get_loop_n_elements(l) == 0) { - printf(" Loop completely empty! "); DDML(l); found_problem = 1; dump_loop(l, "-ha"); } @@ -1385,24 +1352,18 @@ static int test_loop_node(ir_loop *l) { le = get_loop_element(l, 0); if (*(le.kind) != k_ir_node) { assert(le.kind && *(le.kind) == k_ir_loop); - printf(" First loop element is not a node! "); DDML(l); - printf(" "); DDML(le.son); found_problem = 1; dump_loop(l, "-ha"); } if ((*(le.kind) == k_ir_node) && !is_possible_loop_head(le.node)) { - printf(" Wrong node as head! "); DDML(l); - printf(" "); DDMN(le.node); found_problem = 1; dump_loop(l, "-ha"); } if ((get_loop_depth(l) != 0) && (*(le.kind) == k_ir_node) && !has_backedges(le.node)) { - printf(" Loop head has no backedges! "); DDML(l); - printf(" "); DDMN(le.node); found_problem = 1; dump_loop(l, "-ha"); } @@ -1418,7 +1379,6 @@ static int test_loop_node(ir_loop *l) { } if (has_node == 0) { - printf(" Loop has no firm node! "); DDML(l); found_problem = 1; dump_loop(l, "-ha"); } @@ -1432,7 +1392,6 @@ static int test_loop_node(ir_loop *l) { */ void find_strange_loop_nodes(ir_loop *l) { int found_problem = 0; - printf("\nTesting loop "); DDML(l); found_problem = test_loop_node(l); printf("Finished Test\n\n"); if (found_problem) exit(0); diff --git a/ir/ana/irsimpletype.c b/ir/ana/irsimpletype.c index 0ed59c076..28ab8259c 100644 --- a/ir/ana/irsimpletype.c +++ b/ir/ana/irsimpletype.c @@ -43,6 +43,7 @@ #include "irgwalk.h" #include "ident.h" #include "trouts.h" +#include "error.h" #define VERBOSE_UNKNOWN_TYPE(s) printf s @@ -396,12 +397,10 @@ default_code: { break; } - printf(" not implemented: "); DDMN(n); + panic(" not implemented: %+F", n); } break; /* default */ } /* end switch */ - /* printf (" found %s ", get_type_name(tp)); DDM; */ - return tp; } @@ -414,8 +413,6 @@ static ir_type *compute_irn_type(ir_node *n) { set_irn_typeinfo_type(n, tp); } - /* printf (" found %s ", get_type_name(tp)); DDM; */ - return tp; } diff --git a/ir/ana/rta.c b/ir/ana/rta.c index 41bec9e18..9fad78404 100644 --- a/ir/ana/rta.c +++ b/ir/ana/rta.c @@ -39,9 +39,8 @@ #include "eset.h" #include "irgwalk.h" #include "irgmod.h" -#include "typewalk.h" #include "irvrfy.h" -#include "trvrfy.h" +#include "irprintf.h" # ifndef TRUE # define TRUE 1 @@ -108,8 +107,7 @@ static int add_graph (ir_graph *graph) { if (!eset_contains (_live_graphs, graph)) { if (verbose > 1) { - fprintf(stdout, "RTA: new graph of "); - DDMEO(get_irg_entity (graph)); + ir_fprintf(stdout, "RTA: new graph of %+F\n", graph); } eset_insert (_live_graphs, graph); @@ -130,8 +128,7 @@ static int add_class (ir_type *clazz) { if (!eset_contains (_live_classes, clazz)) { if (verbose > 1) { - fprintf(stdout, "RTA: new class: "); - DDMT(clazz); + ir_fprintf(stdout, "RTA: new class: %+F\n", clazz); } eset_insert (_live_classes, clazz); @@ -158,8 +155,7 @@ static int add_implementing_graphs (ir_entity *method) } if (verbose > 1) { - fprintf(stdout, "RTA: new call to "); - DDMEO(method); + ir_fprintf(stdout, "RTA: new call to %+F\n", method); } if (rta_is_alive_class (get_entity_owner (method))) { @@ -220,7 +216,6 @@ static void rta_act (ir_node *node, void *env) /* STRANGE */ } else { - DDMN(ptr); assert(0 && "Unexpected address expression: can not analyse, therefore can not do correct rta!"); } @@ -289,8 +284,8 @@ static int rta_fill_incremental (void) graph = eset_next (live_graphs)) { if (verbose > 1) { - fprintf(stdout, "RTA: RUN %i: considering graph of ", n_runs); - DDMEO(get_irg_entity (graph)); + ir_fprintf(stdout, "RTA: RUN %i: considering graph of %+F\n", n_runs, + graph); } rerun |= rta_fill_graph (graph); @@ -558,14 +553,13 @@ void rta_report (void) for (i = 0; i < get_irp_n_types(); ++i) { ir_type *tp = get_irp_type(i); if (is_Class_type(tp) && rta_is_alive_class(tp)) { - fprintf(stdout, "RTA: considered allocated: "); DDMT(tp); + ir_fprintf(stdout, "RTA: considered allocated: %+F\n", tp); } } for (i = 0; i < get_irp_n_irgs(); i++) { if (rta_is_alive_graph (get_irp_irg(i))) { - fprintf(stdout, "RTA: considered called: graph of "); - DDMEO(get_irg_entity (get_irp_irg(i))); + ir_fprintf(stdout, "RTA: considered called: graph of %+F\n", get_irp_irg(i)); } } } diff --git a/ir/ana2/Makefile.in b/ir/ana2/Makefile.in deleted file mode 100644 index 6f77d0478..000000000 --- a/ir/ana2/Makefile.in +++ /dev/null @@ -1,41 +0,0 @@ -# -# Project: libFIRM -# File name: ir/ana/Makefile.in -# Purpose: -# Author: Boris Boesler, Till Riedel -# Modified by: -# Created: -# CVS-ID: $Id$ -# Copyright: (c) 1999-2003 Universität Karlsruhe -# Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. -# - -top_srcdir := @top_srcdir@ -srcdir = @srcdir@ -topdir = ../.. -subdir := ir/ana2 - -INSTALL_HEADERS = ecg.h irmemwalk.h lset.h typalise.h pto.h pto_comp.h \ - pto_ctx.h pto_debug.h pto_init.h pto_name.h pto_util.h pto_mod.h \ - qset.h gnu_ext.h - -SOURCES = $(INSTALL_HEADERS) - -SOURCES += Makefile.in \ - ecg.c irmemwalk.c lset.c typalise.c \ - pto.c \ - pto_comp.c pto_ctx.c pto_debug.c pto_init.c pto_name.c pto_util.c \ - pto_mod.c \ - qset.c - -include $(topdir)/MakeRules - -CPPFLAGS += -I$(top_srcdir)/ir/adt -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/common \ - -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr -I$(top_srcdir)/ir/tv \ - -I$(top_srcdir)/ir/debug -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st \ - -I$(top_srcdir)/ir/opt -I$(top_srcdir)/ir/arch -I$(top_srcdir)/ir/stat \ - -I$(top_srcdir)/ir/external -I$(topdir)/ir/config -I$(top_srcdir)/ir/arch - -include $(top_srcdir)/MakeTargets - -all: subdir.o diff --git a/ir/ana2/ecg.c b/ir/ana2/ecg.c deleted file mode 100644 index 6b3c7d7f4..000000000 --- a/ir/ana2/ecg.c +++ /dev/null @@ -1,1364 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Extended Call Graph - * @author Florian - * @date 14.09.2004 - * @version $Id$ - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - -/** - Erweiterter Aufrufgraph. -*/ - -#include "irnode.h" -#include "pmap.h" -/* #include "eset.h" */ -#include "irgwalk.h" -#include "irgmod.h" -#include "irvrfy.h" -#include "trvrfy.h" -#include "xmalloc.h" -#include "irdump.h" -#include "irprog_t.h" - -# ifndef TRUE -# define TRUE 1 -# define FALSE 0 -# endif /* not defined TRUE */ - -# define BUF_SIZE 1024 - -# include "ecg.h" -# include "typalise.h" -# include "lset.h" - -# include "gnu_ext.h" - -# define HERE(msg) fprintf (stdout, "%s:%i %s\n", __FUNCTION__, __LINE__, msg) - -/* - le flag -*/ -/* static int verbose = 0; */ -static int do_typalise = 0; - -/* - globals -*/ - -/* Ids for the ctxs */ -static int ctx_id = 0; -ctx_info_t *main_ctx = NULL; - -/* mapping from method graphs (callR) to method graphs (lset_ts of callEds) */ -/* static pmap *calls; */ -static pmap *graph_infos; - -/* linked list of all graph_infos: */ -static graph_info_t *graph_infos_list = NULL; - -/* Counters for ecg_ecg and friends */ -static long _graphs = 0; -static long _calls = 0; -static long _allocs = 0; - -static int _depth = 0; -static int _max_depth = 0; - -static int _max_callEds = 0; -static ir_entity* _max_callEds_callR = NULL; - -/* Protos */ -void set_main_ctx (ctx_info_t*); - -/* ==================== - Alloc stuff - ==================== */ -static void append_alloc (graph_info_t *ginfo, ir_node *alloc, ir_type *tp) -{ - alloc_info_t *ainfo = xmalloc (sizeof (alloc_info_t)); - - ainfo->graph = ginfo->graph; - ainfo->alloc = alloc; - ainfo->tp = tp; - - ainfo->prev = ginfo->allocs; - ginfo->allocs = ainfo; -} - - -/* ==================== - CallEd stuff - ==================== */ -/** - Create a new call info struct from the given values. -*/ -static call_info_t *new_call_info (ir_node *call, - callEd_info_t *callEds, - call_info_t *prev) -{ - call_info_t *cinfo = xmalloc (sizeof (call_info_t)); - cinfo->call = call; - cinfo->callEds = callEds; - cinfo->prev = prev; - - return (cinfo); -} - -/** - Append the given callEd to the given callEd info. -*/ -static callEd_info_t *append_callEd_info (callEd_info_t *ced, ir_graph *callEd) -{ - callEd_info_t *nced = xmalloc (sizeof (callEd_info_t)); - - assert (NULL != callEd); - - nced->callEd = callEd; - nced->prev = ced; - - return (nced); -} - -/** - Append all callEd methods of the given (call) node to the given graph_info. -*/ -static void append_calls (graph_info_t *info, ir_node *call, lset_t *callEds) -{ - ir_graph *callEd = NULL; - call_info_t *cinfo = new_call_info (call, NULL, info->calls); - - info->calls = cinfo; - - /* enter */ - callEd = lset_first (callEds); - - while (NULL != callEd) { - cinfo->callEds = append_callEd_info (cinfo->callEds, callEd); - callEd = lset_next(callEds); - } - -} - -/** - Append the (single) callEd to the given (call) node of the given graph_info. -*/ -static void append_call (graph_info_t *info, ir_node *call, ir_graph *callEd) -{ - call_info_t *cinfo = new_call_info (call, NULL, info->calls); - - info->calls = cinfo; - - cinfo->callEds = append_callEd_info (cinfo->callEds, callEd); -} - -/** - Given a method, find the firm graph that implements that method. - Return NULL for abstract and native methods. -*/ -static ir_graph *_get_implementing_graph (ir_entity *method) -{ - ir_graph *graph = NULL; - - /* What's up with the fenced out stuff in rta? */ - if (peculiarity_existent == get_entity_peculiarity (method)) { - if (visibility_external_allocated == get_entity_visibility (method)) { - /* Todo: native implementation */ - - return (NULL); - } else { - graph = get_entity_irg (get_SymConst_entity (get_atomic_ent_value (method))); - assert (graph && "no graph"); - - return (graph); - } - } else if (0 && (peculiarity_description == get_entity_peculiarity (method))) { - /* abstract --- can't find an implementation */ - graph = get_entity_irg (method); - assert (!graph && "graph in abstract method"); - - return (NULL); - } else if ((peculiarity_description == get_entity_peculiarity (method)) || - (peculiarity_inherited == get_entity_peculiarity (method))) { - /* search UPWARDS */ - int i; - int n_over = get_entity_n_overwrites (method); - - assert (!graph); - - for (i = 0; (NULL == graph) && (i < n_over); i ++) { - ir_entity *over = get_entity_overwrites (method, i); - - graph = _get_implementing_graph (over); - } - } else { - assert (0 && "invalid peculiarity"); - } - - - return (graph); -} - -/** - Collect all graphs of 'method' in the given set. -*/ -static void _collect_implementing_graphs (ir_entity *method, lset_t *set) -{ - /* search DOWN-wards in clazz hierarchy */ - int i; - int n_over = get_entity_n_overwrittenby (method); - ir_graph *graph = get_entity_irg (method); - - if (NULL == graph) { - graph = _get_implementing_graph (method); - } - - if (graph) { - lset_insert (set, graph); - } - - for (i = 0; i < n_over; i ++) { - ir_entity *over = get_entity_overwrittenby (method, i); - - _collect_implementing_graphs (over, set); - } -} - - -/** - Collect all graphs that could possibly be executed when 'method' is called. -*/ -static lset_t *get_implementing_graphs (ir_entity *method, ir_node *select) -{ - /* const char *name = get_entity_name (method); */ - /* fprintf (stdout, "%s (ent %s)\n", __FUNCTION__, name); */ - - int n_graphs; - lset_t *set = lset_create (); - { - ir_graph *impl = _get_implementing_graph (method); - - if (NULL != impl) { - lset_insert (set, impl); - } else { - /* actually, abstract OR native */ - } - } - - _collect_implementing_graphs (method, set); - - if (lset_empty (set)) { - /* then it's a method which is only implemented natively, and we - don' bother to analyse anything */ - return (set); - } - - /* void *tmp = lset_first (set); */ - n_graphs = lset_n_entries (set); - - - if (visibility_external_allocated != get_entity_visibility (method)) { - if (0 == n_graphs) { - ir_graph *graph = get_irn_irg (select); - - dump_ir_block_graph (graph, "-typealise"); - - /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */ - assert (n_graphs && "no graphs for method"); - } - } - /* typalise select_in */ - if (do_typalise) { - ir_node *select_in = get_Sel_ptr (select); - typalise_t *ta = typalise (select_in); - /* assert (ta && "typalise failed (go figure)"); */ - - /* - fprintf (stdout, "typalyse res = "); - - if (NULL != ta) { - if (type_invalid == ta->kind) { - fprintf (stdout, "invalid"); - } else if (type_exact == ta->kind) { - const char *name = get_type_name (ta->res.type); - - fprintf (stdout, "exact ["); - fprintf (stdout, "%s", name); - fprintf (stdout, "]\n"); - } else if (type_types == ta->kind) { - fprintf (stdout, "types ["); - fprintf (stdout, "..."); - fprintf (stdout, "]\n"); - } else if (type_type == ta->kind) { - const char *name = get_type_name (ta->res.type); - fprintf (stdout, "type ["); - fprintf (stdout, "%s", name); - fprintf (stdout, "]\n"); - } - } else { - fprintf (stdout, "(null)\n"); - } - */ - - if (1 != n_graphs) { - int n_filtered_graphs; - - set = filter_for_ta (set, ta); - n_filtered_graphs = lset_n_entries (set); - - /* - fprintf (stdout, "%s: %02d %02d\n", - __FUNCTION__, - n_graphs, - n_filtered_graphs, - n_graphs - n_filtered_graphs); - */ - n_graphs = n_filtered_graphs; - } - - if (visibility_external_allocated != get_entity_visibility (method)) { - if (0 == n_graphs) { - ir_graph *graph = get_irn_irg (select); - - dump_ir_block_graph (graph, "-ecg"); - /* fprintf (stdout, "no graphs for method %s\n", get_entity_name (method)); */ - assert (n_graphs && "no graphs for method"); - } - } - - } - - if (n_graphs > _max_callEds) { - _max_callEds = n_graphs; - _max_callEds_callR = method; - } - - - return (set); -} - -/** - Determine whether a call is actually a call or if it is being - abused for some b/d-ed reason. -*/ -static int call_is_call (ir_node *call, ir_node *ptr) -{ - if (op_SymConst != get_irn_op (ptr)) { - return (TRUE); - } else if (get_SymConst_kind (ptr) != symconst_addr_name) { - return (TRUE); - } - - return (FALSE); -} - -/** - Action for the graph. -*/ -static void ecg_calls_act (ir_node *node, void *env) -{ - ir_op *op = get_irn_op(node); - graph_info_t *graph_info = (graph_info_t*) env; - - if (op_Call == op) { /* CALL */ - ir_entity *ent = NULL; - ir_node *ptr = get_Call_ptr (node); - - if (!call_is_call (node, ptr)) { - /* - fprintf (stdout, "not a call: %s[%li]\n", - get_op_name (get_irn_op (node)), - get_irn_node_nr (node)); */ - return; - } - - /* CALL SEL */ - if (op_Sel == get_irn_op (ptr)) { - lset_t *graphs; - ent = get_Sel_entity (ptr); - graphs = get_implementing_graphs (ent, ptr); - - append_calls (graph_info, node, graphs); - } else if (op_SymConst == get_irn_op (ptr)) { - if (get_SymConst_kind (ptr) == symconst_addr_ent) { - ir_graph *graph; - ent = get_SymConst_entity (ptr); - graph = get_entity_irg (ent); - - if (graph) { - append_call (graph_info, node, graph); - } else { - /* it's an externally allocated thingy */ - } - } else if (get_SymConst_kind (ptr) == symconst_addr_name) { - /* If this SymConst refers to a method the method is external_visible - and therefore must be considered live anyways. */ - if (get_SymConst_name (ptr) != new_id_from_str ("iro_Catch")) { - assert (ent && "couldn't determine entity of call to symConst"); - } - } else { - /* other symconst. */ - assert (0 && "This SymConst can not be an address for a method call."); - } - - /* STRANGE, no less ... */ - } else { - DDMN (ptr); - assert (0 && "Unexpected address expression"); - } - } else if (op_Alloc == op) { - ir_type *tp = get_Alloc_type (node); - /* const char *name = get_type_name (tp); */ - - append_alloc (graph_info, node, tp); - - /* fprintf (stdout, "NEW \"%s\"\n", name); */ - } -} - -/** - Collect called graphs for the given graph. -*/ -static void ecg_fill_graph_calls (ir_graph *graph) -{ - graph_info_t *ginfo = xmalloc (sizeof (graph_info_t)); - - /* memset (ginfo, 0x00, sizeof (graph_info_t)); */ - assert (ginfo != graph_infos_list); - - ginfo->graph = graph; - ginfo->calls = NULL; - ginfo->allocs = NULL; - ginfo->ctxs = NULL; - ginfo->n_ctxs = 0; - ginfo->ecg_seen = 0; - ginfo->allocs_seen = 0; - ginfo->prev = NULL; - - /* link up into global list */ - ginfo->prev = graph_infos_list; - graph_infos_list = ginfo; - - assert (ginfo != ginfo->prev); - - irg_walk_graph (graph, ecg_calls_act, NULL, ginfo); - - pmap_insert (graph_infos, graph, ginfo); -} - -/** - For each graph, collect called graphs, and enter them into calls. -*/ -static void ecg_fill_calls (void) -{ - int i; - - for (i = 0; i < get_irp_n_irgs (); i++) { - ir_graph *graph = get_irp_irg (i); - - ecg_fill_graph_calls (graph); - } -} - -/** - Allocate a new ctx for the given graph and the given enclosing ctx. -*/ -static ctx_info_t *new_ctx (ir_graph *graph, ir_node *call, ctx_info_t *enc) -{ - ctx_info_t *res = xmalloc (sizeof (ctx_info_t)); - - res->graph = graph; - res->call = call; - res->enc = enc; - res->id = ctx_id ++; - - return (res); -} - - -/** - Fill in the ctxs parts of the graph_infos -*/ -static void ecg_fill_ctxs_count (ir_graph *graph) -{ - graph_info_t *ginfo = ecg_get_info (graph); - - /* count how many ctxs we have per graph */ - if (0 == ginfo->ecg_seen) { - call_info_t *cinfo = ginfo->calls; - - ginfo->ecg_seen = 1; - - while (NULL != cinfo) { - callEd_info_t *ced = cinfo->callEds; - - while (NULL != ced) { - ir_graph *callEd_graph = ced->callEd; - - /* first step: we have a new ctx */ - graph_info_t *callEd_info = ecg_get_info (callEd_graph); - callEd_info->n_ctxs ++; - - /* CallR graph -> CallEd_graph */ - ecg_fill_ctxs_count (callEd_graph); - - ced = ced->prev; - } /* end forall callEds (call) */ - - cinfo = cinfo->prev; - } /* end forall (calls(graph)) */ - - ginfo->ecg_seen = 0; - } -} - -static void ecg_fill_ctxs_alloc (void) -{ - /* allocate the memory needed for the ctxts: */ - graph_info_t *ginfo = graph_infos_list; - - while (NULL != ginfo) { - ginfo->ctxs = xcalloc (ginfo->n_ctxs, sizeof (ctx_info_t *)); - - /* - fprintf (stdout, "graph of \"%s\": n_ctxs = %i\n", - get_entity_name (get_irg_entity (ginfo->graph)), ginfo->n_ctxs); - */ - ginfo->n_ctxs = 0; - - assert (ginfo != ginfo->prev); - ginfo = ginfo->prev; - } -} - -/** - Fill in the ctxs parts of the graph_infos -*/ -static void ecg_fill_ctxs_write (ir_graph *graph, ctx_info_t *enc_ctx) -{ - graph_info_t *ginfo = ecg_get_info (graph); - - /* enter a new ctx for all callEds along the call edges of this graph */ - if (0 == ginfo->ecg_seen) { - call_info_t *cinfo = ginfo->calls; - ginfo->ecg_seen = 1; - - while (NULL != cinfo) { - callEd_info_t *ced = cinfo->callEds; - - while (NULL != ced) { - ctx_info_t *ctx = new_ctx (graph, cinfo->call, enc_ctx); - - ir_graph *callEd_graph = ced->callEd; - - /* write the ctx of this call into the callEd graph */ - graph_info_t *callEd_info = ecg_get_info (callEd_graph); - - callEd_info->ctxs [callEd_info->n_ctxs] = ctx; - callEd_info->n_ctxs ++; - - /* CallR graph -> callEd_graph */ - ecg_fill_ctxs_write (callEd_graph, ctx); - - ced = ced->prev; - } /* end forall callEds (call) */ - - cinfo = cinfo->prev; - } /* end forall (calls(graph)) */ - - ginfo->ecg_seen = 0; - } -} - -/** - Fill in the ctxs parts of the graph_infos -*/ -static void ecg_fill_ctxs (void) -{ - ctx_info_t *main_ctx; - ir_graph *main_irg; - graph_info_t *ginfo; - - ecg_fill_ctxs_count (get_irp_main_irg ()); - ecg_fill_ctxs_alloc (); - - main_ctx = new_ctx (get_irp_main_irg (), NULL, NULL); - main_irg = get_irp_main_irg (); - - set_main_ctx (main_ctx); - - /* Grrr, have to add this ctx manually to main.ginfo ... */ - ginfo = ecg_get_info (main_irg); - ginfo->n_ctxs = 1; - ginfo->ctxs = xcalloc (1, sizeof (ctx_info_t *)); - ginfo->ctxs [0] = main_ctx; - - ecg_fill_ctxs_write (main_irg, main_ctx); -} - -/* ==================== - CTX stuff - ==================== */ -/* - Nicely print a ctx_info_t to the given output stream -*/ -void ecg_print_ctx (ctx_info_t *ctx, FILE *stream) -{ - ir_entity *ent = get_irg_entity(ctx->graph); - ir_node *call = ctx->call; - const char *ent_name = get_entity_name (ent); - const char *own_name = get_type_name (get_entity_owner (ent)); - - fprintf (stream, "CTX[%i](%s.%s->%s[%li])", - ctx->id, own_name, ent_name, - get_op_name (get_irn_op (call)), - get_irn_node_nr (call)); - - if (NULL != ctx->enc) { - fprintf (stream, "->%i", ctx->enc->id); - } - - fprintf (stream, "\n"); -} - -/* - Get a ctx of the given graph info -*/ -ctx_info_t *get_ctx (graph_info_t *ginfo, int ctx_idx) -{ - assert (ginfo->n_ctxs > ctx_idx); - - return (ginfo->ctxs [ctx_idx]); -} - -/* - Get the pseudo-ctx of 'main' -*/ -ctx_info_t *get_main_ctx () -{ - return (main_ctx); -} - -/* - Set the pseudo-ctx of 'main' -*/ -void set_main_ctx (ctx_info_t *ctx) -{ - main_ctx = ctx; -} - - -/* ==================== - ECG stuff - ==================== */ - -/* ==================== - Iterator stuff - ==================== */ -/* - Iterate over all graphs -*/ -void ecg_iterate_graphs (graph_hnd_t *hnd, void *env) -{ - graph_info_t *ginfo = graph_infos_list; - - while (NULL != ginfo) { - /* do not visit graphs that have 0 == ginfo->n_ctxs, since they - are not called */ - if (0 != ginfo->n_ctxs) { - hnd (ginfo, env); - } - - ginfo = ginfo->prev; - } -} - - -/* - Iterate of all allocs of a given graph info -*/ -void ecg_iterate_allocs (graph_info_t *ginfo, alloc_hnd_t *hnd, void *env) -{ - alloc_info_t *ainfo = ginfo->allocs; - - while (NULL != ainfo) { - hnd (ainfo, env); - - ainfo = ainfo->prev; - } -} - - -/* - Iterate over all calls of the given graph info -*/ -void ecg_iterate_calls (graph_info_t *ginfo, call_hnd_t *hnd, void *env) -{ - call_info_t *cinfo = ginfo->calls; - - while (NULL != cinfo) { - hnd (cinfo, env); - - cinfo = cinfo->prev; - } -} - - -/* - Iterate over all callEds of the given call info -*/ -void ecg_iterate_callEds (call_info_t *cinfo, callEd_hnd_t *hnd, void *env) -{ - callEd_info_t *ced = cinfo->callEds; - - while (NULL != ced) { - hnd (ced, env); - - ced = ced->prev; - } -} - - -/* - get the call infos for the given graph -*/ -graph_info_t *ecg_get_info (ir_graph *graph) -{ - graph_info_t *ginfo = (graph_info_t*) pmap_get (graph_infos, graph); - - assert (ginfo && "no info for graph"); - - return (ginfo); -} - -/* - Get the Alloc Infos for the given graph -*/ -alloc_info_t *ecg_get_alloc_info (ir_graph *graph) -{ - graph_info_t *ginfo = ecg_get_info (graph); - - return (ginfo->allocs); -} - -/* - Get the Call Info for the given call -*/ -callEd_info_t *ecg_get_callEd_info (ir_node *call) -{ - ir_graph *graph = get_irn_irg (call); - graph_info_t *ginfo = ecg_get_info (graph); - - call_info_t *call_info = ginfo->calls; - - while (NULL != call_info) { - if (call == call_info->call) { - return (call_info->callEds); - } - - call_info = call_info->prev; - } - - return (NULL); -} - - -/** - Dump the given graph and it's calls and it's calls callEds to the given file. -*/ -static int ecg_ecg_graph (FILE *dot, ir_graph *graph) -{ - int graph_no; - call_info_t *cinfo; - alloc_info_t *ainfo; - const char *name = get_irg_entity (graph) ? - get_entity_name (get_irg_entity (graph)) : "noEntity"; - const char *color = - (get_entity_stickyness - (get_irg_entity (graph)) == stickyness_sticky) ? - "red" : "lightyellow"; - - /* graph_info_t *ginfo = (graph_info_t*) pmap_get (graph_infos, graph); */ - graph_info_t *ginfo = ecg_get_info (graph); - - if (0 != ginfo->ecg_seen) { - fprintf (dot, "\t/* recursive call to \"%s\" (%d) */\n", - name, (int) ginfo->ecg_seen); -# if 0 - fprintf (dot, "\t/* recursive call to \"%s\" (0x%08x) */\n", - name, (int) graph); -# endif /* 0 */ - return (ginfo->ecg_seen); - } - - assert (0L <= _graphs); - - graph_no = _graphs ++; - ginfo->ecg_seen = graph_no; - - fprintf (dot, "\t/* Graph of \"%s.%s\" */\n", - get_type_name (get_entity_owner (get_irg_entity (graph))), - name); - fprintf (dot, "\tgraph_%i [label=\"%s\\l%s\\l|n_ctx = %i\\l\", color=\"%s\"];\n", - graph_no, - get_type_name (get_entity_owner (get_irg_entity (graph))), - name, - ginfo->n_ctxs, - color); - fprintf (dot, "\n"); - - if (visibility_external_allocated == - get_entity_visibility (get_irg_entity (graph))) { - fprintf (dot, "\t/* graph \"%s\" is external */\n", name); - - return (graph_no); - } - - cinfo = ginfo->calls; - while (NULL != cinfo) { - ir_node *call = cinfo->call; - callEd_info_t *ced = cinfo->callEds; - const int call_no = _calls ++; - const char *call_color = (NULL == ced) ? "blue" : - (NULL == ced->prev) ? "lightblue" : "blue3"; - - fprintf (dot, "\t/* Call %li */\n", get_irn_node_nr (call)); - fprintf (dot, "\tcall_%i [label=\"call\\[%li\\]\", color=\"%s\", shape=\"ellipse\"];\n", - call_no, get_irn_node_nr (call), call_color); - fprintf (dot, "\tgraph_%i -> call_%i [color=\"black\"];\n", graph_no, call_no); - - while (NULL != ced) { - ir_graph *callEd_graph = ced->callEd; - const int callEd_no = ecg_ecg_graph (dot, callEd_graph); - const char *callEd_name = get_irg_entity (callEd_graph) ? - get_entity_name (get_irg_entity (callEd_graph)) : "noEntity"; - const char *direction = (callEd_no <= graph_no) ? "forward" : "forward"; - const char *callEd_color = (callEd_no <= graph_no) ? "red" : "black"; - - fprintf (dot, "\t/* Call from graph \"%s\" to graph \"%s\" */\n", - name, - callEd_name); - /* Check for recursive calls */ - /* if (callEd_no > graph_no) */ { /* do recursive calls (for now) */ - fprintf (dot, "\tcall_%i -> graph_%i:HEAD [color=\"%s\", dir=\"%s\"];\n", - call_no, callEd_no, callEd_color, direction); - } - - ced = ced->prev; - /* ced = NULL; */ - } /* done all calEds (call) */ - - cinfo = cinfo->prev; - } /* done all calls (graph) */ - - /* now the allocs */ - ainfo = ecg_get_alloc_info (graph); - if (ainfo) { - fprintf (dot, "\t/* now the allocs */\n"); - } else { - fprintf (dot, "\t/* no allocs */\n"); - } - - while (NULL != ainfo) { - ir_node *alloc = ainfo->alloc; - const char *name = get_type_name (ainfo->tp); - const char *color = "red1"; - - _allocs ++; - fprintf (dot, "\talloc_0x%08x_%i [label=\"%s\", color=\"%s\"];\n", - (int) alloc, graph_no, name, color); - - fprintf (dot, "\tgraph_%i -> alloc_0x%08x_%i;\n", - graph_no, (int) alloc, graph_no); - - ainfo = ainfo->prev; - } - - if (0 == ginfo->allocs_seen) { - ginfo->allocs_seen = 1; - } - - /* write table of ctxs */ - { - int i; - const int max_ctxs = 30; - const int n_ctxs = (ginfo->n_ctxs > max_ctxs) ? max_ctxs : ginfo->n_ctxs; - - fprintf (dot, "\tctx_%i [label=\"", graph_no); - - assert (ginfo->ctxs && "no ctx"); - for (i = 0; i < n_ctxs; i ++) { - ctx_info_t *ctx_info = ginfo->ctxs [i]; - - if (NULL != ctx_info->enc) { - fprintf (dot, "ctx_info \\[%i\\] = ctx\\[%i\\-\\>%i\\]\\l", - i, - ctx_info->id, - ctx_info->enc->id); - } else { - fprintf (dot, "ctx_info \\[%i\\] = ctx\\[%i\\]\\l", - i, ctx_info->id); - } - - if (i+1 != n_ctxs) { - fprintf (dot, "|"); - } - } - - if (0 < ginfo->n_ctxs - max_ctxs) { - fprintf (dot, "(%i more)\\l", ginfo->n_ctxs - max_ctxs); - } - - fprintf (dot, "\", color=\"green3\"];\n"); - - fprintf (dot, - "\tgraph_%i:CTX -> ctx_%i:HEAD [label=\"ctx\", dir=\"none\", style=\"dotted\"];\n", - graph_no, graph_no); - } - - fprintf (dot, "\t/* done with graph of \"%s\" */\n\n", name); - - fflush (dot); - ginfo->ecg_seen = 0; - - return (graph_no); -} - -/** - Count how many nodes the ECG will have -*/ -static char spaces [BUF_SIZE]; - -static void ecg_ecg_count (ir_graph *graph) -{ - int graph_no; - call_info_t *cinfo; - graph_info_t *ginfo = (graph_info_t*) pmap_get (graph_infos, graph); - - if (0 != ginfo->ecg_seen) { - return; - } - - _depth ++; - if (_depth > _max_depth) { - _max_depth = _depth; - - /* - fprintf (stdout, "_max_depth = %i\n", _max_depth); - fprintf (stdout, "\tn_graphs: %i\n", _graphs); - */ - } - - assert (0L <= _graphs); - - /* - if (0 == (_graphs % 1000000)) { - fprintf (stdout, "\tn_graphs: %i\n", _graphs); - fprintf (stdout, "_depth = %i\n", _depth); - } - */ - - graph_no = _graphs ++; - ginfo->ecg_seen = graph_no; - - fprintf (stdout, "%sMethod \"%s.%s\"\n", - spaces + BUF_SIZE - _depth, - get_type_name (get_entity_owner (get_irg_entity (graph))), - get_entity_name (get_irg_entity (graph))); - - cinfo = ginfo->calls; - while (NULL != cinfo) { - - callEd_info_t *ced = cinfo->callEds; - - fprintf (stdout, "%sCall \"0x%08x\"\n", - spaces + BUF_SIZE - _depth, - (int) cinfo->call); - - while (NULL != ced) { - ir_graph *callEd_graph = ced->callEd; - - fprintf (stdout, "%sCall Target \"%s.%s\"\n", - spaces + BUF_SIZE - _depth, - get_type_name (get_entity_owner (get_irg_entity (callEd_graph))), - get_entity_name (get_irg_entity (callEd_graph))); - - ecg_ecg_count (callEd_graph); - - ced = ced->prev; - } /* done all calEds (call) */ - cinfo = cinfo->prev; - } /* done all calls (graph) */ - - ginfo->ecg_seen = 0; - _depth --; -} - -/* ==================== - Public Interface - ==================== */ - -/** - Initialise our data structures. -*/ -void ecg_init (int typalise) -{ - do_typalise = typalise; - - if (typalise) { - typalise_init (); - } - - graph_infos = pmap_create (); - - ecg_fill_calls (); - ecg_fill_ctxs (); - ecg_ecg (); -} - -/** - Clean up our mess. -*/ -void ecg_cleanup (void) -{ - int i; - - return; - - for (i = 0; i < get_irp_n_irgs (); i++) { - ir_graph *graph = get_irp_irg (i); - - graph_info_t *info = pmap_get (graph_infos, graph); - call_info_t *cinfo = info->calls; - - while (NULL != cinfo) { - callEd_info_t *ced = cinfo->callEds; - - cinfo->call = NULL; - - while (NULL != ced) { - callEd_info_t *nced = ced->prev; - free (ced); - ced->prev = NULL; - ced->callEd = NULL; - ced = nced; - } - - cinfo->callEds = NULL; - - free (cinfo); - cinfo = cinfo->prev; - } - - free (info); - pmap_insert (graph_infos, graph, NULL); - } - - - pmap_destroy (graph_infos); - - /* paranoia mode */ - graph_infos = NULL; -} - -/** - Show what we have found. -*/ -void ecg_report () -{ - int i; - - FILE *dot = fopen ("calls.dot", "w"); - - fprintf (dot, "digraph \"calls\" {\n"); - fprintf (dot, "\tgraph [rankdir=\"LR\", ordering=\"out\", size=\"11, 7\", rotate=\"90\", ratio=\"fill\"];\n"); - fprintf (dot, "\tnode [shape=\"record\", style=\"filled\"];\n"); - fprintf (dot, "\tedge [color=\"black\"];\n"); - fprintf (dot, "\n"); - - for (i = 0; i < get_irp_n_irgs (); i++) { - ir_graph *graph = get_irp_irg (i); - graph_info_t *ginfo = (graph_info_t*) pmap_get (graph_infos, graph); - - if (0 != ginfo->n_ctxs) { - call_info_t *cinfo; - alloc_info_t *ainfo; - - const char *name = get_irg_entity (graph) ? - get_entity_name (get_irg_entity (graph)) : "noEntity"; - - const char *oname = get_type_name - (get_entity_owner (get_irg_entity (graph))); - - const char *color = - (get_entity_stickyness - (get_irg_entity (graph)) == stickyness_sticky) ? - "red3" : "lightyellow"; - - fprintf (dot, "\t/* graph_0x%08x (\"%s\") */\n", (int) graph, name); - fprintf (dot, - "\tgraph_0x%08x [label=\"%s\\l%s\", color=\"%s\"];\n", - (int) graph, oname, name, color); - fprintf (dot, "\n"); - - cinfo = ginfo->calls; - if (cinfo) { - fprintf (dot, "\t/* now the calls */\n"); - } else { - fprintf (dot, "\t/* no calls, nothing to see, move along! */\n"); - } - - while (NULL != cinfo) { - callEd_info_t *ced; - ir_node *call = cinfo->call; - - fprintf (dot, "\t/* call_0x%08x */\n", (int) call); - fprintf (dot, "\tcall_0x%08x [label=\"call\\[%li\\]\", shape=\"ellipse\", color=\"lightblue\"];\n", - (int) call, get_irn_node_nr (call)); - fprintf (dot, "\tgraph_0x%08x -> call_0x%08x;\n", - (int) graph, (int) call); - - ced = cinfo->callEds; - while (NULL != ced) { - fprintf (dot, "\tcall_0x%08x -> graph_0x%08x;\n", - (int) call, (int) ced->callEd); - ced = ced->prev; - } - fprintf (dot, "\n"); - - cinfo = cinfo->prev; - } - fprintf (dot, "\n"); - - ainfo = ginfo->allocs; - if (ainfo) { - fprintf (dot, "\t/* now the allocs */\n"); - } else { - fprintf (dot, "\t/* no allocs */\n"); - } - - /* allocs */ - while (NULL != ainfo) { - ir_node *alloc = ainfo->alloc; - const char *name = get_type_name (ainfo->tp); - const char *color = "red1"; - - fprintf (dot, "\talloc_0x%08x [label=\"%s\", color=\"%s\"];\n", - (int) alloc, name, color); - fprintf (dot, "\tgraph_0x%08x -> alloc_0x%08x;\n", - (int) graph, (int) alloc); - - ainfo = ainfo->prev; - } - - /* ctxs */ - { - int i; - const int max_ctxs = 30; - const int n_ctxs = (ginfo->n_ctxs > max_ctxs) ? max_ctxs : ginfo->n_ctxs; - - fprintf (dot, "\t/* now the ctxs */\n"); - fprintf (dot, "\tctx_0x%08x [label=\"", (int) graph); - - assert (ginfo->ctxs && "no ctx"); - for (i = 0; i < n_ctxs; i ++) { - ctx_info_t *ctx_info = ginfo->ctxs [i]; - - if (NULL != ctx_info->enc) { - fprintf (dot, "ctx_info \\[%i\\] = ctx\\[%i\\-\\>%i\\]\\l", - i, - ctx_info->id, - ctx_info->enc->id); - } else { - fprintf (dot, "ctx_info \\[%i\\] = ctx\\[%i\\]\\l", - i, ctx_info->id); - } - - if (i+1 != n_ctxs) { - fprintf (dot, "|"); - } - } - - if (0 < ginfo->n_ctxs - max_ctxs) { - fprintf (dot, "(%i more)\\l", ginfo->n_ctxs - max_ctxs); - } - - fprintf (dot, "\", color=\"green3\"];\n"); - - fprintf (dot, - "\tgraph_0x%p -> ctx_0x%p:HEAD [label=\"ctx\", dir=\"none\", style=\"dotted\"];\n", - graph, graph); - } - } else { - fprintf (dot, "\t/* graph is not called */\n"); - } /* end all graphs */ - } - fprintf (dot, "}\n"); - - /* - fprintf (stdout, " max_callEds: %i\n", _max_callEds); - fprintf (stdout, " max_callEds_callR: \"%s\"\n", - get_entity_name (_max_callEds_callR)); - */ - fclose (dot); -} - -/** - Experimental: Print the ecg -*/ -void ecg_ecg (void) -{ - FILE *dot; - ir_graph *main_graph = get_irp_main_irg (); - - _graphs = 0; - _calls = 0; - - /* - memset (spaces, '.', BUF_SIZE); - spaces [BUF_SIZE-1] = '\0'; - - ecg_ecg_count (main_graph); - fprintf (stdout, "n_graphs: %i\n", _graphs); - fprintf (stdout, "max_depth = %i\n", _max_depth); - */ - - /* return; */ - - _graphs = 0; - _calls = 0; - - dot = fopen ("ecg.dot", "w"); - - fprintf (dot, "digraph \"ecg\" {\n"); - fprintf (dot, "\tgraph [rankdir=\"LR\", ordering=\"out\", size=\"11, 7\", rotate=\"90\", ratio=\"fill\"];\n"); - fprintf (dot, "\tnode [shape=\"record\", style=\"filled\"];\n"); - fprintf (dot, "\tedge [color=\"black\"];\n"); - fprintf (dot, "\n"); - fprintf (dot, "\n"); - - /* ir_graph *main_graph = get_irp_main_irg (); */ - ecg_ecg_graph (dot, main_graph); - - fprintf (dot, "\t/* Grand Total: */\n"); - fprintf (dot, "\t/* calls: %i */\n", (int) _calls); - fprintf (dot, "\t/* graphs: %i */\n", (int) _graphs); - fprintf (dot, "\t/* allocs: %i */\n", (int) _allocs); - fprintf (dot, "\t/* (sales tax not included) */\n"); - - fprintf (dot, "}\n"); - - fclose (dot); -} - - - -/* - $Log: ecg.c,v $ - Revision 1.23 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.22 2006/01/13 22:55:03 beck - renamed all types 'type' to 'ir_type' - - Revision 1.21 2005/12/31 15:58:57 beck - added missing includes - - Revision 1.20 2005/12/05 12:01:06 beck - needed include added - - Revision 1.19 2005/03/22 13:55:51 liekweg - Need to initialise typalise now - - Revision 1.18 2005/01/14 14:14:43 liekweg - fix gnu extension - - Revision 1.17 2005/01/14 13:34:25 liekweg - Factor out call_info_t ctor; fix mallocs; fix initialisation - - Revision 1.16 2005/01/10 17:26:34 liekweg - fixup printfs, don't put environments on the stack - - Revision 1.15 2004/12/23 15:40:03 beck - used new xcalloc - - Revision 1.14 2004/12/22 14:43:14 beck - made allocations C-like - - Revision 1.13 2004/12/21 14:21:16 beck - removed C99 constructs - - Revision 1.12 2004/12/20 17:34:34 liekweg - fix recursion handling - - Revision 1.11 2004/12/15 09:18:18 liekweg - pto_name.c - - Revision 1.10 2004/12/06 12:55:06 liekweg - actually iterate - - Revision 1.9 2004/12/02 16:17:50 beck - fixed config.h include - - Revision 1.8 2004/11/30 14:45:44 liekweg - fix graph dumping, remove 'HERE's - - Revision 1.7 2004/11/26 16:01:56 liekweg - debugging annotations - - Revision 1.6 2004/11/24 14:53:55 liekweg - Bugfixes - - Revision 1.5 2004/11/20 21:20:29 liekweg - Added iterator functions - - Revision 1.4 2004/11/18 16:36:37 liekweg - Added unique ids for debugging, added access functions - - Revision 1.3 2004/11/04 14:54:44 liekweg - Nicer Colors - - Revision 1.2 2004/10/21 11:09:37 liekweg - Moved memwalk stuf into irmemwalk - Moved lset stuff into lset - Moved typalise stuff into typalise - - Revision 1.1 2004/10/20 14:59:41 liekweg - Added ana2, added ecg and pto - - Revision 1.6 2004/10/18 12:47:19 liekweg - minor fix - - Revision 1.5 2004/10/14 11:31:28 liekweg - SHUTUP_GCC - - Revision 1.4 2004/10/12 11:02:01 liekweg - wtf? - -*/ diff --git a/ir/ana2/ecg.h b/ir/ana2/ecg.h deleted file mode 100644 index 1b576eca7..000000000 --- a/ir/ana2/ecg.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Extended Call Graph - * @author Florian - * @version $Id$ - */ -#ifndef FIRM_ANA2_EGC_H -#define FIRM_ANA2_EGC_H - -# include "irgraph.h" -# include "irnode.h" - -/* - data -*/ - -typedef struct ctx_info -{ - ir_graph *graph; /* The graph of the callR who created this ctx */ - /* (which is redundant, since it's always == get_irn_graph (call) */ - ir_node *call; /* The call through which this graph was called */ - struct ctx_info *enc; /* The ctx in which our callR was called */ - int id; -} ctx_info_t; - -typedef struct alloc_info -{ - ir_graph *graph; - ir_node *alloc; - ir_type *tp; - struct alloc_info *prev; -} alloc_info_t; - -typedef struct callEd_info -{ - ir_graph *callEd; - struct callEd_info *prev; -} callEd_info_t; - -typedef struct call_info -{ - ir_node *call; - callEd_info_t *callEds; - struct call_info *prev; -} call_info_t; - -typedef struct graph_info -{ - ir_graph *graph; - call_info_t *calls; - alloc_info_t *allocs; - ctx_info_t **ctxs; - int n_ctxs; - int ecg_seen; - int allocs_seen; - struct graph_info *prev; -} graph_info_t; - -typedef void graph_hnd_t (graph_info_t*, void*); -typedef void alloc_hnd_t (alloc_info_t*, void*); -typedef void call_hnd_t (call_info_t*, void*); -typedef void callEd_hnd_t (callEd_info_t*, void*); - -/* protos */ -void ecg_print_ctx (ctx_info_t*, FILE *stream); - -ctx_info_t *get_ctx (graph_info_t*, int); -ctx_info_t *get_main_ctx (void); - -void ecg_iterate_graphs (graph_hnd_t*, void*); -void ecg_iterate_allocs (graph_info_t*, alloc_hnd_t*, void*); -void ecg_iterate_calls (graph_info_t*, call_hnd_t*, void*); -void ecg_iterate_callEds (call_info_t*, callEd_hnd_t*, void*); - -graph_info_t *ecg_get_info (ir_graph*); -alloc_info_t *ecg_get_alloc_info (ir_graph*); -callEd_info_t *ecg_get_callEd_info (ir_node*); - -void ecg_init (int); -void ecg_cleanup (void); -void ecg_report (void); -void ecg_ecg (void); - -#endif /* defined _EGC_H_ */ - - -/* -$Log$ -Revision 1.4 2006/01/13 22:00:15 beck -renamed all types 'type' to 'ir_type' - -Revision 1.3 2004/11/20 21:20:29 liekweg -Added iterator functions - -Revision 1.2 2004/11/18 16:36:37 liekweg -Added unique ids for debugging, added access functions - -Revision 1.1 2004/10/20 14:59:42 liekweg -Added ana2, added ecg and pto - -Revision 1.3 2004/10/14 11:31:29 liekweg -SHUTUP_GCC - -Revision 1.2 2004/10/12 11:02:03 liekweg -wtf? - -Revision 1.1 2004/09/29 12:03:39 liekweg -Added ecg mod - */ diff --git a/ir/ana2/gnu_ext.h b/ir/ana2/gnu_ext.h deleted file mode 100644 index a1feaf72a..000000000 --- a/ir/ana2/gnu_ext.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Provide some GNU CC extensions to the rest of the world - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -/* - gnu_ext: Provide some GNU CC extensions to the rest of the world -*/ - -/* Includes */ - -/* Local Defines: */ -# if !defined (__GNUC__) -# if !defined(__FUNCTION__) -# define __FUNCTION__ "::" -# endif -# if !defined(__PRETTY_FUNCTION__) -# define __PRETTY_FUNCTION__ ":::" -# endif -# endif /* !define __GNUC__ */ - -/* Local Data Types: */ - -/* Local Variables: */ - -/* Local Prototypes: */ - -/* =================================================== - Local Implementation: - =================================================== */ - -/* =================================================== - Exported Implementation: - =================================================== */ - - -/* - $Log$ - Revision 1.2 2006/07/02 16:30:17 beck - Fixed warnings on newer VC - - Revision 1.1 2005/01/14 14:15:19 liekweg - Support GNU extensions on non-GNU platforms - - -*/ diff --git a/ir/ana2/irmemwalk.c b/ir/ana2/irmemwalk.c deleted file mode 100644 index 0f587dd89..000000000 --- a/ir/ana2/irmemwalk.c +++ /dev/null @@ -1,313 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief walk along memory edges - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - * @summary - * Walk over a firm graph along its memory edges. - * - * Any number of graphs can be visited at the same time, but no graph - * can be traversed more than once at any time. - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -# include "irnode_t.h" -# include "irgwalk.h" /* for irg_walk_func */ -# include "irprog.h" /* for get_irp_main_irg */ -# include "xmalloc.h" -# include "gnu_ext.h" - -# ifndef TRUE -# define TRUE 1 -# define FALSE 0 -# endif /* not defined TRUE */ - -/* - Data -*/ - -/** environment for a single memory walker */ -typedef struct walk_mem_env_str { - ir_graph *graph; /**< the graph we're visiting */ - unsigned long visited; /**< 'visited' marker - (unsigned long in case we walk more than 2^32 graphs) */ - irg_walk_func *pre; /**< pre action */ - irg_walk_func *post; /**< post action */ - void *env; /**< user-defined environment */ - - struct walk_mem_env_str *prev; /**< link up walking instances */ - /* what else? */ -} walk_mem_env_t; - -/* - Globals -*/ - -/* Link up walking instances */ -static walk_mem_env_t *walk_envs = NULL; - -/* - Walk over the firm nodes of a graph via the memory edges (only) - starting from a node that has a memory input. -*/ -static void irg_walk_mem_node (ir_node *node, - walk_mem_env_t *walk_env) -{ - const ir_opcode op = get_irn_opcode (node); - ir_node *in = NULL; - - if (get_irn_visited (node) >= walk_env->visited) { - return; - } else { - set_irn_visited (node, walk_env->visited); - } - - if (op_NoMem == get_irn_op (node)) { - /* We don't want to see it it if it's not memory */ - return; - } - - if (iro_Proj == op) { - /* We don't want to see proj nodes at all --- skip over them */ - in = get_Proj_pred (node); - - irg_walk_mem_node (in, walk_env); - - return; - } - - /* execute the 'pre' function */ - if (NULL != walk_env->pre) { - walk_env->pre (node, walk_env->env); - } - - switch (op) { - case (iro_Start): { - } break; - case (iro_Load): { - in = get_Load_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Store): { - in = get_Store_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Alloc): { - in = get_Alloc_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Free): { - in = get_Free_mem (node); - /* WTF? */ - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Raise): { - in = get_Raise_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Sel): { - in = get_Sel_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Call): { - in = get_Call_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Return): { - in = get_Return_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Phi): { - int i; - int n_ins = get_irn_arity (node); - - for (i = 0; i < n_ins; i ++) { - in = get_irn_n (node, i); - - irg_walk_mem_node (in, walk_env); - } - } break; - case (iro_Div): { - in = get_Div_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Quot): { - in = get_Quot_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Mod): { - in = get_Mod_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_DivMod): { - in = get_DivMod_mem (node); - - irg_walk_mem_node (in, walk_env); - } break; - case (iro_Block): { - /* End Block ONLY */ - int i; - int n_ins = get_irn_arity (node); - - for (i = 0; i < n_ins; i ++) { - ir_node *ret = get_irn_n (node, i); - - irg_walk_mem_node (ret, walk_env); - } - } break; - default: { - fprintf (stderr, "%s: not handled: node[%li].op = %s\n", - __FUNCTION__, - get_irn_node_nr (node), - get_op_name (get_irn_op (node))); - - assert (0 && "something not handled"); - } - } - - /* execute the 'post' function */ - if (NULL != walk_env->post) { - walk_env->post (node, walk_env->env); - } -} - -/* - See whether the given graph is being visited right now. - We can't be visiting a graph multiple times. -*/ -int get_irg_is_mem_visited (ir_graph *graph) -{ - walk_mem_env_t *walk_env = walk_envs; - - while (NULL != walk_env) { - if (graph == walk_env->graph) { - return (TRUE); - } - - walk_env = walk_env->prev; - } - - return (FALSE); -} - -/* - Walk over the nodes of the given graph via the memory edges (only). - Each graph can only be subject to this walk once at any given time. -*/ -void irg_walk_mem (ir_graph *graph, - irg_walk_func *pre, irg_walk_func *post, - void *env) -{ - ir_node *end_block = get_irg_end_block (graph); - walk_mem_env_t *walk_env = xmalloc (sizeof (walk_mem_env_t)); - - assert (! get_irg_is_mem_visited (graph)); - - walk_env->graph = graph; - inc_irg_visited (walk_env->graph); - walk_env->visited = get_irg_visited (graph); - - walk_env->prev = walk_envs; - walk_envs = walk_env; - - walk_env->pre = pre; - walk_env->post = post; - walk_env->env = env; - - /* 'graph' is not actually being visited right now, so make sure it is reported that way */ - assert (get_irg_is_mem_visited (graph)); - - /* - The ins of the end BLOCK are either 'return's (regular exits) or - 'ProjX'/'Raise's (exception exits). We only walk over the - 'return' nodes, assuming that all memory-changing nodes are found - from there on. - */ - irg_walk_mem_node (end_block, walk_env); - /* - The end NODE sometimes has some more ins. not sure whether we need to walk them. - */ - - /* allow only properly nested calls right now */ - assert (walk_envs == walk_env); - walk_envs = walk_envs->prev; - - free (walk_env); - - assert (! get_irg_is_mem_visited (graph)); -} - - - -/* - $Log$ - Revision 1.12 2007/01/16 15:45:42 beck - renamed type opcode to ir_opcode - - Revision 1.11 2005/01/26 12:20:20 beck - gnu_ext.h included - - Revision 1.10 2005/01/14 13:34:48 liekweg - Don't cast malloc - - Revision 1.9 2005/01/10 17:26:34 liekweg - fixup printfs, don't put environments on the stack - - Revision 1.8 2004/12/22 14:43:14 beck - made allocations C-like - - Revision 1.7 2004/12/21 14:25:35 beck - removed C99 constructs - make visit counter of same type as irn visit counter - - Revision 1.6 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.5 2004/11/19 10:35:20 liekweg - also test for NoMem - - Revision 1.4 2004/11/18 16:35:11 liekweg - Do not touch Proj nodes at all - - Revision 1.3 2004/11/04 14:57:12 liekweg - fixed end block handling - - Revision 1.2 2004/10/22 14:41:12 liekweg - execute 'pre' for a change. Also, add CVS log - - -*/ diff --git a/ir/ana2/irmemwalk.h b/ir/ana2/irmemwalk.h deleted file mode 100644 index 97cc4aa7c..000000000 --- a/ir/ana2/irmemwalk.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief walk along memory edges - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_IRMEMWALK_H -# define FIRM_ANA2_IRMEMWALK_H - -# include "irgraph.h" -# include "irgwalk.h" - -void irg_walk_mem (ir_graph*, irg_walk_func*, irg_walk_func*, void*); -int get_irg_is_mem_visited (ir_graph*); - -# endif - - -/* - $Log$ - Revision 1.1 2004/10/21 11:09:37 liekweg - Moved memwalk stuf into irmemwalk - Moved lset stuff into lset - Moved typalise stuff into typalise - - - */ diff --git a/ir/ana2/lset.c b/ir/ana2/lset.c deleted file mode 100644 index 12569b027..000000000 --- a/ir/ana2/lset.c +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Lists, err, Sets - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -# include "lset.h" -# include "xmalloc.h" - -# ifndef TRUE -# define TRUE 1 -# define FALSE 0 -# endif /* not defined TRUE */ - -# include - -#ifdef HAVE_STRING_H -# include /* need memset */ -#endif - -/* - Lists, err, Sets - */ - -/* create a new lset */ -lset_t *lset_create (void) -{ - lset_t *lset = xmalloc (sizeof (lset_t)); - memset (lset, 0x00, sizeof (lset_t)); - - return (lset); -} - -/* check whether the lset contains an entry for the given data */ -int lset_contains (lset_t *lset, void *data) -{ - lset_entry_t *entry = lset->first; - - while (NULL != entry) { - if (data == entry->data) { - return (TRUE); - } - - entry = entry->next; - } - - return (FALSE); -} - -/* check whether the given lset is empty */ -int lset_empty (lset_t *lset) -{ - return (NULL == lset->first); -} - - -/* insert the data into the lset (unless there's an entry for it - already) */ -void lset_insert (lset_t *lset, void *data) -{ - if (! lset_contains (lset, data)) { - lset_entry_t *entry = xmalloc (sizeof (lset_entry_t)); - - entry->data = data; - entry->next = lset->first; - lset->first = entry; - - if (NULL == lset->last) { - lset->last = entry; - } - - lset->n_entries ++; - } -} - -/* insert all entries from src into tgt */ -void lset_insert_all (lset_t *tgt, lset_t *src) -{ - lset_entry_t *curs = src->first; - - while (NULL != curs) { - lset_insert (tgt, curs->data); - - curs = curs->next; - } -} - -/* append src to tgt. src is deallocated. */ -void lset_append (lset_t *tgt, lset_t *src) -{ - assert (! tgt->last->next); - - tgt->last->next = src->first; - tgt->last = src->last; - tgt->n_entries += src->n_entries; - - memset (src, 0x00, sizeof (lset_t)); - free (src); -} - -/* remove the entry for the given data element from the lset. return - TRUE iff it was on the list in the first place, FALSE else */ -int lset_remove (lset_t *lset, void *data) -{ - lset_entry_t *entry = lset->first; - lset_entry_t *prev = NULL; - - while (NULL != entry) { - if (data == entry->data) { - /* ok, dike it out */ - - if (NULL == prev) { /* ok, it's lset->first that needs diking */ - lset->first = entry->next; - } else { - prev->next = entry->next; - } - - memset (entry, 0x00, sizeof (lset_entry_t)); - free (entry); - - lset->n_entries --; - - return (TRUE); - } - - prev = entry; - entry = entry->next; - } - - return (FALSE); -} - -/* prepare the given lset for an iteration. return the first element. */ -void *lset_first (lset_t *lset) -{ - lset->curs = lset->first; - - if (lset->first) { - return (lset->first->data); - } else { - return (NULL); - } -} - -/* after calling lset_first, get the next element, if applicable, or - NULL */ -void *lset_next (lset_t *lset) -{ - lset->curs = lset->curs->next; - - if (lset->curs) { - return (lset->curs->data); - } else { - return (NULL); - } -} - -/* say how many entries there are in the given lset */ -int lset_n_entries (lset_t *lset) -{ - return (lset->n_entries); -} - -/* deallocate the lset and all of its entries */ -void lset_destroy (lset_t *lset) -{ - lset_entry_t *curs = lset->first; - - while (NULL != curs) { - lset_entry_t *tmp = curs->next; - - memset (curs, 0x00, sizeof (lset_entry_t)); - free (curs); - - curs = tmp; - } - - memset (lset, 0x00, sizeof (lset_t)); - free (lset); -} - - - -/* - $Log$ - Revision 1.4 2005/01/14 13:36:10 liekweg - fix malloc, fix "initialisation" - - Revision 1.3 2004/12/22 14:43:14 beck - made allocations C-like - - Revision 1.2 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.1 2004/10/21 11:09:37 liekweg - Moved memwalk stuf into irmemwalk - Moved lset stuff into lset - Moved typalise stuff into typalise - - - */ diff --git a/ir/ana2/lset.h b/ir/ana2/lset.h deleted file mode 100644 index 5e58abf52..000000000 --- a/ir/ana2/lset.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Lists, err, Sets - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_LSET_H -# define FIRM_ANA2_LSET_H - -/* - Data Types and Structures -*/ -/* Lists, err, Sets */ -typedef struct lset_entry -{ - void *data; - struct lset_entry *next; -} lset_entry_t; - -typedef struct lset -{ - lset_entry_t *first; - lset_entry_t *last; /* useful for lset_append */ - lset_entry_t *curs; /* for lset_first/lset_next */ - int n_entries; -} lset_t; - -/* create a new lset */ -lset_t *lset_create (void); -/* check whether the lset contains an entry for the given data */ -int lset_contains (lset_t*, void*); -/* check whether the given lset is empty */ -int lset_empty (lset_t*); -/* insert the data into the lset (unless there's an entry for it - already) */ -void lset_insert (lset_t*, void*); -/* insert all entries from src into tgt */ -void lset_insert_all (lset_t*, lset_t*); -/* append src to tgt. src is deallocated. */ -void lset_append (lset_t*, lset_t*); - -/* remove the entry for the given data element from the lset. return - TRUE iff it was on the list in the first place, FALSE else */ -int lset_remove (lset_t*, void*); -/* prepare the given lset for an iteration. return the first element. */ -void *lset_first (lset_t*); -/* after calling lset_first, get the next element, if applicable, or - NULL */ -void *lset_next (lset_t*); -/* say how many entries there are in the given lset */ -int lset_n_entries (lset_t*); -/* deallocate the lset and all of its entries */ -void lset_destroy (lset_t*); - - - -# endif - - -/* - $Log$ - Revision 1.1 2004/10/21 11:09:37 liekweg - Moved memwalk stuf into irmemwalk - Moved lset stuff into lset - Moved typalise stuff into typalise - - - */ diff --git a/ir/ana2/pto.c b/ir/ana2/pto.c deleted file mode 100644 index ce05df5a5..000000000 --- a/ir/ana2/pto.c +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Entry to PTO - * @author Florian - * @date Tue Nov 23 18:37:09 CET 2004 - * @version $Id$ - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* - pto: Entry to PTO -*/ - -#ifdef HAVE_STRING_H -# include -#endif - -# include "pto.h" - -# include "irnode_t.h" -# include "irprog.h" -# include "xmalloc.h" - -# include "pto_debug.h" -# include "pto_init.h" -# include "pto_name.h" -# include "pto_ctx.h" -# include "ecg.h" - -/* Local Defines: */ - -/* Local Data Types: */ - -/* Local Variables: */ -extern char *spaces; - -/* Local Prototypes: */ - -/* =================================================== - Local Implementation: - =================================================== */ - -/* Helper to pto_init */ -static void pto_init_graph_wrapper (graph_info_t *ginfo, void *_unused) -{ - ir_graph *graph = ginfo->graph; - - pto_init_graph (graph); -} - -/* =================================================== - Exported Implementation: - =================================================== */ -/* Initialise the module (not in pto_init.c because it's the entry to pto) */ -void pto_init (int lvl) -{ - set_dbg_lvl (lvl); - - ecg_init (1); - - /* Initialise the name module */ - pto_name_init (); - - /* Initialise the init module */ - pto_init_init (); - - /* allocate ctx-sens names for allocs and set ... etc etc */ - pto_init_type_names (); - - /* initialise all graphs with the static names */ - ecg_iterate_graphs (pto_init_graph_wrapper, NULL); - - /* debugging only */ - spaces = xmalloc (512 * sizeof (char)); - memset (spaces, ' ', 512); - spaces += 511; - *spaces = '\0'; - - /* initialise for the CTX-sensitive ecg-traversal */ - set_curr_ctx (get_main_ctx ()); -} - -void pto_run (void) -{ - ir_graph *save; - ir_graph *graph = get_irp_main_irg (); - - pto_reset_graph_pto (graph, 0); - fake_main_args (graph); - - DBGPRINT (1, (stdout, "START PTO\n")); - DBGPRINT (1, (stdout, "START GRAPH (0x%08x) of \"%s.%s\"\n", - (int) graph, - get_type_name (get_entity_owner (get_irg_entity (graph))), - get_entity_name (get_irg_entity (graph)))); - - /* we need some kind of environment here: NULL */ - save = get_current_ir_graph (); - pto_graph (graph, 0, NULL); - set_current_ir_graph (save); - - DBGPRINT (1, (stdout, "END PTO\n")); -} - -/* Dump all interesting stuff to a bunch of files */ -void pto_dump (void) -{ - pto_dump_names ("names.dot"); -} - -void pto_cleanup (void) -{ - /* todo: clean up our own mess */ - spaces -= 511; /* hope that all changes to spaces are - properly nested */ - memset (spaces, 0x00, 512); - free (spaces); - - /* Cleanup the name module */ - pto_name_cleanup (); - /* Cleanup the Init module */ - pto_init_cleanup (); - - /* clean up ecg infos */ - ecg_cleanup (); -} - - -/* - $Log$ - Revision 1.17 2005/01/10 17:26:34 liekweg - fixup printfs, don't put environments on the stack - - Revision 1.16 2004/12/22 14:43:14 beck - made allocations C-like - - Revision 1.15 2004/12/21 14:26:53 beck - removed C99 constructs - - Revision 1.14 2004/12/20 17:41:14 liekweg - __unused -> _unused - - Revision 1.13 2004/12/20 17:34:34 liekweg - fix recursion handling - - Revision 1.12 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.11 2004/11/30 15:49:27 liekweg - include 'dump' - - Revision 1.10 2004/11/30 14:46:41 liekweg - Correctly reset main graph; remove dbugging stuff - - Revision 1.9 2004/11/26 16:01:56 liekweg - debugging annotations - - Revision 1.8 2004/11/24 14:54:21 liekweg - Added pto.c as main entry point - - -*/ diff --git a/ir/ana2/pto.h b/ir/ana2/pto.h deleted file mode 100644 index 27d7bc8aa..000000000 --- a/ir/ana2/pto.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Import all includes needed for PTO/Entry to PTO - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_PTO_H -# define FIRM_ANA2_PTO_H - -# include "pto_comp.h" - -/* =================================================== - Global Defines: - =================================================== */ -# define N_INITIAL_OJBS 10 - -/* =================================================== - Global Data Types: - =================================================== */ - -/* =================================================== - Global Prototypes: - =================================================== */ -/* Perform PTO on all visible graphs. */ -void pto_init (int); -void pto_run (void); -/* Dump all interesting stuff to a bunch of files */ -void pto_dump (void); -/* Clean up our mess */ -void pto_cleanup (void); - -/* =================================================== - Global Variables: - =================================================== */ - - -# endif - - - -/* - $Log$ - Revision 1.7 2004/11/30 15:49:27 liekweg - include 'dump' - - Revision 1.6 2004/11/24 14:53:55 liekweg - Bugfixes - - Revision 1.5 2004/11/18 16:37:07 liekweg - rewrite - - -*/ diff --git a/ir/ana2/pto_comp.c b/ir/ana2/pto_comp.c deleted file mode 100644 index 108394cc0..000000000 --- a/ir/ana2/pto_comp.c +++ /dev/null @@ -1,837 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Main Implementation of PTO - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -/* - pto_comp: Main Implementation of PTO -*/ - -# include /* for memset */ - -# include "pto_comp.h" -# include "pto_util.h" -# include "pto_name.h" -# include "pto_ctx.h" -# include "pto_mod.h" - -# include "irnode_t.h" -# include "irprog_t.h" -# include "xmalloc.h" -# include "irmemwalk.h" - -# include "pto_debug.h" -# include "pto_init.h" - -# include "ecg.h" - -# include "gnu_ext.h" - -/* Local Defines: */ - -/* Local Data Types: */ -typedef struct pto_env_str { - struct pto_env_str *enc_env; - ir_graph *graph; - int ctx_idx; - int change; -} pto_env_t; - - -/* Local Variables: */ - -/* Debug only: */ -char *spaces = NULL; - -/* Local Prototypes: */ -static pto_t *get_pto (ir_node*, pto_env_t*); -static void pto_call (ir_graph*, ir_node*, pto_env_t*); -static void pto_raise (ir_node*, pto_env_t*); -static void pto_load (ir_node*, pto_env_t*); -static void pto_store (ir_node*, pto_env_t*); -static void pto_method (ir_node*, pto_env_t*); -static void pto_end_block (ir_node*, pto_env_t*); - -/* =================================================== - Local Implementation: - =================================================== */ -/* Add values of the actual arguments to the formal arguments */ -static int add_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) -{ - int change = FALSE; - ir_type *meth = get_entity_type (get_irg_entity (graph)); - ir_node **args = get_irg_proj_args (graph); - int i, n_args; - - assert(op_Call == get_irn_op(call)); - - n_args = get_Call_n_params (call); - - DBGPRINT (1, (stdout, "%s: args of %s[%li] -> 0x%08x\n", - __FUNCTION__, - OPNAME (call), OPNUM (call), (int) graph)); - - for (i = 0; i < n_args; i ++) { - if (NULL != args [i]) { - if (mode_P == get_type_mode (get_method_param_type (meth, i))) { - ir_node *call_arg = get_Call_param (call, i); - pto_t *arg_pto = get_pto (call_arg, env); - pto_t *frm_pto = get_node_pto (args [i]); - - assert (arg_pto); - assert (frm_pto); - - change |= qset_insert_all (frm_pto->values, arg_pto->values); - - DBGPRINT (2, (stdout, "%s: arg [%i]: -> %s[%li] (%i) -> %s[%li] (%i)\n", - __FUNCTION__, - i, - OPNAME (call_arg), OPNUM (call_arg), - arg_pto->values->id, - OPNAME (args [i]), OPNUM (args [i]), - frm_pto->values->id)); - } - } - } - - return (change); -} - -/* Transfer the actual arguments to the formal arguments */ -static void set_graph_args (ir_graph *graph, ir_node *call, pto_env_t *env) -{ - ir_type *meth = get_entity_type (get_irg_entity (graph)); - ir_node **args = get_irg_proj_args (graph); - int i, n_args; - - assert (op_Call == get_irn_op(call)); - - n_args = get_Call_n_params (call); - - for (i = 0; i < n_args; i ++) { - if (NULL != args [i]) { - if (mode_P == get_type_mode (get_method_param_type (meth, i))) { - ir_node *call_arg = get_Call_param (call, i); - pto_t *pto = get_pto (call_arg, env); - assert (pto); - set_node_pto (args [i], pto); - - DBGPRINT (1, (stdout, "%s: arg [%i]: %s[%li] -> %s[%li] (%i)\n", - __FUNCTION__, - i, - OPNAME (call_arg), OPNUM (call_arg), - OPNAME (args [i]), OPNUM (args [i]), - pto->values->id)); - } - } - } -} - -/* Transfer the graph's result to the call */ -static int set_graph_result (ir_graph *graph, ir_node *call) -{ - ir_type *tp = get_entity_type (get_irg_entity (graph)); - ir_node *end_block; - pto_t *ret_pto, *call_pto; - int change; - - if (0 == get_method_n_ress (tp)) { - return (FALSE); - } - - tp = get_method_res_type (tp, 0); - - if (mode_P != get_type_mode (tp)) { - set_node_pto (call, NULL); - - return (FALSE); - } - - end_block = get_irg_end_block (graph); - ret_pto = get_node_pto (end_block); - - call_pto = get_node_pto (call); - - assert (call_pto); - - DBGPRINT (1, (stdout, "%s: before change args\n", __FUNCTION__)); - DBGEXE (1, pto_print_pto (end_block)); - DBGEXE (1, pto_print_pto (call)); - - change = qset_insert_all (call_pto->values, ret_pto->values); - - if (change) { - DBGPRINT (1, (stdout, "%s: after change args\n", __FUNCTION__)); - DBGEXE (1, pto_print_pto (end_block)); - DBGEXE (1, pto_print_pto (call)); - /* assert (0); */ - } - - return (change); -} - -/* Propagation of PTO values */ -static pto_t *get_pto_proj (ir_node *proj, pto_env_t *env) -{ - ir_node *proj_in = get_Proj_pred (proj); - const ir_opcode in_op = get_irn_opcode (proj_in); - pto_t *in_pto = NULL; - pto_t *proj_pto = NULL; /* get_node_pto (proj); */ - - ir_node *proj_in_in = NULL; - - switch (in_op) { - case (iro_Start): /* ProjT (Start) */ - assert (0 && "pto from ProjT(Start) requested"); - - return (NULL); - case (iro_Proj): { /* ProjT (Start), ProjT (Call) */ - ir_opcode in_in_op; - long proj_in_proj; - - proj_in_in = get_Proj_pred (proj_in); - in_in_op = get_irn_opcode (proj_in_in); - proj_in_proj = get_Proj_proj (proj_in); - - assert ((pn_Start_T_args == proj_in_proj) || - (pn_Call_T_result == proj_in_proj)); - - switch (in_in_op) { - case (iro_Start): /* ProjArg (ProjT (Start)) */ - /* then the pto value must have been set to the node */ - proj_pto = get_node_pto (proj); - assert (proj_pto); - - return (proj_pto); - case (iro_Call): /* ProjV (ProjT (Call)) */ - if (NULL != proj_pto) { - return (proj_pto); - } else { - in_pto = get_pto (proj_in, env); - set_node_pto (proj, in_pto); - - assert (in_pto); - - return (in_pto); - } - default: assert (0 && "Proj(Proj(?))"); - } - /* done with case (in_op == iro_Proj) */ - } - - case (iro_Load): /* ProjV (Load) */ - assert (pn_Load_res == get_Proj_proj(proj)); - /* FALLTHROUGH */ - case (iro_Call): /* ProjT (Call) */ - /* FALLTHROUGH */ - case (iro_Alloc): /* ProjV (Alloc) */ - if (NULL != proj_pto) { - return (proj_pto); - } else { - in_pto = get_pto (proj_in, env); - assert (in_pto); - - set_node_pto (proj, in_pto); - return (in_pto); - } - default: - fprintf (stderr, "get_pto_proj(/*todo*/): not handled: proj (%s[%li])\n", - get_op_name (get_irn_op (proj_in)), - get_irn_node_nr (proj_in)); - assert (0 && "Proj(?)"); - return NULL; - } - -} - -static pto_t *get_pto_phi (ir_node *phi, pto_env_t *env) -{ - pto_t *pto; - int change = FALSE; - int i, n_ins; - - assert (mode_P == get_irn_mode (phi)); - - pto = get_node_pto (phi); - assert (pto); /* must be initialised */ - - n_ins = get_irn_arity (phi); - for (i = 0; i < n_ins; i ++) { - ir_node *in = get_irn_n (phi, i); - pto_t *in_pto = get_pto (in, env); - - assert (in_pto); - - change |= qset_insert_all (pto->values, in_pto->values); - } - - env->change |= change; - - return (pto); -} - -static pto_t *get_pto_sel (ir_node *sel, pto_env_t *env) -{ - pto_t *pto = NULL; /* get_node_pto (sel); */ - - if (NULL == pto) { - ir_node *in = get_Sel_ptr (sel); - - pto = get_pto (in, env); - set_node_pto (sel, pto); - } - - return (pto); -} - -static pto_t *get_pto_ret (ir_node *ret, pto_env_t *env) -{ - pto_t *pto = NULL; /* get_node_pto (ret); */ - - if (NULL == pto) { - ir_node *in = get_Return_res (ret, 0); - - pto = get_pto (in, env); - set_node_pto (ret, pto); - } - - assert (pto); - - DBGPRINT (9, (stdout, "%s: ", __FUNCTION__)); - DBGEXE (9, pto_print_pto (ret)); - - return (pto); -} - - -/* Dispatch to propagate PTO values */ -static pto_t *get_pto (ir_node *node, pto_env_t *env) -{ - const ir_opcode op = get_irn_opcode (node); - - DBGPRINT (2, (stdout, "%s (%s[%li])\n", - __FUNCTION__, - OPNAME (node), OPNUM (node))); - - switch (op) { - case (iro_Cast): return (get_pto (get_Cast_op (node), env)); - case (iro_Proj): return (get_pto_proj (node, env)); - case (iro_Phi): return (get_pto_phi (node, env)); - case (iro_Sel): return (get_pto_sel (node, env)); - case (iro_Alloc): return (get_alloc_pto (node)); - case (iro_Return): return (get_pto_ret (node, env)); - - case (iro_Call): /* FALLTHROUGH */ - case (iro_Load): /* FALLTHROUGH */ - case (iro_Const): /* FALLTHROUGH */ - case (iro_SymConst):{ - pto_t *pto = get_node_pto (node); - - assert (pto); - return (pto); - } - default: - /* stopgap measure */ - fprintf (stderr, "%s: not handled: node[%li].op = %s\n", - __FUNCTION__, - get_irn_node_nr (node), - get_op_name (get_irn_op (node))); - assert (0 && "something not handled"); - return NULL; - } -} - - -/* Actions for the nodes: */ -static void pto_load (ir_node *load, pto_env_t *pto_env) -{ - ir_node *ptr; - ir_entity *ent; - - /* perform load */ - DBGPRINT (2, (stdout, "%s (%s[%li]): pto = 0x%08x\n", - __FUNCTION__, - OPNAME (load), OPNUM (load), (int) get_node_pto (load))); - - ptr = get_Load_ptr (load); - - if (is_dummy_load_ptr (ptr)) { - return; - } - - ent = get_ptr_ent (ptr); - - if (mode_P == get_type_mode (get_entity_type (ent))) { - pto_t *ptr_pto = get_pto (ptr, pto_env); - - assert (ptr_pto); - - DBGPRINT (1, (stdout, "%s (%s[%li]): ptr = 0x%08x\n", - __FUNCTION__, - OPNAME (ptr), OPNUM (ptr), (int) ptr_pto)); - - pto_env->change |= mod_load (load, ent, ptr_pto); - } -} - -static void pto_store (ir_node *store, pto_env_t *pto_env) -{ - ir_node *ptr, *val; - ir_entity *ent; - pto_t *ptr_pto, *val_pto; - - /* perform store */ - DBGPRINT (2, (stdout, "%s (%s[%li]) (no pto)\n", - __FUNCTION__, - OPNAME (store), OPNUM (store))); - - ptr = get_Store_ptr (store); - val = get_Store_value (store); - - if (mode_P != get_irn_mode (val)) { - return; - } - - ent = get_ptr_ent (ptr); - - ptr_pto = get_pto (ptr, pto_env); - val_pto = get_pto (val, pto_env); - - assert (ptr_pto); - assert (val_pto); - - DBGPRINT (2, (stdout, "%s (%s[%li]): ptr_pto = 0x%08x\n", - __FUNCTION__, - OPNAME (ptr), OPNUM (ptr), (int) ptr_pto)); - DBGPRINT (2, (stdout, "%s (%s[%li]): val_pto = 0x%08x\n", - __FUNCTION__, - OPNAME (val), OPNUM (val), (int) val_pto)); - - pto_env->change |= mod_store (store, ent, ptr_pto, val_pto); -} - -static void pto_method (ir_node *call, pto_env_t *pto_env) -{ - int i; - callEd_info_t *callEd_info; - - DBGPRINT (2, (stdout, "%s:%i (%s[%li]): pto = 0x%08x\n", - __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call), - (int) get_node_pto (call))); - - callEd_info = ecg_get_callEd_info (call); - - if (NULL == callEd_info) { - DBGPRINT (2, (stdout, "%s:%i (%s[%li]), no graph\n", - __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call))); - } - - i = 0; - while (NULL != callEd_info) { - DBGPRINT (2, (stdout, "%s:%i (%s[%li]), graph %i\n", - __FUNCTION__, __LINE__, OPNAME (call), OPNUM (call), i ++)); - - pto_call (callEd_info->callEd, call, pto_env); - - callEd_info = callEd_info->prev; - } -} - -/* Perform the appropriate action on the given node */ -static void pto_node_node(ir_node *node, pto_env_t *pto_env) -{ - ir_opcode op = get_irn_opcode (node); - - DBGPRINT (1, (stdout, "%s (%s[%li])\n", - __FUNCTION__, OPNAME (node), OPNUM (node))); - - switch (op) { - case (iro_Start): /* nothing */ break; - case (iro_Load): - pto_load (node, pto_env); - break; - - case (iro_Store): - pto_store (node, pto_env); - break; - - case (iro_Call): - pto_method (node, pto_env); - break; - - case (iro_Raise): - pto_raise (node, pto_env); - break; - - case (iro_Return): - /* nothing to do */ - break; - - case (iro_Alloc): - /* nothing to do */ - break; - - case (iro_Block): - pto_end_block (node, pto_env); - break; - - case (iro_Phi): - /* must be a PhiM */ - assert (mode_M == get_irn_mode (node)); - /* nothing to do */ - break; - - /* uninteresting stuff: */ - case (iro_Div): - case (iro_Quot): - case (iro_Mod): - case (iro_DivMod): /* nothing to do */ break; - - default: - /* stopgap measure */ - fprintf (stderr, "%s: not handled: node[%li].op = %s\n", - __FUNCTION__, - get_irn_node_nr (node), - get_op_name (get_irn_op (node))); - assert (0 && "something not handled"); - } -} - - -/* Callback function to execute in pre-order */ -static void pto_node_pre (ir_node *node, void *env) -{ - /* nothing */ -} - -/* Callback function to execute in post-order */ -static void pto_node_post (ir_node *node, void *env) -{ - pto_env_t *pto_env = (pto_env_t*) env; - - DBGPRINT (999, (stdout, "%s (%s[%li])\n", - __FUNCTION__, - OPNAME (node), OPNUM (node))); - - pto_node_node (node, pto_env); -} - -/* Perform a single pass over the given graph */ -static void pto_graph_pass (ir_graph *graph, void *pto_env) -{ - irg_walk_mem (graph, pto_node_pre, pto_node_post, pto_env); -} - -/* Continue PTO for one of the graphs called at a Call */ -static void pto_call (ir_graph *graph, ir_node *call, pto_env_t *pto_env) -{ - int change = FALSE; - - /* only for debugging stuff: */ - ir_entity *ent = get_irg_entity (graph); - const char *ent_name = (char*) get_entity_name (ent); - const char *own_name = (char*) get_type_name (get_entity_owner (ent)); - - /* perform call */ - DBGPRINT (2, (stdout, "%s (%s[%li]) to \"%s.%s\"\n", - __FUNCTION__, - OPNAME (call), OPNUM (call), - own_name, ent_name)); - - if (! get_irg_is_mem_visited (graph)) { - /* handle direct call */ - graph_info_t *ginfo = ecg_get_info (graph); - - /* Save CTX */ - int ctx_idx = find_ctx_idx (call, ginfo, get_curr_ctx ()); - ctx_info_t *call_ctx = get_ctx (ginfo, ctx_idx); - ctx_info_t *old_ctx = set_curr_ctx (call_ctx); - - DBGPRINT (1, (stdout, "%s>CTX: ", -- spaces)); - DBGEXE (1, ecg_print_ctx (call_ctx, stdout)); - - /* Initialise Alloc Names and Node values */ - pto_reset_graph_pto (graph, ctx_idx); - - /* Compute Arguments */ - set_graph_args (graph, call, pto_env); - - /* Visit/Iterate Graph */ - pto_graph (graph, ctx_idx, pto_env); - - /* Restore CTX */ - set_curr_ctx (old_ctx); - - /* Get Return Value from Graph */ - change |= set_graph_result (graph, call); - - DBGPRINT (1, (stdout, "%sgraph) { - enc_env = enc_env->enc_env; /* talk about naming issues here */ - - /* since we're in a recursion loop, we *must* find an env for the callEd here: */ - assert (NULL != enc_env->enc_env); - } - - /* Re-Set arguments */ - rec_change = add_graph_args (graph, call, pto_env); - - DBGPRINT (1, (stdout, "%s: return in:", __FUNCTION__)); - DBGEXE (1, pto_print_pto (get_irg_end_block (graph))); - - if (rec_change) { - DBGPRINT (0, (stdout, "%s: change args\n", __FUNCTION__)); - } - - rec_change |= set_graph_result (graph, call); - - if (rec_change) { - DBGPRINT (1, (stdout, "%s: return out:", __FUNCTION__)); - DBGEXE (1, pto_print_pto (get_irg_end_block (graph))); - } - -# if 0 - /* appears that we don't need this: */ - enc_env->change |= rec_change; -# endif /* 0 */ - } - - /* Todo: Set 'Unknown' Value as Return Value when the graph is not - known */ - - pto_env->change |= change; -} - -static void pto_raise (ir_node *raise, pto_env_t *pto_env) -{ - /* perform raise */ - DBGPRINT (2, (stdout, "%s (%s[%li]): pto = 0x%08x\n", - __FUNCTION__, - OPNAME (raise), OPNUM (raise), (int) get_node_pto (raise))); -} - -static void pto_end_block (ir_node *end_block, pto_env_t *pto_env) -{ - /* perform end block */ - ir_type *tp = get_entity_type (get_irg_entity (get_irn_irg (end_block))); - pto_t *end_pto; - int i, n_ins; - - if (0 == get_method_n_ress (tp)) { - return; - } - - tp = get_method_res_type (tp, 0); - - if (! mode_is_reference(get_type_mode (tp))) { - return; - } - - DBGPRINT (2, (stdout, "%s (%s[%li]): pto = 0x%08x\n", - __FUNCTION__, - OPNAME (end_block), OPNUM (end_block), - (int) get_node_pto (end_block))); - - end_pto = get_node_pto (end_block); - - assert (end_pto); - - n_ins = get_irn_arity (end_block); - for (i = 0; i < n_ins; i ++) { - ir_node *in = get_irn_n (end_block, i); - - if (iro_Return == get_irn_opcode (in)) { - pto_t *in_pto = get_pto (in, pto_env); - - pto_env->change |= qset_insert_all (end_pto->values, in_pto->values); - } - } -} - -/* =================================================== - Exported Implementation: - =================================================== */ -/* Main loop: Initialise and iterate over the given graph */ -void pto_graph (ir_graph *graph, int ctx_idx, pto_env_t *enc_env) -{ - int run; - pto_env_t *pto_env; - - /* Also exported, since we need it in 'pto.c' */ - pto_env = xmalloc (sizeof (pto_env_t)); - pto_env->enc_env = enc_env; - pto_env->graph = graph; - pto_env->ctx_idx = ctx_idx; - pto_env->change = TRUE; - - /* HERE ("start"); */ - - DBGPRINT (2, (stdout, "%s: start for ctx %i\n", - __FUNCTION__, - ctx_idx)); - - /* todo (here): iterate, obey 'changed' attribute */ - run = 0; - while (0 != pto_env->change) { - run ++; - pto_env->change = FALSE; - pto_graph_pass (graph, pto_env); - } - - DBGPRINT (1, (stdout, "%s: %i runs on \"%s.%s\"\n", - __FUNCTION__, - run, - get_type_name (get_entity_owner (get_irg_entity (graph))), - get_entity_name (get_irg_entity (graph)))); - memset (pto_env, 0, sizeof (pto_env_t)); - free (pto_env); - /* HERE ("end"); */ -} - -/* Set the PTO value for the given non-alloc node */ -void set_node_pto (ir_node *node, pto_t *pto) -{ - assert (op_Alloc != get_irn_op(node)); - - set_irn_link (node, (void*) pto); -} - -/*Get the PTO value for the given non-alloc node */ -pto_t *get_node_pto (ir_node *node) -{ - assert (op_Alloc != get_irn_op(node)); - - return ((pto_t*) get_irn_link (node)); -} - -/* Set the PTO value for the given alloc node */ -void set_alloc_pto (ir_node *alloc, alloc_pto_t *alloc_pto) -{ - assert (op_Alloc == get_irn_op(alloc)); - - assert (alloc_pto); - - set_irn_link (alloc, (void*) alloc_pto); -} - -/*Get the current PTO value for the given alloc node */ -pto_t *get_alloc_pto (ir_node *alloc) -{ - alloc_pto_t *alloc_pto = get_irn_link (alloc); - - assert (op_Alloc == get_irn_op(alloc)); - - assert (alloc_pto -> curr_pto); - - return (alloc_pto -> curr_pto); -} - - -/* - $Log$ - Revision 1.21 2007/03/22 10:39:33 matze - a bunch of fixes to make firm work with NDEBUG and without DEBUG_libfirm - - Revision 1.20 2007/01/16 15:45:42 beck - renamed type opcode to ir_opcode - - Revision 1.19 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.18 2006/01/13 22:57:41 beck - renamed all types 'type' to 'ir_type' - used mode_is_reference instead of != mode_P test - - Revision 1.17 2005/02/25 16:48:21 liekweg - fix typo - - Revision 1.16 2005/01/27 15:51:19 liekweg - whitespace change - - Revision 1.15 2005/01/14 14:14:26 liekweg - fix gnu extension, fix fprintf's - - Revision 1.14 2005/01/14 13:37:26 liekweg - fix allocation (size); don't cast malloc - - Revision 1.13 2005/01/10 17:26:34 liekweg - fixup printfs, don't put environments on the stack - - Revision 1.12 2004/12/23 15:46:19 beck - removed unneeded allocations - - Revision 1.11 2004/12/21 14:50:59 beck - removed C)) and GNUC constructs, add default returns - - Revision 1.10 2004/12/20 17:34:35 liekweg - fix recursion handling - - Revision 1.9 2004/12/15 13:31:18 liekweg - remove debugging stuff - - Revision 1.8 2004/12/15 09:18:18 liekweg - pto_name.c - - Revision 1.7 2004/12/06 12:55:06 liekweg - actually iterate - - Revision 1.6 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.5 2004/11/30 14:47:54 liekweg - fix initialisation; do correct iteration - - Revision 1.4 2004/11/26 15:59:40 liekweg - verify pto_{load,store} - - Revision 1.3 2004/11/24 14:53:55 liekweg - Bugfixes - - Revision 1.2 2004/11/20 21:21:56 liekweg - Finalise initialisation - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_comp.h b/ir/ana2/pto_comp.h deleted file mode 100644 index e955d066e..000000000 --- a/ir/ana2/pto_comp.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Main Implementation of PTO - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_PTO_COMP_H -# define FIRM_ANA2_PTO_COMP_H - -# include "pto.h" -# include "irnode.h" -# include "qset.h" - -/* =================================================== - Global Defines: - =================================================== */ - -/* =================================================== - Global Data Types: - =================================================== */ -typedef struct pto_str { - qset_t *values; -} pto_t; - -typedef struct alloc_pto_str { - int dummy; - pto_t **ptos; /* all names */ - pto_t *curr_pto; /* name for current ctx */ -} alloc_pto_t; - -struct pto_env_str; /* forward decl only */ - -/* =================================================== - Global Prototypes: - =================================================== */ -/* Main loop: Initialise the graph for the given ctx_idx and iterate over it */ -void pto_graph (ir_graph*, int, struct pto_env_str*); - -/* Set the PTO value for the given node */ -void set_node_pto (ir_node*, pto_t*); -/*Get the PTO value for the given non-alloc node */ -pto_t *get_node_pto (ir_node*); - -/* Set the PTO value for the given alloc node */ -void set_alloc_pto (ir_node*, alloc_pto_t*); - -/*Get the current PTO value for the given alloc node */ -pto_t *get_alloc_pto (ir_node*); - - -/* =================================================== - Global Variables: - =================================================== */ - - -# endif - - - -/* - $Log$ - Revision 1.3 2004/12/20 17:34:35 liekweg - fix recursion handling - - Revision 1.2 2004/11/24 14:53:55 liekweg - Bugfixes - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_ctx.c b/ir/ana2/pto_ctx.c deleted file mode 100644 index a1c680c3a..000000000 --- a/ir/ana2/pto_ctx.c +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Manage context-sensitivity markers - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -#include - -/* - pto_ctx: Manage context-sensitivity markers -*/ - -# include "pto_ctx.h" -# include "pto_debug.h" -# include "pto_comp.h" -# include "ecg.h" - -# include "irnode.h" -/* # include "xmalloc.h" */ - -/* Local Defines: */ - -/* Local Data Types: */ - -/* Local Variables: */ -static ctx_info_t *curr_ctx = NULL; - -/* Local Prototypes: */ - -/* =================================================== - Local Implementation: - =================================================== */ - - -/* =================================================== - Exported Implementation: - =================================================== */ -/* Find the appropriate ctx for the given call and the given graph */ -/* ctx_info_t *find_ctx (ir_node *call, graph_info_t *ginfo, ctx_info_t *curr_ctx) */ -int find_ctx_idx (ir_node *call, graph_info_t *ginfo, ctx_info_t *curr_ctx) -{ - int i; - const int n_ctxs = ginfo->n_ctxs; - - for (i = 0; i < n_ctxs; i ++) { - ctx_info_t *ctx = ginfo->ctxs [i]; - - if ((ctx->enc == curr_ctx) && (ctx->call == call)) { - return (i); - } - } - - fflush (stdout); - assert (0 && "CTX not found"); - - return (-1); -} - -/* Get the current ctx */ -ctx_info_t *get_curr_ctx (void) -{ - return (curr_ctx); -} - -/* Set the current ctx to the given ctx. Return the old value */ -ctx_info_t *set_curr_ctx (ctx_info_t *ctx) -{ - ctx_info_t *old_ctx = curr_ctx; - - curr_ctx = ctx; - - return (old_ctx); -} - - -/* - $Log$ - Revision 1.6 2005/12/05 12:19:54 beck - added missing include (not anymore included in libFirm) - - Revision 1.5 2005/01/14 13:37:55 liekweg - Insert purpose descr - - Revision 1.4 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.3 2004/11/24 14:53:55 liekweg - Bugfixes - - Revision 1.2 2004/11/20 21:21:35 liekweg - Add pto_ctx_allocs - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_ctx.h b/ir/ana2/pto_ctx.h deleted file mode 100644 index f3a52c2fc..000000000 --- a/ir/ana2/pto_ctx.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Manage context-sensitivity markers - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_PTO_CTX_H -# define FIRM_ANA2_PTO_CTX_H - -# include "ecg.h" - -/* =================================================== - Global Defines: - =================================================== */ - -/* =================================================== - Global Data Types: - =================================================== */ - -/* =================================================== - Global Prototypes: - =================================================== */ -/* Find the appropriate ctx for the given call and the given graph */ -/* ctx_info_t *find_ctx (ir_node*, graph_info_t*, ctx_info_t*); */ -int find_ctx_idx (ir_node*, graph_info_t*, ctx_info_t*); - -/* Get the current ctx */ -ctx_info_t *get_curr_ctx (void); - -/* Set the current ctx to the given ctx. Return the old value */ -ctx_info_t *set_curr_ctx (ctx_info_t*); - -/* Set all alloc names to the right ptos */ -void pto_ctx_allocs (graph_info_t*, int); - -/* =================================================== - Global Variables: - =================================================== */ - - -# endif - - - -/* - $Log$ - Revision 1.3 2005/01/14 13:37:55 liekweg - Insert purpose descr - - Revision 1.2 2004/11/20 21:21:35 liekweg - Add pto_ctx_allocs - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_debug.c b/ir/ana2/pto_debug.c deleted file mode 100644 index c746bc2c1..000000000 --- a/ir/ana2/pto_debug.c +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Useful Macros for Debugging - * @author Florian - * @date Sat Nov 13 19:30:21 CET 2004 - * @version $Id$ - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -/* - pto_debug: Useful Macros for Debugging -*/ - -# include "pto_debug.h" -# include "pto_comp.h" -# include "gnu_ext.h" -# include "qset.h" - -/* # include "xmalloc.h" */ - -/* Local Defines: */ - -/* Local Data Types: */ - -/* Local Variables: */ -static int dbg_lvl = 0; - -/* Local Prototypes: */ - -/* =================================================== - Local Implementation: - =================================================== */ - - -/* =================================================== - Exported Implementation: - =================================================== */ -int get_dbg_lvl () -{ - return (dbg_lvl); -} - -void set_dbg_lvl (int lvl) -{ - /* fprintf (stdout, "%s:%s (): dbg_lvl: %i -> %i\n", */ -/* __FILE__, __FUNCTION__, dbg_lvl, lvl); */ - dbg_lvl = lvl; -} - -void pto_print_pto (ir_node *node) -{ - pto_t *pto = get_node_pto (node); - - fprintf (stdout, "pto (%s[%li]) = ", OPNAME (node), OPNUM (node)); - if (NULL != pto) { - qset_print (pto->values, stdout); - } else { - fprintf (stdout, "NULL"); - } -} - - - -/* - $Log$ - Revision 1.5 2005/02/25 16:47:51 liekweg - fix GNU stuff - - Revision 1.4 2004/12/20 17:34:35 liekweg - fix recursion handling - - Revision 1.3 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.2 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_debug.h b/ir/ana2/pto_debug.h deleted file mode 100644 index 8f5bc15bb..000000000 --- a/ir/ana2/pto_debug.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Useful Macros for Debugging - * @author Florian - * @date Sat Nov 13 19:30:21 CET 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_PTO_DEBUG_H -# define FIRM_ANA2_PTO_DEBUG_H - -# include "irnode.h" - -/* =================================================== - Global Defines: - =================================================== */ -# define DBGPRINT(lvl, args) if (get_dbg_lvl () > lvl) { fprintf args; } -# define DBGEXE(lvl, cmd) if (get_dbg_lvl () > lvl) {cmd;} -# define OPNAME(node) get_irn_opname(node) -# define OPNUM(node) get_irn_node_nr(node) -# define HERE(msg) fprintf (stdout, "%s:%i %s\n", __FUNCTION__, __LINE__, msg) -# define HERE2(msg1, msg2) fprintf (stdout, "%s:%i: %s %s\n", __FUNCTION__, __LINE__, msg1, msg2) -# define HERE3(msg1, msg2, msg3) fprintf (stdout, "%s:%i: %s %s %s\n", __FUNCTION__, __LINE__, msg1, msg2, msg3) - -/* =================================================== - Global Data Types: - =================================================== */ - -/* =================================================== - Global Prototypes: - =================================================== */ -int get_dbg_lvl (void); -void set_dbg_lvl (int); - -void pto_print_pto (ir_node*); - -/* =================================================== - Global Variables: - =================================================== */ - -# endif - - - -/* - $Log$ - Revision 1.5 2005/01/14 13:33:10 liekweg - Use only public irnode interface - - Revision 1.4 2004/12/21 15:51:07 beck - simplifyed - - Revision 1.3 2004/12/20 17:34:35 liekweg - fix recursion handling - - Revision 1.2 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_init.c b/ir/ana2/pto_init.c deleted file mode 100644 index 221b325e9..000000000 --- a/ir/ana2/pto_init.c +++ /dev/null @@ -1,521 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Initialisation Functions - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* - pto_init: Initialisation Functions -*/ - -# include -#ifdef HAVE_STRING_H -# include -#endif -#ifdef HAVE_STRINGS_H -# include -#endif - -# include "obst.h" -# include "pto.h" -# include "pto_init.h" -# include "pto_debug.h" -# include "pto_comp.h" -# include "pto_name.h" -# include "pto_util.h" - -# include "typewalk.h" -# include "irgwalk.h" -# include "tv.h" -# include "xmalloc.h" - -# include "gnu_ext.h" - -/* Local Defines: */ -# define obstack_chunk_alloc xmalloc -# define obstack_chunk_free free - -/* Local Data Types: */ -typedef struct init_env_str -{ - int n_ctxs; -} init_env_t; - -typedef struct reset_env_str -{ - int ctx_idx; -} reset_env_t; - -/* Local Variables: */ -extern struct obstack *qset_obst; /* from pto_name */ - -static struct obstack *pto_obst = NULL; /* all pto_t's go onto this one */ - -/* Local Prototypes: */ - -/* =================================================== - Local Implementation: - =================================================== */ -/** Allocate a new pto */ -static pto_t *new_pto (ir_node *node) -{ - pto_t *pto = obstack_alloc (pto_obst, sizeof (pto_t)); - pto->values = qset_new (N_INITIAL_OJBS, qset_obst); - - return (pto); -} - -/** Allocate a new alloc_pto */ -static alloc_pto_t *new_alloc_pto (ir_node *alloc, int n_ctxs) -{ - int i; - alloc_pto_t *alloc_pto = obstack_alloc (pto_obst, sizeof (alloc_pto_t)); - ir_type *tp; - - assert (op_Alloc == get_irn_op(alloc)); - - tp = get_Alloc_type (alloc); - - alloc_pto->ptos = (pto_t**) obstack_alloc (pto_obst, n_ctxs * sizeof (pto_t*)); - - for (i = 0; i < n_ctxs; i ++) { - desc_t *desc = new_name (tp, alloc, i); - alloc_pto->ptos [i] = new_pto (alloc); - qset_insert (alloc_pto->ptos [i]->values, desc); - } - - return (alloc_pto); -} - -/** Allocate a new pto for a symconst */ -static pto_t* new_symconst_pto (ir_node *symconst) -{ - pto_t *pto; - ir_entity *ent; - desc_t *desc = NULL; - - assert (op_SymConst == get_irn_op(symconst)); - - pto = new_pto (symconst); - ent = get_SymConst_entity (symconst); - - /* - const char *ent_name = (char*) get_entity_name (ent); - const char *own_name = (char*) get_type_name (get_entity_owner (ent)); - HERE3 ("start", own_name, ent_name); - */ - /* Ok, so if the symconst has a pointer-to-mumble, it's some address - calculation, but if it's the mumble itself, it's just the same, - except it's presumably a constant of mumble. In any case, we need to - branch on this. "How's that for object fucking oriented? --jwz" */ - if (is_Pointer_type (get_entity_type (ent))) { - desc = new_ent_name (ent); - } else if (is_Class_type (get_entity_type (ent))) { - desc = new_name (get_entity_type (ent), symconst, -1); - } else { - fprintf (stderr, "%s: not handled: %s[%li] (\"%s\")\n", - __FUNCTION__, - get_op_name (get_irn_op (symconst)), - get_irn_node_nr (symconst), - get_entity_name (ent)); - assert (0 && "something not handled"); - } - - qset_insert (pto->values, desc); - - /* HERE3 ("end", own_name, ent_name); */ - - return (pto); -} - -/* Helper to pto_init --- clear the link fields of class types */ -static void clear_type_link (type_or_ent *thing, void *_unused) -{ - if (is_type (thing)) { - ir_type *tp = (ir_type*) thing; - - if (is_Class_type (tp)) { - DBGPRINT (1, (stdout, "%s (\"%s\")\n", - __FUNCTION__, - get_type_name (tp))); - - set_type_link (tp, NULL); - } - } else if (is_entity (thing)) { - ir_entity *ent = (ir_entity*) thing; - - DBGPRINT (1, (stdout, "%s (\"%s\")\n", - __FUNCTION__, - get_entity_name (ent))); - - set_entity_link (ent, NULL); - } -} - -/** Helper to pto_init_graph --- clear the links of the given node */ -static void clear_node_link (ir_node *node, void *_unused) -{ - set_irn_link (node, NULL); -} - -/** Helper to pto_init_graph --- clear the links of all nodes */ -static void clear_graph_links (ir_graph *graph) -{ - irg_walk_graph (graph, clear_node_link, NULL, NULL); -} - -/** Reset ALL the pto values for a new pass */ -static void reset_node_pto (ir_node *node, void *env) -{ - reset_env_t *reset_env = (reset_env_t*) env; - int ctx_idx = reset_env->ctx_idx; - ir_opcode op = get_irn_opcode (node); - - /* HERE ("start"); */ - - switch (op) { - case (iro_Load): - case (iro_Call): - case (iro_Block): /* END BLOCK only */ - case (iro_Phi): { - /* allocate 'empty' pto values */ - pto_t *pto = new_pto (node); - set_node_pto (node, pto); - } break; - - case (iro_Alloc): { - /* set alloc to 'right' current pto */ - alloc_pto_t *alloc_pto = (alloc_pto_t*) get_irn_link (node); - alloc_pto->curr_pto = alloc_pto->ptos [ctx_idx]; - - DBGPRINT (1, (stdout, "%s: setting pto of \"%s[%li]\" for ctx %i\n", - __FUNCTION__, - OPNAME (node), - OPNUM (node), - ctx_idx)); - - assert (alloc_pto->curr_pto); - } break; - case (iro_Const): - case (iro_SymConst): { - /* nothing, leave as-is */ - } break; - - default: { - /* basically, nothing */ - DBGPRINT (2, (stdout, "%s: resetting pto of \"%s[%li]\"\n", - __FUNCTION__, - OPNAME (node), - OPNUM (node))); - set_node_pto (node, NULL); - } break; - } - - /* HERE ("end"); */ -} - -/** Initialise primary name sources */ -static void init_pto (ir_node *node, void *env) -{ - init_env_t *init_env = (init_env_t*) env; - int n_ctxs = init_env->n_ctxs; - - ir_opcode op = get_irn_opcode (node); - - switch (op) { - case (iro_SymConst): { - if (mode_is_reference (get_irn_mode (node))) { - ir_entity *ent = get_SymConst_entity (node); - ir_type *tp = get_entity_type (ent); - if (is_Class_type (tp) || is_Pointer_type (tp)) { - pto_t *symconst_pto = new_symconst_pto (node); - set_node_pto (node, symconst_pto); - - /* debugging only */ - DBGPRINT (1, (stdout, "%s: new name \"%s\" for \"%s[%li]\"\n", - __FUNCTION__, - get_entity_name (ent), - OPNAME (node), - OPNUM (node))); - } - } - } break; - - case (iro_Alloc): { - alloc_pto_t *alloc_pto = new_alloc_pto (node, n_ctxs); - ir_type *tp; - - set_alloc_pto (node, alloc_pto); - - tp = get_Alloc_type (node); /* debugging only */ - DBGPRINT (1, (stdout, "%s: %i names \"%s\" for \"%s[%li]\"\n", - __FUNCTION__, - n_ctxs, - get_type_name (tp), - OPNAME (node), - OPNUM (node))); - } break; - - case (iro_Const): { - tarval *tv = get_Const_tarval (node); - - /* only need 'NULL' pointer constants */ - if (mode_P == get_tarval_mode (tv)) { - if (get_tarval_null (mode_P) == tv) { - pto_t *pto = new_pto (node); - set_node_pto (node, pto); - } - } - } break; - case (iro_Load): - case (iro_Call): - case (iro_Phi): - /* nothing --- handled by reset_node_pto on each pass */ - break; - default: { - /* nothing */ - } break; - } -} - - -/** Initialise the given graph for a new pass run */ -static void pto_init_graph_allocs (ir_graph *graph) -{ - graph_info_t *ginfo = ecg_get_info (graph); - init_env_t *init_env; - - init_env = xmalloc (sizeof (init_env_t)); - init_env->n_ctxs = ginfo->n_ctxs; - - /* HERE ("start"); */ - - irg_walk_graph (graph, init_pto, NULL, init_env); - - /* HERE ("end"); */ - memset (init_env, 0x00, sizeof (init_env_t)); - free (init_env); -} - -/* =================================================== - Exported Implementation: - =================================================== */ -/* "Fake" the arguments to the main method */ -void fake_main_args (ir_graph *graph) -{ - /* HERE ("start"); */ - - ir_entity *ent = get_irg_entity (graph); - ir_type *mtp = get_entity_type (ent); - ir_node **args = find_irg_args (graph); - ir_type *ctp = get_method_param_type (mtp, 1); /* ctp == char[]*[]* */ - desc_t *arg_desc; - pto_t *arg_pto; - - /* 'main' has signature 'void(int, char[]*[]*)' */ - assert (NULL == args [2]); - - assert (is_Pointer_type (ctp)); - - ctp = get_pointer_points_to_type (ctp); /* ctp == char[]*[] */ - - assert (is_Array_type (ctp)); - - arg_desc = new_name (ctp, args [1], -1); - arg_pto = new_pto (args [1]); - /* todo: simulate 'store' to arg1[] ?!? */ - qset_insert (arg_pto->values, arg_desc); - - set_node_pto (args [1], arg_pto); - - DBGPRINT (1, (stdout, "%s:%i (%s[%li])\n", - __FUNCTION__, __LINE__, - OPNAME (args [1]), OPNUM (args [1]))); - -# ifdef TEST_MAIN_TYPE - ctp = get_array_element_type (ctp); /* ctp == char[]* */ - - assert (is_Pointer_type (ctp)); - - ctp = get_pointer_points_to_type (ctp); /* ctp == char[] */ - - assert (is_Array_type (ctp)); - - ctp = get_array_element_type (ctp); /* ctp == char */ - - assert (is_primitive_type (ctp)); -# endif /* defined TEST_MAIN_TYPE */ - - /* HERE ("end"); */ -} - -/* Initialise the Init module */ -void pto_init_init (void) -{ - pto_obst = (struct obstack*) xmalloc (sizeof (struct obstack)); - - obstack_init (pto_obst); -} - -/* Cleanup the Init module */ -void pto_init_cleanup (void) -{ - obstack_free (pto_obst, NULL); - memset (pto_obst, 0x00, sizeof (struct obstack)); - free (pto_obst); - pto_obst = NULL; -} - - -/* Initialise the Names of the Types/Entities */ -void pto_init_type_names (void) -{ - /* HERE ("start"); */ - type_walk (clear_type_link, NULL, NULL); - /* HERE ("end"); */ -} - -/* Initialise the given graph for a new pass run */ -void pto_init_graph (ir_graph *graph) -{ - ir_node **proj_args; - graph_info_t *ginfo = ecg_get_info (graph); - const int n_ctxs = ginfo->n_ctxs; - - /* only for debugging stuff: */ - ir_entity *ent = get_irg_entity (graph); - const char *ent_name = (char*) get_entity_name (ent); - const char *own_name = (char*) get_type_name (get_entity_owner (ent)); - - DBGPRINT (2, (stdout, "%s: init \"%s.%s\" for %i ctxs\n", - __FUNCTION__, - own_name, ent_name, n_ctxs)); - - /* HERE ("start"); */ - - clear_graph_links (graph); - pto_init_graph_allocs (graph); - - /* HERE ("end"); */ - - assert (NULL == get_irg_proj_args (graph)); - proj_args = find_irg_args (graph); - set_irg_proj_args (graph, proj_args); - assert (proj_args == get_irg_proj_args (graph)); -} - -/* Reset the given graph for a new pass run */ -void pto_reset_graph_pto (ir_graph *graph, int ctx_idx) -{ - reset_env_t *reset_env; - - reset_env = (reset_env_t*) xmalloc (sizeof (reset_env_t)); - reset_env->ctx_idx = ctx_idx; - - /* HERE ("start"); */ - - irg_walk_graph (graph, reset_node_pto, NULL, reset_env); - - /* HERE ("end"); */ - memset (reset_env, 0x00, sizeof (reset_env_t)); - free (reset_env); -} - - -/* - $Log$ - Revision 1.23 2007/01/16 15:45:42 beck - renamed type opcode to ir_opcode - - Revision 1.22 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.21 2006/06/08 10:49:07 beck - renamed type to ir_type - - Revision 1.20 2005/12/05 12:19:54 beck - added missing include (not anymore included in libFirm) - - Revision 1.19 2005/06/17 17:42:32 beck - added doxygen docu - fixed (void) function headers - - Revision 1.18 2005/02/16 13:27:52 beck - added needed tv.h include - - Revision 1.17 2005/01/14 14:12:51 liekweg - prepare gnu extension fix - - Revision 1.16 2005/01/14 13:36:50 liekweg - don't put environments on the stack; handle consts - - Revision 1.15 2005/01/10 17:26:34 liekweg - fixup printfs, don't put environments on the stack - - Revision 1.14 2005/01/05 14:25:54 beck - renames all is_x*_type() functions to is_X*_type() to prevent name clash with EDG fronten - - Revision 1.13 2004/12/21 15:07:55 beck - removed C99 contructs - removed unnecessary allocation - removed use of mode_P, use mode_is_reference() instead - removed handling of Const with pointer tarvals, these constructs are removed - - Revision 1.12 2004/12/20 17:41:14 liekweg - __unused -> _unused - - Revision 1.11 2004/12/20 17:34:35 liekweg - fix recursion handling - - Revision 1.10 2004/12/15 13:31:00 liekweg - store ctx idx in names - - Revision 1.9 2004/12/15 09:18:18 liekweg - pto_name.c - - Revision 1.8 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.7 2004/11/30 14:47:54 liekweg - fix initialisation; do correct iteration - - Revision 1.6 2004/11/26 16:00:41 liekweg - recognize class consts vs. ptr-to-class consts - - Revision 1.5 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.4 2004/11/20 21:21:56 liekweg - Finalise initialisation - - Revision 1.3 2004/11/18 16:37:07 liekweg - rewrite - - -*/ diff --git a/ir/ana2/pto_init.h b/ir/ana2/pto_init.h deleted file mode 100644 index 668023630..000000000 --- a/ir/ana2/pto_init.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief ... - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_PTO_INIT_H -# define FIRM_ANA2_PTO_INIT_H - -# include "irgraph.h" -# include "ecg.h" - -/* =================================================== - Global Defines: - =================================================== */ - -/* =================================================== - Global Data Types: - =================================================== */ - -/* =================================================== - Global Prototypes: - =================================================== */ -/* "Fake" the arguments to the main method */ -void fake_main_args (ir_graph*); - -/* Initialise the Init module */ -void pto_init_init (void); - -/* Cleanup the Init module */ -void pto_init_cleanup (void); - -/* Initialise the Names of the Types/Entities */ -void pto_init_type_names (void); - -/* Initialise the given graph */ -void pto_init_graph (ir_graph*); - -/* Reset the given graph for a new pass run */ -void pto_reset_graph_pto (ir_graph*, int); - -/* =================================================== - Global Variables: - =================================================== */ - - -# endif - - - -/* - $Log$ - Revision 1.4 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.3 2004/11/20 21:21:56 liekweg - Finalise initialisation - - Revision 1.2 2004/11/18 16:37:07 liekweg - rewrite - - -*/ diff --git a/ir/ana2/pto_mod.c b/ir/ana2/pto_mod.c deleted file mode 100644 index 77d915d0c..000000000 --- a/ir/ana2/pto_mod.c +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Load/Store Transfer Functions - * @author Florian - * @date Fri Nov 26 17:29:49 CET 2004 - * @version $Id$ - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* - pto_mod: Load/Store Transfer Functions -*/ - -# include "pto_mod.h" - -# include "xmalloc.h" - -# include "pto_debug.h" -# include "pto_name.h" - -/* Local Defines: */ - -/* Local Data Types: */ - -/* Local Variables: */ - -/* Local Prototypes: */ - -/* =================================================== - Local Implementation: - =================================================== */ - - -/* =================================================== - Exported Implementation: - =================================================== */ -/* Perform the given store; return nonzero iff any involved values change */ -int mod_store (ir_node *store, ir_entity *ent, - pto_t *ptr_pto, pto_t *val_pto) -{ - int change = 0; - - /* foreach descr in ptr_pto, add val_pto->values to descr.ent */ - - qset_t *ptos = ptr_pto->values; - - desc_t *desc = (desc_t*) qset_start (ptos); - - while (NULL != desc) { - qset_t *entry = get_entry (desc, ent); - - change |= qset_insert_all (entry, val_pto->values); - - desc = (desc_t*) qset_next (ptos); - } - - return (change); -} - -/* Perform the given load; return nonzero iff any involved values change */ -int mod_load (ir_node *load, ir_entity *ent, - pto_t *ptr_pto) -{ - int change = 0; - pto_t *res = get_node_pto (load); - /* todo: for each descr in ptr_pto, add descr.ent to res */ - - qset_t *ptos = ptr_pto->values; - desc_t *desc = (desc_t*) qset_start (ptos); - - while (NULL != desc) { - qset_t *entry = get_entry (desc, ent); - - change |= qset_insert_all (res->values, entry); - - desc = (desc_t*) qset_next (ptos); - } - - return (change); -} - - - -/* - $Log$ - Revision 1.3 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.2 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.1 2004/11/30 14:47:54 liekweg - fix initialisation; do correct iteration - - -*/ diff --git a/ir/ana2/pto_mod.h b/ir/ana2/pto_mod.h deleted file mode 100644 index 542d4d845..000000000 --- a/ir/ana2/pto_mod.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Load/Store Transfer Functions - * @author Florian - * @date Fri Nov 26 17:29:49 CET 2004 - * @version $Id$ - */ -#ifndef FIRM_ANA2_PTO_MOD_H -#define FIRM_ANA2_PTO_MOD_H - -#include "irnode.h" -#include "entity.h" -#include "pto_comp.h" - -/* =================================================== - Global Defines: - =================================================== */ - -/* =================================================== - Global Data Types: - =================================================== */ - -/* =================================================== - Global Prototypes: - =================================================== */ -/* Perform the given store; return nonzero iff any involved values change */ -int mod_store (ir_node*, ir_entity*, pto_t*, pto_t*); - -/* Perform the given load; return nonzero iff any involved values change */ -int mod_load (ir_node*, ir_entity*, pto_t*); - -/* =================================================== - Global Variables: - =================================================== */ - - -#endif /* not defined _PTO_MOD_ */ - - - -/* - $Log$ - Revision 1.2 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.1 2004/11/30 14:47:54 liekweg - fix initialisation; do correct iteration - - -*/ diff --git a/ir/ana2/pto_name.c b/ir/ana2/pto_name.c deleted file mode 100644 index 3186ef5f5..000000000 --- a/ir/ana2/pto_name.c +++ /dev/null @@ -1,732 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Names for abstract objects - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -/* - pto_name: Names for abstract objects -*/ - -# include "pto.h" -# include "pto_name.h" -# include "pto_util.h" - -#include - -#ifdef HAVE_STRING_H -# include /* for memcpy */ -#endif -# include - -# include "obst.h" -# include "irnode.h" -# include "irprog.h" -# include "xmalloc.h" - -# include "pto_debug.h" -# include "gnu_ext.h" - -/* Local Defines: */ -# define obstack_chunk_alloc xmalloc -# define obstack_chunk_free free - -# define NALLOC(size) obstack_alloc (name_obst, size) - -/* Local Data Types: */ - -/* Local Variables: */ -struct obstack *qset_obst = NULL; -struct obstack *name_obst = NULL; - -static desc_t *all_descs = NULL; - -static int name_id = 0; - -# define PTO_COLOR - -# ifdef PTO_COLOR -static int last_col_idx = 0; - -/* Local Prototypes: */ -static int pto_name_alloc_color (desc_t*); -static void pto_name_set_color (desc_t*, int); -# endif /* defined PTO_COLOR */ - -/* =================================================== - Local Implementation: - =================================================== */ -# ifdef PTO_COLOR -/* set a nice color to an object descriptor */ -static void pto_name_set_obj_color (obj_desc_t *obj_desc, int col_idx) -{ - int i; - - for (i = 0; i < obj_desc->n_fields; i ++) { - qset_t *ptos = obj_desc->values [i]; - - desc_t *tgt = (desc_t*) qset_start (ptos); - - while (NULL != tgt) { - pto_name_set_color (tgt, col_idx); - - tgt = (desc_t*) qset_next (ptos); - } - } -} - -/* set a nice color to an array descriptor */ -static void pto_name_set_arr_color (arr_desc_t *arr_desc, int col_idx) -{ - qset_t *ptos = arr_desc->value; - - desc_t *tgt = (desc_t*) qset_start (ptos); - - while (NULL != tgt) { - pto_name_set_color (tgt, col_idx); - - tgt = (desc_t*) qset_next (ptos); - } -} - -/* set a nice color to a descriptor */ -static void pto_name_set_color (desc_t *desc, int col_idx) -{ - /* assert (0 == desc->col_idx); */ - - desc->col_idx = col_idx; - - if (FALSE == desc->visit) { - desc->visit = TRUE; - if (object == desc->kind) { - pto_name_set_obj_color ((obj_desc_t*) desc, col_idx); - } else if (array == desc->kind) { - pto_name_set_arr_color ((arr_desc_t*) desc, col_idx); - } - - desc->visit = FALSE; - } -} - - -/* allocate nice colors for an object descriptor */ -static int pto_name_alloc_obj_color (obj_desc_t *obj_desc) -{ - int i; - int col_idx = 0; - - for (i = 0; (0 == col_idx) && (i < obj_desc->n_fields); i ++) { - qset_t *ptos = obj_desc->values [i]; - desc_t *tgt = (desc_t*) qset_start (ptos); - - while ((0 == col_idx) && (NULL != tgt)) { - col_idx = pto_name_alloc_color (tgt); - - tgt = (desc_t*) qset_next (ptos); - } - } - - return (col_idx); -} - -/* allocate nice colors for an array descriptor */ -static int pto_name_alloc_arr_color (arr_desc_t *arr_desc) -{ - int col_idx = 0; - - qset_t *ptos = arr_desc->value; - - desc_t *tgt = (desc_t*) qset_start (ptos); - - while ((NULL != tgt) && (0 == col_idx)) { - col_idx = pto_name_alloc_color (tgt); - tgt = (desc_t*) qset_next (ptos); - } - - return (col_idx); -} - -/* allocate nice colors for the given descriptor */ -static int pto_name_alloc_color (desc_t *desc) -{ - int col_idx = 0; - - if (0 != desc->col_idx) { - return (desc->col_idx); - } - - if (FALSE == desc->visit) { - desc->visit = TRUE; - if (object == desc->kind) { - col_idx = pto_name_alloc_obj_color ((obj_desc_t*) desc); - } else if (array == desc->kind) { - col_idx = pto_name_alloc_arr_color ((arr_desc_t*) desc); - } - desc->visit = FALSE; - } - - if (0 == col_idx) { - col_idx = ++ last_col_idx; - } - - pto_name_set_color (desc, col_idx); - - return (col_idx); -} - -/* allocate nice colors */ -static void pto_name_alloc_colors (void) -{ - desc_t *desc = all_descs; - - while (NULL != desc) { - pto_name_alloc_color (desc); - - desc = desc->prev; - } -} -# endif /* defined PTO_COLOR */ - -/* See whether the given entity is a field. */ -static int is_field (ir_entity *ent) -{ - ir_type *tp = get_entity_type (ent); - - if (is_Primitive_type (tp) || is_Pointer_type (tp)) { - /* actually, we don't get by by restricting ourselves to pointer types */ - return (TRUE); - } else { - return (FALSE); - } -} - -/* Helper to collect_fields(ir_type*): collect all fields of the given - clazz and its super classes into the given obstack. */ -static void _collect_fields (ir_type *clazz, struct obstack *obst) -{ - int n_members = get_class_n_members (clazz); - int n_supers = get_class_n_supertypes (clazz); - int i; - - for (i = 0; i < n_members; i ++) { - ir_entity *ent = get_class_member (clazz, i); - - if (is_field (ent)) { - if (allocation_static != get_entity_allocation (ent)) { - obstack_ptr_grow (obst, ent); - } - } - } - - for (i = 0; i < n_supers; i ++) { - ir_type *s_clazz = get_class_supertype (clazz, i); - - _collect_fields (s_clazz, obst); - } -} - -/* Collect the fields of the given class and its super classes into an array. - The last entry of the array is written NULL. */ -static ir_entity **collect_fields (ir_type *clazz) -{ - struct obstack obst; - int n_fields; - ir_entity ** fields; - void *tmp; - - if (NULL != get_type_link (clazz)) { - DBGPRINT (3, (stdout, "%s: reusing field list for \"%s\"\n", - __FUNCTION__, - get_type_name (clazz))); - - return ((ir_entity **) get_type_link (clazz)); - } else { - DBGPRINT (2, (stdout, "%s: new field list for \"%s\"\n", - __FUNCTION__, - get_type_name (clazz))); - } - - obstack_init (&obst); - - _collect_fields (clazz, &obst); - - /* append terminating NULL */ - obstack_ptr_grow (&obst, NULL); - - n_fields = obstack_object_size (&obst) / sizeof (void*); - - fields = NALLOC (n_fields * sizeof (ir_entity*)); - tmp = obstack_finish(&obst); - - memcpy (fields, tmp, n_fields * sizeof (ir_entity*)); - - obstack_free (&obst, NULL); - - set_type_link (clazz, fields); - - return (fields); -} - -/* Write the intro text for a name dump into the given stream */ -static void pto_name_dump_start (FILE *stream) -{ -# ifdef PTO_COLOR - pto_name_alloc_colors (); -# endif /* defined PTO_COLOR */ - - fprintf (stream, "digraph \"Names\" {\n"); - fprintf (stream, "\tgraph [rankdir=\"LR\", ordering=\"out\", size=\"11,7\", rotate=\"90\"];\n"); - fprintf (stream, "\tnode [shape=\"record\", style=\"filled\"];\n"); - fprintf (stream, "\tedge [color=\"black\"];\n"); - fprintf (stream, "\n"); -} - -/* Write the extro text for a name dump into the given stream */ -static void pto_name_dump_finish (FILE *stream) -{ - fprintf (stream, "}\n"); -} - -/* Write a node for the given descriptor into the given stream */ -static void pto_name_dump_desc (desc_t *desc, FILE *stream) -{ - ir_type *tp = desc->tp; - const char *tp_name = get_type_name (tp); - ir_node *nd; - - fprintf (stream, "\t/* %s \"%s\" */\n", - object == desc->kind ? "Object" : "Array", - tp_name); - - fprintf (stream, "\tdesc_%i [label=\"type \\[%i\\]", - desc->id, desc->id); - - if (-1 != desc->ctx) { - fprintf (stream, ", ctx = %i", desc->ctx); - } else { - fprintf (stream, " (global)"); - } - - fprintf (stream, "\\lname=\\\"%s\\\"", - tp_name); - - nd = desc->node; - - if (NULL != nd) { - ir_graph *graph = get_irn_irg (nd); - ir_entity *method = get_irg_entity (graph); - const char *ent_name = get_entity_name (method); - const char *own_name = get_type_name (get_entity_owner (method)); - - fprintf (stream, "\\lnode=%s\\[%li\\]", - get_op_name (get_irn_op (nd)), - get_irn_node_nr (nd)); - fprintf (stream, "\\lgraph=\\\"%s.%s\\\"", - own_name, - ent_name); - } - - if (desc->kind == object) { - obj_desc_t *obj_desc = (obj_desc_t*) desc; - - int i; - for (i = 0; i < obj_desc->n_fields; i ++) { - ir_entity *field = obj_desc->fields [i]; - - if (is_Pointer_type (get_entity_type (field))) { - const char *ent_name = get_entity_name (field); - - fprintf (stream, "|<%i>%s", i, ent_name); - } - } - } else if (array == desc->kind) { - fprintf (stream, "|[]"); - } else { - assert (0 && "invalid descriptor"); - } - - /* end label string */ - fprintf (stream, "\""); - -# ifdef PTO_COLOR - { - const char *fontcolor; - int col_idx = desc->col_idx; - float hue = (float) col_idx / (float) last_col_idx; - float sat = 1.000f; /* 0.300 .. 1.000 */ - float val = 0.800f; /* 0.300 .. 1.000 */ - - # define MAX_COLORS 12 - if (last_col_idx > MAX_COLORS) { - /* too many colors ... vary value too */ - float div = (float) MAX_COLORS / (float) last_col_idx; - - sat = (div * ((col_idx / MAX_COLORS))); - val = (div * ((col_idx / MAX_COLORS))); - - col_idx = col_idx % MAX_COLORS; - hue = (float) col_idx / (float) MAX_COLORS; - - // re-adjust sat and val - { - const float sat_min = 0.200f; /* 0.200 .. 0.400 */ - const float val_min = 0.300f; /* 0.300 .. 0.400 */ - - sat = sat_min + ((1.0f - sat_min) * sat); - val = val_min + ((1.0f - val_min) * val); - } - } - # undef MAX_COLORS - - fprintf (stream, ", color=\"%01.3f, %01.3f, %01.3f\"", hue, sat, val); - - if ((hue > 0.3) && (sat < 0.5)) { - fontcolor = "white"; - } else if (sat < 0.4) { - fontcolor = "white"; - } else { - fontcolor = "black"; - } - - fprintf (stream, ", fontcolor=\"%s\"", fontcolor); - } -# else /* if defined PTO_COLOR */ - fprintf (stream, ", color=\"lightgrey\""); -# endif /* defined PTO_COLOR */ - - /* end attributes */ - fprintf (stream, "];\n"); - fprintf (stream, "\n"); - - /* now the edges */ - if (desc->kind == object) { - obj_desc_t *obj_desc = (obj_desc_t*) desc; - - int i; - for (i = 0; i < obj_desc->n_fields; i ++) { - desc_t *tgt = (desc_t*) qset_start (obj_desc->values [i]); - - while (NULL != tgt) { - fprintf (stream, "\tdesc_%i:%i -> desc_%i:HEAD;\n", - desc->id, i, tgt->id); - - tgt = (desc_t*) qset_next (obj_desc->values [i]); - } - } - } else if (array == desc->kind) { - arr_desc_t *arr_desc = (arr_desc_t*) desc; - - desc_t *tgt = (desc_t*) qset_start (arr_desc->value); - - while (NULL != tgt) { - fprintf (stream, "\tdesc_%i:arr -> desc_%i:HEAD;\n", - desc->id, tgt->id); - - tgt = (desc_t*) qset_next (arr_desc->value); - } - } - - fprintf (stream, "\n"); -} - - -/* =================================================== - Exported Implementation: - =================================================== */ -/* Find the given descriptor's entry for the given entity */ -qset_t *get_entry (desc_t *desc, ir_entity *ent) -{ - - if (desc->kind == object) { - obj_desc_t *obj_desc = (obj_desc_t*) desc; - int i; - const int n_fields = obj_desc->n_fields; - - for (i = 0; i < n_fields; i ++) { - if (ent == obj_desc->fields [i]) { - return (obj_desc->values [i]); - } - } - - assert (0 && "entry not found"); - } else if (desc->kind == array) { - arr_desc_t *arr_desc = (arr_desc_t*) desc; - - return (arr_desc->value); - } else { - assert (0 && "invalid descriptor"); - } - return NULL; -} - - -/* get a new descriptor for the given type at the given node */ -desc_t *new_name (ir_type *tp, ir_node *node, int ctx) -{ - desc_t *desc = NULL; - - assert ((is_Class_type (tp) || is_Array_type (tp)) && "unsuitable type"); - - DBGPRINT (2, (stdout, "%s: new name for type \"%s\"\n", - __FUNCTION__, - get_type_name (tp))); - fflush (stdout); - - if (is_Class_type (tp)) { - obj_desc_t *obj_desc = NALLOC (sizeof (obj_desc_t)); - int i; - int n_fields; - - obj_desc->kind = object; - obj_desc->fields = collect_fields (tp); - - for (n_fields = 0; (NULL != obj_desc->fields [n_fields]); n_fields ++) { - /* nothing, just count ... */ - } - - obj_desc->n_fields = n_fields; - obj_desc->values = (qset_t**) NALLOC (n_fields * sizeof (qset_t*)); - - for (i = 0; i < n_fields; i ++) { - obj_desc->values [i] = qset_new (N_INITIAL_OJBS, qset_obst); - } - - desc = (desc_t*) obj_desc; - } else if (is_Array_type (tp)) { - arr_desc_t *arr_desc = (arr_desc_t*) NALLOC (sizeof (arr_desc_t)); - - arr_desc->kind = array; - arr_desc->value = qset_new (N_INITIAL_OJBS, qset_obst); - - desc = (desc_t*) arr_desc; - } - - desc->id = name_id ++; - desc->col_idx = 0; - desc->tp = tp; - desc->visit = FALSE; - desc->ctx = ctx; - desc->node = node; - - desc->prev = all_descs; - all_descs = desc; - - return (desc); -} - -# define N_GLOB_INITIAL_FIELDS 20 -static obj_desc_t *obj_glob = NULL; -static int n_glob_fields = N_GLOB_INITIAL_FIELDS; - -/* get a new descriptor for the given (presumably static) entity */ -desc_t *new_ent_name (ir_entity *ent) -{ - int i; - int missing = TRUE; - ir_type *tp = get_entity_type (ent); - - assert (is_Pointer_type (tp)); - tp = get_pointer_points_to_type (tp); - assert (is_Class_type (tp)); - - DBGPRINT (2, (stdout, "%s: new name for entity \"%s\"\n", - __FUNCTION__, - get_entity_name (ent))); - DBGEXE (2, (fflush (stdout))); - - assert (((allocation_static == get_entity_allocation (ent)) || - (allocation_automatic == get_entity_allocation (ent))) && - "not a static/automatic field"); - - if (NULL == obj_glob) { - obj_glob = (obj_desc_t*) NALLOC (sizeof (obj_desc_t)); - - obj_glob->id = name_id ++; - obj_glob->ctx = -1; - obj_glob->col_idx = 0; - obj_glob->visit = FALSE; - obj_glob->kind = object; - obj_glob->tp = get_glob_type (); - obj_glob->node = NULL; - - obj_glob->n_fields = 0; - obj_glob->fields = (ir_entity**) NALLOC (N_GLOB_INITIAL_FIELDS * sizeof (ir_entity*)); - obj_glob->values = (qset_t**) NALLOC (N_GLOB_INITIAL_FIELDS * sizeof (qset_t*)); - - obj_glob->prev = all_descs; - all_descs = (desc_t*) obj_glob; - } - - for (i = 0; missing && (i < obj_glob->n_fields); i ++) { - if (ent == obj_glob->fields [i]) { - missing = FALSE; - } - } - - if (missing) { - if (obj_glob->n_fields == n_glob_fields) { - ir_entity **fields = obj_glob->fields; - qset_t **values = obj_glob->values; - - n_glob_fields *= 2; - obj_glob->fields = (ir_entity**) NALLOC (n_glob_fields * sizeof (ir_entity*)); - obj_glob->values = (qset_t**) NALLOC (n_glob_fields * sizeof (qset_t*)); - - memcpy (obj_glob->fields, fields, obj_glob->n_fields * sizeof (ir_entity*)); - memcpy (obj_glob->values, values, obj_glob->n_fields * sizeof (qset_t*)); - - /* free (fields); */ - /* free (values); */ - } - - obj_glob->fields [obj_glob->n_fields ] = ent; - obj_glob->values [obj_glob->n_fields ++] = qset_new (N_INITIAL_OJBS, qset_obst); - } - - return ((desc_t*) obj_glob); -} -# undef N_GLOB_INITIAL_FIELDS - -/* Dump all names to a file of the given name */ -void pto_dump_names (const char *name) -{ - desc_t *desc = all_descs; - FILE *stream = fopen (name, "w"); - - errno = 0; - if (NULL == stream) { - fprintf (stderr, "%s: unable to open %s (%s)\n", - __FUNCTION__, name, strerror (errno)); - return; - } - - pto_name_dump_start (stream); - - while (NULL != desc) { - pto_name_dump_desc (desc, stream); - - desc = desc->prev; - } - - pto_name_dump_finish (stream); - fclose (stream); -} - -/* Initialise the name module */ -void pto_name_init (void) -{ - DBGPRINT (3, (stdout, "%s\n", __FUNCTION__)); - assert (NULL == name_obst); - assert (NULL == qset_obst); - - name_obst = xmalloc (sizeof (struct obstack)); - qset_obst = xmalloc (sizeof (struct obstack)); - - obstack_init (name_obst); - obstack_init (qset_obst); -} - -/* Cleanup the name module */ -void pto_name_cleanup (void) -{ - DBGPRINT (3, (stdout, "%s\n", __FUNCTION__)); - obstack_free (name_obst, NULL); - obstack_free (qset_obst, NULL); - - memset (name_obst, 0x00, sizeof (struct obstack)); - memset (qset_obst, 0x00, sizeof (struct obstack)); - - free (name_obst); - free (qset_obst); - - name_obst = NULL; - qset_obst = NULL; -} - - -/* - $Log$ - Revision 1.19 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.18 2006/01/13 22:56:21 beck - renamed all types 'type' to 'ir_type' - - Revision 1.17 2005/12/16 16:59:54 grund - *** empty log message *** - - Revision 1.16 2005/12/05 12:19:54 beck - added missing include (not anymore included in libFirm) - - Revision 1.15 2005/03/02 10:14:38 beck - placed a return on all execution pathes - - Revision 1.14 2005/02/17 08:45:38 liekweg - Don't return a value for an invalid descriptor - - Revision 1.13 2005/02/11 10:21:28 beck - get_entry now always returns a value - - Revision 1.12 2005/01/14 14:13:56 liekweg - fix gnu extension, fix fprintf's, fix allocs - - Revision 1.11 2005/01/05 14:25:54 beck - renames all is_x*_type() functions to is_X*_type() to prevent name clash with EDG fronten - - Revision 1.10 2004/12/22 14:43:14 beck - made allocations C-like - - Revision 1.9 2004/12/21 15:34:09 beck - removed C99 constructs - make const float - add default return - - Revision 1.8 2004/12/15 13:30:30 liekweg - use DBGEXE correctly; print yet nicer names - - Revision 1.7 2004/12/15 09:18:18 liekweg - pto_name.c - - Revision 1.6 2004/12/06 12:52:09 liekweg - colorize name dump - - Revision 1.4 2004/11/30 15:49:27 liekweg - include 'dump' - - Revision 1.3 2004/11/30 14:47:54 liekweg - fix initialisation; do correct iteration - - Revision 1.2 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_name.h b/ir/ana2/pto_name.h deleted file mode 100644 index 5b1ed950b..000000000 --- a/ir/ana2/pto_name.h +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Names for abstract objects - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_PTO_NAME_H -# define FIRM_ANA2_PTO_NAME_H - -# include "pto_comp.h" /* for pto_t */ -# include "irnode.h" -# include "type.h" -# include "qset.h" - -/* =================================================== - Global Defines: - =================================================== */ - -/* =================================================== - Global Data Types: - =================================================== */ -typedef enum desc_kind_enum { - none, - object, - array -} desc_kind_t; - -/* abstract super class for all descriptors */ -typedef struct desc_str -{ - int id; - int visit; - int ctx; - int col_idx; - desc_kind_t kind; - ir_type *tp; - ir_node *node; /* allocation node */ - struct desc_str *prev; /* linked list */ -} desc_t; - -/* object descriptor */ -typedef struct obj_desc_str -{ - int id; - int visit; - int ctx; - int col_idx; - desc_kind_t kind; - ir_type *tp; - ir_node *node; /* allocation node */ - struct desc_str *prev; /* linked list */ - - int n_fields; - ir_entity **fields; - qset_t **values; -} obj_desc_t; - -/* array descriptor */ -typedef struct arr_desc_str -{ - int id; - int visit; - int ctx; - int col_idx; - desc_kind_t kind; - ir_type *tp; - ir_node *node; /* allocation node */ - struct desc_str *prev; /* linked list */ - - qset_t *value; -} arr_desc_t; - -/* =================================================== - Global Prototypes: - =================================================== */ -/* Dump all names to a file of the given name */ -void pto_dump_names (const char*); - -/* Find the given descriptor's entry for the given entity */ -qset_t *get_entry (desc_t*, ir_entity*); - -/* get a new descriptor for the given type at the given node */ -desc_t *new_name (ir_type*, ir_node*, int); - -/* get a new descriptor for the given (presumably static) entity */ -desc_t *new_ent_name (ir_entity*); - -/* Initialise the name module */ -void pto_name_init (void); - -/* Cleanup the name module */ -void pto_name_cleanup (void); - -/* =================================================== - Global Variables: - =================================================== */ - - -# endif - - - -/* - $Log$ - Revision 1.8 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.7 2006/01/13 22:00:15 beck - renamed all types 'type' to 'ir_type' - - Revision 1.6 2004/12/15 13:30:41 liekweg - print yet nicer names - - Revision 1.5 2004/12/06 12:52:09 liekweg - colorize name dump - - Revision 1.4 2004/11/30 15:49:27 liekweg - include 'dump' - - Revision 1.3 2004/11/30 14:47:54 liekweg - fix initialisation; do correct iteration - - Revision 1.2 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.1 2004/11/18 16:37:34 liekweg - rewritten - - -*/ diff --git a/ir/ana2/pto_util.c b/ir/ana2/pto_util.c deleted file mode 100644 index fe831498e..000000000 --- a/ir/ana2/pto_util.c +++ /dev/null @@ -1,215 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Utilitites for PTO - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* - pto_util: Utilitites for PTO -*/ - -# include "pto_util.h" - -# include "irnode_t.h" -# include "irgwalk.h" -# include "xmalloc.h" - -# include "pto_debug.h" -# include "gnu_ext.h" - -/* Local Defines: */ -# ifndef TRUE -# define TRUE 1 -# define FALSE 0 -# endif /* not defined TRUE */ - -/* Local Data Types: */ -/* Environment for find_irg_args */ -typedef struct find_irg_args_env { - ir_node **args; - ir_node *arg; -} find_irg_args_env_t; - - -/* Local Variables: */ - -/* Local Prototypes: */ - -/* =================================================== - Local Implementation: - =================================================== */ -/* Helper for find_irg_args */ -static void find_irg_arg (ir_node *node, void *env) -{ - find_irg_args_env_t *arg_env = (find_irg_args_env_t*) env; - - if (iro_Proj == get_irn_opcode (node)) { - if (arg_env->arg == get_Proj_pred (node)) { - long n = get_Proj_proj (node); - - assert (! arg_env->args [n]); - - arg_env->args [n] = node; - } - } -} - -/* =================================================== - Exported Implementation: - =================================================== */ -/* Find the arguments of a graph. For a method that has n args, the - result array has 'n+1' entries, the last of which is written NULL. - Note that not all entries in [0..n-1] will be populated all the time. -*/ -ir_node **find_irg_args (ir_graph *graph) -{ - ir_type *tp = get_entity_type (get_irg_entity (graph)); - const int n_args = get_method_n_params (tp); - ir_node **args = xcalloc (n_args + 1, sizeof (ir_node*)); - ir_node *arg = get_irg_args (graph); - find_irg_args_env_t *arg_env; - - arg_env = (find_irg_args_env_t*) xmalloc (sizeof (find_irg_args_env_t)); - - arg_env->args = args; - arg_env->arg = arg; - - { - ir_graph *save = get_current_ir_graph (); - - set_current_ir_graph (graph); - irg_walk (get_irg_end (graph), find_irg_arg, NULL, arg_env); - set_current_ir_graph (save); - } - - memset (arg_env, 0x00, sizeof (find_irg_args_env_t)); - free (arg_env); - - args [n_args] = NULL; - - return (args); -} - -/* Get the entity of a ptr */ -ir_entity *get_ptr_ent (ir_node *ptr) -{ - ir_entity *ent = NULL; - const ir_opcode ptr_op = get_irn_opcode (ptr); - switch (ptr_op) { - case (iro_Cast): { - ent = get_ptr_ent (get_Cast_op (ptr)); - } break; - case (iro_Sel): { - ent = get_Sel_entity (ptr); - } break; - - case (iro_SymConst): { - ent = get_SymConst_entity (ptr); - } break; - - default: { - fprintf (stderr, "%s: no ent for ptr=%s[%ld]\n", - __FUNCTION__, - get_op_name (get_irn_op (ptr)), - get_irn_node_nr (ptr)); - assert (0); - } - } - - return (ent); -} - -/* Check whether the load of the given ptr is a dummy */ -int is_dummy_load_ptr (ir_node *ptr) -{ - const ir_opcode ptr_op = get_irn_opcode (ptr); - - switch (ptr_op) { - case (iro_Cast): { - return (is_dummy_load_ptr (get_Cast_op (ptr))); - } break; - case (iro_Sel): - case (iro_SymConst): { - return (FALSE); - } break; - - default: { - return (TRUE); - } - } -} - - -/* - $Log$ - Revision 1.19 2007/01/16 15:45:42 beck - renamed type opcode to ir_opcode - - Revision 1.18 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.17 2006/06/08 10:49:07 beck - renamed type to ir_type - - Revision 1.16 2005/01/14 14:13:32 liekweg - fix gnu extension - - Revision 1.15 2005/01/10 17:26:34 liekweg - fixup printfs, don't put environments on the stack - - Revision 1.14 2004/12/23 15:47:09 beck - removed uneeded allocations - used new xcalloc - - Revision 1.13 2004/12/22 14:43:14 beck - made allocations C-like - - Revision 1.12 2004/12/21 15:53:12 beck - removed GNUC constructs - - Revision 1.11 2004/12/20 17:34:35 liekweg - fix recursion handling - - Revision 1.10 2004/12/06 12:55:06 liekweg - actually iterate - - Revision 1.9 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.8 2004/11/26 15:59:14 liekweg - recognize dummy loads - - Revision 1.7 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.6 2004/11/18 16:37:07 liekweg - rewrite - - -*/ diff --git a/ir/ana2/pto_util.h b/ir/ana2/pto_util.h deleted file mode 100644 index df44bc401..000000000 --- a/ir/ana2/pto_util.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Utilitites for PTO - * @author Florian - * @date Sat Nov 13 19:35:27 CET 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_PTO_UTIL_H -# define FIRM_ANA2_PTO_UTIL_H - -# include "irnode.h" -# include "entity.h" - -/* =================================================== - Global Defines: - =================================================== */ - -/* =================================================== - Global Data Types: - =================================================== */ - -/* =================================================== - Global Prototypes: - =================================================== */ -/** Get the entity of a ptr. */ -ir_entity *get_ptr_ent (ir_node *ptr); - -/** - * Find the arguments of a graph. For a method that has n args, the - * result array has 'n+1' entries, the last of which is written NULL. - * - * @param irg The IR graph - */ -ir_node **find_irg_args (ir_graph *irg); - -/* Check whether the load of the given ptr is a dummy */ -int is_dummy_load_ptr (ir_node*); - -/* =================================================== - Global Variables: - =================================================== */ - - -# endif /* not defined _PTO_UTIL_ */ - - - -/* - $Log$ - Revision 1.8 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.7 2005/06/17 17:43:52 beck - added doxygen docu - - Revision 1.6 2004/11/26 15:59:14 liekweg - recognize dummy loads - - Revision 1.5 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.4 2004/11/18 16:37:07 liekweg - rewrite - - -*/ diff --git a/ir/ana2/qset.c b/ir/ana2/qset.c deleted file mode 100644 index 8950429df..000000000 --- a/ir/ana2/qset.c +++ /dev/null @@ -1,786 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief yet another set implementation - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -# include -# include -# include -# include - -# include "obst.h" -# include "timing.h" -# include "qset.h" - -/* local globals */ -int qset_id = 0; - -/* local protos */ - -# ifdef UNSINN -/* Check whether the given list of sortables is sorted. */ -static void q_check (sortable_t*, const int); -# endif /* defined UNSINN */ - -/* Test whether the given val is among values. Return the index of - val in values, or -1. */ -static int q_test (sortable_t*, const sortable_t, const int); - -/* Sort n_elems entries in 'values' */ -static void q_sort (sortable_t*, const int); - -/* Compare funktion, meant to be qsort(3)-compatible */ -static INLINE int sortable_compare (const void *pa, const void *pb) -{ - const int a = * (unsigned int*) pa; - const int b = * (unsigned int*) pb; - - if (a==b) { - return (0); - } - - return ((a < b) ? -1 : +1); -} - -/* - Wrapper for mixed allocation -*/ -static void *mix_malloc (struct obstack *obst, size_t size) -{ - if (NULL != obst) { - return (obstack_alloc (obst, size)); - } else { - return (xmalloc (size)); - } -} - -/* - Allocate a list of sortables of the given length. -*/ -static sortable_t *alloc_list (const int len, struct obstack *obst) -{ - sortable_t *values = (sortable_t*) mix_malloc (obst, len * sizeof (sortable_t)); - - memset (values, 0x00, len * sizeof (sortable_t)); - - return (values); -} - -# ifdef UNSINN -/* - Create a list of sortables of the given length. -*/ -static sortable_t *gen_list (const int len, struct obstack *obst) -{ - int i; - sortable_t *values = alloc_list (len, obst); - - for (i = 0; i < len; i ++) { - values [i] = rand () >> 16; - } - - return (values); -} -# endif /* defined UNSINN */ - -/* - Helper to q_test --- return the index of val in values, or -1 -*/ -static int _q_test (sortable_t *values, - const sortable_t val, - const int lo, const int hi) -{ - int mid; - - /* fprintf (stdout, "%s for %d [%i:%i]\n", __FUNCTION__, val, lo, hi); */ - - if (lo == hi) { - if (EQUAL (val, values [lo])) { - return (lo); - } else { - return (-1); - } - } - - if (COMPARE (val, values [lo])) { - /* too low */ - return (-1); - } - - if (COMPARE (values [hi], val)) { - /* too high */ - return (-1); - } - - mid = (hi + lo) / 2; - - if (EQUAL (val, values [mid])) { - return (mid); - } - - if (COMPARE (val, values [mid])) { - return (_q_test (values, val, lo, mid)); - } else { - return (_q_test (values, val, mid+1, hi)); - } -} - -/* - Helper to q_sort -*/ -static void _q_sort (sortable_t *values, const int lo, const int hi) -{ - sortable_t pivot; - int p_lo; - int p_hi; - - /* handle base case: */ - if (lo >= hi) { - return; - } - - if (1 == hi - lo) { - if (COMPARE (values [hi], values [lo])) { - sortable_t tmp = values [lo]; - values [lo] = values [hi]; - values [hi] = tmp; - } - - return; - } - - pivot = values [lo]; - - p_lo = lo+1; - p_hi = hi; - - while (p_lo <= p_hi) { - if (COMPARE (values [p_lo], pivot)) { - values [p_lo-1] = values [p_lo]; - - p_lo ++; - } else { - sortable_t tmp = values [p_lo]; - - values [p_lo] = values [p_hi]; - values [p_hi] = tmp; - - p_hi --; - } - } - - values [p_lo-1] = pivot; - - _q_sort (values, lo, p_lo-1); - _q_sort (values, p_lo, hi); -} - -# ifdef UNSINN -/* - Little test harness for q_sort and friends. -*/ -static void test_qsort (const int n_runs, const int max_elems, const int incr) -{ - int n_elems = 0; - int i; - - fprintf (stdout, "# n_elems: q_sort time : libc qsort time\n"); - - while (n_elems <= max_elems) { - int total = 0; - int qtotal = 0; - - for (i = 0; i < n_runs; i ++) { - sortable_t *list = gen_list (n_elems, NULL); - - timing_t *timing = start_timing (); - q_sort (list, n_elems); - total += end_timing (timing); - - q_check (list, n_elems); - - free (list); - } - - for (i = 0; i < n_runs; i ++) { - sortable_t *list = gen_list (n_elems, NULL); - - timing_t *timing = start_timing (); - qsort (list, n_elems, sizeof (sortable_t), sortable_compare); - qtotal += end_timing (timing); - - q_check (list, n_elems); - - free (list); - } - - fprintf (stdout, "%d %d %d\n", n_elems, total/n_runs, qtotal/n_runs); - fflush (stdout); - n_elems += incr; - } - - - fprintf (stdout, "\n"); -} - -/* - Little test harness for the qset implementation -*/ -static void test_qset (const int n_entries) -{ - int i; - int n1, n2, n; - - qset_t *q1 = qset_new (n_entries, NULL); - qset_t *q2 = qset_new (n_entries, NULL); - qset_t *q = NULL; - - sortable_t *values = gen_list (n_entries, NULL); - - for (i = 0; i < n_entries; i ++) { - qset_insert (q1, values [i]); - qset_insert (q2, values [i]); - } - - fprintf (stdout, "q1: \t\t"); - qset_print (q1, stdout); - qset_sort (q1); - qset_sort (q2); - - /* TEST */ - q2->is_sorted = FALSE; - qset_sort (q2); - - fprintf (stdout, "q1 (sorted):\t"); - qset_print (q1, stdout); - - assert (qset_compare (q1, q2)); - - q = qset_union (q1, q2); - fprintf (stdout, "qq (union):\t"); - qset_print (q, stdout); - - n1 = qset_size (q1); - n2 = qset_size (q2); - n = qset_size (q); - - fprintf (stdout, "q1.size = %i\n", n1); - fprintf (stdout, "q1.slots = %i\n", q1->n_slots); - fprintf (stdout, "q2.size = %i\n", n2); - fprintf (stdout, "q2.slots = %i\n", q2->n_slots); - fprintf (stdout, "q.size = %i\n", n); - fprintf (stdout, "q.slots = %i\n", q->n_slots); - - assert (n1 == n2); - assert (n2 == n); - - assert (qset_compare (q1, q2)); - assert (qset_compare (q2, q)); - assert (qset_compare (q, q1)); - - for (i = 0; i < n_entries; i ++) { - assert (qset_contains (q1, values [i])); - assert (qset_contains (q2, values [i])); - assert (qset_contains (q, values [i])); - } - - qset_compact (q1); - qset_compact (q); - - fprintf (stdout, "q1.size = %i\n", n1); - fprintf (stdout, "q1.slots = %i\n", q1->n_slots); - fprintf (stdout, "q2.size = %i\n", n2); - fprintf (stdout, "q2.slots = %i\n", q2->n_slots); - fprintf (stdout, "q.size = %i\n", n); - fprintf (stdout, "q.slots = %i\n", q->n_slots); - - assert (qset_compare (q1, q2)); - assert (qset_compare (q2, q)); - assert (qset_compare (q, q1)); - - for (i = 0; i < n_entries; i ++) { - assert (qset_contains (q1, values [i])); - assert (qset_contains (q2, values [i])); - assert (qset_contains (q, values [i])); - } - - qset_delete (q); - qset_delete (q1); - qset_delete (q2); -} -# endif /* defned UNSINN */ - -/* PRIVATE QSET IMPLEMENTATION */ -/* - Resize a qset to (at least) the given size. -*/ -static void qset_resize (qset_t *qset, const int n_slots) -{ - int new_size; - sortable_t *values = NULL; - - if (qset->n_slots >= n_slots) { - return; - } - - new_size = qset->n_slots; - - while (new_size < n_slots) { - new_size *= 2; - } - - values = alloc_list (new_size, qset->obst); - - memcpy (values, qset->values, qset->n_elems * sizeof (sortable_t)); - memset (qset->values, 0x00, qset->n_elems * sizeof (sortable_t)); /* debug only */ - - if (NULL == qset->obst) { - free (qset->values); - } - - qset->values = values; - qset->n_slots = new_size; -} - -/* - Print a list of sortables. -*/ -static void q_print (sortable_t *values, const int n_values, FILE *stream) -{ - int i; - - fprintf (stream, "{"); - - for (i = 0; i < n_values; i ++) { - if (0 == values [i]) { - fprintf (stream, "_"); - } else { - fprintf (stream, "0x08%x", (int) values [i]); - } - - if (i + 1 != n_values) { - fprintf (stream, ", "); - } - } - - fprintf (stream, "}\n"); -} - -# ifdef UNSINN -/* - Check whether the given list of sortables is sorted. -*/ -static void q_check (sortable_t *values, const int n_values) -{ - int i; - - for (i = 1; i < n_values; i ++) { - assert (COMPARE (values [i-1], values [i]) || - EQUAL (values [i-1], values [i])); - } - - for (i = 1; i < n_values; i ++) { - assert (-1 != q_test (values, values [i], n_values)); - } -} -# endif /* defined UNSINN */ - -/* - Test whether the given val is among values. Return the lowest index of val - in values, or -1. -*/ -static int q_test (sortable_t *values, const sortable_t val, const int n_elems) -{ - int idx = _q_test (values, val, 0, n_elems-1); - - while ((0 <= idx-1) && EQUAL (values [idx], val)) { - idx --; - } - - return (idx); -} - -/* - Sort entries in 'values' from index 'lo' to 'hi' (inclusive) -*/ -static void q_sort (sortable_t *values, const int n_elems) -{ - _q_sort (values, 0, n_elems-1); -} - -/* PUBLIC INTERFACE */ - -/* - Allocate a new qset with initial space for up to n_elems. - If a non-NULL obstack is given, it is used for all allocations of this qset - and must be initialised and deleted by the user of the qset. -*/ -qset_t *qset_new (const int n_elems, struct obstack *obst) -{ - qset_t *qset = (qset_t*) mix_malloc (obst, sizeof (qset_t)); - - qset->obst = obst; - qset->values = alloc_list (n_elems, obst); - memset (qset->values, 0x00, n_elems * sizeof (sortable_t)); - - qset->n_slots = n_elems; - qset->n_elems = 0; - qset->is_sorted = FALSE; - qset->id = qset_id ++; - - return (qset); -} - -/* - Sort the entries of the given qset. -*/ -void qset_sort (qset_t *qset) -{ - int occ = 0; - int i; - - if (qset->is_sorted) { - return; - } - - q_sort (qset->values, qset->n_elems); - - for (i = 1; i < qset->n_elems; i ++) { - if (! EQUAL (qset->values [i], qset->values [occ])) { - qset->values [++ occ] = qset->values [i]; - } - } - - occ ++; - - /* - if (qset->n_elems != occ) { - fprintf (stdout, "removed %i duplicates\n", qset->n_elems - occ); - }*/ - - qset->n_elems = occ; - - qset->is_sorted = TRUE; -} - -/* - Compact a qset to take up no more space than required. -*/ -void qset_compact (qset_t *qset) -{ - if (NULL == qset->obst) { - sortable_t *values = (sortable_t*) mix_malloc (qset->obst, - qset->n_elems * sizeof (sortable_t)); - memcpy (values, qset->values, qset->n_elems * sizeof (sortable_t)); - - memset (qset->values, 0x00, qset->n_elems * sizeof (sortable_t)); - - free (qset->values); - - qset->values = values; - qset->n_slots = qset->n_elems; - } -} - -/* - Free the memory associated with the given qset -*/ -void qset_delete (qset_t *qset) -{ - memset (qset->values, 0x00, qset->n_elems * sizeof (sortable_t)); - - if (NULL == qset->obst) { - free (qset->values); - } - - memset (qset, 0x00, sizeof (qset_t)); - - if (NULL == qset->obst) { - free (qset); - } -} - -/* - Test whether the given qset contains the given value. -*/ -int qset_contains (qset_t *qset, sortable_t val) -{ - qset_sort (qset); - - return (-1 != q_test (qset->values, val, qset->n_elems)); -} - -/* - Delete the given value from the given qset (if it exists) -*/ -void qset_remove (qset_t *qset, sortable_t val) -{ - int idx; - int occ = 0; - int i; - - qset_sort (qset); - - idx = q_test (qset->values, val, qset->n_elems); - - if (-1 == idx) { - return; - } - - while (EQUAL (qset->values [idx + occ], val)) { - occ ++; - } - - for (i = idx; i < qset->n_elems - occ; i ++) { - qset->values [i] = qset->values [i+occ]; - } - - qset->n_elems -= occ; -} - -/* - Insert the given elem into the given qset; return nonzero iff any - involved values change. -*/ -int qset_insert (qset_t *qset, sortable_t val) -{ - int i; - const int n_elems = qset->n_elems; - - /* todo: sort, find */ - assert (0 != val); - - for (i = 0; i < n_elems; i ++) { - if (EQUAL (val, qset->values [i])) { - return (FALSE); - } - } - - qset_resize (qset, qset->n_elems+1); - - /* qset_print (qset, stdout); */ - /* fprintf (stdout, "%s: must insert 0x%08x\n", __FUNCTION__, (void*) val); */ - - qset->values [qset->n_elems++] = val; - qset->is_sorted = FALSE; - - return (TRUE); -} - -/* - Insert all elems of qset2 into qset1; return nonzero iff any - involved values change. qset2 is *not* deleted. -*/ -int qset_insert_all (qset_t *qset1, qset_t *qset2) -{ - int change = FALSE; - sortable_t val = qset_start (qset2); - - while (0 != val) { - change |= qset_insert (qset1, val); - - val = qset_next (qset2); - } - - qset_sort (qset1); - - return (change); -} - -/* - Compare two qsets. -*/ -int qset_compare (qset_t *qset1, qset_t *qset2) -{ - int i; - const int n_elems = qset1->n_elems; - - qset_sort (qset1); - qset_sort (qset2); - - if (qset1->n_elems != qset2->n_elems) { - return (FALSE); - } - - for (i = 0; i < n_elems; i ++) { - if (qset1->values [i] != qset2->values [i]) { - return (FALSE); - } - } - - return (TRUE); -} - -/* - Returns the union of two qsets. -*/ -qset_t *qset_union (qset_t *qset1, qset_t *qset2) -{ - qset_t *qset = (qset_t*) mix_malloc (qset1->obst, sizeof (qset_t)); - const int n_elems = qset1->n_elems + qset2->n_elems; - - qset->values = alloc_list (n_elems, qset1->obst); - - memcpy (qset->values, qset1->values, - qset1->n_elems * sizeof (sortable_t)); - - memcpy (qset->values+qset1->n_elems, - qset2->values, qset2->n_elems * sizeof (sortable_t)); - - qset->obst = qset1->obst; - qset->n_elems = n_elems; - qset->n_slots = qset->n_elems; - - qset_sort (qset); - - return (qset); -} - -/* - Report the size of the given qset. -*/ -int qset_size (qset_t *qset) -{ - return (qset->n_elems); -} - -/* - Print the given qset to the given stream. -*/ -void qset_print (qset_t *qset, FILE *stream) -{ - q_print (qset->values, qset->n_elems, stream); -} - -/* - Check wether the given qset is empty -*/ -int qset_is_empty (qset_t *qset) -{ - return (0 == qset->n_elems); -} - -/* - Initialise a new iteration over a qset -*/ -sortable_t *qset_start (qset_t *qset) -{ - sortable_t *start; - - qset->cursor = 0; - - start = qset_next (qset); - - return (start); /* works for empty sets, too */ -} - -/* - Step to the next element -*/ -sortable_t *qset_next (qset_t *qset) -{ - if (qset->n_elems == qset->cursor) { - return (NULL); - } - - /* quick fix to skip NULL entries */ - while ((qset->cursor < qset->n_elems) && - (NULL == qset->values [qset->cursor])) { - qset->cursor ++; - } - - return (qset->values [qset->cursor++]); -} - - -# ifdef UNSINN -int qset_test_main (int argc, char **argv) -{ - struct timeval tp; - unsigned int seed; - - if (-1 == gettimeofday (&tp, NULL)) { - perror ("gettimeofday"); - exit (EXIT_FAILURE); - } - - seed = (unsigned int) tp.tv_usec; - srand (seed); - - /* test_qsort (20, 1000000, 100000); */ - - test_qset (atoi (argv [1])); - - exit (EXIT_SUCCESS); -} -# endif /* defined UNSINN */ - -/* - $Log$ - Revision 1.12 2006/06/06 12:06:27 beck - use xmalloc instead of malloc - - Revision 1.11 2005/06/22 09:34:11 beck - typo fixed - - Revision 1.10 2004/12/21 15:37:31 beck - added config.h include - removed unused sys/times.h - removed C99 constructs - - Revision 1.9 2004/12/20 17:34:35 liekweg - fix recursion handling - - Revision 1.8 2004/12/06 12:49:26 liekweg - virtually no change - - Revision 1.7 2004/11/30 14:47:11 liekweg - insert report changes - - Revision 1.6 2004/11/26 15:58:30 liekweg - don't free inside obstacks (thx, michael) - - Revision 1.5 2004/11/24 14:53:56 liekweg - Bugfixes - - Revision 1.4 2004/11/18 16:35:45 liekweg - Added unique ids for debugging - - Revision 1.3 2004/11/09 16:45:36 liekweg - print pointers - - Revision 1.2 2004/11/08 12:32:00 liekweg - Moved q_* methods into private section - - Revision 1.1 2004/11/04 14:55:13 liekweg - added qset - - - */ diff --git a/ir/ana2/qset.h b/ir/ana2/qset.h deleted file mode 100644 index 4627081d0..000000000 --- a/ir/ana2/qset.h +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief yet another set implementation - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -#ifndef FIRM_ANA2_QSET_H -#define FIRM_ANA2_QSET_H - -# ifndef TRUE -# define TRUE 1 -# define FALSE 0 -# endif /* nof defined TRUE */ - -/* define this as needed */ -# define COMPARE(A,B) (A -#include - -#include "timing.h" -#include "xmalloc.h" - -struct timing_env -{ - struct timeval *start; - struct timeval *end; -}; - -#ifdef _WIN32 -/* no support yet */ -timing_t *start_timing (void) {} -int end_timing (timing_t *t) {} - -#else -#include - - -/* -Helpers -*/ -static int -timeval_subtract (struct timeval *x, struct timeval *y) -{ - /* Perform the carry for the later subtraction by updating Y. */ - if (x->tv_usec < y->tv_usec) { - int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; - y->tv_usec -= 1000000 * nsec; - y->tv_sec += nsec; - } - - if (x->tv_usec - y->tv_usec > 1000000) { - int nsec = (x->tv_usec - y->tv_usec) / 1000000; - y->tv_usec += 1000000 * nsec; - y->tv_sec -= nsec; - } - - return ((x->tv_sec - y->tv_sec) * 1000000 + (x->tv_usec - y->tv_usec)); -} - - -/* - Public Interface -*/ -timing_t * -start_timing (void) -{ - timing_t *t = (timing_t*) xmalloc (sizeof (timing_t)); - - t->start = (struct timeval*) xmalloc (sizeof (struct timeval)); - t->end = (struct timeval*) xmalloc (sizeof (struct timeval)); - - gettimeofday (t->start, NULL); - - return (t); -} - -int -end_timing (timing_t *t) -{ - int time; - - gettimeofday (t->end, NULL); - - time = timeval_subtract (t->end, t->start); - - memset (t->start, 0x0, sizeof (struct timeval)); - free (t->start); - - memset (t->end, 0x0, sizeof (struct timeval)); - free (t->end); - - memset (t, 0x00, sizeof (timing_t)); - free (t); - - return (time); -} -#endif /* _WIN32 */ - - -/* - $Log$ - Revision 1.5 2006/09/12 12:17:37 matze - more warning fixes - - Revision 1.4 2006/06/06 12:06:27 beck - use xmalloc instead of malloc - - Revision 1.3 2005/01/05 14:25:38 beck - added Win32 "support" - - Revision 1.2 2004/12/21 15:52:23 beck - moved struct timing_env to .c file, added config.h - - Revision 1.1 2004/10/29 18:55:52 liekweg - (mostly) generic timimg -*/ diff --git a/ir/ana2/timing.h b/ir/ana2/timing.h deleted file mode 100644 index cf68bf89a..000000000 --- a/ir/ana2/timing.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief generic timing routines - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -#ifndef FIRM_ANA2_TIMING_H -#define FIRM_ANA2_TIMING_H - -/* - Data structures - */ -typedef struct timing_env timing_t; - -/* - Protos -*/ -timing_t *start_timing (void); -int end_timing (timing_t*); - -#endif - - -/* - $Log$ - Revision 1.2 2004/12/21 15:52:23 beck - moved struct timing_env to .c file, added config.h - - Revision 1.1 2004/10/29 18:55:52 liekweg - (mostly) generic timimg - - -*/ diff --git a/ir/ana2/typalise.c b/ir/ana2/typalise.c deleted file mode 100644 index bced3f0ed..000000000 --- a/ir/ana2/typalise.c +++ /dev/null @@ -1,937 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Pto - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -# ifdef HAVE_CONFIG_H -# include "config.h" -# endif - -# include "typalise.h" - -# ifndef TRUE -# define TRUE 1 -# define FALSE 0 -# endif /* not defined TRUE */ - -# include - -#ifdef HAVE_STRING_H -# include -#endif - -# include "irnode_t.h" -# include "irgwalk.h" -# include "xmalloc.h" -# include "gnu_ext.h" -# include "irdump.h" -# include "typewalk.h" - - -/* - Local Globals -*/ - -static long ta_id = 0; - -/* - Local Protos -*/ -static typalise_t *typalise_proj (ir_node*); - -/* DEBUGGING only */ -static void cough_and_die (ir_node *node) -{ - ir_graph *graph = get_irn_irg (node); - - fprintf (stdout, "%s: %s[%li]\n", - __FUNCTION__, - get_op_name (get_irn_op (node)), - get_irn_node_nr (node)); - dump_ir_block_graph (graph, "-typealise"); - assert (0); -} - -/* - Exception b/d -*/ -static ir_type *java_lang_Throwable_tp = NULL; - -static ir_type *get_java_lang_Throwable (void) -{ - assert (NULL != java_lang_Throwable_tp); - - return (java_lang_Throwable_tp); -} - -static void find_java_lang_Throwable (ir_type *tp, void *_unused) -{ - const char *name = get_type_name (tp); - - if (0 == strcmp (name, "java/lang/Throwable")) { - assert (NULL == java_lang_Throwable_tp); - - java_lang_Throwable_tp = tp; - } -} - - -/* - Ctors, Dtors for typalise_t-s -*/ -static typalise_t *ta_exact (ir_type *tp) -{ - typalise_t *ta = xmalloc (sizeof (typalise_t)); - ta->kind = type_exact; - ta->res.type = tp; - ta->id = ta_id ++; - - assert (is_Class_type (tp)); - - return (ta); -} - -static typalise_t *ta_types (lset_t *set) -{ - typalise_t *ta = xmalloc (sizeof (typalise_t)); - ta->kind = type_types; - ta->res.types = set; - ta->id = ta_id ++; - - return (ta); -} - -static typalise_t *ta_type (ir_type *tp) -{ - typalise_t *ta = xmalloc (sizeof (typalise_t)); - ta->kind = type_type; - ta->res.type = tp; - ta->id = ta_id ++; - - assert (is_Class_type (tp)); - - return (ta); -} - -static void ta_delete (typalise_t *ta) -{ - if (type_types == ta->kind) { - lset_destroy (ta->res.types); - ta->res.types = NULL; - } else { - ta->res.type = NULL; - } - - ta->kind = type_invalid; - - free (ta); -} - -/* - Helpers for inheritance, overwriting and stuff -*/ -/** - Find out whether otype is a subtype of stype. - Return non-zero iff otype is a subtype of stype. -*/ -static int is_subtype (ir_type *otype, ir_type *stype) -{ - int n_sub = get_class_n_subtypes (stype); - int is_sub = FALSE; - int i; - - if (otype == stype) { - return (TRUE); - } - - for (i = 0; (!is_sub) && (i < n_sub); i ++) { - ir_type *sub = get_class_subtype (stype, i); - - is_sub |= is_subtype (otype, sub); - } - - - return (is_sub); -} - - -/** - Compute the closure of all subtypes of otype (including otype - itself) -*/ -static void _collect_subtypes (ir_type *otype, lset_t *set) -{ - int i, n_sub; - - lset_insert (set, otype); - - n_sub = get_class_n_subtypes (otype); - for (i = 0; i < n_sub; i ++) { - ir_type *sub = get_class_subtype (otype, i); - - _collect_subtypes (sub, set); - } -} - -static lset_t *subtype_closure (ir_type *otype) -{ - lset_t *set = lset_create (); - - _collect_subtypes (otype, set); - - return (set); -} - -/** - Helper method for get_owner_types -*/ -static void _collect_owner_types (ir_entity *method, ir_graph *graph, lset_t *tps) -{ - int i, n_over; - - /* search DOWNwards in clazz hierarchy */ - - if ((peculiarity_description == get_entity_peculiarity (method)) || - (peculiarity_inherited == get_entity_peculiarity (method))) { - lset_insert (tps, get_entity_owner (method)); - } else if (peculiarity_existent == get_entity_peculiarity (method)) { - ir_graph *ex_graph = get_entity_irg (method); - - if ((NULL == ex_graph) || (ex_graph == graph)) { - /* wtf? they define the same graph again? well, whatever: */ - lset_insert (tps, get_entity_owner (method)); - } else { - /* aha: they define a new graph. can't have that, so bail out */ - return; - } - } - - n_over = get_entity_n_overwrittenby (method); - for (i = 0; i < n_over; i ++) { - ir_entity *ometh = get_entity_overwrittenby (method, i); - - _collect_owner_types (ometh, graph, tps); - } -} - - -/** - Collect all classes that use the given implementation of a method. -*/ -static lset_t *get_owner_types (ir_graph *graph) -{ - lset_t *tps = lset_create (); - ir_entity *meth = get_irg_entity (graph); - - _collect_owner_types (meth, graph, tps); - - return (tps); -} - -/** - Return a list containing all types of 'set' which are a subtype of 'type'. -*/ -static lset_t *filter_for_type (lset_t *set, ir_type *stype) -{ - ir_type *curs = (ir_type*) lset_first (set); - lset_t *lset = lset_create (); - - while (NULL != curs) { - if (is_subtype (curs, stype)) { - lset_insert (lset, curs); - } - - curs = lset_next (set); - } - - return (lset); -} - -/* - Handle typalise_t-s -*/ -/** - Join 'one' and 'two'; both args are deallocated, result is freshly - allocated. -*/ -static typalise_t *ta_join (typalise_t *one, typalise_t *two) -{ - typalise_t *res = NULL; - - /* now, one==NULL or two==NULL cannot happen legitimately (if we hit a NULL pointer constant) - if (NULL == one) { - return (two); - } - - if (NULL == two) { - return (one); - } - */ - switch (one->kind) { - case (type_invalid): { /* shut up, gcc */ } - case (type_exact): { - switch (two->kind) { - case (type_invalid): { /* shut up, gcc */ } - case (type_exact): { - if (one->res.type == two->res.type) { - res = one; - } else { - lset_t *set = lset_create (); - lset_insert (set, one->res.type); - lset_insert (set, two->res.type); - res = ta_types (set); - - ta_delete (one); - } - - ta_delete (two); - } break; - case (type_types): { - lset_insert (two->res.types, one->res.type); - ta_delete (one); - - res = two; - } break; - case (type_type): { - if (is_subtype (one->res.type, two->res.type)) { - ta_delete (one); - res = two; - } else { - lset_t *closure = subtype_closure (two->res.type); - lset_insert (closure, one->res.type); - - ta_delete (two); - - res = one; - } - } break; - } - } break; - case (type_types): { - switch (two->kind) { - case (type_invalid): { /* shut up, gcc */ } - case (type_exact): { - res = ta_join (two, one); - } break; - case (type_types): { - lset_insert_all (one->res.types, two->res.types); - ta_delete (two); - - res = one; - } break; - case (type_type): { - lset_t *closure = subtype_closure (two->res.type); - lset_append (one->res.types, closure); - - ta_delete (two); - - res = one; - } break; - } - } break; - case (type_type): { - switch (two->kind) { - case (type_invalid): { /* shut up, gcc */ } - case (type_exact): { - res = ta_join (two, one); - } break; - case (type_types): { - res = ta_join (two, one); - } break; - case (type_type): { - ir_type *one_type = one->res.type; - ir_type *two_type = two->res.type; - - if (is_subtype (one_type, two_type)) { - ta_delete (one); - res = two; - } else if (is_subtype (two_type, one_type)) { - ta_delete (two); - res = one; - } else { - lset_t *one_closure = subtype_closure (one->res.type); - lset_t *two_closure = subtype_closure (two->res.type); - - lset_append (one_closure, two_closure); - - ta_delete (two); - ta_delete (one); - - res = ta_types (one_closure); - } - } break; - } - } break; - } - - assert (res && "no result"); - - return (res); -} - - -# ifdef SHUT_UP_GCC -static const char *ta_name (typalise_t *ta) -{ -# define BUF_SIZE 1024 - static char buf [BUF_SIZE]; - - int len = sprintf (buf, "[%d] ", ta->id); - - switch (ta->kind) { - case (type_invalid): { /* shut up, gcc */ } - case (type_exact): { - len += sprintf (buf+len, "only "); - strncat (buf, get_type_name (ta->res.type), BUF_SIZE); - } break; - case (type_types): { - len += sprintf (buf+len, "one_of "); - - ir_type *iter = lset_first (ta->res.types); - - int size = BUF_SIZE - len - 1; - while ((NULL != iter) && (0 < size)) { - char *dest = strncat (buf, get_type_name (iter), size); - size = (dest - buf); - - iter = lset_next (ta->res.types); - } - } break; - case (type_type): { - len += sprintf (buf+len, "poly "); - strncat (buf, get_type_name (ta->res.type), BUF_SIZE); - } break; - } - - return (buf); - /* # undef BUF_SIZE */ -} -# endif /* SHUT_UP_GCC */ - -/** - Find out whether the given clazz uses the given implementation of a - method. Presumably, this is because clazz inherits the graph as - the implementation for a method. -*/ -static int uses_graph (ir_type *clazz, ir_entity *meth, ir_graph *graph) -{ - ir_type *g_clazz = get_entity_owner (meth); - int i, n_over, use = FALSE; - - if (g_clazz == clazz) { - return (TRUE); - } - - if (peculiarity_existent == get_entity_peculiarity (meth)) { - ir_graph *g_graph = get_entity_irg (meth); - - if (g_graph != graph) { - return (FALSE); - } - } - - /* else inherited or description */ - n_over = get_entity_n_overwrittenby (meth); /* DOWN-wards */ - for (i = 0; (i < n_over) && (!use); i ++) { - ir_entity *over = get_entity_overwrittenby (meth, i); - - use |= uses_graph (clazz, over, graph); - } - - return (use); -} - -/** - Check whether the given typalise_t includes the given type. -*/ -static int ta_supports (typalise_t *ta, ir_graph *graph) -{ - switch (ta->kind) { - case (type_invalid): { /* shut up, gcc */ } - case (type_exact): { - int res = FALSE; - lset_t *tps = get_owner_types (graph); - - if (lset_contains (tps, ta->res.type)) { - res = TRUE; - } - - lset_destroy (tps); - - return (res); - } - case (type_type): { - ir_entity *meth = get_irg_entity (graph); - ir_type *tp = get_entity_owner (meth); - int res = is_subtype (tp, ta->res.type); - - if (res) { - return (TRUE); - } else { - res = uses_graph (ta->res.type, meth, graph); - } - - return (res); - } - case (type_types): { - ir_type *tp = get_entity_owner (get_irg_entity (graph)); - - return (lset_contains (ta->res.types, tp)); - } - } - - assert (0 && "invalid ta"); - return FALSE; -} - - -/* =========== WHAT ELSE ? =========== */ - -/* - Helpers to typalise (ir_node*) -*/ -/** - Find an approximation to the given load node's value's types -*/ -static typalise_t *typalise_call (ir_node *call) -{ - ir_entity *ent = NULL; - ir_type *tp = NULL; - typalise_t *res = NULL; - ir_node *call_ptr = get_Call_ptr (call); - - if (iro_Sel == get_irn_opcode (call_ptr)) { - ent = get_Sel_entity (call_ptr); - } else if (iro_SymConst == get_irn_opcode (call_ptr)) { - if (get_SymConst_kind (call_ptr) == symconst_addr_ent) { - ent = get_SymConst_entity (call_ptr); - } else if (get_SymConst_kind (call_ptr) == symconst_addr_name) { - ident *id = get_SymConst_name (call_ptr); - const char *name = get_id_str (id); - if (0 == strcmp (name, "iro_Catch")) { - res = ta_type (java_lang_Throwable_tp); - - return (res); - } - - fprintf (stdout, "%s: cannot handle Call[%li] (symconst_addr_name=\"%s\")\n", - __FUNCTION__, get_irn_node_nr (call), - name); - cough_and_die (call_ptr); - } else if (get_SymConst_kind (call_ptr) == symconst_type_tag) { - fprintf (stdout, "%s: cannot handle Call[%li] (symconst_type_tag)\n", - __FUNCTION__, get_irn_node_nr (call)); - cough_and_die (call_ptr); - } else { - fprintf (stdout, "%s: cannot handle Call[%li] (%i)\n", - __FUNCTION__, get_irn_node_nr (call), - get_SymConst_kind (call_ptr)); - cough_and_die (call_ptr); - } - } - - tp = get_entity_type (ent); - assert (is_Method_type (tp)); - - tp = get_method_res_type (tp, 0); - - while (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - } - - res = ta_type (tp); - - return (res); -} - - -/** - Find an approximation to the given load node's value's types -*/ -static typalise_t *typalise_load (ir_node *load) -{ - ir_entity *ent = NULL; - ir_type *tp = NULL; - typalise_t *res = NULL; - ir_node *load_ptr = get_Load_ptr (load); - - if (iro_Sel == get_irn_opcode (load_ptr)) { - ent = get_Sel_entity (load_ptr); - } else if (iro_SymConst == get_irn_opcode (load_ptr)) { - if (get_SymConst_kind (load_ptr) == symconst_addr_ent) { - ent = get_SymConst_entity (load_ptr); - } else if (get_SymConst_kind (load_ptr) == symconst_type_tag) { - tp = get_SymConst_type (load_ptr); - } else { - fprintf (stdout, "%s: cannot handle load (%s)\n", - __FUNCTION__, get_op_name (get_irn_op (load_ptr))); - - cough_and_die (load_ptr); - } - } else { - fprintf (stdout, "%s: cannot handle load (%s)\n", - __FUNCTION__, get_op_name (get_irn_op (load_ptr))); - cough_and_die (load_ptr); - } - - tp = get_entity_type (ent); - - while (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - } - - res = ta_type (tp); - - return (res); -} - - -/** - Find an approximation to the given proj node's value's types -*/ -static typalise_t *typalise_proj (ir_node *proj) -{ - typalise_t *res = NULL; - ir_node *proj_in = get_Proj_pred (proj); - - if (iro_Proj == get_irn_opcode (proj_in)) { - /* fprintf (stdout, "\tProj (Proj)\n"); */ - - proj_in = get_Proj_pred (proj_in); - if (iro_Start == get_irn_opcode (proj_in)) { - /* aha, proj arg */ - ir_graph *graph = get_irn_irg (proj); - ir_entity *meth = get_irg_entity (graph); - - long n = get_Proj_proj (proj); - ir_type *tp = get_method_param_type (get_entity_type (meth), n); - if (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - } - - res = ta_type (tp); - - } else if (iro_Call == get_irn_opcode (proj_in)) { - /* call result ... 'whatever' */ - res = typalise_call (proj_in); - } else { - fprintf (stdout, "\n Proj (Proj (%s)) not handled\n", - get_op_name (get_irn_op (proj_in))); - cough_and_die (proj_in); - } - } else { - ir_opcode op = get_irn_opcode (proj_in); - if ((iro_Load != op) && (iro_Alloc != op) && (iro_Call != op)) { - fprintf (stdout, "\n Proj (%s) not handled\n", - get_op_name (get_irn_op (proj_in))); - cough_and_die (proj_in); - } - res = typalise (proj_in); /* everything else */ - /* Proj (Load), Proj (New), Proj (Call) */ - } - - return (res); -} - - - -/* - Public Interface -*/ -/** - Given a set of graphs and a typalise_t, return the method (s) in - the set that are supported by the typalise_t. Also, deallocates - the given set. -*/ -lset_t *filter_for_ta (lset_t *set, typalise_t *ta) -{ - lset_t *res = lset_create (); - ir_graph *curs = (ir_graph*) lset_first (set); - - while (NULL != curs) { - if (ta_supports (ta, curs)) { - lset_insert (res, curs); - } - - curs = lset_next (set); - } - - lset_destroy (set); - - return (res); -} - -/** - For the given ptr, do a quick check about what (class) types may be - brought along on it. -*/ -typalise_t *typalise (ir_node *node) -{ - ir_opcode op = get_irn_opcode (node); - typalise_t *res = NULL; - - switch (op) { - case (iro_Cast): { - /* casts always succeed */ - typalise_t *ta = NULL; - ir_type *tp = get_Cast_type (node); - - if (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - } - assert (is_Class_type (tp)); - - ta = typalise (get_Cast_op (node)); - - if (NULL == ta) { /* no type found */ - ta = ta_type (tp); - } else if (type_exact == ta->kind) { /* one type found */ - /* nothing (maybe check cast? */ - } else if (type_type == ta->kind) { /* some types found */ - if (is_subtype (tp, ta->res.type)) { - ta->res.type = tp; /* assume cast is correct */ - } else { - /* should assert (is_subtype (ta->res.type, tp)) */ - } - } else if (type_types == ta->kind) { - lset_t *ftp = filter_for_type (ta->res.types, tp); - lset_destroy (ta->res.types); - ta->res.types = ftp; - } - - res = ta; - } break; - - case (iro_Proj): { - res = typalise_proj (node); - } break; - - case (iro_Load): { - res = typalise_load (node); - } break; - - case (iro_Sel): { - /* FILTER */ - /* it's call (sel (ptr)) or load (sel (ptr)) */ - ir_entity *ent = get_Sel_entity (node); - ir_type *tp = get_entity_type (ent); - - if (is_Method_type (tp)) { - /* obsoleted by typalise_call */ - assert (0); - tp = get_entity_type (ent); - tp = get_method_res_type (tp, 0); - - if (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - } - - res = ta_type (tp); - } else if (is_Class_type (tp)) { - tp = get_entity_type (ent); - - if (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - } - - res = ta_type (tp); - } else if (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - res = ta_type (tp); - } else { - assert (0 && "select not handled"); - } - } break; - - case (iro_Phi): { - int n_ins = get_irn_arity (node); - int i; - ir_node *phi_in = NULL; - typalise_t *ta = NULL; - - for (i = 0; i < n_ins; i ++) { - typalise_t *ta_in; - - phi_in = get_irn_n (node, i); - ta_in = typalise (phi_in); - - if (NULL != ta_in) { - ta = (NULL == ta) ? ta_in : ta_join (ta, ta_in); - } - } - - res = ta; - } break; - - case (iro_Alloc): { - ir_type *type = get_Alloc_type (node); - res = ta_exact (type); - } break; - - case (iro_Call): { - /* presumably call (sel (proj (call))) */ - ir_node *ptr = get_Call_ptr (node); - ir_entity *meth = NULL; - if (iro_Sel == get_irn_opcode (ptr)) { - meth = get_Sel_entity (ptr); - } else if (iro_SymConst == get_irn_opcode (ptr)) { - if (get_SymConst_kind (ptr) == symconst_addr_ent) { - meth = get_SymConst_entity (ptr); - } else { - meth = NULL; /* WTF? */ - } - } - - if (NULL != meth) { - ir_type *tp = get_method_res_type ((ir_type*) meth, 0); - res = ta_type (tp); - } else { - /* could be anything */ - /* fprintf (stdout, "meth= (null)"); */ - res = NULL; - } - - /* fprintf (stdout, "]\n"); */ - - } break; - - case (iro_SymConst): { - if (get_SymConst_kind (node) == symconst_type_tag) { - ir_type *tp = get_SymConst_type (node); - - res = ta_type (tp); - } else if (get_SymConst_kind (node) == symconst_addr_ent) { - ir_entity *ent = get_SymConst_entity (node); - ir_type *tp = get_entity_owner (ent); - - while (is_Pointer_type (tp)) { - tp = get_pointer_points_to_type (tp); - } - - assert (is_Class_type (tp)); - - res = ta_type (tp); /* can't use ta_exact */ - } else if (get_SymConst_kind (node) == symconst_addr_name) { - /* oh, this is not a real call but a placeholder (exception stuff) */ - fprintf (stdout, "%s (%s:%i): can't handle pseudo-call %s\n", - __FUNCTION__, __FILE__, __LINE__, - get_op_name (get_irn_op (node))); - - res = NULL; - } else { - fprintf (stdout, "%s (%s:%i): can't handle SymConst %s\n", - __FUNCTION__, __FILE__, __LINE__, - get_op_name (get_irn_op (node))); - - res = NULL; - } - } break; - case (iro_Const): { - /* presumably a NULL constant */ - /* this also means we cannot handle calls against a NULL pointer. */ - res = NULL; - } break; - - /* template: - case (iro_Cast): {} - break; - */ - - default: { - fprintf (stdout, "what's with %s?\n", get_op_name (get_irn_op (node))); - cough_and_die (node); - } break; - } - - return (res); -} - -/* - Initialise the Typalise module -*/ -void typalise_init (void) -{ - if (NULL == java_lang_Throwable_tp) { - class_walk_super2sub (find_java_lang_Throwable, NULL, NULL); - - /* make sure we have found it */ - get_java_lang_Throwable (); - } -} - - - - -/* - $Log$ - Revision 1.14 2007/01/16 15:45:42 beck - renamed type opcode to ir_opcode - - Revision 1.13 2006/12/13 19:46:47 beck - rename type entity into ir_entity - - Revision 1.12 2006/01/13 21:54:02 beck - renamed all types 'type' to 'ir_type' - - Revision 1.11 2005/05/13 16:35:14 beck - made (void) prototypes - removed unused fprintf arguments - - Revision 1.10 2005/05/06 12:02:34 beck - added missing includes - removed C99 features - - Revision 1.9 2005/03/22 13:56:09 liekweg - "small" fix for exception b/d - - Revision 1.8 2005/01/14 14:13:24 liekweg - fix gnu extension - - Revision 1.7 2005/01/10 17:26:34 liekweg - fixup printfs, don't put environments on the stack - - Revision 1.6 2005/01/05 14:25:54 beck - renames all is_x*_type() functions to is_X*_type() to prevent name clash with EDG fronten - - Revision 1.5 2004/12/22 14:43:14 beck - made allocations C-like - - Revision 1.4 2004/12/21 15:50:18 beck - removed C99 constructs - - Revision 1.3 2004/12/02 16:17:51 beck - fixed config.h include - - Revision 1.2 2004/10/22 09:53:10 liekweg - Correctly handle proj_args - - Revision 1.1 2004/10/21 11:09:37 liekweg - Moved memwalk stuf into irmemwalk - Moved lset stuff into lset - Moved typalise stuff into typalise - - - */ diff --git a/ir/ana2/typalise.h b/ir/ana2/typalise.h deleted file mode 100644 index 4d895b2c9..000000000 --- a/ir/ana2/typalise.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- c -*- */ - -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Compute rough approximations of pointer types - * @author Florian - * @date Mon 18 Oct 2004 - * @version $Id$ - */ -# ifndef FIRM_ANA2_TYPALISE_H -# define FIRM_ANA2_TYPALISE_H - -# include "lset.h" - -# include "type.h" -# include "irnode.h" - -/* - Data Types and Structures -*/ -typedef enum typalise_kind_enum { - type_invalid = 0, /* invalid (only set at deletion time) */ - type_exact = 1, /* this and only this type (res.type) */ - type_types = 2, /* these types (res.types) */ - type_type = 3 /* this type and sub types (res.type) */ -} typalise_kind; - -typedef struct typalise -{ - typalise_kind kind; - union { - ir_type *type; /* for kind == kind_exact and kind == kind_type */ - lset_t *types; /* for kind == kind_types */ - } res; - int id; -} typalise_t; - -/* - Protos -*/ -/** - Given a set of graphs and a typalise_t, return the method (s) in - the set that are supported by the typalise_t. Also, deallocates - the given set. -*/ -lset_t *filter_for_ta (lset_t*, typalise_t*); - -/** - For the given ptr, do a quick check about what (class) types may be - brought along on it. -*/ -typalise_t *typalise (ir_node*); - -/* - Initialise the Typalise module -*/ -void typalise_init (void); - -# endif - - -/* - $Log$ - Revision 1.4 2006/01/13 21:54:03 beck - renamed all types 'type' to 'ir_type' - - Revision 1.3 2005/03/22 13:56:09 liekweg - "small" fix for exception b/d - - Revision 1.2 2004/10/21 11:11:21 liekweg - whitespace fix - - Revision 1.1 2004/10/21 11:09:37 liekweg - Moved memwalk stuf into irmemwalk - Moved lset stuff into lset - Moved typalise stuff into typalise - - - */ diff --git a/ir/arch/modeconv.c b/ir/arch/modeconv.c deleted file mode 100644 index b2fc2b8d4..000000000 --- a/ir/arch/modeconv.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief integer mode conversion - * @author Michael Beck - * @version $Id$ - * @summary - * Contains the mode conversion for architectures that did not support lesser - * integer modes. Converts all Op(mode_l) into Op(mode) operations by adding - * conversions were needed. These Conv operations must be implemented in the - * backend as bit-reducing ops. - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -# include "irnode_t.h" -# include "irgraph_t.h" -# include "irmode_t.h" -# include "iropt_t.h" -# include "ircons_t.h" -# include "irgmod.h" -# include "dbginfo.h" -# include "iropt_dbg.h" -# include "irflag_t.h" -# include "irgwalk.h" -# include "modeconv.h" -# include "firmstat.h" - -typedef struct _walker_t { - int bits; /**< number of bits in the destination mode */ - ir_mode *s_mode; /**< signed destination mode */ - ir_mode *u_mode; /**< unsigned destination mode */ - int changes; /**< non-zero if the graph was changed */ -} walker_t; - -/** - * Add a Conv node where needed on output - */ -static ir_node *fix_irn_output(ir_node *node, ir_mode *mode) -{ - switch (get_irn_opcode(node)) { - case iro_Proj: - /* Args, Load, Div, Mod */ - case iro_Conv: - /* Hmm, maybe the Conv should be replaced */ - case iro_Rot: { - ir_node *block = get_nodes_block(node); - - if (get_irn_mode(node) != mode) - return new_r_Conv(current_ir_graph, block, node, mode); - else - return node; - } - default: - return node; - } -} - -/** - * Add a Conv node where needed on input - */ -static ir_node *fix_irn_input(ir_opcode code, ir_node *block, ir_node *pred, ir_mode *mode) -{ - switch (code) { - case iro_DivMod: - case iro_Div: - case iro_Mod: - case iro_Shr: - case iro_Shrs: - case iro_Rot: - case iro_Call: - case iro_Return: { - ir_mode *p_mode = get_irn_mode(pred); - - if (p_mode != mode && mode_is_int(p_mode)) - return new_r_Conv(current_ir_graph, block, pred, mode); - return pred; - } - default: - return pred; - } -} - -/** - * fix the mode of the operations if possible - */ -static void fix_mode(ir_node *n, ir_mode *mode) -{ - ir_opcode code = get_irn_opcode(n); - - if (code == iro_Proj) { - code = get_irn_opcode(get_Proj_pred(n)); - } - - switch (code) { - case iro_Return: - case iro_Load: - case iro_Proj: - case iro_Call: - case iro_Conv: - return; - default: - set_irn_mode(n, mode); - } -} - -/** - * walker for the mode conversion - */ -static void do_mode_conv(ir_node *n, void *env) -{ - walker_t *wenv = env; - ir_mode *mode = get_irn_mode(n); - ir_node *block; - ir_opcode code; - - /* save the old mode, we need this info later */ - set_irn_link(n, mode); - - /* special case: fix the Return */ - if (is_Return(n)) { - ir_entity *ent = get_irg_entity(current_ir_graph); - ir_type *mt = get_entity_type(ent); - int i, n_ress = get_method_n_ress(mt); - - mode = mode_is_signed(mode) ? wenv->s_mode : wenv->u_mode; - block = get_nodes_block(n); - for (i = 0; i < n_ress; ++i) { - ir_node *pred = get_irn_n(n, i + 1); - ir_type *rt = get_method_res_type(mt, i); - - if (is_atomic_type(rt)) { - mode = get_type_mode(rt); - - if (mode != get_irn_mode(pred)) { - pred = fix_irn_input(iro_Return, block, pred, mode); - - set_irn_n(n, i + 1, pred); - } - } - } - - return; - } - - /* convert only integer modes with less than 'bits' bits */ - if (mode_is_int(mode) && get_mode_size_bits(mode) < wenv->bits && get_irn_op(n) != op_Conv) { - mode = mode_is_signed(mode) ? wenv->s_mode : wenv->u_mode; - - code = get_irn_opcode(n); - - if (code == iro_Conv) { - /* formally, the was a convert from modeA to modeB here. - * So, the expression before the conv must have modeA. */ - ir_node *pred = get_Conv_op(n); - ir_mode *modeA = get_irn_link(pred); - - if (modeA != get_irn_mode(pred)) { - pred = new_r_Conv(current_ir_graph, get_nodes_block(pred), pred, modeA); - set_Conv_op(n, pred); - } - } - else if (code == iro_Proj) { - /* special case for Proj: we must fix it's pred */ - ir_node *oper = get_Proj_pred(n); - int i, arity = get_irn_arity(oper); - - code = get_irn_opcode(oper); - block = get_nodes_block(oper); - - for (i = 0; i < arity; ++i) { - ir_node *pred = get_irn_n(oper, i); - - pred = fix_irn_input(code, block, pred, mode); - - set_irn_n(oper, i, pred); - } - - } - else { - int i, arity = get_irn_arity(n); - - block = get_nodes_block(n); - for (i = 0; i < arity; ++i) { - ir_node *pred = get_irn_n(n, i); - - pred = fix_irn_output(pred, mode); - pred = fix_irn_input(code, block, pred, mode); - - set_irn_n(n, i, pred); - } - } - - fix_mode(n, mode); - wenv->changes = 1; - } - - if (get_irn_op(n) == op_Conv) { - /* formally, the was a convert from modeA to modeB here. - * So, the expression before the conv must have modeA. */ - ir_node *pred = get_Conv_op(n); - ir_mode *modeA = get_irn_link(pred); - - if (modeA != get_irn_mode(pred)) { - pred = new_r_Conv(current_ir_graph, get_nodes_block(pred), pred, modeA); - set_Conv_op(n, pred); - } - - /* old conv may now get useless */ - if (get_irn_mode(n) == get_irn_mode(pred)) { - exchange(n, get_Conv_op(n)); - wenv->changes = 1; - } - } -} - -/* - * do the integer mode conversion - */ -void arch_mode_conversion(ir_graph *irg, ir_mode *mode) -{ - walker_t env; - - assert(get_irg_phase_state(irg) != phase_building); - - assert(mode_is_int(mode)); - - env.s_mode = mode_is_signed(mode) ? mode: find_signed_mode(mode) ; - env.u_mode = mode_is_signed(mode) ? find_unsigned_mode(mode) : mode; - env.bits = get_mode_size_bits(mode); - env.changes = 0; - - assert(env.s_mode && env.u_mode && "Could not find modes"); - - irg_walk_graph(irg, NULL, do_mode_conv, &env); - - /* Handle graph state. We never change control flow. */ - if (env.changes) { - set_irg_outs_inconsistent(current_ir_graph); - } -} diff --git a/ir/arch/modeconv.h b/ir/arch/modeconv.h deleted file mode 100644 index 6a4dc65f1..000000000 --- a/ir/arch/modeconv.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief integer mode conversion - * @author Michael Beck - * @version $Id$ - * @summary - * Contains the mode conversion for architectures that did not support lesser - * integer modes. Converts all Op(mode_l) into Op(mode) operations by adding - * conversions were needed. These Conv operations must be implemented in the - * backend as bit-reducing ops. - */ -#ifndef FIRM_ARCH_MODECONV_H -#define FIRM_ARCH_MODECONV_H - -#include "irgraph.h" - -/** Mode conversion.. - * - * Converts all operations with a integer mode lesser than mode into - * operations of type mode. Adds Conv() operations only were strictly - * needed. - */ -void arch_mode_conversion(ir_graph *irg, ir_mode *mode); - -#endif diff --git a/ir/be/TEMPLATE/TEMPLATE_transform.c b/ir/be/TEMPLATE/TEMPLATE_transform.c index f502b8f8e..3dcb6412b 100644 --- a/ir/be/TEMPLATE/TEMPLATE_transform.c +++ b/ir/be/TEMPLATE/TEMPLATE_transform.c @@ -41,7 +41,7 @@ #include "bearch_TEMPLATE_t.h" #include "TEMPLATE_nodes_attr.h" -#include "../arch/archop.h" /* we need this for Min and Max nodes */ +#include "archop.h" #include "TEMPLATE_transform.h" #include "TEMPLATE_new_nodes.h" #include "TEMPLATE_map_regs.h" diff --git a/ir/be/TEMPLATE/bearch_TEMPLATE.c b/ir/be/TEMPLATE/bearch_TEMPLATE.c index 60b3a2755..008e0963a 100644 --- a/ir/be/TEMPLATE/bearch_TEMPLATE.c +++ b/ir/be/TEMPLATE/bearch_TEMPLATE.c @@ -40,7 +40,7 @@ #include "../benode_t.h" #include "../belower.h" #include "../besched_t.h" -#include "../be.h" +#include "be.h" #include "../beabi.h" #include "../bemodule.h" #include "../begnuas.h" @@ -604,11 +604,14 @@ static const backend_params *TEMPLATE_get_libfirm_params(void) { 0, /* no Mulh */ }; static backend_params p = { + 0, /* no dword lowering */ + 0, /* no inline assembly */ NULL, /* no additional opcodes */ NULL, /* will be set later */ - 0, /* no dword lowering */ NULL, /* no creator function */ NULL, /* context for create_intrinsic_fkt */ + NULL, + NULL, }; p.dep_param = &ad; diff --git a/ir/be/TEMPLATE/bearch_TEMPLATE_t.h b/ir/be/TEMPLATE/bearch_TEMPLATE_t.h index bc790c650..411b8eb11 100644 --- a/ir/be/TEMPLATE/bearch_TEMPLATE_t.h +++ b/ir/be/TEMPLATE/bearch_TEMPLATE_t.h @@ -28,7 +28,7 @@ #include "debug.h" #include "bearch_TEMPLATE.h" #include "TEMPLATE_nodes_attr.h" -#include "../be.h" +#include "be.h" #include "../beemitter.h" #include "set.h" diff --git a/ir/be/arm/arm_nodes_attr.h b/ir/be/arm/arm_nodes_attr.h index 6c6ef9dd4..d1c3814b5 100644 --- a/ir/be/arm/arm_nodes_attr.h +++ b/ir/be/arm/arm_nodes_attr.h @@ -27,7 +27,7 @@ #define FIRM_BE_ARM_ARM_NODES_ATTR_H #include "../bearch_t.h" -#include "../../common/firm_types.h" +#include "firm_types.h" /** * Possible ARM register shift types. diff --git a/ir/be/arm/arm_transform.c b/ir/be/arm/arm_transform.c index 8adbcd6c8..cd31b58d0 100644 --- a/ir/be/arm/arm_transform.c +++ b/ir/be/arm/arm_transform.c @@ -44,7 +44,7 @@ #include "bearch_arm_t.h" #include "arm_nodes_attr.h" -#include "../arch/archop.h" /* we need this for Min and Max nodes */ +#include "archop.h" #include "arm_transform.h" #include "arm_new_nodes.h" #include "arm_map_regs.h" diff --git a/ir/be/arm/bearch_arm.c b/ir/be/arm/bearch_arm.c index 014ace005..0a6dff9b2 100644 --- a/ir/be/arm/bearch_arm.c +++ b/ir/be/arm/bearch_arm.c @@ -45,7 +45,7 @@ #include "../benode_t.h" #include "../belower.h" #include "../besched_t.h" -#include "../be.h" +#include "be.h" #include "../beabi.h" #include "../bemachine.h" #include "../beilpsched.h" diff --git a/ir/be/arm/bearch_arm_t.h b/ir/be/arm/bearch_arm_t.h index 0fd4bc27b..0a3e73c11 100644 --- a/ir/be/arm/bearch_arm_t.h +++ b/ir/be/arm/bearch_arm_t.h @@ -31,7 +31,7 @@ #include "debug.h" #include "bearch_arm.h" #include "arm_nodes_attr.h" -#include "../be.h" +#include "be.h" #include "../beemitter.h" #include "set.h" diff --git a/ir/be/beabi.c b/ir/be/beabi.c index db74e0caa..b552a2b75 100644 --- a/ir/be/beabi.c +++ b/ir/be/beabi.c @@ -30,7 +30,6 @@ #include "obst.h" #include "offset.h" -#include "type.h" #include "irgopt.h" #include "irgraph_t.h" diff --git a/ir/be/bearch.c b/ir/be/bearch.c index 0d12a82fd..e9561dd88 100644 --- a/ir/be/bearch.c +++ b/ir/be/bearch.c @@ -36,7 +36,6 @@ #include "bitset.h" #include "pset.h" -#include "entity.h" #include "raw_bitset.h" #include "irprintf.h" diff --git a/ir/be/begnuas.c b/ir/be/begnuas.c index 501499b83..c3798b6b3 100644 --- a/ir/be/begnuas.c +++ b/ir/be/begnuas.c @@ -38,7 +38,6 @@ #include "obst.h" #include "tv.h" #include "irnode.h" -#include "entity.h" #include "irprog.h" #include "pdeq.h" #include "error.h" diff --git a/ir/be/bemain.c b/ir/be/bemain.c index 7a03245ec..20d86fc8b 100644 --- a/ir/be/bemain.c +++ b/ir/be/bemain.c @@ -49,9 +49,7 @@ #include "irtools.h" #include "irvrfy.h" #include "irprintf.h" -#include "return.h" #include "firmstat.h" -#include "cfopt.h" #include "execfreq.h" #include "bearch_t.h" diff --git a/ir/be/benode_t.h b/ir/be/benode_t.h index fc119994b..ff0af86c8 100644 --- a/ir/be/benode_t.h +++ b/ir/be/benode_t.h @@ -32,11 +32,8 @@ #include -#include "irmode.h" +#include "firm_types.h" #include "irnode.h" -#include "irgraph.h" -#include "entity.h" - #include "bearch.h" #define BE_OUT_POS(p) (-((p) + 1)) diff --git a/ir/be/beprofile.c b/ir/be/beprofile.c index 2e76a50fa..82da02572 100644 --- a/ir/be/beprofile.c +++ b/ir/be/beprofile.c @@ -37,7 +37,6 @@ #include "list.h" #include "pmap.h" -#include "entity.h" #include "irprintf.h" #include "irgwalk.h" #include "irdump_t.h" @@ -47,7 +46,7 @@ #include "iredges.h" #include "execfreq.h" #include "irvrfy.h" -#include "type.h" +#include "typerep.h" #include "be_t.h" #include "belive_t.h" diff --git a/ir/be/bespillslots.c b/ir/be/bespillslots.c index e06fa9180..0ad3ce178 100644 --- a/ir/be/bespillslots.c +++ b/ir/be/bespillslots.c @@ -37,7 +37,6 @@ #include "irprintf.h" #include "execfreq.h" #include "unionfind.h" -#include "type.h" #include "irdump_t.h" #include "benode_t.h" diff --git a/ir/be/bestabs.c b/ir/be/bestabs.c index 4443eeb39..1d27373ac 100644 --- a/ir/be/bestabs.c +++ b/ir/be/bestabs.c @@ -34,9 +34,7 @@ #include "obst.h" #include "irprog.h" -#include "entity.h" #include "irgraph.h" -#include "typewalk.h" #include "tv.h" #include "xmalloc.h" #include "pmap.h" diff --git a/ir/be/beverify.c b/ir/be/beverify.c index f9b825fb1..3f533c3e6 100644 --- a/ir/be/beverify.c +++ b/ir/be/beverify.c @@ -389,18 +389,21 @@ static ir_node *get_memory_edge(const ir_node *node) { return result; } -static void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent); +static +void collect(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent); -static void check_entity(be_verify_spillslots_env_t *env, ir_node *node, ir_entity *ent) { +static +void be_check_entity(be_verify_spillslots_env_t *env, ir_node *node, ir_entity *ent) { if(ent == NULL) { ir_fprintf(stderr, "Verify warning: Node %+F in block %+F(%s) should have an entity assigned\n", node, get_nodes_block(node), get_irg_dump_name(env->irg)); } } -static void collect_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent) { +static +void collect_spill(be_verify_spillslots_env_t *env, ir_node *node, ir_node *reload, ir_entity* ent) { ir_entity *spillent = arch_get_frame_entity(env->arch_env, node); - check_entity(env, node, spillent); + be_check_entity(env, node, spillent); get_spill(env, node, ent); if(spillent != ent) { @@ -424,7 +427,7 @@ static void collect_memperm(be_verify_spillslots_env_t *env, ir_node *node, ir_n out = get_Proj_proj(node); spillent = be_get_MemPerm_out_entity(memperm, out); - check_entity(env, memperm, spillent); + be_check_entity(env, memperm, spillent); if(spillent != ent) { ir_fprintf(stderr, "Verify warning: MemPerm %+F has different entity than reload %+F in block %+F(%s)\n", node, reload, get_nodes_block(node), get_irg_dump_name(env->irg)); @@ -511,7 +514,7 @@ static void collect_spills_walker(ir_node *node, void *data) { return; } ent = arch_get_frame_entity(env->arch_env, node); - check_entity(env, node, ent); + be_check_entity(env, node, ent); collect(env, spill, node, ent); ARR_APP1(ir_node*, env->reloads, node); @@ -556,7 +559,7 @@ static void check_lonely_spills(ir_node *node, void *data) { spill_t *spill = find_spill(env, node); if(be_is_Spill(node)) { ir_entity *ent = arch_get_frame_entity(env->arch_env, node); - check_entity(env, node, ent); + be_check_entity(env, node, ent); } if(spill == NULL) { diff --git a/ir/be/firm/bearch_firm.c b/ir/be/firm/bearch_firm.c index 6981c8481..45e97d7fe 100644 --- a/ir/be/firm/bearch_firm.c +++ b/ir/be/firm/bearch_firm.c @@ -36,7 +36,6 @@ #include "irgmod.h" #include "ircons_t.h" #include "irgwalk.h" -#include "type.h" #include "irtools.h" #include "../be_t.h" diff --git a/ir/be/ia32/bearch_ia32.c b/ir/be/ia32/bearch_ia32.c index 738658cd2..f683bba62 100644 --- a/ir/be/ia32/bearch_ia32.c +++ b/ir/be/ia32/bearch_ia32.c @@ -53,7 +53,7 @@ #include "../benode_t.h" #include "../belower.h" #include "../besched_t.h" -#include "../be.h" +#include "be.h" #include "../be_t.h" #include "../beirgmod.h" #include "../be_dbgout.h" diff --git a/ir/be/ia32/bearch_ia32_t.h b/ir/be/ia32/bearch_ia32_t.h index 7706517ed..549add39d 100644 --- a/ir/be/ia32/bearch_ia32_t.h +++ b/ir/be/ia32/bearch_ia32_t.h @@ -34,7 +34,7 @@ #include "set.h" #include "pdeq.h" -#include "../be.h" +#include "be.h" #include "../bemachine.h" #include "../beemitter.h" diff --git a/ir/be/ia32/ia32_intrinsics.c b/ir/be/ia32/ia32_intrinsics.c index dbce3f543..551c5bc61 100644 --- a/ir/be/ia32/ia32_intrinsics.c +++ b/ir/be/ia32/ia32_intrinsics.c @@ -35,7 +35,6 @@ #include "irprog_t.h" #include "lower_intrinsics.h" #include "lower_dw.h" -#include "mangle.h" #include "array.h" #include "ia32_new_nodes.h" diff --git a/ir/be/ia32/ia32_transform.c b/ir/be/ia32/ia32_transform.c index 9f5b820f6..0d00a3c0c 100644 --- a/ir/be/ia32/ia32_transform.c +++ b/ir/be/ia32/ia32_transform.c @@ -45,8 +45,6 @@ #include "irprintf.h" #include "debug.h" #include "irdom.h" -#include "type.h" -#include "entity.h" #include "archop.h" /* we need this for Min and Max nodes */ #include "error.h" #include "cgana.h" diff --git a/ir/be/mips/bearch_mips.c b/ir/be/mips/bearch_mips.c index 2f753460a..d09c1294a 100644 --- a/ir/be/mips/bearch_mips.c +++ b/ir/be/mips/bearch_mips.c @@ -47,7 +47,7 @@ #include "../benode_t.h" #include "../belower.h" #include "../besched_t.h" -#include "../be.h" +#include "be.h" #include "../beabi.h" #include "../bemachine.h" #include "../bemodule.h" diff --git a/ir/be/mips/bearch_mips_t.h b/ir/be/mips/bearch_mips_t.h index 8f2469d10..edf83f7c5 100644 --- a/ir/be/mips/bearch_mips_t.h +++ b/ir/be/mips/bearch_mips_t.h @@ -30,7 +30,7 @@ #include "irgopt.h" #include "bearch_mips.h" #include "mips_nodes_attr.h" -#include "../be.h" +#include "be.h" #include "../beemitter.h" #include "set.h" diff --git a/ir/be/mips/mips_scheduler.c b/ir/be/mips/mips_scheduler.c index c8f3ffb8a..bd8145725 100644 --- a/ir/be/mips/mips_scheduler.c +++ b/ir/be/mips/mips_scheduler.c @@ -34,7 +34,7 @@ #include "mips_scheduler.h" #include "../besched_t.h" -#include "../be.h" +#include "be.h" #include "../beabi.h" #include "iredges.h" #include "ircons.h" diff --git a/ir/be/mips/mips_transform.c b/ir/be/mips/mips_transform.c index 58ec79850..e4412e1d7 100644 --- a/ir/be/mips/mips_transform.c +++ b/ir/be/mips/mips_transform.c @@ -49,7 +49,7 @@ #include "bearch_mips_t.h" #include "mips_nodes_attr.h" -#include "../arch/archop.h" /* we need this for Min and Max nodes */ +#include "archop.h" #include "mips_transform.h" #include "mips_new_nodes.h" #include "mips_map_regs.h" diff --git a/ir/be/ppc32/bearch_ppc32.c b/ir/be/ppc32/bearch_ppc32.c index 26b76068e..003974274 100644 --- a/ir/be/ppc32/bearch_ppc32.c +++ b/ir/be/ppc32/bearch_ppc32.c @@ -42,7 +42,7 @@ #include "../benode_t.h" #include "../belower.h" #include "../besched_t.h" -#include "../be.h" +#include "be.h" #include "../beabi.h" #include "../bemachine.h" #include "../bemodule.h" diff --git a/ir/be/ppc32/bearch_ppc32_t.h b/ir/be/ppc32/bearch_ppc32_t.h index e4c596118..6211511dc 100644 --- a/ir/be/ppc32/bearch_ppc32_t.h +++ b/ir/be/ppc32/bearch_ppc32_t.h @@ -29,7 +29,7 @@ #include "debug.h" #include "bearch_ppc32.h" #include "ppc32_nodes_attr.h" -#include "../be.h" +#include "be.h" #include "../beemitter.h" #include "pset.h" #include "set.h" diff --git a/ir/be/ppc32/ppc32_transform.c b/ir/be/ppc32/ppc32_transform.c index a0437e5fc..84cf1bd02 100644 --- a/ir/be/ppc32/ppc32_transform.c +++ b/ir/be/ppc32/ppc32_transform.c @@ -44,7 +44,7 @@ #include "bearch_ppc32_t.h" #include "ppc32_nodes_attr.h" -#include "../arch/archop.h" /* we need this for Min and Max nodes */ +#include "archop.h" #include "ppc32_transform.h" #include "ppc32_new_nodes.h" #include "ppc32_map_regs.h" diff --git a/ir/common/firm.c b/ir/common/firm.c index dec743c86..d42fc6faf 100644 --- a/ir/common/firm.c +++ b/ir/common/firm.c @@ -41,7 +41,6 @@ #include "ident_t.h" #include "firm.h" #include "irflag_t.h" -#include "mangle.h" /* init functions are not public */ #include "tv_t.h" #include "tpop_t.h" @@ -52,9 +51,7 @@ #include "irgraph_t.h" #include "type_t.h" #include "entity_t.h" -#include "type_identify.h" #include "firmstat.h" -#include "irreflect_t.h" #include "irarch.h" #include "reassoc_t.h" #include "irhooks.h" @@ -133,8 +130,6 @@ void init_firm(const firm_parameter_t *param) firm_init_entity(); /* allocate a hash table. */ init_type_identify(def_params.ti_if); - /* Init reflection facility. */ - firm_init_rflct(); /* Init architecture dependent optimizations. */ arch_dep_init(arch_dep_default_factory); diff --git a/ir/common/firmwalk.c b/ir/common/firmwalk.c index b634bd714..fe38a3010 100644 --- a/ir/common/firmwalk.c +++ b/ir/common/firmwalk.c @@ -38,7 +38,6 @@ #include "irnode_t.h" #include "irprog_t.h" #include "irgwalk.h" -#include "typewalk.h" #include "irtools.h" #include "array.h" diff --git a/ir/debug/debugger.c b/ir/debug/debugger.c index e6e002796..d59edc8bf 100644 --- a/ir/debug/debugger.c +++ b/ir/debug/debugger.c @@ -59,7 +59,6 @@ #include "irgraph_t.h" #include "entity_t.h" #include "irprintf.h" -#include "typewalk.h" #include "irdump.h" #include "debug.h" @@ -190,7 +189,7 @@ do { \ #define FIRM_DBG_MINOR 0 /** for automatic detection of the debug extension */ -static const char *firm_debug_info_string = +static const char firm_debug_info_string[] = API_VERSION(FIRM_DBG_MAJOR, FIRM_DBG_MINOR); /** diff --git a/ir/external/read.c b/ir/external/read.c index fac1e87b3..4066827fe 100644 --- a/ir/external/read.c +++ b/ir/external/read.c @@ -28,13 +28,8 @@ # include "config.h" #endif -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STRING_H -# include -#endif - +#include +#include #include #include @@ -50,7 +45,7 @@ #include "irmode.h" #include "irdump.h" #include "irvrfy.h" -#include "type.h" +#include "typerep.h" #include "tv.h" #include "xmalloc.h" diff --git a/ir/tr/mangle.c b/ir/ident/mangle.c similarity index 98% rename from ir/tr/mangle.c rename to ir/ident/mangle.c index 5446f5799..5df623357 100644 --- a/ir/tr/mangle.c +++ b/ir/ident/mangle.c @@ -27,11 +27,9 @@ # include "config.h" #endif -#ifdef HAVE_STDIO_H # include -#endif -#include "mangle.h" +#include "ident.h" #include "obst.h" /* Make types visible to allow most efficient access */ diff --git a/ir/ir/irarch.c b/ir/ir/irarch.c index d7d5a3514..d427f984c 100644 --- a/ir/ir/irarch.c +++ b/ir/ir/irarch.c @@ -48,7 +48,6 @@ #include "irhooks.h" #include "ircons.h" #include "irarch.h" -#include "irreflect.h" #undef DEB @@ -98,19 +97,10 @@ void arch_dep_init(arch_dep_params_factory_t factory) params = factory(); if (! op_Mulh) { - rflct_sig_t *sig; int mulh_opc = get_next_ir_opcode(); /* create the Mulh operation */ op_Mulh = new_ir_op(mulh_opc, "Mulh", op_pin_state_floats, irop_flag_commutative, oparity_binary, 0, 0, NULL); - sig = rflct_signature_allocate(1, 3); - rflct_signature_set_arg(sig, 0, 0, "Res", RFLCT_MC(Int), 0, 0); - rflct_signature_set_arg(sig, 1, 0, "Block", RFLCT_MC(BB), 0, 0); - rflct_signature_set_arg(sig, 1, 1, "Op 0", RFLCT_MC(Int), 0, 0); - rflct_signature_set_arg(sig, 1, 2, "Op 1", RFLCT_MC(Int), 0, 0); - - rflct_new_opcode(mulh_opc, "Mulh", 0); - rflct_opcode_add_signature(mulh_opc, sig); } } diff --git a/ir/ir/ircgopt.c b/ir/ir/ircgopt.c index da2b33efc..5c332c0ea 100644 --- a/ir/ir/ircgopt.c +++ b/ir/ir/ircgopt.c @@ -42,7 +42,6 @@ #include "irloop_t.h" #include "irflag_t.h" #include "ircons.h" -#include "typewalk.h" #include "irtools.h" /** diff --git a/ir/ir/irdump.c b/ir/ir/irdump.c index 6736c3c43..c56bd1383 100644 --- a/ir/ir/irdump.c +++ b/ir/ir/irdump.c @@ -48,9 +48,7 @@ #include "irdump_t.h" #include "irgwalk.h" -#include "typewalk.h" #include "tv_t.h" -#include "type_or_entity.h" #include "irouts.h" #include "irdom.h" #include "irloop_t.h" diff --git a/ir/ir/irdumptxt.c b/ir/ir/irdumptxt.c index 030ba111b..a4797fa2c 100644 --- a/ir/ir/irdumptxt.c +++ b/ir/ir/irdumptxt.c @@ -414,6 +414,7 @@ void dump_graph_as_text(ir_graph *irg, const char *suffix) { fclose (F); } +#ifdef EXTENDED_ACCESS_STATS static int addr_is_alloc(ir_node *acc) { ir_node *addr = NULL; ir_opcode addr_op; @@ -459,6 +460,7 @@ static int addr_is_alloc(ir_node *acc) { /* In addition, the alloc must be in the same loop. */ return 1; } +#endif /** dumps something like: * @@ -683,7 +685,7 @@ void dump_entity_to_file_prefix(FILE *F, ir_entity *ent, char *prefix, unsigned } if (verbosity & dump_verbosity_accessStats) { -#if 0 +#ifdef EXTENDED_ACCESS_STATS int n_acc = get_entity_n_accesses(ent); int max_depth = 0; int max_L_freq = -1; diff --git a/ir/ir/irgmod.c b/ir/ir/irgmod.c index a7d943d24..3d6cd6dab 100644 --- a/ir/ir/irgmod.c +++ b/ir/ir/irgmod.c @@ -38,6 +38,7 @@ #include "irhooks.h" #include "iredges_t.h" #include "irtools.h" +#include "error.h" /** * Turns a node into a "useless" Tuple. The Tuple just forms a tuple @@ -103,9 +104,7 @@ void exchange(ir_node *old, ir_node *nw) { block = is_Block(nw) ? nw : get_nodes_block(nw); if (! block) { - DDMN(old); - DDMN(nw); - assert(0 && "cannot find legal block for id"); + panic("cannot find legal block for id"); } } diff --git a/ir/ir/irgopt.c b/ir/ir/irgopt.c index 5f50eb2bc..ee808330f 100644 --- a/ir/ir/irgopt.c +++ b/ir/ir/irgopt.c @@ -34,9 +34,9 @@ #include "irgraph_t.h" #include "irprog_t.h" +#include "iroptimize.h" #include "ircons.h" #include "iropt_t.h" -#include "cfopt.h" #include "irgopt.h" #include "irgmod.h" #include "irgwalk.h" diff --git a/ir/ir/irgraph.c b/ir/ir/irgraph.c index 01e652a51..52fcfa2b9 100644 --- a/ir/ir/irgraph.c +++ b/ir/ir/irgraph.c @@ -43,7 +43,6 @@ #include "irflag_t.h" #include "array.h" #include "irgmod.h" -#include "mangle.h" #include "irouts.h" #include "irhooks.h" #include "irtools.h" diff --git a/ir/ir/irgraph_t.h b/ir/ir/irgraph_t.h index 72a9b8b59..bf718e8c5 100644 --- a/ir/ir/irgraph_t.h +++ b/ir/ir/irgraph_t.h @@ -35,8 +35,6 @@ #include "pseudo_irg.h" #include "type_t.h" #include "entity_t.h" -#include "typegmod.h" -#include "tr_inheritance.h" #include "iredgekinds.h" #include "irmemory.h" diff --git a/ir/ir/irgwalk.c b/ir/ir/irgwalk.c index 7e87d1230..d8b3779f7 100644 --- a/ir/ir/irgwalk.c +++ b/ir/ir/irgwalk.c @@ -39,7 +39,6 @@ #include "irgraph_t.h" /* visited flag */ #include "irprog.h" #include "irgwalk.h" -#include "typewalk.h" #include "irhooks.h" #include "ircgcons.h" diff --git a/ir/ir/irmode_t.h b/ir/ir/irmode_t.h index 609aec160..22670d526 100644 --- a/ir/ir/irmode_t.h +++ b/ir/ir/irmode_t.h @@ -31,7 +31,27 @@ #include "irmode.h" #include "tv.h" -/** This struct is supposed to completely define a mode. **/ +/** + * Contains relevant information about a mode. + * + * Necessary information about a mode is stored in this struct + * which is used by the tarval module to perform calculations + * and comparisons of values of a such described mode. + * + * ATTRIBUTES: + * - modecode code: An unambiguous int (enum) for the mode + * - ident *name: Name of this mode. Two modes are different if the name is different. + * - mode_sort sort: sort of mode specifying possible usage categories + * - int size: size of the mode in Bits. + * - unsigned sign:1: signedness of this mode + * - ... more to come + * - modulo_shift specifies for modes of kind irms_int_number + * whether shift applies modulo to value of bits to shift + * + * SEE ALSO: + * The tech report 1999-44 describing FIRM and predefined modes + * tarval.h + */ struct ir_mode { firm_kind kind; /**< distinguishes this node from others */ modecode code; /**< unambiguous identifier of a mode */ diff --git a/ir/ir/irnode.c b/ir/ir/irnode.c index e81089396..370923f5f 100644 --- a/ir/ir/irnode.c +++ b/ir/ir/irnode.c @@ -35,7 +35,6 @@ #include "irnode_t.h" #include "irgraph_t.h" #include "irmode_t.h" -#include "typegmod.h" #include "irbackedge_t.h" #include "irdump.h" #include "irop_t.h" diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 3173d6bbe..4ba56a9cc 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -27,9 +27,7 @@ # include "config.h" #endif -#ifdef HAVE_STRING_H #include -#endif #include "irnode_t.h" #include "irgraph_t.h" @@ -47,8 +45,8 @@ #include "irarch.h" #include "hashptr.h" #include "archop.h" -#include "opt_polymorphy.h" #include "opt_confirms.h" +#include "opt_polymorphy.h" #include "irtools.h" #include "xmalloc.h" diff --git a/ir/ir/irprog.c b/ir/ir/irprog.c index d8cef59ff..bfdf60cf9 100644 --- a/ir/ir/irprog.c +++ b/ir/ir/irprog.c @@ -37,7 +37,6 @@ #include "pseudo_irg.h" #include "array.h" #include "obst.h" -#include "typegmod.h" #include "irop_t.h" #include "irmemory.h" diff --git a/ir/ir/irprog_t.h b/ir/ir/irprog_t.h index 5e882e800..ac95ffb32 100644 --- a/ir/ir/irprog_t.h +++ b/ir/ir/irprog_t.h @@ -36,9 +36,7 @@ #include "pseudo_irg.h" #include "ircgcons.h" #include "firm_common_t.h" -#include "typegmod.h" #include "irtypeinfo.h" -#include "tr_inheritance.h" #include "irmemory.h" #include "callgraph.h" diff --git a/ir/ir/irreflect.c b/ir/ir/irreflect.c deleted file mode 100644 index 0b6633a2c..000000000 --- a/ir/ir/irreflect.c +++ /dev/null @@ -1,504 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Reflection for Firm operands. - * @author Sebastian Hack - * @date 9.9.2004 - * @version $Id$ - */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include - -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STRING_H -# include -#endif -#ifdef HAVE_STRINGS_H -# include -#endif - -#include "obst.h" - -#include "irnode_t.h" -#include "irmode.h" -#include "irreflect.h" - -#define obstack_grow_str(obst,s) obstack_grow((obst), (s), strlen((s))) -#define obstack_grow_str_const(obst,s) obstack_grow((obst), (s), sizeof((s))) - -/** - * Get the number of bits set in a word. - */ -static INLINE int pop(int i) { - unsigned x = (unsigned) i; - x = ((x >> 1) & 0x55555555); - x = (x & 0x33333333) + ((x >> 2) & 0x33333333); - x = (x + (x >> 4)) & 0x0f0f0f0f; - x = x + (x >> 8); - x = x + (x >> 16); - return (int) (x & 0x3f); -} - -/** - * Get the number of bits differing in two variables. - */ -static INLINE int dist(int x, int y) { - return pop(x ^ y); -} - - -#define MAX_SIG_COUNT 8 -#define MAX_ARG_COUNT 10 - -typedef struct { - int num; /**< A sequential number (one opcode can have multiple signatures. */ - rflct_arg_t args[]; /**< The signature. */ -} rflct_args_t; - -typedef struct { - ir_opcode opc; - const char *name; - int commutative; - int sig_count; - rflct_arg_t *sigs[MAX_SIG_COUNT]; -} rflct_opcode_t; - -static struct obstack obst; - -static rflct_opcode_t **opcodes = NULL; - -static int opcodes_size = 0; - -static INLINE void assure_opcode_capacity(int opcode) -{ - if(opcode >= opcodes_size) { - int new_size = 2 * opcode; - rflct_opcode_t **new_opcodes = xcalloc(new_size, sizeof(new_opcodes[0])); - - if(opcodes != NULL) { - memcpy(new_opcodes, opcodes, sizeof(*opcodes) * opcodes_size); - free(opcodes); - } - - opcodes = new_opcodes; - opcodes_size = new_size; - } -} - - -#if 0 -#define OPCODES_COUNT (sizeof(opcodes) / sizeof(opcodes[0])) -#endif -#define OPCODES_COUNT opcodes_size - - -rflct_mode_class_t rflct_get_mode_class(const ir_mode *mode) { - mode_sort sort = get_mode_sort(mode); - - switch(sort) { - case irms_auxiliary: - case irms_control_flow: - if(mode == mode_BB) - return RFLCT_MC(BB); - else if(mode == mode_X) - return RFLCT_MC(X); - case irms_memory: - return RFLCT_MC(Mem); - case irms_internal_boolean: - return RFLCT_MC(Bool); - case irms_int_number: - return mode_is_signed(mode) ? RFLCT_MC(IntS) : RFLCT_MC(IntU); - case irms_float_number: - return RFLCT_MC(Float); - case irms_reference: - return RFLCT_MC(Ref); - case irms_character: - return RFLCT_MC(Char); - } - - return RFLCT_MC(None); -} - -static INLINE const rflct_opcode_t *get_opcode(ir_opcode opc) { - assert(opc >= 0 && opc < OPCODES_COUNT && "Invalid opcode"); - return opcodes[opc]; -} - -static INLINE const rflct_arg_t *get_args(ir_opcode opc, int sig) { - const rflct_opcode_t *opcode = get_opcode(opc); - assert(sig >= 0 && sig < opcode->sig_count - && "Invalid signature"); - return opcode->sigs[sig]; -} - -#define GET_OPCODE(opc) get_opcode(opc) -#define GET_ARGS(opc,args) get_args(opc, args) - -int rflct_get_signature_count(ir_opcode opc) { - const rflct_opcode_t *opcode = GET_OPCODE(opc); - return opcode->sig_count; -} - -int rflct_get_in_args_count(ir_opcode opc, int sig) { - const rflct_arg_t *args = GET_ARGS(opc, sig); - int res = 0, i = 0; - - for(i = 0; args[i].name != NULL; i++); - for(res = 0, i += 1; args[i].name != NULL; res++, i++); - return res; -} - -int rflct_get_out_args_count(ir_opcode opc, int sig) { - const rflct_arg_t *args = GET_ARGS(opc, sig); - int i = 0; - for(i = 0; args[i].name != NULL; i++); - return i; -} - - -const rflct_arg_t *rflct_get_in_args(ir_opcode opc, int sig) { - const rflct_arg_t *args = GET_ARGS(opc, sig); - int i; - - for(i = 0; args[i].name != NULL; i++); - return &args[i + 1]; -} - -const rflct_arg_t *rflct_get_out_args(ir_opcode opc, int sig) { - return GET_ARGS(opc, sig); -} - -int rflct_signature_match(const ir_node *irn, int sig) { - ir_opcode op = get_irn_opcode(irn); - const rflct_arg_t *args = rflct_get_in_args(op, sig); - int dst = 0; - int i, j; - - for(i = 0, j = -1; RFLCT_ARG_VALID(&args[i]) - && j < get_irn_arity(irn); j++) { - - ir_node *child = get_irn_n(irn, j); - const rflct_arg_t *arg = &args[i]; - rflct_mode_class_t mc = rflct_get_mode_class(get_irn_mode(child)); - - if(arg->accepted_modes & mc) - dst += dist(arg->accepted_modes, mc); - else - return INT_MAX; - - if(!arg->is_variadic) - i++; - } - - return dst; -} - -int rflct_get_signature(const ir_node *irn) { - const rflct_opcode_t *opc = GET_OPCODE(get_irn_opcode(irn)); - int min_dist = INT_MAX; - int min_sig = INT_MAX; - int i; - - for(i = 0; i < opc->sig_count; i++) { - int dist = rflct_signature_match(irn, i); - if(dist < min_dist) { - min_dist = dist; - min_sig = i; - } - } - - return min_sig; -} - -static const char *rflct_mode_class_atomic_name(rflct_mode_class_t mc) { -#define XXX(_mc) case RFLCT_MC(_mc): return #_mc - switch(mc) { - XXX(None); - XXX(Mem); - XXX(Bool); - XXX(IntS); - XXX(IntU); - XXX(Float); - XXX(Ref); - XXX(Char); - XXX(X); - XXX(BB); - XXX(Int); - XXX(Intb); - XXX(Num); - XXX(NumP); - XXX(Data); - XXX(Datab); - XXX(DataM); - XXX(DataMX); - XXX(Lh); - default: - return ""; - } -#undef XXX -} - -static void rflct_mode_class_comb_name_obst(struct obstack *obst, - rflct_mode_class_t mc) { - const char *res = rflct_mode_class_atomic_name(mc); - - if(strlen(res) == 0) { - const char *prefix = ""; - int mask; - - obstack_1grow(obst, '{'); - for(mask = 1; mask != 0; mask <<= 1) { - if(mask & mc) { - const char *s = rflct_mode_class_atomic_name(mask); - obstack_grow_str(obst, s); - obstack_grow_str(obst, prefix); - prefix = "|"; - } - } - obstack_1grow(obst, '}'); - - } else - obstack_grow(obst, res, strlen(res)); -} - -char *rflct_mode_class_name(char *str, int n, rflct_mode_class_t mc) { - struct obstack obst; - const char *res; - - obstack_init(&obst); - - rflct_mode_class_comb_name_obst(&obst, mc); - obstack_1grow(&obst, 0); - res = obstack_finish(&obst); - - strncpy(str, res, n); - - obstack_free(&obst, NULL); - - return str; -} - -static void rflct_obstack_grow_args(struct obstack *obst, - const rflct_arg_t *args) { - const rflct_arg_t *arg; - const char *prefix = ""; - - for(arg = args; RFLCT_ARG_VALID(arg); arg++) { - obstack_grow_str(obst, prefix); - obstack_grow_str(obst, arg->name); - if(arg->is_variadic) - obstack_1grow(obst, '*'); - obstack_1grow(obst, ':'); - rflct_mode_class_comb_name_obst(obst, arg->accepted_modes); - prefix = ", "; - } - -} - -char *rflct_to_string(char *buf, int n, ir_opcode opc, int sig) { - struct obstack obst; - char *s; - const rflct_opcode_t *opcode = GET_OPCODE(opc); - - obstack_init(&obst); - - obstack_1grow(&obst, '('); - rflct_obstack_grow_args(&obst, rflct_get_out_args(opc, sig)); - - obstack_grow_str(&obst, ") = "); - obstack_grow_str(&obst, opcode->name); - obstack_1grow(&obst, '('); - - rflct_obstack_grow_args(&obst, rflct_get_in_args(opc, sig)); - - obstack_1grow(&obst, ')'); - obstack_1grow(&obst, 0); - s = obstack_finish(&obst); - strncpy(buf, s, n); - obstack_free(&obst, NULL); - - return buf; -} - -#define NON_VARIADIC 0 -#define VARIADIC 1 - -#define ARG(name,modes) \ -_ARG(name, modes, NON_VARIADIC, -1) - -#define ARG_SAME(name,modes,mode_same) \ -_ARG(name, modes, NON_VARIADIC, mode_same) - -#define VARG(name,modes) \ -_ARG(name, modes, VARIADIC, 0) - -#define VARG_SAME(name,modes) \ -_ARG(name, modes, VARIADIC, 1) - -#define MARK \ -_ARG(NULL, None, NON_VARIADIC, -1) - -#define FINISH \ -_ARG(NULL, None, NON_VARIADIC, 0) - -#define BLOCK ARG("Block", BB) - - static void init_ops(void) { - - int curr_sig; - rflct_opcode_t *opcode; - - obstack_init(&obst); - - assure_opcode_capacity(iro_MaxOpcode); - - -#define BEGIN_OP(op) \ - curr_sig = 0; \ - opcode = obstack_alloc(&obst, sizeof(*opcode)); \ - opcode->opc = iro_ ## op; \ - opcode->name = #op; \ - opcodes[opcode->opc] = opcode; - - -#define BEGIN_ARGS - -#define _ARG(_name,_modes,_variadic,_mode_equals) \ - { \ - rflct_arg_t args; \ - args.name = _name; \ - args.accepted_modes = RFLCT_MC(_modes); \ - args.is_variadic = _variadic; \ - args.mode_equals = _mode_equals; \ - obstack_grow(&obst, &args, sizeof(args)); \ - } - -#define END_ARGS \ - { \ - FINISH; \ - assert(curr_sig < MAX_SIG_COUNT && "Mind the maximum number of signatures"); \ - opcode->sigs[curr_sig++] = obstack_finish(&obst); \ - opcode->sig_count = curr_sig; \ - } - -#define END_OP - -#include "irreflect.def" - -#undef BEGIN_ARGS -#undef END_ARGS -#undef BEGIN_OP -#undef END_OP - } - -#undef _ARG -#define _ARG(_name,_modes,_var,_me) \ -arg->name = _name; \ - arg->accepted_modes = RFLCT_MC(_modes); \ - arg->is_variadic = _var; \ - arg->mode_equals = _me; - -void rflct_new_opcode(ir_opcode opc, const char *name, int commutative) -{ - rflct_opcode_t *ropc = obstack_alloc(&obst, sizeof(*ropc)); - - ropc->opc = opc; - ropc->name = name; - ropc->sig_count = 0; - memset(ropc->sigs, 0, sizeof(ropc->sigs)); - - assure_opcode_capacity(opc); - opcodes[opc] = ropc; -} - -int rflct_opcode_add_signature(ir_opcode opc, rflct_sig_t *sig) -{ - rflct_arg_t *args = sig->args; - rflct_opcode_t *op = opcodes[opc]; - int i; - - assert(op && "Illegal opcode"); - - for(i = 0; i < MAX_SIG_COUNT && op->sigs[i] != NULL; i++); - - if(i >= MAX_SIG_COUNT) - return 0; - - op->sigs[op->sig_count++] = args; - - free(sig); - return 1; -} - - -rflct_sig_t *rflct_signature_allocate(int defs, int uses) -{ - rflct_sig_t *sig = xmalloc(sizeof(*sig)); - - rflct_arg_t *args = - obstack_alloc(&obst, sizeof(*args) * (defs + uses + 2)); - - rflct_arg_t *arg = args + defs; - MARK; - - arg = args + defs + uses + 1; - FINISH; - - sig->defs = defs; - sig->uses = uses; - sig->args = args; - - return sig; -} - -int rflct_signature_get_index(const rflct_sig_t *sig, int is_use, int num) -{ - return is_use ? num + sig->defs + 1 : num; -} - -#undef _ARG -#define _ARG(_name,_modes,_var,_me) \ -arg->name = _name; \ - arg->accepted_modes = _modes; \ - arg->is_variadic = _var; \ - arg->mode_equals = _me; - -int rflct_signature_set_arg(rflct_sig_t *sig, int is_use, int num, - const char *name, rflct_mode_class_t mc, int is_variadic, int mode_equals) -{ - int index = rflct_signature_get_index(sig, is_use, num); - rflct_arg_t *arg = sig->args + index; - _ARG(name, mc, is_variadic, mode_equals); - return index; -} - - -void firm_init_rflct(void) { - init_ops(); -} - -#undef VARIADIC -#undef NON_VARIADIC diff --git a/ir/ir/irreflect.def b/ir/ir/irreflect.def deleted file mode 100644 index 8f5c52713..000000000 --- a/ir/ir/irreflect.def +++ /dev/null @@ -1,481 +0,0 @@ - -BEGIN_OP(Block) - BEGIN_ARGS - ARG("Block", BB) - MARK - ARG("predecessors", X) - END_ARGS -END_OP - -BEGIN_OP(Start) - BEGIN_ARGS - ARG("Execution", X) - ARG("Memory", Mem) - ARG("Stack", Ref) - ARG("Global", Ref) - VARG("Arguments", Data) - ARG("Call By Value", Ref) - MARK - BLOCK - END_ARGS -END_OP - -BEGIN_OP(End) - BEGIN_ARGS - MARK - BLOCK - VARG("Memory & Preds", Lh) - END_ARGS -END_OP - -/* - * EndReg - */ - -/* - * EndExcept - */ - -/* - * Jmp - */ - -BEGIN_OP(Jmp) - BEGIN_ARGS - ARG("Target", X) - MARK - BLOCK - END_ARGS -END_OP - -BEGIN_OP(Break) - BEGIN_ARGS - ARG("Target", X) - MARK - BLOCK - END_ARGS -END_ARGS - -BEGIN_OP(Cond) - BEGIN_ARGS - ARG("False Branch", X) - ARG("True Branch", X) - MARK - BLOCK - ARG("Condition", Bool) - END_ARGS - - BEGIN_ARGS - VARG("Cases", X) - MARK - BLOCK - ARG("Switch", Int) - END_ARGS -END_OP - -BEGIN_OP(Return) - BEGIN_ARGS - ARG("CF", X) - MARK - BLOCK - ARG("Memory", Mem) - VARG("Args", Data) - END_ARGS -END_OP - -BEGIN_OP(CallBegin) - BEGIN_ARGS - VARG("CF", X) - MARK - BLOCK - ARG("Addr", Ref) - END_ARGS -END_OP - -BEGIN_OP(Const) - BEGIN_ARGS - ARG("Value", Data) - MARK - BLOCK - END_ARGS -END_OP - -BEGIN_OP(SymConst) - BEGIN_ARGS - ARG("Value", Int) - MARK - BLOCK - END_ARGS - - BEGIN_ARGS - ARG("Value", Ref) - MARK - BLOCK - END_ARGS -END_OP - -BEGIN_OP(Unknown) - BEGIN_ARGS - ARG("Value", Any) - MARK - BLOCK - END_ARGS -END_OP - -BEGIN_OP(Sel) - BEGIN_ARGS - ARG("Addr", Ref) - MARK - BLOCK - ARG("Memory", Mem) - ARG("Base", Ref) - VARG_SAME("Indices", Int) - END_ARGS -END_OP - -BEGIN_OP(Call) - BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - VARG("Results", Data) - ARG("Exception Memory", Mem) - ARG("Stack", Ref) - MARK - BLOCK - ARG("Memory", Mem) - ARG("Addr", Ref) - VARG("Parameters", Data) - END_ARGS -END_OP - -BEGIN_OP(Add) - BEGIN_ARGS - ARG("Result", NumP) - MARK - BLOCK - ARG_SAME("Op 1", NumP, 0) - ARG_SAME("Op 2", NumP, 0) - END_ARGS - - BEGIN_ARGS - ARG("Result", Ref) - MARK - BLOCK - ARG("Op 1", Ref) - ARG("Op 2", Num) - END_ARGS - - BEGIN_ARGS - ARG("Result", Ref) - MARK - BLOCK - ARG("Op 1", Num) - ARG("Op 2", Ref) - END_ARGS -END_OP - -BEGIN_OP(Sub) - BEGIN_ARGS - ARG("Result", NumP) - MARK - BLOCK - ARG_SAME("Op 1", NumP, 0) - ARG_SAME("Op 2", NumP, 0) - END_ARGS - - BEGIN_ARGS - ARG("Result", Ref) - MARK - BLOCK - ARG("Op 1", NumP) - ARG("Op 2", Ref) - END_ARGS - - BEGIN_ARGS - ARG("Result", Ref) - MARK - BLOCK - ARG("Op 1", Ref) - ARG("Op 2", NumP) - END_ARGS - - BEGIN_ARGS - ARG("Result", Num) - MARK - BLOCK - ARG("Op 1", Ref) - ARG("Op 2", Ref) - END_ARGS -END_OP - -BEGIN_OP(Minus) - BEGIN_ARGS - ARG("Result", Num) - MARK - BLOCK - ARG_SAME("Op 0", Num, 0) - END_ARGS -END_OP - -BEGIN_OP(Mul) - BEGIN_ARGS - ARG("Result", Int) - MARK - BLOCK - ARG("Op 0", Int) - ARG_SAME("Op 1", Int, 3) - END_ARGS - - BEGIN_ARGS - ARG("Result", Float) - MARK - BLOCK - ARG_SAME("Op 0", Float, 0) - ARG_SAME("Op 1", Float, 0) - END_ARGS -END_OP - -BEGIN_OP(Quot) - BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - ARG("Op 0", Float) - MARK - BLOCK - ARG("Memory", Mem) - ARG_SAME("Op 0", Float, 2) - ARG_SAME("Op 1", Float, 2) - END_ARGS -END_OP - -BEGIN_OP(DivMod) - BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - ARG("Res 0", Int) - ARG_SAME("Res 1", Int, 2) - MARK - BLOCK - ARG("Memory", Mem) - ARG_SAME("Op 0", Int, 2) - ARG_SAME("Op 1", Int, 2) - END_ARGS -END_OP - -BEGIN_OP(Div) -BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - ARG("Result", Int) - MARK - BLOCK - ARG("Memory", Mem) - ARG_SAME("Op 0", Int, 2) - ARG_SAME("Op 1", Int, 2) -END_ARGS -END_OP - -BEGIN_OP(Mod) -BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - ARG("Result", Int) - MARK - BLOCK - ARG("Memory", Mem) - ARG_SAME("Op 0", Int, 2) - ARG_SAME("Op 1", Int, 2) -END_ARGS -END_OP - -BEGIN_OP(Abs) -BEGIN_ARGS - ARG("Res", Num) - MARK - BLOCK - ARG_SAME("Op", Num, 0) -END_ARGS -END_OP - -BEGIN_OP(Mux) -BEGIN_ARGS - ARG("Res", NumP) - MARK - BLOCK - ARG("Switch", Bool) - ARG_SAME("Op 0", NumP, 0) - ARG_SAME("Op 1", NumP, 0) -END_ARGS -END_OP - - -BEGIN_OP(And) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op 0", Int, 0) - ARG_SAME("Op 1", Int, 0) -END_ARGS -END_OP - -BEGIN_OP(Or) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op 0", Int, 0) - ARG_SAME("Op 1", Int, 0) -END_ARGS -END_OP - -BEGIN_OP(Eor) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op 0", Int, 0) - ARG_SAME("Op 1", Int, 0) -END_ARGS -END_OP - -BEGIN_OP(Not) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op", Int, 0) -END_ARGS -END_OP - -BEGIN_OP(Shl) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op 0", Int, 0) - ARG("Op 1", IntU) -END_ARGS -END_OP - -BEGIN_OP(Shr) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op 0", Int, 0) - ARG("Op 1", IntU) -END_ARGS -END_OP - -BEGIN_OP(Shrs) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op 0", Int, 0) - ARG("Op 1", IntU) -END_ARGS -END_OP - -BEGIN_OP(Rot) -BEGIN_ARGS - ARG("Res", Int) - MARK - BLOCK - ARG_SAME("Op 0", Int, 0) - ARG("Op 1", Int) -END_ARGS -END_OP - -BEGIN_OP(Cmp) -BEGIN_ARGS - VARG("Res", Bool) - MARK - BLOCK - ARG("Op 0", Datab) - ARG_SAME("Op 1", Datab, 3) -END_ARGS -END_OP - -BEGIN_OP(Conv) -BEGIN_ARGS - VARG("Res", Datab) - MARK - BLOCK - ARG("Op 0", Datab) -END_ARGS -END_OP - -BEGIN_OP(Phi) -BEGIN_ARGS - ARG_SAME("Res", DataM, 3) - MARK - BLOCK - VARG("Op 0", DataM) -END_ARGS -END_OP - -BEGIN_OP(Filter) -BEGIN_ARGS - ARG_SAME("Res", DataM, 3) - MARK - BLOCK - VARG("Op 0", DataM) -END_ARGS -END_OP - -BEGIN_OP(Load) -BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - ARG("Data", Data) - MARK - BLOCK - ARG("Memory", Mem) - ARG("Addr", Ref) -END_ARGS -END_OP - -BEGIN_OP(Store) -BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - MARK - BLOCK - ARG("Memory", Mem) - ARG("Addr", Ref) - ARG("Data", Data) -END_ARGS -END_OP - -BEGIN_OP(Alloc) -BEGIN_ARGS - ARG("Memory", Mem) - ARG("CF", X) - ARG("Addr", Ref) - MARK - BLOCK - ARG("Memory", Mem) - ARG("Size", IntU) -END_ARGS -END_OP - -BEGIN_OP(Free) -BEGIN_ARGS - ARG("Memory", Mem) - MARK - BLOCK - ARG("Memory", Mem) - ARG("Addr", Ref) -END_ARGS -END_OP - -BEGIN_OP(Sync) -BEGIN_ARGS - ARG("Memory", Mem) - MARK - BLOCK - VARG_SAME("Memory", Mem) -END_ARGS -END_OP diff --git a/ir/ir/irreflect.h b/ir/ir/irreflect.h deleted file mode 100644 index 8e303f5c7..000000000 --- a/ir/ir/irreflect.h +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Reflection for Firm operations. - * @author Sebastian Hack - * @date 9.9.2004 - * @version $Id$ - */ -#ifndef FIRM_IR_REFLECT_H -#define FIRM_IR_REFLECT_H - -#include - -#include "firm_types.h" -#include "irop.h" - -#define RFLCT_MC(m) rflct_ms_ ## m -typedef enum { - RFLCT_MC(None) = 0, - RFLCT_MC(Mem) = 2, - RFLCT_MC(Bool) = 4, - RFLCT_MC(IntS) = 8, - RFLCT_MC(IntU) = 16, - RFLCT_MC(Float) = 32, - RFLCT_MC(Ref) = 64, - RFLCT_MC(Char) = 128, - RFLCT_MC(X) = 256, - RFLCT_MC(BB) = 512, - RFLCT_MC(Cf) = RFLCT_MC(X) | RFLCT_MC(BB), - - RFLCT_MC(Int) = RFLCT_MC(IntS) | RFLCT_MC(IntU), - RFLCT_MC(Intb) = RFLCT_MC(Int) | RFLCT_MC(Bool), - RFLCT_MC(Num) = RFLCT_MC(Int) | RFLCT_MC(Float), - RFLCT_MC(NumP) = RFLCT_MC(Num) | RFLCT_MC(Ref), - RFLCT_MC(Data) = RFLCT_MC(NumP) | RFLCT_MC(Char), - RFLCT_MC(Datab) = RFLCT_MC(Data) | RFLCT_MC(Bool), - RFLCT_MC(DataM) = RFLCT_MC(Data) | RFLCT_MC(Mem), - RFLCT_MC(DataMX) = RFLCT_MC(Data) | RFLCT_MC(Mem) | RFLCT_MC(X), - RFLCT_MC(Lh) = RFLCT_MC(Mem) | RFLCT_MC(BB), - - RFLCT_MC(Any) = -1 - -} rflct_mode_class_t; - -typedef struct _rflct_arg_t { - const char *name; /**< The name of the argument (just a description). */ - - int is_variadic; /**< non-zero, if this argument can have multiple parameters. */ - rflct_mode_class_t accepted_modes; /**< The set of accepted modes. */ - - int mode_equals; /**< If not variadic: You can specify the index of - another argument meaning, that the mode of the - operand binding at this argument must be the same - as the mode of the operand binding to the argument - at index. If you don't want to express such a - dependency, just give -1 here. - - If variadic: If true, the modes of all - variadic operands binding to this argument - must be the same. If false, they can differ. */ -} rflct_arg_t; - -typedef struct _rflct_sig_t { - int defs; /**< The number of defined arguments in the signature. */ - int uses; /**< The number of used arguments in the signature. */ - - rflct_arg_t *args; /**< The arguments array. */ -} rflct_sig_t; - -#define RFLCT_ARG_IS_A(arg,modes) (((arg)->accepted_modes & modes) != 0) -#define RFLCT_ARG_VALID(arg) ((arg)->name != NULL) -#define RFLCT_SIG_VALID(sig) ((sig) != INT_MAX) - -/** - * Get the mode class for an IR mode. - * @param mode An IR mode. - * @return The corresponding smallest reflection mode class. - */ -rflct_mode_class_t rflct_get_mode_class(const ir_mode *mode); - -/** - * Get the number of signatures for a Firm opcode. - * @param opc The opcode. - * @return The number of signatures for this opcode. - */ -int rflct_get_signature_count(ir_opcode opc); - -/** - * Try to get the signature, that matches to a given instance - * of a Firm node. - * @param irn The node. - * @return The first matching signature or -1, if no signature matches. - */ -int rflct_get_signature(const ir_node *irn); - -/** - * Get the number of in arguments. - * An in argument is a use of a value. - * @param opc The opcode. - * @param sig The signature you are refering to. - * @return The number of arguments. - */ -int rflct_get_in_args_count(ir_opcode opc, int sig); - -/** - * Get the number of out arguments. - * An out argument is a def of a value. - * @param opc The opcode. - * @param sig The signature you are refering to. - * @return The number of arguments. - */ -int rflct_get_out_args_count(ir_opcode opc, int sig); - -#define rflct_get_args_count(opc, sig, use) \ - ((use) ? rflct_get_in_args_count(opc, sig) : rflct_get_out_args_count(opc, sig)) - -/** - * Get the array of use args. - * The array is terminated with an entry for which - * RFLCT_ARG_VALID is 0. - * @param opc The opcode. - * @param sig The signature you are referring to (Must be between - * 0 and the signature count). - * @return The array. - */ -const rflct_arg_t *rflct_get_in_args(ir_opcode opc, int sig); - -/** - * Get the array of def args. - * The array is terminated with an entry for which - * RFLCT_ARG_VALID is 0. - * @param opc The opcode. - * @param sig The signature you are referring to (Must be between - * 0 and the signature count). - * @return The array. - */ -const rflct_arg_t *rflct_get_out_args(ir_opcode opc, int sig); - -#define rflct_get_args(opc, sig, use) \ - ((use) ? rflct_get_in_args(opc, sig) : rflct_get_out_args(opc, sig)) - -/** - * Make a string representation of a signature of an opcode. - * @param buf The buffer to put the string to. - * @param n The size of buf. - * @param opc The opcode. - * @param sig The signature. - * @return buf. - */ -char *rflct_to_string(char *buf, int n, ir_opcode opc, int sig); - -/** - * Get a string representation of a mode class. - * @param str The buffer to put the string to. - * @param n The size of the buffer. - * @param mc The mode class. - * @return str. - */ -char *rflct_mode_class_name(char *str, int n, rflct_mode_class_t mc); - -/** - * Create a new opcode. - * @param opc The Firm opcode. - * @param name A name. - * @param commutative non-zero, if the opcode is commutative. - */ -void rflct_new_opcode(ir_opcode opc, const char *name, int commutative); - -/** - * Add a signature to the opcode. - * @param opc The opcode. - * @param sig The signature. - * @return non-zero, if the signature was added successfully, false if no - * more signatures can be added to the opcode. - */ -int rflct_opcode_add_signature(ir_opcode opc, rflct_sig_t *sig); - -/** - * Allocate a new signature. - * @param defs Number of def arguments. - * @param uses Number of use arguments. - * @return An allocated signature. - */ -rflct_sig_t *rflct_signature_allocate(int defs, int uses); - -/** - * Set an argument in a signature. - * - * @param sig The signature. - * @param is_use non-zero, if the argument is a use, else it is - * considered a def. - * @param num The index of the argument. - * @param name The name of the argument. - * @param mc The mode class of the argument. - * @param is_variadic non-zero, if the argument is variadic. - * @param mode_equals This variable has following meaning: If the - * argument is variadic, a 1 indicates that all operands binding to this - * argument must have the same mode. A 0 indicates, that their mode must - * be of the specified mode class but can differ. If the argument is non - * variadic, a positive number indicates, that the mode of the operand - * binding to this argument must be the same as the one binding to - * argument indexed by mode_equals. If the mode should not be dependent - * to another mode, set -1 here. - * @return The index of the argument. Only use this index in mode_equals - * parameters of other arguments. - */ -int rflct_signature_set_arg(rflct_sig_t *sig, int is_use, int num, - const char *name, rflct_mode_class_t mc, int is_variadic, int mode_equals); - -/** - * Get the arguments array index for an argument. - * @param sig The signature. - * @param is_use non-zero, if the argument indicates a use or def argument. - * @param num The number of the argument. - * @return The index into the arguments array. - */ -int rflct_signature_get_index(const rflct_sig_t *sig, int is_use, int num); - -#endif diff --git a/ir/ir/irreflect_t.h b/ir/ir/irreflect_t.h deleted file mode 100644 index db874461b..000000000 --- a/ir/ir/irreflect_t.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Basic (private) data structures for reflection. - * @author Sebastian Hack - * @date 10.9.2004 - * @version $Id$ - */ -#ifndef FIRM_IR_REFLECT_T_H -#define FIRM_IR_REFLECT_T_H - -void firm_init_rflct(void); - -#endif diff --git a/ir/lower/lower_calls.c b/ir/lower/lower_calls.c index aabb42c88..edc753cdf 100644 --- a/ir/lower/lower_calls.c +++ b/ir/lower/lower_calls.c @@ -35,10 +35,9 @@ #include "ircons.h" #include "irgmod.h" #include "irgwalk.h" -#include "typewalk.h" #include "lower_calls.h" -#include "return.h" #include "irtools.h" +#include "iroptimize.h" #include "array.h" #include "pmap.h" #include "xmalloc.h" diff --git a/ir/lower/lower_hl.c b/ir/lower/lower_hl.c index 441fbc357..da09af025 100644 --- a/ir/lower/lower_hl.c +++ b/ir/lower/lower_hl.c @@ -30,7 +30,7 @@ #include "irmode_t.h" #include "irnode_t.h" #include "entity_t.h" -#include "type.h" +#include "typerep.h" #include "irprog_t.h" #include "ircons.h" #include "lower_hl.h" diff --git a/ir/opt/cfopt.c b/ir/opt/cfopt.c index b504e6fc1..6fa73c7bf 100644 --- a/ir/opt/cfopt.c +++ b/ir/opt/cfopt.c @@ -27,6 +27,8 @@ # include "config.h" #endif +#include "iroptimize.h" + #include #include "plist.h" @@ -51,7 +53,6 @@ #include "irflag_t.h" #include "firmstat.h" -#include "cfopt.h" #include "iropt_dbg.h" /*------------------------------------------------------------------*/ diff --git a/ir/opt/cfopt.h b/ir/opt/cfopt.h deleted file mode 100644 index fbd552b27..000000000 --- a/ir/opt/cfopt.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Control flow optimizations. - * @author Goetz Lindenmaier, Michael Beck, Sebastian Hack - * @version $Id$ - */ -#ifndef FIRM_OPT_CFOPT_H -#define FIRM_OPT_CFOPT_H - -#include "irgraph.h" - -/** Control flow optimization. - * - * Removes empty blocks doing if simplifications and loop simplifications. - * A block is empty if it contains only a Jmp node and Phi nodes. - * Merges single entry single exit blocks with their predecessor - * and propagates dead control flow by calling equivalent_node(). - * Independent of compiler flag it removes Tuples from cf edges, - * Bad predecessors from Blocks and Phis, and unnecessary predecessors of End. - * - * @bug So far destroys backedge information. - * @bug Chokes on Id nodes if called in a certain order with other - * optimizations. Call local_optimize_graph() before to remove - * Ids. - */ -void optimize_cf(ir_graph *irg); - -#endif /* FIRM_OPT_CFOPT_H */ diff --git a/ir/opt/condeval.c b/ir/opt/condeval.c index d4dd6f8c3..1b1b65403 100644 --- a/ir/opt/condeval.c +++ b/ir/opt/condeval.c @@ -28,9 +28,10 @@ #include "config.h" #endif +#include "iroptimize.h" + #include #include "array.h" -#include "condeval.h" #include "debug.h" #include "ircons.h" #include "irgmod.h" diff --git a/ir/opt/condeval.h b/ir/opt/condeval.h deleted file mode 100644 index 6fbe911d0..000000000 --- a/ir/opt/condeval.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Partial condition evaluation - * @author Christoph Mallon, Matthias Braun - * @version $Id$ - */ -#ifndef FIRM_OPT_CONDEVAL_H -#define FIRM_OPT_CONDEVAL_H - -#include "firm_types.h" - -/** - * Perform partial conditionla evaluation on the given graph. - * - * @param irg the graph - */ -void opt_cond_eval(ir_graph* irg); - -#endif /* FIRM_OPT_CONDEVAL_H */ diff --git a/ir/opt/convopt.c b/ir/opt/convopt.c index b77557087..433c6a524 100644 --- a/ir/opt/convopt.c +++ b/ir/opt/convopt.c @@ -40,8 +40,9 @@ #include "config.h" #endif +#include "iroptimize.h" + #include -#include "convopt.h" #include "debug.h" #include "ircons.h" #include "irgmod.h" diff --git a/ir/opt/convopt.h b/ir/opt/convopt.h deleted file mode 100644 index 454dc3c50..000000000 --- a/ir/opt/convopt.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief conv node optimisation - * @author Matthias Braun, Christoph Mallon - * @version $Id:$ - */ -#ifndef FIRM_OPT_CONVOPT_H -#define FIRM_OPT_CONVOPT_H - -#include "firm_types.h" - -/** - * Try to reduce the number of conv nodes in the given ir graph. - * - * @param irg the graph - */ -void conv_opt(ir_graph *irg); - -#endif /* FIRM_OPT_CONVOPT_H */ diff --git a/ir/opt/data_flow_scalar_replace.c b/ir/opt/data_flow_scalar_replace.c index fa3e72b4f..b7eab3b4b 100644 --- a/ir/opt/data_flow_scalar_replace.c +++ b/ir/opt/data_flow_scalar_replace.c @@ -27,11 +27,10 @@ #include "config.h" #endif -#ifdef HAVE_STRING_H +#include "iroptimize.h" + #include -#endif -#include "data_flow_scalar_replace.h" #include "irflag_t.h" #include "irouts.h" #include "pset.h" @@ -241,7 +240,7 @@ static int is_const_sel(ir_node *sel) { * Returns non-zero, if the address of an entity * represented by a Sel node (or it's successor Sels) is taken. */ -static int is_address_taken(ir_node *sel) +static int is_address_taken_2(ir_node *sel) { int i; @@ -264,7 +263,7 @@ static int is_address_taken(ir_node *sel) case iro_Sel: { /* Check the Sel successor of Sel */ - int res = is_address_taken(succ); + int res = is_address_taken_2(succ); if (res) return 1; @@ -395,7 +394,7 @@ static int find_possible_replacements(ir_graph *irg) /* we can handle arrays, structs and atomic types yet */ if (is_Array_type(ent_type) || is_Struct_type(ent_type) || is_atomic_type(ent_type)) { - if (is_address_taken(succ)) { + if (is_address_taken_2(succ)) { if (get_entity_link(ent)) /* killing one */ --res; set_entity_link(ent, ADDRESS_TAKEN); diff --git a/ir/opt/data_flow_scalar_replace.h b/ir/opt/data_flow_scalar_replace.h deleted file mode 100644 index bd2ef310f..000000000 --- a/ir/opt/data_flow_scalar_replace.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief scalar replacement of compounds - * @author Beyhan Veliev - * @version $Id$ - */ -#ifndef FIRM_OPT_DATA_FLOW_SCALAR_REPLACE_H -#define FIRM_OPT_DATA_FLOW_SCALAR_REPLACE_H - -#include "irgraph.h" - -/** - * Do the scalar replacement optimization. - * Make a date flow analyze and split the - * data flow edges. - * - * @param irg the graph which should be optimized - */ -void data_flow_scalar_replacement_opt(ir_graph *irg); - -#endif diff --git a/ir/opt/escape_ana.c b/ir/opt/escape_ana.c index 61c6e8885..e0f13f915 100644 --- a/ir/opt/escape_ana.c +++ b/ir/opt/escape_ana.c @@ -33,11 +33,12 @@ * * A fast and simple Escape analysis. */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include "iroptimize.h" + #include "irgraph_t.h" #include "irnode_t.h" #include "type_t.h" @@ -46,7 +47,6 @@ #include "analyze_irg_args.h" #include "irgmod.h" #include "ircons.h" -#include "escape_ana.h" #include "debug.h" /** diff --git a/ir/opt/escape_ana.h b/ir/opt/escape_ana.h deleted file mode 100644 index 95e880755..000000000 --- a/ir/opt/escape_ana.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief escape analysis and optimization - * @author Michael Beck - * @date 03.11.2005 - * @version $Id$ - */ -#ifndef FIRM_OPT_IR_OPT_ESCAPE_ANA_H -#define FIRM_OPT_IR_OPT_ESCAPE_ANA_H - -#include "firm_types.h" - -/** - * A callback that checks whether a entity is an allocation - * routine. - */ -typedef int (*check_alloc_entity_func)(ir_entity *ent); - -/** - * Do simple and fast escape analysis for one graph. - * - * @param irg the graph - * @param callback a callback function to check whether a - * given entity is a allocation call - */ -void escape_enalysis_irg(ir_graph *irg, check_alloc_entity_func callback); - -/** - * Do simple and fast escape analysis for all graphs. - * - * This optimization implements a simple and fast but inexact - * escape analysis. Some addresses might be marked as 'escaped' even - * if they are not. - * The advantage is a low memory footprint and fast speed. - * - * @param run_scalar_replace if this flag in non-zero, scalar - * replacement optimization is run on graphs with removed - * allocation - * @param callback a callback function to check whether a - * given entity is a allocation call - * - * This optimization removes allocation which are not used (rare) and replace - * allocation that can be proved dead at the end of the graph which stack variables. - * - * The creation of stack variable allows scalar replacement to be run only - * on those graphs that have been changed. - * - * This is most effective on Java where no other stack variables exists. - */ -void escape_analysis(int run_scalar_replace, check_alloc_entity_func callback); - -#endif diff --git a/ir/opt/funccall.c b/ir/opt/funccall.c index e45a68da3..9c5b1569b 100644 --- a/ir/opt/funccall.c +++ b/ir/opt/funccall.c @@ -27,6 +27,8 @@ #include "config.h" #endif +#include "iroptimize.h" + #include "irnode_t.h" #include "irgraph_t.h" #include "irgmod.h" @@ -35,7 +37,6 @@ #include "dbginfo_t.h" #include "irflag_t.h" #include "ircons.h" -#include "funccall.h" #include "irhooks.h" /** diff --git a/ir/opt/funccall.h b/ir/opt/funccall.h deleted file mode 100644 index fc0636d95..000000000 --- a/ir/opt/funccall.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Optimization of function calls. - * @author Michael Beck - * @version $Id$ - */ -#ifndef FIRM_OPT_FUNCCALL_H -#define FIRM_OPT_FUNCCALL_H - -/** - * Optimize function calls by handling const functions. - * - * This optimization first detects all "const functions", i.e., - * IR graphs that neither read nor write memory (and hence did - * not create exceptions, as these use memory in Firm). - * - * The result of calls to such functions depends only on its - * arguments, hence those calls are no more pinned. - * - * This is a rather strong criteria, so do not expect that a - * lot of functions will be found. Moreover, all of them might - * already be inlined if inlining is activated. - * Anyway, it might be good for handling builtin's or pseudo-graphs, - * even if the later read/write memory (but we know how). - * - * This optimizations read the irg_const_function property of - * entities and and sets the irg_const_function property of - * graphs. - * - * If callee information is valid, we also optimize polymorphic Calls. - * - * @param force_run if non-zero, an optimization run is started even - * if no const function graph was detected. - * Else calls are only optimized if at least one - * const function graph was detected. - * - * If the fontend created external entities with the irg_const_function - * property set, the force_run parameter should be set, else - * should be unset. - * - * @note This optimization destroys the link fields of nodes. - */ -void optimize_funccalls(int force_run); - -#endif /* FIRM_OPT_FUNCCALL_H */ diff --git a/ir/opt/gvn_pre.c b/ir/opt/gvn_pre.c index 927cc4be3..aeddb5887 100644 --- a/ir/opt/gvn_pre.c +++ b/ir/opt/gvn_pre.c @@ -25,13 +25,15 @@ * @version $Id$ * @summary * - * Currently completely broken because our stes so NOT preserve + * Currently completely broken because our sets do NOT preserve * the topological sort! */ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include "iroptimize.h" + #include #include "irgraph_t.h" @@ -47,7 +49,6 @@ #include "ircons.h" #include "irgmod.h" #include "debug.h" -#include "gvn_pre.h" #include "xmalloc.h" /** The debug module handle. */ diff --git a/ir/opt/gvn_pre.h b/ir/opt/gvn_pre.h deleted file mode 100644 index d404a9d41..000000000 --- a/ir/opt/gvn_pre.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Global Value Numbering Partial Redundancy Elimination - * (VanDrunen Hosking 2004) - * @author Michael Beck, Rubino Geiss - * @version $Id$ - */ -#ifndef FIRM_OPT_GVN_PRE_H -#define FIRM_OPT_GVN_PRE_H - -#include "firm_types.h" - -/** - * Does Partial Redundancy Elimination combined with - * Global Value Numbering. - * Can be used to replace place_code() completely. - * - * Based on VanDrunen and Hosking 2004. - * - * @param irg the graph - * - * @note - * Currently completely broken because the used sets do NOT - * preserve the topological sort of its elements. - */ -void do_gvn_pre(ir_graph *irg); - -#endif /* FIRM_OPT_GVN_PRE_H */ diff --git a/ir/opt/ifconv.c b/ir/opt/ifconv.c index 1173ca4df..fd97a4dd3 100644 --- a/ir/opt/ifconv.c +++ b/ir/opt/ifconv.c @@ -30,17 +30,16 @@ #include +#include "iroptimize.h" #include "obst.h" #include "irnode_t.h" #include "cdep.h" #include "ircons.h" -#include "ifconv.h" #include "irdom.h" #include "irgmod.h" #include "irgopt.h" #include "irgwalk.h" #include "irtools.h" -#include "return.h" #include "array.h" #include "xmalloc.h" diff --git a/ir/opt/ifconv.h b/ir/opt/ifconv.h deleted file mode 100644 index 0fea7bfc6..000000000 --- a/ir/opt/ifconv.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/* - * Project: libFIRM - * File name: ir/opt/ifconv.h - * Purpose: If conversion. - * Author: Sebastian Hack. - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1998-2005 Universität Karlsruhe - */ -#ifndef _FIRM_IF_CONV_H -#define _FIRM_IF_CONV_H - -/** - * @file ifconv.h - * - * If conversion. - * @author Sebastian Hack - * @date 10.2.2005 - */ -#include "irnode.h" - -/** - * This function is called to evaluate, if a mux can build - * of the current architecture. - * If it returns non-zero, a mux is created, else the code - * is not modified. - * @param sel A selector of a Cond. - * @param phi_list List of Phi nodes about to be converted (linked via link field) - * @param i First data predecessor involved in if conversion - * @param j Second data predecessor involved in if conversion - */ -typedef int (*arch_allow_ifconv_func)(ir_node *sel, ir_node* phi_list, int i, int j); - -/** - * The parameters structure. - */ -typedef struct _opt_if_conv_info_t { - int max_depth; /**< The maximum depth up to which expressions - are examined when it has to be decided if they - can be placed into another block. */ - arch_allow_ifconv_func allow_ifconv; /**< Evaluator function, if not set all possible Psi - nodes will be created. */ -} opt_if_conv_info_t; - -/** - * Perform If conversion on a graph. - * - * @param irg The graph. - * @param params The parameters for the if conversion. - * - * Cannot handle blocks with Bad control predecessors, so call it after control - * flow optimization. - */ -void opt_if_conv(ir_graph *irg, const opt_if_conv_info_t *params); - -#endif /* _FIRM_IF_CONV_H */ diff --git a/ir/opt/ldst2.c b/ir/opt/ldst2.c index f5ae3a269..f57289a73 100644 --- a/ir/opt/ldst2.c +++ b/ir/opt/ldst2.c @@ -27,6 +27,8 @@ #include "config.h" #endif +#include "iroptimize.h" + #include "array.h" #include "debug.h" #include "ircons.h" @@ -37,9 +39,7 @@ #include "irmemory.h" #include "irnode.h" #include "irnodeset.h" -#include "ldst2.h" #include "obst.h" -#include "return.h" #include "irdump.h" #include "irflag_t.h" diff --git a/ir/opt/ldst2.h b/ir/opt/ldst2.h deleted file mode 100644 index 2908e4b2f..000000000 --- a/ir/opt/ldst2.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief parallelizing Load/Store optimisation - * @author Christoph Mallon - * @version $Id$ - */ -#ifndef LDST2_H -#define LDST2_H - -#include "firm_types.h" - -void opt_ldst2(ir_graph *irg); - -#endif diff --git a/ir/opt/ldstopt.c b/ir/opt/ldstopt.c index b04d247ad..e9724e2ef 100644 --- a/ir/opt/ldstopt.c +++ b/ir/opt/ldstopt.c @@ -27,10 +27,9 @@ # include "config.h" #endif -#ifdef HAVE_STRING_H -# include -#endif +#include +#include "iroptimize.h" #include "irnode_t.h" #include "irgraph_t.h" #include "irmode_t.h" diff --git a/ir/opt/ldstopt.h b/ir/opt/ldstopt.h deleted file mode 100644 index 99718d8a2..000000000 --- a/ir/opt/ldstopt.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Load/Store optimizations. - * @author Michael Beck - * @version $Id$ - */ -#ifndef FIRM_OPT_LDSTOPT_H -#define FIRM_OPT_LDSTOPT_H - -#include "firm_types.h" - -/** Load/Store optimization. - * - * Removes redundant non-volatile Loads and Stores. - * May introduce Bad nodes if exceptional control flow - * is removed. The following cases are optimized: - * - * Load without result: A Load which has only a memory use - * is removed. - * - * Load after Store: A Load after a Store is removed, if - * the Load doesn't have an exception handler OR is in - * the same block as the Store. - * - * Load after Load: A Load after a Load is removed, if the - * Load doesn't have an exception handler OR is in the - * same block as the previous Load. - * - * Store before Store: A Store immediately before another - * Store in the same block is removed, if the Store doesn't - * have an exception handler. - * - * Store after Load: A Store after a Load is removed, if the - * Store doesn't have an exception handler. - */ -void optimize_load_store(ir_graph *irg); - -#endif /* FIRM_OPT_LDSTOPT_H */ diff --git a/ir/opt/loop_unrolling.c b/ir/opt/loop_unrolling.c index dfd7a5832..53f573d0d 100644 --- a/ir/opt/loop_unrolling.c +++ b/ir/opt/loop_unrolling.c @@ -34,12 +34,9 @@ #include "config.h" #endif -#ifdef HAVE_STRING_H #include -#endif - -#include "loop_unrolling.h" +#include "iroptimize.h" #include "irnode_t.h" #include "irgwalk.h" #include "ircons.h" @@ -50,7 +47,7 @@ #include "trouts.h" #include "hashptr.h" #include "pset.h" -#include "strength_red.h" +#include "strength_red_t.h" #include "compute_loop_info.h" #include "irdump.h" #include "irtools.h" diff --git a/ir/opt/loop_unrolling.h b/ir/opt/loop_unrolling.h deleted file mode 100644 index db512bbf0..000000000 --- a/ir/opt/loop_unrolling.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/* - * Project: libFIRM - * File name: ir/opt/loop_unrolling.h - * Purpose: Loop unrolling. - * Author: Beyhan Veliev - * Modified by: - * Created: 16.11.2004 - * CVS-ID: $Id$ - * Copyright: (c) 2004 Universität Karlsruhe - */ - -/** - * @file loop_unrolling.h - * - * Loop unrolling. - * - * @author Beyhan Veliev - */ -#ifndef _LOOP_UNROLLING_H_ -#define _LOOP_UNROLLING_H_ - -#include "irgraph.h" - -/** - * Do Loop unrolling in the given graph. - */ -void optimize_loop_unrolling(ir_graph *irg); - -#endif /* _LOOP_UNROLLING_H_ */ diff --git a/ir/opt/opt_frame.c b/ir/opt/opt_frame.c index 0b9465977..5ea1c4589 100644 --- a/ir/opt/opt_frame.c +++ b/ir/opt/opt_frame.c @@ -30,11 +30,11 @@ #include "config.h" #endif +#include "iroptimize.h" #include "irgraph_t.h" #include "type_t.h" #include "irouts.h" #include "iredges.h" -#include "opt_frame.h" /* * Optimize the frame type of an irg by removing diff --git a/ir/opt/opt_frame.h b/ir/opt/opt_frame.h deleted file mode 100644 index 6237b7d32..000000000 --- a/ir/opt/opt_frame.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Optimize the frame type. - * @date 15.03.2006 - * @author Michael Beck - * @version $Id$ - * @summary - * Optimize the frame type by removing unused type members. - */ -#ifndef FIRM_OPT_FRAME_H -#define FIRM_OPT_FRAME_H - -/** - * @file opt_frame.h - * - * Optimize the frame type by removing unused type members. - */ - -#include "firm_types.h" - -/** - * Optimize the frame type of an irg by removing - * never touched entities. - * - * @param irg The graph whose frame type will be optimized - * - * This function did not change the graph, only it's frame type. - * The layout state of the frame type will be set to layout_undefined - * if entities were removed. - */ -void opt_frame_irg(ir_graph *irg); - -#endif /* FIRM_OPT_FRAME_H */ diff --git a/ir/opt/opt_osr.c b/ir/opt/opt_osr.c index c646988d1..25ce55115 100644 --- a/ir/opt/opt_osr.c +++ b/ir/opt/opt_osr.c @@ -31,7 +31,7 @@ #include "config.h" #endif -#include "opt_osr.h" +#include "iroptimize.h" #include "irgraph.h" #include "ircons.h" #include "irop_t.h" diff --git a/ir/opt/opt_osr.h b/ir/opt/opt_osr.h deleted file mode 100644 index 564d98226..000000000 --- a/ir/opt/opt_osr.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Operator Strength Reduction. - * @date 12.5.2006 - * @author Michael Beck - * @version $Id$ - * @summary - * Implementation of the Operator Strength Reduction algorithm - * by Keith D. Cooper, L. Taylor Simpson, Christopher A. Vick. - */ -#ifndef FIRM_OPT_OPT_OSR_H -#define FIRM_OPT_OPT_OSR_H - -#include "firm_types.h" - -/** Possible flags for the Operator Scalar Replacement. */ -typedef enum osr_flags { - osr_flag_none = 0, /**< no additional flags */ - osr_flag_lftr_with_ov_check = 1, /**< do linear function test replacement - only if no overflow can occur. */ - osr_flag_ignore_x86_shift = 2 /**< ignore Multiplications by 2, 4, 8 */ -} osr_flags; - -/* FirmJNI cannot handle identical enum values... */ - -/** default setting */ -#define osr_flag_default osr_flag_lftr_with_ov_check - -/** - * Do the Operator Scalar Replacement optimization and linear - * function test replacement for loop control. - * Can be switched off using the set_opt_strength_red() flag. - * In that case, only remove_phi_cycles() is executed. - * - * @param irg the graph which should be optimized - * @param flags set of osr_flags - * - * The linear function replacement test is controlled by the flags. - * If the osr_flag_lftr_with_ov_check is set, the replacement is only - * done if do overflow can occur. - * Otherwise it is ALWAYS done which might be insecure. - * - * For instance: - * - * for (i = 0; i < 100; ++i) - * - * might be replaced by - * - * for (i = 0; i < 400; i += 4) - * - * But - * - * for (i = 0; i < 0x7FFFFFFF; ++i) - * - * will not be replaced by - * - * for (i = 0; i < 0xFFFFFFFC; i += 4) - * - * because of overflow. - * - * More bad cases: - * - * for (i = 0; i <= 0xF; ++i) - * - * will NOT be transformed into - * - * for (i = 0xFFFFFFF0; i <= 0xFFFFFFFF; ++i) - * - * although here is no direct overflow. The OV occurs when the ++i - * is executed (and would created an endless loop here!). - * - * For the same reason, a loop - * - * for (i = 0; i <= 9; i += x) - * - * will NOT be transformed because we cannot estimate whether an overflow - * might happen adding x. - * - * Note that i < a + 400 is also not possible with the current implementation - * although this might be allowed by other compilers... - * - * Note further that tests for equality can be handled some simpler (but are not - * implemented yet). - * - * This algorithm destroys the link field of nodes. - */ -void opt_osr(ir_graph *irg, unsigned flags); - -/** - * Removes useless Phi cycles, i.e cycles of Phi nodes with only one - * non-Phi node. - * This is automatically done in opt_osr(), so there is no need to call it - * additionally. - * - * @param irg the graph which should be optimized - * - * This algorithm destroys the link field of nodes. - */ -void remove_phi_cycles(ir_graph *irg); - -#endif /* FIRM_OPT_OPT_OSR_H */ diff --git a/ir/opt/opt_polymorphy.c b/ir/opt/opt_polymorphy.c index c59eaab9d..201f61a56 100644 --- a/ir/opt/opt_polymorphy.c +++ b/ir/opt/opt_polymorphy.c @@ -29,6 +29,7 @@ #include "config.h" #endif +#include "iroptimize.h" #include "irprog_t.h" #include "entity_t.h" #include "type_t.h" diff --git a/ir/opt/opt_polymorphy.h b/ir/opt/opt_polymorphy.h index 72b598b4f..bfe11c14b 100644 --- a/ir/opt/opt_polymorphy.h +++ b/ir/opt/opt_polymorphy.h @@ -30,10 +30,6 @@ #include "firm_types.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * Transform Sel(Alloc)[method] * to SymC[method] under the following conditions: @@ -54,8 +50,4 @@ ir_node *transform_node_Sel(ir_node *node); */ ir_node *transform_node_Load(ir_node *n); -#ifdef __cplusplus -} -#endif - #endif /* FIRM_OPT_OPT_POLYMORPHY_H */ diff --git a/ir/opt/proc_cloning.c b/ir/opt/proc_cloning.c index 1e29e6a1d..7fc28389e 100644 --- a/ir/opt/proc_cloning.c +++ b/ir/opt/proc_cloning.c @@ -35,22 +35,18 @@ #include "config.h" #endif -#ifdef HAVE_STRING_H #include -#endif +#include "iroptimize.h" #include "tv.h" #include "set.h" -#include "entity.h" #include "irprog_t.h" #include "hashptr.h" #include "irgwalk.h" -#include "proc_cloning.h" #include "analyze_irg_args.h" #include "irprintf.h" #include "ircons.h" #include "irouts.h" -#include "mangle.h" #include "irnode_t.h" #include "irtools.h" #include "irgmod.h" diff --git a/ir/opt/proc_cloning.h b/ir/opt/proc_cloning.h deleted file mode 100644 index 2d6711a04..000000000 --- a/ir/opt/proc_cloning.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief procedure cloning - * @author Beyhan Veliev - * @version $Id$ - */ -#ifndef FIRM_OPT_PROC_CLONING_H -#define FIRM_OPT_PROC_CLONING_H - -#include "firm_types.h" - -/** A default threshold. */ -#define DEFAULT_CLONE_THRESHOLD 300 - -/** - * Do procedure cloning. Evaluate a heuristic weight for every - * Call(..., Const, ...). If the weight is bigger than threshold, - * clone the entity and fix the calls. - * - * @param threshold the threshold for cloning - * - * The threshold is an estimation of how many instructions are saved - * when executing a cloned method. If threshold is 0.0, every possible - * call is cloned. - */ -void proc_cloning(float threshold); - -#endif diff --git a/ir/opt/reassoc.c b/ir/opt/reassoc.c index 4e8db32d9..2b3e10ce3 100644 --- a/ir/opt/reassoc.c +++ b/ir/opt/reassoc.c @@ -27,10 +27,10 @@ #include "config.h" #endif +#include "iropt_t.h" #include "irnode_t.h" #include "irgraph_t.h" #include "irmode_t.h" -#include "iropt_t.h" #include "ircons_t.h" #include "irgmod.h" #include "dbginfo.h" diff --git a/ir/opt/reassoc.h b/ir/opt/reassoc.h deleted file mode 100644 index 5047b2b0f..000000000 --- a/ir/opt/reassoc.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/* - * Project: libFIRM - * File name: ir/opt/reassoc.h - * Purpose: Reassociation - * Author: Michael Beck - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1998-2004 Universität Karlsruhe - */ - -/** - * @file reassoc.h - * - * Reassociation optimization. - * Uses the "firm.opt.reassoc" debug space - * - * @author Michael Beck - */ -#ifndef _REASSOC_H_ -#define _REASSOC_H_ - -#include "irgraph.h" - -/** Reassociation. - * - * Applies Reassociation rules to integer expressions. - * Beware: Works only if integer overflow might be ignored, as for C, Java - * and for address expression. - * Works only if Constant folding is activated. - * - * Uses loop information to detect loop-invariant (ie contant - * inside the loop) values. - * - * See Muchnik 12.3.1 Algebraic Simplification and Reassociation of - * Addressing Expressions. - * - * - */ -void optimize_reassociation(ir_graph *irg); - -#endif /* _REASSOC_H_ */ diff --git a/ir/opt/reassoc_t.h b/ir/opt/reassoc_t.h index dec282686..25c200574 100644 --- a/ir/opt/reassoc_t.h +++ b/ir/opt/reassoc_t.h @@ -34,10 +34,10 @@ * * @author Michael Beck */ -#ifndef _REASSOC_T_H_ -#define _REASSOC_T_H_ +#ifndef REASSOC_T_H +#define REASSOC_T_H -#include "reassoc.h" +#include "iroptimize.h" /** * Sets the default reassociation operation for an ir_op_ops. diff --git a/ir/opt/return.c b/ir/opt/return.c index 9cffb1a18..592cc286f 100644 --- a/ir/opt/return.c +++ b/ir/opt/return.c @@ -27,6 +27,7 @@ #include "config.h" #endif +#include "iroptimize.h" #include "irgraph_t.h" #include "ircons_t.h" #include "irnode_t.h" diff --git a/ir/opt/return.h b/ir/opt/return.h deleted file mode 100644 index e83c2844a..000000000 --- a/ir/opt/return.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Normalize returns. - * @author Michael Beck - * @version $Id$ - */ -#ifndef FIRM_OPT_RETURN_H -#define FIRM_OPT_RETURN_H - -#include "firm_types.h" - -/** - * Normalize the Returns of a graph by creating a new End block - * with One Return(Phi). - * This is the preferred input for the if-conversion. - * - * In pseudocode, it means: - * - * if (a) - * return b; - * else - * return c; - * - * is transformed into - * - * if (a) - * res = b; - * else - * res = c; - * return res; - */ -void normalize_one_return(ir_graph *irg); - -/** - * Normalize the Returns of a graph by moving - * the Returns upwards as much as possible. - * This might be preferred for code generation. - * - * In pseudocode, it means: - * - * if (a) - * res = b; - * else - * res = c; - * return res; - * - * is transformed into - * - * if (a) - * return b; - * else - * return c; - */ -void normalize_n_returns(ir_graph *irg); - -#endif /* FIRM_OPT_RETURN_H */ diff --git a/ir/opt/scalar_replace.c b/ir/opt/scalar_replace.c index 7e16e06fd..102532725 100644 --- a/ir/opt/scalar_replace.c +++ b/ir/opt/scalar_replace.c @@ -27,10 +27,9 @@ #include "config.h" #endif -#ifdef HAVE_STRING_H #include -#endif +#include "iroptimize.h" #include "scalar_replace.h" #include "irflag_t.h" #include "irouts.h" diff --git a/ir/opt/scalar_replace.h b/ir/opt/scalar_replace.h index 9313ca7b7..437ef74a6 100644 --- a/ir/opt/scalar_replace.h +++ b/ir/opt/scalar_replace.h @@ -36,13 +36,4 @@ */ int is_address_taken(ir_node *sel); -/** - * Do the scalar replacement optimization. - * Replace local compound entities (like structures and arrays) - * with atomic values if possible. Does not handle classes yet. - * - * @param irg the graph which should be optimized - */ -void scalar_replacement_opt(ir_graph *irg); - #endif /* FIRM_OPT_SCALAR_REPLACE_H */ diff --git a/ir/opt/strength_red.c b/ir/opt/strength_red.c index 804d7b569..13fefd3f2 100644 --- a/ir/opt/strength_red.c +++ b/ir/opt/strength_red.c @@ -34,16 +34,17 @@ #include "config.h" #endif -# include "strength_red.h" - -# include "irouts.h" -# include "irnode_t.h" -# include "irgwalk.h" -# include "irloop_t.h" -# include "ircons.h" -# include "irgmod.h" -# include "irdump_t.h" -# include "firmstat.h" +#include "strength_red_t.h" +#include "iroptimize.h" +#include "irouts.h" +#include "irnode_t.h" +#include "irgwalk.h" +#include "irloop_t.h" +#include "ircons.h" +#include "irgmod.h" +#include "irdump_t.h" +#include "irprintf.h" +#include "firmstat.h" /** Counter for verbose information about optimization. */ @@ -395,9 +396,9 @@ static int reduce(ir_node *reduce_var, induct_var_info *ivi) n_made_new_phis++; if (get_opt_strength_red_verbose() && get_firm_verbosity() > 1) { - printf("The new Phi node is : "); DDMN(ivi->itervar_phi); - printf("reducing operation is : "); DDMN(reduce_var); - printf("in graph : "); DDMG(current_ir_graph); + ir_printf("The new Phi node is : %+F\n", ivi->itervar_phi); + ir_printf("reducing operation is : %+F\n", reduce_var); + ir_printf("in graph : %+F\n", current_ir_graph); } ivi->new_increment = new_r_Mul (current_ir_graph, block_inc, ivi->increment, mul_const, @@ -464,8 +465,8 @@ static int reduce(ir_node *reduce_var, induct_var_info *ivi) get_irn_mode(mul_const)); } if (get_opt_strength_red_verbose() && get_firm_verbosity() > 1) { - printf("\nReducing operation is : "); DDMN(reduce_var); - printf("in graph : "); DDMG(current_ir_graph); + ir_printf("\nReducing operation is : %+F\n", reduce_var); + ir_printf("in graph : %+F\n", current_ir_graph); } return 1; } @@ -504,8 +505,8 @@ static int reduce(ir_node *reduce_var, induct_var_info *ivi) add_const, ivi->new_init); } if (get_opt_strength_red_verbose() && get_firm_verbosity() > 1) { - printf("\nReducing operation is : "); DDMN(reduce_var); - printf("in graph : "); DDMG(current_ir_graph); + ir_printf("\nReducing operation is : %+F\n", reduce_var); + ir_printf("in graph : %+F\n", current_ir_graph); } return 1; } @@ -542,8 +543,8 @@ static int reduce(ir_node *reduce_var, induct_var_info *ivi) ivi->new_init = my_new_r_Sub (current_ir_graph, block_init, ivi->new_init, sub_const); if (get_opt_strength_red_verbose() && get_firm_verbosity() > 1) { - printf("\nReducing operation is : "); DDMN(reduce_var); - printf("in graph : "); DDMG(current_ir_graph); + ir_printf("\nReducing operation is : %+F", reduce_var); + ir_printf("in graph : %+F", current_ir_graph); } return 1; } diff --git a/ir/opt/strength_red.h b/ir/opt/strength_red.h deleted file mode 100644 index 800f12470..000000000 --- a/ir/opt/strength_red.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * - * @file strength_red.h - * - * Project: libFIRM - * File name: ir/opt/strenth_red.h - * Purpose: Strength reduction. - * Author: Beyhan Veliev - * Modified by: - * Created: 22.8.2004 - * CVS-ID: $Id$ - * Copyright: (c) 2004 Universität Karlsruhe - * - * - * - * - */ - - -# ifndef _STRENGTH_RED_H_ -# define _STRENGTH_RED_H_ - -#include "irnode.h" -#include "irgraph.h" -#include "irloop.h" - -/** Performs strength reduction for the passed graph. */ -void reduce_strength(ir_graph *irg); - -/* The information needed for an induction variable */ -# ifndef _STRENGTH_RED_TYP_ -# define _STRENGTH_RED_TYP_ -typedef struct _induct_var_info { - ir_op *operation_code; /**< The opcode of "op" */ - ir_node *increment; /**< The value which increase or decrease the iteration variable. */ - ir_node *init; /**< The start value of the iteration variable. */ - ir_node *op; /**< The operation which increase or decrease the iteration variable. */ - ir_node *itervar_phi; /**< The iteration variable. */ - ir_node *new_phi; /**< The new iteration variable. */ - ir_node *new_increment; /**< The new increment which replace the old one. */ - ir_node *new_init; /**< The new init value of the iteration variable. */ - ir_node *new_op; /**< The new operation that we need after replace. */ - ir_node *new_cmp; /**< The new Cmp which replaces the old one. */ - ir_node *cmp; /**< The Cmp which breaks the loop and compares the iteration variable with a constant. */ - ir_node *cmp_const; /**< The other operand of Cmp. */ - ir_node *cmp_init_block; /**< The initial block of the Cmp. */ - ir_node *reducible_node; /**< The reducible nodes are save here. */ - int is_reducible; /**< To save information if anything is reducible. */ - int phi_pred; /**< To save the value of iteration variable predecessors. */ - int init_pred_pos; /**< To save the position of iteration variable start value. */ - int op_pred_pos; /**< To save the backedge of iteration variable. */ - ir_loop *l_itervar_phi; /**< The loop of the induction variable */ -} induct_var_info; -#endif - -/** If an ir_node is an induction variable return info else return NULL. */ -induct_var_info *is_induction_variable(induct_var_info *info); - -#endif /* _STRENGTH_RED_H_ */ diff --git a/ir/opt/tailrec.c b/ir/opt/tailrec.c index 93d908314..b0402da9d 100644 --- a/ir/opt/tailrec.c +++ b/ir/opt/tailrec.c @@ -28,12 +28,11 @@ # include "config.h" #endif -#ifdef HAVE_STRING_H #include -#endif - #include -#include "tailrec.h" + +#include "iroptimize.h" +#include "scalar_replace.h" #include "array.h" #include "irprog_t.h" #include "irgwalk.h" @@ -44,8 +43,6 @@ #include "ircons.h" #include "irflag.h" #include "trouts.h" -#include "return.h" -#include "scalar_replace.h" #include "irouts.h" #include "irhooks.h" #include "xmalloc.h" diff --git a/ir/opt/tailrec.h b/ir/opt/tailrec.h deleted file mode 100644 index 1f0ca15df..000000000 --- a/ir/opt/tailrec.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Tail-recursion call optimization. - * @date 08.06.2004 - * @author Michael Beck - * @version $Id$ - */ -#ifndef FIRM_OPT_TAILREC_H -#define FIRM_OPT_TAILREC_H - -#include "firm_types.h" - -/** - * Optimizes simple tail-recursion calls by - * converting them into loops. Depends on the flag opt_tail_recursion. - * - * Does not work for Calls that use the exception stuff. - * - * @param irg the graph to be optimized - * - * @return non-zero if the optimization could be applied, 0 else - */ -int opt_tail_rec_irg(ir_graph *irg); - -/* - * Optimize tail-recursion calls for all IR-Graphs. - * Depends on the flag opt_tail_recursion. - */ -void opt_tail_recursion(void); - -# endif /* FIRM_OPT_TAILREC_H */ diff --git a/ir/opt/tropt.c b/ir/opt/tropt.c index 195ac8f47..d2bc5eaef 100644 --- a/ir/opt/tropt.c +++ b/ir/opt/tropt.c @@ -30,12 +30,8 @@ #include -#include "tropt.h" - +#include "iroptimize.h" #include "irprog.h" -#include "mangle.h" - -#include "tr_inheritance.h" #include "irtypeinfo.h" #include "irgwalk.h" #include "irsimpletype.h" diff --git a/ir/opt/tropt.h b/ir/opt/tropt.h deleted file mode 100644 index 3c7dca0dc..000000000 --- a/ir/opt/tropt.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Perform optimizations of the type representation. - * @date 20.4.2005 - * @author Goetz Lindenmaier - * @version $Id$ - */ -#ifndef FIRM_OPT_TROPT_H -#define FIRM_OPT_TROPT_H - -#include "firm_types.h" - -/** This is the type for a method, that returns a pointer type to - * tp. This is needed in the normalization. */ -typedef ir_type *(*gen_pointer_type_to_func)(ir_type *tp); - -/** Insert Casts so that class type casts conform exactly with the type hierarchy. - * - * Formulated in Java, this achieves the following: - * - * For a class hierarchy - * class A {} - * class B extends A {} - * class C extends B {} - * we transforms a cast - * (A)new C() - * to - * (A)((B)new C()). - * - * The algorithm works for Casts with class types, but also for Casts - * with all pointer types that point (over several indirections, - * i.e. ***A) to a class type. Normalizes all graphs. Computes type - * information (@see irtypeinfo.h) if not available. - * Invalidates trout information as new casts are generated. - * - * @param gppt_fct A function that returns a pointer type that points - * to the type given as argument. If this parameter is NULL, a default - * function is used that either uses trout information or performs a O(n) - * search to find an existing pointer type. If it can not find a type, - * generates a pointer type with mode_P_mach and suffix "cc_ptr_tp". - */ -void normalize_irp_class_casts(gen_pointer_type_to_func gppt_fct); - - -/** Insert Casts so that class type casts conform exactly with the type hierarchy - * in given graph. - * - * For more details see normalize_irp_class_casts(). - * - * This transformation requires that type information is computed. @see irtypeinfo.h. - */ -void normalize_irg_class_casts(ir_graph *irg, gen_pointer_type_to_func gppt_fct); - - -/** Optimize casting between class types. - * - * class A { m(); } - * class B extends A { } - * class C extends B {} - * Performs the following transformations: - * C c = (C)(B)(A)(B)new C() --> C c = (C)(B)newC() --> C c = new C() - * (Optimizing downcasts as A a = (A)(B)(new A()) --> A a = new A() can - * be suppressed by setting the flag opt_suppress_downcast_optimization. - * Downcasting A to B might cause an exception. It is not clear - * whether this is modeled by the Firm Cast node, as it has no exception - * outputs.); - * If there is inh_m() that overwrites m() in B: - * ((A) new B()).m() --> (new B()).inh_m() - * Phi((A)x, (A)y) --> (A) Phi (x, y) if (A) is an upcast. - * - * Computes type information if not available. @see irtypeinfo.h. - * Typeinformation is valid after optimization. - * Invalidates trout information. - */ -void optimize_class_casts(void); - -#endif /* FIRM_OPT_TROPT_H */ diff --git a/ir/st/Makefile.in b/ir/st/Makefile.in deleted file mode 100644 index 144a2e155..000000000 --- a/ir/st/Makefile.in +++ /dev/null @@ -1,34 +0,0 @@ -# -# Project: libFIRM -# File name: ir/st/Makefile.in -# Purpose: -# Author: Florian Liekweg, Till Riedel -# Modified by: -# Created: -# CVS-ID: $Id$ -# Copyright: (c) 2001-2003 Universität Karlsruhe -# Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. -# - -top_srcdir := @top_srcdir@ -srcdir = @srcdir@ -topdir = ../.. -subdir := ir/st - -INSTALL_HEADERS = - -SOURCES = $(INSTALL_HEADERS) - -SOURCES += Makefile.in st.c exc.c st.h exc.h bs.h - - -include $(topdir)/MakeRules - -CPPFLAGS += -I$(top_srcdir)/ir/common -I$(top_srcdir)/ir/tr \ - -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/adt \ - -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/tv \ - -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/debug - -include $(top_srcdir)/MakeTargets - -all: subdir.o diff --git a/ir/st/bs.h b/ir/st/bs.h deleted file mode 100644 index d585ecf97..000000000 --- a/ir/st/bs.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Provides a simple bit set. - * @author Florian Liekweg - * @date 4.3.2002 - * @version $Id$ - * @note Not quite complete - */ -#ifndef FIRM_ST_BS_H -#define FIRM_ST_BS_H - -/** - * the type of a bit set - */ -typedef long int bs_t; - -/** set bit in a bit set */ -# define bs_set(bs, i) (bs) |= (0x00000001 << i) - -/** get bit in a bit set */ -# define bs_get(bs, i) (bs) & (0x00000001 << i) - -/** logical AND of two bit sets */ -# define bs_and(bsa, bsb) (bsa) &= (bsb) - -/** logical OR of two bit sets */ -# define bs_or(bsa, bsb) (bsa) |= (bsb) - -/** logical XOR of two bit sets */ -# define bs_xor(bsa, bsb) (bsa) ^= (bsb) - -/** returns TRUE if at least one bit is set */ -# define bs_zro(bs) (0x00000000 != bs) - -#endif diff --git a/ir/st/exc.c b/ir/st/exc.c deleted file mode 100644 index e25334565..000000000 --- a/ir/st/exc.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Helper functions for jack exceptions. - * @author Florian Liekweg - * @date 4.3.2002 - * @version $Id$ - */ - -/** - NAME - exc - PURPOSE - Helper functions for exceptions - S - not quite complete -***/ - -#include -#include "exc.h" - -static char* exc_strings [] = { - "Invalid", /* invalid */ - "Normal", /* normal */ - "Entry", /* entry to region */ - "Exit", /* exit of region */ - "Handler", /* entry to handler */ - "Cont" -}; - - -/* - Return true iff (block b is a handler entry AND a dominates b) OR - (b has a CFG successor that is both a handler entry AND is dominated - by a) -*/ -static bool has_handler (ir_graph *graph, ir_node *b, ir_node *a) -{ - int i = 0; - int n = get_irn_n_outs (b); - ir_node *succ = 0; - - assert (0 && "Wrongly implemented"); - /* must check for _immediate_ dominance !!! */ - - if (is_handler_entry (graph, b) && dominates (graph, a, b)) - return (true); - - for (i = 0; i < n; i ++) - { - succ = get_irn_out (b, i); - - if (has_handler (graph, succ, a)) - return (true); - } - - return (false); -} - -/* - Return true iff the given node represents an exception jump -*/ -static bool is_exc_jmp (ir_node *node) -{ - ir_op *op = get_irn_op (node); - - /* Proj_X (Load), Proj_X (Sto), Proj_X (Div_Int), - Proj_X (Raise), Proj_X (Call), Proj_X (Alloc) */ - if (op == op_Proj) - { - op = get_irn_op (get_Proj_pred (node)); - - assert ((is_fragile_op(get_Proj_pred(node))) && - (op != op_Bad) /*&& (op != op_Unknown)*/ && - (get_irn_mode(node) == mode_X));/* Check for proper Proj attr */ - return (true); - } - else - { - return (false); - } -} - -/* -Return true iff the given node represents a normal cfg jump -*/ -#if 0 -static bool is_cfg_jmp (ir_node *node) -{ - ir_op *op = get_irn_op (node); - - if (op == op_Proj) - { - op = get_irn_op (get_Proj_pred (node)); - - /* Proj_X (Proj_Cmp (Cond)) */ - if (op_Proj == op) - return (true); /* check for op == op_Cmp and op == op_Cond */ - } - - return (false); -} -#endif - -void set_Block_exc(ir_node *n, exc_t exc) { -} - -exc_t get_Block_exc(ir_node *n) { - return 0; -} - - -/* handler handling for Blocks */ -void -set_Block_handler (ir_node *block, ir_node *handler) { - assert (is_Block(block)); - assert (is_Block(handler)); -} - -ir_node * -get_Block_handler (ir_node *block) { - assert (is_Block(block)); - return (NULL); -} - -/* handler handling for Nodes */ -void -set_Node_handler (ir_node *node, ir_node *handler) { - -} - -ir_node * -get_Node_handler (ir_node *node) { - return (NULL); -} - - -/* - Return true iff a new exception region must be left upon entry of this block. - - If all CFG preds of this block are exception jumps, then we must - return true. -*/ -bool is_handler_entry (ir_graph *graph, ir_node *block) -{ - bool is_entry = true; - int i = 0; - int n = get_irn_arity (block); - - if (exc_invalid == get_Block_exc (block)) - { - for (i = 0; (i < n) && (is_entry == true); i ++) - if (is_exc_jmp (get_irn_n (block, i))) - continue; - else - is_entry = false; - - if (true == is_entry) - set_Block_exc (block, exc_handler); - } - - return (exc_handler == get_Block_exc (block)); -} - -/* - Return true iff a new exception region must be started upon entry of this block. - - If this block immediately dominates a handler entry, we must return true. -*/ -bool is_region_entry (ir_graph *graph, ir_node *block) -{ - assert (0 && "Not implemented"); - - if (exc_invalid == get_Block_exc (block)) - { - int i = 0; - int n = get_irn_n_outs (block); - ir_node *succ = 0; - - bool no_handler = true; - - for (i = 0; (i < n) && (no_handler == true); i ++) - { - succ = get_irn_out (block, i); - - if (has_handler (graph, succ, block)) - no_handler = false; - } - - if (false == no_handler) - set_Block_exc (block, exc_region); - } - - return (exc_region == get_Block_exc (block)); - - return (true); -} - -/* - Return true iff this block is part of handler code. - - If this block is dominated by a block for which {@link - is_handler_entry} is true, then this block is part of the handler. -*/ -bool is_handler_block (ir_graph *graph, ir_node *block) -{ - assert (0 && "Not implemented"); - - if (exc_invalid == get_Block_exc (block)) - { - bool no_handler = true; - dom_env_t *env = get_dom_env (graph, block); - int block_index = env->index_a; - bs_t block_mask = 0x00000001 << block_index; - int n_blocks = env->dt->n_blocks; - int i = 0; - - for (i = 0; (i < n_blocks) && (no_handler == true); i ++) - if (0 != (env->dt->masks [i] & block_mask)) /* if dominator */ - if (is_handler_entry (graph, env->dt->blocks [i])) /* is handler entry */ - no_handler = false; - - delete_dom_env (env); - - if (false == no_handler) - set_Block_exc (block, exc_handler); - } - - return (exc_handler == get_Block_exc (block)); -} - -/* - Convert a value of type exc_t to a descriptive string. - Returns a reference to a statically allocated, constant string. -*/ - -const char *exc_to_string (exc_t exc) -{ - int exc_val = (int) exc; - - assert ((0 <= (int) exc_val) && (exc_val < (int) exc_max)); - - return (exc_strings [exc_val]); -} diff --git a/ir/st/exc.h b/ir/st/exc.h deleted file mode 100644 index 1e841ed84..000000000 --- a/ir/st/exc.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Helper functions for jack exceptions. - * @author Florian Liekweg - * @date 4.3.2002 - * @version $Id$ - */ - -/** - NAME - exc - PURPOSE - Helper functions for exceptions - S - not quite complete -***/ - -# include "irnode.h" - -# ifndef _EXC_H_ -# define _EXC_H_ - -# include "st.h" -# include "irop.h" -# include "irouts.h" - -#include - -#ifdef __cplusplus - extern "C" { -#endif - -typedef enum { - exc_invalid = 0, /* not yet computed */ - exc_normal, /* normal CF */ - - /* must push a new exc context at entry of block: */ - exc_region, /* region entry */ - - /* must pop current exc context at EXIT of block */ - exc_exit, /* region exit */ - - /* must pop current exc context at entry of block */ - exc_handler, /* handler entry */ - - exc_max /* maximum value of enum for 'bounds checking' */ -} exc_t; - - - -const char *exc_to_string (exc_t); - -bool is_handler_entry (ir_graph*, ir_node*); -bool is_region_entry (ir_graph*, ir_node*); -bool is_handler_block (ir_graph*, ir_node*); -bool is_cont_entry (ir_graph*, ir_node*); - -void set_Block_exc (ir_node*, exc_t); -exc_t get_Block_exc (ir_node*); - -void set_Node_exc (ir_node*, exc_t); -exc_t get_Node_exc (ir_node*); - -/* handler handling @@@ ajacs specific -- not supported */ -void set_Block_handler (ir_node*, ir_node*); -ir_node* get_Block_handler (ir_node*); - -void set_Node_handler (ir_node*, ir_node*); -ir_node* get_Node_handler (ir_node*); - -#ifdef __cplusplus -} -#endif - -# endif /* def _EXC_H_ */ diff --git a/ir/st/st.c b/ir/st/st.c deleted file mode 100644 index 6065e3c1a..000000000 --- a/ir/st/st.c +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Provide some auxilliary structures for firm graphs. - * @author Florian Liekweg - * @date 26.2.2002 - * @version $Id$ - */ - -/** - NAME - st.h - PURPOSE - provide some auxilliary structures for firm graphs. - S - not quite complete -***/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#ifdef HAVE_STDIO_H -# include -#endif -#ifdef HAVE_STDLIB_H -# include -#endif - -# include "st.h" -# include "irgwalk.h" -# include "xmalloc.h" - -/* init globals: */ -/*static*/ dtree_t *trees = 0; -/* -static dtree_t *last = 0; -*/ - -/* -------------------------------------------------------------------- -* Helper Functions -* -------------------------------------------------------------------- */ -/* - Helper function for get_n_blocks -*/ -static void count_block (ir_node *block, void *env) -{ - int *n = (int*) env; - -# ifdef DEBUG_libfirm - assert (block && "no block"); - assert (env && "no env"); -# endif /* def DEBUG_libfirm */ - - fprintf (stdout, "%s: Block(%p) has # (%i)\n", - __FILE__ ":count_block", (void *)block, *n); - - (*n) ++; -} - -/* - Count the number of blocks in the given graph -*/ -static int get_n_blocks (ir_graph *graph) -{ - int n = 0; - - ir_node *end_block = get_irg_end (graph); - -# ifdef DEBUG_libfirm - assert (graph && "no graph"); - assert (end_block && "no end block"); -# endif /* def DEBUG_libfirm */ - - irg_block_walk (end_block, count_block, NULL, &n); - - fprintf (stdout, "%s: Graph(%p) has (%i) blocks\n", - __FILE__ ":get_n_blocks", (void *)graph, n); - - return (n); -} - -/* - Build an empty dominator relation entry -*/ -static dtree_t *new_dtree (dt_t *tree, ir_graph *graph) -{ - dtree_t *res = (dtree_t*) malloc (sizeof (dtree_t)); - -# ifdef DEBUG_libfirm - assert (res && "no memory for dtree"); -# endif /* def DEBUG_libfirm */ - - res->tree = tree; - res->graph = graph; - res->next = 0; - - return (res); -} - -/* - Build an empty dominator relation -*/ -static dt_t *new_dt (ir_graph *graph) -{ - int n_blocks = get_n_blocks (graph); - - dt_t *res = (dt_t*) malloc (sizeof (dt_t)); - -# ifdef DEBUG_libfirm - assert (n_blocks && "no blocks for dt"); - assert (res && "no memory for dt"); -# endif /* def DEBUG_libfirm */ - - res->n_blocks = n_blocks; - res->graph = graph; - res->blocks = xcalloc(n_blocks, sizeof(res->blocks[0])); - res->idoms = xcalloc(n_blocks, sizeof(res->idoms[0])); - res->masks = xcalloc(n_blocks, sizeof(res->masks[0])); - - assert (res && "no dt"); - - return (res); -} -/* -static void free_dt (dt_t *dt) -{ - free (dt->blocks); dt->blocks = 0; - free (dt->masks); dt->masks = 0; - free (dt); -} -*/ - -/* -------------------------------------------------------------------- -* Private Functions -* -------------------------------------------------------------------- */ - -/* - Given a graph, find its dominator tree in the global list: - - @return The tree, if it exists, and 0 else -*/ -static dt_t *get_dominator_tree (ir_graph *graph) -{ - dtree_t *iter = trees; - -# ifdef DEBUG_libfirm - assert (graph && "no graph"); -# endif /* def DEBUG_libfirm */ - - while ((0 != iter) && (graph != iter->graph)) - iter = iter->next; - - if (0 != iter) - { -# ifdef DEBUG_libfirm - assert ((graph == iter->tree->graph) && "wrong graph"); -# endif /* def DEBUG_libfirm */ - - return (iter->tree); - } - else - { - return (0); - } -} - -/* - Given a dominator tree and a graph, enter the tree into the global list. -*/ -static void add_dominator_tree (dt_t *tree) -{ - dtree_t *dtree = 0; - ir_graph *graph = tree->graph; - -# ifdef DEBUG_libfirm - assert (tree && "no tree" ); - assert (graph && "no graph"); -# endif /* def DEBUG_libfirm */ - - dtree = new_dtree (tree, graph); - -# ifdef VERBOSE_libfirm - fprintf (stdout, "%s: Adding dtree(%p) into trees(%p)\n", - __FILE__ ":" __PRETTY_FUNCTION__, dtree, trees); -# endif /* def VERBOSE_libfirm */ - - /* enter in global list: */ - dtree->next = trees; - trees = dtree; -} - -/* - Get (or create) the index for a given block -*/ -static int get_index (dt_t *dt, ir_node *block) -{ - int i; - -# ifdef DEBUG_libfirm - assert (dt && "no dt"); - assert (block && "no block"); -# endif /* def DEBUG_libfirm */ - - for (i = 0; (i < dt->n_blocks) && (0 != dt->blocks [i]); i ++) - if (block == dt->blocks [i]) - return (i); - - /* not found . . . enter new one: */ - dt->blocks [i] = block; - if (block == get_irg_start_block (dt->graph)) - { - dt->masks [i] = 0x00000001 << i; - -# ifdef VERBOSE_libfirm - fprintf (stdout, "%s: Adding block(%p)[%i] with [%#010lx]\n", - __FILE__ ":" __PRETTY_FUNCTION__, block, i, dt->masks [i]); -# endif /* def VERBOSE_libfirm */ - } - else - { - dt->masks [i] = ~0x00000000; - -# ifdef VERBOSE_libfirm - fprintf (stdout, "%s: Adding block(%p)[%i] with [%#010lx]\n", - __FILE__ ":" __PRETTY_FUNCTION__, block, i, dt->masks [i]); -# endif /* def VERBOSE_libfirm */ - } - - return (i); -} - -/* - Get the bit mask for a block -*/ -static bs_t _get_mask (dt_t*, int); -static bs_t get_mask (dt_t *dt, ir_node *block) -{ - int index = get_index (dt, block); - -# ifdef DEBUG_libfirm - assert (dt && "no dt"); - assert (block && "no block"); -# endif /* def DEBUG_libfirm */ - - return (_get_mask (dt, index)); -} - -/* - Get the bit mask for a block index -*/ -static bs_t _get_mask (dt_t *dt, int index) -{ -# ifdef DEBUG_libfirm - assert (dt && "no dt"); -# endif /* def DEBUG_libfirm */ - - return (dt->masks [index]); -} - -/* - Set the bit mask for a block -*/ -#if 0 -static void _set_mask (dt_t*, int, bs_t); -static void set_mask (dt_t *dt, ir_node *block, bs_t mask) -{ - int index = get_index (dt, block); - -# ifdef DEBUG_libfirm - assert (dt && "no dt"); - assert (block && "no block"); - # endif /* def DEBUG_libfirm */ - - _set_mask (dt, index, mask); -} -#endif -/* - Set the bit mask for a block index -*/ -static void _set_mask (dt_t *dt, int index, bs_t mask) -{ -# ifdef DEBUG_libfirm - assert (dt && "no dt"); -# endif /* def DEBUG_libfirm */ - - dt->masks [index] = mask; -} - -/* - Update the list of dominators of a given block -*/ -typedef struct dt_walk_env_t -{ - dt_t *dt; /* the dominator relation we're building */ - ir_node *start_block; /* need to know the start block of this graph */ - bool changed; /* wether the relation has changed recently */ -} -dt_walk_env_t; - -/* - Helper function for build_dominator_tree -*/ -static void update_dominators (ir_node *block, void *env) -{ - int i; - dt_walk_env_t *w = (dt_walk_env_t*) env; - dt_t *dt = w->dt; - - int block_index = get_index (dt, block); - int n_ins = get_irn_arity (block); - - bs_t old_mask = _get_mask (dt, block_index); - bs_t new_mask = ~0x00000000; - - /* Special handling of Start Block: */ - if (block == w->start_block) - return; - - /* check preds: */ - for (i = 0; i < n_ins; i ++) - { - ir_node *in = get_nodes_block (get_irn_n (block, i)); - bs_t in_mask = get_mask (dt, in); - - new_mask &= in_mask; - } - - /* and remember ourselves: */ - new_mask |= (0x00000001 << block_index); - - if (new_mask != old_mask) - { - w->changed = true; - _set_mask (dt, block_index, new_mask); - -# ifdef VERBOSE_libfirm - fprintf (stdout, "%s: Updating block(%p)[%i] from [%#010lx] to [%#010lx]\n", - __FILE__ ":" __PRETTY_FUNCTION__, - block, block_index, old_mask, new_mask); -# endif /* def VERBOSE_libfirm */ - } -} - -/* - Say wether a dominates b -*/ - -static bool _dominates (dt_t *dt, ir_node *a, ir_node *b) -{ - int index_a = get_index (dt, a); - bs_t b_mask = get_mask (dt, b); - - return (0 != (b_mask & (0x00000001 << index_a))); -} - -/* - Return the immediate dominator of block a -*/ -static ir_node *_get_idom (dt_t *dt, ir_node *block) -{ - ir_node *idom = 0; - int block_index = get_index (dt, block); - - if (0 != (idom = dt->idoms [block_index])) - return (idom); - - /* check all CFG preds: - Question: Shouldn't it be good enough to just ask our first CFG - predecessor? */ - { - int i = 0; - int n = get_irn_arity (block); - ir_node *pred = 0; - - idom = block; /* prime the loop: */ - - for (i = 0; i < n; i ++) - { - ir_node *ndom = 0; - - pred = get_nodes_block (get_irn_n (block, i)); - ndom = _get_idom (dt, pred); - - if (ndom != idom) - if (_dominates (dt, idom, ndom)) - idom = ndom; - } - } - - assert (idom && "Something terribly wrong in _get_idom"); - -# ifdef VERBOSE_libfirm - fprintf (stdout, "%s: idom(%p) = %p\n", - __FILE__ ":" __PRETTY_FUNCTION__, - block, idom); -# endif /* def VERBOSE_libfirm */ - - /* remember it: */ - dt->idoms [block_index] = idom; - - return (idom); -} - -/* -------------------------------------------------------------------- -* Public Functions -* -------------------------------------------------------------------- */ - -/* - Say wether a dominates b -*/ -bool dominates (ir_graph *g, ir_node *a, ir_node *b) -{ - dt_t *dt = get_dominator_tree (g); - - return (_dominates (dt, a, b)); -} - -/* - Return the immediate dominator of block a -*/ -ir_node *get_idom (ir_graph *g, ir_node *a) -{ - dt_t *dt = get_dominator_tree (g); - - return (_get_idom (dt, a)); -} - -/* - Allow for precomputation of necessary data - This will allow for a slightly faster lookup of the dominator - relation if one node is checked for dominance against many other nodes. -*/ -dom_env_t *get_dom_env (ir_graph *graph, ir_node *a) -{ - dom_env_t *env = xcalloc(1, sizeof(*env)); - - env->graph = graph; - env->dt = get_dominator_tree (graph); - env->a = a; - env->index_a = get_index (env->dt, a); - return env; -} - -/* - Dispose a dominator environment -*/ -void delete_dom_env (dom_env_t *env) -{ - env->dt = 0; - env->a = 0; - env->graph = 0; - env->index_a = -1; - - free (env); -} - -/* - Say wether the node in env dominates b - - see get_dom_env -*/ -bool dominates_l (dom_env_t *env, ir_node *b) -{ - int index_a = env->index_a; - dt_t *dt = env->dt; - bs_t b_mask = get_mask (dt, b); - - return (0 != (b_mask & (0x00000001 << index_a))); -} - -/* - Build a new dominator tree for the given graph -*/ -void build_dominator_tree (ir_graph *graph) -{ - /* - dt_walk_env_t *w = (dt_walk_env_t*) alloca (sizeof (dt_walk_env_t)); - - ir_node *end_block = get_irg_end_block (graph); - ir_node *start_block = get_irg_start_block (graph); - int n_blocks = get_n_blocks (graph); - dt_t *dt = get_dominator_tree (graph); - */ - - dt_walk_env_t *w = 0; - ir_node *end_block = 0; - ir_node *start_block = 0; - int n_blocks = 0; - dt_t *dt = 0; - - w = (dt_walk_env_t*) alloca (sizeof (dt_walk_env_t)); - end_block = get_irg_end_block (graph); - start_block = get_irg_start_block (graph); - n_blocks = get_n_blocks (graph); - dt = get_dominator_tree (graph); - -# ifdef DEBUG_libfirm - assert (graph && "no graph"); -# endif /* def DEBUG_libfirm */ - -# ifdef VERBOSE_libfirm - fprintf (stdout, "%s: for graph(%p)\n", __FILE__ ":" __PRETTY_FUNCTION__, graph); -# endif /* def VERBOSE_libfirm */ - - /*if (0 != dt) - free_dt (dt); */ - - dt = new_dt (graph); - - w->dt = dt; - w->start_block = start_block; - w->changed = true; /* at least one walk */ - - /* do the walk: */ - { - int walks = 0; - - while (w->changed) - { - w->changed = false; - irg_block_walk (end_block, update_dominators, update_dominators, (void*) w); - walks ++; - } - -# ifdef VERBOSE_libfirm - fprintf (stdout, "%s: for graph(%p): %i passes\n", - __FILE__ ":" __PRETTY_FUNCTION__, graph, walks); -# endif /* def VERBOSE_libfirm */ - } - - /* ok, now remember it: */ - add_dominator_tree (dt); -} diff --git a/ir/st/st.h b/ir/st/st.h deleted file mode 100644 index 964132951..000000000 --- a/ir/st/st.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Provide some auxilliary structures for firm graphs. - * @author Florian Liekweg - * @date 26.2.2002 - * @version $Id$ - * @note not quite complete - */ -#ifndef FIRM_ST_ST_H -#define FIRM_ST_ST_H - -/* Includes: */ -#include "irgraph.h" -#include "irnode.h" - -#include "bs.h" - -#include - - -/* Data Types: */ - -/** One dominator tree */ -typedef struct -{ - int n_blocks; - ir_graph *graph; /**< PRE */ - ir_node **blocks; - ir_node **idoms; /**< idom [n] == immediate dominator of blocks [n] */ - bs_t *masks; -} -dt_t; - -/** List entry. */ -typedef struct dtree_t -{ - dt_t *tree; - ir_graph *graph; - - struct dtree_t *next; -} -dtree_t; - -/** dominator environment for a node dom_env_t::a in graph dom_env_t::graph */ -typedef struct dom_env_t -{ - dt_t *dt; - ir_graph *graph; - ir_node *a; - int index_a; - bs_t mask; -} dom_env_t; - -/* Forwards for Globals: */ -extern dtree_t *trees; -extern dtree_t *last; - -/* Prototypes: */ -void st_build_dominator_tree (ir_graph*); -bool dominates (ir_graph*, ir_node*, ir_node*); -ir_node *get_idom (ir_graph*, ir_node*); - -dom_env_t *get_dom_env (ir_graph*, ir_node*); -void delete_dom_env (dom_env_t*); -bool dominates_l (dom_env_t*, ir_node*); - -#endif diff --git a/ir/tr/entity.c b/ir/tr/entity.c index 3acca6937..fdc465dfd 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -27,22 +27,14 @@ # include "config.h" #endif -#ifdef HAVE_STRING_H -# include -#endif -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STDDEF_H -# include -#endif +#include +#include +#include #include "firm_common_t.h" #include "xmalloc.h" #include "entity_t.h" -#include "mangle.h" -#include "typegmod.h" #include "array.h" #include "irtools.h" #include "irhooks.h" @@ -623,7 +615,6 @@ ir_node *copy_const_value(dbg_info *dbg, ir_node *n) { case iro_Unknown: nn = new_d_Unknown(m); break; default: - DDMN(n); assert(0 && "opcode invalid or not implemented"); nn = NULL; break; diff --git a/ir/tr/entity.h b/ir/tr/entity.h deleted file mode 100644 index ec77b40af..000000000 --- a/ir/tr/entity.h +++ /dev/null @@ -1,648 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/* - * Project: libFIRM - * File name: ir/tr/entity.h - * Purpose: Representation of all program known entities. - * Author: Martin Trapp, Christian Schaefer - * Modified by: Goetz Lindenmaier, Michael Beck - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1998-2006 Universität Karlsruhe - */ - -/** - * @file entity.h - * @brief Representation of all program known entities. - * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck - * @version $Id$ - * @summary - * - * An entity is the representation of program known objects in Firm. - * The primary concept of entities is to represent members of complex - * types, i.e., fields and methods of classes. As not all programming - * language model all variables and methods as members of some class, - * the concept of entities is extended to cover also local and global - * variables, and arbitrary procedures. - * - * An entity always specifies the type of the object it represents and - * the type of the object it is a part of, the owner of the entity. - * Originally this is the type of the class of which the entity is a - * member. - * The owner of local variables is the procedure they are defined in. - * The owner of global variables and procedures visible in the whole - * program is a universally defined class type "GlobalType". The owner - * of procedures defined in the scope of an other procedure is the - * enclosing procedure. - * - * @link ir_entity - */ -#ifndef FIRM_TR_ENTITY_H -#define FIRM_TR_ENTITY_H - -#include "firm_types.h" -#include "dbginfo.h" - -#include "tr_inheritance.h" - -/*-----------------------------------------------------------------*/ -/* ENTITY */ -/*-----------------------------------------------------------------*/ - -/** - * @page ir_entity Representation of an program entity. - * - * The type ir_entity is an abstract data type to represent program entities. - * If contains the following attributes: - * - * - owner: A compound type this entity is a part of. - * - type: The type of this entity. - * - name: The string that represents this entity in the source program. - * - allocation: A flag saying whether the entity is dynamically or statically - * allocated (values: dynamic_allocated, static_allocated, - * automatic_allocated). - * - visibility: A flag indicating the visibility of this entity (values: local, - * external_visible, external_allocated) - * - variability: A flag indicating the variability of this entity (values: - * uninitialized, initialized, part_constant, constant) - * - volatility: @@@ - * - offset: The offset of the entity within the compound object in bytes. Only set - * if the owner in the state "layout_fixed". - * - offset_bits_remainder: The offset bit remainder of a bitfield entity (in a compound) - * in bits. Only set if the owner in the state "layout_fixed". - * - overwrites: A list of entities overwritten by this entity. This list is only - * existent if the owner of this entity is a class. The members in - * this list must be entities of super classes. - * - overwrittenby: A list of entities that overwrite this entity. This list is only - * existent if the owner of this entity is a class. The members in - * this list must be entities of sub classes. - * - link: A void* to associate some additional information with the entity. - * - irg: If the entity is a method this is the ir graph that represents the - * code of the method. - * - peculiarity: The peculiarity of the entity. If the entity is a method this - * indicates whether the entity represents - * a real method or whether it only exists to describe an interface. - * In that case there nowhere exists code for this entity and this entity - * is never dynamically used in the code. - * Values: description, existent. Default: existent. - * - visited: visited flag. Master flag is type_visited. - * - * These fields can only be accessed via access functions. - * - * @see ir_type - */ - -/* to resolve recursion between entity.h and type.h */ -/** the type of an entity */ -#ifndef _ENTITY_TYPEDEF_ -#define _ENTITY_TYPEDEF_ -typedef struct ir_entity ir_entity, entity; -#endif - -/** - * Creates a new entity. - * - * Automatically inserts the entity as a member of owner. - * Entity is automatic_allocated and uninitialized except if the type - * is type_method, then it is static_allocated and constant. The constant - * value is a pointer to the method. - * Visibility is local, offset -1, and it is not volatile. - */ -ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp); - -/** - * Creates a new entity. - * - * Automatically inserts the entity as a member of owner. - * The entity is automatic allocated and uninitialized except if the type - * is type_method, then it is static allocated and constant. The constant - * value is a pointer to the method. - * Visibility is local, offset -1, and it is not volatile. - */ -ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *tp, dbg_info *db); - -/** - * Copies the entity if the new_owner is different from the - * owner of the old entity, else returns the old entity. - * - * Automatically inserts the new entity as a member of owner. - * Resets the overwrites/overwritten_by fields. - * Keeps the old atomic value. - * @@@ Maybe we should change this. If peculiarity of a method - * is existent, we should add a new SymConst that points to - * itself and not to the origin. Right now we have to change - * the peculiarity and then set a new atomic value by hand. - */ -ir_entity *copy_entity_own(ir_entity *old, ir_type *new_owner); - -/** - * Copies the entity if the new_name is different from the - * name of the old entity, else returns the old entity. - * - * Automatically inserts the new entity as a member of owner. - * The mangled name ld_name is set to NULL. - * Overwrites relation is copied from old. - */ -ir_entity *copy_entity_name(ir_entity *old, ident *new_name); - -/** - * Frees the entity. - * - * The owner will still contain the pointer to this - * entity, as well as all other references! - */ -void free_entity(ir_entity *ent); - -/** Returns the name of an entity. */ -const char *get_entity_name(const ir_entity *ent); - -/** Returns the ident of an entity. */ -ident *get_entity_ident(const ir_entity *ent); - -/** Sets the ident of the entity. */ -void set_entity_ident(ir_entity *ent, ident *id); - -/** Returns the mangled name of the entity. - * - * If the mangled name is set it returns the existing name. - * Else it generates a name with mangle_entity() - * and remembers this new name internally. - */ -ident *get_entity_ld_ident(ir_entity *ent); - -/** Sets the mangled name of the entity. */ -void set_entity_ld_ident(ir_entity *ent, ident *ld_ident); - -/** Returns the mangled name of the entity as a string. */ -const char *get_entity_ld_name(ir_entity *ent); - -/** Returns the owner of the entity. */ -ir_type *get_entity_owner(ir_entity *ent); - -/** Sets the owner field in entity to owner. Don't forget to add - ent to owner!! */ -void set_entity_owner(ir_entity *ent, ir_type *owner); - -/** Returns the type of an entity. */ -ir_type *get_entity_type(ir_entity *ent); - -/** Sets the type of an entity. */ -void set_entity_type(ir_entity *ent, ir_type *tp); - -/** The allocation type. */ -typedef enum { - allocation_automatic, /**< The entity is allocated during runtime, implicitly - as component of a compound type. This is the default. */ - allocation_parameter, /**< The entity is a parameter. It is also automatic allocated. - We distinguish the allocation of parameters from the allocation - of local variables as their placement depends on the calling - conventions. */ - allocation_dynamic, /**< The entity is allocated during runtime, explicitly - by an Alloc node. */ - allocation_static /**< The entity is allocated statically. We can use a - Const as address of the entity. This is the default for methods. */ -} ir_allocation; - -/** Returns the allocation type of an entity. */ -ir_allocation get_entity_allocation(const ir_entity *ent); - -/** Sets the allocation type of an entity. */ -void set_entity_allocation(ir_entity *ent, ir_allocation al); - -/** Return the name of the allocation type. */ -const char *get_allocation_name(ir_allocation vis); - -/** Returns the visibility of an entity. */ -ir_visibility get_entity_visibility(const ir_entity *ent); - -/** Sets the visibility of an entity. */ -void set_entity_visibility(ir_entity *ent, ir_visibility vis); - -/** Return the name of the visibility */ -const char *get_visibility_name(ir_visibility vis); - -/** This enumeration flags the variability of entities. */ -typedef enum { - variability_uninitialized, /**< The content of the entity is completely unknown. Default. */ - variability_initialized, /**< After allocation the entity is initialized with the - value given somewhere in the entity. */ - variability_part_constant, /**< For entities of compound types. - The members of the entity are mixed constant, - initialized or uninitialized. */ - variability_constant /**< The entity is constant. */ -} ir_variability; - -/** Returns the variability of an entity. */ -ir_variability get_entity_variability(const ir_entity *ent); - -/** Sets the variability of an entity. */ -void set_entity_variability(ir_entity *ent, ir_variability var); - -/** Return the name of the variability. */ -const char *get_variability_name(ir_variability var); - -/** This enumeration flags the volatility of entities. */ -typedef enum { - volatility_non_volatile, /**< The entity is not volatile. Default. */ - volatility_is_volatile /**< The entity is volatile */ -} ir_volatility; - -/** Returns the volatility of an entity. */ -ir_volatility get_entity_volatility(const ir_entity *ent); - -/** Sets the volatility of an entity. */ -void set_entity_volatility(ir_entity *ent, ir_volatility vol); - -/** Return the name of the volatility. */ -const char *get_volatility_name(ir_volatility var); - -/** This enumeration flags the stickyness of an entity. */ -typedef enum { - stickyness_unsticky, /**< The entity can be removed from - the program, unless contraindicated - by other attributes. Default. */ - stickyness_sticky /**< The entity must remain in the - program in any case. */ -} ir_stickyness; - -/** Get the entity's stickyness. */ -ir_stickyness get_entity_stickyness(const ir_entity *ent); - -/** Set the entity's stickyness. */ -void set_entity_stickyness(ir_entity *ent, ir_stickyness stickyness); - -/** Returns the offset of an entity (in a compound) in bytes. Only set if layout = fixed. */ -int get_entity_offset(const ir_entity *ent); - -/** Sets the offset of an entity (in a compound) in bytes. */ -void set_entity_offset(ir_entity *ent, int offset); - -/** Returns the offset bit remainder of a bitfield entity (in a compound) in bits. Only set if layout = fixed. */ -unsigned char get_entity_offset_bits_remainder(const ir_entity *ent); - -/** Sets the offset bit remainder of a bitfield entity (in a compound) in bits. */ -void set_entity_offset_bits_remainder(ir_entity *ent, unsigned char offset); - -/** Returns the stored intermediate information. */ -void *get_entity_link(const ir_entity *ent); - -/** Stores new intermediate information. */ -void set_entity_link(ir_entity *ent, void *l); - -/* -- Fields of method entities -- */ -/** The entity knows the corresponding irg if the entity is a method. - This allows to get from a Call to the called irg. - Only entities of peculiarity "existent" can have a corresponding irg, - else the field is fixed to NULL. (Get returns NULL, set asserts.) */ -ir_graph *get_entity_irg(const ir_entity *ent); -void set_entity_irg(ir_entity *ent, ir_graph *irg); - -/** Gets the entity vtable number. */ -unsigned get_entity_vtable_number(const ir_entity *ent); - -/** Sets the entity vtable number. */ -void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number); - -/** Return the peculiarity of an entity. */ -ir_peculiarity get_entity_peculiarity(const ir_entity *ent); - -/** Sets the peculiarity of an entity. */ -void set_entity_peculiarity(ir_entity *ent, ir_peculiarity pec); - -/** Checks if an entity cannot be overridden anymore. */ -int is_entity_final(const ir_entity *ent); - -/** Sets/resets the final flag of an entity. */ -void set_entity_final(ir_entity *ent, int final); - -/** Checks if an entity is compiler generated. */ -int is_entity_compiler_generated(const ir_entity *ent); - -/** Sets/resets the compiler generated flag. */ -void set_entity_compiler_generated(ir_entity *ent, int flag); - -/** - * The state of the address_taken flag. - */ -typedef enum { - ir_address_not_taken = 0, /**< The address is NOT taken. */ - ir_address_taken_unknown = 1, /**< The state of the address taken flag is unknown. */ - ir_address_taken = 2 /**< The address IS taken. */ -} ir_address_taken_state; - -/** Return the state of the address taken flag of an entity. */ -ir_address_taken_state get_entity_address_taken(const ir_entity *ent); - -/** Sets/resets the state of the address taken flag of an entity. */ -void set_entity_address_taken(ir_entity *ent, ir_address_taken_state flag); - -/** Return the name of the address_taken state. */ -const char *get_address_taken_state_name(ir_address_taken_state state); - -/* -- Representation of constant values of entities -- */ -/** - * Returns true if the the node is representable as code on - * const_code_irg. - * - * @deprecated This function is not used by libFirm and stays here - * only as a helper for the old Jack frontend. - */ -int is_irn_const_expression(ir_node *n); - -/** - * Copies a Firm subgraph that complies to the restrictions for - * constant expressions to current_block in current_ir_graph. - * - * @param dbg debug info for all newly created nodes - * @param n the node - * - * Set current_ir_graph to get_const_code_irg() to generate a constant - * expression. - */ -ir_node *copy_const_value(dbg_info *dbg, ir_node *n); - -/* Set has no effect for existent entities of type method. */ -ir_node *get_atomic_ent_value(ir_entity *ent); -void set_atomic_ent_value(ir_entity *ent, ir_node *val); - -/** - * The following type describes a path to a leave in the compound graph. - * Node 0 in the path must be an entity of type tp given in the constructor. If - * the type of this element is compound, the path node 1 is an element of the type - * of node 0 an so forth, until an entity of atomic type is reached. - */ -#ifndef _COMPOUND_GRAPH_PATH_TYPEDEF_ -#define _COMPOUND_GRAPH_PATH_TYPEDEF_ -typedef struct compound_graph_path compound_graph_path; -#endif /* _COMPOUND_GRAPH_PATH_TYPEDEF_ */ - -/** Creates a new compound graph path. */ -compound_graph_path *new_compound_graph_path(ir_type *tp, int length); - -/** Returns non-zero if an object is a compound graph path */ -int is_compound_graph_path(const void *thing); - -/** Frees a graph path object */ -void free_compound_graph_path (compound_graph_path *gr); - -/** Returns the length of a graph path */ -int get_compound_graph_path_length(const compound_graph_path *gr); - -ir_entity *get_compound_graph_path_node(const compound_graph_path *gr, int pos); -void set_compound_graph_path_node(compound_graph_path *gr, int pos, ir_entity *node); -int get_compound_graph_path_array_index(const compound_graph_path *gr, int pos); -void set_compound_graph_path_array_index(compound_graph_path *gr, int pos, int index); - -/** Checks whether the path up to pos is correct. If the path contains a NULL, - * assumes the path is not complete and returns non-zero. */ -int is_proper_compound_graph_path(compound_graph_path *gr, int pos); - -/* A value of a compound entity is a pair of a value and the description of the - corresponding access path to the member of the compound. */ -void add_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path); -void set_compound_ent_value_w_path(ir_entity *ent, ir_node *val, compound_graph_path *path, int pos); -/** Returns the number of constant values needed to initialize the entity. - * - * Asserts if the entity has variability_uninitialized. - * */ -int get_compound_ent_n_values(ir_entity *ent); -/** Returns a constant value given the position. */ -ir_node *get_compound_ent_value(ir_entity *ent, int pos); -/** Returns the access path for value at position pos. */ -compound_graph_path *get_compound_ent_value_path(ir_entity *ent, int pos); -/** Returns a constant value given the access path. - * The path must contain array indices for all array element entities. */ -ir_node *get_compound_ent_value_by_path(ir_entity *ent, compound_graph_path *path); - -/** Removes all constant entries where the path ends at value_ent. Does not - free the memory of the paths. (The same path might be used for several - constant entities. */ -void remove_compound_ent_value(ir_entity *ent, ir_entity *value_ent); - -/* Some languages support only trivial access paths, i.e., the member is a - direct, atomic member of the constant entities type. In this case the - corresponding entity can be accessed directly. The following functions - allow direct access. */ - -/** Generates a Path with length 1. - Beware: Has a bad runtime for array elements (O(|array|) and should be - avoided there. Use add_compound_ent_value_w_path() instead and create - the path manually. */ -void add_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member); - -/** Returns the last member in the path */ -ir_entity *get_compound_ent_value_member(ir_entity *ent, int pos); - -/** Sets the path at pos 0 */ -void set_compound_ent_value(ir_entity *ent, ir_node *val, ir_entity *member, int pos); - -/** Initializes the entity ent which must be of a one dimensional - array type with the values given in the values array. - The array must have a lower and an upper bound. Keeps the - order of values. Does not test whether the number of values - fits into the given array size. Does not test whether the - values have the proper mode for the array. */ -void set_array_entity_values(ir_entity *ent, tarval **values, int num_vals); - -/** - * Return the offset in bits from the last byte address. - * - * This requires that the layout of all concerned types is fixed. - * - * @param ent Any entity of compound type with at least pos initialization values. - * @param pos The position of the value for which the offset is requested. - */ -int get_compound_ent_value_offset_bit_remainder(ir_entity *ent, int pos); - -/** Return the overall offset of value at position pos in bytes. - * - * This requires that the layout of all concerned types is fixed. - * Asserts if bit offset is not byte aligned. - * - * @param ent Any entity of compound type with at least pos initialization values. - * @param pos The position of the value for which the offset is requested. - */ -int get_compound_ent_value_offset_bytes(ir_entity *ent, int pos); - -/* --- Fields of entities with a class type as owner --- */ -/* Overwrites is a field that specifies that an access to the overwritten - entity in the supertype must use this entity. It's a list as with - multiple inheritance several entities can be overwritten. This field - is mostly useful for method entities. - If a Sel node selects an entity that is overwritten by other entities it - must return a pointer to the entity of the dynamic type of the pointer - that is passed to it. Lowering of the Sel node must assure this. - Overwrittenby is the inverse of overwrites. Both add routines add - both relations, they only differ in the order of arguments. */ -void add_entity_overwrites (ir_entity *ent, ir_entity *overwritten); -int get_entity_n_overwrites (ir_entity *ent); -int get_entity_overwrites_index(ir_entity *ent, ir_entity *overwritten); -ir_entity *get_entity_overwrites (ir_entity *ent, int pos); -void set_entity_overwrites (ir_entity *ent, int pos, ir_entity *overwritten); -void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten); - -void add_entity_overwrittenby (ir_entity *ent, ir_entity *overwrites); -int get_entity_n_overwrittenby (ir_entity *ent); -int get_entity_overwrittenby_index(ir_entity *ent, ir_entity *overwrites); -ir_entity *get_entity_overwrittenby (ir_entity *ent, int pos); -void set_entity_overwrittenby (ir_entity *ent, int pos, ir_entity *overwrites); -void remove_entity_overwrittenby(ir_entity *ent, ir_entity *overwrites); - -/** - * Checks whether a pointer points to an entity. - * - * @param thing an arbitrary pointer - * - * @return - * true if the thing is an entity, else false - */ -int is_entity (const void *thing); - -/** Returns true if the type of the entity is a primitive, pointer - * enumeration or method type. - * - * @Note This is a different classification than from is_primitive_type(). - */ -int is_atomic_entity(ir_entity *ent); -/** Returns true if the type of the entity is a class, structure, - array or union type. */ -int is_compound_entity(ir_entity *ent); -/** Returns true if the type of the entity is a Method type. */ -int is_method_entity(ir_entity *ent); - -/** Returns non-zero if ent1 and ent2 have are equal except for their owner. - Two entities are equal if - - they have the same type (the same C-struct) - - ...? -*/ -int equal_entity(ir_entity *ent1, ir_entity *ent2); - -/** Outputs a unique number for this entity if libfirm is compiled for - * debugging, (configure with --enable-debug) else returns the address - * of the type cast to long. - */ -long get_entity_nr(const ir_entity *ent); - -/** Returns the entities visited count. */ -unsigned long get_entity_visited(ir_entity *ent); - -/** Sets the entities visited count. */ -void set_entity_visited(ir_entity *ent, unsigned long num); - -/** Sets visited field in entity to entity_visited. */ -void mark_entity_visited(ir_entity *ent); - -/** Returns true if this entity was visited. */ -int entity_visited(ir_entity *ent); - -/** Returns true if this entity was not visited. */ -int entity_not_visited(ir_entity *ent); - -/** - * Returns the mask of the additional entity properties. - * The properties are automatically inherited from the irg if available - * or from the method type if they were not set using - * set_entity_additional_properties() or - * set_entity_additional_property(). - */ -unsigned get_entity_additional_properties(ir_entity *ent); - -/** Sets the mask of the additional graph properties. */ -void set_entity_additional_properties(ir_entity *ent, unsigned property_mask); - -/** Sets one additional graph property. */ -void set_entity_additional_property(ir_entity *ent, mtp_additional_property flag); - -/** Returns the class type that this type info entity represents or NULL - if ent is no type info entity. */ -ir_type *get_entity_repr_class(const ir_entity *ent); - -/** - * @page unknown_entity The Unknown entity - * - * This entity is an auxiliary entity dedicated to support analyses. - * - * The unknown entity represents that there could be an entity, but it is not - * known. This entity can be used to initialize fields before an analysis (not known - * yet) or to represent the top of a lattice (could not be determined). There exists - * exactly one entity unknown. This entity has as owner and as type the unknown type. It is - * allocated when initializing the entity module. - * - * The entity can take the role of any entity, also methods. It returns default - * values in these cases. - * - * The following values are set: - * - * - name = "unknown_entity" - * - ld_name = "unknown_entity" - * - owner = unknown_type - * - type = unknown_type - * - allocation = allocation_automatic - * - visibility = visibility_external_allocated - * - offset = -1 - * - variability = variability_uninitialized - * - value = SymConst(unknown_entity) - * - values = NULL - * - val_paths = NULL - * - peculiarity = peculiarity_existent - * - volatility = volatility_non_volatile - * - stickyness = stickyness_unsticky - * - ld_name = NULL - * - overwrites = NULL - * - overwrittenby = NULL - * - irg = NULL - * - link = NULL - */ -/* A variable that contains the only unknown entity. */ -extern ir_entity *unknown_entity; - -/** Returns the @link unknown_entity unknown entity @endlink. */ -ir_entity *get_unknown_entity(void); - -/** Encodes how a pointer parameter is accessed. */ -typedef enum acc_bits { - ptr_access_none = 0, /**< no access */ - ptr_access_read = 1, /**< read access */ - ptr_access_write = 2, /**< write access */ - ptr_access_rw = ptr_access_read|ptr_access_write, /**< read AND write access */ - ptr_access_store = 4, /**< the pointer is stored */ - ptr_access_all = ptr_access_rw|ptr_access_store /**< all possible access */ -} ptr_access_kind; - -#define IS_READ(a) ((a) & ptr_access_read) -#define IS_WRITTEN(a) ((a) & ptr_access_write) -#define IS_STORED(a) ((a) & ptr_access_store) - -/** - * Supported image sections. - * Currently only methods can be placed in different sections. - */ -typedef enum { - section_text, /**< The code segment. This is the default for methods. */ - section_constructors /**< The constructor section. */ -} ir_img_section; - -/** Returns the section of a method. */ -ir_img_section get_method_img_section(const ir_entity *method); - -/** Sets the section of a method. */ -void set_method_img_section(ir_entity *method, ir_img_section section); - -#endif /* FIRM_TR_ENTITY_H */ diff --git a/ir/tr/entity_t.h b/ir/tr/entity_t.h index b71f4af77..62cf74e01 100644 --- a/ir/tr/entity_t.h +++ b/ir/tr/entity_t.h @@ -26,13 +26,14 @@ #ifndef FIRM_TR_ENTITY_T_H #define FIRM_TR_ENTITY_T_H +#include + #include "firm_common_t.h" #include "firm_config.h" +#include "typerep.h" #include "type_t.h" -#include "entity.h" -#include "typegmod.h" -#include "mangle.h" +#include "ident.h" #include "pseudo_irg.h" /** A path in a compound graph. */ diff --git a/ir/tr/mangle.h b/ir/tr/mangle.h deleted file mode 100644 index 5f0ff1448..000000000 --- a/ir/tr/mangle.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file mangle.h - * @brief Methods to manipulate names. - * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck - * @version $Id$ - */ -#ifndef FIRM_TR_MANGLE_H -#define FIRM_TR_MANGLE_H - -#include "ident.h" -#include "entity.h" - -/** initializes the name mangling code */ -void firm_init_mangle (void); - -/** Computes a definite name for this entity by concatenating - the name of the owner type and the name of the entity with - a separating "_". */ -ident *mangle_entity (ir_entity *ent); - -/** mangle underscore: Returns a new ident that represents first_scnd. */ -ident *mangle_u (ident *first, ident* scnd); - -/** mangle dot: Returns a new ident that represents first.scnd. */ -ident *mangle_dot (ident *first, ident* scnd); - -/** mangle: Returns a new ident that represents firstscnd. */ -ident *mangle (ident *first, ident* scnd); - -/** returns a mangled name for a Win32 function using it's calling convention */ -ident *decorate_win32_c_fkt(ir_entity *ent, ident *id); - -#endif /* FIRM_TR_MANGLE_H */ diff --git a/ir/tr/tpop.h b/ir/tr/tpop.h deleted file mode 100644 index 060e63af2..000000000 --- a/ir/tr/tpop.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Opcode of types. - * @author Goetz Lindenmaier, Michael Beck - * @version $Id$ - * @summary - * - * This module specifies the kinds of types available in firm. - * - * They are called type opcodes. These include classes, structs, methods, unions, - * arrays, enumerations, pointers and primitive types. - * Special types with own opcodes are the id type, a type representing an unknown - * type and a type used to specify that something has no type. - * - * @see type.h - */ -#ifndef FIRM_TR_TPOP_H -#define FIRM_TR_TPOP_H - -#include "ident.h" - -/** - * An enum for the type kinds. - * For each type kind exists a typecode to identify it. - */ -typedef enum { - tpo_uninitialized = 0, /* not a type opcode */ - tpo_class, /**< A class type. */ - tpo_struct, /**< A struct type. */ - tpo_method, /**< A method type. */ - tpo_union, /**< An union type. */ - tpo_array, /**< An array type. */ - tpo_enumeration, /**< An enumeration type. */ - tpo_pointer, /**< A pointer type. */ - tpo_primitive, /**< A primitive type. */ - tpo_id, /**< Special Id tag used for type replacement. */ - tpo_none, /**< Special type for the None type. */ - tpo_unknown, /**< Special code for the Unknown type. */ - tpo_max /* not a type opcode */ -} tp_opcode; - -/** - * A structure containing information about a kind of type. - * A structure containing information about a kind of type. So far - * this is only the kind name, an enum for case-switching and some - * internal values. - * - * @see get_tpop_name(), get_tpop_code(), get_tpop_ident() - */ -typedef struct tp_op tp_op; - - -/** - * Returns the string for the type opcode. - * - * @param op The type opcode to get the string from. - * @return a string. (@todo Null terminated???) - */ -const char *get_tpop_name (const tp_op *op); - -/** - * Returns an enum for the type opcode. - * - * @param op The type opcode to get the enum from. - * @return the enum. - */ -tp_opcode get_tpop_code (const tp_op *op); - -/** - * Returns the ident for the type opcode. - * - * @param op The type opcode to get the ident from. - * @return The ident. - */ -ident *get_tpop_ident (const tp_op *op); - -/** - * This type opcode marks that the corresponding type is a class type. - * - * Consequently the type refers to supertypes, subtypes and entities. - * Entities can be any fields, but also methods. - * @@@ value class or not??? - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_class; -tp_op *get_tpop_class(void); - -/** - * This type opcode marks that the corresponding type is a compound type - * as a struct in C. - * - * Consequently the type refers to a list of entities - * which may not be methods (but pointers to methods). - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_struct; -tp_op *get_tpop_struct(void); - -/** - * This type opcode marks that the corresponding type is a method type. - * - * Consequently it refers to a list of arguments and results. - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_method; -tp_op *get_tpop_method(void); - -/** - * This type opcode marks that the corresponding type is a union type. - * - * Consequently it refers to a list of unioned types. - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_union; -tp_op *get_tpop_union(void); - -/** - * This type opcode marks that the corresponding type is an array type. - * - * Consequently it contains a list of dimensions (lower and upper bounds) - * and an element type. - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_array; -tp_op *get_tpop_array(void); - -/** - * This type opcode marks that the corresponding type is an enumeration type. - * - * Consequently it contains a list of idents for the enumeration identifiers - * and a list of target values that are the constants used to implement - * the enumerators. - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_enumeration; -tp_op *get_tpop_enumeration(void); - -/** - * This type opcode marks that the corresponding type is a pointer type. - * - * It contains a reference to the type the pointer points to. - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_pointer; -tp_op *get_tpop_pointer(void); - -/** - * This type opcode marks that the corresponding type is a primitive type. - * - * Primitive types are types that are directly mapped to target machine - * modes. - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_primitive; -tp_op *get_tpop_primitive(void); - -/** - * This type opcode is an auxiliary opcode dedicated to support transformations - * of the type structure. - * - * If a type is changed to another type with another - * opcode the new type will be allocated with new memory. All nodes refering - * to the old type need to be changed to refer to the new one. This is simplified - * by turning the old type into an id type that merely forwards to the new type - * that now replaces the old one. - * type_ids should never be visible out of the type module. All access routines - * should automatically check for type_id and eventually follow the forward in - * type_id. Two types are exchanged by a call to exchange_types. - * If a type_id is visible externally report this as bug. If it is assured that - * this never happens this extern variable can be moved to tpop_t.h. - * This struct is dynamically allocated but constant for the lifetime - * of the library. - */ -extern tp_op *type_id; -tp_op *get_tpop_id(void); - -/** - * This type opcode is an auxiliary opcode dedicated to support type analyses. - * - * Types with this opcode represents that there is no type. - * The type can be used to initialize fields of the type* that actually can not - * contain a type or that are initialized for an analysis. There exists exactly - * one type with this opcode. - */ -extern tp_op *tpop_none; -tp_op *get_tpop_none(void); - -/** - * This type opcode is an auxiliary opcode dedicated to support type analyses. - * - * Types with this opcode represents that there could be a type, but it is not - * known. This type can be used to initialize fields before an analysis (not known - * yet) or to represent the top of a lattice (could not be determined). There exists - * exactly one type with this opcode. - */ -extern tp_op *tpop_unknown; -tp_op *get_tpop_unknown(void); - -#endif /* FIRM_TR_TPOP_H */ diff --git a/ir/tr/tpop_t.h b/ir/tr/tpop_t.h index 086b04f60..29e7ae616 100644 --- a/ir/tr/tpop_t.h +++ b/ir/tr/tpop_t.h @@ -29,7 +29,7 @@ #include #include "firm_types.h" -#include "tpop.h" +#include "typerep.h" #include "irmode.h" /** A function called to free attributes of a type. */ diff --git a/ir/tr/tr_inheritance.c b/ir/tr/tr_inheritance.c index b8aabd7fe..b03f42e0f 100644 --- a/ir/tr/tr_inheritance.c +++ b/ir/tr/tr_inheritance.c @@ -27,14 +27,12 @@ # include "config.h" #endif -#include "type.h" -#include "entity.h" -#include "typewalk.h" +#include "typerep.h" #include "irgraph_t.h" #include "irprog_t.h" +#include "irprintf.h" #include "pset.h" #include "set.h" -#include "mangle.h" #include "irgwalk.h" #include "irflag.h" @@ -659,10 +657,10 @@ void verify_irn_class_cast_state(ir_node *n, void *env) { } if (!(this_state >= ccs->expected_state)) { - printf(" Node is "); DDMN(n); - printf(" totype "); DDMT(totype); - printf(" fromtype "); DDMT(fromtype); - printf(" this_state: %s, exp. state: %s\n", + ir_printf(" Node is %+F\n", n); + ir_printf(" totype %+F\n", totype); + ir_printf(" fromtype %+F\n", fromtype); + ir_printf(" this_state: %s, exp. state: %s\n", get_class_cast_state_string(this_state), get_class_cast_state_string(ccs->expected_state)); assert(this_state >= ccs->expected_state && @@ -684,8 +682,7 @@ void verify_irg_class_cast_state(ir_graph *irg) { irg_walk_graph(irg, NULL, verify_irn_class_cast_state, &env); if ((env.worst_situation > env.expected_state) && get_firm_verbosity()) { - printf("Note: class cast state is set lower than reqired in graph\n "); - DDMG(irg); + ir_printf("Note: class cast state is set lower than reqired in graph \n\t%+F\n", irg); printf(" state is %s, reqired is %s\n", get_class_cast_state_string(env.expected_state), get_class_cast_state_string(env.worst_situation)); diff --git a/ir/tr/tr_inheritance.h b/ir/tr/tr_inheritance.h deleted file mode 100644 index 73b3d18a1..000000000 --- a/ir/tr/tr_inheritance.h +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file tr_inheritance.h - * @brief Utility routines for inheritance representation - * @author Goetz Lindenmaier - * @version $Id$ - * @summary - * - * This file supplies a set of utility routines for the inheritance - * representation. - * - * Inheritance is represented in Firm by two relations: sub/supertype - * between class types, overwrites/ovwerwrittenby between entities. - * - * - Classify pairs of types/entities in the inheritance relations. - * - Resolve implicit inheritance. - * - Compute the transitive closure of the subclass/superclass and - * overwrites/overwrittenby relation. - * - * @see type.h entity.h - */ -#ifndef FIRM_TR_INHERITANCE_H -#define FIRM_TR_INHERITANCE_H - -#include "firm_types.h" -#include "type.h" -#include "ident.h" - -/* ----------------------------------------------------------------------- */ -/* Classify pairs of types/entities in the inheritance relations. */ -/* ----------------------------------------------------------------------- */ - -/** Returns true if low is subclass of high. - * - * Low is a subclass of high if low == high or if low is a subclass of - * a subclass of high. I.e, we search in all subtypes of high for low. - * @@@ this can be implemented more efficient if we know the set of all - * subclasses of high. */ -int is_SubClass_of(ir_type *low, ir_type *high); - -/** Subclass check for pointers to classes. - * - * Dereferences at both types the same amount of pointer types (as - * many as possible). If the remaining types are both class types - * and subclasses, returns true, else false. Can also be called with - * two class types. */ -int is_SubClass_ptr_of(ir_type *low, ir_type *high); - -/** Returns true if high is superclass of low. - * - * Low is a subclass of high if low == high or if low is a subclass of - * a subclass of high. I.e, we search in all subtypes of high for low. - * @@@ this can be implemented more efficient if we know the set of all - * subclasses of high. */ -#define is_SuperClass_of(high, low) is_SubClass_of(low, high) - -/** Superclass check for pointers to classes. - * - * Dereferences at both types the same amount of pointer types (as - * many as possible). If the remaining types are both class types - * and superclasses, returns true, else false. Can also be called with - * two class types. */ -#define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low) - -/** Returns true if high is (transitive) overwritten by low. - * - * Returns false if high == low. */ -int is_overwritten_by(ir_entity *high, ir_entity *low); - -/** Resolve polymorphism in the inheritance relation. - * - * Returns the dynamically referenced entity if the static entity and the - * dynamic type are given. - * Searches downwards in overwritten tree. */ -ir_entity *resolve_ent_polymorphy(ir_type *dynamic_class, ir_entity* static_ent); - -/* ----------------------------------------------------------------------- */ -/* Resolve implicit inheritance. */ -/* ----------------------------------------------------------------------- */ - -/** Default name mangling for inherited entities. - * - * Returns an ident that consists of the name of type followed by an - * underscore and the name (not ld_name) of the entity. */ -ident *default_mangle_inherited_name(ir_entity *ent, ir_type *clss); - -/** Type of argument functions for inheritance resolver. - * - * @param ent The entity in the super type that will be overwritten - * by the newly generated entity, for which this name is - * used. - * @param clss The class type in which the new entity will be placed. - */ -typedef ident *mangle_inherited_name_func(ir_entity *ent, ir_type *clss); - -/** Resolve implicit inheritance. - * - * Resolves the implicit inheritance supplied by firm. Firm defines, - * that each entity that is not overwritten in a subclass is - * inherited to this subclass without change implicitly. This - * function generates entities that explicitly represent this - * inheritance. It generates for each entity overwriting entities in - * all subclasses of the owner of the entity, if the entity is not - * overwritten in that subclass. - * - * The name of the new entity is generated with the function passed. - * If the function is NULL, the default_mangle_inherited_name() is - * used. - * - * This function was moved here from firmlower 3/2005. - */ -void resolve_inheritance(mangle_inherited_name_func *mfunc); - - -/* ----------------------------------------------------------------------- */ -/* The transitive closure of the subclass/superclass and */ -/* overwrites/overwrittenby relation. */ -/* */ -/* A walk over the ir (O(#types+#entities)) computes the transitive */ -/* closure. Adding a new type/entity or changing the basic relations in */ -/* some other way invalidates the transitive closure, i.e., it is not */ -/* updated by the basic functions. */ -/* */ -/* The transitive edges are held in a set, not in an array as the */ -/* underlying relation. */ -/* */ -/* Do the sets contain the node itself? I assume NOT! */ -/* ----------------------------------------------------------------------- */ - -/** The state of the transitive closure. - * - * @todo: we could manage the state for each relation separately. Invalidating - * the entity relations does not mean invalidating the class relation. */ -typedef enum { - inh_transitive_closure_none, /**< Closure is not computed, can not be accessed. */ - inh_transitive_closure_valid, /**< Closure computed and valid. */ - inh_transitive_closure_invalid, /**< Closure invalid, but can be accessed. */ - inh_transitive_closure_max /**< Invalid value. */ -} inh_transitive_closure_state; - -void set_irp_inh_transitive_closure_state(inh_transitive_closure_state s); -void invalidate_irp_inh_transitive_closure_state(void); -inh_transitive_closure_state get_irp_inh_transitive_closure_state(void); - - -/** Compute transitive closure of the subclass/superclass and - * overwrites/overwrittenby relation. - * - * This function walks over the ir (O(#types+#entities)) to compute the - * transitive closure. */ -void compute_inh_transitive_closure(void); - -/** Free memory occupied by the transitive closure information. */ -void free_inh_transitive_closure(void); - - -/* - subtype ------------------------------------------------------------- */ - -/** Iterate over all transitive subtypes. */ -ir_type *get_class_trans_subtype_first(ir_type *tp); -ir_type *get_class_trans_subtype_next (ir_type *tp); -int is_class_trans_subtype (ir_type *tp, ir_type *subtp); - -/* - supertype ----------------------------------------------------------- */ - -/** Iterate over all transitive supertypes. */ -ir_type *get_class_trans_supertype_first(ir_type *tp); -ir_type *get_class_trans_supertype_next (ir_type *tp); - -/* - overwrittenby ------------------------------------------------------- */ - -/** Iterate over all entities that transitive overwrite this entities. */ -ir_entity *get_entity_trans_overwrittenby_first(ir_entity *ent); -ir_entity *get_entity_trans_overwrittenby_next (ir_entity *ent); - -/* - overwrites ---------------------------------------------------------- */ - -/** Iterate over all transitive overwritten entities. */ -ir_entity *get_entity_trans_overwrites_first(ir_entity *ent); -ir_entity *get_entity_trans_overwrites_next (ir_entity *ent); - - -/* ----------------------------------------------------------------------- */ -/** The state of Cast operations that cast class types or pointers to class - * types. - * - * The state expresses, how far Cast operations conform with the class - * hierarchy. - * - * class A {} - * class B1 extends A {} - * class B2 extends A {} - * class C extends B1 {} - * normalized: Cast operations conform with the inheritance relation. - * I.e., the type of the operand of a Cast is either a super= or a sub- - * type of the type casted to. Example: (A)((B2) (new C())). - * transitive: Cast operations conform with the transitive inheritance - * relation. Example: (A)(new C()). - * any: Cast operations do not conform with the transitive inheritance - * relation. Example: (B2)(new B1()) - * - * @see: tropt.h - */ -/* ----------------------------------------------------------------------- */ - -/** Flags for class cast state. - * - * The state in irp is always smaller or equal to the state of any - * irg. - * - * We rely on the ordering of the enum. */ -typedef enum { - ir_class_casts_any = 0, /**< There are class casts that do not cast in conformance with - the class hierarchy. @@@ So far this does not happen in Firm. */ - ir_class_casts_transitive = 1, /**< Class casts conform to transitive inheritance edges. Default. */ - ir_class_casts_normalized = 2, /**< Class casts conform to inheritance edges. */ - ir_class_casts_state_max -} ir_class_cast_state; -char *get_class_cast_state_string(ir_class_cast_state s); - -void set_irg_class_cast_state(ir_graph *irg, ir_class_cast_state s); -ir_class_cast_state get_irg_class_cast_state(ir_graph *irg); -void set_irp_class_cast_state(ir_class_cast_state s); -ir_class_cast_state get_irp_class_cast_state(void); - -/** Verify the class cast state of an irg. - * - * Asserts if state is to high, outputs warning if state is to low - * and firm verbosity is set. - */ -void verify_irg_class_cast_state(ir_graph *irg); -#endif /* FIRM_TR_INHERITANCE_H */ diff --git a/ir/tr/trvrfy.c b/ir/tr/trvrfy.c index 7a83dc110..33b340a60 100644 --- a/ir/tr/trvrfy.c +++ b/ir/tr/trvrfy.c @@ -28,13 +28,11 @@ #include "config.h" #endif -#include "trvrfy.h" #include "irgraph_t.h" /* for checking whether constant code is allocated on proper obstack */ #include "irflag_t.h" #include "irprintf.h" #include "irgwalk.h" -#include "typewalk.h" static const char *firm_vrfy_failure_msg; diff --git a/ir/tr/trvrfy.h b/ir/tr/trvrfy.h deleted file mode 100644 index 4b38de1ad..000000000 --- a/ir/tr/trvrfy.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file trvrfy.h - * @brief Check types and entities for correctness. - * @date 29.1.2003 - * @author Michael Beck, Goetz Lindenmaier - * @version $Id$ - */ -#ifndef FIRM_TR_TRVRFY_H -#define FIRM_TR_TRVRFY_H - -#include "firm_types.h" - -/** - * possible trvrfy() error codes - */ -enum trvrfy_error_codes { - no_error = 0, /**< no error */ - error_ent_not_cont, /**< overwritten entity not in superclass */ - error_null_mem, /**< compound contains NULL member */ - error_const_on_wrong_irg, /**< constant placed on wrong IRG */ - error_existent_entity_without_irg, /**< Method entities with pecularity_exist must have an irg */ - error_wrong_ent_overwrites, /**< number of entity overwrites exceeds number of class overwrites */ - error_inherited_ent_without_const, /**< inherited method entity not pointing to existent entity */ - error_glob_ent_allocation, /**< wrong allocation of a global entity */ - error_ent_const_mode, /**< Mode of constant in entity did not match entities type. */ - error_ent_wrong_owner /**< Mode of constant in entity did not match entities type. */ -}; - -/** - * Checks a type. - * - * @return - * 0 if no error encountered - */ -int check_type(ir_type *tp); - -/** - * Check an entity. Currently, we check only if initialized constants - * are build on the const irg graph. - * - * @return - * 0 if no error encountered - * != 0 a trvrfy_error_codes code - */ -int check_entity(ir_entity *ent); - -/** - * Walks the type information and performs a set of sanity checks. - * - * Currently, the following checks are executed: - * - values of initialized entities must be allocated on the constant IRG - * - class types: doesn't have NULL members - * - class types: all overwrites are existent in the super type - * - * @return - * 0 if graph is correct - * else error code. - */ -int tr_vrfy(void); - -/** - * If NDEBUG is defined performs nothing, else calls the tr_vrfy() function. - */ -#ifdef NDEBUG -#define TR_VRFY() 0 -#else -#define TR_VRFY() tr_vrfy() -#endif - -#endif /* FIRM_TR_TRVRFY_H */ diff --git a/ir/tr/type.c b/ir/tr/type.c index 5aac7dfb6..b3fde33d0 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -64,8 +64,6 @@ #include "irprog_t.h" #include "ircons.h" #include "tpop_t.h" -#include "typegmod.h" -#include "mangle.h" #include "tv_t.h" #include "irhooks.h" #include "irtools.h" diff --git a/ir/tr/type_identify.c b/ir/tr/type_identify.c index a0a80fbf9..67b80fc6f 100644 --- a/ir/tr/type_identify.c +++ b/ir/tr/type_identify.c @@ -27,7 +27,7 @@ # include "config.h" #endif -#include "type_identify.h" +#include "typerep.h" #include #include @@ -36,10 +36,8 @@ #include "type_t.h" #include "tpop_t.h" #include "irprog_t.h" -#include "typegmod.h" #include "array.h" #include "irprog_t.h" -#include "mangle.h" #include "pset.h" #include "irtools.h" diff --git a/ir/tr/type_identify.h b/ir/tr/type_identify.h deleted file mode 100644 index 0b4612a64..000000000 --- a/ir/tr/type_identify.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file type_identify.h - * @brief Representation of types. - * @author Goetz Lindenmaier - * @version $Id$ - */ -#ifndef FIRM_TR_TYPE_IDENTIFY_H -#define FIRM_TR_TYPE_IDENTIFY_H - -#include "firm_types.h" - -/* ------------------------------------------------------------------------ */ - -/** Type for a function that compares two types. - * - * @param tp1 The first type to compare. - * @param tp2 The second type to compare. - */ -typedef int (compare_types_func_t)(const void *tp1, const void *tp2); - -/** Compares two types by their name. - * - * Compares the opcode and the name of the types. If these are - * equal returns 0, else non-zero. - */ -int compare_names (const void *tp1, const void *tp2); - -/** Compares two types strict. - * - * returns 0 if tp1 == tp2, else non-zero - */ -int compare_strict (const void *tp1, const void *tp2); - -/* ------------------------------------------------------------------------ */ - -/** Type for a function that computes a hash value for a type. - * - * @param tp The type to compute a hash for. - */ -typedef int (hash_types_func_t)(ir_type *tp); - -/** Computes a hash value by the type name. - * - * Uses the name of the type and the type opcode to compute the hash. - */ -int firm_hash_name (ir_type *tp); - -/* ------------------------------------------------------------------------ */ - -/** Finalize type construction. - * - * Indicate that a type is so far completed that it can be - * distinguished from other types. Mature_type hashes the type into a - * table. It uses the function in compare_types_func to compare the - * types. - * - * If it finds a type identical to tp it returns this type. It turns - * tp into the Id type. All places formerly pointing to tp will now - * point to the found type. All entities of tp now refer to the found - * type as their owner, but they are not a member of this type. This - * is invalid firm -- the entities must be replaced by entities of the - * found type. The Id type will be removed from the representation - * automatically, but within an unknown time span. It occupies memory - * for this time. - * - * @param tp The type to mature. - */ -ir_type * mature_type(ir_type *tp); - -/** Finalize type construction. - * - * Indicate that a type is so far completed that it can be - * distinguished from other types. Mature_type hashes the type into a - * table. It uses the function in compare_types_func to compare the - * types. - * - * If it finds a type identical to tp it returns this type. It frees - * type tp and all its entities. - * - * @param tp The type to mature. - */ -ir_type * mature_type_free(ir_type *tp); - -/** Finalize type construction. - * - * Indicate that a type is so far completed that it can be - * distinguished from other types. Mature_type hashes the type into a - * table. It uses the function in compare_types_func to compare the - * types. - * - * If it find a type identical to tp it returns this type. It frees - * the entities and turns the type into an Id type. All places - * formerly pointing to tp will now point to the found type. The Id - * type will be removed from the representation automatically, but - * within an unknown time span. It occupies memory for this time. - * - * @param tp The type to mature. - */ -ir_type * mature_type_free_entities(ir_type *tp); - -/** - * The interface type for the type identify module; - */ -typedef struct _type_identify_if_t { - compare_types_func_t *cmp; /**< The function that should be used to compare two types. - If NULL, compare_strict() will be used. */ - hash_types_func_t *hash; /**< The function that should be used to calculate a hash - value of a type. If NULL, hash_name() will be used. */ -} type_identify_if_t; - -/** - * Initialise the type identifier module. - * - * @param ti_if The interface functions for this module. - * - * If the parameter ti_if is NULL, the default functions compare_strict() and - * firm_hash_name() will be used. - */ -void init_type_identify(type_identify_if_t *ti_if); - -#endif /* FIRM_TR_TYPE_IDENTIFY_H */ diff --git a/ir/tr/type_or_entity.h b/ir/tr/type_or_entity.h deleted file mode 100644 index eee03edc4..000000000 --- a/ir/tr/type_or_entity.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file - * @brief Provides a datatype to treat types and entities as the same. - * @author Goetz Lindenmaier - * @version $Id$ - */ -#ifndef FIRM_TR_TYPE_OR_ENTITY_H -#define FIRM_TR_TYPE_OR_ENTITY_H - -#include "firm_types.h" - -/** A data type to treat types and entities as the same. */ -typedef union { - ir_type *typ; /**< points to a type */ - ir_entity *ent; /**< points to an entity */ -} type_or_ent; - - -# endif /* FIRM_TR_TYPE_OR_ENTITY_H */ diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h index 8049cc62f..be7efed03 100644 --- a/ir/tr/type_t.h +++ b/ir/tr/type_t.h @@ -28,9 +28,10 @@ #define FIRM_TR_TYPE_T_H #include "firm_config.h" -#include "type.h" +#include "typerep.h" #include "tpop_t.h" #include "irgraph.h" +#include "firm_common.h" #include "array.h" @@ -146,7 +147,68 @@ enum type_flags { tf_tls_type = 32, /**< Set only for the tls type */ }; -/** The structure of a type. */ +/** + * An abstract data type to represent types. + * + * This is the abstract data type with which any type known in the + * compiled program can be represented. This includes types specified + * in the program as well as types defined by the language. In the + * view of the intermediate representation there is no difference + * between these types. + * + * There exist several kinds of types, arranged by the structure of + * the type. These are distinguished by a type opcode. + * A type is described by a set of attributes. Some of these attributes + * are common to all types, others depend on the kind of the type. + * + * The following describes the common attributes. They can only be + * accessed by the functions given below. + * + * The common fields are: + * + * - firm_kind: A firm_kind tag containing k_type. This is useful + * for dynamically checking whether a node is a type node. + * - type_op: A tp_op specifying the kind of the type. + * - name: An identifier specifying the name of the type. To be + * set by the frontend. + * - visibility: The visibility of this type. + * - size: The size of the type, i.e. an entity of this type will + * occupy size bits in memory. In several cases this is + * determined when fixing the layout of this type (class, + * struct, union, array, enumeration). + * - alignment The alignment of the type, i.e. an entity of this type will + * be allocated an an address in memory with this alignment. + * In several cases this is determined when fixing the layout + * of this type (class, struct, union, array) + * - mode: The mode to be used to represent the type on a machine. + * - state: The state of the type. The state represents whether the + * layout of the type is undefined or fixed (values: layout_undefined + * or layout_fixed). Compound types can have an undefined + * layout. The layout of the basic types primitive and pointer + * is always layout_fixed. If the layout of + * compound types is fixed all entities must have an offset + * and the size of the type must be set. + * A fixed layout for enumeration types means that each enumeration + * is associated with an implementation value. + * - assoc_type: The associated lowered/upper type. + * - visit: A counter for walks of the type information. + * - link: A void* to associate some additional information with the type. + * + * These fields can only be accessed via access functions. + * + * Depending on the value of @c type_op, i.e., depending on the kind of the + * type the adt contains further attributes. These are documented below. + * + * @see + * + * @link class_type class @endlink, @link struct_type struct @endlink, + * @link method_type method @endlink, @link union_type union @endlink, + * @link array_type array @endlink, @link enumeration_type enumeration @endlink, + * @link pointer_type pointer @endlink, @link primitive_type primitive @endlink + * + * @todo + * mode maybe not global field?? + */ struct ir_type { firm_kind kind; /**< the firm kind, must be k_type */ const tp_op *type_op; /**< the type operation of the type */ diff --git a/ir/tr/typegmod.c b/ir/tr/typegmod.c index 647ba7877..6c51eaf9f 100644 --- a/ir/tr/typegmod.c +++ b/ir/tr/typegmod.c @@ -27,7 +27,6 @@ #include "config.h" #endif -#include "typegmod.h" #include "type_t.h" #include "tpop_t.h" #include "irmode.h" diff --git a/ir/tr/typegmod.h b/ir/tr/typegmod.h deleted file mode 100644 index 991149187..000000000 --- a/ir/tr/typegmod.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file typegmod.h - * @brief Functionality to modify the type graph. - * @author Goetz Lindenmaier, Michael Beck - * @version $Id$ - */ -#ifndef FIRM_TR_TYPEGMOD_H -#define FIRM_TR_TYPEGMOD_H - -#include "firm_types.h" - -/** - * - * @file typegmod.h - * This module supplies routines that support changing the type graph. - */ - -/** Replaces one type by the other. - * - * Old type is replaced by new_type. All references to old_type - * now point to new_type. The memory for the old type is destroyed, - * but still used. Therefore it is not freed. - * All referenced to this memory will be lost after a certain while. - * An exception is the list of types in irp (irprog.h). - * In the future there might be a routine to recover the memory, but - * this will be at considerable runtime cost. - * - * @param old_type - The old type that shall be replaced by the new type. - * @param new_type - The new type that will replace old_type. - * - */ -void exchange_types(ir_type *old_type, ir_type *new_type); - -/** Skip id types until a useful type is reached. - * - * @param tp - A type of arbitrary kind. - * - * @return - * tp if it is not an id type. - * If tp is an id type returns the real type it stands for. - */ -ir_type *skip_tid(ir_type *tp); - -#endif /*FIRM_TR_TYPEGMOD_H */ diff --git a/ir/tr/typewalk.c b/ir/tr/typewalk.c index 9a4464440..629084abb 100644 --- a/ir/tr/typewalk.c +++ b/ir/tr/typewalk.c @@ -39,11 +39,8 @@ #include -#include "typewalk.h" #include "entity_t.h" #include "type_t.h" -#include "type_or_entity.h" -#include "typegmod.h" #include "irprog_t.h" #include "irgraph_t.h" diff --git a/ir/tr/typewalk.h b/ir/tr/typewalk.h deleted file mode 100644 index 5c50a7ef2..000000000 --- a/ir/tr/typewalk.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. - * - * This file is part of libFirm. - * - * This file may be distributed and/or modified under the terms of the - * GNU General Public License version 2 as published by the Free Software - * Foundation and appearing in the file LICENSE.GPL included in the - * packaging of this file. - * - * Licensees holding valid libFirm Professional Edition licenses may use - * this file in accordance with the libFirm Commercial License. - * Agreement provided with the Software. - * - * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE. - */ - -/** - * @file typewalk.h - * @brief Functionality to modify the type graph. - * @author Goetz Lindenmaier - * @version $Id$ - * @summary - * - * Traverse the type information. - * - * The walker walks the whole ir graph - * to find the distinct type trees in the type graph forest. - * - execute the pre() function before recursion - * - execute the post() function after recursion - */ -#ifndef FIRM_TR_TYPEWALK_H -#define FIRM_TR_TYPEWALK_H - -#include "type.h" -#include "type_or_entity.h" - -#include "irgraph.h" - -/** Type of argument functions for type walkers. - * - * @param tore points to the visited type or entity - * @param env free environment pointer - */ -typedef void type_walk_func(type_or_ent *tore, void *env); - -/** The class walk function - * - * @param clss points to the visited class - * @param env free environment pointer - */ -typedef void class_walk_func(ir_type *clss, void *env); - -/** Touches every type and entity in unspecified order. If new - * types/entities are created during the traversal these will - * be visited, too. - * Does not touch frame types or types for value params ... */ -void type_walk(type_walk_func *pre, type_walk_func *post, void *env); - -/** Walks over all type information reachable from an ir graph. - * - * Walks over all type information reachable from irg, i.e., starts a - * type walk at the irgs entity, the irgs frame type and all types and - * entities that are attributes to firm nodes. */ -void type_walk_irg(ir_graph *irg, - type_walk_func *pre, - type_walk_func *post, - void *env); - -/** - Touches every class in specified order: - - first the super class - - second the class itself - - third the sub classes. If new classes are created - during the traversal these will be visited, too. - - @todo should be named class-walk - - @deprecated will be removed? -*/ -void type_walk_super2sub(type_walk_func *pre, - type_walk_func *post, - void *env); - -/** Walker for class types in inheritance order. - * - * Touches every class in specified order: - * - first the super class - * - second the class itself - * If new classes are created during the traversal these - * will be visited, too. - * Starts the walk at arbitrary classes. - * Executes pre when first visiting a class. Executes post after - * visiting all superclasses. - * - * The arguments pre, post, env may be NULL. */ -void type_walk_super(type_walk_func *pre, - type_walk_func *post, - void *env); - -/** Same as type_walk_super2sub, but visits only class types. - Executes pre for a class if all superclasses have been visited. - Then iterates to subclasses. Executes post after return from - subclass. - Does not visit global type, frame types. - - @bug ?? something is wrong with this. -*/ -void class_walk_super2sub(class_walk_func *pre, - class_walk_func *post, - void *env); - -/** - * the entity walk function. A function type for entity walkers. - * - * @param ent points to the visited entity - * @param env free environment pointer - */ -typedef void entity_walk_func(ir_entity *ent, void *env); - -/** - * Walks over all entities in the type. - * - * @param tp the type - * @param doit the entity walker function - * @param env environment, will be passed to the walker function - */ -void walk_types_entities(ir_type *tp, - entity_walk_func *doit, - void *env); - -#endif /* FIRM_TR_TYPEWALK_H */ -- 2.20.1