move ExtWeakSymbols to AsmPrinter

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32648 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2006-12-18 03:37:18 +00:00
parent 0be3ed886c
commit 15404d060b
7 changed files with 23 additions and 39 deletions

View File

@ -18,6 +18,7 @@
#include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/Support/DataTypes.h" #include "llvm/Support/DataTypes.h"
#include <set>
namespace llvm { namespace llvm {
class Constant; class Constant;
@ -39,6 +40,10 @@ namespace llvm {
/// ///
unsigned FunctionNumber; unsigned FunctionNumber;
protected:
// Necessary for external weak linkage support
std::set<const GlobalValue*> ExtWeakSymbols;
public: public:
/// Output stream on which we're printing assembly code. /// Output stream on which we're printing assembly code.
/// ///

View File

@ -106,6 +106,18 @@ bool AsmPrinter::doInitialization(Module &M) {
} }
bool AsmPrinter::doFinalization(Module &M) { bool AsmPrinter::doFinalization(Module &M) {
if (TAI->getWeakRefDirective()) {
if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
SwitchToDataSection("");
for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
e = ExtWeakSymbols.end(); i != e; ++i) {
const GlobalValue *GV = *i;
std::string Name = Mang->getValueName(GV);
O << TAI->getWeakRefDirective() << Name << "\n";
}
}
delete Mang; Mang = 0; delete Mang; Mang = 0;
return false; return false;
} }

View File

@ -62,8 +62,6 @@ namespace {
: AsmPrinter(O, TM, T) { : AsmPrinter(O, TM, T) {
} }
std::set<std::string> ExtWeakSymbols;
/// We name each basic block in a Function with a unique number, so /// We name each basic block in a Function with a unique number, so
/// that we can consistently refer to them later. This is cleared /// that we can consistently refer to them later. This is cleared
/// at the beginning of each call to runOnMachineFunction(). /// at the beginning of each call to runOnMachineFunction().
@ -246,7 +244,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
std::string Name = Mang->getValueName(GV); std::string Name = Mang->getValueName(GV);
O << Name; O << Name;
if (GV->hasExternalWeakLinkage()) { if (GV->hasExternalWeakLinkage()) {
ExtWeakSymbols.insert(Name); ExtWeakSymbols.insert(GV);
} }
} }
break; break;
@ -337,13 +335,6 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
} }
} }
if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
SwitchToDataSection("");
for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
e = ExtWeakSymbols.end(); i != e; ++i) {
O << TAI->getWeakRefDirective() << *i << "\n";
}
AsmPrinter::doFinalization(M); AsmPrinter::doFinalization(M);
return false; // success return false; // success
} }

View File

@ -50,9 +50,6 @@ namespace {
struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter { struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
std::set<std::string> FnStubs, GVStubs; std::set<std::string> FnStubs, GVStubs;
const PPCSubtarget &Subtarget; const PPCSubtarget &Subtarget;
// Necessary for external weak linkage support
std::set<std::string> ExtWeakSymbols;
PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
: AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget<PPCSubtarget>()) { : AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget<PPCSubtarget>()) {
@ -162,7 +159,7 @@ namespace {
FnStubs.insert(Name); FnStubs.insert(Name);
O << "L" << Name << "$stub"; O << "L" << Name << "$stub";
if (GV->hasExternalWeakLinkage()) if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(Name); ExtWeakSymbols.insert(GV);
return; return;
} }
} }
@ -337,7 +334,7 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
O << Name; O << Name;
if (GV->hasExternalWeakLinkage()) if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(Name); ExtWeakSymbols.insert(GV);
return; return;
} }
@ -658,22 +655,13 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
// reference! // reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage()) if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(Mang->getValueName(GV)); ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C); EmitGlobalConstant(C);
O << '\n'; O << '\n';
} }
} }
if (TAI->getWeakRefDirective()) {
if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
SwitchToDataSection("");
for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
e = ExtWeakSymbols.end(); i != e; ++i) {
O << TAI->getWeakRefDirective() << *i << "\n";
}
}
bool isPPC64 = TD->getPointerSizeInBits() == 64; bool isPPC64 = TD->getPointerSizeInBits() == 64;
// Output stubs for dynamically-linked functions // Output stubs for dynamically-linked functions

View File

@ -257,7 +257,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
} }
if (GV->hasExternalWeakLinkage()) if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(Name); ExtWeakSymbols.insert(GV);
int Offset = MO.getOffset(); int Offset = MO.getOffset();
if (Offset > 0) if (Offset > 0)

View File

@ -250,7 +250,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
// reference! // reference!
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
if (GV->hasExternalWeakLinkage()) if (GV->hasExternalWeakLinkage())
ExtWeakSymbols.insert(Mang->getValueName(GV)); ExtWeakSymbols.insert(GV);
EmitGlobalConstant(C); EmitGlobalConstant(C);
O << '\n'; O << '\n';
@ -278,15 +278,6 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
O << "\t.ascii \" -export:" << *i << "\"\n"; O << "\t.ascii \" -export:" << *i << "\"\n";
} }
if (TAI->getWeakRefDirective()) {
if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
SwitchToDataSection("");
for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
e = ExtWeakSymbols.end(); i != e; ++i) {
O << TAI->getWeakRefDirective() << *i << "\n";
}
}
if (Subtarget->isTargetDarwin()) { if (Subtarget->isTargetDarwin()) {
SwitchToDataSection(""); SwitchToDataSection("");

View File

@ -86,9 +86,6 @@ struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
// Necessary for dllexport support // Necessary for dllexport support
std::set<std::string> DLLExportedFns, DLLExportedGVs; std::set<std::string> DLLExportedFns, DLLExportedGVs;
// Necessary for external weak linkage support
std::set<std::string> ExtWeakSymbols;
inline static bool isScale(const MachineOperand &MO) { inline static bool isScale(const MachineOperand &MO) {
return MO.isImmediate() && return MO.isImmediate() &&
(MO.getImmedValue() == 1 || MO.getImmedValue() == 2 || (MO.getImmedValue() == 1 || MO.getImmedValue() == 2 ||