?? analysis.c
字號:
showline = 0;
}
forest = cp->u.forest;
relink(&sentinel, &sentinel);
for (p = forest; p; p = p->link)
linearize(p, &sentinel);
forest = sentinel.x.next;
assert(forest);
sentinel.x.next->x.prev = NULL;
sentinel.x.prev->x.next = NULL;
if (last == NULL)
root = forest;
for (p=forest;p;p=p->x.next) {
if (cp->kind == Jump && last && p->x.next == NULL) {
int op = generic(last->op);
if (op == EQ || op == LE || op == NE ||
op == LT || op == GE || op == GT) {
// printf("--- %s --- ",p->kids[0]->syms[0]->name);
// printf("%s\n",last->syms[0]->name);
jInfo.conditional = last;
jInfo.cpJump = cp;
jInfo.Jump = p;
watchout = last;
}
}
else if (cp->kind == Label && watchout) {
int op;
if (p->syms[0]->u.l.label == watchout->syms[0]->u.l.label) {
// printf("foundit: %d: jump=%d\n",p->syms[0]->u.l.label,
// last->kids[0]->syms[0]->u.l.label);
assert(jInfo.cpJump);
assert(jInfo.cpJump->prev);
assert(JumpNodeTable[JumpNodeIndex-1] == jInfo.Jump);
assert(JumpNodeTable[JumpNodeIndex-2] == jInfo.conditional);
assert(jInfo.cpJump->u.forest->x.next == NULL);
/* change the sense of the jcc */
switch (jInfo.conditional->op) {
case EQI:
op = NEI;
break;
case LEI:
op = GTI;
break;
case LEU:
op = GTU;
break;
case NEI:
op = EQI;
break;
case LTI:
op = GEI;
break;
case LTU:
op = GEU;
break;
case GEI:
op = LTI;
break;
case GEU:
op = LTU;
break;
case GTI:
op = LEI;
break;
case GTU:
op = LEU;
break;
default:
goto bailout;
}
jInfo.conditional->op = op;
jInfo.conditional->syms[0] = jInfo.Jump->kids[0]->syms[0];
/* erase the jump */
jInfo.cpJump->prev->next = jInfo.cpJump->next;
jInfo.cpJump->next->prev = jInfo.cpJump->prev;
/* fixup the jump table */
JumpNodeTable[--JumpNodeIndex] = NULL;
JumpNodeTable[--JumpNodeIndex] = NULL;
JumpNodeTable[JumpNodeIndex++] = jInfo.conditional;
succIdx -= 2; // erase the jump from the successors table
successorsTable[succIdx] = successorsTable[succIdx+1];
succIdx++;
successorsTable[succIdx] = 0;
endswithjump = 0;
}
bailout:
memset(&jInfo,0,sizeof(jmpInfo));
watchout = NULL;
}
else watchout = NULL;
maxdepth = 0;
hasDangerousOp = 0;
// dumptree(p,0);
// printf("\n");
FindSymbols(p,1);
if (hasDangerousOp) {
SaturateUnsafe(p);
unsafe = 1;
}
p->x.unsafe = unsafe;
Printf2("\n",0);
last = p;
}
break;
case Switch:
l = cp->u.swtch.size;
if (l + succIdx >= MAXSUCCESORS) {
printf(StrTab[422]);// <Overflow in switch\n>
l = MAXSUCCESORS - l;
}
Printf2("switch size %d \n",cp->u.swtch.size);
for (i=0; i<l;i++) {
cp->u.swtch.labels[i]->ref += 1.0;
n = equated(cp->u.swtch.labels[i]);
successorsTable[succIdx] = n->u.l.label;
succIdx++;
}
break;
}
previous = cp;
}
FinishBlock();
return result;
}
//enum { EAX=0, ECX=1, EDX=2, EBX=3, ESI=6, EDI=7 };
extern Symbol intreg[];
void AnalyzeSecondPass(void)
{
int i,k,l,ialias,op,lastpoint,z,swapRegs;
Code cp;
Node p,last;
Symbol lab,oldreg[2],newreg[2],lastLabel;
i = 0;
while (i < aliasIndex) {
ialias = AliasTable[i].alias;
lastpoint = i;
p = AliasTable[i].plabel;
if (p->x.next || p->x.prev) {
printf("inner label\n");
}
i++;
while (ialias == AliasTable[i].label) {
ialias = AliasTable[i].alias;
i++;
}
lab = findlabel(ialias);
for (k=0; k<JumpNodeIndex;k++) {
p = JumpNodeTable[k];
if (p == NULL)
continue;
op = generic(p->op);
if (op == JUMP)
l = p->kids[0]->syms[0]->u.l.label;
else
l = p->syms[0]->u.l.label;
if (l == 0)
printf(StrTab[423]);// <l == 0?????\n>
for (z=lastpoint; z<i;z++) {
if (l == AliasTable[z].label) {
if (op == JUMP) {
p->kids[0]->syms[0]->u.l.equatedto = lab;
p->kids[0]->syms[0] = lab;
}
else {
p->syms[0]->u.l.equatedto = lab;
p->syms[0] = lab;
}
JumpNodeTable[k] = NULL;
break;
}
}
}
}
for (i=0; i<JumpNodeIndex;i++) {
if (JumpNodeTable[i]) {
char *n;
p = JumpNodeTable[i];
op = generic(p->op);
if (op == JUMP) {
l = p->kids[0]->syms[0]->u.l.label;
n = p->kids[0]->syms[0]->name;
}
else {
l = p->syms[0]->u.l.label;
n = p->syms[0]->name;
}
if (l == 0) {
printf(StrTab[424],n);// <Label _$%s not changed!!!!\n>
}
}
}
swapRegs = 0;
if (OptimizeFlag && FunctionInfo.leafFunction
&& FunctionInfo.hasBlockMove == 0) {
if ((usedmask[0] & (1 << 1)) == 0 &&
(usedmask[0] & (1 << 7))) {
/* swap edi with ecx */
oldreg[0] = intreg[7];
newreg[0] = intreg[1];
swapRegs = 1;
usedmask[0] |= (1 << 1);
usedmask[0] &= ~(1 << 7);
if (IntermediateLanguageFile) {
fprintf(ilFile,"; interchanging edi with ecx\n");
}
}
else
if ((usedmask[0] & (1 << 1)) == 0 &&
(usedmask[0] & (1 << 6))) {
/* swap esi with ecx */
oldreg[swapRegs] = intreg[6];
newreg[swapRegs] = intreg[1];
swapRegs++;
usedmask[0] |= (1 << 1);
usedmask[0] &= ~(1 << 6);
if (IntermediateLanguageFile) {
fprintf(ilFile,"; interchanging esi with ecx\n");
}
}
else
if ((usedmask[0] & (1 << 1)) == 0 &&
(usedmask[0] & (1 << 3))) {
/* swap ebx with ecx */
oldreg[swapRegs] = intreg[3];
newreg[swapRegs] = intreg[1];
swapRegs++;
usedmask[0] |= (1 << 1);
usedmask[0] &= ~(1 << 3);
if (IntermediateLanguageFile) {
fprintf(ilFile,"; interchanging ebx with ecx\n");
}
}
}
FunctionInfo.SwappedRegs = swapRegs ? 1 : 0;
/*
Redo the list of nodes to erase the unnecessary labels
*/
lastLabel = NULL;
for (cp = codehead.next; cp; cp = cp->next) {
// This time follow only Jump/Gen/Label Code nodes
switch (cp->kind) {
case Jump:
case Gen:
case Label:
// Follow all the nodes of this forest
last = NULL;
for (p=cp->u.forest;p;p=p->x.next) {
if (generic(p->op) == LABEL) { // If it is a LABEL node
// If it has been erased by the loops above
lab = p->syms[0];
if (lab->u.l.equatedto || lab->u.l.label == 0) {
Printf2("Erasing label %s\n",p->syms[0]->name);
//If is a middle node unlink it
#if 1
if (last) {
last->x.next = p->x.next;
if (p->x.next)
p->x.next->x.prev = last;
}
else {
// This is the first node in the forest
if (p->x.next) // If there are more nodes
cp->u.forest = p->x.next; // unlink
else {
// No more nodes. Delete the forest
cp->prev->next = cp->next;
cp->next->prev = cp->prev;
}
}
#endif
}
else {
lastLabel = lab;
}
}
if (swapRegs)
for (i=0; i<swapRegs;i++)
ReplaceReg(p,oldreg[i],newreg[i]);
// Keep the pointer to the last node
last = p;
}
break;
#ifdef DOPRINTF
case Blockbeg:{
Symbol *p = cp->u.block.locals;
if (*p == NULL) break;
Printf2("Scope %d:\n",cp->u.block.x.offset);
for (; *p; p++) {
Printf2("%s",(*p)->name);
if (p[1]) Printf2(",",0);
}
Printf2("\n",0);
}
break;
#endif
}
}
if (lastLabel) {
cfunc->u.f.label = lastLabel->u.l.label;
}
#ifdef DOPRINTF
rvpB = RootBlock;
printf("\nControl flow analysis\n");
while (rvpB) {
printf("Block %d line %d:",rvpB->Label,rvpB->src.y);
if (rvpB->hasCalls) printf("Has calls ");
else printf("no calls ");
if (rvpB->NrOfSuccessors) {
printf(" %d successors: ",rvpB->NrOfSuccessors);
for (i=0; i<rvpB->NrOfSuccessors;i++) {
printf(" %d ",rvpB->Successors[i]);
}
}
if (rvpB->EndsWithJump)
printf(" end: JUMP");
printf("\n");
if (rvpB->NrOfPredecessors) {
printf("Predecessors %d:",rvpB->NrOfPredecessors);
for (i=0; i<rvpB->NrOfPredecessors;i++) {
printf(" %d",rvpB->Predecessors[i]);
}
printf("\n");
}
else if (rvpB->Label && rvpB->Next) {
// printf("Block %d has no predecessors?\n",rvpB->Label);
}
asl = rvpB->DefUse;
while (asl) {
if (asl->lhs) {
printf(" %s =",asl->lhs->sym->name);
}
else
printf("Uses: ");
rhs = asl->rhs;
while (rhs) {
if (rhs->sym->scope == CONSTANTS)
printf("constant ");
printf(" %s",rhs->sym->name);
rhs = rhs->Next;
}
Printf2("\n",0);
asl = asl->Next;
}
if (rvpB->DefUse)
printf("\n");
rvpB = rvpB->Next;
}
if (aliasIndex) {
printf("Label alias table\n");
for (i=0; i<aliasIndex;i++) {
printf("%d --> %d\n",AliasTable[i].label,AliasTable[i].alias);
}
}
#endif
lastBlock = RootBlock = NULL;
}
int HasSwappedRegs(void)
{
return FunctionInfo.SwappedRegs ? 1 : 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -