Exemple #1
0
void liveVariables(void)
{
    int i;
    sFree();
    hasPhi = FALSE;
    globalVars = briggsAllocs(tempCount);
    worklist = briggsAllocs(blockCount);
    livelist = briggsAllocs(blockCount);
    visited = briggsAllocs(blockCount);
    for (i=0; i < blockCount; i++)
    {
        if (blockArray[i])
        {
            blockArray[i]->liveGen = sallocbit(tempCount);
            blockArray[i]->liveKills = sallocbit(tempCount);
            blockArray[i]-> liveIn = sallocbit(tempCount); 
            blockArray[i]->liveOut = sallocbit(tempCount);
        }
    }
    for (i=0; i <tempCount; i++)
    {
        tempInfo[i]->liveAcrossBlock = FALSE;
    }
    liveSetup();
    if (hasPhi)
        killPhiPaths1();
    liveOut();
    if (hasPhi)
        killPhiPaths2();
}
Exemple #2
0
int stack_free(bstack_t *stack)
{
	int i;

	for (i=0;i<stack->size;i++)
	{
		sFree(stack->elements[i]);	//first free any occupied stack elements
		free(stack->elements[i]);
	}
	free(stack->elements);			//then free the stack

	return 0;
}
Exemple #3
0
int pop(str_t *str, bstack_t *stack)
{
	//take an element off the stack.  return 0 if there are no elements
	//pass in a pointer to a string.  if necessary, this routine will 
	//reallocate space for the string to accomodate its size.  If this happens
	//the pointer to the string's (likely) new location is automatically
	//updated and returned.
	int i;

	//copy out the string at the top of the stack
	//then free the stack's copy.
	if (stack->num != 0)
	{
		stack->num--;
		if (stack->type == QUEUE)
		{
			//for queues, the top element is always node 0
			sCopy(str,stack->elements[0]);
			sFree(stack->elements[0]);
			free(stack->elements[0]);
			stack->top--;
			//now we need to adjust all the pointers down 1
			for (i=1;i<stack->num;i++)
				stack->elements[i-1] = stack->elements[i];
		}
		else
		{
			sCopy(str,stack->elements[stack->top]);
			//sFree(stack->elements[stack->top]);
			//free(stack->elements[stack->top]);
			stack->top--;
		}
		return 1;
	}
	else
		return 0;
}
Exemple #4
0
void optimize(SYMBOL *funcsp)
{
    //printf("optimization start\n");
    if (chosenAssembler->gen->pre_gcse)
        chosenAssembler->gen->pre_gcse(intermed_head);
    #ifdef DUMP_GCSE_INFO
        if (icdFile && funcsp)
            fprintf(icdFile, 
                "\n*************************FUNCTION %s********************************\n", funcsp->name);
    #endif 

    /*
     * icode optimizations goes here.  Note that LCSE is done through
     * DAG construction during the actual construction of the blocks
     * so it is already done at this point.
     *
     * Order IS important!!!!!!!!! be careful!!!!!
     *
     * note that some of these optimizations make changes to the code,
     * with the exception of the actual global optimization pass we are
     * never really deleting dead code at the time we make changes
     * becase we aren't 100% certain what will really be dead
     * we do separate dead-code passes occasionally to clean it up
     */
    /* Global opts */
    
    flows_and_doms();
    gatherLocalInfo(funcsp);
    if (cparams.prm_optimize && !functionHasAssembly)
    {
        Precolor();
        RearrangePrecolors();
    //printf("ssa\n");
        TranslateToSSA();
    //printf("const\n");
        if (optflags & OPT_CONSTANT)
        {
            ConstantFlow(); /* propagate constants */
            RemoveInfiniteThunks();
//			RemoveCriticalThunks();
            doms_only(FALSE);
        }
//		if (optflags & OPT_RESHAPE)
//			Reshape();		/* loop expression reshaping */
    //printf("stren\n");
        if (optflags & OPT_LSTRENGTH)
            ReduceLoopStrength(); /* loop index variable strength reduction */
    //printf("invar\n");
        if (optflags & OPT_INVARIANT)
            MoveLoopInvariants();	/* move loop invariants out of loops */

        if (optflags & OPT_GLOBAL)
        {
        //printf("alias\n");
            AliasPass1();
        }
    //printf("ssa out\n");
        TranslateFromSSA(FALSE);
        removeDead(blockArray[0]);
//		RemoveCriticalThunks();
        if (optflags & OPT_GLOBAL)
        {
    //printf("alias 2\n");
            AliasPass2();
            //printf("global\n");
            GlobalOptimization(); /* partial redundancy, code motion */
            AliasRundown();
        }
                 //printf("end opt\n");
           RemoveCriticalThunks();
        removeDead(blockArray[0]);
        RemoveInfiniteThunks();
    }
    else
    {
        RemoveCriticalThunks();
        RemoveInfiniteThunks();
    }
    /* backend modifies ICODE to improve code generation */
    if (chosenAssembler->gen->post_gcse)
    {
        chosenAssembler->gen->post_gcse(intermed_head);
    }
    /* register allocation - this first where we go into SSA form and backi s because 
     * at this point for global allocation we had to reuse original
     * register names, but the register allocation phase works better
     * when registers are disentangled and have smaller lifetimes
     * 
     * while we are back in SSA form we do some improvements to the code that will
     * help in register allocation and code generation.
     */
    definesInfo();
    liveVariables();
    doms_only(TRUE);
        //printf("to ssa\n");
    TranslateToSSA();
    CalculateInduction();

    /* lower for backend, e.g. do transformations that will improve the eventual
     * code gen, such as picking scaled indexed modes, moving constants, etc...
     */
        //printf("prealloc\n");
    Prealloc(1);
        //printf("from ssa\n");
    TranslateFromSSA(TRUE);
    //printf("peep\n");
      peep_icode(FALSE);			/* peephole optimizations at the ICODE level */
    RemoveCriticalThunks();
    removeDead(blockArray[0]);			/* remove dead blocks */

            //printf("allocate\n");
    /* now do the actual allocation */
    AllocateRegisters(intermed_head); 
    /* backend peephole optimization can sometimes benefit by knowing what is live */
            //printf("live\n");

    CalculateBackendLives();
    sFree();
    peep_icode(TRUE);	/* we do branche opts last to not interfere with other opts */
            //printf("optimzation done\n");

}
Exemple #5
0
void verifyModel(cchar* name, cchar* model)
{
    // Parse CNF:
    VSolver S;
    int     len  = strlen(name);
    char*   tmp  = NULL;
    int     stat = 0;
    FILE*   in;
    if (len > 5 && strcmp(name+len-5, ".bcnf") == 0){
        reportf("(cannot verify BCNF files)\n"); return; }
    if (len > 3 && strcmp(name+len-3, ".gz") == 0){
        tmp = xstrdup("tmp_XXXXXX");
        int fd = mkstemp(tmp);
        if (fd == -1)
            fprintf(stderr, "ERROR! Could not create temporary file for unpacking problem.\n"),
            exit(1);
        else
            close(fd);
        stat = system(sFree(nsprintf("zcat %s  > %s", name, tmp)));
        in = fopen(tmp, "rb");
    }else
        in = fopen(name, "rb");
    if (stat != 0 || in == NULL)
        fprintf(stderr, "ERROR! Could not open file: %s\n", name),
        exit(1);
    parse_DIMACS(in, S);
    fclose(in);
    if (tmp != NULL)
        remove(tmp);

    // Parse model:
    vec<bool>   true_lits(S.nVars()*2, false);
    int         lit;
    in = fopen(model, "rb"); assert(in != NULL);
    for(;;){
        int n = fscanf(in, "%d", &lit);
        if (n != 1 || lit == 0) break;
        if (lit < 0)
            true_lits[index(~Lit(-lit-1))] = true;
        else
            true_lits[index( Lit( lit-1))] = true;
    }
    fclose(in);

    //for (int i = 0; i < true_lits.size(); i++)
    //    if (true_lits[i]) printf(L_LIT" ", L_lit(toLit(i)));
    //printf("\n");

    // Check satisfaction:
    for (int i = 0; i < S.clauses.size(); i++){
        VClause& c = *S.clauses[i];
        for (int j = 0; j < c.size(); j++){
            if (true_lits[index(c[j])])
                goto Satisfied;
        }

        printf("FALSE MODEL!!!\n");
        printf("{");
        for (int j = 0; j < c.size(); j++)
            printf(" x%d:%d", var(c[j]), true_lits[index(c[j])]);
        printf(" }\n");
        exit(0);

      Satisfied:;
    }
}
static LRESULT WINAPI 
sDurationMsgProc (
		HWND	hwnd, 
		UINT	msg, 
		WPARAM	wParam, 
		LPARAM	lParam) 
{
	DCWndData* pDC = Duration_GetPtr(hwnd);

    if (pDC == NULL) {
        if (msg == WM_NCCREATE) 
		{
			pDC = (DCWndData*)sAlloc (sizeof(DCWndData));
			if (pDC == NULL) return 0L;
			Duration_SetPtr (hwnd, pDC);
        }
        else 
        	return DefWindowProc (hwnd, msg, wParam, lParam);
    }
	
    if (msg == WM_NCDESTROY) 
	{
		sFree (pDC);
        pDC = NULL;
        Duration_SetPtr (hwnd, NULL);
    }

	switch (msg) {

	case WM_CREATE :
	{
		LPCREATESTRUCT	lpcs		= (LPCREATESTRUCT)lParam;

		pDC->hwnd		= hwnd;
		pDC->hwndParent = lpcs->hwndParent;
		pDC->iID		= (INT)(lpcs->hMenu); 
		pDC->dwStyle	= lpcs->style & ES_READONLY;
		pDC->hFont		= GetStockObject (DEFAULT_GUI_FONT);

		pDC->iFocused		= -1;
		pDC->iPrevFocused	= 0;
		pDC->bFirstKey		= TRUE;
		pDC->iHeight		= lpcs->cy;

		pDC->iRangeLo[DAYS]		= 0;
		pDC->iRangeLo[HOURS]	= 0;
		pDC->iRangeLo[MINS]		= 0;

		pDC->iRangeHi[DAYS]		= 99;
		pDC->iRangeHi[HOURS]	= 23;
		pDC->iRangeHi[MINS]		= 59;

		pDC->ulDuration			= 0;
		pDC->ulMinDuration		= 0;
		pDC->ulMaxDuration		= 8553600 + 82800 + 3540; // 99d + 23h + 59m

		lstrcpy (&pDC->szText[DAYS][0], "d, ");
		lstrcpy (&pDC->szText[HOURS][0], "h, ");
		lstrcpy (&pDC->szText[MINS][0], "m");

		// create the up/down control
		pDC->hwndUpDown = CreateWindowEx (0L, UPDOWN_CLASS, "",
			WS_CHILD|WS_VISIBLE|pDC->dwStyle,
			0, 0, 0, 0, hwnd, NULL, 0, NULL);

		// create edit controls
		// days
		pDC->hwndEdit[DAYS] = CreateWindowEx (0L, "EDIT", "",
			WS_CHILD|WS_TABSTOP|WS_VISIBLE|ES_NUMBER|ES_RIGHT|pDC->dwStyle, 
			0, 0, 0, 0, hwnd, (HMENU)IDC_EDITDAYS, 0, NULL);
		SendMessage (pDC->hwndEdit[DAYS], 
						WM_SETFONT, (WPARAM)pDC->hFont, FALSE);
		SendMessage (pDC->hwndEdit[DAYS], 
						EM_SETLIMITTEXT, 2, 0);
		pDC->wpOrigEditProc[DAYS] = 
						(WNDPROC) SetWindowLong (pDC->hwndEdit[DAYS],
								GWL_WNDPROC, (LONG)sEditDaysProc); 

		pDC->hwndText[DAYS] = CreateWindowEx (0L, "EDIT", "",
			WS_CHILD|WS_VISIBLE|ES_LEFT|pDC->dwStyle, 
			0, 0, 0, 0, hwnd, (HMENU)IDC_TEXTDAYS, 0, NULL);
		SendMessage (pDC->hwndText[DAYS], 
						WM_SETFONT, (WPARAM)pDC->hFont, FALSE);
		pDC->wpOrigTextProc[DAYS] = 
						(WNDPROC) SetWindowLong (pDC->hwndText[DAYS],
								GWL_WNDPROC, (LONG)sText0Proc); 

		// hours
		pDC->hwndEdit[HOURS] = CreateWindowEx (0L, "EDIT", "",
			WS_CHILD|WS_TABSTOP|WS_VISIBLE|ES_NUMBER|ES_RIGHT|pDC->dwStyle, 
			0, 0, 0, 0, hwnd, (HMENU)IDC_EDITHOURS, 0, NULL);
		SendMessage (pDC->hwndEdit[HOURS], 
						WM_SETFONT, (WPARAM)pDC->hFont, FALSE);
		SendMessage (pDC->hwndEdit[HOURS], 
						EM_SETLIMITTEXT, 2, 0);
		pDC->wpOrigEditProc[HOURS] = 
						(WNDPROC) SetWindowLong (pDC->hwndEdit[HOURS],
								GWL_WNDPROC, (LONG)sEditHoursProc); 

		pDC->hwndText[HOURS] = CreateWindowEx (0L, "EDIT", "",
			WS_CHILD|WS_VISIBLE|ES_LEFT|pDC->dwStyle, 
			0, 0, 0, 0, hwnd, (HMENU)IDC_TEXTHOURS, 0, NULL);
		SendMessage (pDC->hwndText[HOURS], 
						WM_SETFONT, (WPARAM)pDC->hFont, FALSE);
		pDC->wpOrigTextProc[HOURS] = 
						(WNDPROC) SetWindowLong (pDC->hwndText[HOURS],
								GWL_WNDPROC, (LONG)sText1Proc); 

		// minutes
		pDC->hwndEdit[MINS] = CreateWindowEx (0L, "EDIT", "",
			WS_CHILD|WS_TABSTOP|WS_VISIBLE|ES_NUMBER|ES_RIGHT|pDC->dwStyle, 
			0, 0, 0, 0, hwnd, (HMENU)IDC_EDITMINS, 0, NULL);
		SendMessage (pDC->hwndEdit[MINS], 
						WM_SETFONT, (WPARAM)pDC->hFont, FALSE);
		SendMessage (pDC->hwndEdit[MINS], 
						EM_SETLIMITTEXT, 2, 0);
		pDC->wpOrigEditProc[MINS] = 
						(WNDPROC) SetWindowLong (pDC->hwndEdit[MINS],
								GWL_WNDPROC, (LONG)sEditMinsProc); 

		pDC->hwndText[MINS] = CreateWindowEx (0L, "EDIT", "",
			WS_CHILD|WS_VISIBLE|ES_LEFT|pDC->dwStyle, 
			0, 0, 0, 0, hwnd, (HMENU)IDC_TEXTMINS, 0, NULL);
		SendMessage (pDC->hwndText[MINS], 
						WM_SETFONT, (WPARAM)pDC->hFont, FALSE);
		pDC->wpOrigTextProc[MINS] = 
						(WNDPROC) SetWindowLong (pDC->hwndText[MINS],
								GWL_WNDPROC, (LONG)sText2Proc); 

		sSetControls (hwnd, pDC);

		break;
	}

	case WM_GETDLGCODE :
		return DLGC_WANTMESSAGE;
		
	case WM_NOTIFY :
	{
		LPNMHDR	pnmhdr = (LPNMHDR)lParam;

		if (pnmhdr->hwndFrom == pDC->hwndUpDown)
		{
			LPNMUPDOWN pnmud = (LPNMUPDOWN)lParam;
			sScrollUnit (pDC, -1*pnmud->iDelta);
		}
		break;
	}

	case WM_PAINT :
		// paint background, if necessary
		if (pDC->dwStyle & (WS_DISABLED | ES_READONLY))
		{
			PAINTSTRUCT	ps;
			HDC			hdc;
			RECT		rc;

			hdc = BeginPaint (hwnd, &ps);
			GetClientRect (hwnd, &rc);
			FillRect (hdc, &rc, (HBRUSH)(COLOR_3DFACE+1));
			EndPaint (hwnd, &ps);
		}
		break;

	case WM_SETFOCUS :
		SetFocus (pDC->hwndEdit[pDC->iPrevFocused]);
		break;

	case WM_DESTROY :
		SetWindowLong (pDC->hwndText[DAYS], 
							GWL_WNDPROC, (LONG)pDC->wpOrigTextProc[DAYS]); 
		SetWindowLong (pDC->hwndText[HOURS], 
							GWL_WNDPROC, (LONG)pDC->wpOrigTextProc[HOURS]); 
		SetWindowLong (pDC->hwndText[MINS],
							GWL_WNDPROC, (LONG)pDC->wpOrigTextProc[MINS]);
		
		DestroyWindow (pDC->hwndText[DAYS]);
		DestroyWindow (pDC->hwndText[HOURS]);
		DestroyWindow (pDC->hwndText[MINS]);

		SetWindowLong (pDC->hwndEdit[DAYS], 
							GWL_WNDPROC, (LONG)pDC->wpOrigEditProc[DAYS]); 
		SetWindowLong (pDC->hwndEdit[HOURS], 
							GWL_WNDPROC, (LONG)pDC->wpOrigEditProc[HOURS]); 
		SetWindowLong (pDC->hwndEdit[MINS], 
							GWL_WNDPROC, (LONG)pDC->wpOrigEditProc[MINS]); 
		
		DestroyWindow (pDC->hwndEdit[DAYS]);
		DestroyWindow (pDC->hwndEdit[HOURS]);
		DestroyWindow (pDC->hwndEdit[MINS]);

		DestroyWindow (pDC->hwndUpDown);
		break;

	case EM_SETREADONLY :
		if (wParam)
			pDC->dwStyle |= ES_READONLY;
		else
			pDC->dwStyle &= ~ES_READONLY;

		SendMessage (pDC->hwndText[DAYS], msg, wParam, lParam);
		SendMessage (pDC->hwndText[HOURS], msg, wParam, lParam);
		SendMessage (pDC->hwndText[MINS], msg, wParam, lParam);

		SendMessage (pDC->hwndEdit[DAYS], msg, wParam, lParam);
		SendMessage (pDC->hwndEdit[HOURS], msg, wParam, lParam);
		SendMessage (pDC->hwndEdit[MINS], msg, wParam, lParam);

		InvalidateRect (hwnd, NULL, TRUE);
		break;

	case WM_HELP :
	{
		LPHELPINFO lphi = (LPHELPINFO)lParam;

		lphi->iCtrlId = pDC->iID;
		lphi->hItemHandle = pDC->hwnd;
		break;
	}

	case WM_ENABLE :
		if (wParam)
		{
			pDC->dwStyle &= ~WS_DISABLED;
			EnableWindow (pDC->hwndUpDown, TRUE);
		}
		else
		{
			pDC->dwStyle |= WS_DISABLED;
			EnableWindow (pDC->hwndUpDown, FALSE);
		}

		SendMessage (pDC->hwndText[DAYS], msg, wParam, lParam);
		SendMessage (pDC->hwndText[HOURS], msg, wParam, lParam);
		SendMessage (pDC->hwndText[MINS], msg, wParam, lParam);

		SendMessage (pDC->hwndEdit[DAYS], msg, wParam, lParam);
		SendMessage (pDC->hwndEdit[HOURS], msg, wParam, lParam);
		SendMessage (pDC->hwndEdit[MINS], msg, wParam, lParam);

		InvalidateRect (hwnd, NULL, TRUE);
		return 0;

	case PGP_DCM_SETDURATION :
		pDC->ulDuration = lParam;
		sDisplayDuration (pDC);
		break;

	case PGP_DCM_GETDURATION :
		*(PULONG)lParam = pDC->ulDuration;
		break;

	case PGP_DCM_SETMINDURATION :
		pDC->ulMinDuration = (ULONG)lParam;
		break;

	case PGP_DCM_SETMAXDURATION :
		pDC->ulMaxDuration = (ULONG)lParam;
		break;

	case PGP_DCM_SETTEXT :
		lstrcpyn (&pDC->szText[wParam][0], (LPSTR)lParam, MAXTEXTLEN);
		sSetControls (hwnd, pDC);
		InvalidateRect (hwnd, NULL, TRUE);
		break;
	} 
	return (DefWindowProc (hwnd, msg, wParam, lParam));
}