src/tiramisu_core.cpp
void computation::interchange(int L0, int L1)
{
    DEBUG_FCT_NAME(3);
    DEBUG_INDENT(4);

    int inDim0 = loop_level_into_dynamic_dimension(L0);
    int inDim1 = loop_level_into_dynamic_dimension(L1);

    assert(inDim0 >= 0);
    assert(inDim0 < isl_space_dim(isl_map_get_space(this->get_schedule()),
                                  isl_dim_out));
    assert(inDim1 >= 0);
    assert(inDim1 < isl_space_dim(isl_map_get_space(this->get_schedule()),
                                  isl_dim_out));

    isl_map *schedule = this->get_schedule();

    DEBUG(3, tiramisu::str_dump("Original schedule: ", isl_map_to_str(schedule)));
    DEBUG(3, tiramisu::str_dump("Interchanging the dimensions " + std::to_string(
                                    L0) + " and " + std::to_string(L1)));

    int n_dims = isl_map_dim(schedule, isl_dim_out);

    std::string inDim0_str = isl_map_get_dim_name(schedule, isl_dim_out, inDim0);
    std::string inDim1_str = isl_map_get_dim_name(schedule, isl_dim_out, inDim1);

    std::vector<isl_id *> dimensions;

    // ------------------------------------------------------------
    // Create a map for the duplicate schedule.
    // ------------------------------------------------------------

    std::string map = "{ " + this->get_name() + "[";

    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            int duplicate_ID = isl_map_get_static_dim(schedule, 0);
            map = map + std::to_string(duplicate_ID);
        }
        else
        {
            if (isl_map_get_dim_name(schedule, isl_dim_out, i) == NULL)
            {
                isl_id *new_id = isl_id_alloc(this->get_ctx(), generate_new_variable_name().c_str(), NULL);
                schedule = isl_map_set_dim_id(schedule, isl_dim_out, i, new_id);
            }

            map = map + isl_map_get_dim_name(schedule, isl_dim_out, i);
        }

        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }

    map = map + "] ->" + this->get_name() + "[";

    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            int duplicate_ID = isl_map_get_static_dim(schedule, 0);
            map = map + std::to_string(duplicate_ID);
        }
        else
        {
            if ((i != inDim0) && (i != inDim1))
            {
                map = map + isl_map_get_dim_name(schedule, isl_dim_out, i);
                dimensions.push_back(isl_map_get_dim_id(schedule, isl_dim_out, i));
            }
            else if (i == inDim0)
            {
                map = map + inDim1_str;
                isl_id *id1 = isl_id_alloc(this->get_ctx(), inDim1_str.c_str(), NULL);
                dimensions.push_back(id1);
            }
            else if (i == inDim1)
            {
                map = map + inDim0_str;
                isl_id *id1 = isl_id_alloc(this->get_ctx(), inDim0_str.c_str(), NULL);
                dimensions.push_back(id1);
            }
        }

        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }

    map = map + "]}";

    DEBUG(3, tiramisu::str_dump("A map that transforms the duplicate"));
    DEBUG(3, tiramisu::str_dump(map.c_str()));

    isl_map *transformation_map = isl_map_read_from_str(this->get_ctx(), map.c_str());


    transformation_map = isl_map_set_tuple_id(
                             transformation_map, isl_dim_in, isl_map_get_tuple_id(isl_map_copy(schedule), isl_dim_out));
    isl_id *id_range = isl_id_alloc(this->get_ctx(), this->get_name().c_str(), NULL);
    transformation_map = isl_map_set_tuple_id(
                             transformation_map, isl_dim_out, id_range);


    // Check that the names of each dimension is well set
    for (int i = 1; i < isl_map_dim(transformation_map, isl_dim_in); i++)
    {
        isl_id *dim_id = isl_id_copy(dimensions[i - 1]);
        transformation_map = isl_map_set_dim_id(transformation_map, isl_dim_out, i, dim_id);
        assert(isl_map_has_dim_name(transformation_map, isl_dim_in, i));
        assert(isl_map_has_dim_name(transformation_map, isl_dim_out, i));
    }

    DEBUG(3, tiramisu::str_dump("Final transformation map : ", isl_map_to_str(transformation_map)));

    schedule = isl_map_apply_range(isl_map_copy(schedule), isl_map_copy(transformation_map));

    DEBUG(3, tiramisu::str_dump("Schedule after interchange: ", isl_map_to_str(schedule)));

    this->set_schedule(schedule);

    DEBUG_INDENT(-4);
}
/**
 * This function modifies the schedule of the computation so that the two loop
 * levels L0 and L1 are interchanged (swapped).
 */
This function modifies the schedule of the computation so that the two loop
levels L0 and L1 are interchanged (swapped).
This function modifies the schedule of the computation so that the two loop levels L0 and L1 are interchanged ( swapped ) .
void computation::interchange(int L0, int L1)
{
    DEBUG_FCT_NAME(3);
    DEBUG_INDENT(4);
    int inDim0 = loop_level_into_dynamic_dimension(L0);
    int inDim1 = loop_level_into_dynamic_dimension(L1);
    assert(inDim0 >= 0);
    assert(inDim0 < isl_space_dim(isl_map_get_space(this->get_schedule()),
                                  isl_dim_out));
    assert(inDim1 >= 0);
    assert(inDim1 < isl_space_dim(isl_map_get_space(this->get_schedule()),
                                  isl_dim_out));
    isl_map *schedule = this->get_schedule();
    DEBUG(3, tiramisu::str_dump("Original schedule: ", isl_map_to_str(schedule)));
    DEBUG(3, tiramisu::str_dump("Interchanging the dimensions " + std::to_string(
                                    L0) + " and " + std::to_string(L1)));
    int n_dims = isl_map_dim(schedule, isl_dim_out);
    std::string inDim0_str = isl_map_get_dim_name(schedule, isl_dim_out, inDim0);
    std::string inDim1_str = isl_map_get_dim_name(schedule, isl_dim_out, inDim1);
    std::vector<isl_id *> dimensions;
    std::string map = "{ " + this->get_name() + "[";
    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            int duplicate_ID = isl_map_get_static_dim(schedule, 0);
            map = map + std::to_string(duplicate_ID);
        }
        else
        {
            if (isl_map_get_dim_name(schedule, isl_dim_out, i) == NULL)
            {
                isl_id *new_id = isl_id_alloc(this->get_ctx(), generate_new_variable_name().c_str(), NULL);
                schedule = isl_map_set_dim_id(schedule, isl_dim_out, i, new_id);
            }
            map = map + isl_map_get_dim_name(schedule, isl_dim_out, i);
        }
        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }
    map = map + "] ->" + this->get_name() + "[";
    for (int i = 0; i < n_dims; i++)
    {
        if (i == 0)
        {
            int duplicate_ID = isl_map_get_static_dim(schedule, 0);
            map = map + std::to_string(duplicate_ID);
        }
        else
        {
            if ((i != inDim0) && (i != inDim1))
            {
                map = map + isl_map_get_dim_name(schedule, isl_dim_out, i);
                dimensions.push_back(isl_map_get_dim_id(schedule, isl_dim_out, i));
            }
            else if (i == inDim0)
            {
                map = map + inDim1_str;
                isl_id *id1 = isl_id_alloc(this->get_ctx(), inDim1_str.c_str(), NULL);
                dimensions.push_back(id1);
            }
            else if (i == inDim1)
            {
                map = map + inDim0_str;
                isl_id *id1 = isl_id_alloc(this->get_ctx(), inDim0_str.c_str(), NULL);
                dimensions.push_back(id1);
            }
        }
        if (i != n_dims - 1)
        {
            map = map + ",";
        }
    }
    map = map + "]}";
    DEBUG(3, tiramisu::str_dump("A map that transforms the duplicate"));
    DEBUG(3, tiramisu::str_dump(map.c_str()));
    isl_map *transformation_map = isl_map_read_from_str(this->get_ctx(), map.c_str());
    transformation_map = isl_map_set_tuple_id(
                             transformation_map, isl_dim_in, isl_map_get_tuple_id(isl_map_copy(schedule), isl_dim_out));
    isl_id *id_range = isl_id_alloc(this->get_ctx(), this->get_name().c_str(), NULL);
    transformation_map = isl_map_set_tuple_id(
                             transformation_map, isl_dim_out, id_range);
    for (int i = 1; i < isl_map_dim(transformation_map, isl_dim_in); i++)
    {
        isl_id *dim_id = isl_id_copy(dimensions[i - 1]);
        transformation_map = isl_map_set_dim_id(transformation_map, isl_dim_out, i, dim_id);
        assert(isl_map_has_dim_name(transformation_map, isl_dim_in, i));
        assert(isl_map_has_dim_name(transformation_map, isl_dim_out, i));
    }
    DEBUG(3, tiramisu::str_dump("Final transformation map : ", isl_map_to_str(transformation_map)));
    schedule = isl_map_apply_range(isl_map_copy(schedule), isl_map_copy(transformation_map));
    DEBUG(3, tiramisu::str_dump("Schedule after interchange: ", isl_map_to_str(schedule)));
    this->set_schedule(schedule);
    DEBUG_INDENT(-4);
}
void computation :: interchange ( int L0 , int L1 ) { DEBUG_FCT_NAME ( 3 ) ; DEBUG_INDENT ( 4 ) ; int inDim0 = loop_level_into_dynamic_dimension ( L0 ) ; int inDim1 = loop_level_into_dynamic_dimension ( L1 ) ; assert ( inDim0 >= 0 ) ; assert ( inDim0 < isl_space_dim ( isl_map_get_space ( this -> get_schedule ( ) ) , isl_dim_out ) ) ; assert ( inDim1 >= 0 ) ; assert ( inDim1 < isl_space_dim ( isl_map_get_space ( this -> get_schedule ( ) ) , isl_dim_out ) ) ; isl_map * schedule = this -> get_schedule ( ) ; DEBUG ( 3 , tiramisu :: str_dump ( " " , isl_map_to_str ( schedule ) ) ) ; DEBUG ( 3 , tiramisu :: str_dump ( " " + std :: to_string ( L0 ) + " " + std :: to_string ( L1 ) ) ) ; int n_dims = isl_map_dim ( schedule , isl_dim_out ) ; std :: string inDim0_str = isl_map_get_dim_name ( schedule , isl_dim_out , inDim0 ) ; std :: string inDim1_str = isl_map_get_dim_name ( schedule , isl_dim_out , inDim1 ) ; std :: vector < isl_id * > dimensions ; std :: string map = " " + this -> get_name ( ) + " " ; for ( int i = 0 ; i < n_dims ; i ++ ) { if ( i == 0 ) { int duplicate_ID = isl_map_get_static_dim ( schedule , 0 ) ; map = map + std :: to_string ( duplicate_ID ) ; } else { if ( isl_map_get_dim_name ( schedule , isl_dim_out , i ) == NULL ) { isl_id * new_id = isl_id_alloc ( this -> get_ctx ( ) , generate_new_variable_name ( ) . c_str ( ) , NULL ) ; schedule = isl_map_set_dim_id ( schedule , isl_dim_out , i , new_id ) ; } map = map + isl_map_get_dim_name ( schedule , isl_dim_out , i ) ; } if ( i != n_dims - 1 ) { map = map + " " ; } } map = map + " " + this -> get_name ( ) + " " ; for ( int i = 0 ; i < n_dims ; i ++ ) { if ( i == 0 ) { int duplicate_ID = isl_map_get_static_dim ( schedule , 0 ) ; map = map + std :: to_string ( duplicate_ID ) ; } else { if ( ( i != inDim0 ) && ( i != inDim1 ) ) { map = map + isl_map_get_dim_name ( schedule , isl_dim_out , i ) ; dimensions . push_back ( isl_map_get_dim_id ( schedule , isl_dim_out , i ) ) ; } else if ( i == inDim0 ) { map = map + inDim1_str ; isl_id * id1 = isl_id_alloc ( this -> get_ctx ( ) , inDim1_str . c_str ( ) , NULL ) ; dimensions . push_back ( id1 ) ; } else if ( i == inDim1 ) { map = map + inDim0_str ; isl_id * id1 = isl_id_alloc ( this -> get_ctx ( ) , inDim0_str . c_str ( ) , NULL ) ; dimensions . push_back ( id1 ) ; } } if ( i != n_dims - 1 ) { map = map + " " ; } } map = map + " " ; DEBUG ( 3 , tiramisu :: str_dump ( " " ) ) ; DEBUG ( 3 , tiramisu :: str_dump ( map . c_str ( ) ) ) ; isl_map * transformation_map = isl_map_read_from_str ( this -> get_ctx ( ) , map . c_str ( ) ) ; transformation_map = isl_map_set_tuple_id ( transformation_map , isl_dim_in , isl_map_get_tuple_id ( isl_map_copy ( schedule ) , isl_dim_out ) ) ; isl_id * id_range = isl_id_alloc ( this -> get_ctx ( ) , this -> get_name ( ) . c_str ( ) , NULL ) ; transformation_map = isl_map_set_tuple_id ( transformation_map , isl_dim_out , id_range ) ; for ( int i = 1 ; i < isl_map_dim ( transformation_map , isl_dim_in ) ; i ++ ) { isl_id * dim_id = isl_id_copy ( dimensions [ i - 1 ] ) ; transformation_map = isl_map_set_dim_id ( transformation_map , isl_dim_out , i , dim_id ) ; assert ( isl_map_has_dim_name ( transformation_map , isl_dim_in , i ) ) ; assert ( isl_map_has_dim_name ( transformation_map , isl_dim_out , i ) ) ; } DEBUG ( 3 , tiramisu :: str_dump ( " " , isl_map_to_str ( transformation_map ) ) ) ; schedule = isl_map_apply_range ( isl_map_copy ( schedule ) , isl_map_copy ( transformation_map ) ) ; DEBUG ( 3 , tiramisu :: str_dump ( " " , isl_map_to_str ( schedule ) ) ) ; this -> set_schedule ( schedule ) ; DEBUG_INDENT ( -4 ) ; }
This function modifies the schedule of the computation so that the two loop
 levels L0 and L1 are interchanged (swapped).
This function modifies the schedule of the computation so that the two loop levels L0 and L1 are interchanged ( swapped ) .
// ------------------------------------------------------------ // Create a map for the duplicate schedule. // ------------------------------------------------------------ // Check that the names of each dimension is well set