From 38a723a307b722671d2beba0d034d57274517aa6 Mon Sep 17 00:00:00 2001
From: "Guillermo J. Rozas" <edu/mit/csail/zurich/gjr>
Date: Fri, 28 Aug 1987 21:54:15 +0000
Subject: [PATCH] Define with-temporary-register-copy! for 3 operand
 instructions.

---
 v7/src/compiler/back/lapgn2.scm | 46 ++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/v7/src/compiler/back/lapgn2.scm b/v7/src/compiler/back/lapgn2.scm
index af6f50d3e..5a5ef7f9e 100644
--- a/v7/src/compiler/back/lapgn2.scm
+++ b/v7/src/compiler/back/lapgn2.scm
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/compiler/back/lapgn2.scm,v 1.4 1987/08/28 18:51:09 jinx Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/compiler/back/lapgn2.scm,v 1.5 1987/08/28 21:54:15 jinx Exp $
 
 Copyright (c) 1987 Massachusetts Institute of Technology
 
@@ -152,31 +152,47 @@ MIT in each case. |#
 		   (else (register->register-transfer alias target))))
 	    (register-reference target))))))
 
+;; These procedures are used when the copy is going to be transformed,
+;; and the machine has 3 operand instructions, which allow an implicit
+;; motion in the transformation operation.
+;; For example, on the DEC VAX it is cheaper to do
+;;	bicl3	op1,source,target
+;; than
+;; 	movl	source,target
+;; 	bicl2	op1,target
+;; The extra arguments are
+;; REC1, invoked if we are resuing an alias of source.
+;;      It already contains the data to operate on.
+;; REC2, invoked if a `brand-new' alias for target has been allocated.
+;;      We must take care of moving the data ourselves.
+
 (define (with-register-copy-alias! source type target rec1 rec2)
-  ;; REC1 is invoked if we are resuing an alias of source.
-  ;;      It already contains the data to operate on.
-  ;; REC2 is invoked if a `brand-new' alias for target has been allocated.
-  ;;      We must take care of moving the data ourselves.
-  ;; This procedure should be used when the copy is going to be transformed,
-  ;; and the machine has 3 operand instructions, which allow an
-  ;; implicit motion in the transformation operation.
-  ;; For example, on the DEC VAX it is cheaper to do
-  ;;	bicl3	op1,source,target
-  ;; than
-  ;; 	movl	source,target
-  ;; 	bicl2	op1,target
+  (provide-copy-reusing-alias! source type rec1 rec2
+   (lambda (reusable-alias)
+     (add-pseudo-register-alias! target reusable-alias false))
+   (lambda ()
+     (allocate-alias-register! target type))))
+
+(define (with-temporary-register-copy! register type rec1 rec2)
+  (provide-copy-reusing-alias! register type rec1 rec2
+   need-register!
+   (lambda ()
+     (allocate-temporary-register! type))))
+
+(define (provide-copy-reusing-alias! source type rec1 rec2 if-reusable if-not)
+  ;; IF-NOT is assumed to return a machine register.
   (let ((reusable-alias
 	 (and (dead-register? source)
 	      (register-alias source type))))
     (if reusable-alias
 	(begin (delete-dead-registers!)
-	       (add-pseudo-register-alias! target reusable-alias false)
+	       (if-reusable reusable-alias)
 	       (rec1 (register-reference reusable-alias)))
 	(let ((alias (if (machine-register? source)
 			 source
 			 (register-alias source false))))
 	  (delete-dead-registers!)
-	  (let ((target (allocate-alias-register! target type)))
+	  (let ((target (if-not)))
 	    (cond ((not alias)
 		   (rec2 (pseudo-register-home source)
 			 (register-reference target)))
-- 
2.25.1