SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Basic Blocks




    BY:SHIVPRASAD U SHETTI
Three Address Code
 Three-address code (often abbreviated to TAC or 3AC) is an intermediate
code used by     compilers to aid in the implementation of code-improving
transformations.

 Three Address Code is sequence of statements, typically of a general form A:= B
op C, where A,B , and C are either programmer-Defined names, constants or
compiler-generated temporary names; op stands for any operator, such as a fixed- or
floating point arithmetic operator, or a logical operator on Boolean-valued data.

 The reason for the name “Three –address code” is that each statements usually
contains three addresses, two for the operands and one for result.

 Example: Write a Three Address Code for following expression: “ X+Y*Z ”
                Solution: T1 := Y * Z
                        T2 := X + T1
           Where T1 and T2 are compiler-generated temporary names.
TAC Example

                    Three Address Code Computing Dot product

BEGIN                                  1) PROD :=0
                                       2) I:=1
   PROD := 0;
   I := 1;                             3) T1 := 4*I
                                       4) T2 := addr(A) – 4
   DO
         BEGIN                         5) T3 := T2[T1]          /*
                                          Compute A[I] */
            PROD :=PROD +
A[I] *B[I];                            6) T4 := addr(B) - 4
            I :=I+1                    7) T5 := T4[T1]          /* Compute
         END                              B[I] */
    WHILE I ≤ 20                       8) T6 := T3 * T5
END                                    9) PROD := PROD + T6
                                       10) I := I+1
                                       11) If I ≤ 20 goto (3)
Algorithm: Partition into Basic Blocks.

Basic Blocks
                                             Input: A sequence of Three address statements.
  Our first step is to break the code       Output: A list of basic blocks with each three
 of     TAC Example in to basic              address statement in exactly one block.
 blocks,   that   is    sequence      of     Method:
 consecutive statements which may be         1) We first determine the set of leaders, the first
                                                statements of basic blocks the rules we use
 entered only at the beginning, and             are as follow”
 when entered are executed in                     i) The first statement is a leader
 sequence without halt or possibility of          ii) Any statement which is the target of a
 branch(except at the end of the basic          conditional or unconditional goto is a
 block).                                        leader
                                                  iii) Any statement which immediately
  A     useful         algorithms  for         follows a conditional goto is a leader
 partitioning three address statements       2) For each leader construct its basic
                                                block, which consists of the leader and all the
 into basic blocks is the following             statements up to but not including the next
                                                leader or the end of the program .Any
                                                statements not placed in a block can ever be
                                                executed and may now be removed, if
                                                desired.
Basic Block

 A basic block is a sequence of consecutive statements in which flow of control
  enters at the beginning and leaves at the end without halt or possibility of
  branching except at the end.
 The code in a basic block has:
 one entry point, meaning no code within it is the destination of a jump
  instruction anywhere in the program;
 one exit point, meaning only the last instruction can cause the program to
  begin executing code in a different basic block.

 A list of basic blocks with each three-address statement in exactly one block.
 Step 1. Identify the leaders in the code. Leaders are instructions which come
  under any of the following 3 categories :
 The first instruction is a leader.
 The target of a conditional or an unconditional goto/jump instruction is a
  leader.
 The instruction that immediately follows a conditional or an unconditional
  goto/jump instruction is a leader.
 Step 2. Starting from a leader, the set of all following instructions until and not
  including the next leader is the basic block corresponding to the starting leader
 Thus every basic block has a leader.
 BASIC BLOCKS

              A basic block is a sequence of consecutive
    statements in which flow of control enters at the beginning
    and leaves at the end without halt or possibility of
    branching except at the end. The following sequence of
    three-address statements forms a basic block:

   t1 := a*a
   t2 := a*b
   t3 := 2*t2
   t4 := t1+t3
   t5 := b*b
   t6 := t4+t5
 A three-address statement x := y+z is said to define x and to use y or z. A
  name in a basic block is said to live at a given point if its value is used after
  that point in the program, perhaps in another basic block.
 The following algorithm can be used to partition a sequence of three-address
  statements into basic blocks.
 Example 3: Consider the fragment of source code shown in fig. 7; it
    computes the dot product of two vectors a and b of length 20. A list of three-
    address statements performing this computation on our target machine is
    shown in fig. 8.
              begin
                 prod := 0;
                 i := 1;
                 do begin
                     prod := prod + a[i] * b[i];
                     i := i+1;
                  end
                   while i<= 20
               end
   fig 7: program to compute dot product
    Let us apply Algorithm 1 to the three-address code in fig 8 to determine its basic
    blocks. statement (1) is a leader by rule (I) and statement (3) is a leader by rule (II), since the
    last statement can jump to it. By rule (III) the statement following (12) is a leader.
    Therefore, statements (1) and (2) form a basic block. The remainder of the program beginning
    with statement (3) forms a second basic block.

   (1)    prod := 0
   (2)    i := 1
   (3)    t1 := 4*i
   (4)    t2 := a [ t1 ]
   (5)    t3 := 4*i
   (6)    t4 :=b [ t3 ]
   (7)    t5 := t2*t4
   (8)    t6 := prod +t5
   (9)    prod := t6
   (10)   t7 := i+1
   (11)   i := t7
   (12)    if i<=20 goto (3)

   fig 8. Three-address code computing dot product
•
    PROD :=0
•           B1
    I := 1




    T1:=4*I
    T2:=addr(A)-4
•   T3:=T2[T1]B2
    T4:=addr(B)-4
    T5:=T4[T1]
    T6:=T3*T5
    Prod:=PROD + T6
    I:=I+1
    If I<20 goto (3)

Weitere ähnliche Inhalte

Was ist angesagt?

Memory organization (Computer architecture)
Memory organization (Computer architecture)Memory organization (Computer architecture)
Memory organization (Computer architecture)Sandesh Jonchhe
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
Chapter 13 - I/O Systems
Chapter 13 - I/O SystemsChapter 13 - I/O Systems
Chapter 13 - I/O SystemsWayne Jones Jnr
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlaysmyrajendra
 
Database recovery techniques
Database recovery techniquesDatabase recovery techniques
Database recovery techniquespusp220
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques Kalhan Liyanage
 
File concept and access method
File concept and access methodFile concept and access method
File concept and access methodrajshreemuthiah
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES Kathirvel Ayyaswamy
 

Was ist angesagt? (20)

First and follow set
First and follow setFirst and follow set
First and follow set
 
Memory organization (Computer architecture)
Memory organization (Computer architecture)Memory organization (Computer architecture)
Memory organization (Computer architecture)
 
IP Datagram Structure
IP Datagram StructureIP Datagram Structure
IP Datagram Structure
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
File handling in C
File handling in CFile handling in C
File handling in C
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Chapter 13 - I/O Systems
Chapter 13 - I/O SystemsChapter 13 - I/O Systems
Chapter 13 - I/O Systems
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Chapter18
Chapter18Chapter18
Chapter18
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
 
Multiple access protocol
Multiple access protocolMultiple access protocol
Multiple access protocol
 
Database recovery techniques
Database recovery techniquesDatabase recovery techniques
Database recovery techniques
 
Error control
Error controlError control
Error control
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
database recovery techniques
database recovery techniques database recovery techniques
database recovery techniques
 
Mac sub layer
Mac sub layerMac sub layer
Mac sub layer
 
File concept and access method
File concept and access methodFile concept and access method
File concept and access method
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 

Ähnlich wie Basic Block

Code optimization lecture
Code optimization lectureCode optimization lecture
Code optimization lecturePrashant Singh
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Control Flow Graphs
Control Flow GraphsControl Flow Graphs
Control Flow Graphsdaimk2020
 
Control Flow Graphs
Control Flow GraphsControl Flow Graphs
Control Flow Graphsdaimk2020
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design LogsAk
 
Basic blocks - compiler design
Basic blocks - compiler designBasic blocks - compiler design
Basic blocks - compiler designhmnasim15
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )Ikhwan_Fakrudin
 
Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Ikhwan_Fakrudin
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questionsSANTOSH RATH
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)Sourov Kumar Ron
 
Lcdf4 chap 03_p2
Lcdf4 chap 03_p2Lcdf4 chap 03_p2
Lcdf4 chap 03_p2ozgur_can
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)bolovv
 
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12chinthala Vijaya Kumar
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfCode In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfaishwaryaequipment
 
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdfankit482504
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generationAkshaya Arunan
 

Ähnlich wie Basic Block (20)

Code optimization lecture
Code optimization lectureCode optimization lecture
Code optimization lecture
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Control Flow Graphs
Control Flow GraphsControl Flow Graphs
Control Flow Graphs
 
Control Flow Graphs
Control Flow GraphsControl Flow Graphs
Control Flow Graphs
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
 
Basic blocks - compiler design
Basic blocks - compiler designBasic blocks - compiler design
Basic blocks - compiler design
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
Embedded system (Chapter )
Embedded system (Chapter )Embedded system (Chapter )
Embedded system (Chapter )
 
Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1Embedded system (Chapter 5) part 1
Embedded system (Chapter 5) part 1
 
Module wise format oops questions
Module wise format oops questionsModule wise format oops questions
Module wise format oops questions
 
ERTS UNIT 3.ppt
ERTS UNIT 3.pptERTS UNIT 3.ppt
ERTS UNIT 3.ppt
 
Presentation(intermediate code generation)
Presentation(intermediate code generation)Presentation(intermediate code generation)
Presentation(intermediate code generation)
 
Lcdf4 chap 03_p2
Lcdf4 chap 03_p2Lcdf4 chap 03_p2
Lcdf4 chap 03_p2
 
Assignment
AssignmentAssignment
Assignment
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
Computer Science(083) Python Pre Board Exam 1 Sample Paper Class 12
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdfCode In PythonFile 1 main.pyYou will implement two algorithms t.pdf
Code In PythonFile 1 main.pyYou will implement two algorithms t.pdf
 
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
1.5 Legal Labels in Verilog areSystem Verilog extends it and al.pdf
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 

Kürzlich hochgeladen

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 

Kürzlich hochgeladen (20)

HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

Basic Block

  • 1. Basic Blocks BY:SHIVPRASAD U SHETTI
  • 2. Three Address Code  Three-address code (often abbreviated to TAC or 3AC) is an intermediate code used by compilers to aid in the implementation of code-improving transformations.  Three Address Code is sequence of statements, typically of a general form A:= B op C, where A,B , and C are either programmer-Defined names, constants or compiler-generated temporary names; op stands for any operator, such as a fixed- or floating point arithmetic operator, or a logical operator on Boolean-valued data.  The reason for the name “Three –address code” is that each statements usually contains three addresses, two for the operands and one for result.  Example: Write a Three Address Code for following expression: “ X+Y*Z ” Solution: T1 := Y * Z T2 := X + T1 Where T1 and T2 are compiler-generated temporary names.
  • 3. TAC Example Three Address Code Computing Dot product BEGIN 1) PROD :=0 2) I:=1 PROD := 0; I := 1; 3) T1 := 4*I 4) T2 := addr(A) – 4 DO BEGIN 5) T3 := T2[T1] /* Compute A[I] */ PROD :=PROD + A[I] *B[I]; 6) T4 := addr(B) - 4 I :=I+1 7) T5 := T4[T1] /* Compute END B[I] */ WHILE I ≤ 20 8) T6 := T3 * T5 END 9) PROD := PROD + T6 10) I := I+1 11) If I ≤ 20 goto (3)
  • 4. Algorithm: Partition into Basic Blocks. Basic Blocks Input: A sequence of Three address statements.  Our first step is to break the code Output: A list of basic blocks with each three of TAC Example in to basic address statement in exactly one block. blocks, that is sequence of Method: consecutive statements which may be 1) We first determine the set of leaders, the first statements of basic blocks the rules we use entered only at the beginning, and are as follow” when entered are executed in i) The first statement is a leader sequence without halt or possibility of ii) Any statement which is the target of a branch(except at the end of the basic conditional or unconditional goto is a block). leader iii) Any statement which immediately  A useful algorithms for follows a conditional goto is a leader partitioning three address statements 2) For each leader construct its basic block, which consists of the leader and all the into basic blocks is the following statements up to but not including the next leader or the end of the program .Any statements not placed in a block can ever be executed and may now be removed, if desired.
  • 5. Basic Block  A basic block is a sequence of consecutive statements in which flow of control enters at the beginning and leaves at the end without halt or possibility of branching except at the end.  The code in a basic block has:  one entry point, meaning no code within it is the destination of a jump instruction anywhere in the program;  one exit point, meaning only the last instruction can cause the program to begin executing code in a different basic block.  A list of basic blocks with each three-address statement in exactly one block.  Step 1. Identify the leaders in the code. Leaders are instructions which come under any of the following 3 categories :  The first instruction is a leader.  The target of a conditional or an unconditional goto/jump instruction is a leader.  The instruction that immediately follows a conditional or an unconditional goto/jump instruction is a leader.
  • 6.  Step 2. Starting from a leader, the set of all following instructions until and not including the next leader is the basic block corresponding to the starting leader  Thus every basic block has a leader.
  • 7.  BASIC BLOCKS  A basic block is a sequence of consecutive statements in which flow of control enters at the beginning and leaves at the end without halt or possibility of branching except at the end. The following sequence of three-address statements forms a basic block:   t1 := a*a  t2 := a*b  t3 := 2*t2  t4 := t1+t3  t5 := b*b  t6 := t4+t5
  • 8.  A three-address statement x := y+z is said to define x and to use y or z. A name in a basic block is said to live at a given point if its value is used after that point in the program, perhaps in another basic block.  The following algorithm can be used to partition a sequence of three-address statements into basic blocks.
  • 9.  Example 3: Consider the fragment of source code shown in fig. 7; it computes the dot product of two vectors a and b of length 20. A list of three- address statements performing this computation on our target machine is shown in fig. 8.  begin  prod := 0;  i := 1;  do begin  prod := prod + a[i] * b[i];  i := i+1;  end  while i<= 20  end  fig 7: program to compute dot product
  • 10. Let us apply Algorithm 1 to the three-address code in fig 8 to determine its basic blocks. statement (1) is a leader by rule (I) and statement (3) is a leader by rule (II), since the last statement can jump to it. By rule (III) the statement following (12) is a leader. Therefore, statements (1) and (2) form a basic block. The remainder of the program beginning with statement (3) forms a second basic block.   (1) prod := 0  (2) i := 1  (3) t1 := 4*i  (4) t2 := a [ t1 ]  (5) t3 := 4*i  (6) t4 :=b [ t3 ]  (7) t5 := t2*t4  (8) t6 := prod +t5  (9) prod := t6  (10) t7 := i+1  (11) i := t7  (12) if i<=20 goto (3)   fig 8. Three-address code computing dot product
  • 11. PROD :=0 • B1 I := 1 T1:=4*I T2:=addr(A)-4 • T3:=T2[T1]B2 T4:=addr(B)-4 T5:=T4[T1] T6:=T3*T5 Prod:=PROD + T6 I:=I+1 If I<20 goto (3)