X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FX86%2FAsmPrinter%2FX86IntelAsmPrinter.cpp;h=1a40ed46478789c42c08fb401fab161c9b01fd64;hb=481d15a12289ec4d058b863da93794fd8be1e702;hp=12a083aa74e56217ab4aa0ca2594b1e833fb343a;hpb=f3ba70861ccf00b1072ae1b6ade3ebe2da6cff40;p=oota-llvm.git diff --git a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp index 12a083aa74e..1a40ed46478 100644 --- a/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp +++ b/lib/Target/X86/AsmPrinter/X86IntelAsmPrinter.cpp @@ -25,6 +25,8 @@ #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Assembly/Writer.h" +#include "llvm/CodeGen/DwarfWriter.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Mangler.h" #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetOptions.h" @@ -54,11 +56,11 @@ static X86MachineFunctionInfo calculateFunctionInfo(const Function *F, const Type* Ty = AI->getType(); // 'Dereference' type in case of byval parameter attribute - if (F->paramHasAttr(argNum, ParamAttr::ByVal)) + if (F->paramHasAttr(argNum, Attribute::ByVal)) Ty = cast(Ty)->getElementType(); // Size should be aligned to DWORD boundary - Size += ((TD->getABITypeSize(Ty) + 3)/4)*4; + Size += ((TD->getTypeAllocSize(Ty) + 3)/4)*4; } // We're not supporting tooooo huge arguments :) @@ -113,20 +115,15 @@ void X86IntelAsmPrinter::decorateName(std::string &Name, break; default: - assert(0 && "Unsupported DecorationStyle"); + LLVM_UNREACHABLE("Unsupported DecorationStyle"); } } - -std::string X86IntelAsmPrinter::getSectionForFunction(const Function &F) const { - // Intel asm always emits functions to _text. - return "_text"; -} - /// runOnMachineFunction - This uses the printMachineInstruction() /// method to print assembly for each instruction. /// bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { + this->MF = &MF; SetupMachineFunction(MF); O << "\n\n"; @@ -136,6 +133,7 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { // Print out labels for the function. const Function *F = MF.getFunction(); unsigned CC = F->getCallingConv(); + unsigned FnAlign = MF.getAlignment(); // Populate function information map. Actually, We don't want to populate // non-stdcall or non-fastcall functions' information right now. @@ -144,13 +142,10 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { decorateName(CurrentFnName, F); - SwitchToTextSection(getSectionForFunction(*F).c_str(), F); - - unsigned FnAlign = OptimizeForSize ? 1 : 4; - if (F->hasNote(FN_NOTE_OptimizeForSize)) - FnAlign = 1; + SwitchToTextSection("_text", F); switch (F->getLinkage()) { - default: assert(0 && "Unsupported linkage type!"); + default: LLVM_UNREACHABLE("Unsupported linkage type!"); + case Function::PrivateLinkage: case Function::InternalLinkage: EmitAlignment(FnAlign); break; @@ -185,6 +180,8 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) { O << CurrentFnName << "\tendp\n"; + O.flush(); + // We didn't modify anything. return false; } @@ -224,9 +221,6 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO, case MachineOperand::MO_Immediate: O << MO.getImm(); return; - case MachineOperand::MO_MachineBasicBlock: - printBasicBlockLabel(MO.getMBB()); - return; case MachineOperand::MO_JumpTableIndex: { bool isMemOp = Modifier && !strcmp(Modifier, "mem"); if (!isMemOp) O << "OFFSET "; @@ -239,39 +233,29 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO, if (!isMemOp) O << "OFFSET "; O << "[" << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_" << MO.getIndex(); - int Offset = MO.getOffset(); - if (Offset > 0) - O << " + " << Offset; - else if (Offset < 0) - O << Offset; + printOffset(MO.getOffset()); O << "]"; return; } case MachineOperand::MO_GlobalAddress: { - bool isCallOp = Modifier && !strcmp(Modifier, "call"); bool isMemOp = Modifier && !strcmp(Modifier, "mem"); GlobalValue *GV = MO.getGlobal(); - std::string Name = Mang->getValueName(GV); - + std::string Name = Mang->getMangledName(GV); decorateName(Name, GV); - if (!isMemOp && !isCallOp) O << "OFFSET "; - if (GV->hasDLLImportLinkage()) { - // FIXME: This should be fixed with full support of stdcall & fastcall - // CC's + if (!isMemOp) O << "OFFSET "; + + // Handle dllimport linkage. + // FIXME: This should be fixed with full support of stdcall & fastcall + // CC's + if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) O << "__imp_"; - } + O << Name; - int Offset = MO.getOffset(); - if (Offset > 0) - O << " + " << Offset; - else if (Offset < 0) - O << Offset; + printOffset(MO.getOffset()); return; } case MachineOperand::MO_ExternalSymbol: { - bool isCallOp = Modifier && !strcmp(Modifier, "call"); - if (!isCallOp) O << "OFFSET "; O << TAI->getGlobalPrefix() << MO.getSymbolName(); return; } @@ -280,10 +264,42 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO, } } -void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op, - const char *Modifier) { - assert(isMem(MI, Op) && "Invalid memory reference!"); +void X86IntelAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo){ + const MachineOperand &MO = MI->getOperand(OpNo); + switch (MO.getType()) { + default: LLVM_UNREACHABLE("Unknown pcrel immediate operand"); + case MachineOperand::MO_Immediate: + O << MO.getImm(); + return; + case MachineOperand::MO_MachineBasicBlock: + printBasicBlockLabel(MO.getMBB()); + return; + + case MachineOperand::MO_GlobalAddress: { + GlobalValue *GV = MO.getGlobal(); + std::string Name = Mang->getMangledName(GV); + decorateName(Name, GV); + + // Handle dllimport linkage. + // FIXME: This should be fixed with full support of stdcall & fastcall + // CC's + if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) + O << "__imp_"; + O << Name; + printOffset(MO.getOffset()); + return; + } + + case MachineOperand::MO_ExternalSymbol: + O << TAI->getGlobalPrefix() << MO.getSymbolName(); + return; + } +} + +void X86IntelAsmPrinter::printLeaMemReference(const MachineInstr *MI, + unsigned Op, + const char *Modifier) { const MachineOperand &BaseReg = MI->getOperand(Op); int ScaleVal = MI->getOperand(Op+1).getImm(); const MachineOperand &IndexReg = MI->getOperand(Op+2); @@ -304,8 +320,8 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op, NeedPlus = true; } - if (DispSpec.isGlobalAddress() || DispSpec.isConstantPoolIndex() || - DispSpec.isJumpTableIndex()) { + if (DispSpec.isGlobal() || DispSpec.isCPI() || + DispSpec.isJTI()) { if (NeedPlus) O << " + "; printOp(DispSpec, "mem"); @@ -326,6 +342,17 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op, O << "]"; } +void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op, + const char *Modifier) { + assert(isMem(MI, Op) && "Invalid memory reference!"); + MachineOperand Segment = MI->getOperand(Op+4); + if (Segment.getReg()) { + printOperand(MI, Op+4, Modifier); + O << ':'; + } + printLeaMemReference(MI, Op, Modifier); +} + void X86IntelAsmPrinter::printPICJumpTableSetLabel(unsigned uid, const MachineBasicBlock *MBB) const { if (!TAI->getSetDirective()) @@ -338,8 +365,8 @@ void X86IntelAsmPrinter::printPICJumpTableSetLabel(unsigned uid, } void X86IntelAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) { - O << "\"L" << getFunctionNumber() << "$pb\"\n"; - O << "\"L" << getFunctionNumber() << "$pb\":"; + O << "L" << getFunctionNumber() << "$pb\n"; + O << "L" << getFunctionNumber() << "$pb:"; } bool X86IntelAsmPrinter::printAsmMRegister(const MachineOperand &MO, @@ -361,7 +388,7 @@ bool X86IntelAsmPrinter::printAsmMRegister(const MachineOperand &MO, break; } - O << '%' << TRI->getName(Reg); + O << TRI->getName(Reg); return false; } @@ -413,15 +440,15 @@ bool X86IntelAsmPrinter::doInitialization(Module &M) { Mang->markCharUnacceptable('.'); - O << "\t.686\n\t.model flat\n\n"; + O << "\t.686\n\t.MMX\n\t.XMM\n\t.model flat\n\n"; // Emit declarations for external functions. for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) if (I->isDeclaration()) { - std::string Name = Mang->getValueName(I); + std::string Name = Mang->getMangledName(I); decorateName(Name, I); - O << "\textern " ; + O << "\tEXTERN " ; if (I->hasDLLImportLinkage()) { O << "__imp_"; } @@ -433,9 +460,9 @@ bool X86IntelAsmPrinter::doInitialization(Module &M) { for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { if (I->isDeclaration()) { - std::string Name = Mang->getValueName(I); + std::string Name = Mang->getMangledName(I); - O << "\textern " ; + O << "\tEXTERN " ; if (I->hasDLLImportLinkage()) { O << "__imp_"; } @@ -458,24 +485,26 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) { if (EmitSpecialLLVMGlobal(I)) continue; - std::string name = Mang->getValueName(I); + std::string name = Mang->getMangledName(I); Constant *C = I->getInitializer(); unsigned Align = TD->getPreferredAlignmentLog(I); bool bCustomSegment = false; switch (I->getLinkage()) { case GlobalValue::CommonLinkage: - case GlobalValue::LinkOnceLinkage: - case GlobalValue::WeakLinkage: + case GlobalValue::LinkOnceAnyLinkage: + case GlobalValue::LinkOnceODRLinkage: + case GlobalValue::WeakAnyLinkage: + case GlobalValue::WeakODRLinkage: SwitchToDataSection(""); - O << name << "?\tsegment common 'COMMON'\n"; + O << name << "?\tSEGEMNT PARA common 'COMMON'\n"; bCustomSegment = true; // FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256 // are also available. break; case GlobalValue::AppendingLinkage: SwitchToDataSection(""); - O << name << "?\tsegment public 'DATA'\n"; + O << name << "?\tSEGMENT PARA public 'DATA'\n"; bCustomSegment = true; // FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256 // are also available. @@ -487,17 +516,20 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) { O << "\tpublic " << name << "\n"; // FALL THROUGH case GlobalValue::InternalLinkage: - SwitchToDataSection(TAI->getDataSection(), I); + SwitchToSection(TAI->getDataSection()); break; default: - assert(0 && "Unknown linkage type!"); + LLVM_UNREACHABLE("Unknown linkage type!"); } if (!bCustomSegment) EmitAlignment(Align, I); - O << name << ":\t\t\t\t" << TAI->getCommentString() - << " " << I->getName() << '\n'; + O << name << ":"; + if (VerboseAsm) + O << "\t\t\t\t" << TAI->getCommentString() + << " " << I->getName(); + O << '\n'; EmitGlobalConstant(C);