rename some stuff and use an enum for RegClass

This commit is contained in:
Ash Wolf 2022-12-14 01:00:56 +00:00
parent 25bab8b1fb
commit bc1321735c
28 changed files with 234 additions and 293 deletions

View File

@ -4,6 +4,7 @@
#include "compiler/CopyPropagation.h" #include "compiler/CopyPropagation.h"
#include "compiler/PCode.h" #include "compiler/PCode.h"
#include "compiler/PCodeInfo.h" #include "compiler/PCodeInfo.h"
#include "compiler/Registers.h"
#include "compiler/StackFrame.h" #include "compiler/StackFrame.h"
#include "compiler/CError.h" #include "compiler/CError.h"
#include "compiler/CParser.h" #include "compiler/CParser.h"
@ -19,12 +20,12 @@ static int is_add(PCode *instr) {
instr->op == PC_ADDI && instr->op == PC_ADDI &&
( (
instr->args[2].kind == PCOp_IMMEDIATE || instr->args[2].kind == PCOp_IMMEDIATE ||
(instr->args[2].kind == PCOp_MEMORY && (unsigned char) instr->args[2].arg == 1) (instr->args[2].kind == PCOp_MEMORY && (PCOpMemoryArg) instr->args[2].arg == PCOpMemory1)
) )
) )
) )
&& &&
instr->args[0].data.reg.reg >= n_real_registers[(char) instr->args[0].arg]; instr->args[0].data.reg.reg >= n_real_registers[instr->args[0].arg];
} }
static int addpropagatestouse(int candidateID, int useID) { static int addpropagatestouse(int candidateID, int useID) {
@ -140,9 +141,7 @@ static int addpropagatestouse(int candidateID, int useID) {
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (
op->kind == PCOp_REGISTER && PC_OP_IS_WRITE_ANY_REGISTER(op, RegClass_GPR) &&
op->arg == RegClass_GPR &&
(op->data.reg.effect & EffectWrite) &&
(op->data.reg.reg == reg2 || op->data.reg.reg == reg27) (op->data.reg.reg == reg2 || op->data.reg.reg == reg27)
) )
return 0; return 0;
@ -161,9 +160,7 @@ static int addpropagatestouse(int candidateID, int useID) {
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (
op->kind == PCOp_REGISTER && PC_OP_IS_WRITE_ANY_REGISTER(op, RegClass_GPR) &&
op->arg == RegClass_GPR &&
(op->data.reg.effect & EffectWrite) &&
(op->data.reg.reg == reg2 || op->data.reg.reg == reg27) (op->data.reg.reg == reg2 || op->data.reg.reg == reg27)
) )
return 0; return 0;

View File

@ -544,7 +544,7 @@ void gather_alias_info(void) {
if ( if (
(!(pcode->flags & (fPCodeFlag4 | fPCodeFlag40000)) || op != pcode->args) && (!(pcode->flags & (fPCodeFlag4 | fPCodeFlag40000)) || op != pcode->args) &&
op->kind == PCOp_REGISTER && op->kind == PCOp_REGISTER &&
op->arg == RegClass_GPR && (RegClass) op->arg == RegClass_GPR &&
(op->data.reg.effect & EffectRead) (op->data.reg.effect & EffectRead)
) { ) {
alias_array[aliases_idx] = NULL; alias_array[aliases_idx] = NULL;

View File

@ -138,7 +138,7 @@ static int isuniquedefinition(PCode *pcode, Loop *loop) {
return 0; return 0;
if (def->v.kind == PCOp_REGISTER) { if (def->v.kind == PCOp_REGISTER) {
for (list = reg_Defs[(char) def->v.arg][def->v.u.reg]; list; list = list->next) { for (list = reg_Defs[def->v.arg][def->v.u.reg]; list; list = list->next) {
if ( if (
bitvectorgetbit(Defs[list->id].pcode->block->blockIndex, loop->memberblocks) && bitvectorgetbit(Defs[list->id].pcode->block->blockIndex, loop->memberblocks) &&
list->id != defID list->id != defID
@ -171,7 +171,7 @@ static int uniquelyreachesuse(int defID, int useID) {
def = &Defs[defID]; def = &Defs[defID];
use = &Uses[useID]; use = &Uses[useID];
if (def->v.kind == PCOp_REGISTER) { if (def->v.kind == PCOp_REGISTER) {
for (list = reg_Defs[(char) def->v.arg][def->v.u.reg]; list; list = list->next) { for (list = reg_Defs[def->v.arg][def->v.u.reg]; list; list = list->next) {
if ( if (
list->id != defID && list->id != defID &&
bitvectorgetbit(list->id, usedefinfo[use->pcode->block->blockIndex].defvec8) bitvectorgetbit(list->id, usedefinfo[use->pcode->block->blockIndex].defvec8)
@ -209,7 +209,7 @@ static int uniquelyreachesalluses(int defID, Loop *loop) {
def = &Defs[defID]; def = &Defs[defID];
if (def->v.kind == PCOp_REGISTER) { if (def->v.kind == PCOp_REGISTER) {
for (list = reg_Uses[(char) def->v.arg][def->v.u.reg]; list; list = list->next) { for (list = reg_Uses[def->v.arg][def->v.u.reg]; list; list = list->next) {
if ( if (
bitvectorgetbit(list->id, usedefinfo[loop->preheader->blockIndex].usevec1C) || bitvectorgetbit(list->id, usedefinfo[loop->preheader->blockIndex].usevec1C) ||
(bitvectorgetbit(Uses[list->id].pcode->block->blockIndex, loop->memberblocks) && !uniquelyreachesuse(defID, list->id)) (bitvectorgetbit(Uses[list->id].pcode->block->blockIndex, loop->memberblocks) && !uniquelyreachesuse(defID, list->id))
@ -241,7 +241,7 @@ static int isliveonexit(TinyValue *v, Loop *loop) {
vec = usedefinfo[loop->preheader->blockIndex].usevec1C; vec = usedefinfo[loop->preheader->blockIndex].usevec1C;
if (v->kind == PCOp_REGISTER) { if (v->kind == PCOp_REGISTER) {
for (list = reg_Uses[(char) v->arg][v->u.reg]; list; list = list->next) { for (list = reg_Uses[v->arg][v->u.reg]; list; list = list->next) {
if ( if (
bitvectorgetbit(list->id, vec) && bitvectorgetbit(list->id, vec) &&
!bitvectorgetbit(Uses[list->id].pcode->block->blockIndex, loop->memberblocks) !bitvectorgetbit(Uses[list->id].pcode->block->blockIndex, loop->memberblocks)
@ -317,7 +317,7 @@ static void moveinvariantcomputation(PCode *pcode, Loop *loop) {
if (def->v.kind == PCOp_REGISTER) { if (def->v.kind == PCOp_REGISTER) {
for (blocklist = loop->blocks; blocklist; blocklist = blocklist->next) { for (blocklist = loop->blocks; blocklist; blocklist = blocklist->next) {
for (list = reg_Defs[(char) def->v.arg][def->v.u.reg]; list; list = list->next) for (list = reg_Defs[def->v.arg][def->v.u.reg]; list; list = list->next)
bitvectorclearbit(list->id, usedefinfo[blocklist->block->blockIndex].defvec8); bitvectorclearbit(list->id, usedefinfo[blocklist->block->blockIndex].defvec8);
bitvectorsetbit(defID, usedefinfo[blocklist->block->blockIndex].defvec8); bitvectorsetbit(defID, usedefinfo[blocklist->block->blockIndex].defvec8);
} }
@ -874,10 +874,10 @@ static void moveinvariantsfromloop(Loop *loop) {
for (def = &Defs[defID = instr->defID]; defID < number_of_Defs && def->pcode == instr; def++, defID++) { for (def = &Defs[defID = instr->defID]; defID < number_of_Defs && def->pcode == instr; def++, defID++) {
if (def->v.kind == PCOp_REGISTER) { if (def->v.kind == PCOp_REGISTER) {
for (list = reg_Defs[(char) def->v.arg][def->v.u.reg]; list; list = list->next) for (list = reg_Defs[def->v.arg][def->v.u.reg]; list; list = list->next)
bitvectorclearbit(list->id, myvec); bitvectorclearbit(list->id, myvec);
} else if (def->v.kind == PCOp_MEMORY) { } else if (def->v.kind == PCOp_MEMORY) {
if ((char) def->v.arg == 0) { if (def->v.arg == PCOpMemory0) {
for (list = findobjectusedef(def->v.u.object)->defs; list; list = list->next) { for (list = findobjectusedef(def->v.u.object)->defs; list; list = list->next) {
if (uniquely_aliases(instr, Defs[list->id].pcode)) if (uniquely_aliases(instr, Defs[list->id].pcode))
bitvectorclearbit(list->id, myvec); bitvectorclearbit(list->id, myvec);

View File

@ -10,7 +10,7 @@
#include "compiler/StackFrame.h" #include "compiler/StackFrame.h"
#include "compiler/objects.h" #include "compiler/objects.h"
char coloring_class; RegClass coloring_class;
static short used_regs_before_coloring; static short used_regs_before_coloring;
static void markspecialregisters(RegClass rclass) { static void markspecialregisters(RegClass rclass) {
@ -198,7 +198,7 @@ static void rewritepcode(void) {
if ( if (
(instr->flags & fPCodeFlag10) && (instr->flags & fPCodeFlag10) &&
((char) instr->args[1].arg == coloring_class) && (instr->args[1].arg == coloring_class) &&
instr->args[1].data.reg.reg == instr->args[0].data.reg.reg instr->args[1].data.reg.reg == instr->args[0].data.reg.reg
) )
deletepcode(instr); deletepcode(instr);

View File

@ -1,15 +1,12 @@
#include "compiler/CopyPropagation.h" #include "compiler/CopyPropagation.h"
#include "compiler/CMangler.h" #include "compiler/CMangler.h"
#include "compiler/CParser.h" #include "compiler/CParser.h"
#include "compiler/CodeGen.h"
#include "compiler/CompilerTools.h"
#include "compiler/UseDefChains.h"
#include "compiler/PCode.h"
#include "compiler/RegisterInfo.h"
#include "compiler/BitVectors.h" #include "compiler/BitVectors.h"
#include "compiler/CompilerTools.h"
// TODO move me #include "compiler/PCode.h"
extern void pclistblocks(char *, char *); #include "compiler/PCodeListing.h"
#include "compiler/RegisterInfo.h"
#include "compiler/UseDefChains.h"
int propagatedcopies; int propagatedcopies;
int propagated_instructions; int propagated_instructions;
@ -98,13 +95,13 @@ static void computecandidatelist(void) {
} }
for (def = &Defs[defID = pcode->defID]; defID < number_of_Defs && def->pcode == pcode; def++, defID++) { for (def = &Defs[defID = pcode->defID]; defID < number_of_Defs && def->pcode == pcode; def++, defID++) {
if (def->kind == PCOp_REGISTER) { if (def->v.kind == PCOp_REGISTER) {
for (list = reg_Uses[def->arg][def->u.reg]; list; list = list->next) for (list = reg_Uses[def->v.arg][def->v.u.reg]; list; list = list->next)
bitvectorclearbit(list->id, vec); bitvectorclearbit(list->id, vec);
} }
} }
for (use = &Uses[useID = pcode->useID]; useID < number_of_Uses && use->pcode == pcode; use++, useID++) { for (use = &Uses[useID = pcode->useID]; useID < number_of_Uses && use->pcode == pcode; use++, useID++) {
if (use->kind == PCOp_REGISTER) if (use->v.kind == PCOp_REGISTER)
bitvectorsetbit(useID, vec); bitvectorsetbit(useID, vec);
} }
} }
@ -224,7 +221,7 @@ static void computeglobalpropinfo(void) {
UInt32 *vec8; UInt32 *vec8;
UInt32 *vecC; UInt32 *vecC;
int i; int i;
int j; int blockIndex;
int flag; int flag;
PCLink *preds; PCLink *preds;
UInt32 val; UInt32 val;
@ -245,10 +242,10 @@ static void computeglobalpropinfo(void) {
while (flag) { while (flag) {
flag = 0; flag = 0;
for (i = 0; i < pcblockcount; i++) { for (blockIndex = 0; blockIndex < pcblockcount; blockIndex++) {
if (depthfirstordering[i]) { if (depthfirstordering[blockIndex]) {
info = &propinfo[depthfirstordering[i]->blockIndex]; info = &propinfo[depthfirstordering[blockIndex]->blockIndex];
if ((preds = depthfirstordering[i]->predecessors)) { if ((preds = depthfirstordering[blockIndex]->predecessors)) {
vec8 = info->vec8; vec8 = info->vec8;
bitvectorcopy(vec8, propinfo[preds->block->blockIndex].vecC, number_of_candidates); bitvectorcopy(vec8, propinfo[preds->block->blockIndex].vecC, number_of_candidates);
for (preds = preds->nextLink; preds; preds = preds->nextLink) for (preds = preds->nextLink; preds; preds = preds->nextLink)
@ -259,7 +256,7 @@ static void computeglobalpropinfo(void) {
vec8 = info->vec8; vec8 = info->vec8;
vec0 = info->vec0; vec0 = info->vec0;
vec4 = info->vec4; vec4 = info->vec4;
for (j = 0; j < bitvecsize; j++) { for (i = 0; i < bitvecsize; i++) {
val = *vec0 | (*vec8 & ~*vec4); val = *vec0 | (*vec8 & ~*vec4);
if (val != *vecC) { if (val != *vecC) {
*vecC = val; *vecC = val;
@ -359,7 +356,7 @@ static int copypropagatestouse(int candidateID, int useID) {
UseOrDef *use; UseOrDef *use;
short reg1; short reg1;
short reg2; short reg2;
char rclass; RegClass rclass;
PCode *pcode; PCode *pcode;
int i; int i;
PCode *scan; PCode *scan;
@ -419,7 +416,7 @@ static int copypropagatestouse(int candidateID, int useID) {
static void propagateandremovecopy(int id) { static void propagateandremovecopy(int id) {
Candidate *candidate; Candidate *candidate;
unsigned char rclass; RegClass rclass;
short reg1; short reg1;
short reg2; short reg2;
RegUseOrDef *list; RegUseOrDef *list;
@ -434,7 +431,7 @@ static void propagateandremovecopy(int id) {
if (rclass == RegClass_GPR && reg1 >= 32 && reg1 <= last_exception_register[RegClass_GPR]) if (rclass == RegClass_GPR && reg1 >= 32 && reg1 <= last_exception_register[RegClass_GPR])
return; return;
if (!moreaggressiveoptimization && reg2 < n_real_registers[(char) rclass]) if (!moreaggressiveoptimization && reg2 < n_real_registers[rclass])
return; return;
for (list = candidate->list; list; list = list->next) { for (list = candidate->list; list; list = list->next) {
@ -443,7 +440,7 @@ static void propagateandremovecopy(int id) {
while (i--) { while (i--) {
if ( if (
op->kind == PCOp_REGISTER && op->kind == PCOp_REGISTER &&
op->arg == (char) rclass && op->arg == rclass &&
op->data.reg.reg == reg1 && op->data.reg.reg == reg1 &&
(op->data.reg.effect & EffectRead) (op->data.reg.effect & EffectRead)
) )

View File

@ -21,7 +21,7 @@ void InlineAsm_InitializeRegisters() {
hashedregisters[i] = NULL; hashedregisters[i] = NULL;
} }
void InlineAsm_InsertRegister(char *name, char rclass, short num, Object *object) { void InlineAsm_InsertRegister(char *name, RegClass rclass, short num, Object *object) {
HashedRegister **ptr; HashedRegister **ptr;
HashedRegister *hr; HashedRegister *hr;

View File

@ -23,7 +23,7 @@ typedef struct RegInfo {
typedef struct AsmRegister { typedef struct AsmRegister {
char *name; char *name;
char rclass; RegClass rclass;
SInt32 num; SInt32 num;
} AsmRegister; } AsmRegister;

View File

@ -53,25 +53,19 @@ static void buildinterferencematrix(void) {
vec = oalloc(4 * ((regs + 31) >> 5)); vec = oalloc(4 * ((regs + 31) >> 5));
for (block = pcbasicblocks; block; block = block->nextBlock) { for (block = pcbasicblocks; block; block = block->nextBlock) {
bitvectorcopy(vec, liveinfo[block->blockIndex].vecC, regs); bitvectorcopy(vec, liveinfo[block->blockIndex].out, regs);
for (instr = block->lastPCode; instr; instr = instr->prevPCode) { for (instr = block->lastPCode; instr; instr = instr->prevPCode) {
op = instr->args; op = instr->args;
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (PC_OP_IS_WRITE_ANY_REGISTER(op, coloring_class)) {
op->kind == PCOp_REGISTER &&
(char) op->arg == coloring_class &&
(op->data.reg.effect & EffectWrite)
)
{
reg = op->data.reg.reg; reg = op->data.reg.reg;
bitvectorclearbit(reg, vec); bitvectorclearbit(reg, vec);
for (j = 0; j < regs; j++) { for (j = 0; j < regs; j++) {
if (bitvectorgetbit(j, vec)) { if (bitvectorgetbit(j, vec)) {
if ( if (
(instr->flags & fPCodeFlag10) && (instr->flags & fPCodeFlag10) &&
instr->args[0].kind == PCOp_REGISTER && PC_OP_IS_ANY_REGISTER(&instr->args[0], coloring_class) &&
(char) instr->args[0].arg == coloring_class &&
instr->args[1].data.reg.reg == j instr->args[1].data.reg.reg == j
) )
continue; continue;
@ -85,12 +79,7 @@ static void buildinterferencematrix(void) {
op = instr->args; op = instr->args;
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (PC_OP_IS_READ_ANY_REGISTER(op, coloring_class)) {
op->kind == PCOp_REGISTER &&
(char) op->arg == coloring_class &&
(op->data.reg.effect & EffectRead)
)
{
reg = op->data.reg.reg; reg = op->data.reg.reg;
if (bitvectorgetbit(reg, vec) == 0) if (bitvectorgetbit(reg, vec) == 0)
op->data.reg.effect |= Effect4; op->data.reg.effect |= Effect4;
@ -196,7 +185,7 @@ static void coalescenodes(void) {
} }
} }
if (instr->args[0].kind == PCOp_REGISTER && (char) instr->args[0].arg == coloring_class) { if (PC_OP_IS_ANY_REGISTER(&instr->args[0], coloring_class)) {
path1 = coalesced_path(instr->args[0].data.reg.reg); path1 = coalesced_path(instr->args[0].data.reg.reg);
path2 = coalesced_path(instr->args[1].data.reg.reg); path2 = coalesced_path(instr->args[1].data.reg.reg);
if (path1 == path2) { if (path1 == path2) {
@ -240,11 +229,7 @@ static void coalescenodes(void) {
op = instr->args; op = instr->args;
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (PC_OP_IS_ANY_REGISTER(op, coloring_class) && op->data.reg.reg != coalesced[op->data.reg.reg])
op->kind == PCOp_REGISTER &&
(char) op->arg == coloring_class &&
op->data.reg.reg != coalesced[op->data.reg.reg]
)
op->data.reg.reg = coalesced_path(op->data.reg.reg); op->data.reg.reg = coalesced_path(op->data.reg.reg);
op++; op++;
} }
@ -307,7 +292,7 @@ static void eliminatedeadcode(void) {
vec = oalloc(4 * ((regs + 31) >> 5)); vec = oalloc(4 * ((regs + 31) >> 5));
for (block = pcbasicblocks; block; block = block->nextBlock) { for (block = pcbasicblocks; block; block = block->nextBlock) {
bitvectorcopy(vec, liveinfo[block->blockIndex].vecC, regs); bitvectorcopy(vec, liveinfo[block->blockIndex].out, regs);
for (instr = block->lastPCode; instr; instr = instr->prevPCode) { for (instr = block->lastPCode; instr; instr = instr->prevPCode) {
if (dead(instr, coloring_class, vec)) { if (dead(instr, coloring_class, vec)) {
deletepcode(instr); deletepcode(instr);
@ -317,11 +302,7 @@ static void eliminatedeadcode(void) {
op = instr->args; op = instr->args;
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (PC_OP_IS_WRITE_ANY_REGISTER(op, coloring_class))
op->kind == PCOp_REGISTER &&
(char) op->arg == coloring_class &&
(op->data.reg.effect & EffectWrite)
)
bitvectorclearbit(op->data.reg.reg, vec); bitvectorclearbit(op->data.reg.reg, vec);
op++; op++;
} }
@ -329,12 +310,7 @@ static void eliminatedeadcode(void) {
op = instr->args; op = instr->args;
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (PC_OP_IS_READ_ANY_REGISTER(op, coloring_class)) {
op->kind == PCOp_REGISTER &&
(char) op->arg == coloring_class &&
(op->data.reg.effect & EffectRead)
)
{
int reg = op->data.reg.reg; int reg = op->data.reg.reg;
if (!bitvectorgetbit(reg, vec)) if (!bitvectorgetbit(reg, vec))
op->data.reg.effect |= Effect4; op->data.reg.effect |= Effect4;
@ -362,9 +338,7 @@ static void findrematerializations(void) {
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (
op->kind == PCOp_REGISTER && PC_OP_IS_WRITE_ANY_REGISTER(op, coloring_class) &&
(char) op->arg == coloring_class &&
(op->data.reg.effect & EffectWrite) &&
op->data.reg.reg >= n_real_registers[coloring_class] && op->data.reg.reg >= n_real_registers[coloring_class] &&
!(interferencegraph[op->data.reg.reg]->flags & (fPairLow | fPairHigh)) && !(interferencegraph[op->data.reg.reg]->flags & (fPairLow | fPairHigh)) &&
!(interferencegraph[op->data.reg.reg]->flags & fIGNode40) !(interferencegraph[op->data.reg.reg]->flags & fIGNode40)

View File

@ -19,10 +19,10 @@ static void allocateliveinfo(void) {
liveinfo = oalloc(sizeof(LiveInfo) * pcblockcount); liveinfo = oalloc(sizeof(LiveInfo) * pcblockcount);
for (i = 0, info = liveinfo; i < pcblockcount; i++, info++) { for (i = 0, info = liveinfo; i < pcblockcount; i++, info++) {
bitvectorinitialize(info->vec0 = oalloc(4 * ((regs + 31) >> 5)), regs, 0); bitvectorinitialize(info->use = oalloc(4 * ((regs + 31) >> 5)), regs, 0);
bitvectorinitialize(info->vec4 = oalloc(4 * ((regs + 31) >> 5)), regs, 0); bitvectorinitialize(info->def = oalloc(4 * ((regs + 31) >> 5)), regs, 0);
bitvectorinitialize(info->vec8 = oalloc(4 * ((regs + 31) >> 5)), regs, 0); bitvectorinitialize(info->in = oalloc(4 * ((regs + 31) >> 5)), regs, 0);
bitvectorinitialize(info->vecC = oalloc(4 * ((regs + 31) >> 5)), regs, 0); bitvectorinitialize(info->out = oalloc(4 * ((regs + 31) >> 5)), regs, 0);
} }
} }
@ -30,40 +30,30 @@ static void computelocalusedef(void) {
LiveInfo *info; LiveInfo *info;
PCodeBlock *block; PCodeBlock *block;
PCode *instr; PCode *instr;
UInt32 *vec0; UInt32 *use;
UInt32 *vec4; UInt32 *def;
PCodeArg *op; PCodeArg *op;
int i; int i;
for (block = pcbasicblocks; block; block = block->nextBlock) { for (block = pcbasicblocks; block; block = block->nextBlock) {
info = &liveinfo[block->blockIndex]; info = &liveinfo[block->blockIndex];
vec0 = info->vec0; use = info->use;
vec4 = info->vec4; def = info->def;
for (instr = block->firstPCode; instr; instr = instr->nextPCode) { for (instr = block->firstPCode; instr; instr = instr->nextPCode) {
op = instr->args; op = instr->args;
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (PC_OP_IS_READ_ANY_REGISTER(op, coloring_class) && !bitvectorgetbit(op->data.reg.reg, def))
op->kind == PCOp_REGISTER && bitvectorsetbit(op->data.reg.reg, use);
(char) op->arg == coloring_class &&
(op->data.reg.effect & EffectRead) &&
!bitvectorgetbit(op->data.reg.reg, vec4)
)
bitvectorsetbit(op->data.reg.reg, vec0);
op++; op++;
} }
op = instr->args; op = instr->args;
i = instr->argCount; i = instr->argCount;
while (i--) { while (i--) {
if ( if (PC_OP_IS_WRITE_ANY_REGISTER(op, coloring_class) && !bitvectorgetbit(op->data.reg.reg, use))
op->kind == PCOp_REGISTER && bitvectorsetbit(op->data.reg.reg, def);
(char) op->arg == coloring_class &&
(op->data.reg.effect & EffectWrite) &&
!bitvectorgetbit(op->data.reg.reg, vec0)
)
bitvectorsetbit(op->data.reg.reg, vec4);
op++; op++;
} }
} }
@ -73,10 +63,10 @@ static void computelocalusedef(void) {
static void computeglobalinout(void) { static void computeglobalinout(void) {
UInt32 regs; UInt32 regs;
LiveInfo *info; LiveInfo *info;
UInt32 *vec0; UInt32 *use;
UInt32 *vec4; UInt32 *def;
UInt32 *vec8; UInt32 *in;
UInt32 *vecC; UInt32 *out;
int bitvecsize; int bitvecsize;
int blockIndex; int blockIndex;
int i; int i;
@ -95,26 +85,26 @@ static void computeglobalinout(void) {
if ((block = depthfirstordering[--blockIndex])) { if ((block = depthfirstordering[--blockIndex])) {
info = &liveinfo[block->blockIndex]; info = &liveinfo[block->blockIndex];
if ((link = block->successors)) { if ((link = block->successors)) {
vecC = info->vecC; out = info->out;
bitvectorcopy(vecC, liveinfo[link->block->blockIndex].vec8, regs); bitvectorcopy(out, liveinfo[link->block->blockIndex].in, regs);
for (link = link->nextLink; link; link = link->nextLink) for (link = link->nextLink; link; link = link->nextLink)
bitvectorunion(vecC, liveinfo[link->block->blockIndex].vec8, regs); bitvectorunion(out, liveinfo[link->block->blockIndex].in, regs);
} }
vecC = info->vecC; out = info->out;
vec8 = info->vec8; in = info->in;
vec0 = info->vec0; use = info->use;
vec4 = info->vec4; def = info->def;
for (i = 0; i < bitvecsize; i++) { for (i = 0; i < bitvecsize; i++) {
val = *vec0 | (*vecC & ~*vec4); val = *use | (*out & ~*def);
if (val != *vec8) { if (val != *in) {
*vec8 = val; *in = val;
flag = 1; flag = 1;
} }
vec8++; in++;
vecC++; out++;
vec0++; use++;
vec4++; def++;
} }
} }
} }
@ -130,19 +120,19 @@ void computelivevariables(Object *proc) {
computelocalusedef(); computelocalusedef();
if (coloring_class == RegClass_GPR && TYPE_FITS_IN_REGISTER(returnType)) { if (coloring_class == RegClass_GPR && TYPE_FITS_IN_REGISTER(returnType)) {
bitvectorsetbit(3, liveinfo[epilogue->blockIndex].vec0); bitvectorsetbit(3, liveinfo[epilogue->blockIndex].use);
if (TYPE_IS_8BYTES(returnType)) if (TYPE_IS_8BYTES(returnType))
bitvectorsetbit(4, liveinfo[pclastblock->blockIndex].vec0); bitvectorsetbit(4, liveinfo[pclastblock->blockIndex].use);
} else if (coloring_class == RegClass_FPR && IS_TYPE_FLOAT(returnType)) { } else if (coloring_class == RegClass_FPR && IS_TYPE_FLOAT(returnType)) {
bitvectorsetbit(1, liveinfo[epilogue->blockIndex].vec0); bitvectorsetbit(1, liveinfo[epilogue->blockIndex].use);
} else if (coloring_class == RegClass_VR && IS_TYPE_VECTOR(returnType)) { } else if (coloring_class == RegClass_VR && IS_TYPE_VECTOR(returnType)) {
bitvectorsetbit(2, liveinfo[epilogue->blockIndex].vec0); bitvectorsetbit(2, liveinfo[epilogue->blockIndex].use);
} }
computeglobalinout(); computeglobalinout();
} }
int dead(PCode *instr, char rclass, UInt32 *vec) { int dead(PCode *instr, RegClass rclass, UInt32 *vec) {
int i; int i;
PCodeArg *op; PCodeArg *op;
@ -157,7 +147,7 @@ int dead(PCode *instr, char rclass, UInt32 *vec) {
if ( if (
op->kind == PCOp_REGISTER && op->kind == PCOp_REGISTER &&
(op->data.reg.effect & EffectWrite) && (op->data.reg.effect & EffectWrite) &&
(rclass != (char) op->arg || bitvectorgetbit(op->data.reg.reg, vec)) (rclass != op->arg || bitvectorgetbit(op->data.reg.reg, vec))
) )
return 0; return 0;
op++; op++;

View File

@ -3,6 +3,7 @@
#include "compiler/CParser.h" #include "compiler/CParser.h"
#include "compiler/PCode.h" #include "compiler/PCode.h"
#include "compiler/PCodeInfo.h" #include "compiler/PCodeInfo.h"
#include "compiler/Registers.h"
int deletedloads; int deletedloads;
@ -10,7 +11,7 @@ static int is_load(PCode *instr) {
return return
(instr->op == PC_LI || instr->op == PC_VSPLTISB || instr->op == PC_VSPLTISH || instr->op == PC_VSPLTISW) (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[(char) instr->args[0].arg]; instr->args[0].data.reg.reg >= n_real_registers[instr->args[0].arg];
} }
static int loadpropagatestouse(int candidateID, int useID) { static int loadpropagatestouse(int candidateID, int useID) {
@ -23,7 +24,7 @@ static void deleteload(int id) {
candidate = Candidates + id; candidate = Candidates + id;
if (candidate->list || (candidate->pcode->flags & fSideEffects)) if (candidate->list || (candidate->pcode->flags & fSideEffects))
return; return;
if (candidate->pcode->args[0].data.reg.reg < n_real_registers[(char) candidate->pcode->args[0].arg]) if (candidate->pcode->args[0].data.reg.reg < n_real_registers[candidate->pcode->args[0].arg])
return; return;
deletepcode(candidate->pcode); deletepcode(candidate->pcode);

View File

@ -5,6 +5,7 @@
#include "compiler/CompilerTools.h" #include "compiler/CompilerTools.h"
#include "compiler/LoopDetection.h" #include "compiler/LoopDetection.h"
#include "compiler/PCode.h" #include "compiler/PCode.h"
#include "compiler/Registers.h"
#include "compiler/UseDefChains.h" #include "compiler/UseDefChains.h"
#include "compiler/objects.h" #include "compiler/objects.h"
#include "compiler/types.h" #include "compiler/types.h"
@ -1309,7 +1310,7 @@ void changearraytoregisters(void) {
while (i--) { while (i--) {
if ( if (
op->kind == PCOp_MEMORY && op->kind == PCOp_MEMORY &&
(unsigned char) op->arg == 1 && (PCOpMemoryArg) op->arg == PCOpMemory1 &&
(array = lookup_array_object(arrays, op->data.mem.obj)) && (array = lookup_array_object(arrays, op->data.mem.obj)) &&
!array->invalid !array->invalid
) { ) {
@ -1475,7 +1476,7 @@ void changearraytoregisters(void) {
instr->argCount && instr->argCount &&
(instr->flags & (fPCodeFlag2 | fPCodeFlag4)) && (instr->flags & (fPCodeFlag2 | fPCodeFlag4)) &&
instr->args[2].kind == PCOp_MEMORY && instr->args[2].kind == PCOp_MEMORY &&
(unsigned char) instr->args[2].arg == 1 && (PCOpMemoryArg) instr->args[2].arg == PCOpMemory1 &&
(array = lookup_array_object(arrays, instr->args[2].data.mem.obj)) && (array = lookup_array_object(arrays, instr->args[2].data.mem.obj)) &&
!(array->invalid) !(array->invalid)
) )

View File

@ -126,10 +126,10 @@ static void pclistblock(PCodeBlock *block, char *format, UInt32 vecSize) {
if (vecSize) { if (vecSize) {
fprintf(pcfile, "............................................................\n"); fprintf(pcfile, "............................................................\n");
formatdataflowset("use", liveinfo[block->blockIndex].vec0, vecSize, format); formatdataflowset("use", liveinfo[block->blockIndex].use, vecSize, format);
formatdataflowset("def", liveinfo[block->blockIndex].vec4, vecSize, format); formatdataflowset("def", liveinfo[block->blockIndex].def, vecSize, format);
formatdataflowset("in ", liveinfo[block->blockIndex].vec8, vecSize, format); formatdataflowset("in ", liveinfo[block->blockIndex].in, vecSize, format);
formatdataflowset("out", liveinfo[block->blockIndex].vecC, vecSize, format); formatdataflowset("out", liveinfo[block->blockIndex].out, vecSize, format);
} }
fflush(pcfile); fflush(pcfile);

View File

@ -18,7 +18,7 @@ static UInt8 save_state[RegisterMax];
short spr_to_sysreg[4] = {1, 8, 9, 0x100}; short spr_to_sysreg[4] = {1, 8, 9, 0x100};
void asm_used_register(char rclass, short reg) { void asm_used_register(RegClass rclass, short reg) {
int i; int i;
if ((reg < n_real_registers[rclass]) && (reg_state[rclass][reg] == RegState0)) { if ((reg < n_real_registers[rclass]) && (reg_state[rclass][reg] == RegState0)) {
@ -39,7 +39,7 @@ void asm_used_register(char rclass, short reg) {
} }
} }
void retain_register(Object *obj, char rclass, short reg) { void retain_register(Object *obj, RegClass rclass, short reg) {
VarInfo *vi; VarInfo *vi;
#line 95 #line 95
@ -79,7 +79,7 @@ int is_register_object(Object *obj) {
return obj->sclass == OBJECT_SCLASS_101; return obj->sclass == OBJECT_SCLASS_101;
} }
int GetABIFirstNonVolatile(char rclass) { int GetABIFirstNonVolatile(RegClass rclass) {
switch (rclass) { switch (rclass) {
case RegClass_SPR: return 3; case RegClass_SPR: return 3;
case RegClass_CRFIELD: return 2; case RegClass_CRFIELD: return 2;
@ -90,7 +90,7 @@ int GetABIFirstNonVolatile(char rclass) {
} }
} }
char GetRegisterClassName(char rclass) { char GetRegisterClassName(RegClass rclass) {
switch (rclass) { switch (rclass) {
case RegClass_VR: return 'v'; case RegClass_VR: return 'v';
case RegClass_GPR: return 'r'; case RegClass_GPR: return 'r';
@ -102,7 +102,7 @@ char GetRegisterClassName(char rclass) {
} }
} }
static int first_nonvolatile_reg(char rclass) { static int first_nonvolatile_reg(RegClass rclass) {
return GetABIFirstNonVolatile(rclass); return GetABIFirstNonVolatile(rclass);
} }
@ -120,7 +120,7 @@ void setup_diagnostic_reg_strings(void) {
} }
void init_target_registers(void) { void init_target_registers(void) {
char rclass; RegClass rclass;
int reg; int reg;
int end; int end;
int tmp; int tmp;
@ -130,7 +130,7 @@ void init_target_registers(void) {
for (rclass = 0; rclass < RegClassMax; rclass++) { for (rclass = 0; rclass < RegClassMax; rclass++) {
for (reg = 0; reg < RegisterMax; reg++) for (reg = 0; reg < RegisterMax; reg++)
special_register_names[(char)rclass][reg] = NULL; special_register_names[rclass][reg] = NULL;
} }
special_register_names[RegClass_SPR][0] = "XER"; special_register_names[RegClass_SPR][0] = "XER";
@ -150,27 +150,27 @@ void init_target_registers(void) {
reg_state[RegClass_CRFIELD][5] = RegState2; reg_state[RegClass_CRFIELD][5] = RegState2;
for (rclass = 0; rclass < RegClassMax; rclass++) { for (rclass = 0; rclass < RegClassMax; rclass++) {
n_nonvolatile_registers[(char)rclass] = 0; n_nonvolatile_registers[rclass] = 0;
if (last_nonvolatile_reg[(char)rclass] >= 0) { if (last_nonvolatile_reg[rclass] >= 0) {
end = first_nonvolatile_reg(rclass); end = first_nonvolatile_reg(rclass);
for (reg = last_nonvolatile_reg[(char)rclass]; reg >= end; reg--) { for (reg = last_nonvolatile_reg[rclass]; reg >= end; reg--) {
if (reg_state[(char)rclass][reg] == RegState0) { if (reg_state[rclass][reg] == RegState0) {
tmp = n_nonvolatile_registers[(char)rclass]++; tmp = n_nonvolatile_registers[rclass]++;
nonvolatile_registers[(char)rclass][tmp] = reg; nonvolatile_registers[rclass][tmp] = reg;
} }
} }
} }
assignable_registers[(char)rclass] = n_nonvolatile_registers[(char)rclass] - nonvol_reserve[(char)rclass]; assignable_registers[rclass] = n_nonvolatile_registers[rclass] - nonvol_reserve[rclass];
if (assignable_registers[(char)rclass] < 0) if (assignable_registers[rclass] < 0)
assignable_registers[(char)rclass] = 0; assignable_registers[rclass] = 0;
n_scratch_registers[(char)rclass] = 0; n_scratch_registers[rclass] = 0;
for (reg = 0; reg < n_real_registers[(char)rclass]; reg++) { for (reg = 0; reg < n_real_registers[rclass]; reg++) {
if (reg < GetABIFirstNonVolatile(rclass) || reg > last_nonvolatile_reg[(char)rclass]) { if (reg < GetABIFirstNonVolatile(rclass) || reg > last_nonvolatile_reg[rclass]) {
if (reg_state[(char)rclass][reg] == RegState0) { if (reg_state[rclass][reg] == RegState0) {
tmp = n_scratch_registers[(char)rclass]++; tmp = n_scratch_registers[rclass]++;
scratch_registers[(char)rclass][tmp] = reg; scratch_registers[rclass][tmp] = reg;
} }
} }
} }
@ -340,17 +340,17 @@ UInt32 colored_vrs_as_vrsave(PCodeBlock *block) {
return mask; return mask;
} }
void save_before_coloring_nonvolatile_registers(char rclass) { void save_before_coloring_nonvolatile_registers(RegClass rclass) {
used_regs_before_coloring = used_nonvolatile_registers[rclass]; used_regs_before_coloring = used_nonvolatile_registers[rclass];
memcpy(save_state, reg_state[rclass], sizeof(save_state)); memcpy(save_state, reg_state[rclass], sizeof(save_state));
} }
void reset_nonvolatile_registers(char rclass) { void reset_nonvolatile_registers(RegClass rclass) {
used_nonvolatile_registers[rclass] = used_regs_before_coloring; used_nonvolatile_registers[rclass] = used_regs_before_coloring;
memcpy(reg_state[rclass], save_state, sizeof(save_state)); memcpy(reg_state[rclass], save_state, sizeof(save_state));
} }
int is_nonvolatile_register(char rclass, int reg) { int is_nonvolatile_register(RegClass rclass, int reg) {
int i; int i;
for (i = 0; i < n_nonvolatile_registers[rclass]; i++) { for (i = 0; i < n_nonvolatile_registers[rclass]; i++) {
@ -380,7 +380,7 @@ void init_endian(void) {
} }
void update_asm_nonvolatile_registers(void) { void update_asm_nonvolatile_registers(void) {
char rclass; RegClass rclass;
int r31; int r31;
for (rclass = 0; rclass < RegClassMax; rclass++) { for (rclass = 0; rclass < RegClassMax; rclass++) {

View File

@ -5,12 +5,6 @@
#include "compiler/CompilerTools.h" #include "compiler/CompilerTools.h"
#include "compiler/objects.h" #include "compiler/objects.h"
// haven't checked this object file for .data stuff yet
// ONLY FOR TESTING
// this file gets kinda fucked up by the loop unroller
//#pragma opt_unroll_loops off
int used_virtual_registers[RegClassMax]; int used_virtual_registers[RegClassMax];
int used_nonvolatile_registers[RegClassMax]; int used_nonvolatile_registers[RegClassMax];
int assignable_registers[RegClassMax]; int assignable_registers[RegClassMax];
@ -26,6 +20,7 @@ char *register_class_name[RegClassMax];
char *register_class_format[RegClassMax]; char *register_class_format[RegClassMax];
int coloring; int coloring;
int optimizing; int optimizing;
typedef struct ModifiedRegisters { typedef struct ModifiedRegisters {
struct ModifiedRegisters *next; struct ModifiedRegisters *next;
Object *obj; Object *obj;
@ -34,28 +29,27 @@ typedef struct ModifiedRegisters {
static ModifiedRegisters *mod_regs_table[128]; static ModifiedRegisters *mod_regs_table[128];
void init_registers(void) { void init_registers(void) {
char rclass; RegClass rclass;
int j; int j;
for (rclass = 0; rclass < RegClassMax; rclass++) { for (rclass = 0; rclass < RegClassMax; rclass++) {
for (j = 0; j < RegisterMax; j++) { for (j = 0; j < RegisterMax; j++)
reg_state[(char)rclass][j] = RegState0; reg_state[rclass][j] = RegState0;
}
} }
for (rclass = 0; rclass < RegClassMax; rclass++) for (rclass = 0; rclass < RegClassMax; rclass++)
used_nonvolatile_registers[(char)rclass] = 0; used_nonvolatile_registers[rclass] = 0;
optimizing = 1; optimizing = 1;
init_target_registers(); init_target_registers();
for (rclass = 0; rclass < RegClassMax; rclass++) for (rclass = 0; rclass < RegClassMax; rclass++)
used_virtual_registers[(char)rclass] = n_real_registers[(char)rclass]; used_virtual_registers[rclass] = n_real_registers[rclass];
coloring = 1; coloring = 1;
} }
void assign_register_to_variable(Object *obj, char rclass) { void assign_register_to_variable(Object *obj, RegClass rclass) {
VarInfo *vi; VarInfo *vi;
short reg; short reg;
@ -72,7 +66,7 @@ void assign_register_to_variable(Object *obj, char rclass) {
vi->reg = reg; vi->reg = reg;
} }
void retain_register_for_argument(Object *obj, char rclass, short reg) { void retain_register_for_argument(Object *obj, RegClass rclass, short reg) {
VarInfo *vi = obj->u.var.info; VarInfo *vi = obj->u.var.info;
reg_state[rclass][reg] = RegState1; reg_state[rclass][reg] = RegState1;
vi->flags |= VarInfoFlag2; vi->flags |= VarInfoFlag2;
@ -80,7 +74,7 @@ void retain_register_for_argument(Object *obj, char rclass, short reg) {
vi->reg = reg; vi->reg = reg;
} }
int available_registers(char rclass) { int available_registers(RegClass rclass) {
int i; int i;
int count = 0; int count = 0;
@ -92,7 +86,7 @@ int available_registers(char rclass) {
return count; return count;
} }
UInt32 volatile_registers(char rclass) { UInt32 volatile_registers(RegClass rclass) {
UInt32 mask = 0; UInt32 mask = 0;
int i; int i;
int reg; int reg;
@ -106,7 +100,7 @@ UInt32 volatile_registers(char rclass) {
return mask; return mask;
} }
short obtain_nonvolatile_register(char rclass) { short obtain_nonvolatile_register(RegClass rclass) {
int best = -1; int best = -1;
while (used_nonvolatile_registers[rclass] < n_nonvolatile_registers[rclass]) { while (used_nonvolatile_registers[rclass] < n_nonvolatile_registers[rclass]) {
@ -121,54 +115,45 @@ short obtain_nonvolatile_register(char rclass) {
} }
void open_temp_registers(void) { void open_temp_registers(void) {
int rclass; RegClass rclass;
for (rclass = 0; (char)rclass < RegClassMax; rclass++) { for (rclass = 0; rclass < RegClassMax; rclass++) {
int r = used_virtual_registers[(char)rclass]; int r = used_virtual_registers[rclass];
//last_temporary_register[rclass] = r; first_temporary_register[rclass] = last_temporary_register[rclass] = r;
//first_temporary_register[rclass] = r;
first_temporary_register[(char)rclass] = last_temporary_register[(char)rclass] = r;
} }
/*rclass = 0;
while (rclass < RegClassMax) {
r = used_virtual_registers[(char)rclass];
last_temporary_register[(char)rclass] = r;
first_temporary_register[(char)rclass] = r;
rclass = rclass + 1;
}*/
} }
void check_temp_registers(void) { void check_temp_registers(void) {
char rclass; RegClass rclass;
if (!optimizing) { if (!optimizing) {
for (rclass = 0; rclass < RegClassMax; rclass++) { for (rclass = 0; rclass < RegClassMax; rclass++) {
if (used_virtual_registers[(char)rclass] > last_temporary_register[(char)rclass]) if (used_virtual_registers[rclass] > last_temporary_register[rclass])
last_temporary_register[(char)rclass] = used_virtual_registers[(char)rclass]; last_temporary_register[rclass] = used_virtual_registers[rclass];
if (used_virtual_registers[(char)rclass] > 256) if (used_virtual_registers[rclass] > 256)
used_virtual_registers[(char)rclass] = first_temporary_register[(char)rclass]; used_virtual_registers[rclass] = first_temporary_register[rclass];
} }
} }
} }
void close_temp_registers(void) { void close_temp_registers(void) {
char rclass; RegClass rclass;
for (rclass = 0; rclass < RegClassMax; rclass++) { for (rclass = 0; rclass < RegClassMax; rclass++) {
if (used_virtual_registers[(char)rclass] < last_temporary_register[(char)rclass]) if (used_virtual_registers[rclass] < last_temporary_register[rclass])
used_virtual_registers[(char)rclass] = last_temporary_register[(char)rclass]; used_virtual_registers[rclass] = last_temporary_register[rclass];
else else
last_temporary_register[(char)rclass] = used_virtual_registers[(char)rclass]; last_temporary_register[rclass] = used_virtual_registers[rclass];
} }
} }
int count_scratch_registers(void) { int count_scratch_registers(void) {
int rclass; RegClass rclass;
int count; int count;
count = 0; count = 0;
for (rclass = 0; (char)rclass < RegClassMax; rclass++) for (rclass = 0; rclass < RegClassMax; rclass++)
count += n_scratch_registers[(char)rclass]; count += n_scratch_registers[rclass];
return count; return count;
} }
@ -180,19 +165,23 @@ void init_modified_registers(void) {
} }
static void compute_modified_registers(UInt32 *masks) { static void compute_modified_registers(UInt32 *masks) {
int rclass; RegClass rclass;
PCodeBlock *block; PCodeBlock *block;
PCode *pcode; PCode *pcode;
PCodeArg *op;
int i; int i;
for (rclass = 0; rclass < RegClassMax; rclass++) for (rclass = 0; rclass < RegClassMax; rclass++)
masks[(char)rclass] = 0; masks[rclass] = 0;
for (block = pcbasicblocks; block; block = block->nextBlock) { for (block = pcbasicblocks; block; block = block->nextBlock) {
for (pcode = block->firstPCode; pcode; pcode = pcode->nextPCode) { for (pcode = block->firstPCode; pcode; pcode = pcode->nextPCode) {
for (i = 0; i < pcode->argCount; i++) { op = pcode->args;
if (pcode->args[i].kind == PCOp_REGISTER && pcode->args[i].data.reg.effect & EffectWrite) i = pcode->argCount;
masks[pcode->args[i].arg] |= 1 << pcode->args[i].data.reg.reg; while (i--) {
if (op->kind == PCOp_REGISTER && (op->data.reg.effect & EffectWrite))
masks[op->arg] |= 1 << op->data.reg.reg;
op++;
} }
} }
} }
@ -204,25 +193,25 @@ void note_modified_registers(Object *obj) {
mr = galloc(sizeof(ModifiedRegisters)); mr = galloc(sizeof(ModifiedRegisters));
mr->obj = obj; mr->obj = obj;
compute_modified_registers(mr->mask); compute_modified_registers(mr->mask);
mr->next = mod_regs_table[obj->name->hashval]; mr->next = mod_regs_table[obj->name->hashval & 127];
mod_regs_table[obj->name->hashval] = mr; mod_regs_table[obj->name->hashval & 127] = mr;
} }
void find_modified_registers(Object *obj, UInt32 *masks) { void find_modified_registers(Object *obj, UInt32 *masks) {
char rclass; RegClass rclass;
ModifiedRegisters *scan; ModifiedRegisters *scan;
for (rclass = 0; rclass < RegClassMax; rclass++) for (rclass = 0; rclass < RegClassMax; rclass++)
masks[(char)rclass] = 0xFFFFFFFF; masks[rclass] = 0xFFFFFFFF;
if (CParser_HasInternalLinkage(obj)) { if (CParser_HasInternalLinkage(obj)) {
for (scan = mod_regs_table[obj->name->hashval]; scan; scan = scan->next) { for (scan = mod_regs_table[obj->name->hashval & 127]; scan; scan = scan->next) {
if (scan->obj == obj) if (scan->obj == obj)
break; break;
} }
if (scan) { if (scan) {
for (rclass = 0; rclass < RegClassMax; rclass++) for (rclass = 0; rclass < RegClassMax; rclass++)
masks[(char)rclass] = scan->mask[(char)rclass]; masks[rclass] = scan->mask[rclass];
} }
} }
} }

View File

@ -4,6 +4,7 @@
#include "compiler/LoopDetection.h" #include "compiler/LoopDetection.h"
#include "compiler/PCode.h" #include "compiler/PCode.h"
#include "compiler/PCodeInfo.h" #include "compiler/PCodeInfo.h"
#include "compiler/Registers.h"
#include "compiler/UseDefChains.h" #include "compiler/UseDefChains.h"
int strengthreducedloops; int strengthreducedloops;

View File

@ -1,10 +1,11 @@
#include "compiler/UseDefChains.h" #include "compiler/UseDefChains.h"
#include "compiler/Alias.h" #include "compiler/Alias.h"
#include "compiler/PCode.h" #include "compiler/BitVectors.h"
#include "compiler/CompilerTools.h" #include "compiler/CompilerTools.h"
#include "compiler/PCode.h"
#include "compiler/Registers.h"
#include "compiler/objects.h" #include "compiler/objects.h"
#include "compiler/types.h" #include "compiler/types.h"
#include "compiler/BitVectors.h"
int number_of_Defs; int number_of_Defs;
UseOrDef *Defs; UseOrDef *Defs;

View File

@ -21,10 +21,10 @@ typedef struct LocalVectorArray {
} LocalVectorArray; } LocalVectorArray;
typedef struct VectorPropInfo { typedef struct VectorPropInfo {
UInt32 *vec0; UInt32 *use;
UInt32 *vec4; UInt32 *def;
UInt32 *vec8; UInt32 *in;
UInt32 *vecC; UInt32 *out;
} VectorPropInfo; } VectorPropInfo;
typedef struct ADDI { typedef struct ADDI {
@ -116,7 +116,7 @@ static void scaninstructions(LocalVectorArray *arrays) {
while (i--) { while (i--) {
if ( if (
op->kind == PCOp_MEMORY && op->kind == PCOp_MEMORY &&
op->arg == PCOpMemory1 && (PCOpMemoryArg) op->arg == PCOpMemory1 &&
(array = lookup_vector_array_object(arrays, op->data.mem.obj)) && (array = lookup_vector_array_object(arrays, op->data.mem.obj)) &&
!array->invalid !array->invalid
) )
@ -174,7 +174,7 @@ static void computeaddilist(LocalVectorArray *arrays) {
instr->op == PC_ADDI && instr->op == PC_ADDI &&
(reg = instr->args[0].data.reg.reg) >= n_real_registers[RegClass_GPR] && (reg = instr->args[0].data.reg.reg) >= n_real_registers[RegClass_GPR] &&
instr->args[2].kind == PCOp_MEMORY && instr->args[2].kind == PCOp_MEMORY &&
(unsigned char) instr->args[2].arg == 1 && (PCOpMemoryArg) instr->args[2].arg == PCOpMemory1 &&
(array = lookup_vector_array_object(arrays, instr->args[2].data.mem.obj)) && (array = lookup_vector_array_object(arrays, instr->args[2].data.mem.obj)) &&
!array->invalid !array->invalid
) )
@ -195,7 +195,7 @@ static void computeaddilist(LocalVectorArray *arrays) {
for (def = &Defs[defID = instr->defID]; defID < number_of_Defs && def->pcode == instr; def++, defID++) { for (def = &Defs[defID = instr->defID]; defID < number_of_Defs && def->pcode == instr; def++, defID++) {
if (def->v.kind == PCOp_REGISTER) { if (def->v.kind == PCOp_REGISTER) {
RegUseOrDef *l; RegUseOrDef *l;
for (l = reg_Uses[(char) def->v.arg][def->v.u.reg]; l; l = l->next) for (l = reg_Uses[def->v.arg][def->v.u.reg]; l; l = l->next)
bitvectorclearbit(l->id, vec); bitvectorclearbit(l->id, vec);
} }
} }
@ -216,10 +216,10 @@ static void allocatevectorpropinfo(void) {
vectorpropinfo = oalloc(sizeof(VectorPropInfo) * pcblockcount); vectorpropinfo = oalloc(sizeof(VectorPropInfo) * pcblockcount);
for (i = 0, info = vectorpropinfo; i < pcblockcount; i++, info++) { for (i = 0, info = vectorpropinfo; i < pcblockcount; i++, info++) {
info->vec0 = oalloc(4 * ((number_of_ADDIs + 31) >> 5)); info->use = oalloc(4 * ((number_of_ADDIs + 31) >> 5));
info->vec4 = oalloc(4 * ((number_of_ADDIs + 31) >> 5)); info->def = oalloc(4 * ((number_of_ADDIs + 31) >> 5));
info->vec8 = oalloc(4 * ((number_of_ADDIs + 31) >> 5)); info->in = oalloc(4 * ((number_of_ADDIs + 31) >> 5));
info->vecC = oalloc(4 * ((number_of_ADDIs + 31) >> 5)); info->out = oalloc(4 * ((number_of_ADDIs + 31) >> 5));
} }
} }
@ -238,8 +238,8 @@ static void computelocalvectorpropinfo(LocalVectorArray *arrays) {
for (block = pcbasicblocks; block; block = block->nextBlock) { for (block = pcbasicblocks; block; block = block->nextBlock) {
info = &vectorpropinfo[block->blockIndex]; info = &vectorpropinfo[block->blockIndex];
vec0 = info->vec0; vec0 = info->use;
vec4 = info->vec4; vec4 = info->def;
bitvectorinitialize(vec0, number_of_ADDIs, 0); bitvectorinitialize(vec0, number_of_ADDIs, 0);
bitvectorinitialize(vec4, number_of_ADDIs, 0); bitvectorinitialize(vec4, number_of_ADDIs, 0);
index = firstaddinblock[block->blockIndex]; index = firstaddinblock[block->blockIndex];
@ -253,7 +253,7 @@ static void computelocalvectorpropinfo(LocalVectorArray *arrays) {
for (addi_i = 0, addi = ADDIs; addi_i < number_of_ADDIs; addi_i++, addi++) { for (addi_i = 0, addi = ADDIs; addi_i < number_of_ADDIs; addi_i++, addi++) {
if ( if (
addi->instr && addi->instr &&
(char) addi->instr->args[0].arg == (char) op->arg && addi->instr->args[0].arg == op->arg &&
addi->instr->args[0].data.reg.reg == op->data.reg.reg addi->instr->args[0].data.reg.reg == op->data.reg.reg
) )
{ {
@ -270,7 +270,7 @@ static void computelocalvectorpropinfo(LocalVectorArray *arrays) {
if ( if (
instr->op == PC_ADDI && instr->op == PC_ADDI &&
instr->args[2].kind == PCOp_MEMORY && instr->args[2].kind == PCOp_MEMORY &&
instr->args[2].arg == PCOpMemory1 && (PCOpMemoryArg) instr->args[2].arg == PCOpMemory1 &&
(array = lookup_vector_array_object(arrays, instr->args[2].data.mem.obj)) && (array = lookup_vector_array_object(arrays, instr->args[2].data.mem.obj)) &&
!array->invalid !array->invalid
) )
@ -301,13 +301,13 @@ static void computeglobalvectorpropinfo(void) {
bitvecsize = (number_of_ADDIs + 31) >> 5; bitvecsize = (number_of_ADDIs + 31) >> 5;
flag = 1; flag = 1;
info = &vectorpropinfo[pcbasicblocks->blockIndex]; info = &vectorpropinfo[pcbasicblocks->blockIndex];
bitvectorinitialize(info->vec8, number_of_ADDIs, 0); bitvectorinitialize(info->in, number_of_ADDIs, 0);
bitvectorcopy(info->vecC, info->vec0, number_of_ADDIs); bitvectorcopy(info->out, info->use, number_of_ADDIs);
for (block = pcbasicblocks->nextBlock; block; block = block->nextBlock) { for (block = pcbasicblocks->nextBlock; block; block = block->nextBlock) {
info = &vectorpropinfo[block->blockIndex]; info = &vectorpropinfo[block->blockIndex];
vecC = info->vecC; vecC = info->out;
vec4 = info->vec4; vec4 = info->def;
for (i = 0; i < bitvecsize; vecC++, vec4++, i++) for (i = 0; i < bitvecsize; vecC++, vec4++, i++)
*vecC = ~*vec4; *vecC = ~*vec4;
} }
@ -318,16 +318,16 @@ static void computeglobalvectorpropinfo(void) {
if (depthfirstordering[blockIndex]) { if (depthfirstordering[blockIndex]) {
info = &vectorpropinfo[depthfirstordering[blockIndex]->blockIndex]; info = &vectorpropinfo[depthfirstordering[blockIndex]->blockIndex];
if ((preds = depthfirstordering[blockIndex]->predecessors)) { if ((preds = depthfirstordering[blockIndex]->predecessors)) {
vec8 = info->vec8; vec8 = info->in;
bitvectorcopy(vec8, vectorpropinfo[preds->block->blockIndex].vecC, number_of_ADDIs); bitvectorcopy(vec8, vectorpropinfo[preds->block->blockIndex].out, number_of_ADDIs);
for (preds = preds->nextLink; preds; preds = preds->nextLink) for (preds = preds->nextLink; preds; preds = preds->nextLink)
bitvectorintersect(vec8, vectorpropinfo[preds->block->blockIndex].vecC, number_of_ADDIs); bitvectorintersect(vec8, vectorpropinfo[preds->block->blockIndex].out, number_of_ADDIs);
} }
vecC = info->vecC; vecC = info->out;
vec8 = info->vec8; vec8 = info->in;
vec0 = info->vec0; vec0 = info->use;
vec4 = info->vec4; vec4 = info->def;
for (j = 0; j < bitvecsize; j++) { for (j = 0; j < bitvecsize; j++) {
val = *vec0 | (*vec8 & ~*vec4); val = *vec0 | (*vec8 & ~*vec4);
if (val != *vecC) { if (val != *vecC) {

View File

@ -2,10 +2,8 @@
#define COMPILER_COLORING_H #define COMPILER_COLORING_H
#include "compiler/common.h" #include "compiler/common.h"
#include "compiler/Registers.h"
//extern RegClass coloring_class; extern RegClass coloring_class;
extern char coloring_class;
extern void colorinstructions(Object *proc); extern void colorinstructions(Object *proc);

View File

@ -17,7 +17,7 @@ typedef struct IAMnemonic {
typedef struct IARegister { typedef struct IARegister {
char *name; char *name;
char rclass; RegClass rclass;
SInt32 num; SInt32 num;
Object *object; Object *object;
} IARegister; } IARegister;

View File

@ -5,7 +5,7 @@
#include "compiler/InlineAsm.h" #include "compiler/InlineAsm.h"
extern void InlineAsm_InitializeRegisters(void); extern void InlineAsm_InitializeRegisters(void);
extern void InlineAsm_InsertRegister(char *name, char rclass, short num, Object *object); extern void InlineAsm_InsertRegister(char *name, RegClass rclass, short num, Object *object);
extern IARegister *InlineAsm_LookupRegister(char *name); extern IARegister *InlineAsm_LookupRegister(char *name);
#endif #endif

View File

@ -4,15 +4,15 @@
#include "compiler/common.h" #include "compiler/common.h"
typedef struct LiveInfo { typedef struct LiveInfo {
UInt32 *vec0; // use UInt32 *use;
UInt32 *vec4; // def UInt32 *def;
UInt32 *vec8; // in UInt32 *in;
UInt32 *vecC; // out UInt32 *out;
} LiveInfo; } LiveInfo;
extern LiveInfo *liveinfo; extern LiveInfo *liveinfo;
extern void computelivevariables(Object *proc); extern void computelivevariables(Object *proc);
extern int dead(PCode *instr, char rclass, UInt32 *vec); extern int dead(PCode *instr, RegClass rclass, UInt32 *vec);
#endif #endif

View File

@ -51,7 +51,7 @@ typedef enum {
struct PCodeArg { struct PCodeArg {
PCOpKind kind; PCOpKind kind;
unsigned char arg; RegClass arg;
union { union {
struct { struct {
unsigned short effect; unsigned short effect;
@ -79,33 +79,33 @@ struct PCodeArg {
#define PC_OP_IS_REGISTER(_op, _rclass, _reg) \ #define PC_OP_IS_REGISTER(_op, _rclass, _reg) \
((_op)->kind == PCOp_REGISTER && \ ((_op)->kind == PCOp_REGISTER && \
(char) (_op)->arg == (_rclass) && \ (_op)->arg == (_rclass) && \
(_op)->data.reg.reg == (_reg)) (_op)->data.reg.reg == (_reg))
#define PC_OP_IS_READ_REGISTER(_op, _rclass, _reg) \ #define PC_OP_IS_READ_REGISTER(_op, _rclass, _reg) \
((_op)->kind == PCOp_REGISTER && \ ((_op)->kind == PCOp_REGISTER && \
(char) (_op)->arg == (_rclass) && \ (_op)->arg == (_rclass) && \
(_op)->data.reg.reg == (_reg) && \ (_op)->data.reg.reg == (_reg) && \
((_op)->data.reg.effect & EffectRead)) ((_op)->data.reg.effect & EffectRead))
#define PC_OP_IS_WRITE_REGISTER(_op, _rclass, _reg) \ #define PC_OP_IS_WRITE_REGISTER(_op, _rclass, _reg) \
((_op)->kind == PCOp_REGISTER && \ ((_op)->kind == PCOp_REGISTER && \
(char) (_op)->arg == (_rclass) && \ (_op)->arg == (_rclass) && \
(_op)->data.reg.reg == (_reg) && \ (_op)->data.reg.reg == (_reg) && \
((_op)->data.reg.effect & EffectWrite)) ((_op)->data.reg.effect & EffectWrite))
#define PC_OP_IS_ANY_REGISTER(_op, _rclass) \ #define PC_OP_IS_ANY_REGISTER(_op, _rclass) \
((_op)->kind == PCOp_REGISTER && \ ((_op)->kind == PCOp_REGISTER && \
(char) (_op)->arg == (_rclass)) (_op)->arg == (_rclass))
#define PC_OP_IS_READ_ANY_REGISTER(_op, _rclass) \ #define PC_OP_IS_READ_ANY_REGISTER(_op, _rclass) \
((_op)->kind == PCOp_REGISTER && \ ((_op)->kind == PCOp_REGISTER && \
(char) (_op)->arg == (_rclass) && \ (_op)->arg == (_rclass) && \
((_op)->data.reg.effect & EffectRead)) ((_op)->data.reg.effect & EffectRead))
#define PC_OP_IS_WRITE_ANY_REGISTER(_op, _rclass) \ #define PC_OP_IS_WRITE_ANY_REGISTER(_op, _rclass) \
((_op)->kind == PCOp_REGISTER && \ ((_op)->kind == PCOp_REGISTER && \
(char) (_op)->arg == (_rclass) && \ (_op)->arg == (_rclass) && \
((_op)->data.reg.effect & EffectWrite)) ((_op)->data.reg.effect & EffectWrite))

View File

@ -18,6 +18,7 @@ typedef enum {
} PCOpKind; } PCOpKind;
typedef enum { typedef enum {
PCOpMemory0 = 0,
PCOpMemory1 = 1 PCOpMemory1 = 1
} PCOpMemoryArg; } PCOpMemoryArg;

View File

@ -12,12 +12,12 @@ extern short _CALLER_SP_;
extern char *special_register_names[RegClassMax][RegisterMax]; extern char *special_register_names[RegClassMax][RegisterMax];
extern short spr_to_sysreg[4]; extern short spr_to_sysreg[4];
extern void asm_used_register(char rclass, short reg); extern void asm_used_register(RegClass rclass, short reg);
extern void retain_register(Object *obj, char rclass, short reg); extern void retain_register(Object *obj, RegClass rclass, short reg);
extern void retain_GPR_pair(Object *obj, short reg, short regHi); extern void retain_GPR_pair(Object *obj, short reg, short regHi);
extern int is_register_object(Object *obj); extern int is_register_object(Object *obj);
extern int GetABIFirstNonVolatile(char rclass); extern int GetABIFirstNonVolatile(RegClass rclass);
extern char GetRegisterClassName(char rclass); extern char GetRegisterClassName(RegClass rclass);
extern void setup_diagnostic_reg_strings(void); extern void setup_diagnostic_reg_strings(void);
extern void init_target_registers(void); extern void init_target_registers(void);
extern void assign_register_by_type(Object *obj); extern void assign_register_by_type(Object *obj);
@ -27,9 +27,9 @@ extern void set_last_exception_registers(void);
extern VarInfo *Registers_GetVarInfo(Object *obj); extern VarInfo *Registers_GetVarInfo(Object *obj);
extern int used_vrstate_VRs(void); extern int used_vrstate_VRs(void);
extern UInt32 colored_vrs_as_vrsave(PCodeBlock *block); extern UInt32 colored_vrs_as_vrsave(PCodeBlock *block);
extern void save_before_coloring_nonvolatile_registers(char rclass); extern void save_before_coloring_nonvolatile_registers(RegClass rclass);
extern void reset_nonvolatile_registers(char rclass); extern void reset_nonvolatile_registers(RegClass rclass);
extern int is_nonvolatile_register(char rclass, int reg); extern int is_nonvolatile_register(RegClass rclass, int reg);
extern void init_endian(void); extern void init_endian(void);
extern void update_asm_nonvolatile_registers(void); extern void update_asm_nonvolatile_registers(void);

View File

@ -8,25 +8,6 @@ enum {
Register2 = 2, Register2 = 2,
RegisterMax = 32 RegisterMax = 32
}; };
/*const char RegClass_SPR = 0;
const char RegClass_CRFIELD = 1;
const char RegClass_VR = 2;
const char RegClass_FPR = 3;
const char RegClass_GPR = 4;
const char RegClassMax = 5;
const char RegClass_6 = 6;
const char RegClass_DCR = 7;*/
typedef enum RegClass {
RegClass_Invalid = -1,
RegClass_SPR = 0,
RegClass_CRFIELD = 1,
RegClass_VR = 2,
RegClass_FPR = 3,
RegClass_GPR = 4,
RegClassMax = 5,
RegClass_6 = 6,
RegClass_DCR = 7
} RegClass;
enum { enum {
RegState0 = 0, RegState0 = 0,
@ -51,11 +32,11 @@ extern int coloring;
extern int optimizing; extern int optimizing;
extern void init_registers(void); extern void init_registers(void);
extern void assign_register_to_variable(Object *obj, char rclass); extern void assign_register_to_variable(Object *obj, RegClass rclass);
extern void retain_register_for_argument(Object *obj, char rclass, short reg); extern void retain_register_for_argument(Object *obj, RegClass rclass, short reg);
extern int available_registers(char rclass); extern int available_registers(RegClass rclass);
extern UInt32 volatile_registers(char rclass); extern UInt32 volatile_registers(RegClass rclass);
extern short obtain_nonvolatile_register(char rclass); extern short obtain_nonvolatile_register(RegClass rclass);
extern void open_temp_registers(void); extern void open_temp_registers(void);
extern void check_temp_registers(void); extern void check_temp_registers(void);
extern void close_temp_registers(void); extern void close_temp_registers(void);

View File

@ -2,7 +2,6 @@
#define COMPILER_USEDEFCHAINS_H #define COMPILER_USEDEFCHAINS_H
#include "compiler/common.h" #include "compiler/common.h"
#include "compiler/Registers.h"
#include "compiler/PCodeInfo.h" #include "compiler/PCodeInfo.h"
#ifdef __MWERKS__ #ifdef __MWERKS__
@ -10,7 +9,7 @@
#endif #endif
typedef struct TinyValue { typedef struct TinyValue {
PCOpKind kind; PCOpKind kind;
unsigned char arg; RegClass arg;
union { union {
short reg; short reg;
Object *object; Object *object;

View File

@ -10,8 +10,6 @@ typedef struct HashNameNode {
char name[1]; char name[1];
} HashNameNode; } HashNameNode;
typedef struct CPrepFileInfo CPrepFileInfo;
#ifdef __MWERKS__ #ifdef __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
#endif #endif
@ -118,6 +116,7 @@ typedef struct CI_FuncData CI_FuncData;
typedef struct CLabel CLabel; typedef struct CLabel CLabel;
typedef struct ClassList ClassList; typedef struct ClassList ClassList;
typedef struct CParams CParams; typedef struct CParams CParams;
typedef struct CPrepFileInfo CPrepFileInfo;
typedef struct DeclInfo DeclInfo; typedef struct DeclInfo DeclInfo;
typedef struct DeclThing DeclThing; // rename me please typedef struct DeclThing DeclThing; // rename me please
typedef struct DefArgCtorInfo DefArgCtorInfo; typedef struct DefArgCtorInfo DefArgCtorInfo;
@ -307,6 +306,18 @@ enum {
EXPORT_FLAGS_EXPORT = 0x40 EXPORT_FLAGS_EXPORT = 0x40
}; };
typedef enum RegClass {
RegClass_Invalid = -1,
RegClass_SPR = 0,
RegClass_CRFIELD = 1,
RegClass_VR = 2,
RegClass_FPR = 3,
RegClass_GPR = 4,
RegClassMax = 5,
RegClass_6 = 6,
RegClass_DCR = 7
} RegClass;
#ifdef __MWERKS__ #ifdef __MWERKS__
#pragma options align=mac68k #pragma options align=mac68k
#endif #endif

6
notes
View File

@ -105,7 +105,7 @@ DONE IroSubable.c
MOST RegisterInfo.c MOST RegisterInfo.c
MOST TOC.c MOST TOC.c
MOST StackFrame.c MOST StackFrame.c
MOST Registers.c DONE Registers.c
DONE PCode.c DONE PCode.c
95% Switch.c 95% Switch.c
DONE ValueNumbering.c DONE ValueNumbering.c
@ -118,7 +118,7 @@ MOST Operands.c
DONE PCodeListing.c DONE PCodeListing.c
---- Peephole.c ---- Peephole.c
DONE Scheduler.c DONE Scheduler.c
99% Coloring.c DONE Coloring.c
---- PCodeAssembly.c ---- PCodeAssembly.c
---- Intrinsics.c ---- Intrinsics.c
DONE PPCError.c DONE PPCError.c
@ -144,7 +144,7 @@ PART PCodeInfo.c
---- StructMoves.c ---- StructMoves.c
---- FunctionCalls.c ---- FunctionCalls.c
DONE IroBitVect.c DONE IroBitVect.c
MOST InlineAsmRegistersPPC.c 99% InlineAsmRegistersPPC.c
DONE InlineAsmMnemonicsPPC.c DONE InlineAsmMnemonicsPPC.c
DONE InlineAsmRegisters.c DONE InlineAsmRegisters.c
95% Alias.c 95% Alias.c