(ucode-primitive pair?)
(ucode-primitive positive-fixnum?)
(ucode-primitive positive?)
+ (ucode-primitive primitive-procedure-open-coded? 1)
(ucode-primitive string?)
(ucode-primitive vector?)
(ucode-primitive weak-pair? 1)
(define (constant-foldable-operator-value rv)
(if (rvalue/reference? rv)
(variable-usual-definition (variable-name (reference-lvalue rv)))
- (rvalue-constant-value rv)))
+ (let ((primitive (rvalue-constant-value rv)))
+ (assert (primitive-procedure? primitive))
+ (if (eq? primitive (ucode-primitive primitive-procedure-open-coded? 1))
+ primitive-procedure-open-coded?
+ primitive))))
(define (arity-correct? proc n)
(let ((arity (procedure-arity proc)))
(files "rtlgen/opncod")
(parent (compiler rtl-generator))
(export (compiler rtl-generator) combination/inline)
+ (export (compiler fg-optimizer) primitive-procedure-open-coded?)
(export (compiler top-level) open-coding-analysis))
(define-package (compiler rtl-generator find-block)
(files "rtlgen/opncod")
(parent (compiler rtl-generator))
(export (compiler rtl-generator) combination/inline)
+ (export (compiler fg-optimizer) primitive-procedure-open-coded?)
(export (compiler top-level) open-coding-analysis))
(define-package (compiler rtl-generator find-block)
(files "rtlgen/opncod")
(parent (compiler rtl-generator))
(export (compiler rtl-generator) combination/inline)
+ (export (compiler fg-optimizer) primitive-procedure-open-coded?)
(export (compiler top-level) open-coding-analysis))
(define-package (compiler rtl-generator find-block)
(files "rtlgen/opncod")
(parent (compiler rtl-generator))
(export (compiler rtl-generator) combination/inline)
+ (export (compiler fg-optimizer) primitive-procedure-open-coded?)
(export (compiler top-level) open-coding-analysis))
(define-package (compiler rtl-generator find-block)
(files "rtlgen/opncod")
(parent (compiler rtl-generator))
(export (compiler rtl-generator) combination/inline)
+ (export (compiler fg-optimizer) primitive-procedure-open-coded?)
(export (compiler top-level) open-coding-analysis))
(define-package (compiler rtl-generator find-block)
(and entry
(try-handler combination value entry))))))))
+(define (primitive-procedure-open-coded? primitive)
+ (guarantee primitive-procedure? primitive 'PRIMITIVE-PROCEDURE-OPEN-CODED?)
+ (let ((name (primitive-procedure-name primitive)))
+ (and (hash-table-ref name->open-coders name (lambda () #f))
+ #t)))
+
(define (try-handler combination primitive entry)
(let ((operands (combination/operands combination)))
(and (primitive-arity-correct? primitive (length operands))
(find_primitive
((MEMORY_REF (name, SYMBOL_NAME)), intern_p, allow_p, arity));
}
+
+DEFINE_PRIMITIVE ("PRIMITIVE-PROCEDURE-OPEN-CODED?", Prim_primitive_procedure_open_coded, 1, 1,
+ "(PRIMITIVE)\n\
+Returns #t iff PRIMITIVE is open-coded by the compiler.\n\
+Only returns #t if constant-folded by the same compiler.")
+{
+ PRIMITIVE_HEADER (1);
+ CHECK_ARG (1, PRIMITIVE_P);
+ PRIMITIVE_RETURN (SHARP_F);
+}
'(
("compiler/test-fasdump" (compiler portable-fasdump))
"compiler/test-fgopt-conect"
+ "compiler/test-open-code"
"compiler/test-toplev"
"compiler/test-varname"
"compiler/test-vartrap"
--- /dev/null
+#| -*-Scheme-*-
+
+Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
+ 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+ 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
+ 2017, 2018, 2019 Massachusetts Institute of Technology
+
+This file is part of MIT/GNU Scheme.
+
+MIT/GNU Scheme is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+MIT/GNU Scheme is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with MIT/GNU Scheme; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
+USA.
+
+|#
+
+;;;; Tests open-coded conditionals
+
+(declare (usual-integrations))
+\f
+(define-syntax ucode-primitive
+ (sc-macro-transformer
+ (lambda (form environment)
+ environment
+ (apply make-primitive-procedure (cdr form)))))
+
+(define-test 'primitive-procedure-open-coded?
+ (lambda ()
+ (assert-eqv
+ ((ucode-primitive primitive-procedure-open-coded? 1)
+ (ucode-primitive null? 1))
+ (compiled-procedure? (lambda () 0)))))
\ No newline at end of file