Mark all calls as "could throw", when exceptions are enabled. Emit necessary LP info...
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 23 May 2007 11:08:31 +0000 (11:08 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 23 May 2007 11:08:31 +0000 (11:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37311 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineModuleInfo.h
lib/CodeGen/DwarfWriter.cpp
lib/CodeGen/MachineModuleInfo.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 4e7ce5b8f125f74139357b6a5d3c5331c066cf2e..c13ba517529ca5f39f11474c822828e6bf62364c 100644 (file)
@@ -967,6 +967,7 @@ struct LandingPadInfo {
   LandingPadInfo(MachineBasicBlock *MBB)
   : LandingPadBlock(MBB)
   , LandingPadLabel(0)
+  , Personality(NULL)  
   , TypeIds()
   , IsFilter(false)
   {}
index 23ce4b2bf442a94c11e01377a90545ee976a48b4..7e97788bc12e2147f77402893f8a807e2735e32f 100644 (file)
@@ -2852,7 +2852,7 @@ private:
       
       EmitLabel("eh_frame_begin", EHFrameInfo.Number);
 
-      EmitSectionOffset("eh_frame_begin", "section_eh_frame",
+      EmitSectionOffset("eh_frame_begin", "eh_frame_common",
                         EHFrameInfo.Number, EHFrameInfo.PersonalityIndex,
                         true, true);
       Asm->EOL("FDE CIE offset");
index d4d132989ec73470a9767f7688265ee9759677e9..564c070bc34cd4d11bf45f256b7ef55d083a6940 100644 (file)
@@ -1723,7 +1723,9 @@ void MachineModuleInfo::TidyLandingPads() {
     LandingPadInfo &LandingPad = LandingPads[i];
     LandingPad.LandingPadLabel = MappedLabel(LandingPad.LandingPadLabel);
 
-    if (!LandingPad.LandingPadLabel) {
+    // Special case: we *should* emit LPs with null LP MBB. This indicates
+    // "rethrow" case.
+    if (!LandingPad.LandingPadLabel && LandingPad.LandingPadBlock) {
       LandingPads.erase(LandingPads.begin() + i);
       continue;
     }
@@ -1768,9 +1770,15 @@ Function *MachineModuleInfo::getPersonality() const {
 /// getPersonalityIndex - Return unique index for current personality
 /// function. NULL personality function should always get zero index.
 unsigned MachineModuleInfo::getPersonalityIndex() const {
-  const Function* Personality = (!LandingPads.empty() ?
-                                 LandingPads[0].Personality : NULL);
-
+  const Function* Personality = NULL;
+  
+  // Scan landing pads. If there is at least one non-NULL personality - use it.
+  for (unsigned i = 0; i != LandingPads.size(); ++i)
+    if (LandingPads[i].Personality) {
+      Personality = LandingPads[i].Personality;
+      break;
+    }
+  
   for (unsigned i = 0; i < Personalities.size(); ++i) {
     if (Personalities[i] == Personality)
       return i;
index 7fd1938e7a760522dababda4633dcd566f9d40c7..1115b219948cfe4e8f46f8ad1d6c617c6c875771 100644 (file)
@@ -529,8 +529,9 @@ public:
   void ExportFromCurrentBlock(Value *V);
   void LowerCallTo(Instruction &I,
                    const Type *CalledValueTy, unsigned CallingConv,
-                   bool IsTailCall, SDOperand Callee, unsigned OpIdx);
-                                         
+                   bool IsTailCall, SDOperand Callee, unsigned OpIdx,
+                   MachineBasicBlock *LandingPad = NULL);
+  
   // Terminator instructions.
   void visitRet(ReturnInst &I);
   void visitBr(BranchInst &I);
@@ -1341,31 +1342,13 @@ void SelectionDAGLowering::visitInvoke(InvokeInst &I, bool AsTerminator) {
   if (!AsTerminator) {
     // Mark landing pad so that it doesn't get deleted in branch folding.
     LandingPad->setIsLandingPad();
-    
-    // Insert a label before the invoke call to mark the try range.
-    // This can be used to detect deletion of the invoke via the
-    // MachineModuleInfo.
-    MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
-    unsigned BeginLabel = MMI->NextLabelID();
-    DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, getRoot(),
-                            DAG.getConstant(BeginLabel, MVT::i32)));
-
+        
     LowerCallTo(I, I.getCalledValue()->getType(),
-                   I.getCallingConv(),
-                   false,
-                   getValue(I.getOperand(0)),
-                   3);
-
-    // Insert a label before the invoke call to mark the try range.
-    // This can be used to detect deletion of the invoke via the
-    // MachineModuleInfo.
-    unsigned EndLabel = MMI->NextLabelID();
-    DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, getRoot(),
-                            DAG.getConstant(EndLabel, MVT::i32)));
-                            
-    // Inform MachineModuleInfo of range.    
-    MMI->addInvoke(LandingPad, BeginLabel, EndLabel);
-                            
+                I.getCallingConv(),
+                false,
+                getValue(I.getOperand(0)),
+                3, LandingPad);
+
     // Update successor info
     CurMBB->addSuccessor(Return);
     CurMBB->addSuccessor(LandingPad);
@@ -2782,11 +2765,14 @@ void SelectionDAGLowering::LowerCallTo(Instruction &I,
                                        const Type *CalledValueTy,
                                        unsigned CallingConv,
                                        bool IsTailCall,
-                                       SDOperand Callee, unsigned OpIdx) {
+                                       SDOperand Callee, unsigned OpIdx,
+                                       MachineBasicBlock *LandingPad) {
   const PointerType *PT = cast<PointerType>(CalledValueTy);
   const FunctionType *FTy = cast<FunctionType>(PT->getElementType());
   const ParamAttrsList *Attrs = FTy->getParamAttrs();
-
+  MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
+  unsigned BeginLabel = 0, EndLabel = 0;
+    
   TargetLowering::ArgListTy Args;
   TargetLowering::ArgListEntry Entry;
   Args.reserve(I.getNumOperands());
@@ -2803,6 +2789,14 @@ void SelectionDAGLowering::LowerCallTo(Instruction &I,
     Args.push_back(Entry);
   }
 
+  if (ExceptionHandling) {
+    // Insert a label before the invoke call to mark the try range.  This can be
+    // used to detect deletion of the invoke via the MachineModuleInfo.
+    BeginLabel = MMI->NextLabelID();
+    DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, getRoot(),
+                            DAG.getConstant(BeginLabel, MVT::i32)));
+  }
+  
   std::pair<SDOperand,SDOperand> Result =
     TLI.LowerCallTo(getRoot(), I.getType(), 
                     Attrs && Attrs->paramHasAttr(0, ParamAttr::SExt),
@@ -2811,6 +2805,17 @@ void SelectionDAGLowering::LowerCallTo(Instruction &I,
   if (I.getType() != Type::VoidTy)
     setValue(&I, Result.first);
   DAG.setRoot(Result.second);
+
+  if (ExceptionHandling) {
+    // Insert a label at the end of the invoke call to mark the try range.  This
+    // can be used to detect deletion of the invoke via the MachineModuleInfo.
+    EndLabel = MMI->NextLabelID();
+    DAG.setRoot(DAG.getNode(ISD::LABEL, MVT::Other, getRoot(),
+                            DAG.getConstant(EndLabel, MVT::i32)));
+
+    // Inform MachineModuleInfo of range.    
+    MMI->addInvoke(LandingPad, BeginLabel, EndLabel);
+  }
 }
 
 
@@ -2871,12 +2876,12 @@ void SelectionDAGLowering::visitCall(CallInst &I) {
     Callee = getValue(I.getOperand(0));
   else
     Callee = DAG.getExternalSymbol(RenameFn, TLI.getPointerTy());
-    
+
   LowerCallTo(I, I.getCalledValue()->getType(),
-                 I.getCallingConv(),
-                 I.isTailCall(),
-                 Callee,
-                 1);
+              I.getCallingConv(),
+              I.isTailCall(),
+              Callee,
+              1);
 }