implement CodeGen/X86/inline-asm-x-scalar.ll:test3
[oota-llvm.git] / lib / CodeGen / DwarfWriter.cpp
index 9d8417247c8719bb6f5c56910afc2d9b74d95977..1ca9e218375fddc30018d46cbc648fec037548f0 100644 (file)
@@ -237,7 +237,7 @@ public:
   unsigned getOffset()                       const { return Offset; }
   unsigned getSize()                         const { return Size; }
   const std::vector<DIE *> &getChildren()    const { return Children; }
-  const std::vector<DIEValue *> &getValues() const { return Values; }
+  std::vector<DIEValue *> &getValues()       { return Values; }
   void setTag(unsigned Tag)                  { Abbrev.setTag(Tag); }
   void setOffset(unsigned O)                 { Offset = O; }
   void setSize(unsigned S)                   { Size = S; }
@@ -315,7 +315,7 @@ public:
   
   /// EmitValue - Emit value via the Dwarf writer.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const = 0;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form) = 0;
   
   /// SizeOf - Return the size of a value in bytes.
   ///
@@ -365,7 +365,7 @@ public:
     
   /// EmitValue - Emit integer of appropriate size.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of integer value in bytes.
   ///
@@ -402,7 +402,7 @@ public:
   
   /// EmitValue - Emit string value.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of string value in bytes.
   ///
@@ -441,7 +441,7 @@ public:
   
   /// EmitValue - Emit label value.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of label value in bytes.
   ///
@@ -479,7 +479,7 @@ public:
   
   /// EmitValue - Emit label value.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of label value in bytes.
   ///
@@ -517,7 +517,7 @@ public:
   
   /// EmitValue - Emit delta value.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of delta value in bytes.
   ///
@@ -559,7 +559,7 @@ public:
   
   /// EmitValue - Emit debug information entry offset.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of debug information entry in bytes.
   ///
@@ -624,7 +624,7 @@ public:
 
   /// EmitValue - Emit block data.
   ///
-  virtual void EmitValue(const DwarfDebug &DD, unsigned Form) const;
+  virtual void EmitValue(DwarfDebug &DD, unsigned Form);
   
   /// SizeOf - Determine size of block data in bytes.
   ///
@@ -795,7 +795,8 @@ protected:
   /// SubprogramCount - The running count of functions being compiled.
   ///
   unsigned SubprogramCount;
-  
+
+  unsigned SetCounter;
   Dwarf(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
   : O(OS)
   , Asm(A)
@@ -806,6 +807,7 @@ protected:
   , MF(NULL)
   , MMI(NULL)
   , SubprogramCount(0)
+  , SetCounter(1)
   {
   }
 
@@ -823,8 +825,12 @@ public:
   void PrintLabelName(DWLabel Label) const {
     PrintLabelName(Label.Tag, Label.Number);
   }
-  void PrintLabelName(const char *Tag, unsigned Number) const {
-    O << TAI->getPrivateGlobalPrefix() << Tag;
+  void PrintLabelName(const char *Tag, unsigned Number,
+                      bool isInSection = false) const {
+    if (isInSection && TAI->getDwarfSectionOffsetDirective())
+      O << TAI->getDwarfSectionOffsetDirective() << Tag;
+    else
+      O << TAI->getPrivateGlobalPrefix() << Tag;
     if (Number) O << Number;
   }
   
@@ -869,17 +875,15 @@ public:
   /// assemblers do not behave with absolute expressions with data directives,
   /// so there is an option (needsSet) to use an intermediary set expression.
   void EmitDifference(DWLabel LabelHi, DWLabel LabelLo,
-                      bool IsSmall = false) const {
+                      bool IsSmall = false) {
     EmitDifference(LabelHi.Tag, LabelHi.Number,
                    LabelLo.Tag, LabelLo.Number,
                    IsSmall);
   }
   void EmitDifference(const char *TagHi, unsigned NumberHi,
                       const char *TagLo, unsigned NumberLo,
-                      bool IsSmall = false) const {
+                      bool IsSmall = false) {
     if (TAI->needsSet()) {
-      static unsigned SetCounter = 1;
-      
       O << "\t.set\t";
       PrintLabelName("set", SetCounter);
       O << ",";
@@ -907,7 +911,42 @@ public:
       PrintLabelName(TagLo, NumberLo);
     }
   }
-                      
+
+  void EmitSectionOffset(const char* Label, const char* Section,
+                         unsigned LabelNumber, unsigned SectionNumber,
+                         bool IsSmall = false) {
+    if (TAI->needsSet()) {
+      O << "\t.set\t";
+      PrintLabelName("set", SetCounter);
+      O << ",";
+      PrintLabelName(Label, LabelNumber, true);
+      if (!TAI->isAbsoluteSectionOffsets()) {
+        O << "-";
+        PrintLabelName(Section, SectionNumber);
+      }      
+      O << "\n";
+      
+      if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
+        O << TAI->getData32bitsDirective();
+      else
+        O << TAI->getData64bitsDirective();
+        
+      PrintLabelName("set", SetCounter);
+      ++SetCounter;
+    } else {
+      if (IsSmall || TAI->getAddressSize() == sizeof(int32_t))
+        O << TAI->getData32bitsDirective();
+      else
+        O << TAI->getData64bitsDirective();
+        
+      PrintLabelName(Label, LabelNumber, true);
+      if (!TAI->isAbsoluteSectionOffsets()) {
+        O << "-";
+        PrintLabelName(Section, SectionNumber);
+      }
+    }    
+  }
+  
   /// EmitFrameMoves - Emit frame instructions to describe the layout of the
   /// frame.
   void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
@@ -1649,8 +1688,11 @@ private:
   CompileUnit *NewCompileUnit(CompileUnitDesc *UnitDesc, unsigned ID) {
     // Construct debug information entry.
     DIE *Die = new DIE(DW_TAG_compile_unit);
-    AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0),
-                                                  DWLabel("section_line", 0));
+    if (TAI->isAbsoluteSectionOffsets())
+      AddLabel(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0));
+    else
+      AddDelta(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0),
+               DWLabel("section_line", 0));      
     AddString(Die, DW_AT_producer,  DW_FORM_string, UnitDesc->getProducer());
     AddUInt  (Die, DW_AT_language,  DW_FORM_data1,  UnitDesc->getLanguage());
     AddString(Die, DW_AT_name,      DW_FORM_string, UnitDesc->getFileName());
@@ -1934,7 +1976,7 @@ private:
 
   /// EmitDIE - Recusively Emits a debug information entry.
   ///
-  void EmitDIE(DIE *Die) const {
+  void EmitDIE(DIE *Die) {
     // Get the abbreviation for this DIE.
     unsigned AbbrevNumber = Die->getAbbrevNumber();
     const DIEAbbrev *Abbrev = Abbreviations[AbbrevNumber - 1];
@@ -1949,7 +1991,7 @@ private:
              ":0x" + utohexstr(Die->getSize()) + " " +
              TagString(Abbrev->getTag())));
     
-    const std::vector<DIEValue *> &Values = Die->getValues();
+    std::vector<DIEValue *> &Values = Die->getValues();
     const std::vector<DIEAbbrevData> &AbbrevData = Abbrev->getData();
     
     // Emit the DIE attribute values.
@@ -2048,7 +2090,7 @@ private:
 
   /// EmitDebugInfo - Emit the debug info section.
   ///
-  void EmitDebugInfo() const {
+  void EmitDebugInfo() {
     // Start debug info section.
     Asm->SwitchToDataSection(TAI->getDwarfInfoSection());
     
@@ -2065,7 +2107,7 @@ private:
                            
     Asm->EmitInt32(ContentSize);  Asm->EOL("Length of Compilation Unit Info");
     Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF version number");
-    EmitDifference("abbrev_begin", 0, "section_abbrev", 0, true);
+    EmitSectionOffset("abbrev_begin", "section_abbrev", 0, 0, true);
     Asm->EOL("Offset Into Abbrev. Section");
     Asm->EmitInt8(TAI->getAddressSize()); Asm->EOL("Address Size (in bytes)");
   
@@ -2116,7 +2158,7 @@ private:
 
   /// EmitDebugLines - Emit source line information.
   ///
-  void EmitDebugLines() const {
+  void EmitDebugLines() {
     // Minimum line delta, thus ranging from -10..(255-10).
     const int MinLineDelta = -(DW_LNS_fixed_advance_pc + 1);
     // Maximum line delta, thus ranging from -10..(255-10).
@@ -2323,8 +2365,8 @@ private:
     Asm->EOL("Length of Frame Information Entry");
     
     EmitLabel("frame_begin", SubprogramCount);
-    
-    EmitDifference("frame_common_begin", 0, "section_frame", 0, true);
+
+    EmitSectionOffset("frame_common_begin", "section_frame", 0, 0, true);
     Asm->EOL("FDE CIE offset");
 
     EmitReference("func_begin", SubprogramCount);
@@ -2358,8 +2400,8 @@ private:
     EmitLabel("pubnames_begin", Unit->getID());
     
     Asm->EmitInt16(DWARF_VERSION); Asm->EOL("DWARF Version");
-    
-    EmitDifference("info_begin", Unit->getID(), "section_info", 0, true);
+
+    EmitSectionOffset("info_begin", "section_info", Unit->getID(), 0, true);
     Asm->EOL("Offset of Compilation Unit Info");
 
     EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(),true);
@@ -2786,9 +2828,9 @@ private:
       Asm->EOL("Length of Frame Information Entry");
       
       EmitLabel("eh_frame_begin", SubprogramCount);
-      
-      EmitDifference("eh_frame_begin", SubprogramCount,
-                     "section_eh_frame", 0, true);
+
+      EmitSectionOffset("eh_frame_begin", "section_eh_frame",
+                        SubprogramCount, 0, true);
       Asm->EOL("FDE CIE offset");
 
       EmitReference("eh_func_begin", SubprogramCount, true);
@@ -2860,6 +2902,11 @@ private:
     
     // Gather first action index for each landing pad site.
     SmallVector<unsigned, 8> Actions;
+    
+    // FIXME - Assume there is only one filter typeinfo list per function
+    // time being.  I.E., Each call to eh_filter will have the same list.
+    // This can change if a function is inlined. 
+    const LandingPadInfo *Filter = 0;
 
     // Compute sizes for exception table.
     unsigned SizeHeader = sizeof(int8_t) + // LPStart format
@@ -2874,21 +2921,37 @@ private:
     // landing pad site info and the size of the landing pad's actions.
     for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
       const LandingPadInfo &LandingPad = LandingPads[i];
+      bool IsFilter = LandingPad.IsFilter;
       unsigned SizeSiteActions = 0;
       const std::vector<unsigned> &TypeIds = LandingPad.TypeIds;
       unsigned SizeAction = 0;
+      signed FirstAction;
       
-      // Gather the action sizes
-      for (unsigned j = 0, M = TypeIds.size(); j != M; ++j) {
-        unsigned TypeID = TypeIds[i];
-        unsigned SizeTypeID = Asm->SizeULEB128(TypeID);
-        signed Action = j ? -(SizeAction + SizeTypeID) : 0;
-        SizeAction = SizeTypeID + Asm->SizeSLEB128(Action);
+      if (IsFilter) {
+        // FIXME - Assume there is only one filter typeinfo list per function
+        // time being.  I.E., Each call to eh_filter will have the same list.
+        // This can change if a function is inlined. 
+        Filter = &LandingPad;
+        SizeAction =  Asm->SizeSLEB128(-1) + Asm->SizeSLEB128(0);
         SizeSiteActions += SizeAction;
+        // Record the first action of the landing pad site.
+        FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
+      } else if (TypeIds.empty()) {
+        FirstAction = 0;
+      } else {
+        // Gather the action sizes
+        for (unsigned j = 0, M = TypeIds.size(); j != M; ++j) {
+          unsigned TypeID = TypeIds[i];
+          unsigned SizeTypeID = Asm->SizeSLEB128(TypeID);
+          signed Action = j ? -(SizeAction + SizeTypeID) : 0;
+          SizeAction = SizeTypeID + Asm->SizeSLEB128(Action);
+          SizeSiteActions += SizeAction;
+        }
+        
+        // Record the first action of the landing pad site.
+        FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
       }
       
-      // Record the first action of the landing pad site.
-      signed FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
       Actions.push_back(FirstAction);
       
       // Compute this sites contribution to size.
@@ -2896,7 +2959,7 @@ private:
       SizeSites += sizeof(int32_t) + // Site start.
                    sizeof(int32_t) + // Site length.
                    sizeof(int32_t) + // Landing pad.
-                   Asm->SizeULEB128(FirstAction); // Action.
+                   Asm->SizeSLEB128(FirstAction); // Action.
     }
     
     // Final tallies.
@@ -2930,16 +2993,23 @@ private:
     // Emit the landng pad site information.
     for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
       const LandingPadInfo &LandingPad = LandingPads[i];
-      EmitDifference("label", LandingPad.BeginLabel,
-                     "eh_func_begin", SubprogramCount);
+      EmitSectionOffset("label", "eh_func_begin",
+                        LandingPad.BeginLabel, SubprogramCount);
       Asm->EOL("Region start");
       
       EmitDifference("label", LandingPad.EndLabel,
                      "label", LandingPad.BeginLabel);
       Asm->EOL("Region length");
       
-      EmitDifference("label", LandingPad.LandingPadLabel,
-                     "eh_func_begin", SubprogramCount);
+      if (LandingPad.TypeIds.empty()) {
+        if (TAI->getAddressSize() == sizeof(int32_t))
+          Asm->EmitInt32(0);
+        else
+          Asm->EmitInt64(0);
+      } else {
+        EmitSectionOffset("label", "eh_func_begin",
+                          LandingPad.LandingPadLabel, SubprogramCount);
+      }
       Asm->EOL("Landing pad");
 
       Asm->EmitULEB128Bytes(Actions[i]);
@@ -2952,15 +3022,22 @@ private:
       const std::vector<unsigned> &TypeIds = LandingPad.TypeIds;
       unsigned SizeAction = 0;
       
-      for (unsigned j = 0, M = TypeIds.size(); j < M; ++j) {
-        unsigned TypeID = TypeIds[j];
-        unsigned SizeTypeID = Asm->SizeULEB128(TypeID);
-        Asm->EmitSLEB128Bytes(TypeID);
+      if (LandingPad.IsFilter) {
+        Asm->EmitSLEB128Bytes(-1);
         Asm->EOL("TypeInfo index");
-        signed Action = j ? -(SizeAction + SizeTypeID) : 0;
-        SizeAction = SizeTypeID + Asm->SizeSLEB128(Action);
-        Asm->EmitSLEB128Bytes(Action);
+        Asm->EmitSLEB128Bytes(0);
         Asm->EOL("Next action");
+      } else {
+        for (unsigned j = 0, M = TypeIds.size(); j < M; ++j) {
+          unsigned TypeID = TypeIds[j];
+          unsigned SizeTypeID = Asm->SizeSLEB128(TypeID);
+          Asm->EmitSLEB128Bytes(TypeID);
+          Asm->EOL("TypeInfo index");
+          signed Action = j ? -(SizeAction + SizeTypeID) : 0;
+          SizeAction = SizeTypeID + Asm->SizeSLEB128(Action);
+          Asm->EmitSLEB128Bytes(Action);
+          Asm->EOL("Next action");
+        }
       }
     }
 
@@ -2982,6 +3059,19 @@ private:
       Asm->EOL("TypeInfo");
     }
 
+    // Emit the filter typeinfo.
+    if (Filter) {
+      const std::vector<unsigned> &TypeIds = Filter->TypeIds;
+      for (unsigned j = 0, M = TypeIds.size(); j < M; ++j) {
+        unsigned TypeID = TypeIds[j];
+        Asm->EmitSLEB128Bytes(TypeID);
+        Asm->EOL("TypeInfo index");
+      }
+      Asm->EmitSLEB128Bytes(0);
+      Asm->EOL("End of filter typeinfo");
+    }
+    
+    Asm->EmitAlignment(2);
   }
 
 public:
@@ -3107,7 +3197,7 @@ void DIEValue::dump() {
 
 /// EmitValue - Emit integer of appropriate size.
 ///
-void DIEInteger::EmitValue(const DwarfDebug &DD, unsigned Form) const {
+void DIEInteger::EmitValue(DwarfDebug &DD, unsigned Form) {
   switch (Form) {
   case DW_FORM_flag:  // Fall thru
   case DW_FORM_ref1:  // Fall thru
@@ -3148,7 +3238,7 @@ unsigned DIEInteger::SizeOf(const DwarfDebug &DD, unsigned Form) const {
 
 /// EmitValue - Emit string value.
 ///
-void DIEString::EmitValue(const DwarfDebug &DD, unsigned Form) const {
+void DIEString::EmitValue(DwarfDebug &DD, unsigned Form) {
   DD.getAsm()->EmitString(String);
 }
 
@@ -3156,7 +3246,7 @@ void DIEString::EmitValue(const DwarfDebug &DD, unsigned Form) const {
 
 /// EmitValue - Emit label value.
 ///
-void DIEDwarfLabel::EmitValue(const DwarfDebug &DD, unsigned Form) const {
+void DIEDwarfLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
   DD.EmitReference(Label);
 }
 
@@ -3170,7 +3260,7 @@ unsigned DIEDwarfLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
 
 /// EmitValue - Emit label value.
 ///
-void DIEObjectLabel::EmitValue(const DwarfDebug &DD, unsigned Form) const {
+void DIEObjectLabel::EmitValue(DwarfDebug &DD, unsigned Form) {
   DD.EmitReference(Label);
 }
 
@@ -3184,7 +3274,7 @@ unsigned DIEObjectLabel::SizeOf(const DwarfDebug &DD, unsigned Form) const {
 
 /// EmitValue - Emit delta value.
 ///
-void DIEDelta::EmitValue(const DwarfDebug &DD, unsigned Form) const {
+void DIEDelta::EmitValue(DwarfDebug &DD, unsigned Form) {
   bool IsSmall = Form == DW_FORM_data4;
   DD.EmitDifference(LabelHi, LabelLo, IsSmall);
 }
@@ -3200,7 +3290,7 @@ unsigned DIEDelta::SizeOf(const DwarfDebug &DD, unsigned Form) const {
 
 /// EmitValue - Emit debug information entry offset.
 ///
-void DIEntry::EmitValue(const DwarfDebug &DD, unsigned Form) const {
+void DIEntry::EmitValue(DwarfDebug &DD, unsigned Form) {
   DD.getAsm()->EmitInt32(Entry->getOffset());
 }
     
@@ -3221,7 +3311,7 @@ unsigned DIEBlock::ComputeSize(DwarfDebug &DD) {
 
 /// EmitValue - Emit block data.
 ///
-void DIEBlock::EmitValue(const DwarfDebug &DD, unsigned Form) const {
+void DIEBlock::EmitValue(DwarfDebug &DD, unsigned Form) {
   switch (Form) {
   case DW_FORM_block1: DD.getAsm()->EmitInt8(Size);         break;
   case DW_FORM_block2: DD.getAsm()->EmitInt16(Size);        break;