Code flow & analysis

Code flow & analysis

Data flow analysis in Compiler

  • Difficulty Level : Medium
  • Last Updated : 22 Feb, 2022

It is the analysis of flow of data in control flow graph, i.e., the analysis that determines the information regarding the definition and use of data in program. With the help of this analysis, optimization can be done. In general, its process in which values are computed using data flow analysis. The data flow property represents information that can be used for optimization. 

Basic Terminologies – 
 

  • Definition Point: a point in a program containing some definition.
  • Reference Point: a point in a program containing a reference to a data item.
  • Evaluation Point: a point in a program containing evaluation of expression.

 

Data Flow Properties – 
 

  • Available Expression – A expression is said to be available at a program point x if along paths its reaching to x. A Expression is available at its evaluation point. 
    An expression a+b is said to be available if none of the operands gets modified before their use. 

    Example – 
     

  • Advantage – 
    It is used to eliminate common sub expressions. 

     

  • Reaching Definition – A definition D is reaches a point x if there is path from D to x in which D is not killed, i.e., not redefined. 

    Example – 
     

Advantage –
    document.addEventListener("DOMContentLoaded", function () { /* -------- Date Helpers -------- */ function addDays(date, days) { const d = new Date(date); d.setDate(d.getDate() + days); return d; } function isWorkingDay(date) { const day = date.getDay(); // 0=Sun, 6=Sat return day !== 0 && day !== 6; // Mon-Fri only } function addWorkingDays(startDate, days) { let current = new Date(startDate); let remaining = days; while (remaining > 0) { current = addDays(current, 1); if (isWorkingDay(current)) { remaining--; } } return current; } function formatDate(date) { return date.toISOString().split('T')[0]; // YYYY-MM-DD } /* -------- DOM Wiring -------- */ const calcButton = document.getElementById("calcBtn"); const daysInput = document.getElementById("daysInput"); const typeContainer = document.getElementById("typeContainer"); const dayTypeSelect = document.getElementById("dayType"); const resultDiv = document.getElementById("result"); if (!calcButton || !daysInput || !typeContainer || !dayTypeSelect || !resultDiv) { console.error("Required DOM elements missing"); return; } let enteredDays = 0; calcButton.addEventListener("click", function () { enteredDays = parseInt(daysInput.value, 10); if (!Number.isInteger(enteredDays) || enteredDays < 0) { resultDiv.textContent = "Please enter a valid non-negative integer."; resultDiv.style.color = "red"; return; } typeContainer.style.display = "block"; dayTypeSelect.value = ""; resultDiv.textContent = ""; }); dayTypeSelect.addEventListener("change", function () { if (enteredDays === 0) return; const today = new Date(); let resultDate; if (dayTypeSelect.value === "working") { resultDate = addWorkingDays(today, enteredDays); } else { resultDate = addDays(today, enteredDays); } const formatted = formatDate(resultDate); resultDiv.textContent = `Result date: ${formatted}`; resultDiv.style.color = "green"; // Reset enteredDays = 0; typeContainer.style.display = "none"; dayTypeSelect.value = ""; daysInput.value = ""; }); });