[llvm-commits] [llvm] r105872 - /llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp

Bill Wendling isanbard at gmail.com
Fri Jun 11 19:34:30 PDT 2010


Author: void
Date: Fri Jun 11 21:34:29 2010
New Revision: 105872

URL: http://llvm.org/viewvc/llvm-project?rev=105872&view=rev
Log:
When performing the Horrible Hack(tm-Duncan) on the EH code to convert a
clean-up to a catch-all after inlining, take into account that there could be
filter IDs as well. The presence of filters don't mean that the selector catches
anything. It's just metadata information.

Modified:
    llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp

Modified: llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp?rev=105872&r1=105871&r2=105872&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/DwarfEHPrepare.cpp Fri Jun 11 21:34:29 2010
@@ -89,6 +89,8 @@
     /// initializer instead.
     bool CleanupSelectors();
 
+    bool IsACleanupSelector(IntrinsicInst *);
+
     /// FindAllCleanupSelectors - Find all eh.selector calls that are clean-ups.
     void FindAllCleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels);
 
@@ -186,25 +188,49 @@
   return new DwarfEHPrepare(tm, fast);
 }
 
+/// IsACleanupSelector - Return true if the intrinsic instruction is a clean-up
+/// selector instruction.
+bool DwarfEHPrepare::IsACleanupSelector(IntrinsicInst *II) {
+  unsigned NumOps = II->getNumOperands();
+  bool IsCleanUp = (NumOps == 3);
+
+  if (IsCleanUp)
+    return true;
+
+  if (ConstantInt *CI = dyn_cast<ConstantInt>(II->getOperand(3))) {
+    unsigned Val = CI->getZExtValue();
+
+    if (Val == 0 || Val + 3 == NumOps) {
+      // If the value is 0 or the selector has only filters in it, then it's
+      // a cleanup.
+      return true;
+    } else {
+      assert(Val + 3 < NumOps && "Ill-formed eh.selector!");
+
+      if (Val + 4 == NumOps) {
+        if (ConstantInt *FinalVal =
+            dyn_cast<ConstantInt>(II->getOperand(NumOps - 1)))
+          return (FinalVal->getZExtValue() == 0);
+      }
+    }
+  }
+
+  return false;
+}
+
 /// FindAllCleanupSelectors - Find all eh.selector calls that are clean-ups.
 void DwarfEHPrepare::
 FindAllCleanupSelectors(SmallPtrSet<IntrinsicInst*, 32> &Sels) {
   for (Value::use_iterator
          I = SelectorIntrinsic->use_begin(),
          E = SelectorIntrinsic->use_end(); I != E; ++I) {
-    IntrinsicInst *SI = cast<IntrinsicInst>(I);
-    if (!SI || SI->getParent()->getParent() != F) continue;
+    IntrinsicInst *II = cast<IntrinsicInst>(I);
 
-    unsigned NumOps = SI->getNumOperands();
-    if (NumOps > 4) continue;
-    bool IsCleanUp = (NumOps == 3);
-
-    if (!IsCleanUp)
-      if (ConstantInt *CI = dyn_cast<ConstantInt>(SI->getOperand(3)))
-        IsCleanUp = (CI->getZExtValue() == 0);
+    if (II->getParent()->getParent() != F)
+      continue;
 
-    if (IsCleanUp)
-      Sels.insert(SI);
+    if (IsACleanupSelector(II))
+      Sels.insert(II);
   }
 }
 
@@ -360,21 +386,9 @@
         // an eh.selector intrinsic call. If the eh.selector is a 'clean-up', we
         // need to convert it to a 'catch-all'.
         for (SmallPtrSet<IntrinsicInst*, 8>::iterator
-               SI = SelCalls.begin(), SE = SelCalls.end(); SI != SE; ++SI) {
-          IntrinsicInst *II = *SI;
-          unsigned NumOps = II->getNumOperands();
-
-          if (NumOps <= 4) {
-            bool IsCleanUp = (NumOps == 3);
-
-            if (!IsCleanUp)
-              if (ConstantInt *CI = dyn_cast<ConstantInt>(II->getOperand(3)))
-                IsCleanUp = (CI->getZExtValue() == 0);
-
-            if (IsCleanUp)
-              SelsToConvert.insert(II);
-          }
-        }
+               SI = SelCalls.begin(), SE = SelCalls.end(); SI != SE; ++SI)
+          if (IsACleanupSelector(*SI))
+              SelsToConvert.insert(*SI);
       }
     }
   }
@@ -394,6 +408,15 @@
       // from the original selector.
       Args.push_back(II->getOperand(1)); // Exception object pointer.
       Args.push_back(II->getOperand(2)); // Personality function.
+
+      unsigned I = 3;
+      unsigned E = II->getNumOperands() -
+        (isa<ConstantInt>(II->getOperand(II->getNumOperands() - 1)) ? 1 : 0);
+
+      // Add in any filter IDs.
+      for (; I < E; ++I)
+        Args.push_back(II->getOperand(I));
+
       Args.push_back(EHCatchAllValue->getInitializer()); // Catch-all indicator.
 
       CallInst *NewSelector =





More information about the llvm-commits mailing list