[llvm-commits] [llvm-gcc-4.2] r53152 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp llvm-internal.h
Anton Korobeynikov
asl at math.spbu.ru
Sat Jul 5 14:39:14 PDT 2008
Author: asl
Date: Sat Jul 5 16:39:14 2008
New Revision: 53152
URL: http://llvm.org/viewvc/llvm-project?rev=53152&view=rev
Log:
Improve visibility support - don't propagate visibility for external
symbols, unless user explicitely wants so.
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/llvm-internal.h
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=53152&r1=53151&r2=53152&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Sat Jul 5 16:39:14 2008
@@ -104,6 +104,22 @@
bool OptimizationPassesCreated = false;
static void destroyOptimizationPasses();
+// Forward decl visibility style to global.
+void handleVisibility(tree decl, GlobalValue *GV) {
+ // If decl has visibility specified explicitely (via attribute) - honour
+ // it. Otherwise (e.g. visibility specified via -fvisibility=hidden) honour
+ // only if symbol is local.
+ if (TREE_PUBLIC(decl) &&
+ (DECL_VISIBILITY_SPECIFIED(decl) || !DECL_EXTERNAL(decl))) {
+ if (DECL_VISIBILITY(decl) == VISIBILITY_HIDDEN)
+ GV->setVisibility(GlobalValue::HiddenVisibility);
+ else if (DECL_VISIBILITY(decl) == VISIBILITY_PROTECTED)
+ GV->setVisibility(GlobalValue::ProtectedVisibility);
+ else if (DECL_VISIBILITY(decl) == VISIBILITY_DEFAULT)
+ GV->setVisibility(Function::DefaultVisibility);
+ }
+}
+
void llvm_initialize_backend(void) {
// Initialize LLVM options.
std::vector<const char*> Args;
@@ -756,13 +772,8 @@
GlobalAlias* GA = new GlobalAlias(Aliasee->getType(), Linkage, "",
Aliasee, TheModule);
- // Handle visibility style
- if (TREE_PUBLIC(decl)) {
- if (DECL_VISIBILITY(decl) == VISIBILITY_HIDDEN)
- GA->setVisibility(GlobalValue::HiddenVisibility);
- else if (DECL_VISIBILITY(decl) == VISIBILITY_PROTECTED)
- GA->setVisibility(GlobalValue::ProtectedVisibility);
- }
+
+ handleVisibility(decl, GA);
if (V->getType() == GA->getType())
V->replaceAllUsesWith(GA);
@@ -1009,13 +1020,7 @@
TARGET_ADJUST_LLVM_LINKAGE(GV,decl);
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
- // Handle visibility style
- if (TREE_PUBLIC(decl)) {
- if (DECL_VISIBILITY(decl) == VISIBILITY_HIDDEN)
- GV->setVisibility(GlobalValue::HiddenVisibility);
- else if (DECL_VISIBILITY(decl) == VISIBILITY_PROTECTED)
- GV->setVisibility(GlobalValue::ProtectedVisibility);
- }
+ handleVisibility(decl, GV);
// Set the section for the global.
if (TREE_CODE(decl) == VAR_DECL) {
@@ -1201,13 +1206,7 @@
TARGET_ADJUST_LLVM_LINKAGE(FnEntry,decl);
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
- // Handle visibility style
- if (TREE_PUBLIC(decl)) {
- if (DECL_VISIBILITY(decl) == VISIBILITY_HIDDEN)
- FnEntry->setVisibility(GlobalValue::HiddenVisibility);
- else if (DECL_VISIBILITY(decl) == VISIBILITY_PROTECTED)
- FnEntry->setVisibility(GlobalValue::ProtectedVisibility);
- }
+ handleVisibility(decl, FnEntry);
// If FnEntry got renamed, then there is already an object with this name
// in the symbol table. If this happens, the old one must be a forward
@@ -1253,14 +1252,7 @@
TARGET_ADJUST_LLVM_LINKAGE(GV,decl);
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
- // Handle visibility style
- if (TREE_PUBLIC(decl)) {
- if (DECL_VISIBILITY(decl) == VISIBILITY_HIDDEN)
- GV->setVisibility(GlobalValue::HiddenVisibility);
- else if (DECL_VISIBILITY(decl) == VISIBILITY_PROTECTED)
- GV->setVisibility(GlobalValue::ProtectedVisibility);
- }
-
+ handleVisibility(decl, GV);
} else {
// If the global has a name, prevent multiple vars with the same name from
// being created.
@@ -1278,13 +1270,7 @@
TARGET_ADJUST_LLVM_LINKAGE(GV,decl);
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
- // Handle visibility style
- if (TREE_PUBLIC(decl)) {
- if (DECL_VISIBILITY(decl) == VISIBILITY_HIDDEN)
- GV->setVisibility(GlobalValue::HiddenVisibility);
- else if (DECL_VISIBILITY(decl) == VISIBILITY_PROTECTED)
- GV->setVisibility(GlobalValue::ProtectedVisibility);
- }
+ handleVisibility(decl, GV);
// If GV got renamed, then there is already an object with this name in
// the symbol table. If this happens, the old one must be a forward
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=53152&r1=53151&r2=53152&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Sat Jul 5 16:39:14 2008
@@ -592,14 +592,7 @@
"Calling convention disagreement between prototype and impl!");
// The visibility can be changed from the last time we've seen this
// function. Set to current.
- if (TREE_PUBLIC(FnDecl)) {
- if (DECL_VISIBILITY(FnDecl) == VISIBILITY_HIDDEN)
- Fn->setVisibility(Function::HiddenVisibility);
- else if (DECL_VISIBILITY(FnDecl) == VISIBILITY_PROTECTED)
- Fn->setVisibility(Function::ProtectedVisibility);
- else if (DECL_VISIBILITY(FnDecl) == VISIBILITY_DEFAULT)
- Fn->setVisibility(Function::DefaultVisibility);
- }
+ handleVisibility(FnDecl, Fn);
} else {
Function *FnEntry = TheModule->getFunction(Name);
if (FnEntry) {
@@ -646,12 +639,7 @@
#endif /* TARGET_ADJUST_LLVM_LINKAGE */
// Handle visibility style
- if (TREE_PUBLIC(FnDecl)) {
- if (DECL_VISIBILITY(FnDecl) == VISIBILITY_HIDDEN)
- Fn->setVisibility(Function::HiddenVisibility);
- else if (DECL_VISIBILITY(FnDecl) == VISIBILITY_PROTECTED)
- Fn->setVisibility(Function::ProtectedVisibility);
- }
+ handleVisibility(FnDecl, Fn);
// Handle functions in specified sections.
if (DECL_SECTION_NAME(FnDecl))
Modified: llvm-gcc-4.2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-internal.h?rev=53152&r1=53151&r2=53152&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Sat Jul 5 16:39:14 2008
@@ -111,6 +111,7 @@
void writeLLVMValues();
void clearTargetBuiltinCache();
const char* extractRegisterName(union tree_node*);
+void handleVisibility(union tree_node* decl, GlobalValue *GV);
struct StructTypeConversionInfo;
More information about the llvm-commits
mailing list