summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2008-09-03 20:34:58 +0000
committerDale Johannesen <dalej@apple.com>2008-09-03 20:34:58 +0000
commit5c1ff11fc326a56899e1843186f0d04007fef888 (patch)
tree93d18f69200cb156d4fea20b8fa8d505ba937b08 /llvm/lib/CodeGen
parentbec27e2c8b404a98db9cdbdd1bec84dcb1cee238 (diff)
downloadbcm5719-llvm-5c1ff11fc326a56899e1843186f0d04007fef888.tar.gz
bcm5719-llvm-5c1ff11fc326a56899e1843186f0d04007fef888.zip
Do not emit a UsedDirective for things in the llvm.used
list that have internal linkage; the linker doesn't need or want this. (These objects must still be preserved at compile time, so just removing them from the llvm.used list doesn't work.) Should affect only Darwin. llvm-svn: 55722
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index dc88da954ab..a720f04a9ae 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -425,8 +425,34 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
return false;
}
+/// findGlobalValue - if CV is an expression equivalent to a single
+/// global value, return that value.
+const GlobalValue * AsmPrinter::findGlobalValue(const Constant *CV) {
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
+ return GV;
+ else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
+ const TargetData *TD = TM.getTargetData();
+ unsigned Opcode = CE->getOpcode();
+ switch (Opcode) {
+ case Instruction::GetElementPtr: {
+ const Constant *ptrVal = CE->getOperand(0);
+ SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
+ if (TD->getIndexedOffset(ptrVal->getType(), &idxVec[0], idxVec.size()))
+ return 0;
+ return findGlobalValue(ptrVal);
+ }
+ case Instruction::BitCast:
+ return findGlobalValue(CE->getOperand(0));
+ default:
+ return 0;
+ }
+ }
+ return 0;
+}
+
/// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
/// global in the specified llvm.used list as being used with this directive.
+/// Non-globals (i.e. internal linkage) should not be emitted.
void AsmPrinter::EmitLLVMUsedList(Constant *List) {
const char *Directive = TAI->getUsedDirective();
@@ -435,9 +461,12 @@ void AsmPrinter::EmitLLVMUsedList(Constant *List) {
if (InitList == 0) return;
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
- O << Directive;
- EmitConstantValueOnly(InitList->getOperand(i));
- O << '\n';
+ const GlobalValue *GV = findGlobalValue(InitList->getOperand(i));
+ if (GV && !GV->hasInternalLinkage()) {
+ O << Directive;
+ EmitConstantValueOnly(InitList->getOperand(i));
+ O << '\n';
+ }
}
}
OpenPOWER on IntegriCloud