Patch contributed by Anton Korobeynikov!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28480
91177308-0d34-0410-b5e6-
96231b3b80d8
/// method to print assembly for each instruction.
///
bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
/// method to print assembly for each instruction.
///
bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
- // if (forDarwin) {
- // Let PassManager know we need debug information and relay
- // the MachineDebugInfo address on to DwarfWriter.
- DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
- // }
+ // Let PassManager know we need debug information and relay
+ // the MachineDebugInfo address on to DwarfWriter.
+ DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
SetupMachineFunction(MF);
O << "\n\n";
SetupMachineFunction(MF);
O << "\n\n";
break;
case Function::WeakLinkage:
case Function::LinkOnceLinkage:
break;
case Function::WeakLinkage:
case Function::LinkOnceLinkage:
+ if (Subtarget->TargetType == X86Subtarget::isDarwin) {
SwitchToTextSection(
".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n";
SwitchToTextSection(
".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n";
+ } else if (Subtarget->TargetType == X86Subtarget::isCygwin) {
+ EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
+ O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
+ << ",\"ax\"\n";
+ SwitchToTextSection("", F);
+ O << "\t.weak " << CurrentFnName << "\n";
} else {
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
} else {
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
}
O << CurrentFnName << ":\n";
}
O << CurrentFnName << ":\n";
+ if (Subtarget->TargetType == X86Subtarget::isDarwin) {
// Emit pre-function debug information.
DW.BeginFunction(&MF);
}
// Emit pre-function debug information.
DW.BeginFunction(&MF);
}
if (HasDotTypeDotSizeDirective)
O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
if (HasDotTypeDotSizeDirective)
O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
+ if (Subtarget->TargetType == X86Subtarget::isDarwin) {
// Emit post-function debug information.
DW.EndFunction();
}
// Emit post-function debug information.
DW.EndFunction();
}
if (!isMemOp) O << '$';
O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
<< MO.getConstantPoolIndex();
if (!isMemOp) O << '$';
O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
<< MO.getConstantPoolIndex();
- if (forDarwin && TM.getRelocationModel() == Reloc::PIC)
+ if (Subtarget->TargetType == X86Subtarget::isDarwin &&
+ TM.getRelocationModel() == Reloc::PIC)
O << "-\"L" << getFunctionNumber() << "$pb\"";
int Offset = MO.getOffset();
if (Offset > 0)
O << "-\"L" << getFunctionNumber() << "$pb\"";
int Offset = MO.getOffset();
if (Offset > 0)
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
if (!isMemOp && !isCallOp) O << '$';
// Darwin block shameless ripped from PPCAsmPrinter.cpp
bool isMemOp = Modifier && !strcmp(Modifier, "mem");
if (!isMemOp && !isCallOp) O << '$';
// Darwin block shameless ripped from PPCAsmPrinter.cpp
- if (forDarwin && TM.getRelocationModel() != Reloc::Static) {
+ if (Subtarget->TargetType == X86Subtarget::isDarwin &&
+ TM.getRelocationModel() != Reloc::Static) {
GlobalValue *GV = MO.getGlobal();
std::string Name = Mang->getValueName(GV);
// Link-once, External, or Weakly-linked global variables need
GlobalValue *GV = MO.getGlobal();
std::string Name = Mang->getValueName(GV);
// Link-once, External, or Weakly-linked global variables need
}
case MachineOperand::MO_ExternalSymbol: {
bool isCallOp = Modifier && !strcmp(Modifier, "call");
}
case MachineOperand::MO_ExternalSymbol: {
bool isCallOp = Modifier && !strcmp(Modifier, "call");
- if (isCallOp && forDarwin && TM.getRelocationModel() != Reloc::Static) {
+ if (isCallOp &&
+ Subtarget->TargetType == X86Subtarget::isDarwin &&
+ TM.getRelocationModel() != Reloc::Static) {
std::string Name(GlobalPrefix);
Name += MO.getSymbolName();
FnStubs.insert(Name);
std::string Name(GlobalPrefix);
Name += MO.getSymbolName();
FnStubs.insert(Name);
void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts;
// This works around some Darwin assembler bugs.
void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
++EmittedInsts;
// This works around some Darwin assembler bugs.
+ if (Subtarget->TargetType == X86Subtarget::isDarwin) {
switch (MI->getOpcode()) {
case X86::REP_MOVSB:
O << "rep/movsb (%esi),(%edi)\n";
switch (MI->getOpcode()) {
case X86::REP_MOVSB:
O << "rep/movsb (%esi),(%edi)\n";
/// doInitialization
bool X86SharedAsmPrinter::doInitialization(Module &M) {
/// doInitialization
bool X86SharedAsmPrinter::doInitialization(Module &M) {
- const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
-
- forDarwin = false;
PrivateGlobalPrefix = ".L";
DefaultTextSection = ".text";
DefaultDataSection = ".data";
PrivateGlobalPrefix = ".L";
DefaultTextSection = ".text";
DefaultDataSection = ".data";
LCOMMDirective = "\t.lcomm\t";
COMMDirectiveTakesAlignment = false;
HasDotTypeDotSizeDirective = false;
LCOMMDirective = "\t.lcomm\t";
COMMDirectiveTakesAlignment = false;
HasDotTypeDotSizeDirective = false;
StaticCtorsSection = ".mod_init_func";
StaticDtorsSection = ".mod_term_func";
InlineAsmStart = "# InlineAsm Start";
StaticCtorsSection = ".mod_init_func";
StaticDtorsSection = ".mod_term_func";
InlineAsmStart = "# InlineAsm Start";
GlobalPrefix = "_";
COMMDirectiveTakesAlignment = false;
HasDotTypeDotSizeDirective = false;
GlobalPrefix = "_";
COMMDirectiveTakesAlignment = false;
HasDotTypeDotSizeDirective = false;
+ StaticCtorsSection = "\t.section .ctors,\"aw\"";
+ StaticDtorsSection = "\t.section .dtors,\"aw\"";
break;
case X86Subtarget::isWindows:
GlobalPrefix = "_";
break;
case X86Subtarget::isWindows:
GlobalPrefix = "_";
+ if (Subtarget->TargetType == X86Subtarget::isDarwin) {
// Emit initial debug information.
DW.BeginModule(&M);
}
// Emit initial debug information.
DW.BeginModule(&M);
}
if (C->isNullValue() && /* FIXME: Verify correct */
(I->hasInternalLinkage() || I->hasWeakLinkage() ||
I->hasLinkOnceLinkage() ||
if (C->isNullValue() && /* FIXME: Verify correct */
(I->hasInternalLinkage() || I->hasWeakLinkage() ||
I->hasLinkOnceLinkage() ||
- (forDarwin && I->hasExternalLinkage() && !I->hasSection()))) {
+ (Subtarget->TargetType == X86Subtarget::isDarwin &&
+ I->hasExternalLinkage() && !I->hasSection()))) {
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (I->hasExternalLinkage()) {
O << "\t.globl\t" << name << "\n";
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
if (I->hasExternalLinkage()) {
O << "\t.globl\t" << name << "\n";
if (LCOMMDirective != NULL) {
if (I->hasInternalLinkage()) {
O << LCOMMDirective << name << "," << Size;
if (LCOMMDirective != NULL) {
if (I->hasInternalLinkage()) {
O << LCOMMDirective << name << "," << Size;
+ if (Subtarget->TargetType == X86Subtarget::isDarwin)
O << "," << (AlignmentIsInBytes ? (1 << Align) : Align);
} else
O << COMMDirective << name << "," << Size;
} else {
O << "," << (AlignmentIsInBytes ? (1 << Align) : Align);
} else
O << COMMDirective << name << "," << Size;
} else {
- if (I->hasInternalLinkage())
- O << "\t.local\t" << name << "\n";
+ 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 << COMMDirective << name << "," << Size;
if (COMMDirectiveTakesAlignment)
O << "," << (AlignmentIsInBytes ? (1 << Align) : Align);
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage:
case GlobalValue::WeakLinkage:
switch (I->getLinkage()) {
case GlobalValue::LinkOnceLinkage:
case GlobalValue::WeakLinkage:
+ if (Subtarget->TargetType == X86Subtarget::isDarwin) {
O << "\t.globl " << name << "\n"
<< "\t.weak_definition " << name << "\n";
SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I);
O << "\t.globl " << name << "\n"
<< "\t.weak_definition " << name << "\n";
SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I);
+ } else if (Subtarget->TargetType == X86Subtarget::isCygwin) {
+ O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n"
+ << "\t.weak " << name << "\n";
- O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n";
- O << "\t.weak " << name << "\n";
+ O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"
+ << "\t.weak " << name << "\n";
}
break;
case GlobalValue::AppendingLinkage:
}
break;
case GlobalValue::AppendingLinkage:
+ if (Subtarget->TargetType == X86Subtarget::isDarwin) {
SwitchToDataSection("", 0);
// Output stubs for dynamically-linked functions
SwitchToDataSection("", 0);
// Output stubs for dynamically-linked functions
X86DwarfWriter DW;
X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
X86DwarfWriter DW;
X86SharedAsmPrinter(std::ostream &O, X86TargetMachine &TM)
- : AsmPrinter(O, TM), DW(O, this), forDarwin(false) { }
+ : AsmPrinter(O, TM), DW(O, this) {
+ Subtarget = &TM.getSubtarget<X86Subtarget>();
+ }
bool doInitialization(Module &M);
bool doFinalization(Module &M);
bool doInitialization(Module &M);
bool doFinalization(Module &M);
MachineFunctionPass::getAnalysisUsage(AU);
}
MachineFunctionPass::getAnalysisUsage(AU);
}
- bool forDarwin; // FIXME: eliminate.
-
const char *DefaultTextSection; // "_text" for MASM, ".text" for others.
const char *DefaultDataSection; // "_data" for MASM, ".data" for others.
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
std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
// Necessary for Darwin to print out the apprioriate types of linker stubs
std::set<std::string> FnStubs, GVStubs, LinkOnceStubs;
- if (TargetType == isDarwin)
+ if (TargetType == isDarwin || TargetType == isCygwin)