Go to the previous, next section.

Example: An Implementation of include_for()

The following procedure will take a tree_for as an argument and will produce a system of inequalities (a named_lin_ineq) that represent the iteration space of the loop.

named_lin_ineq * include_for(tree_for * tf)
    // the index variable name
    immed idx(tf->index());

    // Find the lower bound
    // create an array_info class to extract linear function of the bounds
    array_info * lb_ai = new array_info;
    append_to_list(lb_ai, tf->lb_op(), tf, io_max, TRUE);
    named_lin_ineq * cl;
    // convert the bounds to named linear inequality class 
    cl  = named_lin_ineq::mk_named_lin_ineq(lb_ai, idx, TRUE); 
    if(cl == NULL) {
        printf("Unknown lower bound\n");
        return NULL;

    // Find the upper bound
    array_info * ub_ai = new array_info;
    append_to_list(ub_ai, tf->ub_op(), tf, io_min, TRUE);
    named_lin_ineq * cu;
    cu  = named_lin_ineq::mk_named_lin_ineq(*ub_ai, idx, FALSE);
    if(cu == NULL) {
        printf("Unknown upper bound\n");
        delete cl;
        return NULL;
    //  add the lower bound and upper bound togther 
    cu = named_lin_ineq::and(cl, cu, 0, 1);
    // Find the step
    access_vector * stp_av = new access_vector(tf->step_op(), tf, TRUE);
    named_lin_ineq * stp;
    stp = named_lin_ineq::mk_named_lin_ineq(stp_av, idx, FALSE);
    boolean stpbad = TRUE;
    if(stp)                                           // check bad step size
        if((stp->n() == 2)&&                          // no sym variables
           (stp->ineqs().m() == 1))                    // no max or mins 
            if(stp->ineqs()[0][0] == 1)                // nont step
               stpbad = FALSE;

    if(stpbad) {
        printf("Unknown or non-unit step size\n");
        delete cl;
        delete cu;
        if(stp) delete stp;
        return NULL;
    delete cl;
    delete stp;

    return cu;

Go to the previous, next section.