Shared Flashcard Set

Details

Comp2010 - Flashcard Set 8 - Code Generation I: Intermediate
Comp2010 - Flashcard Set 8 - Code Generation I: Intermediate Code
16
Computer Science
Undergraduate 2
05/28/2013

Additional Computer Science Flashcards

 


 

Cards

Term
What is an intermediate representation?
Definition
  • Abstract machine language
  • Separates front-end and back-end considerations
  • Enhances modularity and portability
  • Convenient for front-end to generate
  • Convenient to translate to real machine code
  • Simple, straightforward, fairly low-level
Term
What is Zero-Address code?
Definition
  • Abstract code for a stack machine:
    • Store operands on stack (LDC, LOAD, ...)
    • Take operands form stack, process,
      • Store result on stack (ADD, SUB, ...)
      • Move to memory (Store, ...)
Term
How can transforming expressions be achieved?
Definition

Trivial:

  • ...
  • void translate() {
    • left.translate(); right.translate();
    • switch(op) {
    • case PLUS:
      • emit0(Add); break;
    • case MINUS:
      • ...

 

Term
What are some examples of three-address code?
Definition

(MULT, 2, a)

(SUB, b, 3)

Term
How is translating control structures possible?
Definition
  • Need to add more IR operations:
    • Function call/ret
    • Conditional branch
    • Unconditional branch
    • May introduce others, e.g. switch statement
  • Define code templates for high-level control structures
Term
What are the expressions in IR trees in Appel's book?
Definition
  • CONST(i) 
  • TEMP(t)
  • MEM(a)
  • BINOP(op, e1, e2)
  • CALL(f, l) - call function f with arg list l
  • ESEQ(s,e) - evaluate s (for side efects only), evaluate e and return as result
Term
What are the statements in IR trees in Appel's book?
Definition
  • MOVE(dst, src)
  • JUMP(l)
  • JUMP(e,label) - evaluate e, jump to label
  • SEQ(s1, s2) - sequencing s1 followed by s2
  • LABEL(n) - define label n at current position
  • NAME(n) - label n
  • CJUMP(op, e1, e2, t, f) - evaluate (e1 op e2), jump to correspoding label t or f
Term
What are some principles of Registers and Temporaries?
Definition
  • Target architecture uses finite set of registers to hold operands
    • Register-only operations much faster
  • IR uses TEMPs:
    • Assume infinitely many available
    • Register allocation phase will map to actual registers
    • Register spilling(i.e. move to memory) when not enough registers)
  • Goal: store local variables and temporary values in registers where possible
  • CAVEAT: some variables must be allocated in memory(excaping)
Term
What is escaping and spilling?
Definition
  • Escaping: variables must be stored in memory if...
    • They are passed by reference
    • Their address is taken
      • Using &operator in C
      • Accessed by address arithmetic (e.g. arrays
    • They are accessed from a nested function
  • Spilling: Variables must be moved to memory if...
    • Their register is required for a specific purpose
      • Parameter passing
      • Special operations (e.g. floating point arithmetics)
    • There are not enough registers
Term
What happens if a variable escapes?
Definition
  • The variable needs to be stored in stack frame
  • Needs to be addresed via frame pointer
Term
How are Static links handled?
Definition
  • Static links are handled as normal variable in frame
  • To be accessed you need to add ksl(offset of static link in frame) to the frame pointer.
Term
What is the schema for Array access in IR?
Definition
  • Evaluate index: a[j]=a[ j + 1 ];
  • Multiply by element size: a array of int
  • Add base address: a[j]
Term
How do IR trees handle control structures?
Definition
  • Complex control expressions are compiled into SEQuences of CJUMPs:

[image]

 

Term
What are the principles of canonical IR trees?
Definition
  • Some aspects of translated tree complicate later stages of code generation process, e.g.
    • ESEQ within expressions: order of evaluation of subtrees matters
    • CJUMP has two destination labels, real machines' equivalent has only one
    • ...so transform tree to eliminate awkward cases:
      • remove ESEQs, move SEQs to top level
      • Rearrange code so CJUMP always followed immediately by its false label
Term
How can blocks be implemented?
Definition
  • Single-entry, single-exit, straight-line sequences:
    • Always entered at begining and exited at end
    • First statement is LABEL
    • last statement is JUMP or CJUMP
    • No other LABELs, JUMPs, or CJUMPs
  • To partition program into basic blocks, scan sequentially:
    • if LABEL found, start new block
    • add JUMP at end of previous block if necessary
    • if JUMP or CJUMP found, end block
    • add LABEL at start of new block if necessary
Term
What are the principles of code reordering?
Definition
  • Basic blocks can be reordered without affecting results of execution
    • All control flow is made explicit by jumps
  • Group blocks into traces to maximize sequential execution sequences
    • If block bi ends with JUMP to block bj, and bj not yet used, follow bi by bj
    • If block bi ends with CJUMP to block bj or bk, follow with bk if possible, otherwise bj
  • Followed by tidying-up phase to remove useless JUMP and CJUMP instructions
Supporting users have an ad free experience!