summaryrefslogtreecommitdiff
path: root/compiler_and_linker/unsorted/LoadDeletion.c
blob: 8cc0f28d0774508d96367b3236b8e8792f977faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "compiler/LoadDeletion.h"
#include "compiler/CopyPropagation.h"
#include "compiler/CParser.h"
#include "compiler/PCode.h"
#include "compiler/PCodeInfo.h"
#include "compiler/Registers.h"

int deletedloads;

static int is_load(PCode *instr) {
    return
        (instr->op == PC_LI || instr->op == PC_VSPLTISB || instr->op == PC_VSPLTISH || instr->op == PC_VSPLTISW)
        &&
        instr->args[0].data.reg.reg >= n_real_registers[instr->args[0].arg];
}

static int loadpropagatestouse(int candidateID, int useID) {
    return 0;
}

static void deleteload(int id) {
    Candidate *candidate;

    candidate = Candidates + id;
    if (candidate->list || (candidate->pcode->flags & fSideEffects))
        return;
    if (candidate->pcode->args[0].data.reg.reg < n_real_registers[candidate->pcode->args[0].arg])
        return;

    deletepcode(candidate->pcode);
    deletedloads = 1;
}

static Propagation load_immediate_prop = {
    &is_load,
    &loadpropagatestouse,
    &deleteload,
    "LOAD IMMEDIATE",
    "LOAD_IMMEDIATES",
    "l%ld",
    0
};

void deletedeadloads(Object *proc) {
    propagateinstructions(proc, &load_immediate_prop, (copts.optimizationlevel >= 4) ? 4 : 1, 0);
    deletedloads = propagated_instructions;
}