[llvm-commits] [llvm] r169044 - in /llvm/trunk: include/llvm/CodeGen/Passes.h lib/CodeGen/LLVMTargetMachine.cpp lib/CodeGen/Passes.cpp lib/Transforms/Scalar/CodeGenPrepare.cpp

Bill Wendling isanbard at gmail.com
Fri Nov 30 14:08:55 PST 2012


Author: void
Date: Fri Nov 30 16:08:55 2012
New Revision: 169044

URL: http://llvm.org/viewvc/llvm-project?rev=169044&view=rev
Log:
Replace r168930 with a more reasonable patch.

The original patch removed a bunch of code that the SjLjEHPrepare pass placed
into the entry block if all of the landing pads were removed during the
CodeGenPrepare class. The more natural way of doing things is to run the CGP
*before* we run the SjLjEHPrepare pass.

Make it so!

Modified:
    llvm/trunk/include/llvm/CodeGen/Passes.h
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/lib/CodeGen/Passes.cpp
    llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp

Modified: llvm/trunk/include/llvm/CodeGen/Passes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=169044&r1=169043&r2=169044&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Passes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Passes.h Fri Nov 30 16:08:55 2012
@@ -141,6 +141,10 @@
   /// Add passes to lower exception handling for the code generator.
   void addPassesToHandleExceptions();
 
+  /// Add pass to prepare the LLVM IR for code generation. This should be done
+  /// before exception handling preparation passes.
+  virtual void addCodeGenPrepare();
+
   /// Add common passes that perform LLVM IR to IR transforms in preparation for
   /// instruction selection.
   virtual void addISelPrepare();

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=169044&r1=169043&r2=169044&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Fri Nov 30 16:08:55 2012
@@ -96,6 +96,8 @@
 
   PassConfig->addIRPasses();
 
+  PassConfig->addCodeGenPrepare();
+
   PassConfig->addPassesToHandleExceptions();
 
   PassConfig->addISelPrepare();

Modified: llvm/trunk/lib/CodeGen/Passes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Passes.cpp?rev=169044&r1=169043&r2=169044&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Passes.cpp (original)
+++ llvm/trunk/lib/CodeGen/Passes.cpp Fri Nov 30 16:08:55 2012
@@ -400,12 +400,16 @@
   }
 }
 
-/// Add common passes that perform LLVM IR to IR transforms in preparation for
-/// instruction selection.
-void TargetPassConfig::addISelPrepare() {
+/// Add pass to prepare the LLVM IR for code generation. This should be done
+/// before exception handling preparation passes.
+void TargetPassConfig::addCodeGenPrepare() {
   if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
     addPass(createCodeGenPreparePass(getTargetLowering()));
+}
 
+/// Add common passes that perform LLVM IR to IR transforms in preparation for
+/// instruction selection.
+void TargetPassConfig::addISelPrepare() {
   addPass(createStackProtectorPass(getTargetLowering()));
 
   addPreISel();

Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=169044&r1=169043&r2=169044&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Fri Nov 30 16:08:55 2012
@@ -22,7 +22,6 @@
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/IntrinsicInst.h"
-#include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallSet.h"
@@ -184,12 +183,8 @@
   if (!DisableBranchOpts) {
     MadeChange = false;
     SmallPtrSet<BasicBlock*, 8> WorkList;
-    SmallPtrSet<BasicBlock*, 8> LPadList;
-    SmallVector<BasicBlock*, 8> ReturnList;
     for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
       SmallVector<BasicBlock*, 2> Successors(succ_begin(BB), succ_end(BB));
-      if (BB->isLandingPad()) LPadList.insert(BB);
-      if (isa<ReturnInst>(BB->getTerminator())) ReturnList.push_back(BB);
       MadeChange |= ConstantFoldTerminator(BB, true);
       if (!MadeChange) continue;
 
@@ -200,11 +195,9 @@
     }
 
     // Delete the dead blocks and any of their dead successors.
-    bool HadLPads = !LPadList.empty();
     while (!WorkList.empty()) {
       BasicBlock *BB = *WorkList.begin();
       WorkList.erase(BB);
-      LPadList.erase(BB);
       SmallVector<BasicBlock*, 2> Successors(succ_begin(BB), succ_end(BB));
 
       DeleteDeadBlock(BB);
@@ -215,74 +208,6 @@
           WorkList.insert(*II);
     }
 
-    if (HadLPads && LPadList.empty()) {
-      // All of the landing pads were removed. Get rid of the SjLj EH context
-      // code.
-      Module *M = F.getParent();
-
-      // These functions must exist if we have SjLj EH code to clean up.
-      Constant *RegisterFn = M->getFunction("_Unwind_SjLj_Register");
-      Constant *UnregisterFn = M->getFunction("_Unwind_SjLj_Unregister");
-
-      if (RegisterFn) {
-        Constant *LSDAAddrFn =
-          Intrinsic::getDeclaration(M, Intrinsic::eh_sjlj_lsda);
-        Constant *FrameAddrFn =
-          Intrinsic::getDeclaration(M, Intrinsic::frameaddress);
-        Constant *StackAddrFn =
-          Intrinsic::getDeclaration(M, Intrinsic::stacksave);
-        Constant *BuiltinSetjmpFn =
-          Intrinsic::getDeclaration(M, Intrinsic::eh_sjlj_setjmp);
-        Constant *FuncCtxFn =
-          Intrinsic::getDeclaration(M, Intrinsic::eh_sjlj_functioncontext);
-
-        BasicBlock &Entry = F.getEntryBlock();
-        SmallVector<Instruction*, 8> DeadInsts;
-        for (BasicBlock::iterator I = Entry.begin(), E = Entry.end();
-             I != E; ++I) {
-          if (CallInst *CI = dyn_cast<CallInst>(I)) {
-            Value *Callee = CI->getCalledValue();
-            bool IsDead = true;
-            if (Callee != LSDAAddrFn && Callee != FrameAddrFn &&
-                Callee != StackAddrFn && Callee != BuiltinSetjmpFn &&
-                Callee != FuncCtxFn && Callee != RegisterFn)
-              IsDead = false;
-
-            if (IsDead) {
-              Type *Ty = CI->getType();
-              if (!Ty->isVoidTy())
-                CI->replaceAllUsesWith(UndefValue::get(Ty));
-              DeadInsts.push_back(CI);
-            }
-          }
-        }
-
-        // Find and remove the unregister calls.
-        for (SmallVectorImpl<BasicBlock*>::iterator I = ReturnList.begin(),
-               E = ReturnList.end(); I != E; ++I) {
-          BasicBlock *BB = *I;
-          typedef BasicBlock::InstListType::reverse_iterator reverse_iterator;
-
-          for (reverse_iterator II = BB->getInstList().rbegin(),
-                 IE = BB->getInstList().rend(); II != IE; ++II) {
-            if (CallInst *CI = dyn_cast<CallInst>(&*II)) {
-              Value *Callee = CI->getCalledValue();
-
-              if (Callee == UnregisterFn) {
-                DeadInsts.push_back(CI);
-                break;
-              }
-            }
-          }
-        }
-
-        // Kill the dead instructions.
-        for (SmallVectorImpl<Instruction*>::iterator I = DeadInsts.begin(),
-               E = DeadInsts.end(); I != E; ++I)
-          (*I)->eraseFromParent();
-      }
-    }
-
     // Merge pairs of basic blocks with unconditional branches, connected by
     // a single edge.
     if (EverMadeChange || MadeChange)





More information about the llvm-commits mailing list