eliminate the ExtWeakSymbols set from AsmPrinter. This eliminates

a bunch of code from all the targets, and eliminates nondeterministic
ordering of directives being emitted in the output.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74096 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-06-24 18:52:01 +00:00
parent 52cff83526
commit 0a7befa8bd
8 changed files with 46 additions and 134 deletions

View File

@ -63,9 +63,6 @@ namespace llvm {
/// that ought be fixed soon.
DwarfWriter *DW;
// Necessary for external weak linkage support
std::set<const GlobalValue*> ExtWeakSymbols;
/// OptLevel - Generating code at a specific optimization level.
CodeGenOpt::Level OptLevel;
public:

View File

@ -192,13 +192,26 @@ bool AsmPrinter::doInitialization(Module &M) {
}
bool AsmPrinter::doFinalization(Module &M) {
// If the target wants to know about weak references, print them all.
if (TAI->getWeakRefDirective()) {
if (!ExtWeakSymbols.empty())
SwitchToDataSection("");
// FIXME: This is not lazy, it would be nice to only print weak references
// to stuff that is actually used. Note that doing so would require targets
// to notice uses in operands (due to constant exprs etc). This should
// happen with the MC stuff eventually.
SwitchToDataSection("");
for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
e = ExtWeakSymbols.end(); i != e; ++i)
O << TAI->getWeakRefDirective() << Mang->getValueName(*i) << '\n';
// Print out module-level global variables here.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (I->hasExternalWeakLinkage())
O << TAI->getWeakRefDirective() << Mang->getValueName(I) << '\n';
}
for (Module::const_iterator I = M.begin(), E = M.end();
I != E; ++I) {
if (I->hasExternalWeakLinkage())
O << TAI->getWeakRefDirective() << Mang->getValueName(I) << '\n';
}
}
if (TAI->getSetDirective()) {
@ -207,7 +220,7 @@ bool AsmPrinter::doFinalization(Module &M) {
O << '\n';
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
I!=E; ++I) {
I != E; ++I) {
std::string Name = Mang->getValueName(I);
std::string Target;
@ -235,7 +248,7 @@ bool AsmPrinter::doFinalization(Module &M) {
// If we don't have any trampolines, then we don't require stack memory
// to be executable. Some targets have a directive to declare this.
Function* InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
if (TAI->getNonexecutableStackDirective())
O << TAI->getNonexecutableStackDirective() << '\n';

View File

@ -169,11 +169,6 @@ namespace {
O << ")";
}
O << "\n";
// If the constant pool value is a extern weak symbol, remember to emit
// the weak reference.
if (GV && GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
}
void getAnalysisUsage(AnalysisUsage &AU) const {
@ -331,8 +326,6 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
if (isCallOp && Subtarget->isTargetELF() &&
TM.getRelocationModel() == Reloc::PIC_)
O << "(PLT)";
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
break;
}
case MachineOperand::MO_ExternalSymbol: {
@ -749,10 +742,6 @@ void ARMAsmPrinter::printCPInstOperand(const MachineInstr *MI, int OpNo,
EmitMachineConstantPoolValue(MCPE.Val.MachineCPVal);
} else {
EmitGlobalConstant(MCPE.Val.ConstVal);
// remember to emit the weak reference
if (const GlobalValue *GV = dyn_cast<GlobalValue>(MCPE.Val.ConstVal))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
}
}
}
@ -1046,12 +1035,6 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (TAI->hasDotTypeDotSizeDirective())
O << "\t.size " << name << ", " << Size << "\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
}

View File

@ -121,8 +121,6 @@ void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
case MachineOperand::MO_GlobalAddress: {
GlobalValue *GV = MO.getGlobal();
O << Mang->getValueName(GV);
if (GV->isDeclaration() && GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
return;
}
@ -265,12 +263,6 @@ void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
O << name << ":\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
}

View File

@ -361,9 +361,6 @@ void SPUAsmPrinter::printOp(const MachineOperand &MO) {
}
}
O << Name;
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
return;
}
@ -584,12 +581,6 @@ void LinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
PrintUnmangledNameSafely(GVar, O);
O << "'\n";
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
}

View File

@ -194,8 +194,6 @@ namespace {
std::string Name = Mang->getValueName(GV);
FnStubs.insert(Name);
printSuffixedName(Name, "$stub");
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
return;
}
}
@ -403,17 +401,12 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
GVStubs.insert(Name);
printSuffixedName(Name, "$non_lazy_ptr");
}
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
return;
}
}
O << Name;
printOffset(MO.getOffset());
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
return;
}
@ -743,12 +736,6 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
}
O << '\n';
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
}
@ -987,12 +974,6 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
}
O << '\n';
// If the initializer is a extern weak symbol, remember to emit the weak
// reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C);
O << '\n';
}

View File

@ -372,9 +372,6 @@ void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) {
FnStubs.insert(Name);
}
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
printOffset(MO.getOffset());
if (needCloseParen)
@ -549,9 +546,6 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
O << Name;
}
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
printOffset(MO.getOffset());
if (needCloseParen)
@ -1086,44 +1080,8 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
if (I->hasDLLExportLinkage())
DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
// If the global is a extern weak symbol, remember to emit the weak
// reference!
// FIXME: This is rather hacky, since we'll emit references to ALL weak
// stuff, not used. But currently it's the only way to deal with extern weak
// initializers hidden deep inside constant expressions.
if (I->hasExternalWeakLinkage())
ExtWeakSymbols.insert(I);
}
for (Module::const_iterator I = M.begin(), E = M.end();
I != E; ++I) {
// If the global is a extern weak symbol, remember to emit the weak
// reference!
// FIXME: This is rather hacky, since we'll emit references to ALL weak
// stuff, not used. But currently it's the only way to deal with extern weak
// initializers hidden deep inside constant expressions.
if (I->hasExternalWeakLinkage())
ExtWeakSymbols.insert(I);
}
// Output linker support code for dllexported globals
if (!DLLExportedGVs.empty())
SwitchToDataSection(".section .drectve");
for (StringSet<>::iterator i = DLLExportedGVs.begin(),
e = DLLExportedGVs.end();
i != e; ++i)
O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
if (!DLLExportedFns.empty())
SwitchToDataSection(".section .drectve");
for (StringSet<>::iterator i = DLLExportedFns.begin(),
e = DLLExportedFns.end();
i != e; ++i)
O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
if (Subtarget->isTargetDarwin()) {
SwitchToDataSection("");
@ -1195,10 +1153,32 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
}
}
// Output linker support code for dllexported globals on windows.
if (!DLLExportedGVs.empty()) {
SwitchToDataSection(".section .drectve");
for (StringSet<>::iterator i = DLLExportedGVs.begin(),
e = DLLExportedGVs.end(); i != e; ++i)
O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
}
if (!DLLExportedFns.empty()) {
SwitchToDataSection(".section .drectve");
for (StringSet<>::iterator i = DLLExportedFns.begin(),
e = DLLExportedFns.end();
i != e; ++i)
O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
}
// Emit final debug information.
// FIXME: Sink into DoFinalization.
if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
DW->EndModule();
// Do common shutdown.
bool Changed = AsmPrinter::doFinalization(M);
if (NewAsmPrinter) {
Streamer->Finish();
@ -1209,7 +1189,7 @@ bool X86ATTAsmPrinter::doFinalization(Module &M) {
Context = 0;
}
return AsmPrinter::doFinalization(M);
return Changed;
}
// Include the auto-generated portion of the assembly writer.

View File

@ -244,9 +244,6 @@ emitGlobal(const GlobalVariable *GV)
// Mark the end of the global
O << "\t.cc_bottom " << name << ".data\n";
} else {
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
}
}
@ -375,12 +372,7 @@ void XCoreAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
printBasicBlockLabel(MO.getMBB());
break;
case MachineOperand::MO_GlobalAddress:
{
const GlobalValue *GV = MO.getGlobal();
O << Mang->getValueName(GV);
if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(GV);
}
O << Mang->getValueName(MO.getGlobal());
break;
case MachineOperand::MO_ExternalSymbol:
O << MO.getSymbolName();
@ -430,25 +422,8 @@ bool XCoreAsmPrinter::doInitialization(Module &M) {
bool Result = AsmPrinter::doInitialization(M);
DW = getAnalysisIfAvailable<DwarfWriter>();
if (!FileDirective.empty()) {
if (!FileDirective.empty())
emitFileDirective(FileDirective);
}
// Print out type strings for external functions here
for (Module::const_iterator I = M.begin(), E = M.end();
I != E; ++I) {
if (I->isDeclaration() && !I->isIntrinsic()) {
switch (I->getLinkage()) {
default:
assert(0 && "Unexpected linkage");
case Function::ExternalWeakLinkage:
ExtWeakSymbols.insert(I);
// fallthrough
case Function::ExternalLinkage:
break;
}
}
}
return Result;
}