[PATCH] D29553: [AVR] Implement stacksave/stackrestore by expanding (PR31342)

Florian Zeitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 4 16:40:46 PST 2017


Florob created this revision.

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, at 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


https://reviews.llvm.org/D29553

Files:
  lib/Target/AVR/AVRISelLowering.cpp


Index: lib/Target/AVR/AVRISelLowering.cpp
===================================================================
--- lib/Target/AVR/AVRISelLowering.cpp
+++ lib/Target/AVR/AVRISelLowering.cpp
@@ -48,6 +48,8 @@
   setOperationAction(ISD::GlobalAddress, MVT::i16, Custom);
   setOperationAction(ISD::BlockAddress, MVT::i16, Custom);
 
+  setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
+  setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
   setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i8, Expand);
   setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i16, Expand);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29553.87122.patch
Type: text/x-patch
Size: 583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170205/d9eacccd/attachment.bin>


More information about the llvm-commits mailing list