📄 ireach.c
字号:
if (head->dc.left)
{
k = findPointer(head->dc.left);
if (k < pointer_count)
{
for (j = 1; j < source_count; j++)
if (isset(temparray4 + k * sourcebytes, j))
{
enter_definition(sourcearray[j], head);
}
}
}
if (head->dc.right)
{
k = findPointer(head->dc.right);
if (k < pointer_count)
{
for (j = 1; j < source_count; j++)
if (isset(temparray4 + k * sourcebytes, j))
{
enter_definition(sourcearray[j], head);
}
}
}
break;
case i_gosub:
l->callcount++;
break;
break;
}
ptrindex(head, l, temparray4);
head = head->fwd;
}
}
}
//-------------------------------------------------------------------------
void CreateBitArrays(void)
{
int i;
definition_bytes = (definition_count + 8) / 8;
if (definition_bytes % 4)
definition_bytes += 4-definition_bytes % 4;
for (i = 0; i < blocknum; i++)
{
blockarray[i]->block->p_gen = oalloc(definition_bytes);
blockarray[i]->block->p_kill = oalloc(definition_bytes);
blockarray[i]->block->p_in = oalloc(definition_bytes);
blockarray[i]->block->p_out = oalloc(definition_bytes);
}
temparray1 = oalloc(definition_bytes);
temparray2 = oalloc(definition_bytes);
}
//-------------------------------------------------------------------------
void CalculateBlockBasics(void)
{
int i, j, k, left, right, ans;
int ptr, ptr2, gencount, pgen, pagen, def2;
int left1, right1, ans1;
LIST *l1;
for (i = 0; i < blocknum; i++)
{
BLOCK *l = blockarray[i]->block;
QUAD *list = l->head;
memcpy(temparray4, l->p_pin, sourcebytes *pointer_count);
while (list && list->back != l->tail)
{
ptr = INT_MAX;
gencount = 0;
pgen = - 1;
switch (list->dc.opcode)
{
case i_add:
case i_sub:
case i_udiv:
case i_umod:
case i_sdiv:
case i_smod:
case i_umul:
case i_smul:
case i_lsl:
case i_lsr:
case i_asl:
case i_asr:
case i_neg:
case i_not:
case i_and:
case i_or:
case i_eor:
case i_setne:
case i_sete:
case i_setc:
case i_seta:
case i_setnc:
case i_setbe:
case i_setl:
case i_setg:
case i_setle:
case i_setge:
case i_assn:
// start reaching defs
memset(temparray1, 0, definition_bytes);
memset(temparray2, 0, definition_bytes);
setbit(temparray1, list->definition); // gen
// gen bits
l1 = findans(defhash2, list->ans);
if (!l1)
DIAG("CalculateBlockBasics - can't find defintion");
else
{
while (l1)
{
int d = ((QUAD*)(l1->data))->definition;
if (list->definition != d)
setbit(temparray2, d);
l1 = l1->link;
}
}
if (list->ans->mode == i_ind)
{
BYTE *t4;
ptr = findPointer(list->ans);
if (ptr < pointer_count)
{
t4 = temparray4 + ptr * sourcebytes;
if (isset(t4, 0))
{
memset(temparray1, 0xff, definition_bytes);
}
else
{
for (j = 1; j < source_count; j++)
{
if (isset(t4, j))
{
def2 = FindDefinition(j, list);
if (def2 == - 1)
DIAG(
"CalculateBlockBasics - can't find def");
else
{
// gen and kill in presence of pointers
setbit(temparray1, def2);
clearbit(temparray2, def2);
}
}
}
}
}
}
// finish reaching defs
for (j = 0; j < definition_bytes; j += 4)
{
*(unsigned*)(l->p_gen + j) &= ~*(unsigned*)(temparray2
+ j);
*(unsigned*)(l->p_gen + j) |= *(unsigned*)(temparray1 +
j);
*(unsigned*)(l->p_kill + j) &= ~*(unsigned*)(temparray1
+ j);
*(unsigned*)(l->p_kill + j) |= *(unsigned*)(temparray2
+ j);
}
// FALLTHROUGH
case i_coswitch:
case i_jc:
case i_ja:
case i_je:
case i_jnc:
case i_jbe:
case i_jne:
case i_jl:
case i_jg:
case i_jle:
case i_jge:
case i_parm:
if (list->dc.opcode == i_parm)
{
SYM *sp = varsp(list->dc.left);
memset(temparray1, 0, definition_bytes);
memset(temparray2, 0, definition_bytes);
if (sp && list->dc.left->mode == i_immed)
{
l1 = findans(defhash2, sp->imvalue);
if (!l1)
DIAG(
"CalculateBlockBasics - can't find defintion");
else
{
while (l1)
{
int d = ((QUAD*)(l1->data))->definition;
if (list->definition != d)
setbit(temparray2, d);
l1 = l1->link;
}
}
}
else if (sp && list->dc.left->mode == i_direct)
{
ptr = findPointer(list->dc.left);
if (ptr < pointer_count)
{
BYTE *t4 = temparray4 + ptr * sourcebytes;
if (isset(t4, 0))
{
memset(temparray1, 0xff, definition_bytes);
}
else
{
for (j = 1; j < source_count; j++)
{
if (isset(t4, j))
{
def2 = FindDefinition(j, list);
if (def2 == - 1)
DIAG(
"CalculateBlockBasics - can't find def");
else
{
// gen and kill in presence of pointers
setbit(temparray1, def2);
clearbit(temparray2, def2);
}
}
}
}
}
}
for (j = 0; j < definition_bytes; j += 4)
{
*(unsigned*)(l->p_gen + j) &= ~*(unsigned*)
(temparray2 + j);
*(unsigned*)(l->p_gen + j) |= *(unsigned*)
(temparray1 + j);
*(unsigned*)(l->p_kill + j) &= ~*(unsigned*)
(temparray1 + j);
*(unsigned*)(l->p_kill + j) |= *(unsigned*)
(temparray2 + j);
}
}
break;
case i_gosub:
// kill globals
for (j = 0; j < definition_count; j++)
{
IMODE *s = defiarray[j]->ans;
switch (s->offset->nodetype)
{
case en_nacon:
case en_napccon:
case en_nalabcon:
case en_labcon:
case en_absacon:
if (s->mode == i_direct)
{
clearbit(l->p_gen, j);
setbit(l->p_kill, j);
}
else if (s->mode == i_ind)
{
BYTE *t4;
ptr = findPointer(list->ans);
if (ptr < pointer_count)
{
t4 = temparray4 + ptr * sourcebytes;
if (isset(t4, 0))
{
memset(temparray1, 0xff,
definition_bytes);
}
else
{
for (k = 1; k < source_count; k++)
{
if (isset(t4, k))
{
clearbit(l->p_gen, k);
setbit(l->p_kill, k);
}
}
}
}
}
}
}
}
ptrindex(list, l, temparray4);
list = list->fwd;
}
}
}
//-------------------------------------------------------------------------
void CalculateReaching(void)
{
int i, changed, j;
for (i = 0; i < blocknum; i++)
memcpy(blockarray[i]->block->p_out, blockarray[i]->block->p_gen,
definition_bytes);
do
{
changed = FALSE;
for (i = 0; i < blocknum; i++)
{
BLOCK *t = blockarray[dfst[i]]->block;
BLOCKLIST *l = t->flowback;
memset(t->p_in, 0, definition_bytes);
while (l)
{
for (j = 0; j < definition_bytes; j++)t->p_in[j] |= l->block
->p_out[j];
l = l->link;
}
for (j = 0; j < definition_bytes; j++)
{
int v = t->p_out[j];
t->p_out[j] = t->p_gen[j] | (t->p_in[j] &~t->p_kill[j]);
changed |= (v != t->p_out[j]);
}
}
}
while (changed)
;
}
//-------------------------------------------------------------------------
void CalculateEquations(QUAD *head)
{
return ;
defhash = oalloc(sizeof(LIST2*) * DHASH);
defhash2 = oalloc(sizeof(LIST3*) * DHASH);
CountDefinitions();
CreateBitArrays();
CalculateBlockBasics();
CalculateReaching();
#ifdef DUMP_GCSE_INFO
dumpeqn();
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -