adjust optimizer to improve intra-module inlining
Instead of delaying the registration of some constants until a group of expressions is re-optimized, add constant information as it is discovered, which can expose some additional optimizations. The old grouping was probably aimed at avoiding excessive code growth, but I think that other and better controls are now in place. The overall size of ".zo" files in an installation did not grow significantly with this change. Closes PR 14978
This commit is contained in:
parent
17275b946a
commit
a8026824dd
|
@ -1494,6 +1494,21 @@
|
||||||
(set! x x))))
|
(set! x x))))
|
||||||
#f)
|
#f)
|
||||||
|
|
||||||
|
(test-comp '(module m racket/base
|
||||||
|
(define (true) #t)
|
||||||
|
(define no (if (true) (lambda (x) (cons x 'no)) display))
|
||||||
|
(newline) ; <--- just to break the simultaneous group
|
||||||
|
(define yes (if (true) (lambda (x) (cons x 'yes)) display))
|
||||||
|
(no 5)
|
||||||
|
(yes 5))
|
||||||
|
'(module m racket/base
|
||||||
|
(define (true) #t)
|
||||||
|
(define no (lambda (x) (cons x 'no)))
|
||||||
|
(newline)
|
||||||
|
(define yes (lambda (x) (cons x 'yes)))
|
||||||
|
(cons 5 'no)
|
||||||
|
(cons 5 'yes)))
|
||||||
|
|
||||||
(test-comp '(let ([x 1][y 2]) x)
|
(test-comp '(let ([x 1][y 2]) x)
|
||||||
'1)
|
'1)
|
||||||
(test-comp '(let ([x 1][y 2]) (+ y x))
|
(test-comp '(let ([x 1][y 2]) (+ y x))
|
||||||
|
|
|
@ -6874,19 +6874,17 @@ module_optimize(Scheme_Object *data, Optimize_Info *info, int context)
|
||||||
if (e2) {
|
if (e2) {
|
||||||
int pos;
|
int pos;
|
||||||
pos = tl->position;
|
pos = tl->position;
|
||||||
if (sstruct) {
|
|
||||||
/* Add directly to `info->top_level_consts' for use
|
consts = info->top_level_consts;
|
||||||
by sub-struct declarations in the same set */
|
if (!consts) {
|
||||||
if (!info->top_level_consts) {
|
consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
||||||
Scheme_Hash_Table *tlc;
|
info->top_level_consts = consts;
|
||||||
tlc = scheme_make_hash_table(SCHEME_hash_ptr);
|
}
|
||||||
info->top_level_consts = tlc;
|
scheme_hash_set(consts, scheme_make_integer(pos), e2);
|
||||||
}
|
|
||||||
scheme_hash_set(info->top_level_consts, scheme_make_integer(pos), e2);
|
if (sstruct || (SCHEME_TYPE(e2) > _scheme_compiled_values_types_)) {
|
||||||
|
/* No use re-optimizing */
|
||||||
} else {
|
} else {
|
||||||
if (!consts)
|
|
||||||
consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
|
||||||
scheme_hash_set(consts, scheme_make_integer(pos), e2);
|
|
||||||
if (!re_consts)
|
if (!re_consts)
|
||||||
re_consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
re_consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
||||||
scheme_hash_set(re_consts, scheme_make_integer(i_m),
|
scheme_hash_set(re_consts, scheme_make_integer(i_m),
|
||||||
|
@ -6896,9 +6894,12 @@ module_optimize(Scheme_Object *data, Optimize_Info *info, int context)
|
||||||
/* At least mark it as fixed */
|
/* At least mark it as fixed */
|
||||||
if (!fixed_table) {
|
if (!fixed_table) {
|
||||||
fixed_table = scheme_make_hash_table(SCHEME_hash_ptr);
|
fixed_table = scheme_make_hash_table(SCHEME_hash_ptr);
|
||||||
if (!consts)
|
if (!info->top_level_consts) {
|
||||||
consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
||||||
scheme_hash_set(consts, scheme_false, (Scheme_Object *)fixed_table);
|
info->top_level_consts = consts;
|
||||||
|
consts = NULL;
|
||||||
|
}
|
||||||
|
scheme_hash_set(info->top_level_consts, scheme_false, (Scheme_Object *)fixed_table);
|
||||||
}
|
}
|
||||||
scheme_hash_set(fixed_table, scheme_make_integer(tl->position), scheme_true);
|
scheme_hash_set(fixed_table, scheme_make_integer(tl->position), scheme_true);
|
||||||
}
|
}
|
||||||
|
@ -6936,19 +6937,6 @@ module_optimize(Scheme_Object *data, Optimize_Info *info, int context)
|
||||||
if (consts) {
|
if (consts) {
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
if (!info->top_level_consts) {
|
|
||||||
info->top_level_consts = consts;
|
|
||||||
} else {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < consts->size; i++) {
|
|
||||||
if (consts->vals[i]) {
|
|
||||||
scheme_hash_set(info->top_level_consts,
|
|
||||||
consts->keys[i],
|
|
||||||
consts->vals[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Same as in letrec: assume CLOS_SINGLE_RESULT and
|
/* Same as in letrec: assume CLOS_SINGLE_RESULT and
|
||||||
CLOS_PRESERVES_MARKS for all, but then assume not for all
|
CLOS_PRESERVES_MARKS for all, but then assume not for all
|
||||||
if any turn out not (i.e., approximate fix point). */
|
if any turn out not (i.e., approximate fix point). */
|
||||||
|
@ -7049,9 +7037,12 @@ module_optimize(Scheme_Object *data, Optimize_Info *info, int context)
|
||||||
if (next_pos_ready > -1) {
|
if (next_pos_ready > -1) {
|
||||||
if (!fixed_table) {
|
if (!fixed_table) {
|
||||||
fixed_table = scheme_make_hash_table(SCHEME_hash_ptr);
|
fixed_table = scheme_make_hash_table(SCHEME_hash_ptr);
|
||||||
if (!consts)
|
if (!info->top_level_consts) {
|
||||||
consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
consts = scheme_make_hash_table(SCHEME_hash_ptr);
|
||||||
scheme_hash_set(consts, scheme_false, (Scheme_Object *)fixed_table);
|
info->top_level_consts = consts;
|
||||||
|
consts = NULL;
|
||||||
|
}
|
||||||
|
scheme_hash_set(info->top_level_consts, scheme_false, (Scheme_Object *)fixed_table);
|
||||||
}
|
}
|
||||||
scheme_hash_set(fixed_table, scheme_make_integer(next_pos_ready), scheme_true);
|
scheme_hash_set(fixed_table, scheme_make_integer(next_pos_ready), scheme_true);
|
||||||
next_pos_ready = -1;
|
next_pos_ready = -1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user