ir.c
// allocate a stack_index values:
// - without a vreg,
// - used in a & expression,
// - are long double
//
// Pushed variables by the caller have local_index >= 2 and are mapped through.
allocate a stack_index values:
without a vreg,
used in a & expression,
are long double

Pushed variables by the caller have local_index >= 2 and are mapped through.
allocate a stack_index values : without a vreg used in a & expression are long double Pushed variables by the caller have local_index > = 2 and are mapped through .
void allocate_value_stack_indexes(Function *function) {
    int stack_register_count = 0;
    int *stack_index_map = malloc((function->local_symbol_count + 1) * sizeof(int));
    memset(stack_index_map, -1, (function->local_symbol_count + 1) * sizeof(int));
    if (debug_ssa_mapping_local_stack_indexes) print_ir(function, 0, 0);
    for (Tac *tac = function->ir; tac; tac = tac->next) {
        if (tac->dst && tac->dst->local_index < 0 && stack_index_map[-tac->dst->local_index] == -1)
            stack_index_map[-tac->dst->local_index] = stack_register_count++;
        if (tac->src1 && tac->src1->local_index < 0 && stack_index_map[-tac->src1->local_index] == -1)
            stack_index_map[-tac->src1->local_index] = stack_register_count++;
        if (tac->src2 && tac->src2->local_index < 0 && stack_index_map[-tac->src2->local_index] == -1)
            stack_index_map[-tac->src2->local_index] = stack_register_count++;
    }
    for (Tac *tac = function->ir; tac; tac = tac->next) {
        if (tac->dst && tac->dst->local_index < 0)
            tac->dst->stack_index = -stack_index_map[-tac->dst->local_index] - 1;
        if (tac->src1 && tac->src1->local_index < 0)
            tac->src1->stack_index = -stack_index_map[-tac->src1->local_index] - 1;
        if (tac->src2 && tac->src2->local_index < 0)
            tac->src2->stack_index = -stack_index_map[-tac->src2->local_index] - 1;
        if (tac->dst  && tac->dst ->local_index > 0) tac->dst ->stack_index = tac->dst ->local_index;
        if (tac->src1 && tac->src1->local_index > 0) tac->src1->stack_index = tac->src1->local_index;
        if (tac->src2 && tac->src2->local_index > 0) tac->src2->stack_index = tac->src2->local_index;
    }
    for (Tac *tac = function->ir; tac; tac = tac->next) {
        if (tac->dst ) tac->dst ->local_index = 0;
        if (tac->src1) tac->src1->local_index = 0;
        if (tac->src2) tac->src2->local_index = 0;
    }
    function->stack_register_count = stack_register_count;
    if (debug_ssa_mapping_local_stack_indexes)
        printf("Moved %d registers to stack\n", stack_register_count);
    if (debug_ssa_mapping_local_stack_indexes) print_ir(function, 0, 0);
}
void allocate_value_stack_indexes ( Function * function ) { int stack_register_count = 0 ; int * stack_index_map = malloc ( ( function -> local_symbol_count + 1 ) * sizeof ( int ) ) ; memset ( stack_index_map , -1 , ( function -> local_symbol_count + 1 ) * sizeof ( int ) ) ; if ( debug_ssa_mapping_local_stack_indexes ) print_ir ( function , 0 , 0 ) ; for ( Tac * tac = function -> ir ; tac ; tac = tac -> next ) { if ( tac -> dst && tac -> dst -> local_index < 0 && stack_index_map [ - tac -> dst -> local_index ] == -1 ) stack_index_map [ - tac -> dst -> local_index ] = stack_register_count ++ ; if ( tac -> src1 && tac -> src1 -> local_index < 0 && stack_index_map [ - tac -> src1 -> local_index ] == -1 ) stack_index_map [ - tac -> src1 -> local_index ] = stack_register_count ++ ; if ( tac -> src2 && tac -> src2 -> local_index < 0 && stack_index_map [ - tac -> src2 -> local_index ] == -1 ) stack_index_map [ - tac -> src2 -> local_index ] = stack_register_count ++ ; } for ( Tac * tac = function -> ir ; tac ; tac = tac -> next ) { if ( tac -> dst && tac -> dst -> local_index < 0 ) tac -> dst -> stack_index = - stack_index_map [ - tac -> dst -> local_index ] - 1 ; if ( tac -> src1 && tac -> src1 -> local_index < 0 ) tac -> src1 -> stack_index = - stack_index_map [ - tac -> src1 -> local_index ] - 1 ; if ( tac -> src2 && tac -> src2 -> local_index < 0 ) tac -> src2 -> stack_index = - stack_index_map [ - tac -> src2 -> local_index ] - 1 ; if ( tac -> dst && tac -> dst -> local_index > 0 ) tac -> dst -> stack_index = tac -> dst -> local_index ; if ( tac -> src1 && tac -> src1 -> local_index > 0 ) tac -> src1 -> stack_index = tac -> src1 -> local_index ; if ( tac -> src2 && tac -> src2 -> local_index > 0 ) tac -> src2 -> stack_index = tac -> src2 -> local_index ; } for ( Tac * tac = function -> ir ; tac ; tac = tac -> next ) { if ( tac -> dst ) tac -> dst -> local_index = 0 ; if ( tac -> src1 ) tac -> src1 -> local_index = 0 ; if ( tac -> src2 ) tac -> src2 -> local_index = 0 ; } function -> stack_register_count = stack_register_count ; if ( debug_ssa_mapping_local_stack_indexes ) printf ( " \n " , stack_register_count ) ; if ( debug_ssa_mapping_local_stack_indexes ) print_ir ( function , 0 , 0 ) ; }
allocate a stack_index values:
 without a vreg,
 used in a & expression,
 are long double
allocate a stack_index values : without a vreg used in a & expression are long double
// Make stack_index_map // Map registers forced onto the stack // Map registers forced onto the stack // Map function call parameters // From this point onwards, local_index has no meaning and downstream code must not use it.