Revision: 126949 Author: clattner Date: 2007-05-05 11:11:46 -0700 (Sat, 05 May 2007)
Log Message: ----------- >From Anton: this patch modifies the alias support in llvm-gcc to not use c-front-end specific functions. Modified Paths: -------------- apple-local/branches/llvm/gcc/cgraph.c apple-local/branches/llvm/gcc/llvm-backend.cpp apple-local/branches/llvm/gcc/llvm.h apple-local/branches/llvm/gcc/varasm.c Modified: apple-local/branches/llvm/gcc/cgraph.c =================================================================== --- apple-local/branches/llvm/gcc/cgraph.c 2007-05-05 17:57:58 UTC (rev 126948) +++ apple-local/branches/llvm/gcc/cgraph.c 2007-05-05 18:11:46 UTC (rev 126949) @@ -213,7 +213,13 @@ historically been doing the wrong thing in assemble_alias by always printing the leading underscore. Since we're not changing that, make sure user_label_prefix follows the '*' before matching. */ +/* APPLE LOCAL begin LLVM */ +#ifdef ENABLE_LLVM + if (IDENTIFIER_POINTER (decl_asmname)[0] == 1) +#else if (IDENTIFIER_POINTER (decl_asmname)[0] == '*') +#endif +/* APPLE LOCAL end LLVM */ { const char *decl_str = IDENTIFIER_POINTER (decl_asmname) + 1; size_t ulp_len = strlen (user_label_prefix); Modified: apple-local/branches/llvm/gcc/llvm-backend.cpp =================================================================== --- apple-local/branches/llvm/gcc/llvm-backend.cpp 2007-05-05 17:57:58 UTC (rev 126948) +++ apple-local/branches/llvm/gcc/llvm-backend.cpp 2007-05-05 18:11:46 UTC (rev 126949) @@ -58,7 +58,6 @@ #include "coretypes.h" #include "flags.h" #include "tree.h" -#include "c-tree.h" // For aliases #include "diagnostic.h" #include "output.h" #include "toplev.h" @@ -534,48 +533,45 @@ timevar_pop(TV_LLVM_FUNCS); } -// emit_alias_to_llvm - Given decl and target emit alias to target. gcc is -// little bit insane, it can ask us for alias emission in many places. Such -// places are divided into two stages: it's allowed to have unresolved target at -// stage 0 (hence result code -1), but not on stage 1 (error). Zero is returned -// if alias was emitted. -int emit_alias_to_llvm(tree decl, tree target, unsigned stage) { - if (errorcount || sorrycount) return -2; - +// emit_alias_to_llvm - Given decl and target emit alias to target. +void emit_alias_to_llvm(tree decl, tree target, tree target_decl) { + if (errorcount || sorrycount) return; + timevar_push(TV_LLVM_GLOBALS); // Get or create LLVM global for our alias. GlobalValue *V = cast<GlobalValue>(DECL_LLVM(decl)); - // Try to grab decl from IDENTIFIER_NODE - GlobalValue *Aliasee = 0; - if (tree c_decl = lookup_name(target)) - Aliasee = cast<GlobalValue>(DECL_LLVM(c_decl)); + GlobalValue *Aliasee = NULL; + + if (target_decl) + Aliasee = cast<GlobalValue>(DECL_LLVM(target_decl)); + else { + // This is something insane. Probably only LTHUNKs can be here + // Try to grab decl from IDENTIFIER_NODE - // Query SymTab for aliasee - const char* AliaseeName = IDENTIFIER_POINTER(target); - if (!Aliasee) { + // Query SymTab for aliasee + const char* AliaseeName = IDENTIFIER_POINTER(target); Aliasee = dyn_cast_or_null<GlobalValue>(TheModule-> getValueSymbolTable().lookup(AliaseeName)); - } - // Last resort. Query for name set via __asm__ - if (!Aliasee) { - std::string starred = std::string("\001") + AliaseeName; - Aliasee = - dyn_cast_or_null<GlobalValue>(TheModule-> - getValueSymbolTable().lookup(starred)); - } - - if (!Aliasee) { - if (stage) + // Last resort. Query for name set via __asm__ + if (!Aliasee) { + std::string starred = std::string("\001") + AliaseeName; + Aliasee = + dyn_cast_or_null<GlobalValue>(TheModule-> + getValueSymbolTable().lookup(starred)); + } + + if (!Aliasee) { error ("%J%qD aliased to undefined symbol %qE", decl, decl, target); - timevar_pop(TV_LLVM_GLOBALS); - return -1; - } - + timevar_pop(TV_LLVM_GLOBALS); + return; + } + } + GlobalValue::LinkageTypes Linkage; GlobalValue::VisibilityTypes Visibility; @@ -598,7 +594,7 @@ else if (!V->use_empty()) { error ("%J Alias %qD used with invalid type!", decl, decl); timevar_pop(TV_LLVM_GLOBALS); - return -1; + return; } changeLLVMValue(V, GA); @@ -611,9 +607,11 @@ F->eraseFromParent(); else assert(0 && "Unsuported global value"); + + TREE_ASM_WRITTEN(decl) = 1; timevar_pop(TV_LLVM_GLOBALS); - return 0; + return; } Modified: apple-local/branches/llvm/gcc/llvm.h =================================================================== --- apple-local/branches/llvm/gcc/llvm.h 2007-05-05 17:57:58 UTC (rev 126948) +++ apple-local/branches/llvm/gcc/llvm.h 2007-05-05 18:11:46 UTC (rev 126949) @@ -51,7 +51,7 @@ /* emit_global_to_llvm - Emit the specified alias to LLVM */ -int emit_alias_to_llvm(union tree_node*, union tree_node*, unsigned); +void emit_alias_to_llvm(union tree_node*, union tree_node*, union tree_node*); /* llvm_get_decl_name - Used by varasm.c, returns the specified declaration's * name. Modified: apple-local/branches/llvm/gcc/varasm.c =================================================================== --- apple-local/branches/llvm/gcc/varasm.c 2007-05-05 17:57:58 UTC (rev 126948) +++ apple-local/branches/llvm/gcc/varasm.c 2007-05-05 18:11:46 UTC (rev 126949) @@ -4634,8 +4634,6 @@ /* Given an assembly name, find the decl it is associated with. At the same time, mark it needed for cgraph. */ -/* APPLE LOCAL LLVM */ -#ifndef ENABLE_LLVM static tree find_decl_and_mark_needed (tree decl, tree target) { @@ -4673,20 +4671,12 @@ else return NULL_TREE; } -/* APPLE LOCAL LLVM */ -#endif +/* APPLE LOCAL LLVM */ +#ifndef ENABLE_LLVM static void do_assemble_alias (tree decl, tree target) { -/* APPLE LOCAL begin LLVM */ -#ifdef ENABLE_LLVM - if (emit_alias_to_llvm(decl, target, 1) == -1) - error ("%J%qD aliased to undefined symbol %qE", - decl, decl, target); - return; -#endif -/* APPLE LOCAL end LLVM */ if (TREE_ASM_WRITTEN (decl)) return; @@ -4724,12 +4714,14 @@ we do not emit multiple .weak directives for it. */ for (p = &weak_decls; (t = *p) ; ) if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))) - *p = TREE_CHAIN (t); + *p = TREE_CHAIN (t); else - p = &TREE_CHAIN (t); + p = &TREE_CHAIN (t); } #endif } +/* APPLE LOCAL LLVM */ +#endif /* First pass of completing pending aliases. Make sure that cgraph knows which symbols will be required. */ @@ -4737,11 +4729,6 @@ void finish_aliases_1 (void) { -/* APPLE LOCAL begin LLVM */ -#ifdef ENABLE_LLVM - return; -#else -/* APPLE LOCAL end LLVM */ unsigned i; alias_pair p; @@ -4757,9 +4744,6 @@ error ("%J%qD aliased to external symbol %qE", p->decl, p->decl, p->target); } -/* APPLE LOCAL begin LLVM */ -#endif -/* APPLE LOCAL end LLVM */ } /* Second pass of completing pending aliases. Emit the actual assembly. @@ -4773,7 +4757,17 @@ alias_pair p; for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++) +/* APPLE LOCAL begin LLVM */ +#ifdef ENABLE_LLVM + { + tree target_decl; + target_decl = find_decl_and_mark_needed (p->decl, p->target); + emit_alias_to_llvm(p->decl, p->target, target_decl); + } +#else do_assemble_alias (p->decl, p->target); +#endif +/*APPLE LOCAL end LLVM */ alias_pairs = NULL; } @@ -4784,12 +4778,8 @@ void assemble_alias (tree decl, tree target) { -/* APPLE LOCAL begin LLVM */ -#ifndef ENABLE_LLVM tree target_decl; -#endif -/* APPLE LOCAL end LLVM */ - + #if !defined (ASM_OUTPUT_DEF) # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL) error ("%Jalias definitions not supported in this configuration", decl); @@ -4825,20 +4815,16 @@ else cgraph_varpool_node (decl)->alias = true; -/* APPLE LOCAL begin LLVM */ -#ifdef ENABLE_LLVM - /* Can we emit alias right now (usually true for C functions)? If yes - do it, - * otherwise save for late processing */ - if (emit_alias_to_llvm(decl, target, 0) == -1) -#else /* If the target has already been emitted, we don't have to queue the alias. This saves a tad o memory. */ target_decl = find_decl_and_mark_needed (decl, target); if (target_decl && TREE_ASM_WRITTEN (target_decl)) - do_assemble_alias (decl, target); - else +#ifdef ENABLE_LLVM + emit_alias_to_llvm(decl, target, target_decl); +#else + do_assemble_alias (decl, target); #endif -/* APPLE LOCAL end LLVM */ + else { alias_pair p; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits