summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/X86
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/X86')
-rwxr-xr-xllvm/lib/Target/X86/X86ATTAsmPrinter.cpp16
-rwxr-xr-xllvm/lib/Target/X86/X86ATTAsmPrinter.h4
-rw-r--r--llvm/lib/Target/X86/X86AsmPrinter.cpp90
-rwxr-xr-xllvm/lib/Target/X86/X86AsmPrinter.h34
-rwxr-xr-xllvm/lib/Target/X86/X86IntelAsmPrinter.cpp40
-rwxr-xr-xllvm/lib/Target/X86/X86IntelAsmPrinter.h4
6 files changed, 92 insertions, 96 deletions
diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
index 9a78fea8121..6c54d695499 100755
--- a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -43,11 +43,11 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.
- SwitchToTextSection(DefaultTextSection, F);
+ SwitchToTextSection(TAI->getTextSection(), F);
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
break;
case Function::ExternalLinkage:
- SwitchToTextSection(DefaultTextSection, F);
+ SwitchToTextSection(TAI->getTextSection(), F);
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
O << "\t.globl\t" << CurrentFnName << "\n";
break;
@@ -101,7 +101,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// lables that are used in jump table expressions (e.g. LBB1_1-LJT1_0).
EmitJumpTableInfo(MF.getJumpTableInfo());
- if (HasDotTypeDotSizeDirective)
+ if (TAI->hasDotTypeDotSizeDirective())
O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
if (Subtarget->isTargetDarwin()) {
@@ -144,7 +144,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
case MachineOperand::MO_JumpTableIndex: {
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
if (!isMemOp) O << '$';
- O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << "_"
+ O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_"
<< MO.getJumpTableIndex();
if (Subtarget->isTargetDarwin() &&
TM.getRelocationModel() == Reloc::PIC_)
@@ -154,7 +154,7 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
case MachineOperand::MO_ConstantPoolIndex: {
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
if (!isMemOp) O << '$';
- O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
+ O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
<< MO.getConstantPoolIndex();
if (Subtarget->isTargetDarwin() &&
TM.getRelocationModel() == Reloc::PIC_)
@@ -206,14 +206,14 @@ void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
if (isCallOp &&
Subtarget->isTargetDarwin() &&
TM.getRelocationModel() != Reloc::Static) {
- std::string Name(GlobalPrefix);
+ std::string Name(TAI->getGlobalPrefix());
Name += MO.getSymbolName();
FnStubs.insert(Name);
O << "L" << Name << "$stub";
return;
}
if (!isCallOp) O << '$';
- O << GlobalPrefix << MO.getSymbolName();
+ O << TAI->getGlobalPrefix() << MO.getSymbolName();
return;
}
default:
@@ -388,7 +388,7 @@ void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Reg1 = getX86SubSuperRegister(Reg1, MVT::i16);
else
Reg1 = getX86SubSuperRegister(Reg1, MVT::i8);
- O << CommentString << " TRUNCATE ";
+ O << TAI->getCommentString() << " TRUNCATE ";
if (Reg0 != Reg1)
O << "\n\t";
break;
diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.h b/llvm/lib/Target/X86/X86ATTAsmPrinter.h
index 6139c3ae866..e06015034c3 100755
--- a/llvm/lib/Target/X86/X86ATTAsmPrinter.h
+++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.h
@@ -20,8 +20,8 @@
namespace llvm {
struct X86ATTAsmPrinter : public X86SharedAsmPrinter {
- X86ATTAsmPrinter(std::ostream &O, X86TargetMachine &TM)
- : X86SharedAsmPrinter(O, TM) { }
+ X86ATTAsmPrinter(std::ostream &O, X86TargetMachine &TM, TargetAsmInfo *T)
+ : X86SharedAsmPrinter(O, TM, T) { }
virtual const char *getPassName() const {
return "X86 AT&T-Style Assembly Printer";
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 9e862e8c6fa..3fdd7b16672 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -26,10 +26,11 @@
#include "llvm/Support/CommandLine.h"
using namespace llvm;
+enum AsmWriterFlavorTy { att, intel };
+
Statistic<> llvm::EmittedInsts("asm-printer",
"Number of machine instrs printed");
-enum AsmWriterFlavorTy { att, intel };
cl::opt<AsmWriterFlavorTy>
AsmWriterFlavor("x86-asm-syntax",
cl::desc("Choose style of code to emit from X86 backend:"),
@@ -44,16 +45,11 @@ AsmWriterFlavor("x86-asm-syntax",
#endif
);
-// Out of line virtual function to home classes.
-void X86DwarfWriter::virtfn() {}
-
-
-/// doInitialization
-bool X86SharedAsmPrinter::doInitialization(Module &M) {
- PrivateGlobalPrefix = ".L";
- DefaultTextSection = ".text";
- DefaultDataSection = ".data";
+X86TargetAsmInfo::X86TargetAsmInfo(X86TargetMachine &TM) {
+ const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
+ //FIXME - Should to be simplified.
+
switch (Subtarget->TargetType) {
case X86Subtarget::isDarwin:
AlignmentIsInBytes = false;
@@ -73,6 +69,19 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
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 = "_";
@@ -88,6 +97,33 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) {
default: break;
}
+ if (AsmWriterFlavor == intel) {
+ 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()) {
// Emit initial debug information.
DW.BeginModule(&M);
@@ -127,25 +163,25 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
O << "\t.zerofill __DATA__, __common, " << name << ", "
<< Size << ", " << Align;
} else {
- SwitchToDataSection(DefaultDataSection, I);
- if (LCOMMDirective != NULL) {
+ SwitchToDataSection(TAI->getDataSection(), I);
+ if (TAI->getLCOMMDirective() != NULL) {
if (I->hasInternalLinkage()) {
- O << LCOMMDirective << name << "," << Size;
+ O << TAI->getLCOMMDirective() << name << "," << Size;
if (Subtarget->isTargetDarwin())
- O << "," << (AlignmentIsInBytes ? (1 << Align) : Align);
+ O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
} else
- O << COMMDirective << name << "," << Size;
+ O << TAI->getCOMMDirective() << name << "," << Size;
} else {
if (Subtarget->TargetType != X86Subtarget::isCygwin) {
if (I->hasInternalLinkage())
O << "\t.local\t" << name << "\n";
}
- O << COMMDirective << name << "," << Size;
- if (COMMDirectiveTakesAlignment)
- O << "," << (AlignmentIsInBytes ? (1 << Align) : Align);
+ O << TAI->getCOMMDirective() << name << "," << Size;
+ if (TAI->getCOMMDirectiveTakesAlignment())
+ O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
}
}
- O << "\t\t" << CommentString << " " << I->getName() << "\n";
+ O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
} else {
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage:
@@ -170,16 +206,16 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
O << "\t.globl " << name << "\n";
// FALL THROUGH
case GlobalValue::InternalLinkage:
- SwitchToDataSection(DefaultDataSection, I);
+ SwitchToDataSection(TAI->getDataSection(), I);
break;
default:
assert(0 && "Unknown linkage type!");
}
EmitAlignment(Align, I);
- O << name << ":\t\t\t\t" << CommentString << " " << I->getName()
+ O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
<< "\n";
- if (HasDotTypeDotSizeDirective)
+ if (TAI->hasDotTypeDotSizeDirective())
O << "\t.size " << name << ", " << Size << "\n";
EmitGlobalConstant(C);
@@ -234,13 +270,13 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
/// machine description.
///
FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
- X86TargetMachine &tm){
+ X86TargetMachine &tm) {
+ TargetAsmInfo *TAI = new X86TargetAsmInfo(tm);
+
switch (AsmWriterFlavor) {
default:
assert(0 && "Unknown asm flavor!");
- case intel:
- return new X86IntelAsmPrinter(o, tm);
- case att:
- return new X86ATTAsmPrinter(o, tm);
+ case intel: return new X86IntelAsmPrinter(o, tm, TAI);
+ case att: return new X86ATTAsmPrinter(o, tm, TAI);
}
}
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.h b/llvm/lib/Target/X86/X86AsmPrinter.h
index 4bc5b2b3d26..aa8129bd219 100755
--- a/llvm/lib/Target/X86/X86AsmPrinter.h
+++ b/llvm/lib/Target/X86/X86AsmPrinter.h
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/DwarfWriter.h"
#include "llvm/CodeGen/MachineDebugInfo.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Target/TargetAsmInfo.h"
#include <set>
@@ -29,33 +30,16 @@ namespace llvm {
extern Statistic<> EmittedInsts;
-/// X86DwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
-///
-struct X86DwarfWriter : public DwarfWriter {
- X86DwarfWriter(std::ostream &o, AsmPrinter *ap) : DwarfWriter(o, ap) {
- 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";
- TextSection = ".text";
- DataSection = ".data";
- }
- virtual void virtfn(); // out of line virtual fn.
+struct VISIBILITY_HIDDEN X86TargetAsmInfo : public TargetAsmInfo {
+ X86TargetAsmInfo(X86TargetMachine &TM);
};
-struct X86SharedAsmPrinter : public AsmPrinter {
- X86DwarfWriter DW;
+struct VISIBILITY_HIDDEN X86SharedAsmPrinter : public AsmPrinter {
+ DwarfWriter DW;
- X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
- : AsmPrinter(O, TM), DW(O, this) {
+ X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM,
+ TargetAsmInfo *T)
+ : AsmPrinter(O, TM, T), DW(O, this, T) {
Subtarget = &TM.getSubtarget<X86Subtarget>();
}
@@ -70,8 +54,6 @@ struct X86SharedAsmPrinter : public AsmPrinter {
MachineFunctionPass::getAnalysisUsage(AU);
}
- const char *DefaultTextSection; // "_text" for MASM, ".text" for others.
- const char *DefaultDataSection; // "_data" for MASM, ".data" for others.
const X86Subtarget *Subtarget;
// Necessary for Darwin to print out the apprioriate types of linker stubs
diff --git a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp
index c8bcc59b628..7be50e7fa8c 100755
--- a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp
@@ -22,10 +22,6 @@
#include "llvm/Target/TargetOptions.h"
using namespace llvm;
-X86IntelAsmPrinter::X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM)
- : X86SharedAsmPrinter(O, TM) {
-}
-
/// runOnMachineFunction - This uses the printMachineInstruction()
/// method to print assembly for each instruction.
///
@@ -106,8 +102,8 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
case MachineOperand::MO_ConstantPoolIndex: {
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
if (!isMemOp) O << "OFFSET ";
- O << "[" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
- << MO.getConstantPoolIndex();
+ O << "[" << TAI->getPrivateGlobalPrefix() << "CPI"
+ << getFunctionNumber() << "_" << MO.getConstantPoolIndex();
int Offset = MO.getOffset();
if (Offset > 0)
O << " + " << Offset;
@@ -131,7 +127,7 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
case MachineOperand::MO_ExternalSymbol: {
bool isCallOp = Modifier && !strcmp(Modifier, "call");
if (!isCallOp) O << "OFFSET ";
- O << GlobalPrefix << MO.getSymbolName();
+ O << TAI->getGlobalPrefix() << MO.getSymbolName();
return;
}
default:
@@ -272,7 +268,7 @@ void X86IntelAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Reg1 = getX86SubSuperRegister(Reg1, MVT::i16);
else
Reg1 = getX86SubSuperRegister(Reg1, MVT::i8);
- O << CommentString << " TRUNCATE ";
+ O << TAI->getCommentString() << " TRUNCATE ";
if (Reg0 != Reg1)
O << "\n\t";
break;
@@ -284,30 +280,9 @@ void X86IntelAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
}
bool X86IntelAsmPrinter::doInitialization(Module &M) {
- GlobalPrefix = "_";
- CommentString = ";";
-
X86SharedAsmPrinter::doInitialization(M);
-
- 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;
- Mang->markCharUnacceptable('.');
- DefaultTextSection = "_text";
- DefaultDataSection = "_data";
- SwitchToSectionDirective = "";
- TextSectionStartSuffix = "\tsegment 'CODE'";
- DataSectionStartSuffix = "\tsegment 'DATA'";
- SectionEndDirectiveSuffix = "\tends\n";
+ Mang->markCharUnacceptable('.');
O << "\t.686\n\t.model flat\n\n";
@@ -365,7 +340,7 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
O << "\tpublic " << name << "\n";
// FALL THROUGH
case GlobalValue::InternalLinkage:
- SwitchToDataSection(DefaultDataSection, I);
+ SwitchToDataSection(TAI->getDataSection(), I);
break;
default:
assert(0 && "Unknown linkage type!");
@@ -374,7 +349,8 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
if (!bCustomSegment)
EmitAlignment(Align, I);
- O << name << ":\t\t\t\t" << CommentString << " " << I->getName() << '\n';
+ O << name << ":\t\t\t\t" << TAI->getCommentString()
+ << " " << I->getName() << '\n';
EmitGlobalConstant(C);
diff --git a/llvm/lib/Target/X86/X86IntelAsmPrinter.h b/llvm/lib/Target/X86/X86IntelAsmPrinter.h
index c594e462551..8e0e8ba9858 100755
--- a/llvm/lib/Target/X86/X86IntelAsmPrinter.h
+++ b/llvm/lib/Target/X86/X86IntelAsmPrinter.h
@@ -21,7 +21,9 @@
namespace llvm {
struct X86IntelAsmPrinter : public X86SharedAsmPrinter {
- X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM);
+ X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM, TargetAsmInfo *T)
+ : X86SharedAsmPrinter(O, TM, T) {
+ }
virtual const char *getPassName() const {
return "X86 Intel-Style Assembly Printer";
OpenPOWER on IntegriCloud