[llvm-commits] [llvm-gcc-4.0] r42197 - in /llvm-gcc-4.0/trunk/gcc: c-common.c llvm-convert.cpp llvm-internal.h
Chris Lattner
sabre at nondot.org
Fri Sep 21 10:48:28 PDT 2007
Author: lattner
Date: Fri Sep 21 12:48:28 2007
New Revision: 42197
URL: http://llvm.org/viewvc/llvm-project?rev=42197&view=rev
Log:
Add support for a new gcroot attribute. Patch contributed by
Eric Christopher. See test/CFrontend/2007-09-20-GcrootAttribute.c
for an example of use.
Modified:
llvm-gcc-4.0/trunk/gcc/c-common.c
llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp
llvm-gcc-4.0/trunk/gcc/llvm-internal.h
Modified: llvm-gcc-4.0/trunk/gcc/c-common.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/c-common.c?rev=42197&r1=42196&r2=42197&view=diff
==============================================================================
--- llvm-gcc-4.0/trunk/gcc/c-common.c (original)
+++ llvm-gcc-4.0/trunk/gcc/c-common.c Fri Sep 21 12:48:28 2007
@@ -663,6 +663,7 @@
/* APPLE LOCAL begin LLVM */
#ifdef ENABLE_LLVM
static tree handle_annotate_attribute (tree*, tree, tree, int, bool *);
+static tree handle_gcroot_attribute (tree *, tree, tree, int, bool *);
#endif
/* APPLE LOCAL end LLVM */
@@ -757,6 +758,8 @@
#ifdef ENABLE_LLVM
{ "annotate", 0, -1, true, false, false,
handle_annotate_attribute },
+ { "gcroot", 0, 0, false, true, false,
+ handle_gcroot_attribute },
#endif
/* APPLE LOCAL end LLVM */
{ NULL, 0, 0, false, false, false, NULL }
@@ -5812,6 +5815,21 @@
return NULL_TREE;
}
+
+/* Handle the "gcroot" attribute */
+static tree
+handle_gcroot_attribute (tree *node, tree name, tree ARG_UNUSED(args),
+ int ARG_UNUSED(flags), bool *ARG_UNUSED(no_add_attrs))
+{
+ if (!TYPE_P (*node)
+ || !POINTER_TYPE_P (*node))
+ {
+ warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
#endif
/* APPLE LOCAL end LLVM */
Modified: llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp?rev=42197&r1=42196&r2=42197&view=diff
==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-convert.cpp Fri Sep 21 12:48:28 2007
@@ -655,6 +655,11 @@
// Emit annotate intrinsic if arg has annotate attr
if (DECL_ATTRIBUTES(Args))
EmitAnnotateIntrinsic(Tmp, Args);
+
+ // Emit gcroot intrinsic if arg has attribute
+ if (POINTER_TYPE_P(TREE_TYPE(Args))
+ && lookup_attribute ("gcroot", TYPE_ATTRIBUTES(TREE_TYPE(Args))))
+ EmitTypeGcroot(Tmp, Args);
Client.setName(Name);
Client.setLocation(Tmp);
@@ -1420,6 +1425,25 @@
BranchFixups.push_back(BranchFixup(BI, isExceptionEdge));
}
+// Emits code to do something for a type attribute
+void TreeToLLVM::EmitTypeGcroot(Value *V, tree decl) {
+
+ Function *gcrootFun = Intrinsic::getDeclaration(TheModule,
+ Intrinsic::gcroot);
+
+ // The idea is that it's a pointer to type "Value"
+ // which is opaque* but the routine expects i8** and i8*.
+ const PointerType *Ty = PointerType::get(Type::Int8Ty);
+ V = Builder.CreateBitCast(V, PointerType::get(Ty), "tmp");
+
+ Value *Ops[2] = {
+ V,
+ ConstantPointerNull::get(Ty)
+ };
+
+ Builder.CreateCall(gcrootFun, Ops, Ops+2);
+}
+
// Emits annotate intrinsic if the decl has the annotate attribute set.
void TreeToLLVM::EmitAnnotateIntrinsic(Value *V, tree decl) {
@@ -1581,6 +1605,17 @@
// Handle annotate attributes
if (DECL_ATTRIBUTES(decl))
EmitAnnotateIntrinsic(AI, decl);
+
+ // Handle gcroot attribute
+ if (POINTER_TYPE_P(TREE_TYPE (decl))
+ && lookup_attribute("gcroot", TYPE_ATTRIBUTES(TREE_TYPE (decl))))
+ {
+ // We should null out local variables so that a stack crawl
+ // before initialization doesn't get garbage results to follow.
+ const Type *T = cast<PointerType>(AI->getType())->getElementType();
+ EmitTypeGcroot(AI, decl);
+ Builder.CreateStore(Constant::getNullValue(T), AI);
+ }
if (TheDebugInfo) {
if (DECL_NAME(decl)) {
Modified: llvm-gcc-4.0/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/llvm-internal.h?rev=42197&r1=42196&r2=42197&view=diff
==============================================================================
--- llvm-gcc-4.0/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.0/trunk/gcc/llvm-internal.h Fri Sep 21 12:48:28 2007
@@ -472,7 +472,9 @@
/// EmitAnnotateIntrinsic - Emits call to annotate attr intrinsic
void EmitAnnotateIntrinsic(Value *V, tree_node *decl);
-
+
+ /// EmitTypeGcroot - Emits call to make type a gcroot
+ void EmitTypeGcroot(Value *V, tree_node *decl);
private:
/// GatherTypeInfo - Walk through the expression gathering all the
/// typeinfos that are used.
More information about the llvm-commits
mailing list