Correctly clone FlaggedNodes.
[oota-llvm.git] / lib / CodeGen / AsmPrinter.cpp
index bb66bd2ad5c3b0dbd3abce94d53ec5858c54785b..80965020d0df2a2af60d99cec9de17f516f499b6 100644 (file)
@@ -39,7 +39,8 @@ AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
 char AsmPrinter::ID = 0;
 AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
                        const TargetAsmInfo *T)
-  : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T)
+  : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T),
+    IsInTextSection(false)
 {}
 
 std::string AsmPrinter::getSectionForFunction(const Function &F) const {
@@ -69,6 +70,8 @@ void AsmPrinter::SwitchToTextSection(const char *NewSection,
 
   if (!CurrentSection.empty())
     O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
+
+  IsInTextSection = true;
 }
 
 /// SwitchToDataSection - Switch to the specified data section of the executable
@@ -93,6 +96,8 @@ void AsmPrinter::SwitchToDataSection(const char *NewSection,
   
   if (!CurrentSection.empty())
     O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
+
+  IsInTextSection = false;
 }
 
 
@@ -118,9 +123,8 @@ bool AsmPrinter::doInitialization(Module &M) {
 
   SwitchToDataSection("");   // Reset back to no section.
   
-  if (MachineModuleInfo *MMI = getAnalysisToUpdate<MachineModuleInfo>()) {
-    MMI->AnalyzeModule(M);
-  }
+  MMI = getAnalysisToUpdate<MachineModuleInfo>();
+  if (MMI) MMI->AnalyzeModule(M);
   
   return false;
 }
@@ -158,16 +162,17 @@ bool AsmPrinter::doFinalization(Module &M) {
       else if (!I->hasInternalLinkage())
         assert(0 && "Invalid alias linkage");
       
-      O << TAI->getSetDirective() << Name << ", " << Target << "\n";
+      O << TAI->getSetDirective() << ' ' << Name << ", " << Target << "\n";
 
       // If the aliasee has external weak linkage it can be referenced only by
       // alias itself. In this case it can be not in ExtWeakSymbols list. Emit
       // weak reference in such case.
-      if (GV->hasExternalWeakLinkage())
+      if (GV->hasExternalWeakLinkage()) {
         if (TAI->getWeakRefDirective())
           O << TAI->getWeakRefDirective() << Target << "\n";
         else
           O << "\t.globl\t" << Target << "\n";
+      }
     }
   }
 
@@ -344,7 +349,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
       O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
         << '_' << uid << "_set_" << MBB->getNumber();
     } else {
-      printBasicBlockLabel(MBB, false, false);
+      printBasicBlockLabel(MBB, false, false, false);
       // If the arch uses custom Jump Table directives, don't calc relative to
       // JT
       if (!HadJTEntryDirective) 
@@ -352,7 +357,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
           << getFunctionNumber() << '_' << uid;
     }
   } else {
-    printBasicBlockLabel(MBB, false, false);
+    printBasicBlockLabel(MBB, false, false, false);
   }
 }
 
@@ -679,8 +684,8 @@ void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
 //     Align = std::max(Align, ForcedAlignBits);
 //
 void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
-                               unsigned ForcedAlignBits, bool UseFillExpr,
-                               unsigned FillValue) const {
+                               unsigned ForcedAlignBits,
+                               bool UseFillExpr) const {
   if (GV && GV->getAlignment())
     NumBits = Log2_32(GV->getAlignment());
   NumBits = std::max(NumBits, ForcedAlignBits);
@@ -688,6 +693,9 @@ void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
   if (NumBits == 0) return;   // No need to emit alignment.
   if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
   O << TAI->getAlignDirective() << NumBits;
+
+  unsigned FillValue = TAI->getTextAlignFillValue();
+  UseFillExpr &= IsInTextSection && FillValue;
   if (UseFillExpr) O << ",0x" << std::hex << FillValue << std::dec;
   O << "\n";
 }
@@ -939,10 +947,13 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) {
       // api needed to prevent premature destruction
       APInt api = CFP->getValueAPF().convertToAPInt();
       const uint64_t *p = api.getRawData();
+      APFloat DoubleVal = CFP->getValueAPF();
+      DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
       if (TD->isBigEndian()) {
         O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 48)
           << "\t" << TAI->getCommentString()
-          << " long double most significant halfword\n";
+          << " long double most significant halfword of ~"
+          << DoubleVal.convertToDouble() << "\n";
         O << TAI->getData16bitsDirective() << uint16_t(p[0] >> 32)
           << "\t" << TAI->getCommentString()
           << " long double next halfword\n";
@@ -958,7 +969,8 @@ void AsmPrinter::EmitGlobalConstant(const Constant *CV, bool Packed) {
        } else {
         O << TAI->getData16bitsDirective() << uint16_t(p[1])
           << "\t" << TAI->getCommentString()
-          << " long double least significant halfword\n";
+          << " long double least significant halfword of ~"
+          << DoubleVal.convertToDouble() << "\n";
         O << TAI->getData16bitsDirective() << uint16_t(p[0])
           << "\t" << TAI->getCommentString()
           << " long double next halfword\n";
@@ -1104,9 +1116,10 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
   // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
   const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
 
-  // If this asmstr is empty, don't bother printing the #APP/#NOAPP markers.
+  // If this asmstr is empty, just print the #APP/#NOAPP markers.
+  // These are useful to see where empty asm's wound up.
   if (AsmStr[0] == 0) {
-    O << "\n";  // Tab already printed, avoid double indenting next instr.
+    O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << "\n";
     return;
   }
   
@@ -1247,7 +1260,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
 
           if (Modifier[0]=='l')  // labels are target independent
             printBasicBlockLabel(MI->getOperand(OpNo).getMBB(), 
-                                 false, false);
+                                 false, false, false);
           else {
             AsmPrinter *AP = const_cast<AsmPrinter*>(this);
             if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
@@ -1276,10 +1289,24 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
 /// printLabel - This method prints a local label used by debug and
 /// exception handling tables.
 void AsmPrinter::printLabel(const MachineInstr *MI) const {
-  O << "\n" << TAI->getPrivateGlobalPrefix()
+  O << TAI->getPrivateGlobalPrefix()
     << "label" << MI->getOperand(0).getImm() << ":\n";
 }
 
+void AsmPrinter::printLabel(unsigned Id) const {
+  O << TAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
+}
+
+/// printDeclare - This method prints a local variable declaration used by
+/// debug tables.
+/// FIXME: It doesn't really print anything rather it inserts a DebugVariable
+/// entry into dwarf table.
+void AsmPrinter::printDeclare(const MachineInstr *MI) const {
+  int FI = MI->getOperand(0).getIndex();
+  GlobalValue *GV = MI->getOperand(1).getGlobal();
+  MMI->RecordVariable(GV, FI);
+}
+
 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
 /// instruction, using the specified assembler variant.  Targets should
 /// overried this to format as appropriate.
@@ -1299,8 +1326,15 @@ bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
 /// printBasicBlockLabel - This method prints the label for the specified
 /// MachineBasicBlock
 void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
+                                      bool printAlign, 
                                       bool printColon,
                                       bool printComment) const {
+  if (printAlign) {
+    unsigned Align = MBB->getAlignment();
+    if (Align)
+      EmitAlignment(Log2_32(Align));
+  }
+
   O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << "_"
     << MBB->getNumber();
   if (printColon)
@@ -1319,7 +1353,7 @@ void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
   
   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
     << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
-  printBasicBlockLabel(MBB, false, false);
+  printBasicBlockLabel(MBB, false, false, false);
   O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
     << '_' << uid << '\n';
 }
@@ -1332,7 +1366,7 @@ void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
     << getFunctionNumber() << '_' << uid << '_' << uid2
     << "_set_" << MBB->getNumber() << ',';
-  printBasicBlockLabel(MBB, false, false);
+  printBasicBlockLabel(MBB, false, false, false);
   O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
     << '_' << uid << '_' << uid2 << '\n';
 }