ir.c
// Add instructions that write zeroes to dst, starting at offset, with size in src1
Add instructions that write zeroes to dst, starting at offset, with size in src1
Add instructions that write zeroes to dst starting at offset with size in src1
void add_zero_memory_instructions(Function *function) {
    for (Tac *tac = function->ir; tac; tac = tac->next) {
        if (tac->operation != IR_ZERO) continue;
        Value *dst = tac->dst;
        int offset = tac->dst->offset;
        int size = tac->src1->int_value;
        tac->operation = IR_NOP;
        tac->dst = 0;
        tac->src1 = 0;
        Value *zero = new_integral_constant(TYPE_INT, 0);
        if (size < 32) {
            for (int i = 3; i >= 0; i -= 1) {
                int step = 1 << i;
                while (size >= step) {
                    Value *tmp = dup_value(dst);
                    tmp->offset = offset;
                    tmp->type = new_type(TYPE_CHAR + i);
                    insert_instruction_from_operation(tac, IR_MOVE, tmp, zero, 0, 1);
                    size -= step;
                    offset += step;
                }
            }
        }
        else {
            int function_call_count = make_function_call_count(function);
            Value *call_value = make_function_call_value(function_call_count++);
            ir = insert_instruction_after_from_operation(ir, IR_START_CALL, 0, call_value, 0);
            Value *size_value = new_integral_constant(TYPE_INT, size);
            Value *dst_address = insert_address_of_instruction_after(function, &ir, dst);
            ir = insert_arg_instruction_after(ir, call_value, dst_address, 0);
            ir = insert_arg_instruction_after(ir, call_value, zero, 1);
            ir = insert_arg_instruction_after(ir, call_value, size_value, 2);
            ir = insert_function_call_instructions_after(ir, call_value, memset_symbol);
        }
    }
}
void add_zero_memory_instructions ( Function * function ) { for ( Tac * tac = function -> ir ; tac ; tac = tac -> next ) { if ( tac -> operation != IR_ZERO ) continue ; Value * dst = tac -> dst ; int offset = tac -> dst -> offset ; int size = tac -> src1 -> int_value ; tac -> operation = IR_NOP ; tac -> dst = 0 ; tac -> src1 = 0 ; Value * zero = new_integral_constant ( TYPE_INT , 0 ) ; if ( size < 32 ) { for ( int i = 3 ; i >= 0 ; i -= 1 ) { int step = 1 << i ; while ( size >= step ) { Value * tmp = dup_value ( dst ) ; tmp -> offset = offset ; tmp -> type = new_type ( TYPE_CHAR + i ) ; insert_instruction_from_operation ( tac , IR_MOVE , tmp , zero , 0 , 1 ) ; size -= step ; offset += step ; } } } else { int function_call_count = make_function_call_count ( function ) ; Value * call_value = make_function_call_value ( function_call_count ++ ) ; ir = insert_instruction_after_from_operation ( ir , IR_START_CALL , 0 , call_value , 0 ) ; Value * size_value = new_integral_constant ( TYPE_INT , size ) ; Value * dst_address = insert_address_of_instruction_after ( function , & ir , dst ) ; ir = insert_arg_instruction_after ( ir , call_value , dst_address , 0 ) ; ir = insert_arg_instruction_after ( ir , call_value , zero , 1 ) ; ir = insert_arg_instruction_after ( ir , call_value , size_value , 2 ) ; ir = insert_function_call_instructions_after ( ir , call_value , memset_symbol ) ; } } }
Add instructions that write zeroes to dst, starting at offset, with size in src1
Add instructions that write zeroes to dst starting at offset with size in src1
// Write zeros directly // Call memset // Add start call instruction // Add function call