From 97a296f743c3cb78ae106a8e4800a5daa0ca6fc9 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Wed, 21 Jul 2004 20:11:11 +0000 Subject: [PATCH] * Fix printing of signed immediate values (Nate Begeman) * Fix printing of `zeroinitializer' * Fix printing of `linkonce' globals, complete with stubs git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15084 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/PPC32AsmPrinter.cpp | 36 +++++++++++++++++++----- lib/Target/PowerPC/PPCAsmPrinter.cpp | 36 +++++++++++++++++++----- lib/Target/PowerPC/PowerPCAsmPrinter.cpp | 36 +++++++++++++++++++----- 3 files changed, 87 insertions(+), 21 deletions(-) diff --git a/lib/Target/PowerPC/PPC32AsmPrinter.cpp b/lib/Target/PowerPC/PPC32AsmPrinter.cpp index 6c6b66afb08..d920137f30a 100644 --- a/lib/Target/PowerPC/PPC32AsmPrinter.cpp +++ b/lib/Target/PowerPC/PPC32AsmPrinter.cpp @@ -52,7 +52,7 @@ namespace { /// Name-mangler for global names. /// Mangler *Mang; - std::set FnStubs, GVStubs; + std::set FnStubs, GVStubs, LinkOnceStubs; std::set Strings; Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0) @@ -331,7 +331,12 @@ void Printer::emitGlobalConstant(const Constant *CV) { case Type::FloatTyID: case Type::DoubleTyID: assert (0 && "Should have already output floating point constant."); default: - assert (0 && "Can't handle printing this type of thing"); + if (CV == Constant::getNullValue(type)) { // Zero initializer? + O << ".space\t" << TD.getTypeSize(type) << "\n"; + return; + } + std::cerr << "Can't handle printing: " << *CV; + abort(); break; } O << "\t"; @@ -413,8 +418,11 @@ void Printer::printOp(const MachineOperand &MO, return; case MachineOperand::MO_SignExtendedImmed: + O << (short)MO.getImmedValue(); + return; + case MachineOperand::MO_UnextendedImmed: - O << (int)MO.getImmedValue(); + O << (unsigned short)MO.getImmedValue(); return; case MachineOperand::MO_PCRelativeDisp: @@ -601,9 +609,8 @@ bool Printer::doFinalization(Module &M) { unsigned Size = TD.getTypeSize(C->getType()); unsigned Align = TD.getTypeAlignment(C->getType()); - if (C->isNullValue() && - (I->hasLinkOnceLinkage() || I->hasInternalLinkage() || - I->hasWeakLinkage() /* FIXME: Verify correct */)) { + if (C->isNullValue() && /* FIXME: Verify correct */ + (I->hasInternalLinkage() || I->hasWeakLinkage())) { SwitchSection(O, CurSection, ".data"); if (I->hasInternalLinkage()) O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType()) @@ -616,13 +623,18 @@ bool Printer::doFinalization(Module &M) { } else { switch (I->getLinkage()) { case GlobalValue::LinkOnceLinkage: + O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n" + << ".weak_definition " << name << '\n' + << ".private_extern " << name << '\n' + << ".section __DATA,__datacoal_nt,coalesced,no_toc\n"; + LinkOnceStubs.insert(name); + break; case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak. // Nonnull linkonce -> weak O << "\t.weak " << name << "\n"; SwitchSection(O, CurSection, ""); O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"; break; - case GlobalValue::AppendingLinkage: // FIXME: appending linkage variables should go into a section of // their name or something. For now, just emit them as external. @@ -645,6 +657,16 @@ bool Printer::doFinalization(Module &M) { } } + // Output stubs for link-once variables + if (LinkOnceStubs.begin() != LinkOnceStubs.end()) + O << ".data\n.align 2\n"; + for (std::set::iterator i = LinkOnceStubs.begin(), + e = LinkOnceStubs.end(); i != e; ++i) + { + O << *i << "$non_lazy_ptr:\n" + << "\t.long\t" << *i << '\n'; + } + // Output stubs for dynamically-linked functions for (std::set::iterator i = FnStubs.begin(), e = FnStubs.end(); i != e; ++i) diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp index 6c6b66afb08..d920137f30a 100644 --- a/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -52,7 +52,7 @@ namespace { /// Name-mangler for global names. /// Mangler *Mang; - std::set FnStubs, GVStubs; + std::set FnStubs, GVStubs, LinkOnceStubs; std::set Strings; Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0) @@ -331,7 +331,12 @@ void Printer::emitGlobalConstant(const Constant *CV) { case Type::FloatTyID: case Type::DoubleTyID: assert (0 && "Should have already output floating point constant."); default: - assert (0 && "Can't handle printing this type of thing"); + if (CV == Constant::getNullValue(type)) { // Zero initializer? + O << ".space\t" << TD.getTypeSize(type) << "\n"; + return; + } + std::cerr << "Can't handle printing: " << *CV; + abort(); break; } O << "\t"; @@ -413,8 +418,11 @@ void Printer::printOp(const MachineOperand &MO, return; case MachineOperand::MO_SignExtendedImmed: + O << (short)MO.getImmedValue(); + return; + case MachineOperand::MO_UnextendedImmed: - O << (int)MO.getImmedValue(); + O << (unsigned short)MO.getImmedValue(); return; case MachineOperand::MO_PCRelativeDisp: @@ -601,9 +609,8 @@ bool Printer::doFinalization(Module &M) { unsigned Size = TD.getTypeSize(C->getType()); unsigned Align = TD.getTypeAlignment(C->getType()); - if (C->isNullValue() && - (I->hasLinkOnceLinkage() || I->hasInternalLinkage() || - I->hasWeakLinkage() /* FIXME: Verify correct */)) { + if (C->isNullValue() && /* FIXME: Verify correct */ + (I->hasInternalLinkage() || I->hasWeakLinkage())) { SwitchSection(O, CurSection, ".data"); if (I->hasInternalLinkage()) O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType()) @@ -616,13 +623,18 @@ bool Printer::doFinalization(Module &M) { } else { switch (I->getLinkage()) { case GlobalValue::LinkOnceLinkage: + O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n" + << ".weak_definition " << name << '\n' + << ".private_extern " << name << '\n' + << ".section __DATA,__datacoal_nt,coalesced,no_toc\n"; + LinkOnceStubs.insert(name); + break; case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak. // Nonnull linkonce -> weak O << "\t.weak " << name << "\n"; SwitchSection(O, CurSection, ""); O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"; break; - case GlobalValue::AppendingLinkage: // FIXME: appending linkage variables should go into a section of // their name or something. For now, just emit them as external. @@ -645,6 +657,16 @@ bool Printer::doFinalization(Module &M) { } } + // Output stubs for link-once variables + if (LinkOnceStubs.begin() != LinkOnceStubs.end()) + O << ".data\n.align 2\n"; + for (std::set::iterator i = LinkOnceStubs.begin(), + e = LinkOnceStubs.end(); i != e; ++i) + { + O << *i << "$non_lazy_ptr:\n" + << "\t.long\t" << *i << '\n'; + } + // Output stubs for dynamically-linked functions for (std::set::iterator i = FnStubs.begin(), e = FnStubs.end(); i != e; ++i) diff --git a/lib/Target/PowerPC/PowerPCAsmPrinter.cpp b/lib/Target/PowerPC/PowerPCAsmPrinter.cpp index 6c6b66afb08..d920137f30a 100644 --- a/lib/Target/PowerPC/PowerPCAsmPrinter.cpp +++ b/lib/Target/PowerPC/PowerPCAsmPrinter.cpp @@ -52,7 +52,7 @@ namespace { /// Name-mangler for global names. /// Mangler *Mang; - std::set FnStubs, GVStubs; + std::set FnStubs, GVStubs, LinkOnceStubs; std::set Strings; Printer(std::ostream &o, TargetMachine &tm) : O(o), TM(tm), labelNumber(0) @@ -331,7 +331,12 @@ void Printer::emitGlobalConstant(const Constant *CV) { case Type::FloatTyID: case Type::DoubleTyID: assert (0 && "Should have already output floating point constant."); default: - assert (0 && "Can't handle printing this type of thing"); + if (CV == Constant::getNullValue(type)) { // Zero initializer? + O << ".space\t" << TD.getTypeSize(type) << "\n"; + return; + } + std::cerr << "Can't handle printing: " << *CV; + abort(); break; } O << "\t"; @@ -413,8 +418,11 @@ void Printer::printOp(const MachineOperand &MO, return; case MachineOperand::MO_SignExtendedImmed: + O << (short)MO.getImmedValue(); + return; + case MachineOperand::MO_UnextendedImmed: - O << (int)MO.getImmedValue(); + O << (unsigned short)MO.getImmedValue(); return; case MachineOperand::MO_PCRelativeDisp: @@ -601,9 +609,8 @@ bool Printer::doFinalization(Module &M) { unsigned Size = TD.getTypeSize(C->getType()); unsigned Align = TD.getTypeAlignment(C->getType()); - if (C->isNullValue() && - (I->hasLinkOnceLinkage() || I->hasInternalLinkage() || - I->hasWeakLinkage() /* FIXME: Verify correct */)) { + if (C->isNullValue() && /* FIXME: Verify correct */ + (I->hasInternalLinkage() || I->hasWeakLinkage())) { SwitchSection(O, CurSection, ".data"); if (I->hasInternalLinkage()) O << "\t.lcomm " << name << "," << TD.getTypeSize(C->getType()) @@ -616,13 +623,18 @@ bool Printer::doFinalization(Module &M) { } else { switch (I->getLinkage()) { case GlobalValue::LinkOnceLinkage: + O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n" + << ".weak_definition " << name << '\n' + << ".private_extern " << name << '\n' + << ".section __DATA,__datacoal_nt,coalesced,no_toc\n"; + LinkOnceStubs.insert(name); + break; case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak. // Nonnull linkonce -> weak O << "\t.weak " << name << "\n"; SwitchSection(O, CurSection, ""); O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"; break; - case GlobalValue::AppendingLinkage: // FIXME: appending linkage variables should go into a section of // their name or something. For now, just emit them as external. @@ -645,6 +657,16 @@ bool Printer::doFinalization(Module &M) { } } + // Output stubs for link-once variables + if (LinkOnceStubs.begin() != LinkOnceStubs.end()) + O << ".data\n.align 2\n"; + for (std::set::iterator i = LinkOnceStubs.begin(), + e = LinkOnceStubs.end(); i != e; ++i) + { + O << *i << "$non_lazy_ptr:\n" + << "\t.long\t" << *i << '\n'; + } + // Output stubs for dynamically-linked functions for (std::set::iterator i = FnStubs.begin(), e = FnStubs.end(); i != e; ++i) -- 2.34.1