[llvm-commits] [llvm-gcc-4.0] r42287 - in /llvm-gcc-4.0/trunk/gcc: c-common.h llvm-backend.cpp objc/objc-act.c stub-objc.c
Chris Lattner
clattner at apple.com
Tue Sep 25 14:29:16 PDT 2007
On Sep 24, 2007, at 7:51 PM, Bill Wendling wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=42287&view=rev
> Log:
> During the processing of Objective-C "protocols", the objc frontend
> creates two
> decls for the protocol. One for the metadata and another for when it's
> referenced. However, protocols are "internal global", so when we do
> a lookup
> for the reference, it doesn't find the first decl because it's not
> "external".
> This will perform a second lookup for objective C protocols if we
> don't find
> it among the "external globals".
Hi Bill,
This is a good short-term solution Bill, but I don't think it is what
we want to keep.
Specifically, your new function adds a fairly expensive call to
strstr to the global variable emission path for all languages.
It would be better to merge the vardecls in objc-act.c where it
creates them. I see this code:
/* Build decl = initializer; for each protocol referenced in @protocol
(MyProtole) expression. */
static void
build_protocollist_translation_table (void)
{
tree chain;
static char string[BUFSIZE];
for (chain = protocollist_ref_chain; chain; chain = TREE_CHAIN
(chain))
{
tree expr = TREE_VALUE (chain);
tree decl = TREE_PURPOSE (chain);
gcc_assert (TREE_CODE (expr) == PROTOCOL_INTERFACE_TYPE);
/* APPLE LOCAL begin radar 4695109 */
sprintf (string, "_OBJC_PROTOCOL_$_%s",
IDENTIFIER_POINTER (PROTOCOL_NAME (expr)));
expr = start_var_decl (objc_v2_protocol_template, string);
/* APPLE LOCAL end radar 4695109 */
expr = convert (objc_protocol_type, build_fold_addr_expr (expr));
finish_var_decl (decl, expr);
}
}
and this:
static void
build_v2_protocol_reference (tree p)
{
tree decl;
const char *proto_name;
/* static struct protocol_t _OBJC_PROTOCOL_$<mumble>; */
proto_name = synth_id_with_class_suffix ("_OBJC_PROTOCOL_$", p);
decl = start_var_decl (objc_v2_protocol_template, proto_name);
PROTOCOL_V2_FORWARD_DECL (p) = decl;
}
I'm not sure which happens first, but this is creating two DECL nodes
with the same name. Can you please investigate using lookup_name to
only create the new var_decl node if it doesn't already exist?
It might just be a matter of changing the code to looks like this:
proto_name = synth_id_with_class_suffix ("_OBJC_PROTOCOL_$", p);
if ((decl = lookup_name(proto_name)) == 0)
decl = start_var_decl (objc_v2_protocol_template, proto_name);
PROTOCOL_V2_FORWARD_DECL (p) = decl;
Or something.
-Chris
> Modified:
> llvm-gcc-4.0/trunk/gcc/c-common.h
> llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp
> llvm-gcc-4.0/trunk/gcc/objc/objc-act.c
> llvm-gcc-4.0/trunk/gcc/stub-objc.c
>
> Modified: llvm-gcc-4.0/trunk/gcc/c-common.h
> URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/c-
> common.h?rev=42287&r1=42286&r2=42287&view=diff
>
> ======================================================================
> ========
> --- llvm-gcc-4.0/trunk/gcc/c-common.h (original)
> +++ llvm-gcc-4.0/trunk/gcc/c-common.h Mon Sep 24 21:51:18 2007
> @@ -1139,6 +1139,12 @@
> extern void objc_remove_weak_read (tree*);
> /* APPLE LOCAL end radar 4426814 */
>
> +/* APPLE LOCAL begin - LLVM radar 5476262 */
> +#ifdef ENABLE_LLVM
> +extern bool objc_is_protocol_reference (const char *name);
> +#endif
> +/* APPLE LOCAL end - LLVM radar 5476262 */
> +
> /* APPLE LOCAL begin C* language */
> extern void objc_set_method_opt (int);
> void objc_finish_foreach_loop (location_t, tree, tree, tree, tree);
>
> Modified: llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/
> llvm-backend.cpp?rev=42287&r1=42286&r2=42287&view=diff
>
> ======================================================================
> ========
> --- llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp (original)
> +++ llvm-gcc-4.0/trunk/gcc/llvm-backend.cpp Mon Sep 24 21:51:18 2007
> @@ -66,6 +66,7 @@
> #include "function.h"
> #include "tree-inline.h"
> #include "langhooks.h"
> +#include "c-common.h"
> }
>
> // Non-zero if bytecode from PCH is successfully read.
> @@ -1060,6 +1061,14 @@
> // If the global has a name, prevent multiple vars with the
> same name from
> // being created.
> GlobalVariable *GVE = TheModule->getGlobalVariable(Name);
> +
> + // And Objective-C "@protocol" will create a decl for the
> + // protocol metadata and then when the protocol is
> + // referenced. However, protocols have file-scope, so they
> + // aren't found in the GlobalVariable list unless we look at
> + // non-extern globals as well.
> + if (!GVE && c_dialect_objc() && objc_is_protocol_reference
> (Name))
> + GVE = TheModule->getGlobalVariable(Name, true);
>
> if (GVE == 0) {
> GV = new GlobalVariable(Ty, false,
> GlobalValue::ExternalLinkage,0,
>
> Modified: llvm-gcc-4.0/trunk/gcc/objc/objc-act.c
> URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/
> objc/objc-act.c?rev=42287&r1=42286&r2=42287&view=diff
>
> ======================================================================
> ========
> --- llvm-gcc-4.0/trunk/gcc/objc/objc-act.c (original)
> +++ llvm-gcc-4.0/trunk/gcc/objc/objc-act.c Mon Sep 24 21:51:18 2007
> @@ -11669,6 +11669,19 @@
> }
> }
>
> +/* APPLE LOCAL begin - LLVM radar 5476262 */
> +#ifdef ENABLE_LLVM
> +/* This routine returns true if the name is the same as a protocol
> + reference name. */
> +
> +bool
> +objc_is_protocol_reference (const char *name)
> +{
> + return flag_objc_abi == 2 && strstr (name, "_OBJC_PROTOCOL_$_") !
> = 0;
> +}
> +#endif
> +/* APPLE LOCAL end - LLVM radar 5476262 */
> +
> /* This routine builds the protocol_reference_chain for each
> protocol name used
> @protocol(MyProtocol) expression. IDENT is current protocol
> name. */
>
>
> Modified: llvm-gcc-4.0/trunk/gcc/stub-objc.c
> URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.0/trunk/gcc/
> stub-objc.c?rev=42287&r1=42286&r2=42287&view=diff
>
> ======================================================================
> ========
> --- llvm-gcc-4.0/trunk/gcc/stub-objc.c (original)
> +++ llvm-gcc-4.0/trunk/gcc/stub-objc.c Mon Sep 24 21:51:18 2007
> @@ -548,3 +548,13 @@
> return false;
> }
> /* APPLE LOCAL end radar 4985544 */
> +
> +/* APPLE LOCAL begin - LLVM radar 5476262 */
> +#ifdef ENABLE_LLVM
> +bool
> +objc_is_protocol_reference (const char * ARG_UNUSED(name))
> +{
> + return false;
> +}
> +#endif
> +/* APPLE LOCAL end - LLVM radar 5476262 */
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list