[llvm-commits] [gcc-plugin] r81323 - in /gcc-plugin/trunk: llvm-cache.c llvm-cache.h
Duncan Sands
baldrick at free.fr
Wed Sep 9 02:20:57 PDT 2009
Author: baldrick
Date: Wed Sep 9 04:20:56 2009
New Revision: 81323
URL: http://llvm.org/viewvc/llvm-project?rev=81323&view=rev
Log:
Make associating NULL with a tree be the same as
there being no association. Add a utility for
changing associated values.
Modified:
gcc-plugin/trunk/llvm-cache.c
gcc-plugin/trunk/llvm-cache.h
Modified: gcc-plugin/trunk/llvm-cache.c
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-cache.c?rev=81323&r1=81322&r2=81323&view=diff
==============================================================================
--- gcc-plugin/trunk/llvm-cache.c (original)
+++ gcc-plugin/trunk/llvm-cache.c Wed Sep 9 04:20:56 2009
@@ -1,6 +1,5 @@
/* Caching values "in" trees
Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
-Contributed by Chris Lattner (sabre at nondot.org)
This file is part of GCC.
@@ -41,46 +40,57 @@
#define tree_llvm_map_marked_p tree_map_base_marked_p
static GTY ((if_marked ("tree_llvm_map_marked_p"),
- param_is (struct tree_llvm_map)))
+ param_is(struct tree_llvm_map)))
htab_t llvm_cache;
-bool llvm_has_cached (union tree_node *t) {
+/// llvm_has_cached - Returns whether a value has been associated with the tree.
+bool llvm_has_cached(union tree_node *tree) {
struct tree_map_base in;
if (!llvm_cache)
return false;
- in.from = t;
- return htab_find (llvm_cache, &in) != NULL;
+ in.from = tree;
+ return htab_find(llvm_cache, &in) != NULL;
}
-const void *llvm_get_cached (union tree_node *t) {
+/// llvm_get_cached - Returns the value associated with the tree, or NULL.
+const void *llvm_get_cached(union tree_node *tree) {
struct tree_llvm_map *h;
struct tree_map_base in;
if (!llvm_cache)
return NULL;
- in.from = t;
- h = (struct tree_llvm_map *) htab_find (llvm_cache, &in);
+ in.from = tree;
+ h = (struct tree_llvm_map *) htab_find(llvm_cache, &in);
return h ? h->val : NULL;
}
-const void *llvm_set_cached (union tree_node *t, const void *val) {
+/// llvm_set_cached - Associates the given value with the tree (and returns it).
+/// To delete an association, pass a NULL value here.
+const void *llvm_set_cached(union tree_node *tree, const void *val) {
struct tree_llvm_map **slot;
struct tree_map_base in;
- if (!llvm_cache)
- llvm_cache = htab_create_ggc (1024, tree_llvm_map_hash, tree_llvm_map_eq, NULL);
+ in.from = tree;
- in.from = t;
+ // If deleting, remove the slot.
+ if (val == NULL) {
+ if (llvm_cache)
+ htab_remove_elt(llvm_cache, &in);
+ return NULL;
+ }
- slot = (struct tree_llvm_map **) htab_find_slot (llvm_cache, &in, INSERT);
+ if (!llvm_cache)
+ llvm_cache = htab_create_ggc(1024, tree_llvm_map_hash, tree_llvm_map_eq, NULL);
+
+ slot = (struct tree_llvm_map **) htab_find_slot(llvm_cache, &in, INSERT);
gcc_assert(slot);
if (!*slot) {
- *slot = GGC_NEW (struct tree_llvm_map);
- (*slot)->base.from = t;
+ *slot = GGC_NEW(struct tree_llvm_map);
+ (*slot)->base.from = tree;
}
(*slot)->val = val;
@@ -88,4 +98,36 @@
return val;
}
+struct update {
+ const void *old_val;
+ const void *new_val;
+};
+
+/// replace - If the current value for the slot matches old_val, then replace
+/// it with new_val, or delete it if new_val is NULL.
+static int replace(void **slot, void *data) {
+ struct tree_llvm_map *entry = *(struct tree_llvm_map **)slot;
+ struct update *u = (struct update *)data;
+
+ if (entry->val != u->old_val)
+ return 1;
+
+ if (u->new_val != NULL)
+ entry->val = u->new_val;
+ else
+ htab_clear_slot(llvm_cache, slot);
+
+ return 1;
+}
+
+/// llvm_replace_cached - Replaces all occurrences of old_val with new_val.
+void llvm_replace_cached(const void *old_val, const void *new_val) {
+ struct update u = { old_val, new_val };
+
+ if (!llvm_cache || old_val == NULL)
+ return;
+
+ htab_traverse(llvm_cache, replace, &u);
+}
+
#include "gt-llvm-cache.h"
Modified: gcc-plugin/trunk/llvm-cache.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-cache.h?rev=81323&r1=81322&r2=81323&view=diff
==============================================================================
--- gcc-plugin/trunk/llvm-cache.h (original)
+++ gcc-plugin/trunk/llvm-cache.h Wed Sep 9 04:20:56 2009
@@ -34,12 +34,17 @@
#include "target.h"
#include "tree.h"
-extern bool llvm_has_cached (union tree_node *);
+/// llvm_has_cached - Returns whether a value has been associated with the tree.
+extern bool llvm_has_cached(union tree_node *tree);
-extern const void *llvm_get_cached (union tree_node *);
+/// llvm_get_cached - Returns the value associated with the tree, or NULL.
+extern const void *llvm_get_cached(union tree_node *tree);
-extern const void *llvm_set_cached (union tree_node *, const void *);
+/// llvm_set_cached - Associates the given value with the tree (and returns it).
+/// To delete an association, pass NULL for the value.
+extern const void *llvm_set_cached(union tree_node *tree, const void *val);
-extern void llvm_init_cache (void);
+/// llvm_replace_cached - Replaces all occurrences of old_val with new_val.
+extern void llvm_replace_cached(const void *old_val, const void *new_val);
#endif /* LLVM_CACHE_H */
More information about the llvm-commits
mailing list