From 13bdca744bda9321d6e0f4beca7bf9ac2e0870c0 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Tue, 12 Sep 2017 16:24:29 +0200 Subject: [PATCH] Reduce lookup_attribute memory footprint. 2017-09-12 Martin Liska * attribs.c (private_lookup_attribute): New function. * attribs.h (private_lookup_attribute): Declared here. (lookup_attribute): Called from this place. From-SVN: r252022 --- gcc/ChangeLog | 6 ++++++ gcc/attribs.c | 22 ++++++++++++++++++++++ gcc/attribs.h | 20 +++++++++----------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 62e8fae4128..a4fbc2aecd9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-09-12 Martin Liska + + * attribs.c (private_lookup_attribute): New function. + * attribs.h (private_lookup_attribute): Declared here. + (lookup_attribute): Called from this place. + 2017-09-12 Richard Biener PR tree-optimization/82157 diff --git a/gcc/attribs.c b/gcc/attribs.c index b8f58a74596..4ef35b861f8 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -1584,3 +1584,25 @@ attribute_list_contained (const_tree l1, const_tree l2) return 1; } + +/* The backbone of lookup_attribute(). ATTR_LEN is the string length + of ATTR_NAME, and LIST is not NULL_TREE. + + The function is called from lookup_attribute in order to optimize + for size. */ + +tree +private_lookup_attribute (const char *attr_name, size_t attr_len, tree list) +{ + while (list) + { + tree attr = get_attribute_name (list); + size_t ident_len = IDENTIFIER_LENGTH (attr); + if (cmp_attribs (attr_name, attr_len, IDENTIFIER_POINTER (attr), + ident_len)) + break; + list = TREE_CHAIN (list); + } + + return list; +} diff --git a/gcc/attribs.h b/gcc/attribs.h index 06e6993e958..65e002ce988 100644 --- a/gcc/attribs.h +++ b/gcc/attribs.h @@ -87,6 +87,14 @@ extern tree handle_dll_attribute (tree *, tree, tree, int, bool *); extern int attribute_list_equal (const_tree, const_tree); extern int attribute_list_contained (const_tree, const_tree); +/* The backbone of lookup_attribute(). ATTR_LEN is the string length + of ATTR_NAME, and LIST is not NULL_TREE. + + The function is called from lookup_attribute in order to optimize + for size. */ +extern tree private_lookup_attribute (const char *attr_name, size_t attr_len, + tree list); + /* For a given IDENTIFIER_NODE, strip leading and trailing '_' characters so that we have a canonical form of attribute names. */ @@ -151,17 +159,7 @@ lookup_attribute (const char *attr_name, tree list) /* Do the strlen() before calling the out-of-line implementation. In most cases attr_name is a string constant, and the compiler will optimize the strlen() away. */ - while (list) - { - tree attr = get_attribute_name (list); - size_t ident_len = IDENTIFIER_LENGTH (attr); - if (cmp_attribs (attr_name, attr_len, IDENTIFIER_POINTER (attr), - ident_len)) - break; - list = TREE_CHAIN (list); - } - - return list; + return private_lookup_attribute (attr_name, attr_len, list); } } -- 2.30.2