+ All Categories
Home > Documents > Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

Date post: 06-Apr-2018
Category:
Upload: white909
View: 217 times
Download: 0 times
Share this document with a friend

of 200

Transcript
  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    1/200

    1 Wolf Zimmermann

    On the Correctness of

    Transformations inCompiler Back-Ends

    Wolf Zimmermann

    Universitat Halle

    Joint work with the Verifix Teams in Karlsruhe, Kiel, and Ulm

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    2/200

    1. Motivation

    2 Wolf Zimmermann

    program

    Processor

    Compiler

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    3/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    correct program

    (w.r.t. a specification)

    Program verification

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    4/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    correct

    Hardware verification

    program

    (w.r.t. a specification)

    Program verification

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    5/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    6/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    7/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

    u Borland Pascal Compiler Bug List

    contains ca. 50 compiler errorsu Java Compiler Bug Database from Sun

    contains ca. 90 compiler errors

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    8/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

    u Borland Pascal Compiler Bug List

    contains ca. 50 compiler errorsu Java Compiler Bug Database from Sun

    contains ca. 90 compiler errors

    Goal of Verifix: Construction of Correct Compilers

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    9/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

    u Borland Pascal Compiler Bug List

    contains ca. 50 compiler errorsu Java Compiler Bug Database from Sun

    contains ca. 90 compiler errors

    Goal of Verifix: Construction of Correct Compilersu Programming languages in commercial use

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    10/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

    u Borland Pascal Compiler Bug List

    contains ca. 50 compiler errorsu Java Compiler Bug Database from Sun

    contains ca. 90 compiler errors

    Goal of Verifix: Construction of Correct Compilersu Programming languages in commercial useu Machine language of commercially available processor families

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    11/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

    u Borland Pascal Compiler Bug List

    contains ca. 50 compiler errorsu Java Compiler Bug Database from Sun

    contains ca. 90 compiler errors

    Goal of Verifix: Construction of Correct Compilersu Programming languages in commercial useu Machine language of commercially available processor familiesu efficiency of generated code comparable with code generated by unverified

    compilers

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    12/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

    u Borland Pascal Compiler Bug List

    contains ca. 50 compiler errorsu Java Compiler Bug Database from Sun

    contains ca. 90 compiler errors

    Goal of Verifix: Construction of Correct Compilersu Programming languages in commercial useu Machine language of commercially available processor familiesu efficiency of generated code comparable with code generated by unverified

    compilers

    Idea: Use well-established compiler technology

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    13/200

    1. Motivation

    2 Wolf Zimmermann

    Processor

    Compiler

    Program verification

    (w.r.t. a specification)

    Hardware verification

    programcorrect

    ?

    Compiler Bugs:

    u Borland Pascal Compiler Bug List

    contains ca. 50 compiler errorsu Java Compiler Bug Database from Sun

    contains ca. 90 compiler errors

    Goal of Verifix: Construction of Correct Compilersu Programming languages in commercial useu Machine language of commercially available processor familiesu efficiency of generated code comparable with code generated by unverified

    compilers

    Idea: Use well-established compiler technologyHere: Back-Ends

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    14/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    15/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    16/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    17/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

    Preservation of observable behaviour I/O-behaviour of a compiled program im-plements an I/O-behaviour of the corresponding source program

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    18/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

    Preservation of observable behaviour I/O-behaviour of a compiled program im-plements an I/O-behaviour of the corresponding source programu Memory overflows, time overflows, arithmetic overflows?

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    19/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

    Preservation of observable behaviour I/O-behaviour of a compiled program im-plements an I/O-behaviour of the corresponding source programu Memory overflows, time overflows, arithmetic overflows?

    Preservation of observable behaviour upto resource limitations Violation ofresource limitations is allowed

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    20/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

    Preservation of observable behaviour I/O-behaviour of a compiled program im-plements an I/O-behaviour of the corresponding source programu Memory overflows, time overflows, arithmetic overflows?

    Preservation of observable behaviour upto resource limitations Violation ofresource limitations is allowed

    u Every program SL compiles into program TL such that preserves the observable behaviour of upto resource limitations

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    21/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

    Preservation of observable behaviour I/O-behaviour of a compiled program im-plements an I/O-behaviour of the corresponding source programu Memory overflows, time overflows, arithmetic overflows?

    Preservation of observable behaviour upto resource limitations Violation ofresource limitations is allowed

    u Every program SL compiles into program TL such that preserves the observable behaviour of upto resource limitationsr

    compilation of programs with more than 1 000 000 000 000 000 lines ofcode?

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    22/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

    Preservation of observable behaviour I/O-behaviour of a compiled program im-plements an I/O-behaviour of the corresponding source programu Memory overflows, time overflows, arithmetic overflows?

    Preservation of observable behaviour upto resource limitations Violation ofresource limitations is allowed

    u Every program SL compiles into program TL such that preserves the observable behaviour of upto resource limitationsr

    compilation of programs with more than 1 000 000 000 000 000 lines ofcode? Almost all programs cannot be compiled

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    23/200

    2. A Practical Notion of Correctness

    3 Wolf Zimmermann

    Refinement based: refines the semantics of a language construct traditional approach

    u Many optimizations are illegal

    Preservation of observable behaviour I/O-behaviour of a compiled program im-plements an I/O-behaviour of the corresponding source programu Memory overflows, time overflows, arithmetic overflows?

    Preservation of observable behaviour upto resource limitations Violation ofresource limitations is allowed

    u Every program SL compiles into program TL such that preserves the observable behaviour of upto resource limitationsr

    compilation of programs with more than 1 000 000 000 000 000 lines ofcode? Almost all programs cannot be compiledu Compiler C : SL TL is correct iffr For every program SL that is compiled into a program TL,r preserves the observable behaviour of upto resource limitations

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    24/200

    3. Proving the Correctness of a Compiler

    4 Wolf Zimmermann

    intermediate code

    target code as graph

    attributed syntax tree

    target program as binary code

    source program

    Front End Generator

    Generator

    Generator

    attribute grammar

    Com

    pilingSpecification

    im

    plementationinhigh

    levelprogramminglanguage

    implementationasbinarycode

    LALR(1)grammar

    abstract syntax

    graph rewriting rules

    term rewriting rules

    intermediate code

    generation

    code generation

    assembly

    Compiler Compiler

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    25/200

    3. Proving the Correctness of a Compiler

    4 Wolf Zimmermann

    source program

    attributed syntax tree

    target program as binary code

    target code as graph

    intermediate code

    This Talk

    This Talk

    Front End Generator

    Generator

    Generator

    attribute grammar

    Com

    pilingSpecification

    im

    plementationinhigh

    levelprogramminglanguage

    intermediate code

    generation

    implementationasbinarycode

    LALR(1)grammar

    abstract syntax

    graph rewriting rules

    term rewriting rulescode generation

    assembly

    Compiler Compiler

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    26/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    27/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

    u Same specification technique for all levels of

    programming languages used in compilers

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    28/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

    u Same specification technique for all levels of

    programming languages used in compilers

    u Proof techniques

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    29/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

    u Same specification technique for all levels of

    programming languages used in compilers

    u Proof techniques

    u Formal definition of static parts of programming languages such

    as arithmetic, data types, addresses etc.

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    30/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

    u Same specification technique for all levels of

    programming languages used in compilers

    u Proof techniques

    u Formal definition of static parts of programming languages such

    as arithmetic, data types, addresses etc.

    Verifix:

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    31/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

    u Same specification technique for all levels of

    programming languages used in compilers

    u Proof techniques

    u Formal definition of static parts of programming languages such

    as arithmetic, data types, addresses etc.

    Verifix:

    u Operational semantics

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    32/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

    u Same specification technique for all levels of

    programming languages used in compilers

    u Proof techniques

    u Formal definition of static parts of programming languages such

    as arithmetic, data types, addresses etc.

    Verifix:

    u Operational semantics

    u States describe algebras

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    33/200

    4. Semantics and Abstract State Machines

    5 Wolf Zimmermann

    Requirements: on programming language semantics

    u Same specification technique for all levels of

    programming languages used in compilers

    u Proof techniques

    u Formal definition of static parts of programming languages such

    as arithmetic, data types, addresses etc.

    Verifix:

    u Operational semantics

    u States describe algebras

    Abstract state machines

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    34/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    35/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUAD

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    36/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    37/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    38/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    39/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    40/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    41/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    42/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    43/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

    ifpc is ADDQ thenreg(rc) := reg(ra) Q reg(rb)Proceed

    endif

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    44/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

    ifpc is ADDQ thenreg(rc) := reg(ra) Q reg(rb)Proceed

    endififpc is ADDI then

    reg(rc) := reg(ra) Q SExt16(immed(pc))Proceed

    endif

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    45/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

    ifpc is ADDQ thenreg(rc) := reg(ra) Q reg(rb)Proceed

    endififpc is ADDI then

    reg(rc) := reg(ra) Q SExt16(immed(pc))Proceed

    endififpc is LDQ then

    reg(ra) := mem(reg(rb) SExt16(disp))Proceed

    endififpc is LDA then

    reg(ra) := reg(rb) SExt16(disp)Proceed

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    46/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0

    ...mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

    ifpc is ADDQ thenreg(rc) := reg(ra) Q reg(rb)Proceed

    endififpc is ADDI then

    reg(rc) := reg(ra) Q SExt16(immed(pc))Proceed

    endififpc is LDQ then

    reg(ra) := mem(reg(rb) SExt16(disp))Proceed

    endififpc is LDA then

    reg(ra) := reg(rb) SExt16(disp)Proceed

    endif

    ifpc is LDAH thenreg(ra) := reg(rb) LogShift(SExt16(disp), 16))Proceed

    endif

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    47/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0.

    ..mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

    ifpc is ADDQ thenreg(rc) := reg(ra) Q reg(rb)Proceed

    endififpc is ADDI then

    reg(rc) := reg(ra) Q SExt16(immed(pc))Proceed

    endififpc is LDQ then

    reg(ra) := mem(reg(rb) SExt16(disp))Proceed

    endififpc is LDA then

    reg(ra) := reg(rb) SExt16(disp)Proceed

    endif

    ifpc is LDAH thenreg(ra) := reg(rb) LogShift(SExt16(disp), 16))Proceed

    endififpc is STQ then

    mem(reg(rb) SExt16(disp)) := reg(ra)Proceed

    endif

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    48/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0.

    ..mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

    ifpc is ADDQ thenreg(rc) := reg(ra) Q reg(rb)Proceed

    endififpc is ADDI then

    reg(rc) := reg(ra) Q SExt16(immed(pc))Proceed

    endififpc is LDQ then

    reg(ra) := mem(reg(rb) SExt16(disp))Proceed

    endififpc is LDA then

    reg(ra) := reg(rb) SExt16(disp)Proceed

    endif

    ifpc is LDAH thenreg(ra) := reg(rb) LogShift(SExt16(disp), 16))Proceed

    endififpc is STQ then

    mem(reg(rb) SExt16(disp)) := reg(ra)Proceed

    endififpc is ZAP then

    reg(rc) := zerobytes(reg(ra), imbyte(pc))Proceed

    endif

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    49/200

    Example: DEC-Alpha Machine Language Semantics

    6 Wolf Zimmermann

    State Space and Macros:reg : RADDR QUADfreg : RADDR QUAD

    mem : QUAD BYTEpc : QUADAuxiliary Functions:opcode : LONG OPCODE opcoderega : LONG ?RADDR register atype : LONG ?TFCODE operation typeimmed : LONG ?WORD constant operanddisp : LONG ?WORD const. relative addressimbyte : LONG ?BYTE byte in ZAP-instr.

    mem(a) concat([mem(a), . . . , mem(a Q 7)])mem(a) := q mem(a) := split8(q)0.

    ..mem(a Q 7) := split8(q)7pc is ADD

    opcode(pc) = 010000pc is ADDQ pc is ADD

    type(pc) = 00000100000Proceed pc := pc Q 4ra rega(pc)

    State Transitions:

    ifpc is ADDQ thenreg(rc) := reg(ra) Q reg(rb)Proceed

    endififpc is ADDI then

    reg(rc) := reg(ra) Q SExt16(immed(pc))Proceed

    endififpc is LDQ then

    reg(ra) := mem(reg(rb) SExt16(disp))Proceed

    endififpc is LDA then

    reg(ra) := reg(rb) SExt16(disp)Proceed

    endif

    ifpc is LDAH thenreg(ra) := reg(rb) LogShift(SExt16(disp), 16))Proceed

    endififpc is STQ then

    mem(reg(rb) SExt16(disp)) := reg(ra)Proceed

    endififpc is ZAP then

    reg(rc) := zerobytes(reg(ra), imbyte(pc))Proceed

    endififpc is BR then

    reg(ra) := pc 4pc := pc Q 4 Q LogShift(SExt21(disp, 2))

    endif

    G

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    50/200

    Example: Basic Block Graphs

    7 Wolf Zimmermann

    base:ADDR sp:ADDR hp:ADDR

    VALUEmem:ADDR

    ip:LABELNN

    l: instr0

    instrk

    instrn

    E l B i Bl k G h

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    51/200

    Example: Basic Block Graphs

    7 Wolf Zimmermann

    base:ADDR sp:ADDR hp:ADDR

    VALUEmem:ADDR

    ip:LABELNN

    l: instr0

    instrk

    instrn

    eval : EXPR VALUEeval(int

    ck) = SExt

    k(c)

    eval(addrck) = base A SExtk(c)eval(ldI(x)) = mem(eval(x))eval(ldA(x)) = mem(eval(x))eval(x +I y) = eval(x) I eval(y)eval(x +A y) = eval(x) A eval(y)I, A is integer/addressaddition on the target machine

    E l B i Bl k G h

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    52/200

    Example: Basic Block Graphs

    7 Wolf Zimmermann

    base:ADDR sp:ADDR hp:ADDR

    VALUEmem:ADDR

    ip:LABELNN

    l: instr0

    instrk

    instrn

    eval : EXPR VALUEeval(int

    ck) = SExt

    k(c)

    eval(addrck) = base A SExtk(c)eval(ldI(x)) = mem(eval(x))eval(ldA(x)) = mem(eval(x))eval(x +I y) = eval(x) I eval(y)eval(x +A y) = eval(x) A eval(y)I, A is integer/addressaddition on the target machineinstr((l, k)) = lab1(l)k

    E l B i Bl k G h

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    53/200

    Example: Basic Block Graphs

    7 Wolf Zimmermann

    base:ADDR sp:ADDR hp:ADDR

    VALUEmem:ADDR

    ip:LABELNN

    l: instr0

    instrk

    instrn

    eval : EXPR VALUEeval(intck) = SExtk(c)

    eval(addrck) = base A SExtk(c)eval(ldI(x)) = mem(eval(x))eval(ldA(x)) = mem(eval(x))eval(x +I y) = eval(x) I eval(y)eval(x +A y) = eval(x) A eval(y)I, A is integer/addressaddition on the target machineinstr((l, k)) = lab1(l)k

    if ip is ASSIGN thenmem(eval(lhs(ip))) := eval(rhs(ip))Proceed

    endif

    E l B i Bl k G h

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    54/200

    Example: Basic Block Graphs

    7 Wolf Zimmermann

    base:ADDR sp:ADDR hp:ADDR

    VALUEmem:ADDR

    ip:LABELNN

    l: instr0

    instrk

    instrn

    eval : EXPR VALUEeval(intck) = SExtk(c)

    eval(addrck) = base A SExtk(c)eval(ldI(x)) = mem(eval(x))eval(ldA(x)) = mem(eval(x))eval(x +I y) = eval(x) I eval(y)eval(x +A y) = eval(x) A eval(y)I, A is integer/addressaddition on the target machineinstr((l, k)) = lab1(l)k

    if ip is ASSIGN thenmem(eval(lhs(ip))) := eval(rhs(ip))Proceed

    endifif ip is JMP thenip := (target(ip), 0)

    endif

    E l B i Bl k G h

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    55/200

    Example: Basic Block Graphs

    7 Wolf Zimmermann

    base:ADDR sp:ADDR hp:ADDR

    VALUEmem:ADDR

    ip:LABELNN

    l: instr0

    instrk

    instrn

    eval : EXPR VALUEeval(intck) = SExtk(c)

    eval(addrck) = base A SExtk(c)eval(ldI(x)) = mem(eval(x))eval(ldA(x)) = mem(eval(x))eval(x +I y) = eval(x) I eval(y)eval(x +A y) = eval(x) A eval(y)I, A is integer/addressaddition on the target machineinstr((l, k)) = lab1(l)k

    if ip is ASSIGN thenmem(eval(lhs(ip))) := eval(rhs(ip))Proceed

    endifif ip is JMP thenip := (target(ip), 0)

    endif

    Macros:ip is T instr(ip) TProceed ip := (ip

    1, ip

    2+1)

    5 C d G ti b T R iti

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    56/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    5 C d G ti b T R iti

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    57/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    5 C d G ti b T R iti

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    58/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:

    5 Code Generation b Term Re riting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    59/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1

    5 Code Generation by Term Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    60/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    5 Code Generation by Term Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    61/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3

    5 Code Generation by Term Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    62/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    5 Code Generation by Term Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    63/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    ld

    :=I

    +

    addr28 :=I ldI(addr28) +I int1

    5 Code Generation by Term Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    64/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    R2

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1

    5 Code Generation by Term Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    65/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    R2

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2

    5 Code Generation by Term Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    66/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    R2

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30

    5 Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    67/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    R2

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1

    5 Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    68/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    R2

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2

    5 Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    69/200

    5. Code Generation by Term-Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    R2

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2

    5 Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    70/200

    5. Code Generation by Term Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    addr28

    int1

    addr28

    I

    I

    R2

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2 ADDIR2, #1, R2

    5 Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    71/200

    5. Code Generation by Term Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    Rule 2

    ld

    addr28

    R2

    R2

    addr +I

    Iint

    28

    1

    :=I

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2 ADDIR2, #1, R2addr28 :=I R2

    5. Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    72/200

    5. Code Generation by Term Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    Rule 2

    ld

    addr28

    R2

    R2

    addr +I

    Iint

    28

    1

    :=I

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2 ADDIR2, #1, R2addr28 :=I R2 (4)X = R2

    5. Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    73/200

    5. Code Generation by Term Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    Rule 2

    ld

    addr28

    R2

    R2

    addr +I

    Iint

    28

    1

    :=I

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2 ADDIR2, #1, R2addr28 :=I R2 (4)X = R2 STQ R2, (28)R30

    5. Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    74/200

    5. Code Generation by Term Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    Rule 2

    ld

    addr28

    R2

    R2

    addr +I

    Iint

    28

    1

    :=I

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2 ADDIR2, #1, R2addr28 :=I R2 (4)X = R2 STQ R2, (28)R30

    5. Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    75/200

    5. Code Generation by Term Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    Rule 2

    Rule 4

    int

    28addr

    R2

    I

    I

    addr

    1

    28

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2 ADDIR2, #1, R2addr28 :=I R2 (4)X = R2 STQ R2, (28)R30

    5. Code Generation by Term-Rewriting

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    76/200

    5. Code Generation by Term Rewriting

    8 Wolf Zimmermann

    Code Selection by Term-Rewrite Rules:

    t X {m1, . . . , mn} intermediate language expressions

    t {m1, . . . , mn} intermediate language instructionsm1, . . . , mn are machine instructionsregister assignment associates X with a machine register

    Example:ldI(c16) X {LDQ X, (c16)R31} Rule 1X +I intc16 Z {ADDI X, #c16, Z} Rule 2

    intc32 X {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X} Rule 3addrc16 :=I Y {STQ Y, (c16)R30} Rule 4

    Rule 1

    Rule 2

    Rule 4

    int

    28addr

    R2

    I

    I

    addr

    1

    28

    :=I

    +

    ld

    R2

    addr28 :=I ldI(addr28) +I int1(1) X = R2 LDQ R2, (28)R30addr28 :=I R2 +I int1 (2)X = R2 Z = R2 ADDIR2, #1, R2addr28 :=I R2 (4)X = R2 STQ R2, (28)R30

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    77/200

    6 Local and Global Correctness

    9 Wolf Zimmermann

    Simulation Proofs:

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    78/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    79/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    80/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    81/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    82/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    83/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    84/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    85/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    I/O

    I/O

    I/O

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    86/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    I/O

    I/O

    I/O

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    87/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    I/O

    I/O

    I/O

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    88/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    I/O

    I/O

    I/O

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    89/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    I/O

    I/O

    I/O

    Local Correctness:

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    90/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    I/O

    I/O

    I/O

    Local Correctness:

    1)ra(m )

    ra(m instr[ra(X)]

    instr[t]

    n0

    q1

    q n+1q1q nqn1

    q0

    q

    Rule t X{m1, . . . , mn}

    6. Local and Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    91/200

    9 Wolf Zimmermann

    Simulation Proofs:

    observable

    abstraction

    observable

    abstraction

    I/O

    I/O

    I/O

    I/O

    Local Correctness:

    1)ra(m )

    ra(m instr[ra(X)]

    instr[t]

    n0

    q1

    q n+1q1q nqn1

    q0

    q

    Rule t X{m1, . . . , mn}

    1)ra(m

    t

    ra(m

    )n qn

    1q

    1q0

    q0

    qn1q

    Rule t {m1, . . . , mn}

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    92/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    93/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    94/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selection

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    95/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    96/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct andu for every rule t X{m1; . . . ; mn} register ra(X) does not contain a live

    value.

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    97/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct andu for every rule t X{m1; . . . ; mn} register ra(X) does not contain a live

    value.Then, every target program that can be obtained from a source program usingT preserve the observable behaviour of upto resource constraints

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    98/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct andu for every rule t X{m1; . . . ; mn} register ra(X) does not contain a live

    value.Then, every target program that can be obtained from a source program usingT preserve the observable behaviour of upto resource constraints

    Discussion:

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    99/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct andu for every rule t X{m1; . . . ; mn} register ra(X) does not contain a live

    value.Then, every target program that can be obtained from a source program usingT preserve the observable behaviour of upto resource constraints

    Discussion:

    u No specific assumption on intermediate languages except basic block graphs

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    100/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct andu for every rule t X{m1; . . . ; mn} register ra(X) does not contain a live

    value.Then, every target program that can be obtained from a source program usingT preserve the observable behaviour of upto resource constraints

    Discussion:

    u No specific assumption on intermediate languages except basic block graphsu No specific assumption on processor assembly languages except register

    machines

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    101/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct andu for every rule t X{m1; . . . ; mn} register ra(X) does not contain a live

    value.Then, every target program that can be obtained from a source program usingT preserve the observable behaviour of upto resource constraints

    Discussion:

    u No specific assumption on intermediate languages except basic block graphsu No specific assumption on processor assembly languages except register

    machinesu No specific assumption on term-rewrite rules

    Global Correctness

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    102/200

    10 Wolf Zimmermann

    Global Correctness Single simulations stemming from program transformationsare sequentially composable to simulations

    Global Correctness Theorem: (JUCS1997)u Let T be a set of term-rewrite rules specifying code selectionu Suppose each rule of T is locally correct andu for every rule t X{m1; . . . ; mn} register ra(X) does not contain a live

    value.Then, every target program that can be obtained from a source program usingT preserve the observable behaviour of upto resource constraints

    Discussion:

    u No specific assumption on intermediate languages except basic block graphsu No specific assumption on processor assembly languages except register

    machinesu No specific assumption on term-rewrite rules

    Specific compilers require only local correctness proofs

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    103/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rules

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    104/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossible

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    105/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    106/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    107/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    108/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    109/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mn

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    110/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mnr Check whether reg(X) = eval(t)

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    111/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mnr Check whether reg(X) = eval(t)u Rules t {m1; . . . ; mn}:

    7. Local Correctness Proofs

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    112/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mnr Check whether reg(X) = eval(t)u Rules t {m1; . . . ; mn}:r Symbolically compose state transitions associated with m1; . . . ; mn into

    single state transition

    7. Local Correctness Proofs

    P bl R l l b k d f h h l

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    113/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mnr Check whether reg(X) = eval(t)u Rules t {m1; . . . ; mn}:r Symbolically compose state transitions associated with m1; . . . ; mn into

    single state transitionr Compare this with the state transition associated with t

    7. Local Correctness Proofs

    P bl R l il b k d f h h 2000 i l

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    114/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mnr Check whether reg(X) = eval(t)u Rules t {m1; . . . ; mn}:r Symbolically compose state transitions associated with m1; . . . ; mn into

    single state transitionr Compare this with the state transition associated with t

    Observations:

    7. Local Correctness Proofs

    P bl R l il b k d f h h 2000 i l

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    115/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mnr Check whether reg(X) = eval(t)

    u Rules t {m1; . . . ; mn}:r Symbolically compose state transitions associated with m1; . . . ; mn into

    single state transitionr Compare this with the state transition associated with t

    Observations:

    u Proof strategies are complete for expressions and instructions

    7. Local Correctness Proofs

    P bl R l il b k d f h h 2000 i l

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    116/200

    11 Wolf Zimmermann

    Problem: Real compiler back-ends often have more than 2000 term-rewrite rulesu Manual proofs are impossibleu Machine proofs must be readable

    Proof Strategies:

    u Rules t X{m1; . . . ; mn}:r Compute symbolically eval(t)r Symbolically execute state transitions associated with m1; . . . ; mnr Check whether reg(X) = eval(t)

    u Rules t {m1; . . . ; mn}:r Symbolically compose state transitions associated with m1; . . . ; mn into

    single state transitionr Compare this with the state transition associated with t

    Observations:

    u Proof strategies are complete for expressions and instructionsu Proof strategies can be easily mechanized using simplification mechanisms

    Examples

    E l 32 X {LDA X ( 32 L)R31 ZAP X #f X LDAH X ( 32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    117/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}

    Examples

    E l 32 X {LDA X ( 32 L)R31 ZAP X #f X LDAH X ( 32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    118/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    Examples

    E l 32 X {LDA X ( 32 L)R31 ZAP X #f X LDAH X ( 32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    119/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =?

    Examples

    E l 32 X {LDA X ( 32 L)R31 ZAP X #f X LDAH X ( 32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    120/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31

    Examples

    Example: 32 X {LDA X ( 32 L)R31 ZAP X #fc X LDAH X ( 32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    121/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    122/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0]

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    123/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    124/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    125/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0]

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    126/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    127/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    128/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    129/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Example: addrc16 :=I Y {STQ Y, (c16)R30}

    Examples

    Example: c32 X; {LDA X (c32 L)R31; ZAP X #fc X; LDAH X (c32 H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    130/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Example: addrc16 :=I Y {STQ Y, (c16)R30}u State transition for addrc16 :=I Y:

    Examples

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    131/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times, b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Example: addrc16 :=I Y {STQ Y, (c16)R30}u State transition for addrc16 :=I Y:

    mem(eval(addrc16)) := eval(rg(Y))

    Examples

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    132/200

    12 Wolf Zimmermann

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times, b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Example: addrc16 :=I Y {STQ Y, (c16)R30}u State transition for addrc16 :=I Y:

    mem(eval(addrc16)) := eval(rg(Y)) = mem(base SExt16(c16)) := reg(Y)

    Examples

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    133/200

    12 Wolf Zimmermann

    Example: c3 X; { X, (c3 L)R3 ; X, # c, X; X, (c3 H)X}u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z }

    48 times, b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Example: addrc16 :=I Y {STQ Y, (c16)R30}u State transition for addrc16 :=I Y:

    mem(eval(addrc16)) := eval(rg(Y)) = mem(base SExt16(c16)) := reg(Y)= mem(reg(R30) SExt16(c16)) := reg(Y)

    Examples

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    134/200

    12 Wolf Zimmermann

    p ; { , ( ) ; , # , ; , ( ) }u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z } 48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Example: addrc16 :=I Y {STQ Y, (c16)R30}u State transition for addrc16 :=I Y:

    mem(eval(addrc16)) := eval(rg(Y)) = mem(base SExt16(c16)) := reg(Y)= mem(reg(R30) SExt16(c16)) := reg(Y)

    u State transition for STQ Y, (c16)R30:

    Examples

    Example: c32 X; {LDA X, (c32.L)R31; ZAP X, #fc, X; LDAH X, (c32.H)X}

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    135/200

    12 Wolf Zimmermann

    p ; { , ( ) ; , # , ; , ( ) }u eval(intc32) = SExt32(c32)

    reg(X) =? LDA X, (c32.L)R31 reg(X) := reg(X) SExt16(c32.L)

    reg(X) = [b15, . . . , b15 | { z } 48 times

    , b15, . . . , b0] ZAP X, #fc, X reg(X) := zerobytes(reg(X), #fc)

    reg(X) = [0, . . . , 0 | { z }

    48 times

    , b15, . . . , b0] LDAH X, (c32.H)X reg(X) := reg(X)

    LShft(SExt16(c32.H), 16)

    reg(X) = [b31, . . . , b31 | { z }

    32 times

    , b31, . . . , b0] = SExt32(c32)

    Example: addrc16 :=I Y {STQ Y, (c16)R30}u State transition for addrc16 :=I Y:

    mem(eval(addrc16)) := eval(rg(Y)) = mem(base SExt16(c16)) := reg(Y)= mem(reg(R30) SExt16(c16)) := reg(Y)

    u State transition for STQ Y, (c16)R30:

    mem(reg(R30) SExt16(c16)) := reg(Y)

    Skip assembly

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    136/200

    13 Wolf Zimmermann

    p

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    137/200

    13 Wolf Zimmermann

    u Binary Format except jumps

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    138/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    139/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    140/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    141/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    No jump necessary

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    142/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    No jump necessary

    a+c:

    a:JMP bb2

    1

    bb

    bb1

    2

    2

    JMP c

    bb

    bb

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    143/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    No jump necessary

    a+c:

    a:JMP bb2

    1

    bb

    bb1

    2

    2

    JMP c

    bb

    bb

    Relative distance small

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructions

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    144/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    No jump necessary

    a+c:

    a:JMP bb2

    1

    bb

    bb1

    2

    2

    JMP c

    bb

    bb

    Relative distance small

    Relative address cannot beencoded in instruction

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructionsu Bi F j

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    145/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    No jump necessary

    a+c:

    a:JMP bb2

    1

    bb

    bb1

    2

    2

    JMP c

    bb

    bb

    Relative distance small

    Relative address cannot beencoded in instruction

    a:

    a:

    JMP bb2Instructions

    for computing a

    JMP R

    bb1

    bb2

    bb1

    bb2

    stored in R

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructionsu Bi F j

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    146/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    No jump necessary

    a+c:

    a:JMP bb2

    1

    bb

    bb1

    2

    2

    JMP c

    bb

    bb

    Relative distance small

    Relative address cannot beencoded in instruction

    a:

    a:

    JMP bb2Instructions

    for computing a

    JMP R

    bb1

    bb2

    bb1

    bb2

    stored in R

    Relative distance large

    7. Assembly

    After Code Selection: Basic Block Graph with Machine Instructionsu Bi F j

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    147/200

    13 Wolf Zimmermann

    u Binary Format except jumps Linearize basic block graphs and map jumps

    Mapping Jumps: Labels are mapped to jump targets

    bb2

    bb

    2

    2bb

    1bb

    JMP bb

    1

    No jump necessary

    a+c:

    a:JMP bb2

    1

    bb

    bb1

    2

    2

    JMP c

    bb

    bb

    Relative distance small

    Relative address cannot beencoded in instruction

    a:

    a:

    JMP bb2Instructions

    for computing a

    JMP R

    bb1

    bb2

    bb1

    bb2

    stored in R

    Relative distance largeAbsolute address of jumptarget must be computedin a register

    Example: DEC-Alpha

    Term-Rewrite Rules: Lett is the address of the jump instruction

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    148/200

    14 Wolf Zimmermann

    current is the address of the jump instruction,

    Example: DEC-Alpha

    Term-Rewrite Rules: Letcurrent is the address of the jump instruction

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    149/200

    14 Wolf Zimmermann

    current is the address of the jump instruction,addrbb(L) is the address of the first instruction of basic block with label L

    Example: DEC-Alpha

    Term-Rewrite Rules: Letcurrent is the address of the jump instruction

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformations in Compiler Back-Ends

    150/200

    14 Wolf Zimmermann

    current is the address of the jump instruction,addrbb(L) is the address of the first instruction of basic block with label L

    l = addrbb(L) current,

    Example: DEC-Alpha

    Term-Rewrite Rules: Letcurrent is the address of the jump instruction

  • 8/3/2019 Wolf Zimmermann- On the Correctness of Transformation


Recommended