Handle InvokeInst in EvaluateBlock. Don't try to support exceptions, it's just
authorNick Lewycky <nicholas@mxc.ca>
Sun, 12 Feb 2012 05:09:35 +0000 (05:09 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sun, 12 Feb 2012 05:09:35 +0000 (05:09 +0000)
that no optz'ns have run yet to convert invokes to calls.

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

lib/Transforms/IPO/GlobalOpt.cpp

index c7f71a6d50087de40f8b3982601d9e167b66ebef..d959a223caca33e3d8431b049d6319ec2511901f 100644 (file)
@@ -2403,18 +2403,19 @@ static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
                                               UndefValue::get(Ty),
                                               AI->getName()));
       InstResult = AllocaTmps.back();
-    } else if (CallInst *CI = dyn_cast<CallInst>(CurInst)) {
+    } else if (isa<CallInst>(CurInst) || isa<InvokeInst>(CurInst)) {
+      CallSite CS(CurInst);
 
       // Debug info can safely be ignored here.
-      if (isa<DbgInfoIntrinsic>(CI)) {
+      if (isa<DbgInfoIntrinsic>(CS.getInstruction())) {
         ++CurInst;
         continue;
       }
 
       // Cannot handle inline asm.
-      if (isa<InlineAsm>(CI->getCalledValue())) return false;
+      if (isa<InlineAsm>(CS.getCalledValue())) return false;
 
-      if (MemSetInst *MSI = dyn_cast<MemSetInst>(CI)) {
+      if (MemSetInst *MSI = dyn_cast<MemSetInst>(CS.getInstruction())) {
         if (MSI->isVolatile()) return false;
         Constant *Ptr = getVal(Values, MSI->getDest());
         Constant *Val = getVal(Values, MSI->getValue());
@@ -2430,13 +2431,12 @@ static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
 
       // Resolve function pointers.
       Function *Callee = dyn_cast<Function>(getVal(Values,
-                                                   CI->getCalledValue()));
-      if (!Callee) return false;  // Cannot resolve.
+                                                   CS.getCalledValue()));
+      if (!Callee || Callee->mayBeOverridden())
+        return false;  // Cannot resolve.
 
       SmallVector<Constant*, 8> Formals;
-      CallSite CS(CI);
-      for (User::op_iterator i = CS.arg_begin(), e = CS.arg_end();
-           i != e; ++i)
+      for (User::op_iterator i = CS.arg_begin(), e = CS.arg_end(); i != e; ++i)
         Formals.push_back(getVal(Values, *i));
 
       if (Callee->isDeclaration()) {
@@ -2457,6 +2457,11 @@ static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
                               TLI))
           return false;
         InstResult = RetVal;
+
+        if (InvokeInst *II = dyn_cast<InvokeInst>(CurInst)) {
+          NextBB = II->getNormalDest();
+          return true;
+        }
       }
     } else if (isa<TerminatorInst>(CurInst)) {
       if (BranchInst *BI = dyn_cast<BranchInst>(CurInst)) {