Exemple #1
0
static void
run_cfg(char *obj_file)
{
    int	    i;
    char    s[128];
    FILE    *fcfg;

    sprintf(s, "%s.cfg", obj_file);
    //printf("dumping control flow graphs to file:%s\n", s);
    fcfg = fopen(s, "w");
    if (fcfg == NULL) {
	fprintf(stderr, "fail to create file: %s.cfg\n", s);
	exit(1);
    }

    for (i=0; i<prog.num_procs; i++) {
	dump_cfg(fcfg, &prog.procs[i]);
    }
    fclose(fcfg);

    //printf("done.\n");
}
Exemple #2
0
struct tube *ReadTube(const char *fn)
{
    int i, j;
    char *tmp;
    char **dp;
    char buf[200];
    char sector[100];
    float x, y, z, height, width;
    int num_elems;
    float part;
    struct tube *tu;

    dprintf(1, "Reading tube configuration");
    tu = (struct tube *)AllocTube();

    dp = dump_cfg();
    for (i = 0; dp[i] && *dp[i]; i++)
    {
        dprintf(5, "%3d: #%s#\n", i, dp[i]);
        free(dp[i]);
    }
    if (dp)  free(dp);

    // peer
    strcpy(buf, G_PEER);
    tu->pe_orient = -1;
    if ((tmp = IHS_GetCFGValue(fn, buf, G_PEER_ORIENT)) != NULL)
    {
        if (!strcmp(tmp, G_PEER_VERTICAL))
            tu->pe_orient = PE_VERTICAL;
        else if (!strcmp(tmp, G_PEER_HORIZONTAL))
            tu->pe_orient = PE_HORIZONTAL;
        free(tmp);
    }
    for (i = 0; ; i++)
    {
        int start_cs, end_cs;

        sprintf(buf, T_PEER, i);
        dprintf(3, "Scanning for %s in %s", buf, fn);

        if ((tmp = IHS_GetCFGValue(fn, buf, P_START_SEC)) != NULL)
        {
            int num;
            sscanf(tmp, "%d", &num);
            start_cs = num;
            free(tmp);
        }
        else
            start_cs = 0;
        if ((tmp = IHS_GetCFGValue(fn, buf, P_END_SEC)) != NULL)
        {
            int num;
            sscanf(tmp, "%d", &num);
            end_cs = num;
            free(tmp);
        }
        else
            end_cs = 0;
        if (start_cs == end_cs || end_cs == 0 || start_cs > end_cs)
        {
            dprintf(2, "Einlesen peer abgebrochen (i=%d)", i);
            break;
        }
        AllocT_PE(tu);
        tu->pe[i]->p_start_cs = start_cs;
        tu->pe[i]->p_end_cs = end_cs;

        if ((tmp = IHS_GetCFGValue(fn, buf, P_TYPE_DIST)) != NULL)
        {
            int num;
            sscanf(tmp, "%d", &num);
            tu->pe[i]->p_type_dist = num;
            free(tmp);
        }
        if ((tmp = IHS_GetCFGValue(fn, buf, P_START_DIST)) != NULL)
        {
            float num;
            sscanf(tmp, "%f", &num);
            tu->pe[i]->p_start_dist = num;
            free(tmp);
        }
        if ((tmp = IHS_GetCFGValue(fn, buf, P_END_DIST)) != NULL)
        {
            float num;
            sscanf(tmp, "%f", &num);
            tu->pe[i]->p_end_dist = num;
            free(tmp);
        }
        if ((tmp = IHS_GetCFGValue(fn, buf, P_NOSE_LENGTH)) != NULL)
        {
            float num;
            sscanf(tmp, "%f", &num);
            tu->pe[i]->p_nose_length = num;
            free(tmp);
        }
        if ((tmp = IHS_GetCFGValue(fn, buf, P_NOSE_RAD)) != NULL)
        {
            float num;
            sscanf(tmp, "%f", &num);
            tu->pe[i]->p_nose_rad = num;
            free(tmp);
        }
    }

    strcpy(buf, G_SECTION);
    for (i = 0; i < 4; i++)
        tu->d_el[i] = 1;
    tu->d_el_o = 1;
    if ((tmp = IHS_GetCFGValue(fn, buf, G_ELEMS_RV)) != NULL)
    {
        sscanf(tmp, "%d", &num_elems);
        if (num_elems > 0)
            tu->d_el[0] = num_elems;
        free(tmp);
    }
    if ((tmp = IHS_GetCFGValue(fn, buf, G_ELEMS_TH)) != NULL)
    {
        sscanf(tmp, "%d", &num_elems);
        if (num_elems > 0)
            tu->d_el[1] = num_elems;
        free(tmp);
    }
    if ((tmp = IHS_GetCFGValue(fn, buf, G_ELEMS_LV)) != NULL)
    {
        sscanf(tmp, "%d", &num_elems);
        if (num_elems > 0)
            tu->d_el[2] = num_elems;
        free(tmp);
    }
    if ((tmp = IHS_GetCFGValue(fn, buf, G_ELEMS_BH)) != NULL)
    {
        sscanf(tmp, "%d", &num_elems);
        if (num_elems > 0)
            tu->d_el[3] = num_elems;
        free(tmp);
    }
    if ((tmp = IHS_GetCFGValue(fn, buf, G_ELEMS_O)) != NULL)
    {
        sscanf(tmp, "%d", &num_elems);
        if (num_elems > 0)
            tu->d_el_o = num_elems;
        free(tmp);
    }

    for (i = 0; ; i++)
    {
        x = y = z = height = width = 0.0;
        sprintf(buf, T_SECTION, i);
        dprintf(2, "Scanning for %s in %s", buf, fn);

        if ((tmp = IHS_GetCFGValue(fn, buf, T_MIDDLE)) != NULL)
        {
            sscanf(tmp, "%f,%f,%f", &x, &y, &z);
            free(tmp);

            num_elems = 1;
            AllocT_CS(tu);
            for (j = 0; j < 8; j++)
            {
                tu->cs[i]->d_part[j] = 0.8f;
                sprintf(sector, G_PART, sectornames[j]);
                if ((tmp = IHS_GetCFGValue(fn, buf, sector)) != NULL)
                {
                    sscanf(tmp, "%f", &part);
                    if (part > 0.0 && part < 1.0)
                        tu->cs[i]->d_part[j] = part;
                    free(tmp);
                }
                else
                {
                    dprintf(5, "Error during reading: %d, %s, %s, using default value\n", j, sectornames[j], sector);
                }
            }
            tu->cs[i]->d_linfact = 1.0;
            if ((tmp = IHS_GetCFGValue(fn, buf, G_LINFACT)) != NULL)
            {
                sscanf(tmp, "%f", &part);
                if (part > -50.0 && part < 50.0)
                    tu->cs[i]->d_linfact = part;
                free(tmp);
            }
            if ((tmp = IHS_GetCFGValue(fn, buf, G_ELEMS)) != NULL)
            {
                sscanf(tmp, "%d", &num_elems);
                free(tmp);
            }
            if ((tmp = IHS_GetCFGValue(fn, buf, T_HEIGHT)) != NULL)
            {
                sscanf(tmp, "%f", &height);
                free(tmp);
            }
            if ((tmp = IHS_GetCFGValue(fn, buf, T_WIDTH)) != NULL)
            {
                sscanf(tmp, "%f", &width);
                free(tmp);
            }
            if ((tmp = IHS_GetCFGValue(fn, buf, T_ANGLE)) != NULL)
            {
                sscanf(tmp, "%f", (float *)&(tu->cs[tu->cs_num-1]->d_angle));
                free(tmp);
                if ((tmp = IHS_GetCFGValue(fn, buf, T_ANGLETYPE)) != NULL)
                {
                    if (!strcmp(angletypes[T_ANGLE_ABSOLUTE], tmp))
                        tu->cs[tu->cs_num-1]->d_angletype = T_ANGLE_ABSOLUTE;
                    else if (!strcmp(angletypes[T_ANGLE_RELATIV], tmp))
                        tu->cs[tu->cs_num-1]->d_angletype = T_ANGLE_RELATIV;
                    else
                        tu->cs[tu->cs_num-1]->d_angletype = 0;
                    free(tmp);
                }
                else
                {
                    tu->cs[tu->cs_num-1]->d_angletype = T_ANGLE_RELATIV;
                }
            }
            for (j = 0; j < 4; j++)
            {
                float a, b;
                if ((tmp = IHS_GetCFGValue(fn, buf, abtypes[j])) != NULL)
                {
                    if (2 != sscanf(tmp, "%f,%f", &a, &b))
                    {
                        tu->cs[tu->cs_num-1]->d_a[j] = 0.0;
                        tu->cs[tu->cs_num-1]->d_b[j] = 0.0;
                    }
                    else
                    {
                        tu->cs[tu->cs_num-1]->d_a[j] = a;
                        tu->cs[tu->cs_num-1]->d_b[j] = b;
                    }
                    free(tmp);
                }
            }
            tu->cs[tu->cs_num-1]->d_m_x = x;
            tu->cs[tu->cs_num-1]->d_m_y = y;
            tu->cs[tu->cs_num-1]->d_m_z = z;
            tu->cs[tu->cs_num-1]->d_width = width;
            tu->cs[tu->cs_num-1]->d_height = height;
            tu->cs[tu->cs_num-1]->d_nume = num_elems;

            // for the first time, we have to set the c_ section ...
            tu->cs[tu->cs_num-1]->c_m_x = tu->cs[tu->cs_num-1]->d_m_x;
            tu->cs[tu->cs_num-1]->c_m_y = tu->cs[tu->cs_num-1]->d_m_y;
            tu->cs[tu->cs_num-1]->c_m_z = tu->cs[tu->cs_num-1]->d_m_z;
            tu->cs[tu->cs_num-1]->c_width = tu->cs[tu->cs_num-1]->d_width;
            tu->cs[tu->cs_num-1]->c_height = tu->cs[tu->cs_num-1]->d_height;
            for (j = 0; j < 4; j++)
            {
                tu->cs[tu->cs_num-1]->c_a[j] = tu->cs[tu->cs_num-1]->d_a[j];
                tu->cs[tu->cs_num-1]->c_b[j] = tu->cs[tu->cs_num-1]->d_b[j];
            }
            tu->cs[tu->cs_num-1]->c_angletype = tu->cs[tu->cs_num-1]->d_angletype;
            tu->cs[tu->cs_num-1]->c_angle = tu->cs[tu->cs_num-1]->d_angle;
            // and now grid parameters ...
            tu->cs[tu->cs_num-1]->c_nume = tu->cs[tu->cs_num-1]->d_nume;
            for (j = 0; j < 8; j++)
                tu->cs[tu->cs_num-1]->c_part[j] = tu->cs[tu->cs_num-1]->d_part[j];
            tu->cs[tu->cs_num-1]->c_linfact = tu->cs[tu->cs_num-1]->d_linfact;
        }
        else
        {
            dprintf(1, "End reading tube configuration");
            break;
        }
    }
    tu->c_el_o  = tu->d_el_o;
    for (i = 0; i < 4; i++)
        tu->c_el[i] = tu->d_el[i];
    DumpTube(tu);

    return tu;
}
Exemple #3
0
/* imc_reg_alloc is the main loop of the allocation algorithm. It operates
 * on a single compilation unit at a time.
 */
void
imc_reg_alloc(struct Parrot_Interp *interpreter, IMC_Unit * unit)
{
    int to_spill;
    int todo, first;

    if (!unit)
        return;
    if (!optimizer_level && pasm_file)
        return;

    init_tables(interpreter);
    allocated = 0;

#if IMC_TRACE
    fprintf(stderr, "reg_alloc.c: imc_reg_alloc\n");
    if (unit->instructions->r[1] && unit->instructions->r[1]->pcc_sub) {
        fprintf(stderr, "img_reg_alloc: pcc_sub (nargs = %d)\n",
            unit->instructions->r[1]->pcc_sub->nargs);
    }
#endif

    debug(interpreter, DEBUG_IMC, "\n------------------------\n");
    debug(interpreter, DEBUG_IMC, "processing sub %s\n", function);
    debug(interpreter, DEBUG_IMC, "------------------------\n\n");
    if (IMCC_INFO(interpreter)->verbose ||
            (IMCC_INFO(interpreter)->debug & DEBUG_IMC))
        imc_stat_init(unit);

    /* consecutive labels, if_branch, unused_labels ... */
    pre_optimize(interpreter, unit);
    if (optimizer_level == OPT_PRE && pasm_file)
        return;

    nodeStack = imcstack_new();
    unit->n_spilled = 0;

    todo = first = 1;
    while (todo) {
        find_basic_blocks(interpreter, unit, first);
        build_cfg(interpreter, unit);

        if (first && (IMCC_INFO(interpreter)->debug & DEBUG_CFG))
            dump_cfg(unit);
        first = 0;
        todo = cfg_optimize(interpreter, unit);
    }

    todo = first = 1;
    while (todo) {
        if (!first) {
            find_basic_blocks(interpreter, unit, 0);
            build_cfg(interpreter, unit);
        }
        first = 0;

        compute_dominators(interpreter, unit);
        find_loops(interpreter, unit);

        build_reglist(interpreter, unit);
        life_analysis(interpreter, unit);
        /* optimize, as long as there is something to do */
        if (dont_optimize)
            todo = 0;
        else {
            todo = optimize(interpreter, unit);
            if (todo)
                pre_optimize(interpreter, unit);
        }
    }
    todo = 1;
#if !DOIT_AGAIN_SAM
    build_interference_graph(interpreter, unit);
#endif
    while (todo) {
#if DOIT_AGAIN_SAM
        build_interference_graph(interpreter, unit);
#endif
        if (optimizer_level & OPT_SUB)
            allocate_wanted_regs(unit);
        compute_spilling_costs(interpreter, unit);
#ifdef DO_SIMPLIFY
        /* simplify until no changes can be made */
        while (simplify(unit)) {}
#endif
        order_spilling(unit);          /* put the remaining items on stack */

        to_spill = try_allocate(interpreter, unit);
        allocated = 1;

        if ( to_spill >= 0 ) {
            allocated = 0;
            spill(interpreter, unit, to_spill);
            /*
             * build the new cfg/reglist on the fly in spill() and
             * do life analysis there for only the involved regs
             */
#if DOIT_AGAIN_SAM
            find_basic_blocks(interpreter, unit, 0);
            build_cfg(interpreter, unit);
            build_reglist(interpreter, unit);
            life_analysis(interpreter);
#endif
        }
        else {
            /* the process is finished */
            todo = 0;
        }
    }
    if (optimizer_level & OPT_SUB)
        sub_optimize(interpreter, unit);
    if (IMCC_INFO(interpreter)->debug & DEBUG_IMC)
        dump_instructions(unit);
    if (IMCC_INFO(interpreter)->verbose  ||
            (IMCC_INFO(interpreter)->debug & DEBUG_IMC))
        print_stat(interpreter, unit);
    imcstack_free(nodeStack);
}