Don't print global names twice with -asm-verbose.
[oota-llvm.git] / lib / Target / X86 / AsmPrinter / X86IntelAsmPrinter.cpp
index 12a083aa74e56217ab4aa0ca2594b1e833fb343a..7823ca6da3dc6cd0b6878a840ecac118b475a48a 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Assembly/Writer.h"
+#include "llvm/CodeGen/DwarfWriter.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetOptions.h"
@@ -54,11 +55,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<PointerType>(Ty)->getElementType();
 
     // Size should be aligned to DWORD boundary
-    Size += ((TD->getABITypeSize(Ty) + 3)/4)*4;
+    Size += ((TD->getTypePaddedSize(Ty) + 3)/4)*4;
   }
 
   // We're not supporting tooooo huge arguments :)
@@ -117,16 +118,11 @@ void X86IntelAsmPrinter::decorateName(std::string &Name,
   }
 }
 
-
-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";
 
@@ -144,13 +140,14 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   decorateName(CurrentFnName, F);
 
-  SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
+  SwitchToTextSection("_text", F);
 
-  unsigned FnAlign = OptimizeForSize ? 1 : 4;
-  if (F->hasNote(FN_NOTE_OptimizeForSize))
+  unsigned FnAlign = 4;
+  if (F->hasFnAttr(Attribute::OptimizeForSize))
     FnAlign = 1;
   switch (F->getLinkage()) {
   default: assert(0 && "Unsupported linkage type!");
+  case Function::PrivateLinkage:
   case Function::InternalLinkage:
     EmitAlignment(FnAlign);
     break;
@@ -185,6 +182,8 @@ bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
 
   O << CurrentFnName << "\tendp\n";
 
+  O.flush();
+
   // We didn't modify anything.
   return false;
 }
@@ -239,11 +238,7 @@ 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;
   }
@@ -262,11 +257,7 @@ void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
       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: {
@@ -304,8 +295,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");
@@ -465,8 +456,10 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
 
     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";
       bCustomSegment = true;
@@ -487,7 +480,7 @@ 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!");
@@ -496,8 +489,11 @@ bool X86IntelAsmPrinter::doFinalization(Module &M) {
     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);