aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2019-04-18 07:40:35 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2019-04-18 07:40:35 +0000
commit1b73c7ef7c9c3c04610bc2d2819affea917d91d2 (patch)
tree29a99fe4c910cd73b11e1d33bd71a1ba7ae40e99 /gcc/tree.c
parent3d52462c8cdfad4e0839041af3a586ddb13965d5 (diff)
downloadgcc-1b73c7ef7c9c3c04610bc2d2819affea917d91d2.zip
gcc-1b73c7ef7c9c3c04610bc2d2819affea917d91d2.tar.gz
gcc-1b73c7ef7c9c3c04610bc2d2819affea917d91d2.tar.bz2
tree.c (get_qualified_type): Put found type variants at the head of the variant list.
2019-04-18 Richard Biener <rguenther@suse.de> * tree.c (get_qualified_type): Put found type variants at the head of the variant list. From-SVN: r270437
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index a483cc1..73102c4 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -6451,17 +6451,28 @@ check_aligned_type (const_tree cand, const_tree base, unsigned int align)
tree
get_qualified_type (tree type, int type_quals)
{
- tree t;
-
if (TYPE_QUALS (type) == type_quals)
return type;
+ tree mv = TYPE_MAIN_VARIANT (type);
+ if (check_qualified_type (mv, type, type_quals))
+ return mv;
+
/* Search the chain of variants to see if there is already one there just
like the one we need to have. If so, use that existing one. We must
preserve the TYPE_NAME, since there is code that depends on this. */
- for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
- if (check_qualified_type (t, type, type_quals))
- return t;
+ for (tree *tp = &TYPE_NEXT_VARIANT (mv); *tp; tp = &TYPE_NEXT_VARIANT (*tp))
+ if (check_qualified_type (*tp, type, type_quals))
+ {
+ /* Put the found variant at the head of the variant list so
+ frequently searched variants get found faster. The C++ FE
+ benefits greatly from this. */
+ tree t = *tp;
+ *tp = TYPE_NEXT_VARIANT (t);
+ TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (mv);
+ TYPE_NEXT_VARIANT (mv) = t;
+ return t;
+ }
return NULL_TREE;
}