Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.3
 
1.4
 
MAIN:pj:20050115153553
 
optim2.c
_>3030 #include "external.h"
 3131 
 3232 #include <string.h>
<> 33+#include <stdlib.h>
  34+#include <machine/limits.h>
3335 
<> 36+#ifndef MIN
  37+#define MIN(a,b) (((a)<(b))?(a):(b))
  38+#endif
  39+
  40+#ifndef MAX
  41+#define MAX(a,b) (((a) > (b)) ? (a) : (b))
  42+#endif
  43+
3444 extern int saving;
 3545 
 3646 void saveip(struct interpass *ip);
     
 !
4757         int use;
 4858 } *rsv;
 4959 
<> 60+struct basicblock {
  61+        CIRCLEQ_ENTRY(basicblock) bbelem;
  62+        SIMPLEQ_HEAD(, cfgnode) children;
  63+        SIMPLEQ_HEAD(, cfgnode) parents;
  64+        struct interpass *first; /* first element of basic block */
  65+        struct interpass *last/* last element of basic block */
  66+};
  67+
  68+struct labelinfo {
  69+        struct basicblock **arr;
  70+        unsigned int size;
  71+        unsigned int low;
  72+};
  73+
  74+struct cfgnode {
  75+        SIMPLEQ_ENTRY(cfgnode) cfgelem;
  76+        struct basicblock *bblock;
  77+};
  78+
  79+int bblocks_build(struct labelinfo *labinfo);
  80+void cfg_build(struct labelinfo *labinfo);
  81+
  82+
  83+static CIRCLEQ_HEAD(, basicblock) bblocks = CIRCLEQ_HEAD_INITIALIZER(bblocks);
  84+
5085 static void
 5186 addcand(TWORD type, int off, int avoid)
 5287 {
     
 !
193228  * - address is taken of the temporary
 194229  * - variable is declared "volatile".
 195230  */
<>196 -static int
  231+int asgregs(void);
  232+int
197233 asgregs(void)
 198234 {
 199235         struct interpass *ip;
     
 !
239275 saveip(struct interpass *ip)
 240276 {
 241277         struct interpass *prol;
<> 278+#if 0
242279         int regs;
<> 280+#endif
  281+        struct labelinfo labinfo;
243282 
 244283         SIMPLEQ_INSERT_TAIL(&ipole, ip, sqelem);
 245284 
 246285         if (ip->type != IP_EPILOG)
 247286                 return;
 248287         saving = -1;
 249288 
<>250 -        deljumps();     /* Delete redundant jumps and dead code */
  289+        //              deljumps();     /* Delete redundant jumps and dead code */
  290+        if (xssaflag) {
  291+                CIRCLEQ_INIT(&bblocks);
  292+                if (bblocks_build(&labinfo)) {
  293+                        cfg_build(&labinfo);
  294+#if 0
  295+                        dfg = dfg_build(cfg);
  296+                        ssa = ssa_build(cfg, dfg);
  297+#endif
  298+                }
  299+ 
  300+        }
  301+#if 0
251302         regs = asgregs();       /* Assign non-temporary registers */
<> 303+#endif
252304 
 253305 #ifdef PCC_DEBUG
 254306         if (ip->ip_regs != MAXRVAR)
     
 !
257309 
 258310         prol = SIMPLEQ_FIRST(&ipole);
 259311         prol->ip_auto = ip->ip_auto;
<>260 -        prol->ip_regs = ip->ip_regs = regs;
  312+        prol->ip_regs = ip->ip_regs; // = regs;
261313 
 262314 #ifdef MYOPTIM
 263315         myoptim(prol);
     
 !
324376                 break;
 325377         }
 326378 }
<_ 379+
  380+/*
  381+ * Build the basic blocks, algorithm 9.1, pp 529 in Compilers.
  382+ *
  383+ * Also fills the labelinfo struct with information about which bblocks
  384+ * that contain which label.
  385+ */
  386+
  387+int
  388+bblocks_build(struct labelinfo *labinfo)
  389+{
  390+        struct interpass *ip;
  391+        struct basicblock *bb = NULL;
  392+        int leader = 1;
  393+        unsigned int low = UINT_MAX, high = 0;
  394+        int XXXcount = 0;
  395+        int i;
  396+
  397+        /*
  398+         * First statement is a leader.
  399+         * Any statement that is target of a jump is a leader.
  400+         * Any statement that immediately follows a jump is a leader.
  401+         */
  402+
  403+        SIMPLEQ_FOREACH(ip, &ipole, sqelem) {
  404+                /* Garbage, skip it */
  405+                if ((ip->type == IP_LOCCTR) || (ip->type == IP_NEWBLK))
  406+                        continue;
  407+
  408+                if (leader) {
  409+                        bb = tmpalloc(sizeof(struct basicblock));
  410+                        bb->first = bb->last = ip;
  411+                        SIMPLEQ_INIT(&bb->children);
  412+                        SIMPLEQ_INIT(&bb->parents);
  413+                        CIRCLEQ_INSERT_TAIL(&bblocks, bb, bbelem);
  414+                        leader = 0;
  415+                        XXXcount++;
  416+                }
  417+                
  418+                /* Prologue and epilogue in their own bblock */
  419+                if ((ip->type == IP_PROLOG) || (ip->type == IP_EPILOG)) {
  420+                        bb->last = ip;
  421+                        if (ip->type == IP_EPILOG)
  422+                                high = MAX(ip->ip_retl, high);
  423+                        leader = 1;
  424+                        continue;
  425+                }
  426+                
  427+                /* Keep track of highest and lowest label number */
  428+                if (ip->type == IP_DEFLAB) {
  429+                        low = MIN(ip->ip_lbl, low);
  430+                        high = MAX(ip->ip_lbl, high);
  431+                }
  432+
  433+                /* Make sure each label is in a unique bblock */
  434+                if (((ip->type == IP_DEFLAB) || (ip->type == IP_DEFNAM)) &&
  435+                    bb->first != ip) {
  436+                        bb = tmpalloc(sizeof(struct basicblock));
  437+                        bb->first = bb->last = ip;
  438+                        SIMPLEQ_INIT(&bb->children);
  439+                        SIMPLEQ_INIT(&bb->parents);
  440+                        CIRCLEQ_INSERT_TAIL(&bblocks, bb, bbelem);
  441+                        XXXcount++;
  442+                        continue;
  443+                }
  444+
  445+                if (ip->type == IP_ASM)
  446+                        return 0;
  447+
  448+                if (ip->type == IP_NODE) {
  449+                        switch(ip->ip_node->n_op) {
  450+                        case CBRANCH:
  451+                        case CALL:
  452+                        case UCALL:
  453+                        case FORTCALL:
  454+                        case UFORTCALL:
  455+                        case STCALL:
  456+                        case USTCALL:
  457+                        case GOTO:
  458+                        case RETURN:
  459+                                /* Jumps, last in bblock. */
  460+                                leader = 1;
  461+                                break;
  462+
  463+                        case NAME:
  464+                        case ICON:
  465+                        case FCON:
  466+                        case REG:
  467+                        case OREG:
  468+                        case MOVE:
  469+                        case PLUS:
  470+                        case MINUS:
  471+                        case DIV:
  472+                        case MOD:
  473+                        case MUL:
  474+                        case AND:
  475+                        case OR:
  476+                        case ER:
  477+                        case LS:
  478+                        case COMPL:
  479+                        case INCR:
  480+                        case DECR:
  481+                        case UMUL:
  482+                        case UMINUS:
  483+                        case EQ:
  484+                        case NE:
  485+                        case LE:
  486+                        case GE:
  487+                        case GT:
  488+                        case ULE:
  489+                        case ULT:
  490+                        case UGE:
  491+                        case UGT:
  492+                        case ASSIGN:
  493+                        case FORCE:
  494+                        case FUNARG:
  495+                                /* Not jumps, continue with bblock. */
  496+                                break;
  497+
  498+                        default:
  499+                                comperr("optim2:bblocks_build() %d",ip->ip_node->n_op );
  500+                                break;
  501+                        }
  502+                }
  503+
  504+                bb->last = ip;
  505+        }
  506+#ifdef PCC_DEBUG
  507+        printf("Basic blocks in func: %d\n", XXXcount);
  508+        printf("Label range in func: %d\n %d", high - low + 1, low);
  509+#endif
  510+
  511+        labinfo->low = low;
  512+        labinfo->size = high - low + 1;
  513+        labinfo->arr = tmpalloc(labinfo->size * sizeof(struct basicblock *));
  514+        for(i = 0; i <= labinfo->size; i++) {
  515+                labinfo->arr[i] = NULL;
  516+        }
  517+
  518+        /* Build the label table */
  519+        CIRCLEQ_FOREACH(bb, &bblocks, bbelem) {
  520+                if (bb->first->type == IP_DEFLAB) {
  521+                        labinfo->arr[bb->first->ip_lbl - low] = bb;
  522+                }
  523+                if (bb->first->type == IP_EPILOG) {
  524+                        labinfo->arr[bb->first->ip_retl - low] = bb;
  525+                }
  526+        }
  527+
  528+        return 1;
  529+}
  530+
  531+/*
  532+ * Build the control flow graph.
  533+ */
  534+
  535+void
  536+cfg_build(struct labelinfo *labinfo)
  537+{
  538+        /* Child and parent nodes */
  539+        struct cfgnode *cnode;
  540+        struct cfgnode *pnode;
  541+        struct basicblock *bb;
  542+        
  543+        CIRCLEQ_FOREACH(bb, &bblocks, bbelem) {
  544+
  545+                if (bb->first->type == IP_EPILOG) {
  546+                        break;
  547+                }
  548+
  549+                cnode = tmpalloc(sizeof(struct cfgnode));
  550+                pnode = tmpalloc(sizeof(struct cfgnode));
  551+                pnode->bblock = bb;
  552+
  553+                if ((bb->last->type == IP_NODE) &&
  554+                    (bb->last->ip_node->n_op == GOTO)) {
  555+                        if (bb->last->ip_node->n_left->n_lval - labinfo->low >
  556+                            labinfo->size) {
  557+                                comperr("Label out of range: %d, base %d",
  558+                                        bb->last->ip_node->n_left->n_lval,
  559+                                        labinfo->low);
  560+                        }
  561+                        cnode->bblock = labinfo->arr[bb->last->ip_node->n_left->n_lval - labinfo->low];
  562+                        SIMPLEQ_INSERT_TAIL(&cnode->bblock->parents, pnode, cfgelem);
  563+                        SIMPLEQ_INSERT_TAIL(&bb->children, cnode, cfgelem);
  564+                        continue;
  565+                }
  566+                if ((bb->last->type == IP_NODE) &&
  567+                    (bb->last->ip_node->n_op == CBRANCH)) {
  568+                        if (bb->last->ip_node->n_right->n_lval - labinfo->low >
  569+                            labinfo->size)
  570+                                comperr("Label out of range: %d",
  571+                                        bb->last->ip_node->n_left->n_lval);
  572+                        
  573+                        cnode->bblock = labinfo->arr[bb->last->ip_node->n_right->n_lval - labinfo->low];
  574+                        SIMPLEQ_INSERT_TAIL(&cnode->bblock->parents, pnode, cfgelem);
  575+                        SIMPLEQ_INSERT_TAIL(&bb->children, cnode, cfgelem);
  576+                        cnode = tmpalloc(sizeof(struct cfgnode));
  577+                        pnode = tmpalloc(sizeof(struct cfgnode));
  578+                        pnode->bblock = bb;
  579+                }
  580+
  581+                cnode->bblock = CIRCLEQ_NEXT(bb, bbelem);
  582+                SIMPLEQ_INSERT_TAIL(&cnode->bblock->parents, pnode, cfgelem);
  583+                SIMPLEQ_INSERT_TAIL(&bb->children, cnode, cfgelem);
  584+        }
  585+}
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-30 17:57 +0200