[llvm-branch-commits] [llvm-branch] r136063 - in /llvm/branches/exception-handling-rewrite: include/llvm/Bitcode/LLVMBitCodes.h include/llvm/Instructions.h lib/AsmParser/LLLexer.cpp lib/AsmParser/LLParser.cpp lib/AsmParser/LLToken.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp lib/CodeGen/ShadowStackGC.cpp lib/Transforms/InstCombine/InstCombineCalls.cpp lib/VMCore/AsmWriter.cpp

Bill Wendling isanbard at gmail.com
Tue Jul 26 00:46:35 PDT 2011


Author: void
Date: Tue Jul 26 02:46:35 2011
New Revision: 136063

URL: http://llvm.org/viewvc/llvm-project?rev=136063&view=rev
Log:
Add a flag indicating whether the landingpad instruction represents a cleanup or
not.

Modified:
    llvm/branches/exception-handling-rewrite/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h
    llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp
    llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp
    llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h
    llvm/branches/exception-handling-rewrite/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/branches/exception-handling-rewrite/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/branches/exception-handling-rewrite/lib/CodeGen/ShadowStackGC.cpp
    llvm/branches/exception-handling-rewrite/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/branches/exception-handling-rewrite/lib/VMCore/AsmWriter.cpp

Modified: llvm/branches/exception-handling-rewrite/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/include/llvm/Bitcode/LLVMBitCodes.h?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/branches/exception-handling-rewrite/include/llvm/Bitcode/LLVMBitCodes.h Tue Jul 26 02:46:35 2011
@@ -285,7 +285,7 @@
 
     FUNC_CODE_DEBUG_LOC        = 35, // DEBUG_LOC:  [Line,Col,ScopeVal, IAVal]
     FUNC_CODE_INST_FENCE       = 36, // FENCE: [ordering, synchscope]
-    FUNC_CODE_INST_LANDINGPAD  = 37  // LANDINGPAD: [ty, val, num, id0,val0 ...]
+    FUNC_CODE_INST_LANDINGPAD  = 37  // LANDINGPAD: [ty,val,val,num,id0,val0...]
   };
 } // End bitc namespace
 } // End llvm namespace

Modified: llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h (original)
+++ llvm/branches/exception-handling-rewrite/include/llvm/Instructions.h Tue Jul 26 02:46:35 2011
@@ -1789,6 +1789,9 @@
   /// ReservedSpace - The number of operands actually allocated.  NumOperands is
   /// the number actually in use.
   unsigned ReservedSpace;
+
+  /// IsCleanup - True if the landingpad instruction is also a cleanup.
+  bool IsCleanup;
   LandingPadInst(const LandingPadInst &LP);
 public:
   enum ClauseType { Catch, Filter };
@@ -1808,13 +1811,15 @@
   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
                           unsigned NumReservedValues, const Twine &NameStr,
                           Instruction *InsertBefore)
-    : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertBefore) {
+    : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertBefore),
+      IsCleanup(false) {
     init(PersonalityFn, 1 + NumReservedValues, NameStr);
   }
   explicit LandingPadInst(Type *RetTy, Value *PersonalityFn,
                           unsigned NumReservedValues, const Twine &NameStr,
                           BasicBlock *InsertAtEnd)
-    : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertAtEnd) {
+    : Instruction(RetTy, Instruction::LandingPad, 0, 0, InsertAtEnd),
+      IsCleanup(false) {
     init(PersonalityFn, 1 + NumReservedValues, NameStr);
   }
 protected:
@@ -1842,6 +1847,10 @@
   /// landing pad.
   const Value *getPersonalityFn() const { return getOperand(0); }
 
+  // Simple accessors.
+  bool isCleanup() const { return IsCleanup; }
+  void setCleanup(bool Val) { IsCleanup = Val; }
+
   /// addClause - Add a clause to the landing pad.
   void addClause(ClauseType CT, Value *ClauseVal);
 

Modified: llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/AsmParser/LLLexer.cpp Tue Jul 26 02:46:35 2011
@@ -583,6 +583,7 @@
   KEYWORD(blockaddress);
 
   KEYWORD(personality);
+  KEYWORD(cleanup);
   KEYWORD(catch);
   KEYWORD(filter);
 #undef KEYWORD

Modified: llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/AsmParser/LLParser.cpp Tue Jul 26 02:46:35 2011
@@ -3509,7 +3509,8 @@
 }
 
 /// ParseLandingPad
-///   ::= 'landingpad' Type 'personality' TypeAndValue (ClauseID ClauseList)+
+///   ::= 'landingpad' Type 'personality' TypeAndValue 'cleanup'?
+///       (ClauseID ClauseList)+
 /// ClauseID
 ///   ::= 'catch'
 ///   ::= 'filter'
@@ -3525,8 +3526,9 @@
       ParseTypeAndValue(PersFn, PersFnLoc, PFS))
     return true;
 
-  SmallVector<std::pair<LandingPadInst::ClauseType, Value*>, 16> Clauses;
+  bool IsCleanup = EatIfPresent(lltok::kw_cleanup);
 
+  SmallVector<std::pair<LandingPadInst::ClauseType, Value*>, 16> Clauses;
   while (Lex.getKind() == lltok::kw_catch || Lex.getKind() == lltok::kw_filter){
     LandingPadInst::ClauseType CT;
     if (Lex.getKind() == lltok::kw_catch) {
@@ -3546,6 +3548,7 @@
   }
 
   LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, Clauses.size());
+  LP->setCleanup(IsCleanup);
 
   for (SmallVectorImpl<std::pair<LandingPadInst::ClauseType, Value*> >::iterator
          I = Clauses.begin(), E = Clauses.end(); I != E; ++I)

Modified: llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h (original)
+++ llvm/branches/exception-handling-rewrite/lib/AsmParser/LLToken.h Tue Jul 26 02:46:35 2011
@@ -121,7 +121,7 @@
     kw_fptoui, kw_fptosi, kw_inttoptr, kw_ptrtoint, kw_bitcast,
     kw_select, kw_va_arg,
 
-    kw_landingpad, kw_personality, kw_catch, kw_filter,
+    kw_landingpad, kw_personality, kw_cleanup, kw_catch, kw_filter,
 
     kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_unwind, kw_resume,
     kw_unreachable,

Modified: llvm/branches/exception-handling-rewrite/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/Bitcode/Reader/BitcodeReader.cpp?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/Bitcode/Reader/BitcodeReader.cpp Tue Jul 26 02:46:35 2011
@@ -2527,9 +2527,9 @@
     }
 
     case bitc::FUNC_CODE_INST_LANDINGPAD: {
-      // LANDINGPAD: [ty, val, num, id0,val0 ...]
+      // LANDINGPAD: [ty, val, val, num, id0,val0 ...]
       unsigned Idx = 0;
-      if (Record.size() < 5)
+      if (Record.size() < 6)
         return Error("Invalid LANDINGPAD record");
       Type *Ty = getTypeByID(Record[Idx++]);
       if (!Ty) return Error("Invalid LANDINGPAD record");
@@ -2537,9 +2537,10 @@
       if (getValueTypePair(Record, Idx, NextValueNo, PersFn))
         return Error("Invalid LANDINGPAD record");
 
+      bool IsCleanup = !!Record[Idx++];
       unsigned NumClauses = Record[Idx++];
       LandingPadInst *LP = LandingPadInst::Create(Ty, PersFn, NumClauses);
-
+      LP->setCleanup(IsCleanup);
       for (unsigned J = 0; J != NumClauses; ++J) {
         LandingPadInst::ClauseType CT =
           LandingPadInst::ClauseType(Record[Idx++]);

Modified: llvm/branches/exception-handling-rewrite/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/Bitcode/Writer/BitcodeWriter.cpp Tue Jul 26 02:46:35 2011
@@ -1154,6 +1154,7 @@
     Code = bitc::FUNC_CODE_INST_LANDINGPAD;
     Vals.push_back(VE.getTypeID(LP.getType()));
     PushValueAndType(LP.getPersonalityFn(), InstID, Vals, VE);
+    Vals.push_back(LP.isCleanup());
     Vals.push_back(LP.getNumClauses());
     for (unsigned I = 0, E = LP.getNumClauses(); I != E; ++I) {
       Vals.push_back(LP.getClauseType(I));

Modified: llvm/branches/exception-handling-rewrite/lib/CodeGen/ShadowStackGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/CodeGen/ShadowStackGC.cpp?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/CodeGen/ShadowStackGC.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/CodeGen/ShadowStackGC.cpp Tue Jul 26 02:46:35 2011
@@ -113,9 +113,11 @@
         while (StateBB != StateE) {
           BasicBlock *CurBB = StateBB++;
 
-          // Branches and invokes do not escape, only unwind and return do.
+          // Branches and invokes do not escape, only unwind, resume, and return
+          // do.
           TerminatorInst *TI = CurBB->getTerminator();
-          if (!isa<UnwindInst>(TI) && !isa<ReturnInst>(TI))
+          if (!isa<UnwindInst>(TI) && !isa<ReturnInst>(TI) &&
+              !isa<ResumeInst>(TI))
             continue;
 
           Builder.SetInsertPoint(TI->getParent(), TI);

Modified: llvm/branches/exception-handling-rewrite/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/Transforms/InstCombine/InstCombineCalls.cpp Tue Jul 26 02:46:35 2011
@@ -732,9 +732,11 @@
       }
     }
     
-    // If the stack restore is in a return/unwind block and if there are no
-    // allocas or calls between the restore and the return, nuke the restore.
-    if (!CannotRemove && (isa<ReturnInst>(TI) || isa<UnwindInst>(TI)))
+    // If the stack restore is in a return, resume, or unwind block and if there
+    // are no allocas or calls between the restore and the return, nuke the
+    // restore.
+    if (!CannotRemove && (isa<ReturnInst>(TI) || isa<ResumeInst>(TI) ||
+                          isa<UnwindInst>(TI)))
       return EraseInstFromFunction(CI);
     break;
   }

Modified: llvm/branches/exception-handling-rewrite/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/exception-handling-rewrite/lib/VMCore/AsmWriter.cpp?rev=136063&r1=136062&r2=136063&view=diff
==============================================================================
--- llvm/branches/exception-handling-rewrite/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/branches/exception-handling-rewrite/lib/VMCore/AsmWriter.cpp Tue Jul 26 02:46:35 2011
@@ -1741,6 +1741,9 @@
     Out << " personality ";
     writeOperand(LPI->getPersonalityFn(), true); Out << '\n';
 
+    if (LPI->isCleanup())
+      Out << "          cleanup\n";
+
     for (unsigned i = 0, e = LPI->getNumClauses(); i != e; ) {
       if (i != 0) Out << "\n";
 





More information about the llvm-branch-commits mailing list