Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
e0689256
Commit
e0689256
authored
Dec 28, 1991
by
Richard Kenner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*** empty log message ***
From-SVN: r145
parent
97686cc9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
979 additions
and
601 deletions
+979
-601
gcc/genrecog.c
+979
-601
No files found.
gcc/genrecog.c
View file @
e0689256
...
...
@@ -29,7 +29,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
which is the insn code number for the pattern that matched.
This is the same as the order in the machine description of the
entry that matched. This number can be used as an index into various
insn_* tables, such as insn_template
s
, insn_outfun, and insn_n_operands
insn_* tables, such as insn_template, insn_outfun, and insn_n_operands
(found in insn-output.c).
The third argument to recog is an optional pointer to an int.
...
...
@@ -58,37 +58,44 @@ struct obstack *rtl_obstack = &obstack;
extern
void
free
();
/* Data structure for a listhead of decision trees. The alternatives
to a node are kept in a doublely-linked list so we can easily add nodes
to the proper place when merging. */
struct
decision_head
{
struct
decision
*
first
,
*
last
;
};
/* Data structure for decision tree for recognizing
legitimate instructions. */
struct
decision
{
int
number
;
char
*
position
;
RTX_CODE
code
;
char
*
exact
;
enum
machine_mode
mode
;
char
*
tests
;
int
insn_code_number
;
int
num_clobbers_to_add
;
struct
decision
*
next
;
struct
decision
*
success
;
int
opno
;
int
dupno
;
int
test_elt_zero_int
;
int
elt_zero_int
;
int
test_elt_one_int
;
int
elt_one_int
;
int
ignmode
;
struct
decision
*
afterward
;
int
label_needed
;
char
*
c_test
;
char
enforce_mode
;
int
veclen
;
int
subroutine_number
;
/* Used for DEFINE_SPLITs. */
char
*
c_hook
;
rtx
split_sequence
;
int
number
;
/* Node number, used for labels */
char
*
position
;
/* String denoting position in pattern */
RTX_CODE
code
;
/* Code to test for or UNKNOWN to suppress */
char
ignore_code
;
/* If non-zero, need not test code */
char
ignore_mode
;
/* If non-zero, need not test mode */
int
veclen
;
/* Length of vector, if nonzero */
enum
machine_mode
mode
;
/* Machine mode of node */
char
enforce_mode
;
/* If non-zero, test `mode' */
char
retest_code
,
retest_mode
;
/* See write_tree_1 */
int
test_elt_zero_int
;
/* Nonzero if should test XINT (rtl, 0) */
int
elt_zero_int
;
/* Required value for XINT (rtl, 0) */
int
test_elt_one_int
;
/* Nonzero if should test XINT (rtl, 1) */
int
elt_one_int
;
/* Required value for XINT (rtl, 2) */
char
*
tests
;
/* If nonzero predicate to call */
int
pred
;
/* `preds' index of predicate or -1 */
char
*
c_test
;
/* Additional test to perform */
struct
decision_head
success
;
/* Nodes to test on success */
int
insn_code_number
;
/* Insn number matched, if success */
int
num_clobbers_to_add
;
/* Number of CLOBBERs to be added to pattern */
struct
decision
*
next
;
/* Node to test on failure */
struct
decision
*
prev
;
/* Node whose failure tests us */
struct
decision
*
afterward
;
/* Node to test on success, but failure of
successor nodes */
int
opno
;
/* Operand number, if >= 0 */
int
dupno
;
/* Number of operand to compare against */
int
label_needed
;
/* Nonzero if label needed when writing tree */
int
subroutine_number
;
/* Number of subroutine this node starts */
};
#define SUBROUTINE_THRESHOLD 50
...
...
@@ -100,53 +107,67 @@ static int next_subroutine_number;
enum
routine_type
{
RECOG
,
SPLIT
};
static
int
try_merge_1
();
static
int
no_same_mode
();
static
int
same_codes
();
static
int
same_modes
();
/* Next available node number for tree nodes. */
/*
static int
recognize (top)
{
staten:
x = XVECEXP (top, 0, 3);
if (test_code (GET_CODE (x))
&& test_mode (MODE (x))
&& whatever_else)
goto statep;
else if (next one...)
goto statem:
goto stater;
statep:
actions...;
return 1;
static
int
next_number
;
statem:
x = stack[depth--];
more tests...;
/* Next number to use as an insn_code. */
stateq:
stack[++depth] = x;
x = XEXP (stack[depth], 0);
more tests...;
static
int
next_insn_code
;
stater:
x = XEXP (stack[depth], 1);
}
/* Similar, but counts all expressions in the MD file; used for
error messages. */
*/
static
int
next_index
;
static
int
next_number
;
/* Record the highest depth we ever have so we know how many variables to
allocate in each subroutine we make. */
static
int
next_insn_code
;
static
int
max_depth
;
static
int
next_index
;
/* This table contains a list of the rtl codes that can possibly match a
predicate defined in recog.c. The function `not_both_true' uses it to
deduce that there are no expressions that can be matches by certain pairs
of tree nodes. Also, if a predicate can match only one code, we can
hardwire that code into the node testing the predicate. */
static
struct
pred_table
{
char
*
name
;
RTX_CODE
codes
[
NUM_RTX_CODE
];
}
preds
[]
=
{{
"general_operand"
,
{
CONST_INT
,
CONST_DOUBLE
,
CONST
,
SYMBOL_REF
,
LABEL_REF
,
SUBREG
,
REG
,
MEM
}},
#ifdef PREDICATE_CODES
PREDICATE_CODES
#endif
{
"address_operand"
,
{
CONST_INT
,
CONST_DOUBLE
,
CONST
,
SYMBOL_REF
,
LABEL_REF
,
SUBREG
,
REG
,
MEM
,
PLUS
,
MINUS
,
MULT
}},
{
"register_operand"
,
{
SUBREG
,
REG
}},
{
"scratch_operand"
,
{
SCRATCH
,
REG
}},
{
"immediate_operand"
,
{
CONST_INT
,
CONST_DOUBLE
,
CONST
,
SYMBOL_REF
,
LABEL_REF
}},
{
"const_int_operand"
,
{
CONST_INT
}},
{
"const_double_operand"
,
{
CONST_INT
,
CONST_DOUBLE
}},
{
"nonimmediate_operand"
,
{
SUBREG
,
REG
,
MEM
}},
{
"nonmemory_operand"
,
{
CONST_INT
,
CONST_DOUBLE
,
CONST
,
SYMBOL_REF
,
LABEL_REF
,
SUBREG
,
REG
}},
{
"push_operand"
,
{
MEM
}},
{
"memory_operand"
,
{
SUBREG
,
MEM
}},
{
"indirect_operand"
,
{
SUBREG
,
MEM
}},
{
"comparison_operation"
,
{
EQ
,
NE
,
LE
,
LT
,
GE
,
LT
,
LEU
,
LTU
,
GEU
,
GTU
}},
{
"mode_independent_operand"
,
{
CONST_INT
,
CONST_DOUBLE
,
CONST
,
SYMBOL_REF
,
LABEL_REF
,
SUBREG
,
REG
,
MEM
}}};
#define NUM_KNOWN_PREDS (sizeof preds / sizeof preds[0])
static
int
try_merge_1
();
static
int
no_same_mode
();
static
int
same_codes
();
static
int
same_modes
();
char
*
xmalloc
();
static
struct
decision
*
add_to_sequence
();
static
struct
decision
*
merge_trees
();
static
struct
decision
_head
merge_trees
();
static
struct
decision
*
try_merge_2
();
static
void
write_subroutine
();
static
void
print_code
();
...
...
@@ -159,41 +180,44 @@ static char *concat ();
static
void
fatal
();
void
fancy_abort
();
static
void
mybzero
();
static
struct
decision
*
first
;
static
void
mybcopy
();
/* Construct and return a sequence of decisions
that will recognize INSN.
*/
that will recognize INSN.
static
struct
decision
*
make_insn_sequence
(
insn
)
TYPE says what type of routine we are recognizing (RECOG or SPLIT). */
static
struct
decision_head
make_insn_sequence
(
insn
,
type
)
rtx
insn
;
enum
routine_type
type
;
{
rtx
x
;
char
*
c_test
=
XSTR
(
insn
,
2
);
char
*
c_test
=
XSTR
(
insn
,
type
==
RECOG
?
2
:
1
);
struct
decision
*
last
;
struct
decision_head
head
;
if
(
XVECLEN
(
insn
,
1
)
==
1
)
x
=
XVECEXP
(
insn
,
1
,
0
);
if
(
XVECLEN
(
insn
,
type
==
RECOG
)
==
1
)
x
=
XVECEXP
(
insn
,
type
==
RECOG
,
0
);
else
{
x
=
rtx_alloc
(
PARALLEL
);
XVEC
(
x
,
0
)
=
XVEC
(
insn
,
1
);
XVEC
(
x
,
0
)
=
XVEC
(
insn
,
type
==
RECOG
);
PUT_MODE
(
x
,
VOIDmode
);
}
last
=
add_to_sequence
(
x
,
0
,
""
);
last
=
add_to_sequence
(
x
,
&
head
,
""
);
if
(
c_test
[
0
])
last
->
c_test
=
c_test
;
last
->
insn_code_number
=
next_insn_code
;
last
->
num_clobbers_to_add
=
0
;
/* If
X is a PARALLEL, see if it ends with a group of CLOBBERs of (hard)
registers or MATCH_SCRATCHes. If so, set up to recognize the pattern
without these CLOBBERs. */
/* If
this is not a DEFINE_SPLIT and X is a PARALLEL, see if it ends with a
group of CLOBBERs of (hard) registers or MATCH_SCRATCHes. If so, set up
to recognize the pattern
without these CLOBBERs. */
if
(
GET_CODE
(
x
)
==
PARALLEL
)
if
(
type
==
RECOG
&&
GET_CODE
(
x
)
==
PARALLEL
)
{
int
i
;
...
...
@@ -206,7 +230,7 @@ make_insn_sequence (insn)
if
(
i
!=
XVECLEN
(
x
,
0
))
{
rtx
new
;
struct
decision
*
previous_first
=
first
;
struct
decision
_head
clobber_head
;
if
(
i
==
1
)
new
=
XVECEXP
(
x
,
0
,
0
);
...
...
@@ -220,57 +244,40 @@ make_insn_sequence (insn)
XVECEXP
(
new
,
0
,
j
)
=
XVECEXP
(
x
,
0
,
j
);
}
last
=
add_to_sequence
(
new
,
0
,
""
);
last
=
add_to_sequence
(
new
,
&
clobber_head
,
""
);
if
(
c_test
[
0
])
last
->
c_test
=
c_test
;
last
->
insn_code_number
=
next_insn_code
;
last
->
num_clobbers_to_add
=
XVECLEN
(
x
,
0
)
-
i
;
first
=
merge_trees
(
previous_first
,
first
);
head
=
merge_trees
(
head
,
clobber_head
);
}
}
next_insn_code
++
;
return
first
;
}
static
struct
decision
*
make_split_sequence
(
insn
)
rtx
insn
;
{
rtx
x
;
char
*
c_test
=
XSTR
(
insn
,
1
);
char
*
c_hook
=
XSTR
(
insn
,
3
);
struct
decision
*
last
;
if
(
type
==
SPLIT
)
/* Define the subroutine we will call below and emit in genemit. */
printf
(
"extern rtx gen_split_%d ();
\n
"
,
last
->
insn_code_number
);
if
(
XVECLEN
(
insn
,
0
)
==
1
)
x
=
XVECEXP
(
insn
,
0
,
0
);
else
{
x
=
rtx_alloc
(
PARALLEL
);
XVEC
(
x
,
0
)
=
XVEC
(
insn
,
0
);
PUT_MODE
(
x
,
VOIDmode
);
}
return
head
;
}
last
=
add_to_sequence
(
x
,
0
,
""
);
/* Create a chain of nodes to verify that an rtl expression matches
PATTERN.
if
(
c_test
[
0
])
last
->
c_test
=
c_test
;
if
(
c_hook
!=
0
&&
c_hook
[
0
]
!=
0
)
last
->
c_hook
=
c_hook
;
last
->
split_sequence
=
XEXP
(
insn
,
2
);
last
->
insn_code_number
=
next_insn_code
++
;
LAST is a pointer to the listhead in the previous node in the chain (or
in the calling function, for the first node).
/* Define the subroutine we will call below and emit in genemit. */
printf
(
"extern rtx gen_split_%d ();
\n
"
,
last
->
insn_code_number
);
POSITION is the string representing the current position in the insn.
return
first
;
}
A pointer to the final node in the chain is returned. */
static
struct
decision
*
add_to_sequence
(
pattern
,
last
,
position
)
rtx
pattern
;
struct
decision
*
last
;
struct
decision
_head
*
last
;
char
*
position
;
{
register
RTX_CODE
code
;
...
...
@@ -280,102 +287,118 @@ add_to_sequence (pattern, last, position)
char
*
newpos
;
register
char
*
fmt
;
register
int
i
;
int
depth
;
int
depth
=
strlen
(
position
)
;
int
len
;
if
(
depth
>
max_depth
)
max_depth
=
depth
;
new
->
number
=
next_number
++
;
new
->
position
=
copystr
(
position
);
new
->
exact
=
0
;
new
->
next
=
0
;
new
->
success
=
0
;
new
->
insn_code_number
=
-
1
;
new
->
num_clobbers_to_add
=
0
;
new
->
tests
=
0
;
new
->
opno
=
-
1
;
new
->
dupno
=
-
1
;
new
->
ignore_code
=
0
;
new
->
ignore_mode
=
0
;
new
->
enforce_mode
=
1
;
new
->
retest_code
=
new
->
retest_mode
=
0
;
new
->
veclen
=
0
;
new
->
test_elt_zero_int
=
0
;
new
->
test_elt_one_int
=
0
;
new
->
elt_zero_int
=
0
;
new
->
elt_one_int
=
0
;
new
->
enforce_mode
=
0
;
new
->
ignmode
=
0
;
new
->
tests
=
0
;
new
->
pred
=
-
1
;
new
->
c_test
=
0
;
new
->
success
.
first
=
new
->
success
.
last
=
0
;
new
->
insn_code_number
=
-
1
;
new
->
num_clobbers_to_add
=
0
;
new
->
next
=
0
;
new
->
prev
=
0
;
new
->
afterward
=
0
;
new
->
opno
=
-
1
;
new
->
dupno
=
-
1
;
new
->
label_needed
=
0
;
new
->
c_test
=
0
;
new
->
c_hook
=
0
;
new
->
split_sequence
=
0
;
new
->
veclen
=
0
;
new
->
subroutine_number
=
0
;
this
=
new
;
if
(
last
==
0
)
first
=
new
;
else
last
->
success
=
new
;
last
->
first
=
last
->
last
=
new
;
depth
=
strlen
(
position
);
newpos
=
(
char
*
)
alloca
(
depth
+
2
);
strcpy
(
newpos
,
position
);
newpos
[
depth
+
1
]
=
0
;
restart
:
if
(
pattern
==
0
)
{
new
->
exact
=
"0"
;
new
->
code
=
UNKNOWN
;
new
->
mode
=
VOIDmode
;
return
new
;
}
new
->
mode
=
GET_MODE
(
pattern
);
new
->
code
=
code
=
GET_CODE
(
pattern
);
switch
(
code
)
{
case
MATCH_OPERAND
:
new
->
opno
=
XINT
(
pattern
,
0
);
new
->
code
=
UNKNOWN
;
new
->
tests
=
XSTR
(
pattern
,
1
);
if
(
*
new
->
tests
==
0
)
new
->
tests
=
0
;
return
new
;
case
MATCH_SCRATCH
:
new
->
opno
=
XINT
(
pattern
,
0
);
new
->
code
=
UNKNOWN
;
new
->
tests
=
"scratch_operand"
;
if
(
*
new
->
tests
==
0
)
new
->
tests
=
0
;
return
new
;
case
MATCH_OPERATOR
:
case
MATCH_PARALLEL
:
new
->
opno
=
XINT
(
pattern
,
0
);
new
->
code
=
UNKNOWN
;
new
->
code
=
(
code
==
MATCH_PARALLEL
?
PARALLEL
:
UNKNOWN
);
new
->
enforce_mode
=
0
;
if
(
code
==
MATCH_SCRATCH
)
new
->
tests
=
"scratch_operand"
;
else
new
->
tests
=
XSTR
(
pattern
,
1
);
if
(
*
new
->
tests
==
0
)
new
->
tests
=
0
;
for
(
i
=
0
;
i
<
XVECLEN
(
pattern
,
2
);
i
++
)
/* See if we know about this predicate and save its number. If we do,
and it only accepts one code, note that fact. The predicate
`const_int_operand' only tests for a CONST_INT, so if we do so we
can avoid calling it at all.
Finally, if we know that the predicate does not allow CONST_INT, we
know that the only way the predicate can match is if the modes match
(here we use the kluge of relying on the fact that "address_operand"
accepts CONST_INT; otherwise, it would have to be a special case),
so we can test the mode (but we need not). This fact should
considerably simplify the generated code. */
if
(
new
->
tests
)
for
(
i
=
0
;
i
<
NUM_KNOWN_PREDS
;
i
++
)
if
(
!
strcmp
(
preds
[
i
].
name
,
new
->
tests
))
{
newpos
[
depth
]
=
i
+
'0'
;
new
=
add_to_sequence
(
XVECEXP
(
pattern
,
2
,
i
),
new
,
newpos
);
}
this
->
success
->
enforce_mode
=
0
;
return
new
;
int
j
;
int
allows_const_int
=
0
;
case
MATCH_PARALLEL
:
new
->
opno
=
XINT
(
pattern
,
0
);
new
->
code
=
PARALLEL
;
new
->
tests
=
XSTR
(
pattern
,
1
);
if
(
*
new
->
tests
==
0
)
new
->
pred
=
i
;
if
(
preds
[
i
].
codes
[
1
]
==
0
&&
new
->
code
==
UNKNOWN
)
{
new
->
code
=
preds
[
i
].
codes
[
0
];
if
(
!
strcmp
(
"const_int_operand"
,
new
->
tests
))
new
->
tests
=
0
;
}
for
(
j
=
0
;
j
<
NUM_RTX_CODE
&&
preds
[
i
].
codes
[
j
]
!=
0
;
j
++
)
if
(
preds
[
i
].
codes
[
j
]
==
CONST_INT
)
allows_const_int
=
1
;
if
(
!
allows_const_int
)
new
->
enforce_mode
=
new
->
ignore_mode
=
1
;
break
;
}
if
(
code
==
MATCH_OPERATOR
||
code
==
MATCH_PARALLEL
)
{
for
(
i
=
0
;
i
<
XVECLEN
(
pattern
,
2
);
i
++
)
{
newpos
[
depth
]
=
i
+
'a'
;
new
=
add_to_sequence
(
XVECEXP
(
pattern
,
2
,
i
),
new
,
newpos
);
newpos
[
depth
]
=
i
+
(
code
==
MATCH_OPERATOR
?
'0'
:
'a'
);
new
=
add_to_sequence
(
XVECEXP
(
pattern
,
2
,
i
),
&
new
->
success
,
newpos
);
}
this
->
success
.
first
->
enforce_mode
=
0
;
}
this
->
success
->
enforce_mode
=
0
;
return
new
;
case
MATCH_OP_DUP
:
...
...
@@ -386,82 +409,79 @@ add_to_sequence (pattern, last, position)
for
(
i
=
0
;
i
<
XVECLEN
(
pattern
,
1
);
i
++
)
{
newpos
[
depth
]
=
i
+
'0'
;
new
=
add_to_sequence
(
XVECEXP
(
pattern
,
1
,
i
),
new
,
newpos
);
new
=
add_to_sequence
(
XVECEXP
(
pattern
,
1
,
i
),
&
new
->
success
,
newpos
);
}
this
->
success
->
enforce_mode
=
0
;
this
->
success
.
first
->
enforce_mode
=
0
;
return
new
;
case
MATCH_DUP
:
new
->
dupno
=
XINT
(
pattern
,
0
);
new
->
code
=
UNKNOWN
;
new
->
enforce_mode
=
0
;
return
new
;
case
ADDRESS
:
pattern
=
XEXP
(
pattern
,
0
);
goto
restart
;
case
PC
:
new
->
exact
=
"pc_rtx"
;
return
new
;
case
CC0
:
new
->
exact
=
"cc0_rtx"
;
return
new
;
case
CONST_INT
:
if
(
INTVAL
(
pattern
)
==
0
)
{
new
->
exact
=
"const0_rtx"
;
return
new
;
}
if
(
INTVAL
(
pattern
)
==
1
)
{
new
->
exact
=
"const1_rtx"
;
return
new
;
}
if
(
INTVAL
(
pattern
)
==
-
1
)
{
new
->
exact
=
"constm1_rtx"
;
return
new
;
}
if
(
INTVAL
(
pattern
)
==
STORE_FLAG_VALUE
)
{
new
->
exact
=
"const_true_rtx"
;
return
new
;
}
break
;
case
SET
:
newpos
[
depth
]
=
'0'
;
new
=
add_to_sequence
(
SET_DEST
(
pattern
),
new
,
newpos
);
this
->
success
->
enforce_mode
=
1
;
new
=
add_to_sequence
(
SET_DEST
(
pattern
),
&
new
->
success
,
newpos
);
this
->
success
.
first
->
enforce_mode
=
1
;
newpos
[
depth
]
=
'1'
;
new
=
add_to_sequence
(
SET_SRC
(
pattern
),
new
,
newpos
);
new
=
add_to_sequence
(
SET_SRC
(
pattern
),
&
new
->
success
,
newpos
);
/* If set are setting CC0 from anything other than a COMPARE, we
must enforce the mode so that we do not produce ambiguous insns. */
if
(
GET_CODE
(
SET_DEST
(
pattern
))
==
CC0
&&
GET_CODE
(
SET_SRC
(
pattern
))
!=
COMPARE
)
this
->
success
.
first
->
enforce_mode
=
1
;
return
new
;
case
SIGN_EXTEND
:
case
ZERO_EXTEND
:
case
STRICT_LOW_PART
:
newpos
[
depth
]
=
'0'
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
0
),
new
,
newpos
);
this
->
success
->
enforce_mode
=
1
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
0
),
&
new
->
success
,
newpos
);
this
->
success
.
first
->
enforce_mode
=
1
;
return
new
;
case
SUBREG
:
this
->
test_elt_one_int
=
1
;
this
->
elt_one_int
=
XINT
(
pattern
,
1
);
newpos
[
depth
]
=
'0'
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
0
),
new
,
newpos
);
this
->
success
->
enforce_mode
=
1
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
0
),
&
new
->
success
,
newpos
);
this
->
success
.
first
->
enforce_mode
=
1
;
return
new
;
case
ZERO_EXTRACT
:
case
SIGN_EXTRACT
:
newpos
[
depth
]
=
'0'
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
0
),
new
,
newpos
);
this
->
success
->
enforce_mode
=
1
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
0
),
&
new
->
success
,
newpos
);
this
->
success
.
first
->
enforce_mode
=
1
;
newpos
[
depth
]
=
'1'
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
1
),
new
,
newpos
);
new
=
add_to_sequence
(
XEXP
(
pattern
,
1
),
&
new
->
success
,
newpos
);
newpos
[
depth
]
=
'2'
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
2
),
new
,
newpos
);
new
=
add_to_sequence
(
XEXP
(
pattern
,
2
),
&
new
->
success
,
newpos
);
return
new
;
case
EQ
:
case
NE
:
case
LE
:
case
LT
:
case
GE
:
case
GT
:
case
LEU
:
case
LTU
:
case
GEU
:
case
GTU
:
/* If the first operand is (cc0), we don't have to do anything
special. */
if
(
GET_CODE
(
XEXP
(
pattern
,
0
))
==
CC0
)
break
;
/* ... fall through ... */
case
COMPARE
:
/* Enforce the mode on the first operand to avoid ambiguous insns. */
newpos
[
depth
]
=
'0'
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
0
),
&
new
->
success
,
newpos
);
this
->
success
.
first
->
enforce_mode
=
1
;
newpos
[
depth
]
=
'1'
;
new
=
add_to_sequence
(
XEXP
(
pattern
,
1
),
&
new
->
success
,
newpos
);
return
new
;
}
...
...
@@ -471,7 +491,7 @@ add_to_sequence (pattern, last, position)
{
newpos
[
depth
]
=
'0'
+
i
;
if
(
fmt
[
i
]
==
'e'
||
fmt
[
i
]
==
'u'
)
new
=
add_to_sequence
(
XEXP
(
pattern
,
i
),
new
,
newpos
);
new
=
add_to_sequence
(
XEXP
(
pattern
,
i
),
&
new
->
success
,
newpos
);
else
if
(
fmt
[
i
]
==
'i'
&&
i
==
0
)
{
this
->
test_elt_zero_int
=
1
;
...
...
@@ -498,7 +518,7 @@ add_to_sequence (pattern, last, position)
{
newpos
[
depth
]
=
'a'
+
j
;
new
=
add_to_sequence
(
XVECEXP
(
pattern
,
i
,
j
),
new
,
newpos
);
&
new
->
success
,
newpos
);
}
}
else
if
(
fmt
[
i
]
!=
'0'
)
...
...
@@ -507,45 +527,232 @@ add_to_sequence (pattern, last, position)
return
new
;
}
/*
Merge two decision trees OLD and ADD,
modifying OLD destructively,
and return the merged tree. */
/*
Return 1 if we can prove that there is no RTL that can match both
D1 and D2. Otherwise, return 0 (it may be that there is an RTL that
can match both or just that we couldn't prove there wasn't such an RTL).
static
struct
decision
*
merge_trees
(
old
,
add
)
register
struct
decision
*
old
,
*
add
;
TOPLEVEL is non-zero if we are to only look at the top level and not
recursively descend. */
static
int
not_both_true
(
d1
,
d2
,
toplevel
)
struct
decision
*
d1
,
*
d2
;
int
toplevel
;
{
while
(
add
)
struct
decision
*
p1
,
*
p2
;
/* If they are both to test modes and the modes are different, they aren't
both true. Similarly for codes, integer elements, and vector lengths. */
if
((
d1
->
enforce_mode
&&
d2
->
enforce_mode
&&
d1
->
mode
!=
VOIDmode
&&
d2
->
mode
!=
VOIDmode
&&
d1
->
mode
!=
d2
->
mode
)
||
(
d1
->
code
!=
UNKNOWN
&&
d2
->
code
!=
UNKNOWN
&&
d1
->
code
!=
d2
->
code
)
||
(
d1
->
test_elt_zero_int
&&
d2
->
test_elt_zero_int
&&
d1
->
elt_zero_int
!=
d2
->
elt_zero_int
)
||
(
d1
->
test_elt_one_int
&&
d2
->
test_elt_one_int
&&
d1
->
elt_one_int
!=
d2
->
elt_one_int
)
||
(
d1
->
veclen
&&
d2
->
veclen
&&
d1
->
veclen
!=
d2
->
veclen
))
return
1
;
/* If either is a wild-card MATCH_OPERAND without a predicate, it can match
absolutely anything, so we can't say that no intersection is possible.
This case is detected by having a zero TESTS field with a code of
UNKNOWN. */
if
((
d1
->
tests
==
0
&&
d1
->
code
==
UNKNOWN
)
||
(
d2
->
tests
==
0
&&
d2
->
code
==
UNKNOWN
))
return
0
;
/* If either has a predicate that we know something about, set things up so
that D1 is the one that always has a known predicate. Then see if they
have any codes in common. */
if
(
d1
->
pred
>=
0
||
d2
->
pred
>=
0
)
{
int
i
,
j
;
if
(
d2
->
pred
>=
0
)
p1
=
d1
,
d1
=
d2
,
d2
=
p1
;
/* If D2 tests an explicit code, see if it is in the list of valid codes
for D1's predicate. */
if
(
d2
->
code
!=
UNKNOWN
)
{
for
(
i
=
0
;
i
<
NUM_RTX_CODE
&&
preds
[
d1
->
pred
].
codes
[
i
];
i
++
)
if
(
preds
[
d1
->
pred
].
codes
[
i
]
==
d2
->
code
)
break
;
if
(
preds
[
d1
->
pred
].
codes
[
i
]
==
0
)
return
1
;
}
/* Otherwise see if the predicates have any codes in common. */
else
if
(
d2
->
pred
>=
0
)
{
for
(
i
=
0
;
i
<
NUM_RTX_CODE
&&
preds
[
d1
->
pred
].
codes
[
i
];
i
++
)
{
register
struct
decision
*
next
=
add
->
next
;
add
->
next
=
0
;
if
(
!
try_merge_1
(
old
,
add
))
old
=
try_merge_2
(
old
,
add
);
add
=
next
;
for
(
j
=
0
;
j
<
NUM_RTX_CODE
;
j
++
)
if
(
preds
[
d2
->
pred
].
codes
[
j
]
==
0
||
preds
[
d2
->
pred
].
codes
[
j
]
==
preds
[
d1
->
pred
].
codes
[
i
])
break
;
if
(
preds
[
d2
->
pred
].
codes
[
j
]
!=
0
)
break
;
}
return
old
;
if
(
preds
[
d1
->
pred
].
codes
[
i
]
==
0
)
return
1
;
}
}
/* If we got here, we can't prove that D1 and D2 cannot both be true.
If we are only to check the top level, return 0. Otherwise, see if
we can prove that all choices in both successors are mutually
exclusive. If either does not have any successors, we can't prove
they can't both be true. */
if
(
toplevel
||
d1
->
success
.
first
==
0
||
d2
->
success
.
first
==
0
)
return
0
;
for
(
p1
=
d1
->
success
.
first
;
p1
;
p1
=
p1
->
next
)
for
(
p2
=
d2
->
success
.
first
;
p2
;
p2
=
p2
->
next
)
if
(
!
not_both_true
(
p1
,
p2
,
0
))
return
0
;
return
1
;
}
/* Merge ADD into the next-chain starting with OLD
only if it overlaps a condition already tested in OLD.
Returns 1 if successful (OLD is modified),
0 if nothing has been done. */
/* Assuming that we can reorder all the alternatives at a specific point in
the tree (see discussion in merge_trees), we would prefer an ordering of
nodes where groups of consecutive nodes test the same mode and, within each
mode, groups of nodes test the same code. With this order, we can
construct nested switch statements, the inner one to test the code and
the outer one to test the mode.
We would like to list nodes testing for specific codes before those
that test predicates to avoid unnecessary function calls. Similarly,
tests for specific modes should preceed nodes that allow any mode.
This function returns the merit (with 0 being the best) of inserting
a test involving the specified MODE and CODE after node P. If P is
zero, we are to determine the merit of inserting the test at the front
of the list. */
static
int
try_merge_1
(
old
,
add
)
register
struct
decision
*
old
,
*
add
;
position_merit
(
p
,
mode
,
code
)
struct
decision
*
p
;
enum
machine_mode
mode
;
RTX_CODE
code
;
{
enum
machine_mode
p_mode
;
/* The only time the front of the list is anything other than the worst
position is if we are testing a mode that isn't VOIDmode. */
if
(
p
==
0
)
return
mode
==
VOIDmode
?
3
:
2
;
p_mode
=
p
->
enforce_mode
?
p
->
mode
:
VOIDmode
;
/* The best case is if the codes and modes both match. */
if
(
p_mode
==
mode
&&
p
->
code
==
code
)
return
0
;
/* If the codes don't match, the next best case is if the modes match.
In that case, the best position for this node depends on whether
we are testing for a specific code or not. If we are, the best place
is after some other test for an explicit code and our mode or after
the last test in the previous mode if every test in our mode is for
an unknown code.
If we are testing for UNKNOWN, then the next best case is at the end of
our mode. */
if
((
code
!=
UNKNOWN
&&
((
p_mode
==
mode
&&
p
->
code
!=
UNKNOWN
)
||
(
p_mode
!=
mode
&&
p
->
next
&&
(
p
->
next
->
enforce_mode
?
p
->
next
->
mode
:
VOIDmode
)
==
mode
&&
(
p
->
next
->
code
==
UNKNOWN
))))
||
(
code
==
UNKNOWN
&&
p_mode
==
mode
&&
(
p
->
next
==
0
||
(
p
->
next
->
enforce_mode
?
p
->
next
->
mode
:
VOIDmode
)
!=
mode
)))
return
1
;
/* The third best case occurs when nothing is testing MODE. If MODE
is not VOIDmode, then the third best case is after something of any
mode that is not VOIDmode. If we are testing VOIDmode, the third best
place is the end of the list. */
if
(
p_mode
!=
mode
&&
((
mode
!=
VOIDmode
&&
p_mode
!=
VOIDmode
)
||
(
mode
==
VOIDmode
&&
p
->
next
==
0
)))
return
2
;
/* Otherwise, we have the worst case. */
return
3
;
}
/* Merge two decision tree listheads OLDH and ADDH,
modifying OLDH destructively, and return the merged tree. */
static
struct
decision_head
merge_trees
(
oldh
,
addh
)
register
struct
decision_head
oldh
,
addh
;
{
while
(
old
)
{
if
((
old
->
position
==
add
->
position
||
(
old
->
position
&&
add
->
position
&&
!
strcmp
(
old
->
position
,
add
->
position
)))
&&
(
old
->
tests
==
add
->
tests
||
(
old
->
tests
&&
add
->
tests
&&
!
strcmp
(
old
->
tests
,
add
->
tests
)))
&&
(
old
->
c_test
==
add
->
c_test
||
(
old
->
c_test
&&
add
->
c_test
&&
!
strcmp
(
old
->
c_test
,
add
->
c_test
)))
&&
(
old
->
c_hook
==
add
->
c_hook
||
(
old
->
c_hook
&&
add
->
c_hook
&&
!
strcmp
(
old
->
c_hook
,
add
->
c_hook
)))
struct
decision
*
add
,
*
next
;
if
(
oldh
.
first
==
0
)
return
addh
;
if
(
addh
.
first
==
0
)
return
oldh
;
/* If we are adding things at different positions, something is wrong. */
if
(
strcmp
(
oldh
.
first
->
position
,
addh
.
first
->
position
))
abort
();
for
(
add
=
addh
.
first
;
add
;
add
=
next
)
{
enum
machine_mode
add_mode
=
add
->
enforce_mode
?
add
->
mode
:
VOIDmode
;
struct
decision
*
best_position
=
0
;
int
best_merit
=
4
;
struct
decision
*
old
;
next
=
add
->
next
;
/* The semantics of pattern matching state that the tests are done in
the order given in the MD file so that if an insn matches two
patterns, the first one will be used. However, in practice, most,
if not all, patterns are unambiguous so that their order is
independent. In that case, we can merge identical tests and
group all similar modes and codes together.
Scan starting from the end of OLDH until we reach a point
where we reach the head of the list or where we pass a pattern
that could also be true if NEW is true. If we find an identical
pattern, we can merge them. Also, record the last node that tests
the same code and mode and the last one that tests just the same mode.
If we have no match, place NEW after the closest match we found. */
for
(
old
=
oldh
.
last
;
old
;
old
=
old
->
prev
)
{
int
our_merit
;
/* If we don't have anything to test except an additional test,
do not consider the two nodes equal. If we did, the test below
would cause an infinite recursion. */
if
(
old
->
tests
==
0
&&
old
->
test_elt_zero_int
==
0
&&
old
->
test_elt_one_int
==
0
&&
old
->
veclen
==
0
&&
old
->
dupno
==
-
1
&&
old
->
mode
==
VOIDmode
&&
old
->
code
==
UNKNOWN
&&
(
old
->
c_test
!=
0
||
add
->
c_test
!=
0
))
;
else
if
((
old
->
tests
==
add
->
tests
||
(
old
->
pred
>=
0
&&
old
->
pred
==
add
->
pred
)
||
(
old
->
tests
&&
add
->
tests
&&
!
strcmp
(
old
->
tests
,
add
->
tests
)))
&&
old
->
test_elt_zero_int
==
add
->
test_elt_zero_int
&&
old
->
elt_zero_int
==
add
->
elt_zero_int
&&
old
->
test_elt_one_int
==
add
->
test_elt_one_int
...
...
@@ -553,263 +760,440 @@ try_merge_1 (old, add)
&&
old
->
veclen
==
add
->
veclen
&&
old
->
dupno
==
add
->
dupno
&&
old
->
opno
==
add
->
opno
/* In a collection of nodes that don't have predicates,
we can always merge a new one with any node that matches it.
This is because we know that two different nodes can't possibly match
the same RTL object. So we can reorder the tests to simplify the
whole collection of them.
But when predicates are involved, we have to preserve the order of
testing them. This means that a new node can only be merged with the
last existing node.
enforce_mode indicates that at this level each of the nodes
requires a particular mode. When this is true, then we know
that two nodes with different modes can't possibly both match.
Therefore, it is ok to merge a new node with the last node
that wants the same mode, even if other nodes for different modes
appear after it. no_same_mode tests for this condition. */
&&
(
old
->
tests
==
0
||
(
add
->
enforce_mode
?
no_same_mode
(
old
)
:
old
->
next
==
0
))
&&
old
->
code
==
add
->
code
&&
old
->
mode
==
add
->
mode
&&
(
old
->
exact
==
add
->
exact
||
(
old
->
exact
&&
add
->
exact
&&
!
strcmp
(
old
->
exact
,
add
->
exact
))))
&&
old
->
enforce_mode
==
add
->
enforce_mode
&&
old
->
mode
==
add
->
mode
)
{
/* If the additional test is not the same, split both nodes
into nodes that just contain all things tested before the
additional test and nodes that contain the additional test
and actions when it is true. This optimization is important
because of the case where we have almost identical patterns
with different tests on target flags. */
if
(
old
->
c_test
!=
add
->
c_test
&&
!
(
old
->
c_test
&&
add
->
c_test
&&
!
strcmp
(
old
->
c_test
,
add
->
c_test
)))
{
if
(
old
->
insn_code_number
>=
0
||
old
->
opno
>=
0
)
{
struct
decision
*
split
=
(
struct
decision
*
)
xmalloc
(
sizeof
(
struct
decision
));
mybcopy
(
old
,
split
,
sizeof
(
struct
decision
));
old
->
success
.
first
=
old
->
success
.
last
=
split
;
old
->
c_test
=
0
;
old
->
opno
=
-
1
;
old
->
insn_code_number
=
-
1
;
old
->
num_clobbers_to_add
=
0
;
split
->
number
=
next_number
++
;
split
->
next
=
split
->
prev
=
0
;
split
->
mode
=
VOIDmode
;
split
->
code
=
UNKNOWN
;
split
->
veclen
=
0
;
split
->
test_elt_zero_int
=
0
;
split
->
test_elt_one_int
=
0
;
split
->
tests
=
0
;
split
->
pred
=
-
1
;
}
if
(
add
->
insn_code_number
>=
0
||
add
->
opno
>=
0
)
{
struct
decision
*
split
=
(
struct
decision
*
)
xmalloc
(
sizeof
(
struct
decision
));
mybcopy
(
add
,
split
,
sizeof
(
struct
decision
));
add
->
success
.
first
=
add
->
success
.
last
=
split
;
add
->
c_test
=
0
;
add
->
opno
=
-
1
;
add
->
insn_code_number
=
-
1
;
add
->
num_clobbers_to_add
=
0
;
split
->
number
=
next_number
++
;
split
->
next
=
split
->
prev
=
0
;
split
->
mode
=
VOIDmode
;
split
->
code
=
UNKNOWN
;
split
->
veclen
=
0
;
split
->
test_elt_zero_int
=
0
;
split
->
test_elt_one_int
=
0
;
split
->
tests
=
0
;
split
->
pred
=
-
1
;
}
}
old
->
success
=
merge_trees
(
old
->
success
,
add
->
success
);
if
(
old
->
insn_code_number
>=
0
&&
add
->
insn_code_number
>=
0
)
fatal
(
"Two actions at one point in tree"
);
if
(
old
->
insn_code_number
==
-
1
)
old
->
insn_code_number
=
add
->
insn_code_number
;
return
1
;
}
old
=
old
->
next
;
add
=
0
;
break
;
}
return
0
;
}
/* Merge ADD into the next-chain that starts with OLD,
preferably after something that tests the same place
that ADD does.
The next-chain of ADD itself is ignored, and it is set
up for entering ADD into the new chain.
Returns the new chain. */
/* Unless we have already found the best possible insert point,
see if this position is better. If so, record it. */
static
struct
decision
*
try_merge_2
(
old
,
add
)
struct
decision
*
old
,
*
add
;
{
register
struct
decision
*
p
;
struct
decision
*
last
=
0
;
struct
decision
*
last_same_place
=
0
;
if
(
best_merit
!=
0
&&
((
our_merit
=
position_merit
(
old
,
add_mode
,
add
->
code
))
<
best_merit
))
best_merit
=
our_merit
,
best_position
=
old
;
/* Put this in after the others that test the same place,
if there are any. If not, find the last chain element
and insert there.
if
(
!
not_both_true
(
old
,
add
,
0
))
break
;
}
One modification: if this one is NOT a MATCH_OPERAND,
put it before any MATCH_OPERANDS that test the same place.
/* If ADD was duplicate, we are done. */
if
(
add
==
0
)
continue
;
Another: if enforce_mode (i.e. this is first operand of a SET),
put this after the last thing that tests the same place for
the same mode
. */
/* Otherwise, find the best place to insert ADD. Normally this is
BEST_POSITION. However, if we went all the way to the top of
the list, it might be better to insert at the top
. */
#if 0
int operand = 0 != add->tests;
#endif
if
(
best_position
==
0
)
abort
();
for
(
p
=
old
;
p
;
p
=
p
->
next
)
{
if
(
p
->
position
==
add
->
position
||
(
p
->
position
&&
add
->
position
&&
!
strcmp
(
p
->
position
,
add
->
position
)))
if
(
old
==
0
&&
position_merit
(
0
,
add_mode
,
add
->
code
)
<
best_merit
)
{
last_same_place
=
p
;
/* If enforce_mode, segregate the modes in numerical order. */
if
(
p
->
enforce_mode
&&
(
int
)
add
->
mode
<
(
int
)
p
->
mode
)
break
;
#if 0
/* Keep explicit decompositions before those that test predicates.
If enforce_mode, do this separately within each mode. */
if (! p->enforce_mode || p->mode == add->mode)
if (!operand && p->tests)
break;
#endif
add
->
prev
=
0
;
add
->
next
=
oldh
.
first
;
oldh
.
first
->
prev
=
add
;
oldh
.
first
=
add
;
}
/* If this is past the end of the decisions at the same place as ADD,
stop looking now; add ADD before here. */
else
if
(
last_same_place
)
break
;
last
=
p
;
}
/* Insert before P, which means after LAST. */
if
(
last
)
else
{
add
->
next
=
last
->
next
;
last
->
next
=
add
;
return
old
;
add
->
prev
=
best_position
;
add
->
next
=
best_position
->
next
;
best_position
->
next
=
add
;
if
(
best_position
==
oldh
.
last
)
oldh
.
last
=
add
;
else
add
->
next
->
prev
=
add
;
}
}
add
->
next
=
old
;
return
add
;
return
oldh
;
}
static
int
no_same_mode
(
node
)
struct
decision
*
node
;
{
register
struct
decision
*
p
;
register
enum
machine_mode
mode
=
node
->
mode
;
for
(
p
=
node
->
next
;
p
;
p
=
p
->
next
)
if
(
p
->
mode
==
mode
)
return
0
;
return
1
;
}
/* Count the number of subnodes of HEAD. If the number is high enough,
make the first node in HEAD start a separate subroutine in the C code
that is generated.
/* Count the number of subnodes of node NODE, assumed to be the start
of a next-chain. If the number is high enough, make NODE start
a separate subroutine in the C code that is generated.
TYPE gives the type of routine we are writing.
TYPE gives the type of routine we are writing. */
INITIAL is non-zero if this is the highest-level node. We never write
it out here. */
static
int
break_out_subroutines
(
node
,
type
)
struct
decision
*
node
;
break_out_subroutines
(
head
,
type
,
initial
)
struct
decision
_head
head
;
enum
routine_type
type
;
int
initial
;
{
int
size
=
0
;
struct
decision
*
sub
;
for
(
sub
=
node
;
sub
;
sub
=
sub
->
next
)
size
+=
1
+
break_out_subroutines
(
sub
->
success
,
type
);
if
(
size
>
SUBROUTINE_THRESHOLD
)
struct
decision
*
node
,
*
sub
;
for
(
sub
=
head
.
first
;
sub
;
sub
=
sub
->
next
)
size
+=
1
+
break_out_subroutines
(
sub
->
success
,
type
,
0
);
if
(
size
>
SUBROUTINE_THRESHOLD
&&
!
initial
)
{
node
->
subroutine_number
=
++
next_subroutine_number
;
write_subroutine
(
node
,
type
);
head
.
first
->
subroutine_number
=
++
next_subroutine_number
;
write_subroutine
(
head
.
first
,
type
);
size
=
1
;
}
return
size
;
}
/* Write out a subroutine of type TYPE to do comparisons starting at node
TREE. */
static
void
write_subroutine
(
tree
,
type
)
struct
decision
*
tree
;
enum
routine_type
type
;
{
char
*
return_type
=
(
type
==
SPLIT
?
"rtx"
:
"int"
)
;
int
i
;
if
(
type
==
SPLIT
)
{
printf
(
"rtx
\n
split_%d (x0, insn)
\n
"
,
tree
->
subroutine_number
);
printf
(
" register rtx x0;
\n
rtx insn;
\n
"
);
}
printf
(
"rtx
\n
split"
);
else
{
printf
(
"int
\n
recog_%d (x0, insn, pnum_clobbers)
\n
"
,
tree
->
subroutine_number
);
printf
(
"int
\n
recog"
);
if
(
tree
!=
0
&&
tree
->
subroutine_number
>
0
)
printf
(
"_%d"
,
tree
->
subroutine_number
);
else
if
(
type
==
SPLIT
)
printf
(
"_insns"
);
printf
(
" (x0, insn"
);
if
(
type
==
RECOG
)
printf
(
", pnum_clobbers"
);
printf
(
")
\n
"
);
printf
(
" register rtx x0;
\n
rtx insn;
\n
"
);
if
(
type
==
RECOG
)
printf
(
" int *pnum_clobbers;
\n
"
);
}
printf
(
"{
\n
"
);
printf
(
" register rtx *ro = &recog_operand[0];
\n
"
);
printf
(
" register rtx x1, x2, x3, x4, x5;
\n
rtx x6, x7, x8, x9, x10, x11;
\n
"
);
printf
(
" %s tem;
\n
"
,
return_type
);
write_tree
(
tree
,
""
,
0
,
""
,
1
,
type
);
printf
(
" register rtx "
);
for
(
i
=
1
;
i
<
max_depth
;
i
++
)
printf
(
"x%d, "
,
i
);
printf
(
"x%d;
\n
"
,
max_depth
);
printf
(
" %s tem;
\n
"
,
type
==
SPLIT
?
"rtx"
:
"int"
);
write_tree
(
tree
,
""
,
0
,
1
,
type
);
printf
(
" ret0: return %d;
\n
}
\n\n
"
,
type
==
SPLIT
?
0
:
-
1
);
}
/* Write out C code to perform the decisions in the tree. */
/* This table is used to indent the recog_* functions when we are inside
conditions or switch statements. We only support small indentations
and always indent at least two spaces. */
static
char
*
write_tree_1
(
tree
,
prevpos
,
afterward
,
afterpos
,
initial
,
type
)
static
char
*
indents
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"
\t
"
,
"
\t
"
,
"
\t
"
,
"
\t
"
,
"
\t
"
,
"
\t
"
,
"
\t
"
,
"
\t\t
"
,
"
\t\t
"
,
"
\t\t
"
,
"
\t\t
"
,
"
\t\t
"
,
"
\t\t
"
};
/* Write out C code to perform the decisions in TREE for a subroutine of
type TYPE. If all of the choices fail, branch to node AFTERWARD, if
non-zero, otherwise return. PREVPOS is the position of the node that
branched to this test.
When we merged all alternatives, we tried to set up a convenient order.
Specifically, tests involving the same mode are all grouped together,
followed by a group that does not contain a mode test. Within each group
of the same mode, we also group tests with the same code, followed by a
group that does not test a code.
Occasionally, we cannot arbitarily reorder the tests so that multiple
sequence of groups as described above are present.
We generate two nested switch statements, the outer statement for
testing modes, and the inner switch for testing RTX codes. It is
not worth optimizing cases when only a small number of modes or
codes is tested, since the compiler can do that when compiling the
resulting function. We do check for when every test is the same mode
or code. */
void
write_tree_1
(
tree
,
prevpos
,
afterward
,
type
)
struct
decision
*
tree
;
char
*
prevpos
;
int
afterward
;
char
*
afterpos
;
int
initial
;
struct
decision
*
afterward
;
enum
routine_type
type
;
{
register
struct
decision
*
p
,
*
p1
;
char
*
pos
;
register
int
depth
;
int
ignmode
;
enum
anon1
{
NO_SWITCH
,
CODE_SWITCH
,
MODE_SWITCH
}
in_switch
=
NO_SWITCH
;
register
int
depth
=
tree
?
strlen
(
tree
->
position
)
:
0
;
enum
machine_mode
switch_mode
=
VOIDmode
;
RTX_CODE
switch_code
=
UNKNOWN
;
int
uncond
=
0
;
char
modemap
[
NUM_MACHINE_MODES
];
char
codemap
[
NUM_RTX_CODE
];
int
indent
=
2
;
int
i
;
/* One tricky area is what is the exact state when we branch to a
node's label. There are two cases where we branch: when looking at
successors to a node, or when a set of tests fails.
In the former case, we are always branching to the first node in a
decision list and we want all required tests to be performed. We
put the labels for such nodes in front of any switch or test statements.
These branches are done without updating the position to that of the
target node.
In the latter case, we are branching to a node that is not the first
node in a decision list. We have already checked that it is possible
for both the node we originally tested at this level and the node we
are branching to to be both match some pattern. That means that they
usually will be testing the same mode and code. So it is normally safe
for such labels to be inside switch statements, since the tests done
by virtue of arriving at that label will usually already have been
done. The exception is a branch from a node that does not test a
mode or code to one that does. In such cases, we set the `retest_mode'
or `retest_code' flags. That will ensure that we start a new switch
at that position and put the label before the switch.
The branches in the latter case must set the position to that of the
target node. */
pos
=
prevpos
;
tree
->
label_needed
=
1
;
printf
(
"
\n
"
);
if
(
tree
&&
tree
->
subroutine_number
==
0
)
{
printf
(
" L%d:
\n
"
,
tree
->
number
);
tree
->
label_needed
=
0
;
}
if
(
tree
)
{
change_state
(
prevpos
,
tree
->
position
,
2
);
prevpos
=
tree
->
position
;
}
for
(
p
=
tree
;
p
;
p
=
p
->
next
)
{
/* Find the next alternative to p
that might be true when p is true.
Test that one next if p's successors fail.
Note that when the `tests' field is nonzero
it is up to the specified test-function to compare machine modes
and some (such as general_operand) don't always do so.
But when inside a switch-on-modes we ignore this and
consider all modes mutually exclusive. */
for
(
p1
=
p
->
next
;
p1
;
p1
=
p1
->
next
)
if
(((
p
->
code
==
UNKNOWN
||
p1
->
code
==
UNKNOWN
||
p
->
code
==
p1
->
code
)
&&
(
p
->
mode
==
VOIDmode
||
p1
->
mode
==
VOIDmode
||
p
->
mode
==
p1
->
mode
||
(
in_switch
!=
MODE_SWITCH
&&
(
p
->
tests
||
p1
->
tests
))))
||
strcmp
(
p1
->
position
,
p
->
position
))
break
;
enum
machine_mode
mode
=
p
->
enforce_mode
?
p
->
mode
:
VOIDmode
;
int
inner_indent
;
if
(
p
->
success
.
first
==
0
&&
p
->
insn_code_number
<
0
)
abort
();
/* Find the next alternative to p that might be true when p is true.
Test that one next if p's successors fail. */
for
(
p1
=
p
->
next
;
p1
&&
not_both_true
(
p
,
p1
,
1
);
p1
=
p1
->
next
)
;
p
->
afterward
=
p1
;
if
(
p1
)
p1
->
label_needed
=
1
;
if
(
in_switch
==
MODE_SWITCH
&&
(
p
->
mode
==
VOIDmode
||
(
!
p
->
enforce_mode
&&
p
->
tests
!=
0
)))
if
(
p1
)
{
in_switch
=
NO_SWITCH
;
printf
(
" }
\n
"
);
if
(
mode
==
VOIDmode
&&
p1
->
enforce_mode
&&
p1
->
mode
!=
VOIDmode
)
p1
->
retest_mode
=
1
;
if
(
p
->
code
==
UNKNOWN
&&
p1
->
code
!=
UNKNOWN
)
p1
->
retest_code
=
1
;
p1
->
label_needed
=
1
;
}
if
(
in_switch
==
CODE_SWITCH
&&
p
->
code
==
UNKNOWN
)
/* If we have a different code or mode than the last node and
are in a switch on codes, we must either end the switch or
go to another case. We must also end the switch if this
node needs a label and to retest either the mode or code. */
if
(
switch_code
!=
UNKNOWN
&&
(
switch_code
!=
p
->
code
||
switch_mode
!=
mode
||
(
p
->
label_needed
&&
(
p
->
retest_mode
||
p
->
retest_code
))))
{
enum
rtx_code
code
=
p
->
code
;
/* If P is testing a predicate that we know about and we haven't
seen any of the codes that are valid for the predicate, we
can write a series of "case" statement, one for each possible
code. Since we are already in a switch, these redundant tests
are very cheap and will reduce the number of predicate called. */
if
(
p
->
pred
>=
0
)
{
in_switch
=
NO_SWITCH
;
printf
(
" }
\n
"
);
for
(
i
=
0
;
i
<
NUM_RTX_CODE
&&
preds
[
p
->
pred
].
codes
[
i
];
i
++
)
if
(
codemap
[(
int
)
preds
[
p
->
pred
].
codes
[
i
]])
break
;
if
(
preds
[
p
->
pred
].
codes
[
i
]
==
0
)
code
=
MATCH_OPERAND
;
}
if
(
p
->
label_needed
)
printf
(
" L%d:
\n
"
,
p
->
number
);
if
(
code
==
UNKNOWN
||
codemap
[(
int
)
code
]
||
switch_mode
!=
mode
||
(
p
->
label_needed
&&
(
p
->
retest_mode
||
p
->
retest_code
)))
{
printf
(
"%s}
\n
"
,
indents
[
indent
-
2
]);
switch_code
=
UNKNOWN
;
indent
-=
4
;
}
else
{
if
(
!
uncond
)
printf
(
"%sbreak;
\n
"
,
indents
[
indent
]);
if
(
code
==
MATCH_OPERAND
)
{
for
(
i
=
0
;
i
<
NUM_RTX_CODE
&&
preds
[
p
->
pred
].
codes
[
i
];
i
++
)
{
printf
(
"%scase "
,
indents
[
indent
-
2
]);
print_code
(
preds
[
p
->
pred
].
codes
[
i
]);
printf
(
":
\n
"
);
codemap
[(
int
)
preds
[
p
->
pred
].
codes
[
i
]]
=
1
;
}
}
else
{
printf
(
"%scase "
,
indents
[
indent
-
2
]);
print_code
(
code
);
printf
(
":
\n
"
);
codemap
[(
int
)
p
->
code
]
=
1
;
}
switch_code
=
code
;
}
if
(
p
->
success
==
0
&&
p
->
insn_code_number
<
0
)
uncond
=
0
;
}
/* If we were previously in a switch on modes and now have a different
mode, end at least the case, and maybe end the switch if we are
not testing a mode or testing a mode whose case we already saw. */
if
(
switch_mode
!=
VOIDmode
&&
(
switch_mode
!=
mode
||
(
p
->
label_needed
&&
p
->
retest_mode
)))
{
if
(
mode
==
VOIDmode
||
modemap
[(
int
)
mode
]
||
(
p
->
label_needed
&&
p
->
retest_mode
))
{
printf
(
"%s}
\n
"
,
indents
[
indent
-
2
]);
switch_mode
=
VOIDmode
;
indent
-=
4
;
}
else
{
if
(
!
uncond
)
printf
(
" break;
\n
"
);
printf
(
" case %smode:
\n
"
,
GET_MODE_NAME
(
mode
));
switch_mode
=
mode
;
modemap
[(
int
)
mode
]
=
1
;
}
uncond
=
0
;
}
/* If we are about to write dead code, something went wrong. */
if
(
!
p
->
label_needed
&&
uncond
)
abort
();
change_state
(
pos
,
p
->
position
);
pos
=
p
->
position
;
depth
=
strlen
(
pos
);
/* If we need a label and we will want to retest the mode or code at
that label, write the label now. We have already ensured that
things will be valid for the test. */
if
(
p
->
label_needed
&&
(
p
->
retest_mode
||
p
->
retest_code
))
{
printf
(
"%sL%d:
\n
"
,
indents
[
indent
-
2
],
p
->
number
);
p
->
label_needed
=
0
;
}
ignmode
=
(
p
->
ignmode
||
p
->
tests
)
;
uncond
=
0
;
if
(
in_switch
==
NO_SWITCH
)
/* If we are not in any switches, see if we can shortcut things
by checking for identical modes and codes. */
if
(
switch_mode
==
VOIDmode
&&
switch_code
==
UNKNOWN
)
{
/* If p and its alternatives all want the same mode,
reject all others at once, first, then ignore the mode. */
if
(
!
ignmode
&&
p
->
mode
!=
VOIDmode
&&
p
->
next
&&
same_modes
(
p
,
p
->
mode
))
if
(
mode
!=
VOIDmode
&&
p
->
next
&&
same_modes
(
p
,
mode
))
{
printf
(
" if (GET_MODE (x%d) != %smode)
\n
"
,
depth
,
GET_MODE_NAME
(
p
->
mode
));
if
(
afterward
)
{
printf
(
" {
\n
"
);
change_state
(
p
os
,
afterpos
);
printf
(
" goto L%d;
\n
}
\n
"
,
afterward
);
printf
(
" {
\n
"
);
change_state
(
p
->
position
,
afterward
->
position
,
6
);
printf
(
" goto L%d;
\n
}
\n
"
,
afterward
->
number
);
}
else
printf
(
" goto ret0;
\n
"
);
clear_modes
(
p
);
ignmode
=
1
;
mode
=
VOIDmode
;
}
/* If p and its alternatives all want the same code,
reject all others at once, first, then ignore the code. */
if
(
p
->
code
!=
UNKNOWN
&&
p
->
next
&&
same_codes
(
p
,
p
->
code
))
{
printf
(
" if (GET_CODE (x%d) != "
,
depth
);
...
...
@@ -817,9 +1201,9 @@ write_tree_1 (tree, prevpos, afterward, afterpos, initial, type)
printf
(
")
\n
"
);
if
(
afterward
)
{
printf
(
" {"
);
change_state
(
p
os
,
afterpos
);
printf
(
" goto L%d;
}
\n
"
,
afterward
);
printf
(
" {
\n
"
);
change_state
(
p
->
position
,
afterward
->
position
,
indent
+
4
);
printf
(
" goto L%d;
\n
}
\n
"
,
afterward
->
number
);
}
else
printf
(
" goto ret0;
\n
"
);
...
...
@@ -827,223 +1211,170 @@ write_tree_1 (tree, prevpos, afterward, afterpos, initial, type)
}
}
/* If p and its alternatives all have different modes
and there are at least 4 of them, make a switch. */
if
(
in_switch
==
NO_SWITCH
)
{
register
int
i
;
int
lose
=
0
;
/* If we are not in a mode switch and we are testing for a specific
mode, start a mode switch unless we have just one node or the next
node is not testing a mode (we have already tested for the case of
more than one mode, but all of the same mode). */
mybzero
(
modemap
,
sizeof
modemap
);
for
(
p1
=
p
,
i
=
0
;
(
p1
&&
p1
->
mode
!=
VOIDmode
&&
(
p1
->
tests
==
0
||
p1
->
enforce_mode
));
p1
=
p1
->
next
,
i
++
)
{
if
(
!
p
->
enforce_mode
&&
modemap
[(
int
)
p1
->
mode
])
{
lose
=
1
;
break
;
}
modemap
[(
int
)
p1
->
mode
]
=
1
;
}
if
(
!
lose
&&
i
>=
4
)
if
(
switch_mode
==
VOIDmode
&&
mode
!=
VOIDmode
&&
p
->
next
!=
0
&&
p
->
next
->
enforce_mode
&&
p
->
next
->
mode
!=
VOIDmode
)
{
in_switch
=
MODE_SWITCH
;
printf
(
" switch (GET_MODE (x%d))
\n
{
\n
"
,
depth
);
}
mybzero
(
modemap
,
sizeof
modemap
);
printf
(
"%sswitch (GET_MODE (x%d))
\n
"
,
indents
[
indent
],
depth
);
printf
(
"%s{
\n
"
,
indents
[
indent
+
2
]);
indent
+=
4
;
printf
(
"%scase %smode:
\n
"
,
indents
[
indent
-
2
],
GET_MODE_NAME
(
mode
));
modemap
[(
int
)
mode
]
=
1
;
switch_mode
=
mode
;
}
if
(
in_switch
==
NO_SWITCH
)
{
register
int
i
;
mybzero
(
codemap
,
sizeof
codemap
);
for
(
p1
=
p
,
i
=
0
;
p1
&&
p1
->
code
!=
UNKNOWN
;
p1
=
p1
->
next
,
i
++
)
{
if
(
codemap
[(
int
)
p1
->
code
])
break
;
codemap
[(
int
)
p1
->
code
]
=
1
;
}
if
((
p1
==
0
||
p1
->
code
==
UNKNOWN
)
&&
i
>=
4
)
{
in_switch
=
CODE_SWITCH
;
printf
(
" switch (GET_CODE (x%d))
\n
{
\n
"
,
depth
);
}
}
/* Similarly for testing codes. */
if
(
in_switch
==
MODE_SWITCH
)
if
(
switch_code
==
UNKNOWN
&&
p
->
code
!=
UNKNOWN
&&
!
p
->
ignore_code
&&
p
->
next
!=
0
&&
p
->
next
->
code
!=
UNKNOWN
)
{
if
(
modemap
[(
int
)
p
->
mode
])
{
printf
(
" case %smode:
\n
"
,
GET_MODE_NAME
(
p
->
mode
));
modemap
[(
int
)
p
->
mode
]
=
0
;
}
}
if
(
in_switch
==
CODE_SWITCH
)
{
if
(
codemap
[(
int
)
p
->
code
])
{
printf
(
" case "
);
mybzero
(
codemap
,
sizeof
codemap
);
printf
(
"%sswitch (GET_CODE (x%d))
\n
"
,
indents
[
indent
],
depth
);
printf
(
"%s{
\n
"
,
indents
[
indent
+
2
]);
indent
+=
4
;
printf
(
"%scase "
,
indents
[
indent
-
2
]);
print_code
(
p
->
code
);
printf
(
":
\n
"
);
codemap
[(
int
)
p
->
code
]
=
0
;
}
codemap
[(
int
)
p
->
code
]
=
1
;
switch_code
=
p
->
code
;
}
printf
(
" if ("
);
if
(
p
->
exact
||
(
p
->
code
!=
UNKNOWN
&&
in_switch
!=
CODE_SWITCH
))
/* Now that most mode and code tests have been done, we can write out
a label for an inner node, if we haven't already. */
if
(
p
->
label_needed
)
printf
(
"%sL%d:
\n
"
,
indents
[
indent
-
2
],
p
->
number
);
inner_indent
=
indent
;
/* The only way we can have to do a mode or code test here is if
this node needs such a test but is the only node to be tested.
In that case, we won't have started a switch. Note that this is
the only way the switch and test modes can disagree. */
if
((
mode
!=
switch_mode
&&
!
p
->
ignore_mode
)
||
(
p
->
code
!=
switch_code
&&
p
->
code
!=
UNKNOWN
&&
!
p
->
ignore_code
)
||
p
->
test_elt_zero_int
||
p
->
test_elt_one_int
||
p
->
veclen
||
p
->
dupno
>=
0
||
p
->
tests
||
p
->
num_clobbers_to_add
)
{
if
(
p
->
exact
)
printf
(
"x%d == %s"
,
depth
,
p
->
exact
);
else
printf
(
"%sif ("
,
indents
[
indent
]);
if
(
mode
!=
switch_mode
&&
!
p
->
ignore_mode
)
printf
(
"GET_MODE (x%d) == %smode && "
,
depth
,
GET_MODE_NAME
(
mode
));
if
(
p
->
code
!=
switch_code
&&
p
->
code
!=
UNKNOWN
&&
!
p
->
ignore_code
)
{
printf
(
"GET_CODE (x%d) == "
,
depth
);
print_code
(
p
->
code
);
}
printf
(
" && "
);
}
if
(
p
->
mode
!=
VOIDmode
&&
!
ignmode
&&
in_switch
!=
MODE_SWITCH
)
printf
(
"GET_MODE (x%d) == %smode && "
,
depth
,
GET_MODE_NAME
(
p
->
mode
));
if
(
p
->
test_elt_zero_int
)
printf
(
"XINT (x%d, 0) == %d && "
,
depth
,
p
->
elt_zero_int
);
if
(
p
->
veclen
)
printf
(
"XVECLEN (x%d, 0) == %d && "
,
depth
,
p
->
veclen
);
if
(
p
->
test_elt_one_int
)
printf
(
"XINT (x%d, 1) == %d && "
,
depth
,
p
->
elt_one_int
);
if
(
p
->
veclen
)
printf
(
"XVECLEN (x%d, 0) == %d && "
,
depth
,
p
->
veclen
);
if
(
p
->
dupno
>=
0
)
printf
(
"rtx_equal_p (x%d, ro[%d]) && "
,
depth
,
p
->
dupno
);
if
(
p
->
num_clobbers_to_add
)
printf
(
"pnum_clobbers != 0 && "
);
if
(
p
->
tests
)
printf
(
"%s (x%d, %smode)"
,
p
->
tests
,
depth
,
GET_MODE_NAME
(
p
->
mode
));
else
printf
(
"1"
);
printf
(
")
\n
"
);
inner_indent
+=
2
;
}
else
uncond
=
1
;
if
(
p
->
opno
>=
0
)
printf
(
")
\n
{ ro[%d] = x%d; "
,
{
printf
(
"%s{
\n
%sro[%d] = x%d;
\n
"
,
indents
[
inner_indent
],
indents
[
inner_indent
+
2
],
p
->
opno
,
depth
);
else
printf
(
")
\n
"
);
inner_indent
+=
2
;
}
if
(
p
->
c_test
)
printf
(
"if (%s) "
,
p
->
c_test
);
{
printf
(
"%sif (%s)
\n
"
,
indents
[
inner_indent
],
p
->
c_test
);
inner_indent
+=
2
;
uncond
=
0
;
}
if
(
p
->
insn_code_number
>=
0
)
{
if
(
type
==
SPLIT
)
printf
(
"return gen_split_%d (operands);"
,
p
->
insn_code_number
);
printf
(
"%sreturn gen_split_%d (operands);
\n
"
,
indents
[
inner_indent
],
p
->
insn_code_number
);
else
{
if
(
p
->
num_clobbers_to_add
)
{
printf
(
"
\n
{
\n
"
);
printf
(
"
\t
if (pnum_clobbers == 0) goto ret0; "
);
printf
(
"*pnum_clobbers = %d; "
,
p
->
num_clobbers_to_add
);
printf
(
"return %d;
\n
}"
,
p
->
insn_code_number
);
if
(
p
->
opno
<
0
||
p
->
c_test
)
{
printf
(
"%s{
\n
"
,
indents
[
inner_indent
]);
inner_indent
+=
2
;
}
printf
(
"%s*pnum_clobbers = %d;
\n
"
,
indents
[
inner_indent
],
p
->
num_clobbers_to_add
);
printf
(
"%sreturn %d;
\n
"
,
indents
[
inner_indent
],
p
->
insn_code_number
);
if
(
p
->
opno
<
0
||
p
->
c_test
)
{
inner_indent
-=
2
;
printf
(
"%s}
\n
"
,
indents
[
inner_indent
]);
}
}
else
printf
(
"return %d;"
,
p
->
insn_code_number
);
printf
(
"%sreturn %d;
\n
"
,
indents
[
inner_indent
],
p
->
insn_code_number
);
}
}
else
printf
(
"goto L%d;"
,
p
->
success
->
number
);
printf
(
"%sgoto L%d;
\n
"
,
indents
[
inner_indent
],
p
->
success
.
first
->
number
);
if
(
p
->
opno
>=
0
)
printf
(
" }
\n
"
);
else
printf
(
"
\n
"
);
printf
(
"%s}
\n
"
,
indents
[
inner_indent
-
2
]);
}
/* Now, if inside a switch, branch to next switch member
that might also need to be tested if this one fails
. */
/* We have now tested all alternatives. End any switches we have open
and branch to the alternative node
. */
if
(
in_switch
==
CODE_SWITCH
)
if
(
switch_code
!=
UNKNOWN
)
{
/* Find the next alternative to p
that might be applicable if p was applicable. */
for
(
p1
=
p
->
next
;
p1
;
p1
=
p1
->
next
)
if
(
p1
->
code
==
UNKNOWN
||
p
->
code
==
p1
->
code
)
break
;
if
(
p1
==
0
||
p1
->
code
==
UNKNOWN
)
printf
(
" break;
\n
"
);
else
if
(
p1
!=
p
->
next
)
{
printf
(
" goto L%d;
\n
"
,
p1
->
number
);
p1
->
label_needed
=
1
;
}
printf
(
"%s}
\n
"
,
indents
[
indent
-
2
]);
indent
-=
4
;
}
if
(
in_switch
==
MODE_SWITCH
)
{
/* Find the next alternative to p
that might be applicable if p was applicable. */
for
(
p1
=
p
->
next
;
p1
;
p1
=
p1
->
next
)
if
(
p1
->
mode
==
VOIDmode
||
p
->
mode
==
p1
->
mode
)
break
;
if
(
p1
==
0
||
p1
->
mode
==
VOIDmode
)
printf
(
" break;
\n
"
);
else
if
(
p1
!=
p
->
next
)
if
(
switch_mode
!=
VOIDmode
)
{
printf
(
" goto L%d;
\n
"
,
p1
->
number
);
p1
->
label_needed
=
1
;
}
}
printf
(
"%s}
\n
"
,
indents
[
indent
-
2
]);
indent
-=
4
;
}
if
(
in
_switch
!=
NO_SWITCH
)
printf
(
" }
\n
"
);
if
(
in
dent
!=
2
)
abort
(
);
if
(
afterward
)
{
change_state
(
p
os
,
afterpos
);
printf
(
" goto L%d;
\n
"
,
afterward
);
change_state
(
p
revpos
,
afterward
->
position
,
2
);
printf
(
" goto L%d;
\n
"
,
afterward
->
number
);
}
else
printf
(
" goto ret0;
\n
"
);
return
pos
;
}
static
void
write_tree
(
tree
,
prevpos
,
afterward
,
afterpos
,
initial
,
type
)
struct
decision
*
tree
;
char
*
prevpos
;
int
afterward
;
char
*
afterpos
;
int
initial
;
enum
routine_type
type
;
{
register
struct
decision
*
p
;
char
*
pos
=
prevpos
;
char
*
name_prefix
=
(
type
==
SPLIT
?
"split"
:
"recog"
);
char
*
call_suffix
=
(
type
==
SPLIT
?
""
:
", pnum_clobbers"
);
if
(
tree
->
subroutine_number
>
0
&&
!
initial
)
{
printf
(
" L%d:
\n
"
,
tree
->
number
);
if
(
afterward
)
{
printf
(
" tem = %s_%d (x0, insn%s);
\n
"
,
name_prefix
,
tree
->
subroutine_number
,
call_suffix
);
printf
(
" if (tem >= 0) return tem;
\n
"
);
change_state
(
pos
,
afterpos
);
printf
(
" goto L%d;
\n
"
,
afterward
);
}
else
printf
(
" return %s_%d (x0, insn%s);
\n
"
,
name_prefix
,
tree
->
subroutine_number
,
call_suffix
);
return
;
}
pos
=
write_tree_1
(
tree
,
prevpos
,
afterward
,
afterpos
,
initial
,
type
);
for
(
p
=
tree
;
p
;
p
=
p
->
next
)
if
(
p
->
success
)
{
pos
=
p
->
position
;
write_tree
(
p
->
success
,
pos
,
p
->
afterward
?
p
->
afterward
->
number
:
afterward
,
p
->
afterward
?
pos
:
afterpos
,
0
,
type
);
}
}
static
void
...
...
@@ -1077,7 +1408,7 @@ clear_codes (p)
register
struct
decision
*
p
;
{
for
(;
p
;
p
=
p
->
next
)
p
->
code
=
UNKNOWN
;
p
->
ignore_code
=
1
;
}
static
int
...
...
@@ -1097,13 +1428,66 @@ clear_modes (p)
register
struct
decision
*
p
;
{
for
(;
p
;
p
=
p
->
next
)
p
->
ignmode
=
1
;
p
->
enforce_mode
=
0
;
}
/* Write out the decision tree starting at TREE for a subroutine of type TYPE.
PREVPOS is the position at the node that branched to this node.
INITIAL is nonzero if this is the first node we are writing in a subroutine.
If all nodes are false, branch to the node AFTERWARD. */
static
void
change_state
(
oldpos
,
newpos
)
write_tree
(
tree
,
prevpos
,
afterward
,
initial
,
type
)
struct
decision
*
tree
;
char
*
prevpos
;
struct
decision
*
afterward
;
int
initial
;
enum
routine_type
type
;
{
register
struct
decision
*
p
;
char
*
name_prefix
=
(
type
==
SPLIT
?
"split"
:
"recog"
);
char
*
call_suffix
=
(
type
==
SPLIT
?
""
:
", pnum_clobbers"
);
if
(
!
initial
&&
tree
->
subroutine_number
>
0
)
{
printf
(
" L%d:
\n
"
,
tree
->
number
);
if
(
afterward
)
{
printf
(
" tem = %s_%d (x0, insn%s);
\n
"
,
name_prefix
,
tree
->
subroutine_number
,
call_suffix
);
printf
(
" if (tem >= 0) return tem;
\n
"
);
change_state
(
tree
->
position
,
afterward
->
position
,
2
);
printf
(
" goto L%d;
\n
"
,
afterward
->
number
);
}
else
printf
(
" return %s_%d (x0, insn%s);
\n
"
,
name_prefix
,
tree
->
subroutine_number
,
call_suffix
);
return
;
}
write_tree_1
(
tree
,
prevpos
,
afterward
,
type
);
for
(
p
=
tree
;
p
;
p
=
p
->
next
)
if
(
p
->
success
.
first
)
write_tree
(
p
->
success
.
first
,
p
->
position
,
p
->
afterward
?
p
->
afterward
:
afterward
,
0
,
type
);
}
/* Assuming that the state of argument is denoted by OLDPOS, take whatever
actions are necessary to move to NEWPOS.
INDENT says how many blanks to place at the front of lines. */
static
void
change_state
(
oldpos
,
newpos
,
indent
)
char
*
oldpos
;
char
*
newpos
;
int
indent
;
{
int
odepth
=
strlen
(
oldpos
);
int
depth
=
odepth
;
...
...
@@ -1119,11 +1503,11 @@ change_state (oldpos, newpos)
while
(
depth
<
ndepth
)
{
if
(
newpos
[
depth
]
>=
'a'
&&
newpos
[
depth
]
<=
'z'
)
printf
(
"
x%d = XVECEXP (x%d, 0, %d);
\n
"
,
depth
+
1
,
depth
,
newpos
[
depth
]
-
'a'
);
printf
(
"
%s
x%d = XVECEXP (x%d, 0, %d);
\n
"
,
indents
[
indent
],
depth
+
1
,
depth
,
newpos
[
depth
]
-
'a'
);
else
printf
(
"
x%d = XEXP (x%d, %c);
\n
"
,
depth
+
1
,
depth
,
newpos
[
depth
]);
printf
(
"
%s
x%d = XEXP (x%d, %c);
\n
"
,
indents
[
indent
],
depth
+
1
,
depth
,
newpos
[
depth
]);
++
depth
;
}
}
...
...
@@ -1152,6 +1536,15 @@ mybzero (b, length)
*
b
++
=
0
;
}
static
void
mybcopy
(
in
,
out
,
length
)
register
char
*
in
,
*
out
;
register
unsigned
length
;
{
while
(
length
--
>
0
)
*
out
++
=
*
in
++
;
}
static
char
*
concat
(
s1
,
s2
)
char
*
s1
,
*
s2
;
...
...
@@ -1219,13 +1612,14 @@ main (argc, argv)
char
**
argv
;
{
rtx
desc
;
struct
decision
*
tree
=
0
;
struct
decision
*
split_tree
=
0
;
struct
decision
_head
recog_tree
;
struct
decision
_head
split_tree
;
FILE
*
infile
;
extern
rtx
read_rtx
();
register
int
c
;
obstack_init
(
rtl_obstack
);
recog_tree
.
first
=
recog_tree
.
last
=
split_tree
.
first
=
split_tree
.
last
=
0
;
if
(
argc
<=
1
)
fatal
(
"No input file name."
);
...
...
@@ -1264,9 +1658,11 @@ from the machine description file `md'. */\n\n");
desc
=
read_rtx
(
infile
);
if
(
GET_CODE
(
desc
)
==
DEFINE_INSN
)
tree
=
merge_trees
(
tree
,
make_insn_sequence
(
desc
));
recog_tree
=
merge_trees
(
recog_tree
,
make_insn_sequence
(
desc
,
RECOG
));
else
if
(
GET_CODE
(
desc
)
==
DEFINE_SPLIT
)
split_tree
=
merge_trees
(
split_tree
,
make_split_sequence
(
desc
));
split_tree
=
merge_trees
(
split_tree
,
make_insn_sequence
(
desc
,
SPLIT
));
if
(
GET_CODE
(
desc
)
==
DEFINE_PEEPHOLE
||
GET_CODE
(
desc
)
==
DEFINE_EXPAND
)
next_insn_code
++
;
...
...
@@ -1294,7 +1690,7 @@ from the machine description file `md'. */\n\n");
PARALLEL of the appropriate size, copy the initial entries, and call
\n
\
add_clobbers (found in insn-emit.c) to fill in the CLOBBERs."
);
if
(
split_tree
)
if
(
split_tree
.
first
)
printf
(
"
\n\n
The function split_insns returns 0 if the rtl could not
\n
\
be split or the split rtl in a SEQUENCE if it can be."
);
...
...
@@ -1307,30 +1703,12 @@ from the machine description file `md'. */\n\n");
printf
(
"#define operands recog_operand
\n\n
"
);
next_subroutine_number
=
0
;
break_out_subroutines
(
tree
,
RECOG
);
printf
(
"int
\n
recog (x0, insn, pnum_clobbers)
\n
"
);
printf
(
" register rtx x0;
\n
rtx insn;
\n
"
);
printf
(
" int *pnum_clobbers;
\n
{
\n
"
);
printf
(
" register rtx *ro = &recog_operand[0];
\n
"
);
printf
(
" register rtx x1, x2, x3, x4, x5;
\n
rtx x6, x7, x8, x9, x10, x11;
\n
"
);
printf
(
" int tem;
\n
"
);
if
(
tree
)
write_tree
(
tree
,
""
,
0
,
""
,
1
,
RECOG
);
printf
(
" ret0: return -1;
\n
}
\n
"
);
break_out_subroutines
(
recog_tree
,
RECOG
,
1
);
write_subroutine
(
recog_tree
.
first
,
RECOG
);
next_subroutine_number
=
0
;
break_out_subroutines
(
split_tree
,
SPLIT
);
printf
(
"rtx
\n
split_insns (x0, insn)
\n
register rtx x0;
\n
rtx insn;
\n
{
\n
"
);
printf
(
" register rtx *ro = &recog_operand[0];
\n
"
);
printf
(
" register rtx x1, x2, x3, x4, x5;
\n
rtx x6, x7, x8, x9, x10, x11;
\n
"
);
printf
(
" rtx tem;
\n
"
);
if
(
split_tree
)
write_tree
(
split_tree
,
""
,
0
,
""
,
1
,
SPLIT
);
printf
(
" ret0: return 0;
\n
}
\n
"
);
break_out_subroutines
(
split_tree
,
SPLIT
,
1
);
write_subroutine
(
split_tree
.
first
,
SPLIT
);
fflush
(
stdout
);
exit
(
ferror
(
stdout
)
!=
0
?
FATAL_EXIT_CODE
:
SUCCESS_EXIT_CODE
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment