Make sure that landing pad entries in the EH call site table are in the proper
authorJim Grosbach <grosbach@apple.com>
Thu, 21 Jan 2010 00:43:30 +0000 (00:43 +0000)
committerJim Grosbach <grosbach@apple.com>
Thu, 21 Jan 2010 00:43:30 +0000 (00:43 +0000)
order for SjLj style exception handling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94055 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineModuleInfo.h
include/llvm/Function.h
lib/CodeGen/AsmPrinter/DwarfException.cpp
lib/CodeGen/MachineModuleInfo.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SjLjEHPrepare.cpp

index e9b645b5e8d5d5bdbb067c3c3a4d2fa150998ffb..192f37df2c0db0797d8d84bdee3e977e0ed5d3e4 100644 (file)
@@ -113,7 +113,11 @@ class MachineModuleInfo : public ImmutablePass {
   // LandingPads - List of LandingPadInfo describing the landing pad information
   // in the current function.
   std::vector<LandingPadInfo> LandingPads;
-  
+
+  // Map of invoke call site index values to associated begin EH_LABEL for
+  // the current function.
+  DenseMap<unsigned, unsigned> CallSiteMap;
+
   // TypeInfos - List of C++ TypeInfo used in the current function.
   //
   std::vector<GlobalVariable *> TypeInfos;
@@ -301,7 +305,19 @@ public:
   const std::vector<LandingPadInfo> &getLandingPads() const {
     return LandingPads;
   }
-  
+
+  /// setCallSiteBeginLabel - Map the begin label for a call site
+  void setCallSiteBeginLabel(unsigned BeginLabel, unsigned Site) {
+    CallSiteMap[BeginLabel] = Site;
+  }
+
+  /// getCallSiteBeginLabel - Get the call site number for a begin label
+  unsigned getCallSiteBeginLabel(unsigned BeginLabel) {
+    assert(CallSiteMap.count(BeginLabel) &&
+           "Missing call site number for EH_LABEL!");
+    return CallSiteMap[BeginLabel];
+  }
+
   /// getTypeInfos - Return a reference to the C++ typeinfo for the current
   /// function.
   const std::vector<GlobalVariable *> &getTypeInfos() const {
index 38822332c433a690033bae2f9cf880f8ce24898c..72cb267ae0b5f46669bb22767b7b6b3b0d68c7fc 100644 (file)
@@ -24,6 +24,7 @@
 #include "llvm/Argument.h"
 #include "llvm/Attributes.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/ADT/DenseMap.h"
 
 namespace llvm {
 
@@ -86,6 +87,8 @@ private:
   mutable ArgumentListType ArgumentList;  ///< The formal arguments
   ValueSymbolTable *SymTab;               ///< Symbol table of args/instructions
   AttrListPtr AttributeList;              ///< Parameter attributes
+  DenseMap<Instruction*, unsigned>
+    CallSiteNumbering;                    ///< SjLj EH call site numbering
 
   // HasLazyArguments is stored in Value::SubclassData.
   /*bool HasLazyArguments;*/
@@ -165,7 +168,19 @@ public:
     setValueSubclassData((getSubclassDataFromValue() & 1) |
                          (static_cast<unsigned>(CC) << 1));
   }
-  
+
+  /// setCallSiteNumber - Set the call site number mapping for an invoke
+  /// in the function
+  void setCallSiteNumber(Instruction *II, unsigned Num) {
+    CallSiteNumbering[II] = Num;
+  }
+
+  /// getCallSiteNumber - Get the call site number for an invoke instruction
+  unsigned getCallSiteNumber(Instruction *II) {
+    if (CallSiteNumbering.count(II) == 0) return 0;
+    return CallSiteNumbering[II];
+  }
+
   /// getAttributes - Return the attribute list for this Function.
   ///
   const AttrListPtr &getAttributes() const { return AttributeList; }
index 615be0e1c796e8b69110a1f1d76b9b3b8f6562cd..d09f9d9bca4bcd32d8138c4f3d5e9a167d1de5a5 100644 (file)
@@ -590,7 +590,16 @@ ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
         }
 
         // Otherwise, create a new call-site.
-        CallSites.push_back(Site);
+        if (MAI->getExceptionHandlingType() == ExceptionHandling::Dwarf)
+          CallSites.push_back(Site);
+        else {
+          // SjLj EH must maintain the call sites in the order assigned
+          // to them by the SjLjPrepare pass.
+          unsigned SiteNo = MMI->getCallSiteBeginLabel(BeginLabel);
+          if (CallSites.size() < SiteNo)
+            CallSites.resize(SiteNo);
+          CallSites[SiteNo - 1] = Site;
+        }
         PreviousIsInvoke = true;
       } else {
         // Create a gap.
index ed5bb5e5410c3d583552974095ac79096791cbb1..dc26d9144ffae8cbccbdaed14594b0757b90fb70 100644 (file)
@@ -71,6 +71,7 @@ void MachineModuleInfo::EndFunction() {
 
   // Clean up exception info.
   LandingPads.clear();
+  CallSiteMap.clear();
   TypeInfos.clear();
   FilterIds.clear();
   FilterEnds.clear();
index a3fb34576ac0730884e8fab0ab816f406d06e4de..5b733a873ff7a8c38f75f0a0a607b6e085b5db83 100644 (file)
@@ -5049,6 +5049,12 @@ void SelectionDAGBuilder::LowerCallTo(CallSite CS, SDValue Callee,
     // used to detect deletion of the invoke via the MachineModuleInfo.
     BeginLabel = MMI->NextLabelID();
 
+    // Keep track of which landing pads go with which invokes. SjLj uses
+    // this to maintain the ordering of pads in the LSDA. Dwarf ignores it.
+    Function *F = LandingPad->getParent()->getFunction();
+    MMI->setCallSiteBeginLabel(BeginLabel,
+                               F->getCallSiteNumber(CS.getInstruction()));
+
     // Both PendingLoads and PendingExports must be flushed here;
     // this call might not return.
     (void)getRoot();
index 95589331cf423d1c567b29fb3633b7ab42518b96..95b94e6c307376a267d422a4c2318845701c8ecc 100644 (file)
@@ -474,8 +474,10 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
     // At this point, we are all set up, update the invoke instructions
     // to mark their call_site values, and fill in the dispatch switch
     // accordingly.
-    for (unsigned i = 0, e = Invokes.size(); i != e; ++i)
+    for (unsigned i = 0, e = Invokes.size(); i != e; ++i) {
+      F.setCallSiteNumber(Invokes[i], i+1);
       markInvokeCallSite(Invokes[i], i+1, CallSite, DispatchSwitch);
+    }
 
     // The front end has likely added calls to _Unwind_Resume. We need
     // to find those calls and mark the call_site as -1 immediately prior.