X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fmeta-vmdef.lisp;h=805761f5cd5825581ed5385d23c51754f6dc5d63;hb=e0697854ef9f4999c8585b64be1b282ce4725176;hp=51b9898ac9320147896f48b157a5751e3aea6c27;hpb=78a057624fecd10d0fb2ead4ef02ffc361b1ee22;p=sbcl.git diff --git a/src/compiler/meta-vmdef.lisp b/src/compiler/meta-vmdef.lisp index 51b9898..805761f 100644 --- a/src/compiler/meta-vmdef.lisp +++ b/src/compiler/meta-vmdef.lisp @@ -275,8 +275,7 @@ ;;; type descriptor for the Lisp type that is equivalent to this type. (defmacro !def-primitive-type (name scs &key (type name)) (declare (type symbol name) (type list scs)) - (let ((scns (mapcar #'meta-sc-number-or-lose scs)) - (ctype-form `(specifier-type ',type))) + (let ((scns (mapcar #'meta-sc-number-or-lose scs))) `(progn (/show0 "doing !DEF-PRIMITIVE-TYPE, NAME=..") (/primitive-print ,(symbol-name name)) @@ -284,9 +283,8 @@ (setf (gethash ',name *backend-meta-primitive-type-names*) (make-primitive-type :name ',name :scs ',scns - :type ,ctype-form))) - ,(once-only ((n-old `(gethash ',name *backend-primitive-type-names*)) - (n-type ctype-form)) + :specifier ',type))) + ,(once-only ((n-old `(gethash ',name *backend-primitive-type-names*))) `(progn ;; If the PRIMITIVE-TYPE structure already exists, we ;; destructively modify it so that existing references in @@ -300,13 +298,13 @@ (cond (,n-old (/show0 "in ,N-OLD clause of COND") (setf (primitive-type-scs ,n-old) ',scns) - (setf (primitive-type-type ,n-old) ,n-type)) + (setf (primitive-type-specifier ,n-old) ',type)) (t (/show0 "in T clause of COND") (setf (gethash ',name *backend-primitive-type-names*) (make-primitive-type :name ',name :scs ',scns - :type ,n-type)))) + :specifier ',type)))) (/show0 "done with !DEF-PRIMITIVE-TYPE") ',name))))) @@ -406,7 +404,7 @@ (variant () :type list) (variant-vars () :type list) ;; variables bound to the VOP and Vop-Node when in the generator body - (vop-var (gensym) :type symbol) + (vop-var '.vop. :type symbol) (node-var nil :type (or symbol null)) ;; a list of the names of the codegen-info arguments to this VOP (info-args () :type list) @@ -467,10 +465,7 @@ ;; This is only meaningful in :ARGUMENT and :TEMPORARY operands. (target nil :type (or symbol null)) ;; TEMP is a temporary that holds the TN-REF for this operand. - ;; TEMP-TEMP holds the write reference that begins a temporary's - ;; lifetime. - (temp (gensym) :type symbol) - (temp-temp nil :type (or symbol null)) + (temp (make-operand-parse-temp) :type symbol) ;; the time that this operand is first live and the time at which it ;; becomes dead again. These are TIME-SPECs, as returned by ;; PARSE-TIME-SPEC. @@ -481,7 +476,7 @@ (scs nil :type list) ;; Variable that is bound to the load TN allocated for this operand, or to ;; NIL if no load-TN was allocated. - (load-tn (gensym) :type symbol) + (load-tn (make-operand-parse-load-tn) :type symbol) ;; an expression that tests whether to do automatic operand loading (load t) ;; In a wired or restricted temporary this is the SC the TN is to be @@ -519,9 +514,9 @@ (error "~S is not an operand to ~S." name (vop-parse-name parse)))) found)) -;;; Get the VOP-Parse structure for NAME or die trying. For all -;;; meta-compile time uses, the VOP-Parse should be used instead of -;;; the VOP-Info. +;;; Get the VOP-PARSE structure for NAME or die trying. For all +;;; meta-compile time uses, the VOP-PARSE should be used instead of +;;; the VOP-INFO. (defun vop-parse-or-lose (name) (the vop-parse (or (gethash name *backend-parsed-vops*) @@ -529,8 +524,8 @@ ;;; Return a list of LET-forms to parse a TN-REF list into the temps ;;; specified by the operand-parse structures. MORE-OPERAND is the -;;; Operand-Parse describing any more operand, or NIL if none. REFS is -;;; an expression that evaluates into the first tn-ref. +;;; OPERAND-PARSE describing any more operand, or NIL if none. REFS is +;;; an expression that evaluates into the first TN-REF. (defun access-operands (operands more-operand refs) (declare (list operands)) (collect ((res)) @@ -544,9 +539,9 @@ (res `(,(operand-parse-name more-operand) ,prev)))) (res))) -;;; This is used with ACCESS-OPERANDS to prevent warnings for TN-Ref +;;; This is used with ACCESS-OPERANDS to prevent warnings for TN-REF ;;; temps not used by some particular function. It returns the name of -;;; the last operand, or NIL if Operands is NIL. +;;; the last operand, or NIL if OPERANDS is NIL. (defun ignore-unreferenced-temps (operands) (when operands (operand-parse-temp (car (last operands))))) @@ -681,8 +676,16 @@ nil) t))) :key #'car)) - (oe-type '(mod #.max-vop-tn-refs)) ; :REF-ORDERING element type - (te-type '(mod #.(* max-vop-tn-refs 2))) ; :TARGETS element type + ;; :REF-ORDERING element type + ;; + ;; KLUDGE: was (MOD #.MAX-VOP-TN-REFS), which is still right + (oe-type '(unsigned-byte 8)) + ;; :TARGETS element-type + ;; + ;; KLUDGE: was (MOD #.(* MAX-VOP-TN-REFS 2)), which does + ;; not correspond to the definition in + ;; src/compiler/vop.lisp. + (te-type '(unsigned-byte 16)) (ordering (make-specializable-array (length sorted) :element-type oe-type))) @@ -748,13 +751,13 @@ (rassoc name (funs))))) (unless name (error "no move function defined to ~:[save~;load~] SC ~S ~ - with ~S ~:[to~;from~] from SC ~S" + ~:[to~;from~] from SC ~S" load-p sc-name load-p (sc-name alt))) (cond (found (unless (eq (cdr found) name) (error "can't tell whether to ~:[save~;load~]~@ - or ~S when operand is in SC ~S" + with ~S or ~S when operand is in SC ~S" load-p name (cdr found) (sc-name alt))) (pushnew alt (car found))) (t @@ -778,7 +781,7 @@ (if funs (let* ((tn `(tn-ref-tn ,(operand-parse-temp op))) (n-vop (or (vop-parse-vop-var parse) - (setf (vop-parse-vop-var parse) (gensym)))) + (setf (vop-parse-vop-var parse) '.vop.))) (form (if (rest funs) `(sc-case ,tn ,@(mapcar (lambda (x) @@ -823,7 +826,7 @@ ,load-tn (tn-ref-tn ,temp)))))) -;;; Make a lambda that parses the VOP TN-Refs, does automatic operand +;;; Make a lambda that parses the VOP TN-REFS, does automatic operand ;;; loading, and runs the appropriate code generator. (defun make-generator-function (parse) (declare (type vop-parse parse)) @@ -878,6 +881,16 @@ ,@(vop-parse-body parse)) ,@(saves)))))) +(defvar *parse-vop-operand-count*) +(defun make-operand-parse-temp () + ;; FIXME: potentially causes breakage in contribs from locked + ;; packages. + (intern (format nil "OPERAND-PARSE-TEMP-~D" *parse-vop-operand-count*) + (symbol-package '*parse-vop-operand-count*))) +(defun make-operand-parse-load-tn () + (intern (format nil "OPERAND-PARSE-LOAD-TN-~D" *parse-vop-operand-count*) + (symbol-package '*parse-vop-operand-count*))) + ;;; Given a list of operand specifications as given to DEFINE-VOP, ;;; return a list of OPERAND-PARSE structures describing the fixed ;;; operands, and a single OPERAND-PARSE describing any more operand. @@ -894,6 +907,7 @@ (error "malformed operand specifier: ~S" spec)) (when more (error "The MORE operand isn't the last operand: ~S" specs)) + (incf *parse-vop-operand-count*) (let* ((name (first spec)) (old (if (vop-parse-inherits parse) (find-operand name @@ -982,9 +996,9 @@ (dolist (name (cddr spec)) (unless (symbolp name) (error "bad temporary name: ~S" name)) + (incf *parse-vop-operand-count*) (let ((res (make-operand-parse :name name :kind :temporary - :temp-temp (gensym) :born (parse-time-spec :load) :dies (parse-time-spec :save)))) (do ((opt (second spec) (cddr opt))) @@ -1029,87 +1043,102 @@ :key #'operand-parse-name)))))) (values)) +(defun compute-parse-vop-operand-count (parse) + (declare (type vop-parse parse)) + (labels ((compute-count-aux (parse) + (declare (type vop-parse parse)) + (if (null (vop-parse-inherits parse)) + (length (vop-parse-operands parse)) + (+ (length (vop-parse-operands parse)) + (compute-count-aux + (vop-parse-or-lose (vop-parse-inherits parse))))))) + (if (null (vop-parse-inherits parse)) + 0 + (compute-count-aux (vop-parse-or-lose (vop-parse-inherits parse)))))) + ;;; the top level parse function: clobber PARSE to represent the ;;; specified options. (defun parse-define-vop (parse specs) (declare (type vop-parse parse) (list specs)) - (dolist (spec specs) - (unless (consp spec) - (error "malformed option specification: ~S" spec)) - (case (first spec) - (:args - (multiple-value-bind (fixed more) - (!parse-vop-operands parse (rest spec) :argument) - (setf (vop-parse-args parse) fixed) - (setf (vop-parse-more-args parse) more))) - (:results - (multiple-value-bind (fixed more) - (!parse-vop-operands parse (rest spec) :result) - (setf (vop-parse-results parse) fixed) - (setf (vop-parse-more-results parse) more)) - (setf (vop-parse-conditional-p parse) nil)) - (:conditional - (setf (vop-parse-result-types parse) ()) - (setf (vop-parse-results parse) ()) - (setf (vop-parse-more-results parse) nil) - (setf (vop-parse-conditional-p parse) t)) - (:temporary - (parse-temporary spec parse)) - (:generator - (setf (vop-parse-cost parse) - (vop-spec-arg spec 'unsigned-byte 1 nil)) - (setf (vop-parse-body parse) (cddr spec))) - (:effects - (setf (vop-parse-effects parse) (rest spec))) - (:affected - (setf (vop-parse-affected parse) (rest spec))) - (:info - (setf (vop-parse-info-args parse) (rest spec))) - (:ignore - (setf (vop-parse-ignores parse) (rest spec))) - (:variant - (setf (vop-parse-variant parse) (rest spec))) - (:variant-vars - (let ((vars (rest spec))) - (setf (vop-parse-variant-vars parse) vars) - (setf (vop-parse-variant parse) - (make-list (length vars) :initial-element nil)))) - (:variant-cost - (setf (vop-parse-cost parse) (vop-spec-arg spec 'unsigned-byte))) - (:vop-var - (setf (vop-parse-vop-var parse) (vop-spec-arg spec 'symbol))) - (:move-args - (setf (vop-parse-move-args parse) - (vop-spec-arg spec '(member nil :local-call :full-call - :known-return)))) - (:node-var - (setf (vop-parse-node-var parse) (vop-spec-arg spec 'symbol))) - (:note - (setf (vop-parse-note parse) (vop-spec-arg spec '(or string null)))) - (:arg-types - (setf (vop-parse-arg-types parse) - (!parse-vop-operand-types (rest spec) t))) - (:result-types - (setf (vop-parse-result-types parse) - (!parse-vop-operand-types (rest spec) nil))) - (:translate - (setf (vop-parse-translate parse) (rest spec))) - (:guard - (setf (vop-parse-guard parse) (vop-spec-arg spec t))) - ;; FIXME: :LTN-POLICY would be a better name for this. It would - ;; probably be good to leave it unchanged for a while, though, - ;; at least until the first port to some other architecture, - ;; since the renaming would be a change to the interface between - (:policy - (setf (vop-parse-ltn-policy parse) - (vop-spec-arg spec 'ltn-policy))) - (:save-p - (setf (vop-parse-save-p parse) - (vop-spec-arg spec - '(member t nil :compute-only :force-to-stack)))) - (t - (error "unknown option specifier: ~S" (first spec))))) - (values)) + (let ((*parse-vop-operand-count* (compute-parse-vop-operand-count parse))) + (dolist (spec specs) + (unless (consp spec) + (error "malformed option specification: ~S" spec)) + (case (first spec) + (:args + (multiple-value-bind (fixed more) + (!parse-vop-operands parse (rest spec) :argument) + (setf (vop-parse-args parse) fixed) + (setf (vop-parse-more-args parse) more))) + (:results + (multiple-value-bind (fixed more) + (!parse-vop-operands parse (rest spec) :result) + (setf (vop-parse-results parse) fixed) + (setf (vop-parse-more-results parse) more)) + (setf (vop-parse-conditional-p parse) nil)) + (:conditional + (setf (vop-parse-result-types parse) ()) + (setf (vop-parse-results parse) ()) + (setf (vop-parse-more-results parse) nil) + (setf (vop-parse-conditional-p parse) t)) + (:temporary + (parse-temporary spec parse)) + (:generator + (setf (vop-parse-cost parse) + (vop-spec-arg spec 'unsigned-byte 1 nil)) + (setf (vop-parse-body parse) (cddr spec))) + (:effects + (setf (vop-parse-effects parse) (rest spec))) + (:affected + (setf (vop-parse-affected parse) (rest spec))) + (:info + (setf (vop-parse-info-args parse) (rest spec))) + (:ignore + (setf (vop-parse-ignores parse) (rest spec))) + (:variant + (setf (vop-parse-variant parse) (rest spec))) + (:variant-vars + (let ((vars (rest spec))) + (setf (vop-parse-variant-vars parse) vars) + (setf (vop-parse-variant parse) + (make-list (length vars) :initial-element nil)))) + (:variant-cost + (setf (vop-parse-cost parse) (vop-spec-arg spec 'unsigned-byte))) + (:vop-var + (setf (vop-parse-vop-var parse) (vop-spec-arg spec 'symbol))) + (:move-args + (setf (vop-parse-move-args parse) + (vop-spec-arg spec '(member nil :local-call :full-call + :known-return)))) + (:node-var + (setf (vop-parse-node-var parse) (vop-spec-arg spec 'symbol))) + (:note + (setf (vop-parse-note parse) (vop-spec-arg spec '(or string null)))) + (:arg-types + (setf (vop-parse-arg-types parse) + (!parse-vop-operand-types (rest spec) t))) + (:result-types + (setf (vop-parse-result-types parse) + (!parse-vop-operand-types (rest spec) nil))) + (:translate + (setf (vop-parse-translate parse) (rest spec))) + (:guard + (setf (vop-parse-guard parse) (vop-spec-arg spec t))) + ;; FIXME: :LTN-POLICY would be a better name for this. It + ;; would probably be good to leave it unchanged for a while, + ;; though, at least until the first port to some other + ;; architecture, since the renaming would be a change to the + ;; interface between + (:policy + (setf (vop-parse-ltn-policy parse) + (vop-spec-arg spec 'ltn-policy))) + (:save-p + (setf (vop-parse-save-p parse) + (vop-spec-arg spec + '(member t nil :compute-only :force-to-stack)))) + (t + (error "unknown option specifier: ~S" (first spec))))) + (values))) ;;;; making costs and restrictions @@ -1259,7 +1288,7 @@ (error "bad thing to be a operand type: ~S" spec))))))) (mapcar #'parse-operand-type specs))) -;;; Check the consistency of Op's Sc restrictions with the specified +;;; Check the consistency of OP's SC restrictions with the specified ;;; primitive-type restriction. :CONSTANT operands have already been ;;; filtered out, so only :OR and * restrictions are left. ;;; @@ -1337,7 +1366,7 @@ (values)) ;;; Compute stuff that can only be computed after we are done parsing -;;; everying. We set the VOP-Parse-Operands, and do various error checks. +;;; everying. We set the VOP-PARSE-OPERANDS, and do various error checks. (defun !grovel-vop-operands (parse) (declare (type vop-parse parse)) @@ -1367,8 +1396,8 @@ ;;;; function translation stuff ;;; Return forms to establish this VOP as a IR2 translation template -;;; for the :TRANSLATE functions specified in the VOP-Parse. We also -;;; set the Predicate attribute for each translated function when the +;;; for the :TRANSLATE functions specified in the VOP-PARSE. We also +;;; set the PREDICATE attribute for each translated function when the ;;; VOP is conditional, causing IR1 conversion to ensure that a call ;;; to the translated is always used in a predicate position. (defun !set-up-fun-translation (parse n-template) @@ -1440,13 +1469,13 @@ (defparameter *slot-inherit-alist* '((:generator-function . vop-info-generator-function)))) -;;; This is something to help with inheriting VOP-Info slots. We +;;; This is something to help with inheriting VOP-INFO slots. We ;;; return a keyword/value pair that can be passed to the constructor. ;;; SLOT is the keyword name of the slot, Parse is a form that -;;; evaluates to the VOP-Parse structure for the VOP inherited. If +;;; evaluates to the VOP-PARSE structure for the VOP inherited. If ;;; PARSE is NIL, then we do nothing. If the TEST form evaluates to ;;; true, then we return a form that selects the named slot from the -;;; VOP-Info structure corresponding to PARSE. Otherwise, we return +;;; VOP-INFO structure corresponding to PARSE. Otherwise, we return ;;; the FORM so that the slot is recomputed. (defmacro inherit-vop-info (slot parse test form) `(if (and ,parse ,test) @@ -1455,7 +1484,7 @@ (template-or-lose ',(vop-parse-name ,parse)))) (list ,slot ,form))) -;;; Return a form that creates a VOP-Info structure which describes VOP. +;;; Return a form that creates a VOP-INFO structure which describes VOP. (defun set-up-vop-info (iparse parse) (declare (type vop-parse parse) (type (or vop-parse null) iparse)) (let ((same-operands @@ -1504,11 +1533,11 @@ ;;; are defaulted from the inherited argument (or result) of the same ;;; name. The following operand options are defined: ;;; -;;; :SCs (SC*) -;;; :SCs specifies good SCs for this operand. Other SCs will be -;;; penalized according to move costs. A load TN will be allocated if -;;; necessary, guaranteeing that the operand is always one of the -;;; specified SCs. +;;; :SCs (SC*) +;;; :SCs specifies good SCs for this operand. Other SCs will +;;; be penalized according to move costs. A load TN will be +;;; allocated if necessary, guaranteeing that the operand is +;;; always one of the specified SCs. ;;; ;;; :LOAD-TN Load-Name ;;; Load-Name is bound to the load TN allocated for this @@ -1523,7 +1552,7 @@ ;;; operand. ;;; ;;; :MORE T-or-NIL -;;; If specified, NAME is bound to the TN-Ref for the first +;;; If specified, NAME is bound to the TN-REF for the first ;;; argument or result following the fixed arguments or results. ;;; A :MORE operand must appear last, and cannot be targeted or ;;; restricted. @@ -1683,12 +1712,12 @@ ;;;; emission macros ;;; Return code to make a list of VOP arguments or results, linked by -;;; TN-Ref-Across. The first value is code, the second value is LET* +;;; TN-REF-ACROSS. The first value is code, the second value is LET* ;;; forms, and the third value is a variable that evaluates to the ;;; head of the list, or NIL if there are no operands. Fixed is a list -;;; of forms that evaluate to TNs for the fixed operands. TN-Refs will +;;; of forms that evaluate to TNs for the fixed operands. TN-REFS will ;;; be made for these operands according using the specified value of -;;; Write-P. More is an expression that evaluates to a list of TN-Refs +;;; WRITE-P. More is an expression that evaluates to a list of TN-REFS ;;; that will be made the tail of the list. If it is constant NIL, ;;; then we don't bother to set the tail. (defun make-operand-list (fixed more write-p) @@ -1789,12 +1818,12 @@ ;;; ;;; This is like VOP, but allows for emission of templates with ;;; arbitrary numbers of arguments, and for emission of templates -;;; using already-created TN-Ref lists. +;;; using already-created TN-REF lists. ;;; -;;; The Arguments and Results are TNs to be referenced as the first +;;; The ARGS and RESULTS are TNs to be referenced as the first ;;; arguments and results to the template. More-Args and More-Results -;;; are heads of TN-Ref lists that are added onto the end of the -;;; TN-Refs for the explicitly supplied operand TNs. The TN-Refs for +;;; are heads of TN-REF lists that are added onto the end of the +;;; TN-REFS for the explicitly supplied operand TNs. The TN-REFS for ;;; the more operands must have the TN and WRITE-P slots correctly ;;; initialized. ;;; @@ -1853,15 +1882,15 @@ (collect ((clauses)) (do ((cases forms (rest cases))) ((null cases) - (clauses `(t (error "unknown SC to SC-Case for ~S:~% ~S" ,n-tn + (clauses `(t (error "unknown SC to SC-CASE for ~S:~% ~S" ,n-tn (sc-name (tn-sc ,n-tn)))))) (let ((case (first cases))) (when (atom case) - (error "illegal SC-Case clause: ~S" case)) + (error "illegal SC-CASE clause: ~S" case)) (let ((head (first case))) (when (eq head t) (when (rest cases) - (error "T case is not last in SC-Case.")) + (error "T case is not last in SC-CASE.")) (clauses `(t nil ,@(rest case))) (return)) (clauses `((or ,@(mapcar (lambda (x) @@ -1890,7 +1919,7 @@ ,@forms)) ;;; Iterate over all the TNs live at some point, with the live set -;;; represented by a local conflicts bit-vector and the IR2-Block +;;; represented by a local conflicts bit-vector and the IR2-BLOCK ;;; containing the location. (defmacro do-live-tns ((tn-var live block &optional result) &body body) (let ((n-conf (gensym)) @@ -1911,7 +1940,7 @@ (let ((,ltns (ir2-block-local-tns ,n-block))) ;; Do TNs always-live in this block and live :MORE TNs. (do ((,n-conf (ir2-block-global-tns ,n-block) - (global-conflicts-next ,n-conf))) + (global-conflicts-next-blockwise ,n-conf))) ((null ,n-conf)) (when (or (eq (global-conflicts-kind ,n-conf) :live) (let ((,i (global-conflicts-number ,n-conf)))