diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index 042e1d3f021d..52a621d0d82f 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -49,7 +49,7 @@ namespace llvm { /// Target Asm Printer information. /// - TargetAsmInfo *TAI; + const TargetAsmInfo *TAI; /// Name-mangler for global names. /// @@ -65,7 +65,7 @@ namespace llvm { std::string CurrentSection; protected: - AsmPrinter(std::ostream &o, TargetMachine &TM, TargetAsmInfo *T); + AsmPrinter(std::ostream &o, TargetMachine &TM, const TargetAsmInfo *T); public: /// SwitchToTextSection - Switch to the specified section of the executable diff --git a/llvm/include/llvm/CodeGen/DwarfWriter.h b/llvm/include/llvm/CodeGen/DwarfWriter.h index 1b5cd8f6c462..bd95fe24d051 100644 --- a/llvm/include/llvm/CodeGen/DwarfWriter.h +++ b/llvm/include/llvm/CodeGen/DwarfWriter.h @@ -88,7 +88,7 @@ private: AsmPrinter *Asm; /// TAI - Target Asm Printer. - TargetAsmInfo *TAI; + const TargetAsmInfo *TAI; /// TD - Target data. const TargetData *TD; @@ -387,12 +387,12 @@ private: public: - DwarfWriter(std::ostream &OS, AsmPrinter *A, TargetAsmInfo *T); + DwarfWriter(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T); virtual ~DwarfWriter(); // Accessors. // - TargetAsmInfo *getTargetAsmInfo() const { return TAI; } + const TargetAsmInfo *getTargetAsmInfo() const { return TAI; } /// SetDebugInfo - Set DebugInfo when it's known that pass manager has /// created it. Set by the target AsmPrinter. diff --git a/llvm/include/llvm/Target/TargetAsmInfo.h b/llvm/include/llvm/Target/TargetAsmInfo.h index 56c25179c78f..6f63ba3a31ab 100644 --- a/llvm/include/llvm/Target/TargetAsmInfo.h +++ b/llvm/include/llvm/Target/TargetAsmInfo.h @@ -21,6 +21,9 @@ namespace llvm { + // Forward declaration. + class TargetMachine; + /// TargetAsmInfo - This class is intended to be used as a base class for asm /// properties and features specific to the target. class TargetAsmInfo { @@ -266,7 +269,7 @@ namespace llvm { unsigned getAddressSize() const { return AddressSize; } - bool getNeedsSet() const { + bool needsSet() const { return NeedsSet; } const char *getCommentString() const { diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h index 2a41d5ec3d0d..6b5efd41496c 100644 --- a/llvm/include/llvm/Target/TargetMachine.h +++ b/llvm/include/llvm/Target/TargetMachine.h @@ -20,6 +20,7 @@ namespace llvm { +class TargetAsmInfo; class TargetData; class TargetSubtarget; class TargetInstrInfo; @@ -65,11 +66,16 @@ class TargetMachine { TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT void operator=(const TargetMachine &); // DO NOT IMPLEMENT protected: // Can only create subclasses. - TargetMachine() { } + TargetMachine() : AsmInfo(NULL) { } /// getSubtargetImpl - virtual method implemented by subclasses that returns /// a reference to that target's TargetSubtarget-derived member variable. virtual const TargetSubtarget *getSubtargetImpl() const { return 0; } + + /// AsmInfo - Contains target specific asm information. + /// + mutable const TargetAsmInfo *AsmInfo; + public: virtual ~TargetMachine(); @@ -96,6 +102,18 @@ public: virtual const TargetFrameInfo *getFrameInfo() const { return 0; } virtual TargetLowering *getTargetLowering() const { return 0; } virtual const TargetData *getTargetData() const { return 0; } + + + /// getTargetAsmInfo - Return target specific asm information. + /// + const TargetAsmInfo *getTargetAsmInfo() const { + if (!AsmInfo) AsmInfo = createTargetAsmInfo(); + return AsmInfo; + } + + /// createTargetAsmInfo - Create a new instance of target specific asm + /// information. + virtual const TargetAsmInfo *createTargetAsmInfo() const { return NULL; } /// getSubtarget - This method returns a pointer to the specified type of /// TargetSubtarget. In debug builds, it verifies that the object being diff --git a/llvm/lib/CodeGen/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter.cpp index e6d56244c9c5..5af89c79c801 100644 --- a/llvm/lib/CodeGen/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter.cpp @@ -27,7 +27,8 @@ #include using namespace llvm; -AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm, TargetAsmInfo *T) +AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm, + const TargetAsmInfo *T) : FunctionNumber(0), O(o), TM(tm), TAI(T) {} diff --git a/llvm/lib/CodeGen/DwarfWriter.cpp b/llvm/lib/CodeGen/DwarfWriter.cpp index 9c4726ebc782..22d67449e174 100644 --- a/llvm/lib/CodeGen/DwarfWriter.cpp +++ b/llvm/lib/CodeGen/DwarfWriter.cpp @@ -574,24 +574,24 @@ void DIEAbbrev::Emit(const DwarfWriter &DW) const { } #ifndef NDEBUG - void DIEAbbrev::print(std::ostream &O) { - O << "Abbreviation @" - << std::hex << (intptr_t)this << std::dec +void DIEAbbrev::print(std::ostream &O) { + O << "Abbreviation @" + << std::hex << (intptr_t)this << std::dec + << " " + << TagString(Tag) + << " " + << ChildrenString(ChildrenFlag) + << "\n"; + + for (unsigned i = 0, N = Data.size(); i < N; ++i) { + O << " " + << AttributeString(Data[i].getAttribute()) << " " - << TagString(Tag) - << " " - << ChildrenString(ChildrenFlag) + << FormEncodingString(Data[i].getForm()) << "\n"; - - for (unsigned i = 0, N = Data.size(); i < N; ++i) { - O << " " - << AttributeString(Data[i].getAttribute()) - << " " - << FormEncodingString(Data[i].getForm()) - << "\n"; - } } - void DIEAbbrev::dump() { print(std::cerr); } +} +void DIEAbbrev::dump() { print(std::cerr); } #endif //===----------------------------------------------------------------------===// @@ -1160,7 +1160,7 @@ void DwarfWriter::EmitReference(const std::string &Name) const { /// is an option (needsSet) to use an intermediary 'set' expression. void DwarfWriter::EmitDifference(const char *TagHi, unsigned NumberHi, const char *TagLo, unsigned NumberLo) const { - if (TAI->getNeedsSet()) { + if (TAI->needsSet()) { static unsigned SetCounter = 0; O << "\t.set\t"; @@ -2467,7 +2467,8 @@ void DwarfWriter::ConstructSubprogramDIEs() { // Main entry points. // -DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A, TargetAsmInfo *T) +DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A, + const TargetAsmInfo *T) : O(OS) , Asm(A) , TAI(T) diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp index 98c37904cfd7..2a0c4042ba3e 100644 --- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -38,20 +38,8 @@ using namespace llvm; namespace { Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); - struct VISIBILITY_HIDDEN ARMTargetAsmInfo : public TargetAsmInfo { - ARMTargetAsmInfo() { - Data16bitsDirective = "\t.half\t"; - Data32bitsDirective = "\t.word\t"; - Data64bitsDirective = 0; - ZeroDirective = "\t.skip\t"; - CommentString = "@"; - ConstantPoolSection = "\t.text\n"; - AlignmentIsInBytes = false; - } - }; - struct VISIBILITY_HIDDEN ARMAsmPrinter : public AsmPrinter { - ARMAsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T) + ARMAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) : AsmPrinter(O, TM, T) { } @@ -113,8 +101,7 @@ namespace { /// FunctionPass *llvm::createARMCodePrinterPass(std::ostream &o, TargetMachine &tm) { - ARMTargetAsmInfo *TAI = new ARMTargetAsmInfo(); - return new ARMAsmPrinter(o, tm, TAI); + return new ARMAsmPrinter(o, tm, tm.getTargetAsmInfo()); } /// runOnMachineFunction - This uses the printMachineInstruction() diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.h b/llvm/lib/Target/ARM/ARMTargetMachine.h index f09b92b8f39f..bf8deba9c3bd 100644 --- a/llvm/lib/Target/ARM/ARMTargetMachine.h +++ b/llvm/lib/Target/ARM/ARMTargetMachine.h @@ -20,6 +20,7 @@ #include "llvm/Target/TargetFrameInfo.h" #include "ARMInstrInfo.h" #include "ARMFrameInfo.h" +#include "ARMTargetAsmInfo.h" namespace llvm { @@ -40,6 +41,10 @@ public: virtual const TargetData *getTargetData() const { return &DataLayout; } static unsigned getModuleMatchQuality(const Module &M); + virtual const TargetAsmInfo *createTargetAsmInfo() const { + return static_cast(new ARMTargetAsmInfo(*this)); + } + // Pass Pipeline Configuration virtual bool addInstSelector(FunctionPassManager &PM, bool Fast); virtual bool addAssemblyEmitter(FunctionPassManager &PM, bool Fast, diff --git a/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp b/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp index d709ed7342cc..2ce4865404bd 100644 --- a/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp +++ b/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp @@ -29,20 +29,13 @@ using namespace llvm; namespace { Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); - struct VISIBILITY_HIDDEN AlphaTargetAsmInfo : public TargetAsmInfo { - AlphaTargetAsmInfo() { - AlignmentIsInBytes = false; - PrivateGlobalPrefix = "$"; - } - }; - struct VISIBILITY_HIDDEN AlphaAsmPrinter : public AsmPrinter { /// Unique incrementer for label values for referencing Global values. /// unsigned LabelNumber; - AlphaAsmPrinter(std::ostream &o, TargetMachine &tm, TargetAsmInfo *T) + AlphaAsmPrinter(std::ostream &o, TargetMachine &tm, const TargetAsmInfo *T) : AsmPrinter(o, tm, T), LabelNumber(0) { } @@ -82,8 +75,7 @@ namespace { /// FunctionPass *llvm::createAlphaCodePrinterPass (std::ostream &o, TargetMachine &tm) { - AlphaTargetAsmInfo *TAI = new AlphaTargetAsmInfo(); - return new AlphaAsmPrinter(o, tm, TAI); + return new AlphaAsmPrinter(o, tm, tm.getTargetAsmInfo()); } #include "AlphaGenAsmWriter.inc" diff --git a/llvm/lib/Target/Alpha/AlphaTargetMachine.cpp b/llvm/lib/Target/Alpha/AlphaTargetMachine.cpp index 9c9f52dcf137..cbe0cdbf4d73 100644 --- a/llvm/lib/Target/Alpha/AlphaTargetMachine.cpp +++ b/llvm/lib/Target/Alpha/AlphaTargetMachine.cpp @@ -53,7 +53,8 @@ AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS) : DataLayout("e"), FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), JITInfo(*this), - Subtarget(M, FS) { + Subtarget(M, FS), + AsmInfo(NULL) { } diff --git a/llvm/lib/Target/Alpha/AlphaTargetMachine.h b/llvm/lib/Target/Alpha/AlphaTargetMachine.h index d71c7cec72db..d47ca8215c9f 100644 --- a/llvm/lib/Target/Alpha/AlphaTargetMachine.h +++ b/llvm/lib/Target/Alpha/AlphaTargetMachine.h @@ -20,6 +20,7 @@ #include "AlphaInstrInfo.h" #include "AlphaJITInfo.h" #include "AlphaSubtarget.h" +#include "AlphaTargetAsmInfo.h" namespace llvm { @@ -31,9 +32,13 @@ class AlphaTargetMachine : public LLVMTargetMachine { TargetFrameInfo FrameInfo; AlphaJITInfo JITInfo; AlphaSubtarget Subtarget; + AlphaTargetAsmInfo *AsmInfo; public: AlphaTargetMachine(const Module &M, const std::string &FS); + ~AlphaTargetMachine() { + if (AsmInfo) delete AsmInfo; + } virtual const AlphaInstrInfo *getInstrInfo() const { return &InstrInfo; } virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; } @@ -46,6 +51,10 @@ public: return &JITInfo; } + virtual const TargetAsmInfo *createTargetAsmInfo() const { + return static_cast(new AlphaTargetAsmInfo(*this)); + } + static unsigned getJITMatchQuality(); static unsigned getModuleMatchQuality(const Module &M); diff --git a/llvm/lib/Target/IA64/IA64AsmPrinter.cpp b/llvm/lib/Target/IA64/IA64AsmPrinter.cpp index 1de12153e273..4a16777f9bbb 100644 --- a/llvm/lib/Target/IA64/IA64AsmPrinter.cpp +++ b/llvm/lib/Target/IA64/IA64AsmPrinter.cpp @@ -23,8 +23,8 @@ #include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/CodeGen/MachineFunctionPass.h" -#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetAsmInfo.h" +#include "llvm/Target/TargetMachine.h" #include "llvm/Support/Mangler.h" #include "llvm/ADT/Statistic.h" #include @@ -32,31 +32,11 @@ using namespace llvm; namespace { Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); - - struct VISIBILITY_HIDDEN IA64TargetAsmInfo : public TargetAsmInfo { - IA64TargetAsmInfo() { - CommentString = "//"; - Data8bitsDirective = "\tdata1\t"; // FIXME: check that we are - Data16bitsDirective = "\tdata2.ua\t"; // disabling auto-alignment - Data32bitsDirective = "\tdata4.ua\t"; // properly - Data64bitsDirective = "\tdata8.ua\t"; - ZeroDirective = "\t.skip\t"; - AsciiDirective = "\tstring\t"; - - GlobalVarAddrPrefix=""; - GlobalVarAddrSuffix=""; - FunctionAddrPrefix="@fptr("; - FunctionAddrSuffix=")"; - - // FIXME: would be nice to have rodata (no 'w') when appropriate? - ConstantPoolSection = "\n\t.section .data, \"aw\", \"progbits\"\n"; - } - }; struct IA64AsmPrinter : public AsmPrinter { std::set ExternalFunctionNames, ExternalObjectNames; - IA64AsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T) + IA64AsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) : AsmPrinter(O, TM, T) { } @@ -366,8 +346,7 @@ bool IA64AsmPrinter::doFinalization(Module &M) { /// FunctionPass *llvm::createIA64CodePrinterPass(std::ostream &o, IA64TargetMachine &tm) { - IA64TargetAsmInfo *TAI = new IA64TargetAsmInfo(); - return new IA64AsmPrinter(o, tm, TAI); + return new IA64AsmPrinter(o, tm, tm.getTargetAsmInfo()); } diff --git a/llvm/lib/Target/IA64/IA64TargetMachine.h b/llvm/lib/Target/IA64/IA64TargetMachine.h index 5a4b6b699575..61ac05f6a2bf 100644 --- a/llvm/lib/Target/IA64/IA64TargetMachine.h +++ b/llvm/lib/Target/IA64/IA64TargetMachine.h @@ -19,6 +19,7 @@ #include "llvm/Target/TargetFrameInfo.h" #include "IA64InstrInfo.h" #include "IA64ISelLowering.h" +#include "IA64TargetAsmInfo.h" namespace llvm { @@ -40,6 +41,10 @@ public: return &InstrInfo.getRegisterInfo(); } virtual const TargetData *getTargetData() const { return &DataLayout; } + + virtual const TargetAsmInfo *createTargetAsmInfo() const { + return static_cast(new IA64TargetAsmInfo(*this)); + } static unsigned getModuleMatchQuality(const Module &M); diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp index 9ec7106c32ac..b50fc4595999 100644 --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -50,7 +50,7 @@ namespace { struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter { std::set FnStubs, GVStubs; - PPCAsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T) + PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) : AsmPrinter(O, TM, T) {} virtual const char *getPassName() const { @@ -239,49 +239,14 @@ namespace { }; - struct VISIBILITY_HIDDEN DarwinTargetAsmInfo : public TargetAsmInfo { - DarwinTargetAsmInfo(PPCTargetMachine &TM) { - bool isPPC64 = TM.getSubtargetImpl()->isPPC64(); - - CommentString = ";"; - GlobalPrefix = "_"; - PrivateGlobalPrefix = "L"; - ZeroDirective = "\t.space\t"; - SetDirective = "\t.set"; - Data64bitsDirective = isPPC64 ? ".quad\t" : 0; - AlignmentIsInBytes = false; - ConstantPoolSection = "\t.const\t"; - JumpTableDataSection = ".const"; - JumpTableTextSection = "\t.text"; - LCOMMDirective = "\t.lcomm\t"; - StaticCtorsSection = ".mod_init_func"; - StaticDtorsSection = ".mod_term_func"; - InlineAsmStart = "# InlineAsm Start"; - InlineAsmEnd = "# InlineAsm End"; - - NeedsSet = true; - AddressSize = isPPC64 ? 8 : 4; - DwarfAbbrevSection = ".section __DWARF,__debug_abbrev"; - DwarfInfoSection = ".section __DWARF,__debug_info"; - DwarfLineSection = ".section __DWARF,__debug_line"; - DwarfFrameSection = ".section __DWARF,__debug_frame"; - DwarfPubNamesSection = ".section __DWARF,__debug_pubnames"; - DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes"; - DwarfStrSection = ".section __DWARF,__debug_str"; - DwarfLocSection = ".section __DWARF,__debug_loc"; - DwarfARangesSection = ".section __DWARF,__debug_aranges"; - DwarfRangesSection = ".section __DWARF,__debug_ranges"; - DwarfMacInfoSection = ".section __DWARF,__debug_macinfo"; - } - }; - /// DarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac OS /// X struct VISIBILITY_HIDDEN DarwinAsmPrinter : public PPCAsmPrinter { DwarfWriter DW; - DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM, TargetAsmInfo *T) + DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM, + const TargetAsmInfo *T) : PPCAsmPrinter(O, TM, T), DW(O, this, T) { bool isPPC64 = TM.getSubtargetImpl()->isPPC64(); } @@ -309,8 +274,7 @@ namespace { /// FunctionPass *llvm::createDarwinCodePrinterPass(std::ostream &o, PPCTargetMachine &tm) { - TargetAsmInfo *TAI = new DarwinTargetAsmInfo(tm); - return new DarwinAsmPrinter(o, tm, TAI); + return new DarwinAsmPrinter(o, tm, tm.getTargetAsmInfo()); } // Include the auto-generated portion of the assembly writer diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.h b/llvm/lib/Target/PowerPC/PPCTargetMachine.h index 9a77a4fcb89a..d11f0158a02d 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetMachine.h +++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.h @@ -19,6 +19,7 @@ #include "PPCJITInfo.h" #include "PPCInstrInfo.h" #include "PPCISelLowering.h" +#include "PPCTargetAsmInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetData.h" @@ -55,6 +56,9 @@ public: return InstrItins; } + virtual const TargetAsmInfo *createTargetAsmInfo() const { + return static_cast(new DarwinTargetAsmInfo(*this)); + } // Pass Pipeline Configuration virtual bool addInstSelector(FunctionPassManager &PM, bool Fast); diff --git a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp index 2bc6f6332e6a..1e6efcbeaf28 100644 --- a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp +++ b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp @@ -37,19 +37,8 @@ using namespace llvm; namespace { Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); - struct VISIBILITY_HIDDEN SparcTargetAsmInfo : public TargetAsmInfo { - SparcTargetAsmInfo() { - 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"; - } - }; - struct VISIBILITY_HIDDEN SparcAsmPrinter : public AsmPrinter { - SparcAsmPrinter(std::ostream &O, TargetMachine &TM, TargetAsmInfo *T) + SparcAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T) : AsmPrinter(O, TM, T) { } @@ -85,8 +74,7 @@ namespace { /// FunctionPass *llvm::createSparcCodePrinterPass(std::ostream &o, TargetMachine &tm) { - SparcTargetAsmInfo *TAI = new SparcTargetAsmInfo(); - return new SparcAsmPrinter(o, tm, TAI); + return new SparcAsmPrinter(o, tm, tm.getTargetAsmInfo()); } /// runOnMachineFunction - This uses the printMachineInstruction() diff --git a/llvm/lib/Target/Sparc/SparcTargetMachine.h b/llvm/lib/Target/Sparc/SparcTargetMachine.h index e377afa08531..995d346f9244 100644 --- a/llvm/lib/Target/Sparc/SparcTargetMachine.h +++ b/llvm/lib/Target/Sparc/SparcTargetMachine.h @@ -19,6 +19,7 @@ #include "llvm/Target/TargetFrameInfo.h" #include "SparcInstrInfo.h" #include "SparcSubtarget.h" +#include "SparcTargetAsmInfo.h" namespace llvm { @@ -41,6 +42,9 @@ public: virtual const TargetData *getTargetData() const { return &DataLayout; } static unsigned getModuleMatchQuality(const Module &M); + virtual const TargetAsmInfo *createTargetAsmInfo() const { + return static_cast(new SparcTargetAsmInfo(*this)); + } // Pass Pipeline Configuration virtual bool addInstSelector(FunctionPassManager &PM, bool Fast); diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index 3a9c8b30c438..3ca64c44edba 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Support/CommandLine.h" @@ -95,6 +96,7 @@ namespace { // TargetMachine::~TargetMachine() { + if (AsmInfo) delete AsmInfo; } /// getRelocationModel - Returns the code generation relocation model. The diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp index 6c54d6954995..e3653e4920e2 100755 --- a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp @@ -16,8 +16,10 @@ #include "X86ATTAsmPrinter.h" #include "X86.h" #include "X86TargetMachine.h" +#include "X86TargetAsmInfo.h" #include "llvm/Module.h" #include "llvm/Support/Mangler.h" +#include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetOptions.h" #include using namespace llvm; diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.h b/llvm/lib/Target/X86/X86ATTAsmPrinter.h index e06015034c35..ff707caee68d 100755 --- a/llvm/lib/Target/X86/X86ATTAsmPrinter.h +++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.h @@ -20,7 +20,7 @@ namespace llvm { struct X86ATTAsmPrinter : public X86SharedAsmPrinter { - X86ATTAsmPrinter(std::ostream &O, X86TargetMachine &TM, TargetAsmInfo *T) + X86ATTAsmPrinter(std::ostream &O, X86TargetMachine &TM, const TargetAsmInfo *T) : X86SharedAsmPrinter(O, TM, T) { } virtual const char *getPassName() const { diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp index 2e32f34506b6..4a54e5914dab 100644 --- a/llvm/lib/Target/X86/X86AsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp @@ -23,88 +23,12 @@ #include "llvm/Type.h" #include "llvm/Assembly/Writer.h" #include "llvm/Support/Mangler.h" +#include "llvm/Target/TargetAsmInfo.h" using namespace llvm; Statistic<> llvm::EmittedInsts("asm-printer", "Number of machine instrs printed"); -X86TargetAsmInfo::X86TargetAsmInfo(X86TargetMachine &TM) { - const X86Subtarget *Subtarget = &TM.getSubtarget(); - - //FIXME - Should to be simplified. - - switch (Subtarget->TargetType) { - case X86Subtarget::isDarwin: - AlignmentIsInBytes = false; - GlobalPrefix = "_"; - Data64bitsDirective = 0; // we can't emit a 64-bit unit - ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. - PrivateGlobalPrefix = "L"; // Marker for constant pool idxs - ConstantPoolSection = "\t.const\n"; - JumpTableDataSection = "\t.const\n"; // FIXME: depends on PIC mode - FourByteConstantSection = "\t.literal4\n"; - EightByteConstantSection = "\t.literal8\n"; - LCOMMDirective = "\t.lcomm\t"; - COMMDirectiveTakesAlignment = false; - HasDotTypeDotSizeDirective = false; - StaticCtorsSection = ".mod_init_func"; - StaticDtorsSection = ".mod_term_func"; - InlineAsmStart = "# InlineAsm Start"; - InlineAsmEnd = "# InlineAsm End"; - SetDirective = "\t.set"; - - NeedsSet = true; - DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; - DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; - DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; - DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; - DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; - DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; - DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; - DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; - DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; - DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; - DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; - break; - case X86Subtarget::isCygwin: - GlobalPrefix = "_"; - COMMDirectiveTakesAlignment = false; - HasDotTypeDotSizeDirective = false; - StaticCtorsSection = "\t.section .ctors,\"aw\""; - StaticDtorsSection = "\t.section .dtors,\"aw\""; - break; - case X86Subtarget::isWindows: - GlobalPrefix = "_"; - HasDotTypeDotSizeDirective = false; - break; - default: break; - } - - if (Subtarget->isFlavorIntel()) { - GlobalPrefix = "_"; - CommentString = ";"; - - PrivateGlobalPrefix = "$"; - AlignDirective = "\talign\t"; - ZeroDirective = "\tdb\t"; - ZeroDirectiveSuffix = " dup(0)"; - AsciiDirective = "\tdb\t"; - AscizDirective = 0; - Data8bitsDirective = "\tdb\t"; - Data16bitsDirective = "\tdw\t"; - Data32bitsDirective = "\tdd\t"; - Data64bitsDirective = "\tdq\t"; - HasDotTypeDotSizeDirective = false; - - TextSection = "_text"; - DataSection = "_data"; - SwitchToSectionDirective = ""; - TextSectionStartSuffix = "\tsegment 'CODE'"; - DataSectionStartSuffix = "\tsegment 'DATA'"; - SectionEndDirectiveSuffix = "\tends\n"; - } -} - /// doInitialization bool X86SharedAsmPrinter::doInitialization(Module &M) { if (Subtarget->isTargetDarwin()) { @@ -255,11 +179,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o, X86TargetMachine &tm) { const X86Subtarget *Subtarget = &tm.getSubtarget(); - TargetAsmInfo *TAI = new X86TargetAsmInfo(tm); if (Subtarget->isFlavorIntel()) { - return new X86IntelAsmPrinter(o, tm, TAI); + return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo()); } else { - return new X86ATTAsmPrinter(o, tm, TAI); + return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo()); } } diff --git a/llvm/lib/Target/X86/X86AsmPrinter.h b/llvm/lib/Target/X86/X86AsmPrinter.h index aa8129bd219b..8d32f59d8b17 100755 --- a/llvm/lib/Target/X86/X86AsmPrinter.h +++ b/llvm/lib/Target/X86/X86AsmPrinter.h @@ -22,7 +22,6 @@ #include "llvm/CodeGen/DwarfWriter.h" #include "llvm/CodeGen/MachineDebugInfo.h" #include "llvm/ADT/Statistic.h" -#include "llvm/Target/TargetAsmInfo.h" #include @@ -30,15 +29,11 @@ namespace llvm { extern Statistic<> EmittedInsts; -struct VISIBILITY_HIDDEN X86TargetAsmInfo : public TargetAsmInfo { - X86TargetAsmInfo(X86TargetMachine &TM); -}; - struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter { DwarfWriter DW; X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM, - TargetAsmInfo *T) + const TargetAsmInfo *T) : AsmPrinter(O, TM, T), DW(O, this, T) { Subtarget = &TM.getSubtarget(); } diff --git a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp index 7be50e7fa8ca..ddf807f7687c 100755 --- a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp @@ -14,11 +14,13 @@ //===----------------------------------------------------------------------===// #include "X86IntelAsmPrinter.h" +#include "X86TargetAsmInfo.h" #include "X86.h" #include "llvm/Constants.h" #include "llvm/Module.h" #include "llvm/Assembly/Writer.h" #include "llvm/Support/Mangler.h" +#include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetOptions.h" using namespace llvm; diff --git a/llvm/lib/Target/X86/X86IntelAsmPrinter.h b/llvm/lib/Target/X86/X86IntelAsmPrinter.h index 8e0e8ba98583..ef0af2a6b58d 100755 --- a/llvm/lib/Target/X86/X86IntelAsmPrinter.h +++ b/llvm/lib/Target/X86/X86IntelAsmPrinter.h @@ -21,7 +21,8 @@ namespace llvm { struct X86IntelAsmPrinter : public X86SharedAsmPrinter { - X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM, TargetAsmInfo *T) + X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM, + const TargetAsmInfo *T) : X86SharedAsmPrinter(O, TM, T) { } diff --git a/llvm/lib/Target/X86/X86TargetMachine.h b/llvm/lib/Target/X86/X86TargetMachine.h index 9b50c7e408db..0bbef0582ff4 100644 --- a/llvm/lib/Target/X86/X86TargetMachine.h +++ b/llvm/lib/Target/X86/X86TargetMachine.h @@ -21,6 +21,7 @@ #include "X86InstrInfo.h" #include "X86JITInfo.h" #include "X86Subtarget.h" +#include "X86TargetAsmInfo.h" #include "X86ISelLowering.h" namespace llvm { @@ -50,6 +51,9 @@ public: static unsigned getModuleMatchQuality(const Module &M); static unsigned getJITMatchQuality(); + virtual const TargetAsmInfo *createTargetAsmInfo() const { + return static_cast(new X86TargetAsmInfo(*this)); + } // Set up the pass pipeline. virtual bool addInstSelector(FunctionPassManager &PM, bool Fast);