URL
https://opencores.org/ocsvn/scarts/scarts/trunk
Subversion Repositories scarts
[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [rtl.scm] - Rev 6
Compare with Previous | Blame | View Log
; Basic RTL support. ; Copyright (C) 2000, 2001, 2009 Red Hat, Inc. ; This file is part of CGEN. ; See file COPYING.CGEN for details. ; The name for the description language has been changed a couple of times. ; RTL isn't my favorite because of perceived confusion with GCC ; (and perceived misinterpretation of intentions!). ; On the other hand my other choices were taken (and believed to be ; more confusing). ; ; RTL functions are described by class <rtx-func>. ; The complete list of rtl functions is defined in doc/rtl.texi. ; Conventions used in this file: ; - procs that perform the basic rtl or semantic expression manipulation that ; is for public use shall be prefixed with "s-" or "rtl-" or "rtx-" ; - no other procs shall be so prefixed ; - rtl globals and other rtx-func object support shall be prefixed with ; "-rtx[-:]" ; - no other procs shall be so prefixed ; Class for defining rtx nodes. ; FIXME: Add new members that are lambda's to perform the argument checking ; specified by `arg-types' and `arg-modes'. This will save a lookup during ; traversing. It will also allow custom versions for oddballs (e.g. for ; `member' we want to verify the 2nd arg is a `number-list' rtx). ; ??? Still useful? ; name as it appears in RTL ; argument list ; types of each argument, as symbols ; This is #f for macros. ; Possible values: ; OPTIONS - optional list of :-prefixed options. ; ANYMODE - any mode ; INTMODE - any integer mode ; FLOATMODE - any floating point mode ; NUMMODE - any numeric mode ; EXPLNUMMODE - explicit numeric mode, can't be DFLT or VOID ; NONVOIDMODE - can't be `VOID' ; VOIDMODE - must be `VOID' ; DFLTMODE - must be `DFLT', used when any mode is inappropriate ; RTX - any rtx ; SETRTX - any rtx allowed to be `set' ; TESTRTX - the test of an `if' ; CONDRTX - a cond expression ((test) rtx ... rtx) ; CASERTX - a case expression ((symbol .. symbol) rtx ... rtx) ; LOCALS - the locals list of a sequence ; ENV - environment stack ; ATTRS - attribute list ; SYMBOL - operand must be a symbol ; STRING - operand must be a string ; NUMBER - operand must be a number ; SYMORNUM - operand must be a symbol or number ; OBJECT - operand is an object ; required mode of each argument ; This is #f for macros. ; Possible values include any mode name and: ; ANY - any mode ; NA - not applicable ; OP0 - mode is specified in operand 0 ; unless it is DFLT in which case use the default mode ; of the operand ; MATCH1 - must match mode of operand 1 ; which will have OP0 for its mode spec ; MATCH2 - must match mode of operand 2 ; which will have OP0 for its mode spec ; <MODE-NAME> - must match specified mode ; The class of rtx. ; This is #f for macros. ; ARG - operand, local, const ; SET - set ; UNARY - not, inv, etc. ; BINARY - add, sub, etc. ; TRINARY - addc, subc, etc. ; IF - if ; COND - cond, case ; SEQUENCE - sequence, parallel ; UNSPEC - c-call ; MISC - everything else ; A symbol indicating the flavour of rtx node this is. ; function - normal function ; syntax - don't pre-eval arguments ; operand - result is an operand ; macro - converts one rtx expression to another ; The word "style" was chosen to be sufficiently different ; from "type", "kind", and "class". ; A function to perform the rtx. ; Ordinal number of rtx. Used to index into tables. ; Predicate. ; Accessor fns ; Add standard `get-name' method since this isn't a subclass of <ident>. ; List of mode types for arg-types. ; List of valid values for arg-types, not including mode names. ; List of valid mode matchers, excluding mode names. ; List of all defined rtx names. This can be map'd over without having ; to know the innards of -rtx-func-table (which is a hash table). ; Table of rtx function objects. ; This is set in rtl-init!. ; Look up the <rtx-func> object for RTX-KIND. ; Returns the object or #f if not found. ; RTX-KIND may already be an <rtx-func> object. FIXME: delete? ; Table of rtx macro objects. ; This is set in rtl-init!. ; Table of operands, modes, and other non-functional aspects of RTL. ; This is defined in rtl-finish!, after all operands have been read in. ; Number of next rtx to be defined. ; Return the number of rtx's. ; Define Rtx Node ; ; Add an entry to the rtx function table. ; NAME-ARGS is a list of the operation name and arguments. ; The mode of the result must be the first element in `args' (if there are ; any arguments). ; ARG-TYPES is a list of argument types (-rtx-valid-types). ; ARG-MODES is a list of mode matchers (-rtx-valid-matches). ; CLASS is the class of the rtx to be created. ; ACTION is a list of Scheme expressions to perform the operation. ; ; ??? Note that we can support variables. Not sure it should be done. ; Add it to the table of rtx handlers. ; Written this way so Hobbit can handle it. ; Same as define-rtx-node but don't pre-evaluate the arguments. ; Remember that `mode' must be the first argument. ; Add it to the table of rtx handlers. ; Written this way so Hobbit can handle it. ; Same as define-rtx-node but return an operand (usually an <operand> object). ; ??? `mode' must be the first argument? ; Operand nodes must specify an action. ; Add it to the table of rtx handlers. ; Written this way so Hobbit can handle it. ; Convert one rtx expression into another. ; NAME-ARGS is a list of the operation name and arguments. ; ACTION is a list of Scheme expressions to perform the operation. ; The result of ACTION must be another rtx expression (a list). ; macro nodes must specify an action ; class ; Add it to the table of rtx macros. ; Written this way so Hobbit can handle it. ; RTL macro expansion. ; RTL macros are different than pmacros. The difference is that the expansion ; happens internally, RTL macros are part of the language. ; Lookup MACRO-NAME and return its <rtx-func> object or #f if not found. ; Lookup (car exp) and return the macro's lambda if it is one or #f. ; Expand a list. ; Main entry point to expand a macro invocation. ; pair? -> cheap (and (not (null? exp)) (list? exp)) ; If the result is a new macro invocation, recurse. ; Publically accessible version. ; RTX mode support. ; Get implied mode of X, either an operand expression, sequence temp, or ; a hardware reference expression. ; The result is the name of the mode. ; ((operand) (obj:name (op:mode (current-op-lookup (cadr x))))) ; ((opspec) ; (if (eq? (rtx-opspec-mode x) 'VOID) ; (rtx-lvalue-mode-name estate (rtx-opspec-hw-ref x)) ; (rtx-opspec-mode x))) ; ((reg mem) (cadr x)) ;; (local options mode name) "unknown local""rtx-lvalue-mode-name: not an operand or hardware reference:"; Lookup the mode to use for semantic operations (unsigned modes aren't ; allowed since we don't have ANDUSI, etc.). ; ??? I have actually implemented both ways (full use of unsigned modes ; and mostly hidden use of unsigned modes). Neither makes me real ; comfortable, though I liked bringing unsigned modes out into the open ; even if it doubled the number of semantic operations. ; MODE is a mode name or <mode> object. ; Return the mode of object OBJ. ; Return a boolean indicating of modes M1,M2 are compatible. ;(eq? (obj:name mode1) (obj:name mode2))) ; ??? This is more permissive than is perhaps proper. ; Environments (sequences with local variables). ; Temporaries are created within a sequence. ; e.g. (sequence ((WI tmp)) (set tmp reg0) ...) ; ??? Perhaps what we want here is `let' but for now I prefer `sequence'. ; This isn't exactly `let' either as no initial value is specified. ; Environments are also used to specify incoming values from the top level. ;(define cx-temp:name (elm-make-getter <c-expr-temp> 'name)) ;(define cx-temp:mode (elm-make-getter <c-expr-temp> 'mode)) ;(define cx-temp:value (elm-make-getter <c-expr-temp> 'value)) ; ??? calls to gen-c-symbol don't belong here "tmp_"; Return a boolean indicating if X is an <rtx-temp>. ; Respond to 'get-mode messages. ; Respond to 'get-name messages. ; An environment is a list of <rtx-temp> objects. ; An environment stack is a list of environments. ; Create an initial environment. ; VAR-LIST is a list of (name <mode> value) elements. ; Convert VAR-LIST to an associative list of <rtx-temp> objects. ; Create an initial environment with local variables. ; VAR-LIST is a list of (mode-name name) elements, i.e. the locals argument to ; `sequence' or equivalent thereof. ; Convert VAR-LIST to an associative list of <rtx-temp> objects. ; Return the symbol name of the limit variable of `do-count' ; given iteration-variable ITER-VAR. ; ??? We don't publish that this variable is available to use, but we could. ; Create an environment with the iteration local variables of `do-count'. ; Push environment ENV onto the front of environment stack ENV-STACK, ; returning a new object. ENV-STACK is not modified. ; Lookup variable NAME in environment ENV. ; The result is the <rtx-temp> object. ; ??? Should environments only have rtx-temps? ;(display "looking up:") (display name) (newline) ; Create a "closure" of EXPR using the current temp stack. "rtx-env stack (empty):\n"; done "rtx-env stack, level "":\n"" ";(display (obj:name (rtx-temp-mode (cdr var)))) ;(display " ") ; Build, test, and analyze various kinds of rtx's. ; ??? A lot of this could be machine generated except that I don't yet need ; that much. ; Return value of constant RTX (either const or enum). "rtx-constant-value: not const or enum"; Return register number or #f if absent. ; (reg options mode hw-name [regno [selector]]) ; Return register selector or #f if absent. ; Return both register number and selector. ; Return memory address. ; Return memory selector or #f if absent. ; Return both memory address and selector. ; Return MEM with new address NEW-ADDR. ; ??? Complicate as necessary. ; Return argument to `symbol' rtx. "can't use rtx-local-obj on local name";(define (rtx-opspec? rtx) (eq? 'opspec (rtx-name rtx))) ;(define (rtx-opspec-mode rtx) (rtx-mode rtx)) ;(define (rtx-opspec-hw-ref rtx) (list-ref rtx 5)) ;(define (rtx-opspec-set-op-num! rtx num) (set-car! (cddddr rtx) num)) ; If `else' clause is missing the result is #f. ; Same as rtx-sequence-locals except return in assq'able form. ; Return a semi-pretty string describing RTX. ; This is used by hw to include the index in the element's name. "-""-"; Various rtx utilities. ; Dump an rtx expression. "#<object "" "">"; Dump an expression to a string. ; Return a boolean indicating if EXPR is known to be a compile-time constant. ; Return boolean indicating if EXPR has side-effects. ; FIXME: for now punt. ; Return a boolean indicating if EXPR is a "true" boolean value. ; ; ??? In RTL, #t is a synonym for (const 1). This is confusing for Schemers, ; so maybe RTL's #t should be renamed to TRUE. ; Return a boolean indicating if EXPR is a "false" boolean value. ; ; ??? In RTL, #f is a synonym for (const 0). This is confusing for Schemers, ; so maybe RTL's #f should be renamed to FALSE. ; Return canonical boolean values. ; Convert EXPR to a canonical boolean if possible. ; Return rtx values for #f/#t. ; Return #t if X is an rtl expression. ; e.g. '(add WI dr simm8); ; pair? -> cheap non-null-list? ; Instruction field support. ; Return list of ifield names refered to in EXPR. ; Assumes EXPR is more than just (ifield x). ; Hardware rtx handlers. ; Subroutine of hw to compute the object's name. ; The name of the operand must include the index so that multiple copies ; of a hardware object (e.g. h-gr[0], h-gr[14]) can be distinguished. ; We make some attempt to make the name pretty as it appears in generated ; files. ; (obj:name (op:type self)) ; (obj:name (op:index self))))) "-"; Return the <operand> object described by ; HW-NAME/MODE-NAME/SELECTOR/INDEX-ARG. ; ; HW-NAME is the name of the hardware element. ; INDEX-ARG is an rtx or number of the index. ; In the case of scalar hardware elements, pass 0 for INDEX-ARG. ; MODE-NAME is the name of the mode. ; In the case of a vector of registers, INDEX-ARG is the vector index. ; In the case of a scalar register, the value is ignored, but pass 0 (??? #f?). ; SELECTOR is an rtx or number and is passed to HW-NAME to allow selection of a ; particular variant of the hardware. It's kind of like an INDEX, but along ; an atypical axis. An example is memory ASI's on Sparc. Pass ; hw-selector-default if there is no selector. ; ESTATE is the current rtx evaluation state. ; ; e.g. (hw estate WI h-gr #f (const INT 14)) ; selects register 14 of the h-gr set of registers. ; ; *** The index is passed unevaluated because for parallel execution support ; *** a variable is created with a name based on the hardware element and ; *** index, and we want a reasonably simple and stable name. We get this by ; *** stringize-ing it. ; *** ??? Though this needs to be redone anyway. ; ; ??? The specified hardware element must be either a scalar or a vector. ; Maybe in the future allow arrays although there's significant utility in ; allowing only at most a scalar index. ; Enforce some rules to keep things in line with the current design. "invalid mode name""invalid hw name""invalid index""invalid selector""invalid hardware element"; ??? lookup-for-new? "invalid mode"; Record the selector. ; Create the index object. ; For the simulator the following could be done which ; would save having to create a closure. ; ??? Old code, left in for now. ; (rtx-get estate DFLT ; (rtx-eval (estate-context estate) ; (estate-econfig estate) ; index-arg rtx-evaluator)) ; Make sure constant indices are recorded as such. "invalid index""invalid mode for hardware"; The name of the operand must include the index so that multiple copies ; of a hardware object (e.g. h-gr[0], h-gr[14]) can be distinguished. ; Empty comment and attribute. ; ??? Stick the arguments in the comment for debugging purposes? ""; This is shorthand for (hw estate mode hw-name regno selector). ; ESTATE is the current rtx evaluation state. ; INDX-SEL is an optional register number and possible selector. ; The register number, if present, is (car indx-sel) and must be a number or ; unevaluated RTX expression. ; The selector, if present, is (cadr indx-sel) and must be a number or ; unevaluated RTX expression. ; ??? A register selector isn't supported yet. It's just an idea that's ; been put down on paper for future reference. ; This is shorthand for (hw estate mode h-memory addr selector). ; ADDR must be an unevaluated RTX expression. ; If present (car sel) must be a number or unevaluated RTX expression. ; For the rtx nodes to use. ; The program counter. ; When this code is loaded, global `pc' is nil, it hasn't been set to the ; pc operand yet (see operand-init!). We can't use `pc' inside the drn as the ; value is itself. So we use s-pc. rtl-finish! must be called after ; operand-init!. ; Conditional execution. ; `if' in RTL has a result, like ?: in C. ; We support both: one with a result (non VOID mode), and one without (VOID mode). ; The non-VOID case must have an else part. ; MODE is the mode of the result, not the comparison. ; The comparison is expected to return a zero/non-zero value. ; ??? Perhaps this should be a syntax-expr. Later. "if: too many elements in `else' part"; Subroutines. ; ??? Not sure this should live here. "define-subr"; Misc. utilities. ; The argument to drn,drmn,drsn must be Scheme code (or a fixed subset ; thereof). .str/.sym are used in pmacros so it makes sense to include them ; in the subset. ; Given (expr1 expr2 expr3 expr4), for example, ; return (fn (fn (fn expr1 expr2) expr3) expr4). ; Called before a .cpu file is read in. ; Sanity checks. ; All rtx take options for the first arg and a mode for the second. ; pc is the one exception, blech ; else a macro "\ Define an rtx subroutine, name/value pair list version. "; Install builtins ; Called after cpu files are loaded to add misc. remaining entries to the ; rtx handler table for use during evaluation. ; rtl-finish! must be done before ifmt-compute!, the latter will ; construct hardware objects which is done by rtx evaluation. "Building rtx operand table ...\n"; Update s-pc, must be called after operand-init!. ; Table of traversers for the various rtx elements. ; Initialize the operand hash table. ; Add the operands to the eval symbol table. ; Add ifields to the eval symbol table.