cmp: inl: remove maybe-save-value and introduce inline-arg0 instead

This function has very clear resemblence of inline-args so it is moved to
cmpc-opt-inl.
This commit is contained in:
Daniel Kochmański 2023-11-30 18:39:52 +01:00
parent a12d24a8bf
commit 48c39c8083
2 changed files with 43 additions and 39 deletions

View file

@ -83,7 +83,7 @@
(c2expr* form)
(list type temp))
(list type
(list 'si:STRUCTURE-REF
(list 'SI:STRUCTURE-REF
(first (coerce-locs
(inline-args (list (c1form-arg 0 form)))))
(c1form-arg 1 form)
@ -113,20 +113,21 @@
(emit-inlined-variable form forms))
(CALL-GLOBAL
(emit-inlined-call-global form (c1form-primary-type form)))
(si:STRUCTURE-REF
(SI:STRUCTURE-REF
(emit-inlined-structure-ref form forms))
#+clos
(si:INSTANCE-REF
(SI:INSTANCE-REF
(emit-inlined-instance-ref form forms))
(SETQ
(emit-inlined-setq form forms))
(PROGN
(emit-inlined-progn form forms))
(emit-inlined-progn form forms))
(VALUES
(emit-inlined-values form forms))
(t (let* ((type (c1form-primary-type form))
(temp (make-inline-temp-var type)))
(let ((*destination* temp)) (c2expr* form))
(temp (make-inline-temp-var type))
(*destination* temp))
(c2expr* form)
(list type temp))))))
;;;
@ -135,13 +136,23 @@
;;; side effects: emits code for temporary variables
;;;
;;; Whoever calls inline-args must bind *inline-blocks* to 0 and afterwards
;;; call close-inline-blocks
;;; call close-inline-blocks.
;;;
(defun inline-args (forms)
(loop for form-list on forms
for form = (first form-list)
collect (emit-inline-form form (rest form-list))))
;;;
;;; inline-arg0:
;;; returns a location that contains the function
;;; side effects: emits code for a temporary variable
;;;
;;; Whoever calls inline-arg0 must rebind *TEMP*.
;;;
(defun inline-arg0 (value-form other-forms)
(emit-inline-form value-form other-forms))
(defun maybe-open-inline-block ()
(unless (plusp *inline-blocks*)
(open-inline-block)))

View file

@ -9,22 +9,6 @@
(in-package #:compiler)
;;; Functions that use MAYBE-SAVE-VALUE should rebind *TEMP*.
(defun maybe-save-value (value &optional (other-forms nil other-forms-flag))
(declare (si::c-local))
(let ((name (c1form-name value)))
(cond ((eq name 'LOCATION)
(c1form-arg 0 value))
((and (eq name 'VARIABLE)
other-forms-flag
(not (var-changed-in-form-list (c1form-arg 0 value) other-forms)))
(c1form-arg 0 value))
(t
(let* ((temp (make-temp-var))
(*destination* temp))
(c2expr* value)
temp)))))
;;; FIXME functions declared as SI::C-LOCAL can't be called from the stack
;;; because they are not installed in the environment. That means that if we
;;; have such function and call it with too many arguments it will be
@ -52,6 +36,28 @@
(defun c2mcall (c1form form args fun-val call-type)
(c2call-stack c1form form args t))
;;;
;;; c2call-stack:
;;;
;;; This is the most generic way of calling functions. First we push them on
;;; the stack, and then we apply from the stack frame. Other variants call
;;; inline-args and put results directly in the function call.
;;;
(defun c2call-stack (c1form form args values-p)
(declare (ignore c1form))
(let* ((*inline-blocks* 0)
(*temp* *temp*)
(loc (inlined-arg-loc (inline-arg0 form args))))
(with-stack-frame (frame)
(let ((*destination* (if values-p 'VALUEZ 'LEAVE)))
(dolist (arg args)
(c2expr* arg)
(if values-p
(wt-nl "ecl_stack_frame_push_values(" frame ");")
(wt-nl "ecl_stack_frame_push(" frame ",value0);"))))
(unwind-exit (call-stack-loc nil loc)))
(close-inline-blocks)))
;;;
;;; c2call-global:
;;;
@ -126,23 +132,10 @@
(form-type (c1form-primary-type form))
(function-p (and (subtypep form-type 'function)
(policy-assume-right-type)))
(loc (maybe-save-value form args)))
(loc (inlined-arg-loc (inline-arg0 form args))))
(unwind-exit (call-unknown-global-loc loc (inline-args args) function-p))
(close-inline-blocks)))
(defun c2call-stack (c1form form args values-p)
(declare (ignore c1form))
(let* ((*temp* *temp*)
(loc (maybe-save-value form args)))
(with-stack-frame (frame)
(let ((*destination* (if values-p 'VALUEZ 'LEAVE)))
(dolist (arg args)
(c2expr* arg)
(if values-p
(wt-nl "ecl_stack_frame_push_values(" frame ");")
(wt-nl "ecl_stack_frame_push(" frame ",value0);"))))
(unwind-exit (call-stack-loc nil loc)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; CALL LOCATIONS
@ -266,8 +259,8 @@
;;;
;;; call-stack-loc
;;; LOC is NIL or location containing function
;;; ARGS is the list of typed locations for arguments
;;; LOC is the location containing function
;;; FNAME is NIL or a name of the function
;;;
(defun call-stack-loc (fname loc)
`(CALL-STACK ,loc ,fname))