[llvm-commits] [gcc-plugin] r76434 - in /gcc-plugin/trunk: Makefile llvm-cache.c llvm-cache.h

Duncan Sands baldrick at free.fr
Mon Jul 20 10:27:45 PDT 2009


Author: baldrick
Date: Mon Jul 20 12:27:45 2009
New Revision: 76434

URL: http://llvm.org/viewvc/llvm-project?rev=76434&view=rev
Log:
Add a generic mechanism for associating a void*
with a gcc tree.  The point is that if the tree
is garbage collected then the map entry is auto
removed.  Well, it would be if the garbage collector
new about the new GTY type - leave that for later.

Added:
    gcc-plugin/trunk/llvm-cache.c
    gcc-plugin/trunk/llvm-cache.h
Modified:
    gcc-plugin/trunk/Makefile

Modified: gcc-plugin/trunk/Makefile
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/Makefile?rev=76434&r1=76433&r2=76434&view=diff

==============================================================================
--- gcc-plugin/trunk/Makefile (original)
+++ gcc-plugin/trunk/Makefile Mon Jul 20 12:27:45 2009
@@ -1,21 +1,21 @@
-PLUGIN_SOURCE_FILES=llvm-convert.cpp llvm-backend.cpp llvm-debug.cpp llvm-types.cpp bits_and_bobs.cpp
-PLUGIN_OBJECT_FILES=$(patsubst %.cpp,%.o,$(PLUGIN_SOURCE_FILES))
+C_SOURCE_FILES=llvm-cache.c
+CPP_SOURCE_FILES=llvm-convert.cpp llvm-backend.cpp llvm-debug.cpp llvm-types.cpp bits_and_bobs.cpp
+PLUGIN_OBJECT_FILES=$(C_SOURCE_FILES:.c=.o) $(CPP_SOURCE_FILES:.cpp=.o)
 
 #GCCPLUGIN_DIR:=$(shell $(GCC) -print-file-name=plugin)
 GCCSOURCE_DIR=/home/duncan/tmp/gcc.fsf.master
 GCCOBJECT_DIR=/home/duncan/tmp/gcc.fsf.master-objects
 
-#CXXFLAGS+=-I$(GCCPLUGINS_DIR)/include -fPIC -O2
+#CFLAGS+=-I$(GCCPLUGINS_DIR)/include -fPIC -O2
 
-CXXFLAGS+=-Werror -fPIC -g -O2
-CXXFLAGS+=$(shell llvm-config --cppflags)
-CXXFLAGS+=\
-	-I${GCCOBJECT_DIR}/gcc -I${GCCOBJECT_DIR}/gcc/include \
-	-I${GCCSOURCE_DIR}/gcc -I${GCCSOURCE_DIR}/include \
-	-I${GCCSOURCE_DIR}/libcpp/include -I${GCCSOURCE_DIR}/libdecnumber \
-	-I${GCCOBJECT_DIR}/libdecnumber
+CFLAGS+=-Werror -fPIC -g -O2
+CFLAGS+= -I${GCCOBJECT_DIR}/gcc -I${GCCOBJECT_DIR}/gcc/include \
+	 -I${GCCSOURCE_DIR}/gcc -I${GCCSOURCE_DIR}/include \
+	 -I${GCCSOURCE_DIR}/libcpp/include -I${GCCSOURCE_DIR}/libdecnumber \
+	 -I${GCCOBJECT_DIR}/libdecnumber
+CXXFLAGS+=$(CFLAGS) $(shell llvm-config --cppflags)
 
-LDFLAGS+=$(shell llvm-config --ldflags) $(shell llvm-config --libs analysis core target)
+LDFLAGS+=$(shell llvm-config --ldflags) $(shell llvm-config --libs analysis core target x86)
 
 llvm.so: $(PLUGIN_OBJECT_FILES)
 	$(CXX) -shared $^ -o $@ ${LDFLAGS}

Added: gcc-plugin/trunk/llvm-cache.c
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-cache.c?rev=76434&view=auto

==============================================================================
--- gcc-plugin/trunk/llvm-cache.c (added)
+++ gcc-plugin/trunk/llvm-cache.c Mon Jul 20 12:27:45 2009
@@ -0,0 +1,89 @@
+/* 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.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+//===----------------------------------------------------------------------===//
+// This code lets you to associate a void* with a tree, as if it were cached
+// inside the tree: if the tree is garbage collected and reallocated, then the
+// cached value will have been cleared.
+//===----------------------------------------------------------------------===//
+
+// Plugin headers
+#include "llvm-cache.h"
+
+// GCC headers
+#include "hashtab.h"
+
+#include "stdio.h" //QQ
+
+#define tree_llvm_map_eq tree_map_base_eq
+#define tree_llvm_map_hash tree_map_base_hash
+#define tree_llvm_map_marked_p tree_map_base_marked_p
+
+static int debugging_tree_llvm_map_marked_p (const void *p) {//QQ
+  printf("debugging_ggc call for %p\n", p);
+  return tree_map_base_marked_p(p);
+}
+
+static GTY ((if_marked ("debugging_tree_llvm_map_marked_p"),
+             param_is (struct tree_llvm_map)))
+  htab_t llvm_cache;
+
+bool llvm_has_cached (union tree_node *t) {
+  struct tree_map_base in;
+
+  if (!llvm_cache)
+    return false;
+
+  in.from = t;
+  return htab_find (llvm_cache, &in) != NULL;
+}
+
+const void *llvm_get_cached (union tree_node *t) {
+  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);
+  return h ? h->val : NULL;
+}
+
+const void *llvm_set_cached (union tree_node *t, 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 = t;
+
+  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)->val = val;
+}

Added: gcc-plugin/trunk/llvm-cache.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-cache.h?rev=76434&view=auto

==============================================================================
--- gcc-plugin/trunk/llvm-cache.h (added)
+++ gcc-plugin/trunk/llvm-cache.h Mon Jul 20 12:27:45 2009
@@ -0,0 +1,61 @@
+/* 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.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
+
+//===----------------------------------------------------------------------===//
+// This code lets you to associate a void* with a tree, as if it were cached
+// inside the tree: if the tree is garbage collected and reallocated, then the
+// cached value will have been cleared.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CACHE_H
+#define LLVM_CACHE_H
+
+#define IN_GCC
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "ggc.h"
+#include "target.h"
+#include "tree.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct GTY(()) tree_llvm_map {
+  struct tree_map_base base;
+  const void *val;
+};
+
+extern bool llvm_has_cached (union tree_node *);
+
+extern const void *llvm_get_cached (union tree_node *);
+
+extern const void *llvm_set_cached (union tree_node *, const void *);
+
+extern void llvm_init_cache (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LLVM_CACHE_H */





More information about the llvm-commits mailing list