[llvm-commits] CVS: llvm/lib/CodeGen/DwarfWriter.cpp

Duncan Sands baldrick at free.fr
Wed May 16 05:12:43 PDT 2007



Changes in directory llvm/lib/CodeGen:

DwarfWriter.cpp updated: 1.145 -> 1.146
---
Log message:

Output exception call-sites in address order, as required by the unwinding
runtime.


---
Diffs of the changes:  (+54 -10)

 DwarfWriter.cpp |   64 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 54 insertions(+), 10 deletions(-)


Index: llvm/lib/CodeGen/DwarfWriter.cpp
diff -u llvm/lib/CodeGen/DwarfWriter.cpp:1.145 llvm/lib/CodeGen/DwarfWriter.cpp:1.146
--- llvm/lib/CodeGen/DwarfWriter.cpp:1.145	Tue May 15 08:54:14 2007
+++ llvm/lib/CodeGen/DwarfWriter.cpp	Wed May 16 07:12:23 2007
@@ -13,6 +13,7 @@
 
 #include "llvm/CodeGen/DwarfWriter.h"
 
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/UniqueVector.h"
@@ -31,6 +32,7 @@
 #include "llvm/Target/MRegisterInfo.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetFrameInfo.h"
+#include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include <ostream>
@@ -2911,6 +2913,21 @@
   ///     found the the frame is unwound and handling continues.
   ///  3. Type id table contains references to all the C++ typeinfo for all
   ///     catches in the function.  This tables is reversed indexed base 1.
+
+  struct KeyInfo {
+    static inline unsigned getEmptyKey() { return -1U; }
+    static inline unsigned getTombstoneKey() { return -2U; }
+    static unsigned getHashValue(const unsigned &Key) { return Key; }
+    static bool isPod() { return true; }
+  };
+
+  struct PadSite {
+    unsigned PadIndex;
+    unsigned SiteIndex;
+  };
+
+  typedef DenseMap<unsigned, PadSite, KeyInfo> PadMapType;
+
   void EmitExceptionTable() {
     // Map all labels and get rid of any dead landing pads.
     MMI->TidyLandingPads();
@@ -3013,20 +3030,47 @@
     Asm->EOL("Call site format (DW_EH_PE_udata4)");
     Asm->EmitULEB128Bytes(SizeSites);
     Asm->EOL("Call-site table length");
-    
-    // Emit the landing pad site information.
+
+    // Emit the landing pad site information in order of address.
+    PadMapType PadMap;
+
     for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
       const LandingPadInfo &LandingPad = LandingPads[i];
       for (unsigned j=0, E = LandingPad.BeginLabels.size(); j != E; ++j) {
-        EmitSectionOffset("label", "eh_func_begin",
-                          LandingPad.BeginLabels[j], SubprogramCount,
+        unsigned BeginLabel = LandingPad.BeginLabels[j];
+        assert(!PadMap.count(BeginLabel) && "duplicate landing pad labels!");
+        PadSite P = { i, j };
+        PadMap[BeginLabel] = P;
+      }
+    }
+
+    for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
+         I != E; ++I) {
+      for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
+           MI != E; ++MI) {
+        if (MI->getOpcode() != TargetInstrInfo::LABEL)
+          continue;
+
+        unsigned BeginLabel = MI->getOperand(0).getImmedValue();
+        PadMapType::iterator L = PadMap.find(BeginLabel);
+
+        if (L == PadMap.end())
+          continue;
+
+        PadSite P = L->second;
+        const LandingPadInfo &LandingPad = LandingPads[P.PadIndex];
+
+        assert(BeginLabel == LandingPad.BeginLabels[P.SiteIndex] &&
+               "Inconsistent landing pad map!");
+
+        EmitSectionOffset("label", "eh_func_begin", BeginLabel, SubprogramCount,
                           false, true);
         Asm->EOL("Region start");
-      
-        EmitDifference("label", LandingPad.EndLabels[j],
-                       "label", LandingPad.BeginLabels[j]);
+
+        EmitDifference("label", LandingPad.EndLabels[P.SiteIndex],
+                       "label", BeginLabel);
         Asm->EOL("Region length");
-      
+
         if (LandingPad.TypeIds.empty()) {
           if (TAI->getAddressSize() == sizeof(int32_t))
             Asm->EmitInt32(0);
@@ -3038,11 +3082,11 @@
         }
         Asm->EOL("Landing pad");
 
-        Asm->EmitULEB128Bytes(Actions[i]);
+        Asm->EmitULEB128Bytes(Actions[P.PadIndex]);
         Asm->EOL("Action");
       }
     }
-    
+
     // Emit the actions.
     for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
       const LandingPadInfo &LandingPad = LandingPads[i];






More information about the llvm-commits mailing list