What is a Basic Block ? A BASIC BLOCK is a sequence of consecutive language statements with the following properties: Program flow doesn't jump into or.

Slides:



Advertisements
Similar presentations
Goal: Write Programs in Assembly
Advertisements

CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
1 ILP (Recap). 2 Basic Block (BB) ILP is quite small –BB: a straight-line code sequence with no branches in except to the entry and no branches out except.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
Apr. 12, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 6: Branching and Procedures in MIPS* Jeremy R. Johnson Wed. Apr. 12, 2000.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
1 CS 201 Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Programming with Shared Memory Introduction to OpenMP
CS470/570 Lecture 5 Introduction to OpenMP Compute Pi example OpenMP directives and options.
Algorithms and Computing Lecture 3 Control Statements By Dr. M. Tahir Khaleeq.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Program Looping Making Decisions Copyright © 2012 by Yong-Gu Lee
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
RELATIONAL OPERATORS LOGICAL OPERATORS CONDITION Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
CSc 453 Final Code Generation Saumya Debray The University of Arizona Tucson.
1 Code Generation Part II Chapter 9 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
Computer architecture Lecture 11: Reduced Instruction Set Computers Piotr Bilski.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
1 Control Flow Analysis Topic today Representation and Analysis Paper (Sections 1, 2) For next class: Read Representation and Analysis Paper (Section 3)
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic3: Instructions, The Language of the Machine José Nelson Amaral.
1 Chapter10: Code generator. 2 Code Generator Source Program Target Program Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator.
Variable Scope. When you declare a variable, that name and value is only “alive” for some parts of the program  We must declare variables before we use.
CS 404 Introduction to Compiler Design
Chapter 6: Loops.
Introduction to OpenMP
CS2100 Computer Organisation
Optimizing Compilers Background
Iteration statement while do-while
Programming Fundamentals
Flow of Control.
CS170 Computer Organization and Architecture I
Flow of Control.
Switch Statements, Do While, Break, Continue, Goto, Comma Operator
Conditional Construct
TARGET CODE GENERATION
1) C program development 2) Selection structure
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Flow of Control.
Coding Constructs considered Violations of Structured Programming
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Low Level Programming Languages
Control Flow Analysis (Chapter 7)
A Simple Two-Pass Assembler
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Interval Partitioning of a Flow Graph
COMS 361 Computer Organization
COMS 361 Computer Organization
Flow of Control.
8 Code Generation Topics A simple code generator algorithm
Structured Programming
Intermediate Code Generation
Code Generation Part II
Decision making and control functions
Target Code Generation
TARGET CODE GENERATION
Chapter 15 Debugging.
CSc 453 Final Code Generation
Iteration Statement for
Bubble Sort begin; int A[10]; main(){ int i,j; Do 10 i = 0, 9, 1
Chapter 15 Debugging.
Code Optimization.
Presentation transcript:

What is a Basic Block ? A BASIC BLOCK is a sequence of consecutive language statements with the following properties: Program flow doesn't jump into or from that block except maybe to the first statement or from the last statement. A simple example of such a jump is executing any GOTO statement, but IF and DO statements are really constructed out of similar implied jumps. The sequence is maximal in the sense that adding one more statement at the beginning of the block, or one more statement at the end, will make the previous requirement false. When you examine the way program control flows, the basic blocks are the natural building blocks, so making their boundaries stand out will make the code easier to follow

Mapping C code to Blocks Using IR Viewer Fact2 benchmark source int main (int argc, char *argv[]) { int i,s,n; if (argc < 2) { printf("Usage: fact2 <n>\n"); exit(1); } n = atoi(argv[1]); for (i=1, s=1 ; i <= n ; i++) s *= i; printf("fact %d = %d\n", (i-1), s); exit(0); A BASIC BLOCK is a sequence of consecutive language statements with the following properties: Program flow doesn't jump into or from that block except maybe to the first statement or from the last statement. A simple example of such a jump is executing any GOTO statement, but IF and DO statements are really constructed out of similar implied jumps. The sequence is maximal in the sense that adding one more statement at the beginning of the block, or one more statement at the end, will make the previous requirement false. When you examine the way program control flows, the basic blocks are the natural building blocks, so making their boundaries stand out will make the code easier to follow.

Indentifying Loops int main (int argc, char *argv[]) { int i,s,n; if (argc < 2) { printf("Usage: fact2 <n>\n"); exit(1); } n = atoi(argv[1]); for (i=1, s=1 ; i <= n ; i++) s *= i; printf("fact %d = %d\n", (i-1), s); exit(0);

Reading REBEL Code Format of a Rebel Operation Format of Operand in Rebel Operation

Example Rebel Block (eight Benchmark) bb 2 ( weight(1) entry_ops(65) exit_ops(66) entry_edges(ctrl ^13) exit_edges(ctrl ^21) flags(sched) attr(lc ^102) subregions( op 65 (C_MERGE [] [] s_time(0) s_opcode(C_MERGE.0) in_edges(op-64(1)) flags(sched)) op 7 (MOVE [br<6:i gpr 4>] [i<0>] p<t> s_time(0) s_opcode(MOVE.0) op 8 (MOVE [br<5:i gpr 12>] [i<0>] p<t> s_time(0) s_opcode(MOVE.1) op 9 (MOVE [br<4:i gpr 11>] [i<0>] p<t> s_time(0) s_opcode(MOVE.2) op 10 (MOVE [br<3:i gpr 5>] [i<0>] p<t> s_time(0) s_opcode(MOVE.3) op 11 (MOVE [br<2:i gpr 10>] [i<0>] p<t> s_time(1) s_opcode(MOVE.0) op 12 (MOVE [br<1:i gpr 2>] [i<0>] p<t> s_time(1) s_opcode(MOVE.1) op 66 (DUMMY_BR [] [] s_time(2) s_opcode(DUMMY_BR.0) out(op-67(1)) ) Frequency of visits to region Entry only at Op 65 and exit at Op 66 Sub-region containing Operations In the eight benchmark, this block corresponds to the a=b=c=d=e=x=y=0; statement. Each Operation MOVEs to the variable’s register the value ‘0’ Thus one of the above variables is in virtual register 1/physical register 2 and is initialized to ‘0’ The Format of the various instructions is given in the HPL-PD Industry Standard Architecture