- add barcelona and generic32 targets
[libfirm] / ir / be / ia32 / bearch_ia32.c
index bf01b6e..50aa361 100644 (file)
@@ -51,6 +51,7 @@
 #include "xmalloc.h"
 #include "irtools.h"
 #include "iroptimize.h"
+#include "instrument.h"
 
 #include "../beabi.h"
 #include "../beirg_t.h"
@@ -927,6 +928,10 @@ static ia32_irn_ops_t ia32_irn_ops = {
  *                       |___/
  **************************************************/
 
+static ir_entity *mcount = NULL;
+
+#define ID(s) new_id_from_chars(s, sizeof(s) - 1)
+
 static void ia32_before_abi(void *self) {
        lower_mode_b_config_t lower_mode_b_config = {
                mode_Iu,  /* lowered mode */
@@ -938,6 +943,16 @@ static void ia32_before_abi(void *self) {
        ir_lower_mode_b(cg->irg, &lower_mode_b_config);
        if (cg->dump)
                be_dump(cg->irg, "-lower_modeb", dump_ir_block_graph_sched);
+       if (cg->gprof) {
+               if (mcount == NULL) {
+                       ir_type *tp = new_type_method(ID("FKT.mcount"), 0, 0);
+                       mcount = new_entity(get_glob_type(), ID("mcount"), tp);
+                       /* FIXME: enter the right ld_ident here */
+                       set_entity_ld_ident(mcount, get_entity_ident(mcount));
+                       set_entity_visibility(mcount, visibility_external_allocated);
+               }
+               instrument_initcall(cg->irg, mcount);
+       }
 }
 
 /**
@@ -1516,14 +1531,16 @@ static void ia32_codegen(void *self) {
        free(cg);
 }
 
+/**
+ * Returns the node representing the PIC base.
+ */
 static ir_node *ia32_get_pic_base(void *self) {
        ir_node         *block;
        ia32_code_gen_t *cg      = self;
        ir_node         *get_eip = cg->get_eip;
-       if(get_eip != NULL)
+       if (get_eip != NULL)
                return get_eip;
 
-
        block       = get_irg_start_block(cg->irg);
        get_eip     = new_rd_ia32_GetEIP(NULL, cg->irg, block);
        cg->get_eip = get_eip;
@@ -1537,7 +1554,7 @@ static void *ia32_cg_init(be_irg_t *birg);
 
 static const arch_code_generator_if_t ia32_code_gen_if = {
        ia32_cg_init,
-       ia32_get_pic_base,
+       ia32_get_pic_base,   /* return node used as base in pic code addresses */
        ia32_before_abi,     /* before abi introduce hook */
        ia32_prepare_graph,
        NULL,                /* spill */
@@ -1563,6 +1580,12 @@ static void *ia32_cg_init(be_irg_t *birg) {
        cg->birg      = birg;
        cg->blk_sched = NULL;
        cg->dump      = (birg->main_env->options->dump_flags & DUMP_BE) ? 1 : 0;
+       cg->gprof     = (birg->main_env->options->gprof) ? 1 : 0;
+
+       if (cg->gprof) {
+               /* Linux gprof implementation needs base pointer */
+               birg->main_env->options->omit_fp = 0;
+       }
 
        /* enter it */
        isa->cg = cg;