IU-Fall-2021

Course web page for Fall 2021.

View the Project on GitHub IUCompilerCourse/IU-Fall-2021

Lecture: Tuples continued

select-instructions

Here is where we implement the new operations needed for tuples.

example: block9056

allocate-registers

prelude-and-conclusion

Example

Source program:

(vector-ref (vector 42) 0)

print( (42,)[0] )

expose allocation:

(vector-ref T 0)

where T is

(let ([_ (if (< (+ (global-value free_ptr) 16) 
                (global-value fromspace_end))
             (void)
             (collect 16))])
   (let ([alloc5 (allocate 1 (Vector Integer))])
      (let ([_6 (vector-set! alloc5 0 42)])
         alloc5)))

remove complex operands:

(let ([_ (if (let ([tmp8 (global-value free_ptr)])
                     (let ([tmp9 (+ tmp8 16)])
                        (let ([tmp46150 (global-value fromspace_end)])
                           (< tmp9 tmp46150))))
                 (void)
                 (collect 16))])
   (let ([alloc5 (allocate 1 (Vector Integer))])
      (let ([_6 (vector-set! alloc5 0 42)])
         (vector-ref alloc5 0))))

explicate control:

start:
	tmp8 = (global-value free_ptr);
	tmp9 = (+ tmp8 16);
	tmp46150 = (global-value fromspace_end);
	if (< tmp9 tmp46150)
	   goto block46152;
	else
	   goto block46153;
block46152:
	_ = (void);
	goto block46151;
block46153:
	(collect 16)
	goto block46151;
block46151:
	alloc5 = (allocate 1 (Vector Integer));
	_6 = (vector-set! alloc5 0 42);
	return (vector-ref alloc5 0);

select instructions:

start:
	movq free_ptr(%rip), tmp8
	movq tmp8, tmp9
	addq $16, tmp9
	movq fromspace_end(%rip), tmp46150
	cmpq tmp46150, tmp9
	jl block46152
	jmp block46153
block46152:
	movq $0, _7
	jmp block46151
block46153:
	movq %r15, %rdi
	movq $16, %rsi
	callq collect
	jmp block46151
block46151:
	movq free_ptr(%rip), %r11
	addq $16, free_ptr(%rip)
	movq $3, 0(%r11)
	movq %r11, alloc5
	movq alloc5, %r11
	movq $42, 8(%r11)
	movq $0, _6
	movq alloc5, %r11
	movq 8(%r11), %rax
	jmp conclusion

prelude and conclusion:

main:
	pushq %rbp
	movq %rsp, %rbp
	subq $0, %rsp
	movq $65536, %rdi
	movq $65536, %rsi
	callq initialize
	movq rootstack_begin(%rip), %r15
	jmp start
start:
	movq free_ptr(%rip), %rcx
	addq $16, %rcx
	movq fromspace_end(%rip), %rdx
	cmpq %rdx, %rcx
	jl block46185
	jmp block46186
block46185:
	movq $0, %rcx
	jmp block46184
block46186:
	movq %r15, %rdi
	movq $16, %rsi
	callq collect
	jmp block46184
block46184:
	movq free_ptr(%rip), %r11
	addq $16, free_ptr(%rip)
	movq $3, 0(%r11)
	movq %r11, %rcx
	movq %rcx, %r11
	movq $42, 8(%r11)
	movq $0, %rdx
	movq %rcx, %r11
	movq 8(%r11), %rax
	jmp conclusion
conclusion:
	subq $0, %r15
	addq $0, %rsp
	popq %rbp
	retq