MimP5Stuff.mesa
Copyright Ó 1988, 1989, 1991 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) June 23, 1989 4:32:53 pm PDT
DIRECTORY
MimCode USING [CodeList],
IntCodeDefs USING [BlockNode, Label, Node, NodeList, Var],
Tree USING [Link];
MimP5Stuff: CEDAR DEFINITIONS = BEGIN
OPEN IntCodeDefs, MimCode;
Procedures
BlockValSimplify: PROC [cl: CodeList, node: Node, bn: BlockNode] RETURNS [BOOL];
Given a code list to generate into, we simplify an assignment or declaration with a block value that declares an unnecessary temporary. We return TRUE if the simplification was possible, and FALSE if it was not possible.
MakeConsBlock: PROC
[cl: CodeList, dest: Node, bits: INT, assumeTemp: BOOL] RETURNS [Node];
Given a code list cl with accumulated code, we return a node that computes the same thing as the nodes in the code list. The value of the returned node should have the given number of bits. This procedure attempts to coalesce assignments to adjacent fields of dest. Further, if many assignments of zeros to a particular are seen, the destination is bulk zeroed before the assignments take place (this can save lots of code).
If assumeTemp = TRUE, then we can be more aggressive about combining assignments to dest, because we can assume that the value of dest is not used on the rhs of any assignments in the block.
Intersects: PROC [node: Node, var: Var] RETURNS [BOOL];
Returns TRUE if the execution of node might depend on or affect the value of var. This routine is quite conservative.
GetCard: PROC [node: Node, start: INT ¬ 0, bits: NAT ¬ BITS[CARD]] RETURNS [CARD];
Precondition: IsCard[node]
Returns a CARD that is properly aligned with the given field specification.
IsCard: PROC [node: Node] RETURNS [BOOL];
Returns TRUE if the node can easily return a CARD value.
IsSimpleVar: PROC [n: Node] RETURNS [BOOL];
Returns TRUE if the node is a simple variable (local variable, global variable, or field of a simple variable).
CanonBlock: PUBLIC PROC [n: Node] RETURNS [Node];
Used to canonicalize blocks. This will remove some awkward constructions. The only simplifications are for block nodes. A block node is not necessarily returned!
SubstTailGoTos: PROC [node: Node, label: Label, subst: Node] RETURNS [Node];
Finds all tail go to nodes and substitutes the subst node for them.
CombineAssignments: PROC [nl: NodeList, assumeTemp: BOOL] RETURNS [BOOL];
Attempts to combine assignments to fields of the same destination by destructively altering the given node list. If look2, then an extra attempt to combine assignments of constants is made (since it generates better code). When the assignments are combined, it should normally take fewer instructions to do the same thing.
If assumeTemp, then we can assume that the destination of the assignments will not be used in the rhs of any of the assignments.
SplitAssignment: PROC [nl: NodeList] RETURNS [BOOL];
If the first node in the list is a simple assignment of a to a field that crosses a word boundary (or appears to cross), then the assignment is split into two assignments, each of which stays within a word. TRUE is returned iff such a split was made.
SimplifyParts: PROC [parts: NodeList, offset: INT ¬ 0] RETURNS [NodeList];
Destructively modifies the parts list to try to combine parts that fit within a single word. Assumes the given target offset to keep from combining across word boundaries. Returns the new node list head (which may share structure with the old list).
Accumulate: PROC [x: Node, y: Node] RETURNS [Node];
Adds two nodes together (they should be no more than bitsPerWord wide) using unsigned, unchecked addition.
ShiftLeft: PROC [n: Node, shift: NAT, bits: NAT ¬ 0] RETURNS [Node];
Generates code to shift the given node left by the given number of bits, resulting in a node with the given number of bits. The node given must be less than or equal to bitsPerWord wide. If bits = 0, then the resulting number of bits is the same as the given node.
ShiftRight: PROC [n: Node, shift: NAT, bits: NAT ¬ 0] RETURNS [Node];
Generates code to shift the given node right by the given number of bits, resulting in a node with the given number of bits. The node given must be less than or equal to bitsPerWord wide. If bits = 0, then the resulting number of bits is the same as the given node.
Vulnerable: UNSAFE PROC [t1: Tree.Link, t2: Tree.Link, lhs: BOOL] RETURNS [BOOL];
If lhs, then returns TRUE if the address of t1 may change if t2 is executed.
If NOT lhs, then returns TRUE if the value of t1 may change if t2 is executed.
SideEffectFree: UNSAFE PROC [t: Tree.Link] RETURNS [BOOL];
Returns TRUE if the normal execution of the expression t has no side effects. For this procedure, a signal is a side effect, but an error is not, because a signal can be resumed.
END.