Implement two intra-procedural dataflow analyses

Assignment Help Other Subject
Reference no: EM132006898

Dataflow Analysis

Objective

This lab will familiarize you with writing static program analyses using the LLVM compiler infrastructure. LLVM is a collection of compiler and analysis toolchain utilities widely used in the software analysis community. You will use LLVM to implement two intra-procedural dataflow analyses, one forward (reaching definitions analysis) and one backward (liveness analysis). In LLVM, these are referred to as passes over the code.

Lab Setup

1. Download and extract the lab code found on Canvas in the dataflow.zip archive.

2. Navigate to dataflow/build and run the following commands:

cmake ..
make clean
make

You should now see libDataflowPass.so under dataflow/build/Dataflow.

3. Go to the dataflow/example directory and generate LLVM bitcode from the programs we will analyze with the following commands:

clang -emit-llvm ArrayDemo.c -c -o ArrayDemo.bc
clang -emit-llvm Greatest.c -c -o Greatest.bc

4. Run a Dataflow pass using the command below to ensure everything works as expected for the test program ArrayDemo.c. This pass demonstrates the API by printing the definitions, uses, predecessors, and successors of each instruction.

opt -load ../build/Dataflow/libDataflowPass.so -Printer < ArrayDemo.bc > /dev/null

In addition to testing your setup, the printer pass (in Printer.cpp) is a very useful reference for implementing your own passes.

Lab Instructions

Complete the doAnalysis method in the ReachDefAnalysis.cpp and LivenessAnalysis.cpp (located in dataflow/Dataflow/) skeleton files to implement the two analyses. Do not write your analysis code outside of these files, as these files are the only ones you will submit. You may use the C++ Standard Template Library (STL) when implementing your analyses, but you may not use other third party libraries.

Your code will need to iterate over the program points in the input program and store the computed dataflow facts in DataflowAnalysis::inMap and DataflowAnalysis::outMap. Both analyses inherit from the base class DataflowAnalysis, which you can find in the header file DataflowAnalysis.h located in the directory dataflow/Dataflow/. Besides including useful classes such as SetVector and ValueMap, DataflowAnalysis.h also defines useful utility functions such as getPredecessors, getSuccessors, and isDef.

LLVM passes are performed an intermediate representation (LLVM bitcode) generated from the program source code. LLVM bitcode is generated in Static Single Assignment (SSA) form, a common simplification used by compiler infrastructure. In SSA form, each variable is assigned exactly once, and every variable is defined before it is used. Variables are represented directly by the instruction defining it. In fact, the Instruction class is a subtype of the Value class. You can check whether an instruction defines a variable by checking getType()->isVoidTy(). An entry into the inMap or outMap is the instruction as opposed to a variable. The lectures speak to variables being stored (x or y) but with the SSA representation being used, the instruction itself is a proxy for the variable. That is why the inMap and outMap all show the instructions in the printer output.

Since each variable is uniquely defined, variables will never be redefined in SSA form. This will affect the generation of KILL sets in your implementation of reaching definitions analysis, specifically, they will always be empty.

After completing the two doAnalysis methods, rebuild the analyses using the commands from setup step 2, and then rerun the analyses using following commands to print the results of the analyses on the ArrayDemo program:

opt -load ../build/Dataflow/libDataflowPass.so -ReachDef < ArrayDemo.bc > /dev/null opt -load ../build/Dataflow/libDataflowPass.so -Liveness < ArrayDemo.bc > /dev/null

If your implementation is correct, your output will match the example output in ArrayDemo_ReachDef and ArrayDemo_Liveness found in dataflow/example/. The order of elements in the IN and OUT sets does not matter, but the number of elements and the values should match exactly.

We have also included another program, Greatest.c, and it's expected outputs for testing your implementation. You can use commands similar to those above to analyze this program. We also encourage students to develop their own test cases / corresponding output and share them on Piazza, although we will not be validating them for correctness.

Additionally, we have provided images of the control flow graphs (CFGs) for both programs, named array_demo_graph.png and greatest_graph.png. Each instruction is represented by a node, and edges represent an instruction's successor instruction(s). These graphs are useful for reasoning about the correctness of your IN and OUT sets for the sample program analyses. We recommend that you take a moment to review the graph and ensure you understand the structure of each program. Pay close attention to the instructions that have multiple successor and/or predecessor instructions.

Helpful LLVM API Information

ValueMap has a similar interface to std::map. For example, you can access or insert an element using the [] operator:

ValueMap<Instruction*, int> vm; Instruction* I = /*...*/; vm[I] = 5; // inserts <I, 5> to the map

LLVM will generate all of the necessary objects for your analyses according to its object model (see DataflowAnalysis.cpp). You will not need to create new elements to insert into DataflowAnalysis::inMap or DataflowAnalysis::outMap, your code should add the pointer to the object to the ValueMap.

SetVector has a similar interface to std::vector, except that it does not permit inserting duplicate elements. The == operator returns false for two SetVector objects containing the same elements in different orders.

Also, functions in the <algorithm> library from the STL work with SetVector. For example:
SetVector<int> sv; for( int i = 0; i < 5; i++ )
sv.insert(i); sv.insert(0); // has no effect if (std::all_of(sv.begin(), sv.end(), isPositive))
// all_of is from <algorithm> printf("All numbers in sv are positive!");

assuming isPositive is defined elsewhere as:
             bool isPositive(int i) {return i > 0;}

Items to Submit
Submit the following files in a single compressed file (.zip format) named lab3.zip. For full credit, there must not be any subfolders or extra files contained within your zip file.
1. LivenessAnalysis.cpp
2. ReachDefAnalysis.cpp

Attachment:- dataflow.zip

Reference no: EM132006898

Questions Cloud

Estimate the population mean for a 95 confidence level : Estimate the population mean for a 95% confidence level. Your final answers should be correct to 2 places after the decimal point.
Describe the rationals for the nursing intervention : Describe the rationals for the following nursing intervention for a 75 year old lady/man. Use a minimum 2 complete sentences for each intervention.
Introduce the company to activity-based costing : Explain how activity-based costing is different from job costing. Give examples of each costing approach and how they can be applied to different industries.
Compute a z-score important : 1. What is a z-score? What is the formula? Why is being able to compute a z-score important?
Implement two intra-procedural dataflow analyses : Dataflow Analysis - You will use LLVM to implement two intra-procedural dataflow analyses, one forward (reaching definitions analysis) and one backward livenes
Identify your strengths related to the given four content : Write a reflection of 750-1,000 words in which you identify your strengths and weaknesses related to the four content areas below.
Run a regression analysis : Can someone please confirm that when we use Excel to run a regression analysis, the intercept and slope coefficients that Excel gives are population parameters
Determining the explanatory variables : If we have two explanatory variables A1, A2, which of the following is true about Significance F calculated using regression model in excel?
Find the probability that the sales for next month : Find the probability that the sales for next month was 15,000 or larger.

Reviews

urv2006898

10/16/2018 3:39:37 AM

Undeniably the best assignment writing services. My experience was exceptional. Thanks. "I really would like to say thank you for all that you have done to assist me with keeping my stress levels low. Working with you guys is always soothing. thank you so much. good handled."

len2006898

6/4/2018 5:42:53 AM

While efficiency is important, it is entirely secondary to correctness. While you may lose some points for an inefficient yet correct algorithm, you will not gain points for an efficient yet incorrect algorithm. There is a time limit several times longer than the expected execution time for an efficient algorithm in the grader. Any analysis that has not completed at the end of this time limit will not be considered correct as will any analysis that causes a crash.

len2006898

6/4/2018 5:42:39 AM

Also, the assignment needs to be done completely correct. Here is the video for the introduction to the lab Generally, credit for this lab is awarded as follows: If the correct output set for Analysis X contains n entries and your output set contains a of those correct entries and b spurious entries, then you will receive max(0, (a-b)/n) of the points for Analysis X, using floating-point division. Your dataflow analyses will be graded against four programs, the two benchmark programs provided as a part of this lab assignment and two that are not provided. In general, the programs used in grading but not provided as part of the lab are of the same order of complexity as the provided programs.

Write a Review

Other Subject Questions & Answers

  What disadvantages has bloc membership produced

Virtually every country is now party to one or more free trade agreements. Supporters argue that free trade is good for nations.  What is the basis for their support That is, what are the specific benefits that countries seek by joining an economic b..

  Physical functioning deteriorates

As we age, our physical functioning deteriorates. This is most likely due to reduced efficiency in basic cellular processes. One cause of this is thought to be what?

  Violence by islamic youth in france

Critically discuss some of the reasons for the recent rise of violence by Islamic youth in France? Use at least one internet source in addition to the text to answer this question.

  An analysis of project tasks and phases

Reflect on your readings for this unit and familiarize yourself with the project planning tools explored and Pay specific attention to the Work Breakdown Structure and Gantt chart from your Resources - Review your scenario. Begin to conceptualize whi..

  Are trash receptacles easy to gain access to

Are trash receptacles easy to gain access to?Are documents shredded before being discarded?Are areaswhere trash is stored easily accessible?

  Method in researching human behavior

Describe how you would use this method in researching human behavior and what topics you might study.

  Discuss issues involved if annie wants to add square footage

Discuss the issues involved if Annie wants to add square footage or makes structural alterations in order to live there. Discuss the issues if she adds square footage or makes structural Alterations in restarting the restaurant.

  Describe the national fire protection association

Explain at least five National Fire Protection Association (NFPA) codes or requirements related to the leakage current limits in medical equipment in hospitals

  How may anthropology be applied to address some problems

How may anthropology be applied to address some problems of the modern world. Give some general ideas and a specific example.

  Explain the person life in terms of nature influences

Explain the person's life in terms of nature/nurture influences. Provide an analysis of the role cognitive, physical, and social-emotional development/changes played in the person's life

  What language problem is reflected in this situation

Judonna and Candice were shopping at the mall. Judonna needed to go to the other end of the mall to get something. She said to Candice, “Meet me at 2:00 in front of Sears.” What language problem is reflected in this situation?

  What did mr welch mean by this statement

Keki Dadiseth, retired Unilever business executive, followed some basic rules that can trigger change (Goleman, Boyatzis, & McKee, 2002). What did Mr. Welch mean by this statement? What are some ways in which leaders can overcome change

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd