Page MenuHomePhabricator

[AVR] Implement stacksave/stackrestore by expanding (PR31342)
ClosedPublic

Authored by Florob on Feb 4 2017, 4:40 PM.

Details

Summary

This implements the missing stacksave/stackrestore intrinsics via expansion.

Output of llc -O0 -march=avr ~/devel/llvm/test/CodeGen/Generic/stacksave-restore.ll for sanity checking (comments mine):

	.text
	.file	".../llvm/test/CodeGen/Generic/stacksave-restore.ll"
	.globl	test
	.p2align	1
	.type	test,@function
test:                                   ; @test
; BB#0:
# Save r28, r29
	push	r28
	push	r29

# SP -= 4, Y = SP
	in	r28, 61
	in	r29, 62
	sbiw	r28, 4
	in	r0, 63
	cli
	out	62, r29
	out	63, r0
	out	61, r28

# Save SP
	in	r18, 61
	in	r19, 62

	mov	r20, r22
	mov	r21, r23

# stacksave (Z = SP)
	in	r30, 61
	in	r31, 62

# alloca
	lsl	r22
	rol	r23
	lsl	r22
	rol	r23
	in	r26, 61
	in	r27, 62
	sub	r26, r22
	sbc	r27, r23
	andi	r26, 252
	in	r0, 63
	cli
	out	62, r27
	out	63, r0
	out	61, r26

# stackrestore (SP = Z)
	in	r0, 63
	cli
	out	62, r31
	out	63, r0
	out	61, r30

# alloca
	in	r30, 61
	in	r31, 62
	sub	r30, r22
	sbc	r31, r23
	andi	r30, 252
	in	r0, 63
	cli
	out	62, r31
	out	63, r0
	out	61, r30

	std	Y+3, r24                ; 2-byte Folded Spill
	std	Y+4, r25                ; 2-byte Folded Spill

# Set return value
	mov	r24, r26
	mov	r25, r27

# Restore SP
	in	r0, 63
	cli
	out	62, r19
	out	63, r0
	out	61, r18

	std	Y+1, r20                ; 2-byte Folded Spill
	std	Y+2, r21                ; 2-byte Folded Spill

# SP = Y + 4
	adiw	r28, 4
	in	r0, 63
	cli
	out	62, r29
	out	63, r0
	out	61, r28

# Restore r28, r29
	pop	r29
	pop	r28
	ret
.Lfunc_end0:
	.size	test, .Lfunc_end0-test

Diff Detail

Repository
rL LLVM

Event Timeline

Florob created this revision.Feb 4 2017, 4:40 PM
dylanmckay edited edge metadata.Feb 4 2017, 10:55 PM

Can you add a CodeGen test for this expansion?

Florob updated this revision to Diff 87141.Feb 5 2017, 6:37 AM

I've added a basic CodeGen test. Since this is effectively expanded to a register read/write I'm not entirely sure doing this specifically for stacksave/stackrestore is ideal though.

This revision is now accepted and ready to land.Feb 5 2017, 12:31 PM
Florob added a comment.Feb 5 2017, 1:39 PM

I don't have commit access as I'm far from a regular contributor. It would be nice if you could commit this on my behalf.

This revision was automatically updated to reflect the committed changes.