aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/cp-tree.h
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-06-29 09:36:58 -0400
committerPatrick Palka <ppalka@redhat.com>2023-06-29 09:36:58 -0400
commite972bdce61cc5213a4b0309ef88fb611617843dc (patch)
treeee91d7caa98a5f5e95f9dd950538502b6d8f343a /gcc/cp/cp-tree.h
parentc7ed2ccd590d9c0d0146f61c97ca6500910936b8 (diff)
downloadgcc-e972bdce61cc5213a4b0309ef88fb611617843dc.zip
gcc-e972bdce61cc5213a4b0309ef88fb611617843dc.tar.gz
gcc-e972bdce61cc5213a4b0309ef88fb611617843dc.tar.bz2
c++: cache partial template specialization selection
There's currently no cheap way to obtain the partial template specialization (and arguments relative to it) that was selected for a class or variable template specialization. Our only option is to compute the result from scratch via most_specialized_partial_spec. For class templates this isn't really an issue because we usually need this information just once, upon instantiation. But for variable templates we need it upon specialization and also later upon instantiation. We could implement an ad-hoc cache for variable templates only, but it'd be nice for this information to be readily available in general. To that end, this patch adds a TI_PARTIAL_INFO field to TEMPLATE_INFO that holds another TEMPLATE_INFO consisting of the partial template and arguments relative to it, which most_specialized_partial_spec then uses to transparently cache its (now TEMPLATE_INFO) result. Similarly, there's no easy way to go from the DECL_TEMPLATE_RESULT of a partial TEMPLATE_DECL back to that TEMPLATE_DECL. (Our best option is to walk the DECL_TEMPLATE_SPECIALIZATIONS list of the primary TEMPLATE_DECL.) So this patch also uses this new field to link these entities in both directions. gcc/cp/ChangeLog: * cp-tree.h (tree_template_info::partial): New data member. (TI_PARTIAL_INFO): New tree accessor. (most_specialized_partial_spec): Add defaulted bool parameter. * module.cc (trees_out::core_vals) <case TEMPLATE_INFO>: Stream TI_PARTIAL_INFO. (trees_in::core_vals) <case TEMPLATE_INFO>: Likewise. * parser.cc (specialization_of): Adjust after making most_specialized_partial_spec return TEMPLATE_INFO instead of TREE_LIST. * pt.cc (process_partial_specialization): Set TI_PARTIAL_INFO of 'decl' to point back to the partial TEMPLATE_DECL. Likewise (and pass rechecking=true to most_specialization_partial_spec). (instantiate_class_template): Likewise. (instantiate_template): Set TI_PARTIAL_INFO to the result of most_specialization_partial_spec after forming a variable template specialization. (most_specialized_partial_spec): Add 'rechecking' parameter. Exit early if the template is not primary. Use the TI_PARTIAL_INFO of the corresponding TEMPLATE_INFO as a cache unless 'rechecking' is true. Don't bother setting TREE_TYPE of each TREE_LIST. (instantiate_decl): Adjust after making most_specialized_partial_spec return TEMPLATE_INFO instead of TREE_LIST. * ptree.cc (cxx_print_xnode) <case TEMPLATE_INFO>: Dump TI_PARTIAL_INFO.
Diffstat (limited to 'gcc/cp/cp-tree.h')
-rw-r--r--gcc/cp/cp-tree.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index fbeff33..2faf6fa 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1564,6 +1564,7 @@ struct GTY(()) tree_template_info {
struct tree_base base;
tree tmpl;
tree args;
+ tree partial;
vec<deferred_access_check, va_gc> *deferred_access_checks;
};
@@ -3755,6 +3756,14 @@ struct GTY(()) lang_decl {
((struct tree_template_info*)TEMPLATE_INFO_CHECK (NODE))->args
#define TI_PENDING_TEMPLATE_FLAG(NODE) \
TREE_LANG_FLAG_1 (TEMPLATE_INFO_CHECK (NODE))
+
+/* For a class or variable template specialization, this contains the
+ TEMPLATE_INFO result of most_specialized_partial_spec, i.e. the selected
+ partial template specialization and arguments relative to it. */
+#define TI_PARTIAL_INFO(NODE) \
+ (gcc_checking_assert (PRIMARY_TEMPLATE_P (TI_TEMPLATE (NODE))), \
+ ((struct tree_template_info*)NODE)->partial)
+
/* For a given TREE_VEC containing a template argument list,
this property contains the number of arguments that are not
defaulted. */
@@ -7398,7 +7407,7 @@ extern bool comp_template_args (tree, tree, tree * = NULL,
extern int template_args_equal (tree, tree, bool = false);
extern tree maybe_process_partial_specialization (tree);
extern tree most_specialized_instantiation (tree);
-extern tree most_specialized_partial_spec (tree, tsubst_flags_t);
+extern tree most_specialized_partial_spec (tree, tsubst_flags_t, bool = false);
extern void print_candidates (tree);
extern void instantiate_pending_templates (int);
extern tree tsubst_default_argument (tree, int, tree, tree,