From aed845f3f5da8ddf145ba617066b7438bc93d8d3 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Wed, 29 Feb 2012 14:20:14 -0500 Subject: [PATCH] eliminating unnecessary argcount assignment when primitives are used --- compiler/compiler.rkt | 21 +++++++++++++++------ version.rkt | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/compiler.rkt b/compiler/compiler.rkt index e40136a..763ada4 100644 --- a/compiler/compiler.rkt +++ b/compiler/compiler.rkt @@ -1099,17 +1099,26 @@ (append-instruction-sequences (make-PushEnvironment (length (App-operands exp)) #f) (apply append-instruction-sequences operand-codes) - (make-AssignImmediate 'argcount (make-Const (length (App-operands exp)))) + + ;; Optimization: if the expected arity is a known constant, we don't + ;; need to touch argcount either. If it's variable, we emit the argcount, since + ;; it's something we need at runtime. + (if (number? expected-arity) + empty-instruction-sequence + (make-AssignImmediate 'argcount (make-Const (length (App-operands exp))))) + (if (arity-matches? expected-arity (length (App-operands exp))) (compile-primitive-procedure-call primitive-name cenv (make-Const (length (App-operands exp))) target linkage) - (make-Perform (make-RaiseArityMismatchError! - (make-Reg 'proc) - expected-arity - (make-Const (length (App-operands exp))))))))) + (append-instruction-sequences + (compile (App-operator exp) extended-cenv 'proc next-linkage/expects-single) + (make-Perform (make-RaiseArityMismatchError! + (make-Reg 'proc) + expected-arity + (make-Const (length (App-operands exp)))))))))) ;; If we know the procedure is implemented as a primitive (as opposed to a general closure), @@ -1117,7 +1126,7 @@ ;; We don't need to check arity (as that's already been checked statically). ;; Assumes 1. the procedure value is NOT loaded into proc. We know statically what the ;; procedure is supposed to be. -;; 2. number-of-arguments has been written into the argcount register, +;; 2. (OPTIONAL) number-of-arguments has been conditionally written into the argcount register, ; ; 3. the number-of-arguments values are on the stack. (: compile-primitive-procedure-call (Symbol CompileTimeEnvironment OpArg Target Linkage -> InstructionSequence)) (define (compile-primitive-procedure-call primitive-name cenv number-of-arguments target linkage) diff --git a/version.rkt b/version.rkt index e2ffcd6..9e25c79 100644 --- a/version.rkt +++ b/version.rkt @@ -7,4 +7,4 @@ (provide version) (: version String) -(define version "1.201") +(define version "1.202")