[llvm-commits] [llvm] r54450 - in /llvm/trunk/lib/Target/Sparc: SparcAsmPrinter.cpp SparcTargetAsmInfo.cpp SparcTargetAsmInfo.h SparcTargetMachine.cpp
Anton Korobeynikov
asl at math.spbu.ru
Thu Aug 7 02:51:25 PDT 2008
Author: asl
Date: Thu Aug 7 04:51:25 2008
New Revision: 54450
URL: http://llvm.org/viewvc/llvm-project?rev=54450&view=rev
Log:
Switch Sparc to new section handling stuff. Refactor printing of module-level GVs significantly.
Modified:
llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp
llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h
llvm/trunk/lib/Target/Sparc/SparcTargetMachine.cpp
Modified: llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp?rev=54450&r1=54449&r2=54450&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcAsmPrinter.cpp Thu Aug 7 04:51:25 2008
@@ -54,6 +54,7 @@
return "Sparc Assembly Printer";
}
+ void printModuleLevelGV(const GlobalVariable* GVar);
void printOperand(const MachineInstr *MI, int opNum);
void printMemOperand(const MachineInstr *MI, int opNum,
const char *Modifier = 0);
@@ -61,6 +62,7 @@
bool printInstruction(const MachineInstr *MI); // autogenerated.
bool runOnMachineFunction(MachineFunction &F);
+ std::string getSectionForFunction(const Function &F) const;
bool doInitialization(Module &M);
bool doFinalization(Module &M);
};
@@ -78,6 +80,11 @@
return new SparcAsmPrinter(o, tm, tm.getTargetAsmInfo());
}
+// Substitute old hook with new one temporary
+std::string SparcAsmPrinter::getSectionForFunction(const Function &F) const {
+ return TAI->SectionForGlobal(&F);
+}
+
/// runOnMachineFunction - This uses the printInstruction()
/// method to print assembly for each instruction.
///
@@ -177,21 +184,21 @@
void SparcAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
const char *Modifier) {
printOperand(MI, opNum);
-
+
// If this is an ADD operand, emit it like normal operands.
if (Modifier && !strcmp(Modifier, "arith")) {
O << ", ";
printOperand(MI, opNum+1);
return;
}
-
+
if (MI->getOperand(opNum+1).isRegister() &&
MI->getOperand(opNum+1).getReg() == SP::G0)
return; // don't print "+%g0"
if (MI->getOperand(opNum+1).isImmediate() &&
MI->getOperand(opNum+1).getImm() == 0)
return; // don't print "+0"
-
+
O << "+";
if (MI->getOperand(opNum+1).isGlobalAddress() ||
MI->getOperand(opNum+1).isConstantPoolIndex()) {
@@ -216,77 +223,90 @@
}
bool SparcAsmPrinter::doFinalization(Module &M) {
- const TargetData *TD = TM.getTargetData();
-
// 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->hasInitializer()) { // External global require no code
- // Check to see if this is a special global used by LLVM, if so, emit it.
- if (EmitSpecialLLVMGlobal(I))
- continue;
-
- O << "\n\n";
- std::string name = Mang->getValueName(I);
- Constant *C = I->getInitializer();
- unsigned Size = TD->getABITypeSize(C->getType());
- unsigned Align = TD->getPreferredAlignment(I);
-
- if (C->isNullValue() && (I->hasCommonLinkage() ||
- I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
- I->hasWeakLinkage() /* FIXME: Verify correct */)) {
- SwitchToDataSection(".data", I);
- if (I->hasInternalLinkage())
- O << "\t.local " << name << "\n";
-
- O << "\t.comm " << name << "," << TD->getABITypeSize(C->getType())
- << "," << Align;
- O << "\n";
- } else {
- switch (I->getLinkage()) {
- case GlobalValue::CommonLinkage:
- case GlobalValue::LinkOnceLinkage:
- case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
- // Nonnull linkonce -> weak
- O << "\t.weak " << name << "\n";
- SwitchToDataSection("", I);
- O << "\t.section\t\".llvm.linkonce.d." << name
- << "\",\"aw\", at 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.
- case GlobalValue::ExternalLinkage:
- // If external or appending, declare as a global symbol
- O << "\t.globl " << name << "\n";
- // FALL THROUGH
- case GlobalValue::InternalLinkage:
- if (C->isNullValue())
- SwitchToDataSection(".bss", I);
- else
- SwitchToDataSection(".data", I);
- break;
- case GlobalValue::GhostLinkage:
- cerr << "Should not have any unmaterialized functions!\n";
- abort();
- case GlobalValue::DLLImportLinkage:
- cerr << "DLLImport linkage is not supported by this target!\n";
- abort();
- case GlobalValue::DLLExportLinkage:
- cerr << "DLLExport linkage is not supported by this target!\n";
- abort();
- default:
- assert(0 && "Unknown linkage type!");
- }
-
- O << "\t.align " << Align << "\n";
- O << "\t.type " << name << ",#object\n";
- O << "\t.size " << name << "," << Size << "\n";
- O << name << ":\n";
- EmitGlobalConstant(C);
- }
- }
+ printModuleLevelGV(I);
+
+ O << '\n';
return AsmPrinter::doFinalization(M);
}
+
+void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
+ const TargetData *TD = TM.getTargetData();
+
+ if (!GVar->hasInitializer())
+ return; // External global require no code
+
+ // Check to see if this is a special global used by LLVM, if so, emit it.
+ if (EmitSpecialLLVMGlobal(GVar))
+ return;
+
+ O << "\n\n";
+ std::string SectionName = TAI->SectionForGlobal(GVar);
+ std::string name = Mang->getValueName(GVar);
+ Constant *C = GVar->getInitializer();
+ unsigned Size = TD->getABITypeSize(C->getType());
+ unsigned Align = TD->getPreferredAlignment(GVar);
+
+ // FIXME: ELF supports visibility
+ SwitchToDataSection(SectionName.c_str());
+
+ if (C->isNullValue() && !GVar->hasSection()) {
+ if (!GVar->isThreadLocal() &&
+ (GVar->hasInternalLinkage() || GVar->isWeakForLinker())) {
+ if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
+
+ if (GVar->hasInternalLinkage())
+ O << "\t.local " << name << "\n";
+
+ O << TAI->getCOMMDirective() << name << ',' << Size;
+ if (TAI->getCOMMDirectiveTakesAlignment())
+ O << ',' << (1 << Align);
+
+ O << '\n';
+ return;
+ }
+ }
+
+ switch (GVar->getLinkage()) {
+ case GlobalValue::CommonLinkage:
+ case GlobalValue::LinkOnceLinkage:
+ case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak.
+ // Nonnull linkonce -> weak
+ O << "\t.weak " << name << "\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.
+ case GlobalValue::ExternalLinkage:
+ // If external or appending, declare as a global symbol
+ O << TAI->getGlobalDirective() << name << "\n";
+ // FALL THROUGH
+ case GlobalValue::InternalLinkage:
+ break;
+ case GlobalValue::GhostLinkage:
+ cerr << "Should not have any unmaterialized functions!\n";
+ abort();
+ case GlobalValue::DLLImportLinkage:
+ cerr << "DLLImport linkage is not supported by this target!\n";
+ abort();
+ case GlobalValue::DLLExportLinkage:
+ cerr << "DLLExport linkage is not supported by this target!\n";
+ abort();
+ default:
+ assert(0 && "Unknown linkage type!");
+ }
+
+ if (Align)
+ O << "\t.align " << Align << "\n";
+
+ if (TAI->hasDotTypeDotSizeDirective()) {
+ O << "\t.type " << name << ",#object\n";
+ O << "\t.size " << name << "," << Size << "\n";
+ }
+
+ O << name << ":\n";
+ EmitGlobalConstant(C);
+}
Modified: llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp?rev=54450&r1=54449&r2=54450&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.cpp Thu Aug 7 04:51:25 2008
@@ -15,11 +15,31 @@
using namespace llvm;
-SparcTargetAsmInfo::SparcTargetAsmInfo(const SparcTargetMachine &TM) {
+SparcELFTargetAsmInfo::SparcELFTargetAsmInfo(const TargetMachine &TM):
+ ELFTargetAsmInfo(TM) {
Data16bitsDirective = "\t.half\t";
Data32bitsDirective = "\t.word\t";
Data64bitsDirective = 0; // .xword is only supported by V9.
ZeroDirective = "\t.skip\t";
CommentString = "!";
ConstantPoolSection = "\t.section \".rodata\",#alloc\n";
+ COMMDirectiveTakesAlignment = true;
+}
+
+std::string SparcELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
+ std::string Flags = ",";
+
+ if (flags & SectionFlags::Mergeable)
+ return ELFTargetAsmInfo::PrintSectionFlags(flags);
+
+ if (!(flags & SectionFlags::Debug))
+ Flags += "#alloc";
+ if (flags & SectionFlags::Code)
+ Flags += "#execinstr";
+ if (flags & SectionFlags::Writeable)
+ Flags += "#write";
+ if (flags & SectionFlags::TLS)
+ Flags += "#tls";
+
+ return Flags;
}
Modified: llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h?rev=54450&r1=54449&r2=54450&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/Sparc/SparcTargetAsmInfo.h Thu Aug 7 04:51:25 2008
@@ -15,16 +15,18 @@
#define SPARCTARGETASMINFO_H
#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Target/ELFTargetAsmInfo.h"
namespace llvm {
// Forward declaration.
- class SparcTargetMachine;
+ class TargetMachine;
- struct SparcTargetAsmInfo : public TargetAsmInfo {
- explicit SparcTargetAsmInfo(const SparcTargetMachine &TM);
- };
+ struct SparcELFTargetAsmInfo : public ELFTargetAsmInfo {
+ explicit SparcELFTargetAsmInfo(const TargetMachine &TM);
+ std::string PrintSectionFlags(unsigned flags) const;
+ };
} // namespace llvm
Modified: llvm/trunk/lib/Target/Sparc/SparcTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Sparc/SparcTargetMachine.cpp?rev=54450&r1=54449&r2=54450&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Sparc/SparcTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/Sparc/SparcTargetMachine.cpp Thu Aug 7 04:51:25 2008
@@ -22,7 +22,8 @@
static RegisterTarget<SparcTargetMachine> X("sparc", " SPARC");
const TargetAsmInfo *SparcTargetMachine::createTargetAsmInfo() const {
- return new SparcTargetAsmInfo(*this);
+ // FIXME: Handle Solaris subtarget someday :)
+ return new SparcELFTargetAsmInfo(*this);
}
/// SparcTargetMachine ctor - Create an ILP32 architecture model
More information about the llvm-commits
mailing list