When promoting the result of fp_to_uint/fp_to_sint,
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfWriter.cpp
index 99e94e2ac049b986e210962ad1c88ed3b209e387..1cf75b923b36c2e1bc3a8d2304dfb8c0e0d88179 100644 (file)
@@ -1050,15 +1050,15 @@ public:
       }
 
       // If advancing cfa.
-      if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
-        if (!Src.isRegister()) {
-          if (Src.getRegister() == MachineLocation::VirtualFP) {
+      if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
+        if (!Src.isReg()) {
+          if (Src.getReg() == MachineLocation::VirtualFP) {
             Asm->EmitInt8(DW_CFA_def_cfa_offset);
             Asm->EOL("DW_CFA_def_cfa_offset");
           } else {
             Asm->EmitInt8(DW_CFA_def_cfa);
             Asm->EOL("DW_CFA_def_cfa");
-            Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister(), isEH));
+            Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), isEH));
             Asm->EOL("Register");
           }
 
@@ -1069,18 +1069,18 @@ public:
         } else {
           assert(0 && "Machine move no supported yet.");
         }
-      } else if (Src.isRegister() &&
-        Src.getRegister() == MachineLocation::VirtualFP) {
-        if (Dst.isRegister()) {
+      } else if (Src.isReg() &&
+        Src.getReg() == MachineLocation::VirtualFP) {
+        if (Dst.isReg()) {
           Asm->EmitInt8(DW_CFA_def_cfa_register);
           Asm->EOL("DW_CFA_def_cfa_register");
-          Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister(), isEH));
+          Asm->EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), isEH));
           Asm->EOL("Register");
         } else {
           assert(0 && "Machine move no supported yet.");
         }
       } else {
-        unsigned Reg = RI->getDwarfRegNum(Src.getRegister(), isEH);
+        unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH);
         int Offset = Dst.getOffset() / stackGrowth;
 
         if (Offset < 0) {
@@ -1152,7 +1152,7 @@ private:
 
   /// SectionMap - Provides a unique id per text section.
   ///
-  UniqueVector<std::string> SectionMap;
+  UniqueVector<const Section*> SectionMap;
 
   /// SectionSourceLines - Tracks line numbers per text section.
   ///
@@ -1409,10 +1409,10 @@ private:
   /// provided.
   void AddAddress(DIE *Die, unsigned Attribute,
                             const MachineLocation &Location) {
-    unsigned Reg = RI->getDwarfRegNum(Location.getRegister(), false);
+    unsigned Reg = RI->getDwarfRegNum(Location.getReg(), false);
     DIEBlock *Block = new DIEBlock();
 
-    if (Location.isRegister()) {
+    if (Location.isReg()) {
       if (Reg < 32) {
         AddUInt(Block, 0, DW_FORM_data1, DW_OP_reg0 + Reg);
       } else {
@@ -2031,6 +2031,42 @@ private:
     ConstructScope(RootScope, 0, 0, SPDie, Unit);
   }
 
+  /// ConstructDefaultScope - Construct a default scope for the subprogram.
+  ///
+  void ConstructDefaultScope(MachineFunction *MF) {
+    // Find the correct subprogram descriptor.
+    std::vector<SubprogramDesc *> Subprograms;
+    MMI->getAnchoredDescriptors<SubprogramDesc>(*M, Subprograms);
+
+    for (unsigned i = 0, N = Subprograms.size(); i < N; ++i) {
+      SubprogramDesc *SPD = Subprograms[i];
+
+      if (SPD->getName() == MF->getFunction()->getName()) {
+        // Get the compile unit context.
+        CompileUnit *Unit = GetBaseCompileUnit();
+
+        // Get the subprogram die.
+        DIE *SPDie = Unit->getDieMapSlotFor(SPD);
+        assert(SPDie && "Missing subprogram descriptor");
+
+        // Add the function bounds.
+        AddLabel(SPDie, DW_AT_low_pc, DW_FORM_addr,
+                 DWLabel("func_begin", SubprogramCount));
+        AddLabel(SPDie, DW_AT_high_pc, DW_FORM_addr,
+                 DWLabel("func_end", SubprogramCount));
+
+        MachineLocation Location(RI->getFrameRegister(*MF));
+        AddAddress(SPDie, DW_AT_frame_base, Location);
+        return;
+      }
+    }
+#if 0
+    // FIXME: This is causing an abort because C++ mangled names are compared
+    // with their unmangled counterparts. See PR2885. Don't do this assert.
+    assert(0 && "Couldn't find DIE for machine function!");
+#endif
+  }
+
   /// EmitInitial - Emit initial Dwarf declarations.  This is necessary for cc
   /// tools to recognize the object file contains Dwarf information.
   void EmitInitial() {
@@ -2062,9 +2098,9 @@ private:
     Asm->SwitchToDataSection(TAI->getDwarfRangesSection());
     EmitLabel("section_ranges", 0);
 
-    Asm->SwitchToTextSection(TAI->getTextSection());
+    Asm->SwitchToSection(TAI->getTextSection());
     EmitLabel("text_begin", 0);
-    Asm->SwitchToDataSection(TAI->getDataSection());
+    Asm->SwitchToSection(TAI->getDataSection());
     EmitLabel("data_begin", 0);
   }
 
@@ -2353,9 +2389,10 @@ private:
       // Isolate current sections line info.
       const std::vector<SourceLineInfo> &LineInfos = SectionSourceLines[j];
 
-      if (VerboseAsm)
-        Asm->EOL(std::string("Section ") + SectionMap[j + 1]);
-      else
+      if (VerboseAsm) {
+        const Section* S = SectionMap[j + 1];
+        Asm->EOL(std::string("Section ") + S->getName());
+      } else
         Asm->EOL();
 
       // Dwarf assumes we start with first line of first source file.
@@ -2587,7 +2624,7 @@ private:
     Asm->SwitchToDataSection(TAI->getDwarfARangesSection());
 
     // FIXME - Mock up
-  #if 0
+#if 0
     CompileUnit *Unit = GetBaseCompileUnit();
 
     // Don't include size of length
@@ -2611,7 +2648,7 @@ private:
 
     Asm->EmitInt32(0); Asm->EOL("EOM (1)");
     Asm->EmitInt32(0); Asm->EOL("EOM (2)");
-  #endif
+#endif
 
     Asm->EOL();
   }
@@ -2747,14 +2784,14 @@ public:
     if (!ShouldEmitDwarf()) return;
 
     // Standard sections final addresses.
-    Asm->SwitchToTextSection(TAI->getTextSection());
+    Asm->SwitchToSection(TAI->getTextSection());
     EmitLabel("text_end", 0);
-    Asm->SwitchToDataSection(TAI->getDataSection());
+    Asm->SwitchToSection(TAI->getDataSection());
     EmitLabel("data_end", 0);
 
     // End text sections.
     for (unsigned i = 1, N = SectionMap.size(); i <= N; ++i) {
-      Asm->SwitchToTextSection(SectionMap[i].c_str());
+      Asm->SwitchToSection(SectionMap[i]);
       EmitLabel("section_end", i);
     }
 
@@ -2821,7 +2858,7 @@ public:
 
   /// EndFunction - Gather and emit post-function debug information.
   ///
-  void EndFunction() {
+  void EndFunction(MachineFunction *MF) {
     if (!ShouldEmitDwarf()) return;
 
     // Define end label for subprogram.
@@ -2832,7 +2869,7 @@ public:
 
     if (!LineInfos.empty()) {
       // Get section line info.
-      unsigned ID = SectionMap.insert(Asm->CurrentSection);
+      unsigned ID = SectionMap.insert(Asm->CurrentSection_);
       if (SectionSourceLines.size() < ID) SectionSourceLines.resize(ID);
       std::vector<SourceLineInfo> &SectionLineInfos = SectionSourceLines[ID-1];
       // Append the function info to section info.
@@ -2841,7 +2878,18 @@ public:
     }
 
     // Construct scopes for subprogram.
-    ConstructRootScope(MMI->getRootScope());
+    if (MMI->getRootScope())
+      ConstructRootScope(MMI->getRootScope());
+    else
+      // FIXME: This is wrong. We are essentially getting past a problem with
+      // debug information not being able to handle unreachable blocks that have
+      // debug information in them. In particular, those unreachable blocks that
+      // have "region end" info in them. That situation results in the "root
+      // scope" not being created. If that's the case, then emit a "default"
+      // scope, i.e., one that encompasses the whole function. This isn't
+      // desirable. And a better way of handling this (and all of the debugging
+      // information) needs to be explored.
+      ConstructDefaultScope(MF);
 
     DebugFrames.push_back(FunctionDebugFrameInfo(SubprogramCount,
                                                  MMI->getFrameMoves()));
@@ -3385,8 +3433,8 @@ private:
 
     // Begin the exception table.
     Asm->SwitchToDataSection(TAI->getDwarfExceptionSection());
-    O << "GCC_except_table" << SubprogramCount << ":\n";
     Asm->EmitAlignment(2, 0, 0, false);
+    O << "GCC_except_table" << SubprogramCount << ":\n";
     for (unsigned i = 0; i != SizeAlign; ++i) {
       Asm->EmitInt8(0);
       Asm->EOL("Padding");
@@ -3921,8 +3969,8 @@ void DwarfWriter::BeginFunction(MachineFunction *MF) {
 
 /// EndFunction - Gather and emit post-function debug information.
 ///
-void DwarfWriter::EndFunction() {
-  DD->EndFunction();
+void DwarfWriter::EndFunction(MachineFunction *MF) {
+  DD->EndFunction(MF);
   DE->EndFunction();
 
   if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())