[llvm-commits] [llvm-gcc-4.2] r78036 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp tree.h varasm.c
Bill Wendling
isanbard at gmail.com
Mon Aug 3 20:17:08 PDT 2009
Author: void
Date: Mon Aug 3 22:17:06 2009
New Revision: 78036
URL: http://llvm.org/viewvc/llvm-project?rev=78036&view=rev
Log:
Don't adorn ObjC metadata with "\1[Ll]_". This is now done in the back-end,
where it should be. Declare what used to be "\1L_OBJC_*" metadata "private" and
what used to be "\1l_OBJC_" linker private.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
llvm-gcc-4.2/trunk/gcc/tree.h
llvm-gcc-4.2/trunk/gcc/varasm.c
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=78036&r1=78035&r2=78036&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Mon Aug 3 22:17:06 2009
@@ -102,6 +102,7 @@
std::vector<std::pair<Constant*, int> > StaticCtors, StaticDtors;
SmallSetVector<Constant*, 32> AttributeUsedGlobals;
+SmallSetVector<Constant*, 32> AttributeCompilerUsedGlobals;
std::vector<Constant*> AttributeAnnotateGlobals;
/// PerFunctionPasses - This is the list of cleanup passes run per-function
@@ -205,6 +206,11 @@
AttributeUsedGlobals.insert(New);
}
+ if (AttributeCompilerUsedGlobals.count(Old)) {
+ AttributeCompilerUsedGlobals.remove(Old);
+ AttributeCompilerUsedGlobals.insert(New);
+ }
+
for (unsigned i = 0, e = StaticCtors.size(); i != e; ++i) {
if (StaticCtors[i].first == Old)
StaticCtors[i].first = New;
@@ -788,6 +794,7 @@
sys::Program::ChangeStdoutToBinary();
AttributeUsedGlobals.clear();
+ AttributeCompilerUsedGlobals.clear();
timevar_pop(TV_LLVM_INIT);
}
@@ -843,7 +850,8 @@
if (!AttributeUsedGlobals.empty()) {
std::vector<Constant *> AUGs;
const Type *SBP= PointerType::getUnqual(Type::Int8Ty);
- for (SmallSetVector<Constant *,32>::iterator AI = AttributeUsedGlobals.begin(),
+ for (SmallSetVector<Constant *,32>::iterator
+ AI = AttributeUsedGlobals.begin(),
AE = AttributeUsedGlobals.end(); AI != AE; ++AI) {
Constant *C = *AI;
AUGs.push_back(TheFolder->CreateBitCast(C, SBP));
@@ -858,6 +866,25 @@
AttributeUsedGlobals.clear();
}
+ if (!AttributeCompilerUsedGlobals.empty()) {
+ std::vector<Constant *> ACUGs;
+ const Type *SBP= PointerType::getUnqual(Type::Int8Ty);
+ for (SmallSetVector<Constant *,32>::iterator
+ AI = AttributeCompilerUsedGlobals.begin(),
+ AE = AttributeCompilerUsedGlobals.end(); AI != AE; ++AI) {
+ Constant *C = *AI;
+ ACUGs.push_back(TheFolder->CreateBitCast(C, SBP));
+ }
+
+ ArrayType *AT = ArrayType::get(SBP, ACUGs.size());
+ Constant *Init = ConstantArray::get(AT, ACUGs);
+ GlobalValue *gv = new GlobalVariable(*TheModule, AT, false,
+ GlobalValue::AppendingLinkage, Init,
+ "llvm.compiler.used");
+ gv->setSection("llvm.metadata");
+ AttributeCompilerUsedGlobals.clear();
+ }
+
// Add llvm.global.annotations
if (!AttributeAnnotateGlobals.empty()) {
Constant *Array = ConstantArray::get(
@@ -1051,6 +1078,8 @@
// A weak alias has TREE_PUBLIC set but not the other bits.
if (DECL_LLVM_PRIVATE(decl))
Linkage = GlobalValue::PrivateLinkage;
+ else if (DECL_LLVM_LINKER_PRIVATE(decl))
+ Linkage = GlobalValue::LinkerPrivateLinkage;
else if (DECL_WEAK(decl))
// The user may have explicitly asked for weak linkage - ignore flag_odr.
Linkage = GlobalValue::WeakAnyLinkage;
@@ -1317,6 +1346,9 @@
if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
&& DECL_LLVM_PRIVATE(decl)) {
Linkage = GlobalValue::PrivateLinkage;
+ } else if (CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_WITH_VIS)
+ && DECL_LLVM_LINKER_PRIVATE(decl)) {
+ Linkage = GlobalValue::LinkerPrivateLinkage;
} else if (!TREE_PUBLIC(decl)) {
Linkage = GlobalValue::InternalLinkage;
} else if (DECL_WEAK(decl)) {
@@ -1376,8 +1408,12 @@
}
// Handle used decls
- if (DECL_PRESERVE_P (decl))
- AttributeUsedGlobals.insert(GV);
+ if (DECL_PRESERVE_P (decl)) {
+ if (DECL_LLVM_PRIVATE (decl))
+ AttributeUsedGlobals.insert(GV);
+ else if (DECL_LLVM_LINKER_PRIVATE (decl))
+ AttributeCompilerUsedGlobals.insert(GV);
+ }
// Add annotate attributes for globals
if (DECL_ATTRIBUTES(decl))
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=78036&r1=78035&r2=78036&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Mon Aug 3 22:17:06 2009
@@ -474,6 +474,8 @@
// Compute the linkage that the function should get.
if (DECL_LLVM_PRIVATE(FnDecl)) {
Fn->setLinkage(Function::PrivateLinkage);
+ } else if (DECL_LLVM_LINKER_PRIVATE(FnDecl)) {
+ Fn->setLinkage(Function::LinkerPrivateLinkage);
} else if (!TREE_PUBLIC(FnDecl) /*|| lang_hooks.llvm_is_in_anon(subr)*/) {
Fn->setLinkage(Function::InternalLinkage);
} else if (DECL_COMDAT(FnDecl)) {
@@ -1995,21 +1997,21 @@
// what exception is being unwound, append a catch-all.
// The representation of a catch-all is language specific.
- Value *Catch_All;
+ Value *CatchAll;
if (!lang_eh_catch_all) {
// Use a "cleanup" - this should be good enough for most languages.
- Catch_All = ConstantInt::get(Type::Int32Ty, 0);
+ CatchAll = ConstantInt::get(Type::Int32Ty, 0);
} else {
tree catch_all_type = lang_eh_catch_all();
if (catch_all_type == NULL_TREE)
// Use a C++ style null catch-all object.
- Catch_All = Constant::getNullValue(
+ CatchAll = Constant::getNullValue(
PointerType::getUnqual(Type::Int8Ty));
else
// This language has a type that catches all others.
- Catch_All = Emit(catch_all_type, 0);
+ CatchAll = Emit(catch_all_type, 0);
}
- Args.push_back(Catch_All);
+ Args.push_back(CatchAll);
}
// Emit the selector call.
Modified: llvm-gcc-4.2/trunk/gcc/tree.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/tree.h?rev=78036&r1=78035&r2=78036&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/tree.h (original)
+++ llvm-gcc-4.2/trunk/gcc/tree.h Mon Aug 3 22:17:06 2009
@@ -2927,6 +2927,8 @@
#ifdef ENABLE_LLVM
#define DECL_LLVM_PRIVATE(NODE) \
(DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.llvm_private_flag)
+#define DECL_LLVM_LINKER_PRIVATE(NODE) \
+ (DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.llvm_linker_private_flag)
#endif
/* LLVM LOCAL end */
@@ -3069,6 +3071,7 @@
/* LLVM LOCAL begin */
unsigned llvm_private_flag : 1;
+ unsigned llvm_linker_private_flag : 1;
/* LLVM LOCAL end */
ENUM_BITFIELD(symbol_visibility) visibility : 2;
@@ -3091,7 +3094,7 @@
unsigned block_synthesized_function : 1;
/* APPLE LOCAL radar 5847976 */
unsigned block_weak : 1;
- /* 4 unused bits (llvm). */
+ /* 3 unused bits (llvm). */
/* APPLE LOCAL end radar 5932809 - copyable byref blocks */
/* APPLE LOCAL end radar 5732232 - blocks */
};
Modified: llvm-gcc-4.2/trunk/gcc/varasm.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/varasm.c?rev=78036&r1=78035&r2=78036&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/varasm.c (original)
+++ llvm-gcc-4.2/trunk/gcc/varasm.c Mon Aug 3 22:17:06 2009
@@ -755,23 +755,45 @@
void
set_user_assembler_name (tree decl, const char *name)
{
- char *starred = alloca (strlen (name) + 2);
+ size_t len = strlen (name);
+ char *starred = alloca (len + 2);
/* LLVM LOCAL begin */
#ifndef ENABLE_LLVM
starred[0] = '*';
strcpy (starred + 1, name);
#else
- /* If the name isn't an LLVM intrinsic, add a starting '\1' character to
- * indicate that the target assembler shouldn't modify the name. If it *is*
- * an LLVM intrinsic name, just set the name, to support code like this:
- * unsigned bswap(unsigned) __asm__("llvm.bswap");
- */
- if (name[0] != 'l' || name[1] != 'l' || name[2] != 'v' || name[3] != 'm'
- || name[4] != '.') {
- starred[0] = 1;
- strcpy (starred + 1, name);
- } else {
- strcpy (starred, name);
+ {
+ /* If the name isn't an LLVM intrinsic, add a starting '\1' character to
+ indicate that the target assembler shouldn't modify the name. If it *is*
+ an LLVM intrinsic name, just set the name, to support code like this:
+ unsigned bswap(unsigned) __asm__("llvm.bswap"); */
+ bool has_llvm_prefix =
+ (len > 5 && name[0] == 'l' && name[1] == 'l' && name[2] == 'v' &&
+ name[3] == 'm' && name[4] == '.');
+
+ /* If the name is an OBJC metadata name, then don't prepend a '\1' character
+ to it. Instead, mark it as either "private" or "linker private". */
+ bool has_objc_prefix =
+ (len > 7 && (name[0] == 'l' || name[0] == 'L') && name[1] == '_' &&
+ ((name[2] == 'O' && name[3] == 'B' && name[4] == 'J' && name[5] == 'C') ||
+ (name[2] == 'o' && name[3] == 'b' && name[4] == 'j' && name[5] == 'c')) &&
+ name[6] == '_');
+
+ if (!has_llvm_prefix && !has_objc_prefix) {
+ starred[0] = 1;
+ strcpy (starred + 1, name);
+ } else {
+ strcpy (starred, name);
+
+ if (has_objc_prefix) {
+ DECL_LLVM_PRIVATE (decl) = (name[0] == 'L');
+ DECL_LLVM_LINKER_PRIVATE (decl) = (name[0] == 'l');
+
+ /* Remove the "[Ll]_" prefix. The LLVM assembly printer is now
+ intelligent enough to add the appropriate prefix to the name. */
+ strcpy (starred, &name[2]);
+ }
+ }
}
#endif
/* LLVM LOCAL end */
More information about the llvm-commits
mailing list